📄 asmshow.pas
字号:
procedure TASMShowForm.FindDlgFind(Sender: TObject);
var i, iFrom, iTo : Integer;
bDown, bMatchCase, bFound : Boolean;
s, sSearch : String;
begin
// Find Next
FsTextToFind:=FindDlg.FindText;
bDown:=frDown in FindDlg.Options;
bMatchCase:=frMatchCase in FindDlg.Options;
bFound:=False;
With ASMList Do
Begin
iFrom:=ItemIndex; iTo:=Items.Count-1;
if not bMatchCase then sSearch:=UpperCase(FsTextToFind)
else sSearch:=FsTextToFind;
Items.BeginUpdate;
Screen.Cursor:=crHourGlass;
Try
if bDown then
begin
if iFrom=iTo then iFrom:=iTo-1;
For i:=iFrom+1 to iTo do
begin
s:=Items[i];
if not bMatchCase then s:=UpperCase(s);
if Pos(sSearch,s)<>0 then
begin
s:=Copy(s,1,8);
_GotoLine(MakeLong(i,i),False);
bFound:=True;
Break;
end;
end
end
else begin
if iFrom=0 then iFrom:=1;
For i:=iFrom-1 downto 0 do
begin
s:=Items[i];
if not bMatchCase then s:=UpperCase(s);
if Pos(sSearch,s)<>0 then
begin
s:=Copy(s,1,8);
_GotoLine(MakeLong(i,i),False);
bFound:=True;
Break;
end;
end;
end;
Finally
Items.EndUpdate;
Screen.Cursor:=crDefault;
End;
if not bFound then ShowMessage('Search text not found');
End;
end;
procedure TASMShowForm._GotoLine(wLine: LongInt; bSaveJump: Boolean);
var idx,bk : Integer;
begin
idx:=ASMList.ItemIndex;
bk:=ASMList.TopIndex;
SendMessage(ASMShowForm.ASMList.Handle,
WM_VSCROLL,MakeLong(SB_THUMBPOSITION, wLine div MaxWord),0);
ASMList.ItemIndex:=(LoWord(wLine));
ASMList.Selected[LoWord(wLine)]:=True;
ASMList.Selected[idx]:=False;
if bSaveJump then sLastJumpRva:=MakeLong(idx,bk)
else sLastJumpRva:=0;
ASMListClick(self);
end;
procedure TASMShowForm.miPluginsClick(Sender: TObject);
begin
If MainUnit.DeDePlugins_Count=0 Then ShowMessage('Load plugins from Options|Configuration|Plugins first');
end;
Function _GetCallReference(dwVirtOffset : DWORD; var sReference : String; var btRefType : Byte; btMode : Byte = 0) : Boolean;
Begin
End;
Function _GetObjectName(dwVirtOffset : DWORD; var sObjName : String) : Boolean;
Begin
End;
Function _GetFieldReference(dwVirtOffset : DWORD; var sReference : String) : Boolean;
Begin
End;
procedure TASMShowForm.UpdatePlugInData;
var i : Integer;
inst : TMenuItem;
begin
For i:=miPlugins.Count-1 downto 0 do miPlugins.Delete(i);
For i:=1 To MainUnit.DeDePlugins_Count Do
Begin
inst:=TMenuItem.Create(miPlugIns);
inst.Caption:=MainUnit.DeDePlugins_PluginsArray[i].sPlugInName;
inst.OnClick:=PlugInClick;
miPlugins.Add(inst);
End;
end;
procedure TASMShowForm.PlugInClick(Sender: TObject);
var i, idx, int_idx : Integer;
_In : TListGenIN;
_Out: TListGenOUT;
dw : DWORD;
begin
idx:=miPlugIns.IndexOf((Sender as TMenuItem))+1; // It is 1-based
int_idx:=MainUnit.DeDePlugins_PluginsArray[idx].InternalIndex;
for i:=0 to ASMList.Items.Count do
begin
dw:=HEX2DWORD(ASMList.Items[i]);
if dw<>0 then break;
end;
_In.dwStartAddress:=dw;
_Out.Listing:=TStringList.Create;
Try
// Check for correct offsets
MainUnit.bPlugInsFixRelative:=
(MainUnit.DeDePlugins_PluginsArray[idx].PlugInType and ptFixRelativeOffsets)<>0;
MainUnit.DeDePlugins_PluginsArray[idx].StartPlugInProc(int_idx,_In,_Out);
if (MainUnit.DeDePlugins_PluginsArray[idx].PlugInType and ptOwnerShow)=0
Then Begin
ShowPlugInForm.Memo.Lines.Assign(_Out.Listing);
ShowPlugInForm.ShowModal;
End
Else; // The Plugin will show the result by itself
Finally
_Out.Listing.Free;
End;
end;
procedure TASMShowForm.ShowDSFPattern(rva : String);
var phPos : DWORD;
buff : TSymBuffer;
s : String;
i : Integer;
begin
phPos:=Hex2DWORD(rva)
-PEHeader.IMAGE_BASE
-PEHeader.Objects[1].RVA
+PEHeader.Objects[1].PHYSICAL_OFFSET;
With PEStream Do
Begin
BeginSearch;
Try
Seek(phPos,soFromBeginning);
ReadBuffer(buff[1],_PatternSize);
UnlinkCalls(buff,0,Hex2DWORD(rva));
s:='';
For i:=1 To _PatternSize Do s:=s+Byte2Hex(buff[i]);
InputBox(rva,'DSF_ID',s);
Finally
EndSearch;
End;
End;
end;
procedure TASMShowForm.ChangeFont1Click(Sender: TObject);
var s : String;
begin
If FontDlg.Execute then
begin
s:=FontDlg.Font.Name;
if (s='Webdings') or (s='Wingdings') or (s='Marlett')
then begin
ShowMessage('You crazy or what ??? :))');
Exit;
end;
if (s='Symbol')
then begin
ShowMessage('WOW! Man you defenitely roxx :))');
end;
if FontDlg.Font.Size>14
then begin
ShowMessage('You blind or what ??? :))');
Exit;
end;
ASMList.Font:=FontDlg.Font;
end;
end;
// [ LC ]
procedure TASMShowForm.ASMListKeyPress(Sender: TObject; var Key: Char);
begin
case Key of
';' : CommentBtnClick(self);
end; { case }
end;
procedure TASMShowForm.A1Click(Sender: TObject);
begin
ShowMessage('Not implemented yet!'); Exit;
Asm2PasForm.Show;
end;
procedure TASMShowForm.ASMListClick(Sender: TObject);
var i : Integer;
s : String;
dwRVA, dwPh : DWORD;
begin
i:=-1;
Repeat
Inc(i);
s:=ASMList.Items[ASMList.ItemIndex+i]+#32;
until (s[1] in ['0'..'9']) or (ASMList.ItemIndex+i>=ASMList.Items.Count-1);
if (s[1] in ['0'..'9']) then
begin
s:=Copy(s,1,8);
dwRVA:=HEX2DWORD(s);
if DeDeDisAsm.OffsetInSegment(dwRVA,'CODE')
then begin
i:=PEHeader.GetSectionIndexEx('CODE');
if i=255 then i:=1;
dwPh:= dwRVA-PEHeader.IMAGE_BASE-PEHeader.Objects[i].RVA+PEHeader.Objects[i].PHYSICAL_OFFSET;
s:=' Phys Offset: '+DWORD2HEX(dwPh);
end
else s:='';
SBar.Panels[1].Text:=s;
end
else SBar.Panels[1].Text:='';
end;
procedure TASMShowForm.EditASMComment(rva : Longint);
var j : longint;
prevComment : string;
begin
EditTextForm.Edit1.Clear;
if GetComment(RVA, j, prevComment) then begin
EditTextForm.Edit1.Text := prevComment;
end; { if }
EditTextForm.Show;
EditComment(RVA);
end;
procedure TASMShowForm.CommentBtnClick(Sender: TObject);
var i, RVA : Longint;
prevComment : String;
begin
i := AsmList.ItemIndex;
while i <= (AsmList.Count - 1) do begin
prevComment := AsmList.Items.Strings[i];
if Copy(prevComment, 9, 2) = ' ' then begin
RVA := HEX2DWORD(Copy(prevComment, 1, 8));
AsmList.ItemIndex := i;
break;
end else begin
inc(i);
end; { if }
end; { while }
// '0054E9F7 A164844000 mov eax, dword ptr [$408464]'
// '12345678901234567890123456789012345'
// ' 1 2 3 '
EditTextForm.Caption:=Copy(AsmList.Items.Strings[i],35,Length(AsmList.Items.Strings[i])-34);
EditASMComment(RVA);
end;
procedure TASMShowForm.LocRBClick(Sender: TObject);
var i : Integer;
s : String;
li : TListItem;
begin
if LocRB.Checked then
begin
VarLv.Clear;
for i:=0 to ExpressionCount-1 do
begin
if GetCurrFirstRVA<>DWORD2HEX(Expressions[i].RVA) then continue;
li:=VarLv.Items.Add;
li.Caption:=Expressions[i].Name;
li.SubItems.Add(Expressions[i].Comment);
li.Data:=Pointer(Expressions[i].RVA);
end;
end;
end;
procedure TASMShowForm.GlobRBClick(Sender: TObject);
var i : Integer;
s, sRVA : String;
li : TListItem;
begin
if GlobRB.Checked then
begin
VarLv.Clear;
for i:=0 to ExpressionCount-1 do
begin
if Expressions[i].RVA<>0 then Continue;
li:=VarLv.Items.Add;
li.Caption:=Expressions[i].Name;
li.SubItems.Add(Expressions[i].Comment);
li.Data:=nil;
end;
end;
end;
procedure TASMShowForm.VarLVDblClick(Sender: TObject);
begin
if VarLV.Selected=nil then exit;
EditExprForm.Caption:=VarLV.Selected.Caption;
EditExprForm.Edit1.Text:=VarLV.Selected.SubItems[0];
EditExprForm.ShowModal;
if EditExprForm.ModalResult<>mrCancel then
begin
VarLV.Selected.SubItems[0]:=EditExprForm.Edit1.Text;
EditExpression(Longint(VarLV.Selected.Data),VarLV.Selected.Caption,VarLV.Selected.SubItems[0]);
Disassemble1Click(Self);
end;
end;
procedure TASMShowForm.VarBtnClick(Sender: TObject);
begin
if VarsPanel.Width=0
then begin
VarsPanel.Width:=221;
Splitter2.Visible:=True;
VarBtn.Caption:='->';
VarBtn.Hint:='Hide Advanced Panel';
end
else begin
VarsPanel.Width:=0;
Splitter2.Visible:=False;
VarBtn.Caption:='<-';
VarBtn.Hint:='Show Advanced Panel';
end;
end;
procedure TASMShowForm.ASMListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Chr(Key) in ['f','F'])
then FindTxtBtnClick(Self);
end;
procedure TASMShowForm.SetEmulParams(sData: String);
var tmp : TStringList;
begin
tmp:=TStringList.Create;
try
tmp.CommaText:=sData;
eaxEdit.Text:=tmp.Values['EAX'];
edxEdit.Text:=tmp.Values['EDX'];
ecxEdit.Text:=tmp.Values['ECX'];
ebxEdit.Text:=tmp.Values['EBX'];
esiEdit.Text:=tmp.Values['ESI'];
ediEdit.Text:=tmp.Values['EDI'];
finally
tmp.free;
end;
end;
procedure TASMShowForm.eaxEditKeyPress(Sender: TObject; var Key: Char);
var i : Integer;
begin
i:=InitRegGrp.Tag;
if (i>=DASMInitEmulData.Count) or (i<0) then exit;
DASMInitEmulData[i]:=Format('EAX=%s,ECX=%s,EDX=%s,EBX=%s,ESI=%s,EDI=%s',
[eaxEdit.Text,ecxEdit.Text,edxEdit.Text,ebxEdit.Text,esiEdit.Text,ediEdit.Text]);
end;
procedure TASMShowForm.SaveBtnClick(Sender: TObject);
var DUF : TDufFile;
i : Integer;
begin
SaveDlg.InitialDir:=ExtractFileDir(Application.ExeName)+'\Projects';
If SaveDlg.Execute then
begin
DUF:=TDufFile.Create;
try
DUF.DUFVersion:=CURR_DUFF_VERSION;
DUF.ExpressionCount:=ExpressionCount;
SetLength(DUF.Expressions,ExpressionCount);
DUF.ExpressionCount:=0;
for i:=0 to ExpressionCount-1 do
if Expressions[i].Comment<>'' then
begin
DUF.Expressions[DUF.ExpressionCount]:=Expressions[i];
DUF.ExpressionCount:=DUF.ExpressionCount+1;
end;
DUF.CommentsCount:=CommentsCount;
SetLength(DUF.Comments,CommentsCount);
for i:=0 to CommentsCount-1 do DUF.Comments[i]:=Comments[i];
DUF.EmulationCount:=0;
DUF.SaveToFile(SaveDlg.FileName);
finally
DUF.Free;
end;
end;
end;
procedure TASMShowForm.LoadBtnClick(Sender: TObject);
var DUF : TDufFile;
i : Integer;
begin
OpenDlg.InitialDir:=ExtractFileDir(Application.ExeName)+'\Projects';
If OpenDlg.Execute then
begin
DUF:=TDufFile.Create;
Try
DUF.LoadFromFile(OpenDlg.FileName);
ExpressionCount:=DUF.ExpressionCount;
SetLength(Expressions,ExpressionCount);
for i:=0 to DUF.ExpressionCount-1 do Expressions[i]:=DUF.Expressions[i];
CommentsCount:=DUF.CommentsCount;
SetLength(Comments,DUF.CommentsCount);
for i:=0 to DUF.CommentsCount-1 do Comments[i]:=DUF.Comments[i];
EmulationCount:=DUF.EmulationCount;
SetLength(Emulations,DUF.EmulationCount);
for i:=0 to DUF.EmulationCount-1 do Emulations[i]:=DUF.Emulations[i];
Finally
DUF.Free;
End;
GlobRBClick(Self);
LocRBClick(Self);
Disassemble1Click(self);
end;
end;
initialization
LastColor:=clBlack;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -