unit DissectCodeunit; {$MODE Delphi} interface uses jwawindows, windows, LCLIntf, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls,DissectCodeThread,CEFuncProc, symbolhandler, LResources, frmReferencedStringsUnit, newkernelhandler, MemFuncs, commonTypeDefs; type TOnDoneDissect=(odDoNothing, odOpenReferedStringList, odOpenReferedFunctionsList); type { TfrmDissectCode } TfrmDissectCode = class(TForm) ProgressBar1: TProgressBar; Timer1: TTimer; Panel1: TPanel; lbModuleList: TListBox; Panel2: TPanel; Label2: TLabel; Label3: TLabel; Panel3: TPanel; Label6: TLabel; Label7: TLabel; btnStart: TButton; cbIncludesystemModules: TCheckBox; Label4: TLabel; lblStringRef: TLabel; Label5: TLabel; lblConditionalJumps: TLabel; Label9: TLabel; lblUnConditionalJumps: TLabel; Label11: TLabel; lblCalls: TLabel; Label1: TLabel; lblMaxOffset: TLabel; procedure btnStartClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure cbIncludesystemModulesClick(Sender: TObject); private { Private declarations } starttime: dword; procedure cleanModuleList; procedure fillModuleList(withSystemModules: boolean); public { Public declarations } ondone: TOnDoneDissect; end; var frmDissectCode: TfrmDissectCode; implementation uses frmReferencedFunctionsUnit; resourcestring rsStop = 'Stop'; rsStart = 'Start'; rsPleaseSelectSomethingToScan = 'Please select something to scan'; rsDone = 'done'; procedure TfrmDissectCode.btnStartClick(Sender: TObject); var start,stop:PtrUInt; tempregions: tmemoryregions; i,j: integer; temp: tmemoryregion; h,m,s,ms: word; n: integer; flipped: boolean; begin if btnStart.caption=rsStop then begin timer1.Enabled:=false; if dissectcode<>nil then begin dissectcode.cancelscan; dissectcode.clear; end; Timer1Timer(timer1); btnStart.Caption:=rsStart; //showmessage('dissected till address '+inttohex(dissectcode.currentaddress,8)); exit; end; if lbModuleList.SelCount=0 then raise exception.Create(rsPleaseSelectSomethingToScan); if dissectcode=nil then dissectcode:=TDissectCodeThread.create(false); dissectcode.clear; setlength(dissectcode.memoryregion,0); for i:=0 to lbModuleList.items.count-1 do begin if lbModuleList.Selected[i] then begin getexecutablememoryregionsfromregion(tmoduledata(lbModuleList.Items.Objects[i]).moduleaddress,tmoduledata(lbModuleList.Items.Objects[i]).moduleaddress+tmoduledata(lbModuleList.Items.Objects[i]).modulesize,tempregions); setlength(dissectcode.memoryregion,length(dissectcode.memoryregion)+length(tempregions)); for j:=0 to length(tempregions)-1 do dissectcode.memoryregion[length(dissectcode.memoryregion)-length(tempregions)+j]:=tempregions[j]; end; end; //sort the regions so they are from big to small (bubblesort) n:=length(dissectcode.memoryregion); for i:=0 to n-1 do begin flipped:=false; for j:=0 to n-2-i do begin if dissectcode.memoryregion[j+1].BaseAddress0 then begin lbModuleList.ItemIndex:=0; lbModuleList.Selected[0]:=true; end; end; procedure TfrmDissectCode.cbIncludesystemModulesClick(Sender: TObject); begin fillmodulelist(cbIncludesystemModules.checked); end; initialization {$i DissectCodeunit.lrs} end.