Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Including .exes in C

Name: Anonymous 2009-09-04 11:19

So I'm writing a program on Windows where I'd like to include an exe to run. Source for the exe isn't available. Is there a good way of doing this?

What I have currently is this: convert the exe to a character array and write it to a temporary file for calling with system or spawn. But this seems like the wrong way to go about it. At the very least, the Google has suggested named pipes might be the way to go, but I've got no idea how to work with them.

Halp?

Name: Anonymous 2009-09-04 11:21

Try making sense first

Name: Anonymous 2009-09-04 11:22

Decompile and __asm()

Name: Anonymous 2009-09-04 11:25

system("something.exe");
like that? won't get you any output from the exe though.
in *nix it would be piss easy, just use a pipe. i don't know if windows supports that though

Name: Anonymous 2009-09-04 11:29

There's literally hundreds of ways to do this. Your way isn't wrong, but since we're talking Windows here, why don't you use what the OS provides: store the executable in an unformated resource, that way the resource compiler will include it when you compile your program, and it will be easy to build, and then create the process directly with CreateProcess, which would avoid pitfalls that can happen when using system(). The code won't be portable if written this way, but since you said clearly that it will run on Windows, I don't see why this would be a problem (if it is, just use what you're doing now). Is there an issue with dumping and running the executable?
It's possible to do it without writing the executable to a file, but that's an advanced low-level subject(knowledge of the PE file format, code transformation/loading may be required, good knowledge of kernel32 and windows internals preferred), and I'd rather not go into it without knowing more details about exactly what you want to do.

Name: Anonymous 2009-09-04 11:30

>>2
Alright, I'll try again.

I am writing a program.
There is another program someone else has written.
I would like to run that program from my program, but its source isn't available.

The way I'm doing it now is:
Convert their program to hex.
Load it into my program as a char array.
Write that to a file at runtime.
Execute that file using system or spawn.

I don't actually need the output of that program, just the return value, which both system and spawn will give me.



>>4
Yes, like that, only the program doesn't exist in a file before I run my program. And windows supports (named) pipes but I don't know how to use them or if they're at all what I want here.

Name: Anonymous 2009-09-04 11:34

>>6
CreateProcess and resources seems to be what you want. I'm a bit confused why can't you just distribute both executables with your program, but I'll leave that alone for now. Named pipes would be useful if you plan on redirecting input and output from his application.

Name: Anonymous 2009-09-04 11:35

>>5
>Is there an issue with dumping and running the executable?
Not really, it just seems inelegant and ideally it would work even if the user had no write permissions to anything.

>It's possible to do it without writing the executable to a file, but that's an advanced low-level subject
Damn. Thanks. It seemed like dumping it to a named pipe would be somewhat better than dumping to a file, but, as I say, I don't know how to work with those. If anyone can suggest something there or tell me why that's bad, that'd be great.

Name: Anonymous 2009-09-04 11:39

>>8
I've never seen anyone use named pipes to store a program and use it as a parameter to CreateProcess, and my old copy of MSDN doesn't seem to indicate this being possible at all, and if it were possible, it'd probably only work in very recent versions of NT OS(vista,win7?).

To quote:
lpApplicationName
Pointer to a null-terminated string that specifies the module to execute.
The string can specify the full path and filename of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification.

If you have any question about usage of some functions, just consult MSDN.

Name: Anonymous 2009-09-04 12:55

>>6
>>2 here, thanks for the explanation. I'd go with what everyone else is saying - store the executable in a resource and write it out to a file, then CreateProcess() it, or do >>4 and >>7's pipe business

Name: Anonymous 2009-09-05 16:21

>>1
So I'm writing a program on Windows
I stopped reading here

Name: EXPERT LINUX HACKERS 2009-09-05 17:29

http://www.linuxforums.org/forum/linux-programming-scripting/27562-keypress-c.html
^ Read this thread to achieve Satori.

if(getchar() == *shiftASCII*)
Frozen-Void QUALITY

Name: Anonymous 2009-09-05 21:22

Name: Anonymous 2009-09-05 21:51

>>12
ರ_ರ LINUX PROGRAMMER QUALITY

Name: Anonymous 2009-09-06 7:20

IHBT.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-09-06 13:02

>>12 I use while(x=getch()){switch(x){case...123}}


___________________________________________
http://bayimg.com/image/aadbjaace.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
My Blog: http://frozenvoid.blogspot.com/
«We are not human beings having a spiritual experience. We are spiritual beings having a human experience.»

Name: Anonymous 2011-02-04 18:26

<

Name: Anonymous 2011-02-04 19:22

Don't change these.
Name: Email:
Entire Thread Thread List