Reading from exe directly on RAM

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading from exe directly on RAM

Marco Alvarado
Hello! I want to read data from my executable files. This data is
appended to the file, and would like to read it directly instead of
loading another copy of the file. I'm think on using a function like
this:

function  PeekExeByte(Byte2Get: Integer): byte;
Begin
  If Byte2Get < 1 then Exit;
  Result := byte(pointer(Hinstance+Byte2Get-1)^);
End;

Should work on Windows, but I'd like to know if you see any problems I
could have with other platforms?

Thanks in advance!
-Marco
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Reading from exe directly on RAM

Tomas Hajny
On Wed, April 16, 2008 17:41, Marco Alvarado wrote:

> Hello! I want to read data from my executable files. This data is
> appended to the file, and would like to read it directly instead of
> loading another copy of the file. I'm think on using a function like
> this:
>
> function  PeekExeByte(Byte2Get: Integer): byte;
> Begin
>   If Byte2Get < 1 then Exit;
>   Result := byte(pointer(Hinstance+Byte2Get-1)^);
> End;
>
> Should work on Windows, but I'd like to know if you see any problems I
> could have with other platforms?

If you really talk about just appending data at the end of the executable
file, I wouldn't expect this to work on any platform except the most
primitive ones (like .COM files at DOS times), because most operating
systems define structure of the executable file and only load into memory
the parts they really need. There are other ways for doing this like
directly embedding your data as constants in your program (using something
like data2inc), adding data as resources, using standalone data file
instead of misusing the EXE file, etc.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal