Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-15-2006, 05:40 AM   #1 (permalink)
psycotica
Registered User
 
Join Date: Aug 2006
Posts: 5
psycotica is on a distinguished road
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.
psycotica is offline   Reply With Quote
Old 08-15-2006, 05:53 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-15-2006, 01:04 PM   #3 (permalink)
psycotica
Registered User
 
Join Date: Aug 2006
Posts: 5
psycotica is on a distinguished road
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?
psycotica is offline   Reply With Quote
Old 08-15-2006, 09:02 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
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;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-16-2006, 12:07 PM   #5 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
You basically have to build a virtual machine to run the instructions that you're reading.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 08-18-2006, 03:55 AM   #6 (permalink)
psycotica
Registered User
 
Join Date: Aug 2006
Posts: 5
psycotica is on a distinguished road
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...?
psycotica is offline   Reply With Quote
Old 08-18-2006, 04:32 AM   #7 (permalink)
AssKoala
Anti-Zealot
 
AssKoala's Avatar
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
AssKoala is on a distinguished road
Send a message via AIM to AssKoala Send a message via MSN to AssKoala Send a message via Yahoo to AssKoala
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.
AssKoala is offline   Reply With Quote
Old 08-19-2006, 05:07 AM   #8 (permalink)
psycotica
Registered User
 
Join Date: Aug 2006
Posts: 5
psycotica is on a distinguished road
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?
psycotica is offline   Reply With Quote
Old 08-21-2006, 05:21 PM   #9 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 08-28-2006, 03:10 AM   #10 (permalink)
psycotica
Registered User
 
Join Date: Aug 2006
Posts: 5
psycotica is on a distinguished road
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.
psycotica is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I know if a server (on the box) is running? jaro Platform/API C++ 4 04-28-2006 07:27 AM
running apache on a local network sde Linux / BSD / OS X 6 03-17-2006 07:54 AM
Running Applications inside Applications inplace Spiderman_gtp Platform/API C++ 4 07-28-2005 07:56 AM
running a script at designated time tzarin PHP 5 05-12-2004 07:11 PM
running PHP in a specific directory? Admin PHP 1 04-24-2003 06:27 PM


All times are GMT -8. The time now is 07:34 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting