📄 dedesym.pas
字号:
FS.Free;
End;
SetLength(Index,Count);
FileName:=AsFileName;
Result:=DeDeBPL.LoadBPLSymbolFile(sym,str,AsFileName,mode,PatternSize,Count,Comment,Index);
UpdateFirstByteSet;
Except
ShowMessage(err_load_symfile+AsFileName+'"');
Result:=False;
End;
end;
Function GetDSFVersion(Sym : TDeDeSymbol) : String;
var ident : Integer;
Begin
Result:='unknown';
ident:=Sym.PatternSize;
If ident=$F Then
Begin
Result:='1.0';
Exit;
End;
If ident=32 Then
Begin
Result:='1.2';
Exit;
End;
If ident=40 Then
Begin
Result:='2.0';
Exit;
End;
If ident=50 Then
Begin
Result:='2.1';
Exit;
End;
End;
Procedure ParseExportParamFlags(sFlags : String; var beg, en : String);
var i : Integer;
Begin
en:='';beg:='';
i:=1;
While i<=Length(sFlags) Do
begin
case sFlags[i] of
// i = integer
'i' : en:=en+'; Integer';
// j = int64
'j' : en:=en+'; Int64';
// g = extended
'g' : en:=en+'; Extended';
// ui = Cardinal
'u' : begin
Inc(i);
//ui = Cardinal
If Copy(sFlags,i,1)='i' then en:=en+'; Cardinal';
end;
// p = Pointer
'p' : en:=en+'; Pointer';
'x' : begin
Inc(i);
//xi = Array of
If Copy(sFlags,i,1)='i' then beg:='Array Of ';
if Copy(sFlags,i,1)='t' then
begin
//xt1 = String
en:=en+'; String';
//inc(i);
//If Copy(sFlags,i,1)='1' then en:=en+'; String';
end;
end;
// vt1 VAR
'v' : begin
Inc(i);
if Copy(sFlags,i,1)='t' then
begin
//xt1 = String
en:=en+'; VAR';
//inc(i);
//If Copy(sFlags,i,1)='1' then en:=en+'; String';
end;
end;
end;
inc(i);
end;
If copy(en,Length(en)-8,9)='; Pointer' then
en:=Copy(en,1,Length(en)-9);
End;
procedure ParseExportParam(var sParam : String);
var s, ss, s1, s0, beg, mid, en, sf, sf0, sp, sfx : String;
i,len : Integer;
bChanges, bSkip, bFirst, bFlag : Boolean;
begin
sp:=sParam+' ';
s:='';
i:=Pos('$',sp);
s0:=Copy(sp,1,i-1);
bFirst:=True;
repeat
bChanges:=False;
i:=Pos('$',sp);
If i=0 Then
begin
s:=s+sp;
break;
end;
repeat inc(i) until Copy(sp,i,1)[1] in ['0'..'9',' '];
// Here the flags at the beginning of a params are parsed
sf0:=Copy(sp,1,i-1);
If bFirst Then
Begin
bFirst:=False;
ParseExportParamFlags(sf0,beg,en);
If Copy(en,1,2)='; ' then en:=Copy(en,3,Length(en)-2);
s:=s+beg+en;
End;
//
If Copy(sp,i,1)<>' ' Then
Begin
dec(i);ss:='';
repeat inc(i); ss:=ss+Copy(sp,i,1) until not (Copy(sp,i,1)[1] in ['0'..'9']);
ss:=Copy(ss,1,Length(ss)-1);
len:=StrToInt(ss);
mid:='';
If not ( (Pos('$',Copy(sp,i,len))<>0)
and (Pos('%',Copy(sp,i,len))=0))
then if (len>3) then mid:=Copy(sp,i,len);
inc(i,len);
// Parsing Flags Meaning
en:='';beg:='';sf:='';
while (i<Length(sp)) and (Copy(sp,i,1)[1] in ['a'..'z']) do
Begin
sf:=sf+sp[i];
Inc(i);
End;
ParseExportParamFlags(sf,beg,en);
s:=s+'; '+beg+mid+en;
If i<>Length(sp) then sp:=Copy(sp,i,Length(sp)-i+1)
else sp:='';
If (sp<>'') and (Copy(sp,1,1)[1] in ['0'..'9']) Then sp:='$'+sp;
bChanges:=True;
End;
until not bChanges;
ss:=s;s:='';
bChanges:=True;bSkip:=False;
For i:=1 To Length(ss) Do
Case ss[i] of
'@' : if bSkip then s1:=s1+'.'
else s:=s+'.';
'%' : begin
if bChanges
then begin
bSkip:=True;
s1:='';
end
else begin
bSkip:=False;
If Copy(s1,1,3)='Set' Then s1:=Copy(s1,4,Length(s1)-3);
s1:=s1+' ';
ParseExportParam(s1);
If Copy(s1,1,2)='; ' Then s1:=Copy(s1,3,Length(s1)-2);
If Copy(s1,Length(s1)-2,3)='; ' Then s1:=Copy(s1,1,Length(s1)-3);
If Copy(s1,Length(s1)-1,2)='; ' Then s1:=Copy(s1,1,Length(s1)-2);
If Copy(s1,Length(s1),1)=' ' Then s1:=Copy(s1,1,Length(s1)-1);
s:=s+'['+s1+']';
end;
bChanges:=not bChanges;
end;
Else if bSkip then s1:=s1+ss[i]
else s:=s+ss[i];
End;
s:=s0+s;
sfx:='';
bFlag:=False;
For i:=1 To Length(s) Do
Begin
If bFlag then
if s[i] in [#32,';']
then begin
if s[i]=#32 Then if Copy(sfx,Length(sfx),1)<>#32 then sfx:=sfx+' ';
continue;
end
else bFlag:=False;
If (s[i]=';') and (not bFlag) Then
begin
bFlag:=True;
sfx:=sfx+';';
continue;
end;
sfx:=sfx+s[i];
End;
sParam:=sfx;
end;
procedure ParseExportName(var sExport : String);
var s1 : String;
i : Integer;
begin
s1:='';
For i:=1 To Length(sExport) Do
Case sExport[i] of
'@' : s1:=s1+'.'
Else s1:=s1+sExport[i];
End;
sExport:=s1;
end;
function DCUFixParams(s : String) : String;
var iPos, len : Integer;
i : Integer;
const fixups_count=3;
fixups : array [1..fixups_count,1..2] of String =
(
('array[$0..-$1]' ,'array')
,('false..true' ,'boolean')
,('$' ,'')
);
begin
i:=0;
// Dont use "for-loop" here !!!!
// The order of appling fixups is important
//
// For i:=0 to fixoups_count do
// Here the compiler can produce code that decrements from max value
// instead of increment from min that will fuck up the result
repeat
iPos:=Pos(fixups[i+1,1],s);
While iPos<>0 Do
Begin
len:=Length(fixups[i+1,1]);
s:=Copy(s,1,iPos-1)+fixups[i+1,2]+Copy(s,iPos+len,Length(s)-iPos-len+1);
iPos:=Pos(fixups[i+1,1],s);
End;
Inc(i);
until i>=fixups_count;
Result:=s;
end;
// This should replace param names with param type name
//
// (sParam1, sParam2 : Stirng; dwParam3 : DWORD) -> (String; String; DWORD;)
function DCUExculdeParamNames(s : String) : String;
var s0,s1,s2,ss,st : String;
iPos, iPos2, i : Integer;
TmpLst : TStringList;
begin
iPos:=Pos('(',s);
s1:=Copy(s,1,iPos); s:=Copy(s,iPos+1,Length(s)-iPos);
iPos:=Pos(')',s);
s2:=Copy(s,iPos,Length(s)-iPos+1); s:=Copy(s,1,iPos-1);
// Replacing
s0:='';
TmpLst:=TStringList.Create;
Try
iPos:=Pos(':',s);
while iPos<>0 do
begin
iPos2:=Pos(';',s);
if iPos2=0 then
begin
iPos2:=Length(s)+1;
s:=s+';';
end;
ss:=Copy(s,1,iPos-1);
st:=Copy(s,iPos+1,iPos2-iPos-1);
st:=Trim(st)+';';
TmpLst.CommaText:=ss;
s:=Copy(s,iPos2+1,Length(s)-iPos2);
iPos:=Pos(':',s);
for iPos2:=1 to TmpLst.Count Do s0:=s0+st;
end;
Finally
TmpLst.Free;
End;
Result:=s1+s0+s2;
i:=Pos(';)',Result);
if i<>0 then Result:=Copy(Result,1,i-1)+Copy(Result,i+1,Length(Result)-i);
s:=Result;
Result:='';
For i:=1 to Length(s) Do
if s[i]<>' ' then Result:=Result+s[i];
end;
procedure TDeDeSymbol.UpdateFirstByteSet;
var i : Integer;
buff : TSymBuffer;
begin
Sym.Seek(0,soFromBeginning);
for i:=0 To Count-1 Do
Begin
Sym.ReadBuffer(buff[1],_PatternSize);
FirstByteSet:=FirstByteSet+[buff[1]];
End;
end;
initialization
DASM:=TDisAsm.Create;
FirstByteSet:=[];
finalization
DASM.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -