Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a Executable offset -> Ascii 2

Status
Not open for further replies.

Ante0

Programmer
Apr 19, 2007
98
SE
How would you do to read some bytes at a offset then converting the information into Ascii.
I tried with this:
Code:
var 
fb: file of byte;
b: byte;
offset: string;
begin
fb := Edit1.text; //Path to exe.
offset := '$'+Edit2.text; //Offset
b:= $90; 
Seek(fb,Offset);
Read(b);
Edit3.text := b;
end;

but this doesn't work.
Any ideas?
I just need to get some ascii from inside a program, but the ascii only appears after you open the program.
 
try to do this with a TFileStream:

Code:
uses SysUtils,...
...
//!!! untested
function readExe(Filename : string; Offset, NumberofBytesToRead : integer) : string;

var FileStream : TFileStream;
    
begin
 FileStream := TFileStream.Create(filename, fmOpenRead or fmShareDenyNone); 
 try
  SetLength(Result, NumberofBytesToRead);
  // read our bytes
  FileStream.Read(Result[1], NumberOfBytesToRead); 
 finally
  FreeAndNil(FileStream);
 end;
end;

this function assumes you have 'readable' ascii in your exe file at the offset specified...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Hmm, it only seems to result = MZP.
No matter what Offset I set.
What does Result do in SetLength(Result, NumberofBytesToRead);?
 
whosrdaddy accidentally left out a bit. Replace the // read our bytes comment line with
Code:
FileStream.Pos := offset;
 
Thank you griffyn for the addition :)
It works great now! ;)
 
oops, my bad, thanks Griffyn

[thumbsup]

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top