Is there a way...

This is a discussion on Is there a way... within the C Programming forums, part of the General Programming Boards category; Is there a way for a program to read it's own executable code?...

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    Is there a way...

    Is there a way for a program to read it's own executable code?
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Yes, probably, have you tried? What do you need it for? OS/Platform/Compiler?

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    Quote Originally Posted by anonytmouse
    Yes, have you tried? What do you need it for?
    I just wanted to know if it was possible.

    Can you point me to a page that would have the list of functions I would need to use to try it out?

    OS: Windows (XP)
    Compiler: GCC
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Code:
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
      FILE *fp = fopen(argv[0], "rb");
    
      // Now you can use any of the FILE stream functions to read the executable.
    
      fclose(fp);
    
      return 0;
    }
    If you understand what you're doing, you're not learning anything.

  5. #5
    Jez
    Jez is offline
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    Hello again kinghajj, Yes you can read the executable, it's just a file like any other. (you could open a .exe file in notepad if you wanted to take a look)

    But to figure out what that data means would require a disassembler, which converts native machine code into assembly language. I suppose there might be something that would convert this back into some horrible machine generated C, but if there is, I don't know about it.

    P.S. - have you fixed the spelling mistake in your sig yet?

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    You don't need a dissassembler, if you know how the executable works, for instance the elf format in linux, or a.out, etc, then you can read information from it if you feel like it.
    If any information is needed on how these formats work, you can look here:
    http://www.nondot.org/sabre/os/artic...leFileFormats/
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21