📄 psvautoassembler.pas.svn-base
字号:
{*******************************************************}
{ RichEdit Syntax HighLight }
{ version 3.0 }
{ Author: }
{ Serhiy Perevoznyk }
{ serge_perevoznyk@hotmail.com }
{*******************************************************}
{The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynHighlighterPas.pas, released 2000-04-17.
The Original Code is based on the mwPasSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Martin Waldenburg.
Portions created by Martin Waldenburg are Copyright (C) 1998 Martin Waldenburg.
All Rights Reserved.
The Original Code can be obtained from http://synedit.sourceforge.net/
This code has again be modified to work with cheat engine's auto assembler language
}
unit psvAutoAssembler;
interface
uses
SysUtils,
Windows,
Classes,
Controls,
psvRichSyntax,
Graphics,
assemblerunit;
type
TtkTokenKind = (tkAsm, tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkSpace, tkString, tkSymbol, tkUnknown, tkRegister);
TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty,
rsUnKnown);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
TpsvAARTF = class(TpsvRTFSyntax)
private
fAsmStart: Boolean;
fRange: TRangeState;
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fIdentFuncTable: array[0..222] of TIdentFuncTableFunc;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: string): Boolean;
function Func9: TtkTokenKind; //ah
function Func10: TtkTokenKind; //bh
function Func11: TtkTokenKind; //ch
function Func12: TtkTokenKind; //dh
function Func13: TtkTokenKind; //di / al
function Func14: TtkTokenKind; //bl
function Func15: TtkTokenKind; //cl
function Func16: TtkTokenKind; //dl
function Func18: TtkTokenKind; //edi / bp
function Func23: TtkTokenKind; //ebp
function Func25: TtkTokenKind; //ax / 25
function Func26: TtkTokenKind; //bx
function Func27: TtkTokenKind; //cx
function Func28: TtkTokenKind; //dx / si
function Func30: TtkTokenKind; //eax / eip
function Func31: TtkTokenKind; //ebx
function Func32: TtkTokenKind; //ecx
function Func33: TtkTokenKind; //edx / esi
function Func35: TtkTokenKind; //sp
function Func39: TtkTokenKind; //enable
function Func40: TtkTokenKind; //esp
function Func43: TtkTokenKind; //alloc /define
function Func52: TtkTokenKind; //dealloc / disable
function Func54: TtkTokenKind; //kalloc
function Func59: TtkTokenKind; //readmem
function Func68: TtkTokenKind; //include
function Func101: TtkTokenKind; //fullaccess/loadbinary
function Func108: TtkTokenKind; //CreateThread
function Func117: TtkTokenKind; //loadlibrary
function Func187: TtkTokenKind; //registersymbol
function Func222: TtkTokenKind; //unregistersymbol
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure AddressOpProc;
procedure AsciiCharProc;
procedure AnsiProc;
procedure BorProc;
procedure BraceOpenProc;
procedure ColonOrGreaterProc;
procedure CRProc;
procedure IdentProc;
procedure IntegerProc;
procedure LFProc;
procedure LowerProc;
procedure NullProc;
procedure NumberProc;
procedure PointProc;
procedure RoundOpenProc;
procedure SemicolonProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure SymbolProc;
procedure UnknownProc;
protected
function GetEol: Boolean; override;
function GetRange: Pointer;
function GetToken: string; override;
function GetTokenAttribute: integer; override;
function GetTokenID: TtkTokenKind;
function GetTokenKind: integer;
function GetTokenPos: Integer;
procedure Next; override;
procedure ResetRange;
procedure SetLine(NewValue: string; LineNumber:Integer); override;
procedure SetRange(Value: Pointer);
procedure PrepareToken(var AToken : string); override;
function PrepareOutput(Attr: integer; AToken : string): string; override;
public
constructor Create; override;
procedure SetupDefaultColors; override;
end;
implementation
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I, J: Char;
begin
for I := #0 to #255 do
begin
Case I of
'_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
else Identifiers[I] := False;
end;
J := UpCase(I);
Case I of
'a'..'z', 'A'..'Z', '_': mHashTable[I] := Ord(J) - 64;
else mHashTable[Char(I)] := 0;
end;
end;
end;
procedure TpsvAARTF.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := AltFunc;
Inc(pF);
end;
fIdentFuncTable[9] := Func9;
fIdentFuncTable[10] := Func10;
fIdentFuncTable[11] := Func11;
fIdentFuncTable[12] := Func12;
fIdentFuncTable[13] := Func13;
fIdentFuncTable[14] := Func14;
fIdentFuncTable[15] := Func15;
fIdentFuncTable[16] := Func16;
fIdentFuncTable[18] := Func18;
fIdentFuncTable[23] := Func23;
fIdentFuncTable[25] := Func25;
fIdentFuncTable[26] := Func26;
fIdentFuncTable[27] := Func27;
fIdentFuncTable[28] := Func28;
fIdentFuncTable[30] := Func30;
fIdentFuncTable[31] := Func31;
fIdentFuncTable[32] := Func32;
fIdentFuncTable[33] := Func33;
fIdentFuncTable[35] := Func35;
fIdentFuncTable[39] := Func39;
fIdentFuncTable[40] := Func40;
fIdentFuncTable[43] := Func43;
fIdentFuncTable[52] := Func52;
fIdentFuncTable[54] := Func54;
fIdentFuncTable[59] := Func59;
fIdentFuncTable[68] := Func68;
fIdentFuncTable[101] := Func101;
fIdentFuncTable[108] := Func108;
fIdentFuncTable[117] := Func117;
fIdentFuncTable[187] := Func187;
fIdentFuncTable[222] := Func222;
end;
function TpsvAARTF.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
if ToHash^ in ['_', '0'..'9'] then inc(ToHash);
fStringLen := ToHash - fToIdent;
end; { KeyHash }
function TpsvAARTF.KeyComp(const aKey: string): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end; { KeyComp }
function TpsvAARTF.Func9: TtkTokenKind;
begin
if KeyComp('ah') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func10: TtkTokenKind;
begin
if KeyComp('bh') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func11: TtkTokenKind;
begin
if KeyComp('ch') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func12: TtkTokenKind;
begin
if KeyComp('dh') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func13: TtkTokenKind;
begin
if KeyComp('di') then Result := tkRegister else
if KeyComp('al') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func14: TtkTokenKind;
begin
if KeyComp('bl') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func15: TtkTokenKind;
begin
if KeyComp('cl') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func16: TtkTokenKind;
begin
if KeyComp('dl') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func18: TtkTokenKind;
begin
if KeyComp('edi') then Result := tkRegister else
if KeyComp('bp') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func23: TtkTokenKind;
begin
if KeyComp('ebp') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func25: TtkTokenKind;
begin
if KeyComp('ax') then Result := tkRegister else
if KeyComp('ip') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func26: TtkTokenKind;
begin
if KeyComp('bx') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func27: TtkTokenKind;
begin
if KeyComp('cx') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func28: TtkTokenKind;
begin
if KeyComp('dx') then Result := tkRegister else
if KeyComp('si') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func30: TtkTokenKind;
begin
if KeyComp('eax') then Result := tkRegister else
if KeyComp('eip') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func31: TtkTokenKind;
begin
if KeyComp('ebx') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func32: TtkTokenKind;
begin
if KeyComp('Label') then Result := tkKey else
if KeyComp('ecx') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func33: TtkTokenKind;
begin
if KeyComp('edx') then Result := tkRegister else
if KeyComp('esi') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func35: TtkTokenKind;
begin
if KeyComp('bp') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func39: TtkTokenKind; //enable
begin
if KeyComp('enable') then Result := tkspace else
Result := tkIdentifier;
end;
function TpsvAARTF.Func40: TtkTokenKind; //enable
begin
if KeyComp('esp') then Result := tkRegister else
Result := tkIdentifier;
end;
function TpsvAARTF.Func43: TtkTokenKind; //alloc /define
begin
if KeyComp('alloc') then Result := tkKey else
if KeyComp('define') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func52: TtkTokenKind; //dealloc
begin
if KeyComp('dealloc') then Result := tkKey else
if KeyComp('disable') then Result := tkspace else
Result := tkIdentifier;
end;
function TpsvAARTF.Func54: TtkTokenKind; //kalloc
begin
if KeyComp('kalloc') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func59: TtkTokenKind; //readmem
begin
if KeyComp('readmem') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func68: TtkTokenKind; //include
begin
if KeyComp('include') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func101: TtkTokenKind;
begin
if KeyComp('LoadBinary') then Result := tkKey else
if KeyComp('fullaccess') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func108: TtkTokenKind; //CreateThread
begin
if KeyComp('createthread') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func117: TtkTokenKind; //loadlibrary
begin
if KeyComp('loadlibrary') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func187: TtkTokenKind; //registersymbol
begin
if KeyComp('registersymbol') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.Func222: TtkTokenKind; //unregistersymbol
begin
if KeyComp('unregistersymbol') then Result := tkKey else
Result := tkIdentifier;
end;
function TpsvAARTF.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier
end;
function getfirsttoken(s: string): string;
var i: integer;
begin
result:=s;
for i:=1 to length(s) do
begin
if (s[i]=' ') or (s[i]=#9) or (s[i]=',') or (s[i]=#10) or (s[i]=#13) then
begin
result:=copy(s,1,i-1);
exit;
end;
end;
end;
function TpsvAARTF.IdentKind(MayBe: PChar): TtkTokenKind;
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -