Thread: Load and run machine code at runtime

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    114

    Post Load and run machine code at runtime

    Problem:

    Load a file with compiled machine code and execute it at runtime. Not to run other EXEs or DLLs, but pure compiled machine code saved in files. To be used like this:

    Code:
    void *ptr = LoadMachineCode("fileofpuremachinecode.code");
    ExecuteCode(ptr);
    Also a good way of compiling C/C++ to files of machine code.

    I know of libs and such, but this is not a question about libs and dlls. But the question is how to load a file at runtime and execute its code. If there is a way...

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Neither of those function exist in VC++, sorry.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    That was such a dumb answer so I don't even know what to write here... Of course they don't exists. Read the question. It say: "To be used like this:". They are my functions to show you how I plan to use what I ask for.

    Don't answer if you don't know what you are talking about. And you obiously don't!

    BTW... VC++ stands for Visual C++ which is Microsofts C++ development tool, and not a programming language itself.

  4. #4
    Unregistered
    Guest
    wow ninebit...you are a true retard...thats rare man.

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> That was such a dumb answer so I don't even know what to write here...

    Didn't stop you trying though did it! Here for example...

    >>>
    Don't answer if you don't know what you are talking about. And you obiously don't!
    <<<

    Let's look at your "question".

    Code:
    void *ptr = LoadMachineCode("fileofpuremachinecode.code");
    ExecuteCode(ptr);
    One could easily be forgiven for thinking that you had been given this as a code sample and were asking why it didn't work. I was merely pointing out that in VC, (and get real, of course I know what VC is, I've been using it just about every day since version 1), and that you may need enquire which compiler/OS was required to get this to run.

    If you want help here, you might want to moderate that attitude, before I moderate it for you!!!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    What operating system and compiler do you need this to work on?
    What does the asm code do?
    will your process need to communicate and run concurrently with the asm process or just block waiting for the asm process to complete. If you want help please give some more information.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    >What operating system and compiler do you need this to work on?

    Windows 2000, MSVC.

    >What does the asm code do?

    Undefined. Lets start out simple and add from there.

    >will your process need to communicate and run concurrently with the asm process or just block waiting for the asm process to complete. If you want help please give some more information.

    The program will stop and wait for the asm process to complete.

    No params need to be sent to the process.

    A solution I'm thinking of is loading the file to memory and typecast the memptr to a function ptr, and call that function ptr...

    Why do I wan't to know this crazy stuff? No speciall reason, exept the joy of learning, and defeating though problems.


    Good thing there is at least one mentaly mature programmer on this board: Stoned_Coder.

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    goto msdn and look up CreateProcess().
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    Thanx mate!

    Will sertainly look into that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ text file
    By statquos in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2008, 01:42 PM
  2. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  3. Making standalone APP run in background
    By hart in forum Windows Programming
    Replies: 3
    Last Post: 02-27-2005, 11:20 AM
  4. Run machine-code in a non-executable
    By AeroHammer in forum C++ Programming
    Replies: 6
    Last Post: 09-03-2002, 08:30 PM
  5. bootable floppy
    By Robert_Ingleby in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 03-08-2002, 02:46 AM