unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Process;
type
TForm1 = class(TForm)
ButtonRunObjdump: TButton;
MemoOutput: TMemo;
procedure ButtonRunObjdumpClick(Sender: TObject);
private
procedure RunObjdump(const FilePath: string);
public
end;
TThread1 = class(TThread)
private
q: QWord;
protected
procedure Execute; override;
procedure Done;
public
command: string;
memo: string;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TThread1.Execute;
var
Output: string;
begin
q := GetTickCount64;
try
{$ifdef MSWINDOWS}
if RunCommand('cmd', ['/c '+command], Output, [], swoHIDE) then
{$else MSWINDOWS}
if RunCommand('/bin/bash', ['-c', Command], Output) then
{$endif}
memo := Output
else
memo := 'Error: Failed to run objdump.';
except
on E: Exception do memo := 'Exception: ' + E.Message;
end;
Synchronize(@Done);
end;
procedure TThread1.Done;
begin
Form1.MemoOutput.Lines.Text := memo;
Form1.Caption := 'Done in '+inttostr(GetTickCount64-q)+' ms.';
Form1.ButtonRunObjdump.Enabled := true;
end;
procedure TForm1.ButtonRunObjdumpClick(Sender: TObject);
var
FilePath: string;
begin
// Specify the binary file to analyze
{$ifdef MSWINDOWS}
FilePath := 'C:\Windows\System32\notepad.exe';
{$else MSWINDOWS}
FilePath := '/home/aruna/lazarus/memoryLayout/project1';
{$endif}
if FileExists(FilePath) then
RunObjdump(FilePath)
else
MemoOutput.Lines.Add('File not found: ' + FilePath);
end;
procedure TForm1.RunObjdump(const FilePath: string);
var
Command: string;
thr: TThread1;
begin
MemoOutput.Clear; // Clear previous output
//Command := 'objdump -T ' + FilePath; // Construct the objdump command
//Command := 'objdump -h ' + FilePath; // Construct the objdump command
//Command := 'file ' + FilePath; // Construct the objdump command
//Command := 'strings -d ' + FilePath; // Construct the objdump command
//Command := 'ldd ' + FilePath; // Construct the objdump command
//Command := 'readelf -d ' + FilePath; // Construct the objdump command
//Command := '' + FilePath; // Construct the objdump command
Command := 'objdump -d --section=.text "'+FilePath+'"';
ButtonRunObjdump.Enabled := false;
MemoOutput.Lines.Add('working...');
thr := TThread1.Create(true);
thr.FreeOnTerminate := true;
thr.command := Command;
thr.Resume;
end;
end.