|
 |
|
 |
08-15-2006, 05:40 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Aug 2006
Posts: 5
|
Running Exe's
Alright, basically what I want to do is read an exe file as a binary file and execute each command as I read it. That is most likely impossible in pure c/c++ but if you have any help in assembler or c++ or anything, that would be fantastic. I'm trying to basically run an exe through my exe.
|
|
|
08-15-2006, 05:53 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
|
Why not use C, and call the apropriate exec*() function on your executable ?
What gain would you have, to read the file as binary, and execute each instruction as read ??
Unless you're trying to debug a program, so you want to make sure at all time to know where in the program you are...
But for that, theres already a number of excelent debuggers out there..
In order to read the executable, you need to know exactly where in the executable the compiler places the preloading header, how many bytes from that the first instruction is, and then read the file instruction-wise..
Sounds to me like an awful lot of trouble, just to run the damned program within your program.
|
|
|
08-15-2006, 01:04 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Aug 2006
Posts: 5
|
Ok, I see your point, so let me try something else, to read an exe and spit it out isn't the final purpose for this. I basically want a program that runs binary commands... I just figured that reading through an exe would be the easiest, kind of like an interpreter that doesn't interpret anything, just runs it... understand?
|
|
|
08-15-2006, 09:02 PM
|
#4 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
|
What do you mean ?? something like this:
Code:
#include <stdio.h>
#define SIZE 16
int main(int argc, char* argv[])
{
FILE *fp;
char buff[SIZE];
int i, n;
if(argc != 2)
{
printf("Usage: %s <filename>\n", argv[0]);
return -1;
}
if(!(fp=fopen(argv[1], "rb")))
{
printf("Error opening file: %s\n", argv[1]);
return -1;
}
while(n=fread(buff, 1, SIZE, fp))
{
for(i=0; i<n; ++i)
printf("%X ", buff[i]);
for(i=0; i<n; ++i)
printf("%c", buff[i]);
printf("\n");
}
fclose(fp);
return 0;
}
|
|
|
08-16-2006, 12:07 PM
|
#5 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
|
You basically have to build a virtual machine to run the instructions that you're reading.
__________________
Stop intellectual property from infringing on me
|
|
|
08-18-2006, 03:55 AM
|
#6 (permalink)
|
|
Registered User
Join Date: Aug 2006
Posts: 5
|
really... so I can't just almost inject the command into ram or something so it will be executed as if the OS loaded it there. By virtual machine you mean I have to code IF statements for every instruction and do them my self right...?
|
|
|
08-18-2006, 04:32 AM
|
#7 (permalink)
|
|
Anti-Zealot
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
|
Quote:
|
Originally Posted by psycotica
really... so I can't just almost inject the command into ram or something so it will be executed as if the OS loaded it there. By virtual machine you mean I have to code IF statements for every instruction and do them my self right...?
|
That's a dangerous area to be meddling in.
Yes, you CAN inject commands into RAM, but that's a technique generally used by worms or other nasty things. In other words, it's not a good way to build your app seeing as there's lots of tech out there to prevent such things.
__________________
If you always think like an expert, you'll always be a beginner. | "A handful of knowledgeable people is more effective than an army of fools" -Writing Secure Code, 2nd Ed.
|
|
|
08-19-2006, 05:07 AM
|
#8 (permalink)
|
|
Registered User
Join Date: Aug 2006
Posts: 5
|
I see, well I want the record to show I'm not making a worm, first off... but still... my plan is still to make an interpreter of sorts as mentioned above, does anyone have an idea of how to do that without having to pre-code every possibility rather than just have a translation table or something?
|
|
|
08-21-2006, 05:21 PM
|
#9 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
|
The reason you'd have to write code for each insruction is that exe files are nothing but assembly statements. You only have to write a translation table that takes care of each opcode, and some variables to represent the machine registers but for x86 that's fairly complicated.
What's your overall goal? Do you just want an "interpretted style" programming language, that compiles once? Are you writing some sort of debugger? Is it just a loader for something else?
__________________
Stop intellectual property from infringing on me
|
|
|
08-28-2006, 03:10 AM
|
#10 (permalink)
|
|
Registered User
Join Date: Aug 2006
Posts: 5
|
I know about exe's, I just figured that there was some command that could execute a given opcode, well, through some manipulation, like moving the opcode into the next read place in ram, for instance. My final goal in it's first stages is to make my own assembler, just as a test, to see how it would work before moving on. I hope that helped, but no, I am making a runtime interpreter, but since it's assembler it is just more of a word for word translater.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 06:55 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|