extra Newbie cheater
Reputation: 0
Joined: 29 May 2011 Posts: 10
|
Posted: Wed Jun 08, 2011 12:28 pm Post subject: [delphi] how can i display binary location in exe ?? |
|
|
i mak an app to search a text in exe
it works fine
you type your string
press search
open dialog come up
select
then you have the correct address
my request to read another location realative to this location
say
this location + 20
for example the adress is 100
i want to display the address 110 in the edit 3 box
by the way
this new location contain normal characters in any hex editor
how can i apply that to that code
how can 1 display the new location contents in the "edit3" box as picture ??
| Code: | unit search;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ScanFile(const FileName: string;
const forString: string;
caseSensitive: Boolean): Longint;
const
BufferSize = $8001; { 32K+1 bytes }
var
pBuf, pEnd, pScan, pPos: PChar;
filesize: LongInt;
bytesRemaining: LongInt;
bytesToRead: Integer;
F: file;
SearchFor: PChar;
oldMode: Word;
begin
{ assume failure }
Result := -1;
if (Length(forString) = 0) or (Length(FileName) = 0) then Exit;
SearchFor := nil;
pBuf := nil;
{ open file as binary, 1 byte recordsize }
AssignFile(F, FileName);
oldMode := FileMode;
FileMode := 0; { read-only access }
Reset(F, 1);
FileMode := oldMode;
try { allocate memory for buffer and pchar search string }
SearchFor := StrAlloc(Length(forString) + 1);
StrPCopy(SearchFor, forString);
if not caseSensitive then { convert to upper case }
AnsiUpper(SearchFor);
GetMem(pBuf, BufferSize);
filesize := System.Filesize(F);
bytesRemaining := filesize;
pPos := nil;
while bytesRemaining > 0 do
begin
{ calc how many bytes to read this round }
if bytesRemaining >= BufferSize then
bytesToRead := Pred(BufferSize)
else
bytesToRead := bytesRemaining;
{ read a buffer full and zero-terminate the buffer }
BlockRead(F, pBuf^, bytesToRead, bytesToRead);
pEnd := @pBuf[bytesToRead];
pEnd^ := #0;
pScan := pBuf;
while pScan < pEnd do
begin
if not caseSensitive then { convert to upper case }
AnsiUpper(pScan);
pPos := StrPos(pScan, SearchFor); { search for substring }
if pPos <> nil then
begin { Found it! }
Result := FileSize - bytesRemaining +
Longint(pPos) - Longint(pBuf);
Break;
end;
pScan := StrEnd(pScan);
Inc(pScan);
end;
if pPos <> nil then Break;
bytesRemaining := bytesRemaining - bytesToRead;
if bytesRemaining > 0 then
begin
Seek(F, FilePos(F) - Length(forString));
bytesRemaining := bytesRemaining + Length(forString);
end;
end; { While }
finally
CloseFile(F);
if SearchFor <> nil then StrDispose(SearchFor);
if pBuf <> nil then FreeMem(pBuf, BufferSize);
end;
end; { ScanFile }
procedure TForm1.Button1Click(Sender: TObject);
var
openDialog : TOpenDialog;
Position: integer;
begin
openDialog := TOpenDialog.Create(self);
openDialog.InitialDir := 'c:\';
openDialog.Options := [ofFileMustExist];
openDialog.Filter :=
'EXE FILE|*.EXE|ANY FILE|*.*';
openDialog.FilterIndex := 2;
if openDialog.Execute
then ShowMessage(openDialog.FileName)
else ShowMessage('Open file was cancelled');
Position := ScanFile(openDialog.FileName, edit1.text, False);
edit2.Text:=(IntToStr(Position));
openDialog.Free;
end;
end. |
| Description: |
|
| Filesize: |
11.09 KB |
| Viewed: |
4515 Time(s) |

|
|
|