Is there a way for a program to read it's own executable code?
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
Yes, probably, have you tried? What do you need it for? OS/Platform/Compiler?
I just wanted to know if it was possible.Originally Posted by anonytmouse
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
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.
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?
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