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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

embed C application in C code

Status
Not open for further replies.

peterve

IS-IT--Management
Mar 19, 2000
1,348
NL
Hi,

I know my question may sound a bit weird, but I have a very good reason for asking :

I have a small C application, compiled into an exe file
Now I want to run the C application from within another C application.
I know I can'launch' the exe file, but I want to 'embed' the exe file in my other C code; as some sort of variable
(e.g. by converting the first exe file to an array of characters, and then launching the array from within the second C application)

any ideas how I can do this ?

thanks

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
You can embed the .exe as a data array within another application, but you still need to copy it out to a temporary executable to be able to run it.



--
 
so there is no way to create assembly code or "shellcode" from the exe file, put it somewhere in memory, and change EIP so it runs that code ?
I don't want that exe file to be present on the system ever... I know it will be in memory at runtime, but I don't want it to be present on disk (other than part of the parent exe file)

thanks

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
Well exe files are not simply a memory image of the program as it would be loaded into memory.

There's a lot of relocation information in the header of a .exe file which needs to be interpreted and acted upon before the code can be run.

The program loader does an awful lot of work behind the scenes before running your .exe, most of which you would end up duplicating.

Do you have the source code for your small application?


--
 
source code :

First application says 'Hello world'
Second application has to say 'Hello world' by running the first exe

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
So why don't you just rename main() in your child program to say main2(), then simply call main2() from your main program at the point you want it to happen.

Where currently you do
[tt]cc hello.c
cc world.c[/tt]

To create two separate executables, by renaming a function you can do this
[tt]cc hello.c world.c[/tt]
to produce a single executable with both functions in it.

> so there is no way to create assembly code or "shellcode" from the exe file
"shellcode" is a term so often applied to the code those annoying malware writers employ to take over someones machine. I hope this isn't what you want this "trick" for.

--
 
About the shellcode : no... but i took the idea from malware writers because they use a technique to put executable code somewhere on the stack or in the heap and have it executed.

All of that happens from within a compiled executable, so compiling both c files into one big file is not an option.

Any other ideas ?

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
Why can't you write the embedded exe to a temporary file?
 
for security reasons
I want to encrypt the second exe and put it in a variable inside the first exe (or read the encrypted file)

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
nope...

--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
google "self extracting archive" and see if any support encryption.
But if you're trying to hide the code from the person running the code, then the key is going to be stored in clear text inside the bit of the code doing the decrypt.

Perhaps you need to state the real problem you're trying to solve.


--
 
true - you will only be able to see the unencrypted code in memory, at runtime... but that is ok
after all - there's no way to protect against that, isn't it?
Or maybe somebody has another solution to protect the code, even at runtime ?

THe real problem is that I want to protect a certain piece of code against 'easy' decompilation when somebody has obtained a copy of the executable.




--------------------------------------------------------------------
How can I believe in God when just last week I got my tongue caught in the roller of an electric typewriter?
---------------------------------------------------------------------
 
Don't tread on windmills. It's not so hard to catch (with debugger) your super-secret application at the moment when your super-secret code will be ready to execute in your super-secret variable...
 
How about a shrouder for the modules in question then.

Code riddled with lots of gotos at the asm level will be a lot harder to follow.

Plus you don't have to resort to the hackery of running a separate executable. Just shroud secret.c and compile with
[tt]cc clear.c shrouded_secret.c[/tt]


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top