• Welcome to Valhalla Legends Archive.
 

Executing Data In Libraries

Started by FrostWraith, February 08, 2007, 04:03 PM

Previous topic - Next topic

FrostWraith

I was thinking about trying something new and wasn't sure if this is at all possible.  I was thinking about putting multiple executables in a single file and was wondering if it was possible to read the binary data of the file and execute it without having to extract it first.

Example:

compilation.bin contains 3 files:
prog1.exe ; prog2.exe ; prog3.exe

Say the length of the first file would be 20,000 bytes.  Could I do something along the lines of:
Execute (compilation.bin, 1, 20000)

This structure would be somewhat similar to blizzards mpq archive.

All help appreciated!

MyndFyre

This is very similar to this thread I posted some time ago.  It's probably not feasible for what you're hoping for.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Joe[x86]

Quote from: FrostWraith on February 08, 2007, 04:03 PM
I was thinking about trying something new and wasn't sure if this is at all possible.  I was thinking about putting multiple executables in a single file and was wondering if it was possible to read the binary data of the file and execute it without having to extract it first.

Example:

compilation.bin contains 3 files:
prog1.exe ; prog2.exe ; prog3.exe

Say the length of the first file would be 20,000 bytes.  Could I do something along the lines of:
Execute (compilation.bin, 1, 20000)

This structure would be somewhat similar to blizzards mpq archive.

All help appreciated!

I think with DLL's there is a away to map them to the program's memory and execute them, but for EXE's, I don't know.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

Now that I think about it, you might be able to load the entire EXE into a byte array and far jump to it's pointer, pretending it's a function (the program's main() should return a value upon close too, so it'd be a true int function), but your host program would wait for the loaded program to return before the method finishes causing it to freeze up. Also, I'm pretty sure most C++ compilers impose some sort of limit on how big of a byte array you can declare too (IE: Compiler rule of no arrays longer than a half MB or so), but that could easily be defeated by declaring enough arrays next to eachother in memory.

It'd be REALLY ugly, but I think it's possible.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joex86] link=topic=16275.msg164661#msg164661 date=1171319288]
Now that I think about it, you might be able to load the entire EXE into a byte array and far jump to it's pointer, pretending it's a function (the program's main() should return a value upon close too, so it'd be a true int function), but your host program would wait for the loaded program to return before the method finishes causing it to freeze up. Also, I'm pretty sure most C++ compilers impose some sort of limit on how big of a byte array you can declare too (IE: Compiler rule of no arrays longer than a half MB or so), but that could easily be defeated by declaring enough arrays next to eachother in memory.

It'd be REALLY ugly, but I think it's possible.

1.) You don't need to declare a byte array in C or C++.  You can simply malloc() it.
2.) When you read data like that you don't get to execute it directly.  You'd have to do change its execution permissions.
3.) When Windows loads binaries, it performs automatic relocation by remapping pointers according to the image's base address.  For instance, if a binary is compiled to execute at 0x400000, but it's loaded at virtual address 0x480000, Windows will automatically offset all pointers in the image to the base address.  There isn't really a public operating system API to do this.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

...and wouldn't you have to take care of dynamically linking everything as well?

MyndFyre

Quote from: Banana fanna fo fanna on February 13, 2007, 08:51 PM
...and wouldn't you have to take care of dynamically linking everything as well?

Oh yeah, there's that too.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Arta

I think you can do this. You just need to write your own loader. ImageHlp can do a lot of the heavy lifting for you (like making sure all the sections are mapped to the correct memory locations). I'm not sure if it will do linking for you. I don't know if it does base address relocation either, but it shouldn't be too hard: see the IMAGE_DIRECTORY_ENTRY_BASERELOC data directory.

In any event, it's completely possible -- but not trivial. Depending on how much of the work ImageHlp can do for you, it might be reasonably easy.

Skywing

I think that you are looking for CreateFileMapping(...SEC_IMAGE...) + MapViewOfFile(...) and not imagehlp.

Arta

Hmm, I was referring to MapAndLoad, but it's been a while since I looked at these things.