I am simply experimenting but have found a phenomena that I would be very appreciative if someone could try to explain.
I write a simple Hello World program in C. Use gcc
to compile this program into a hello
Unix Executable File, and can run it using ./hello
. Neat.
I open this hello
file, to see a series of 4 character segments (if someone wants to throw in a technical description for what I am seeing here also, I wouldn't complain.).
My question is, how come when I copy and paste all of these hexadecimal segments to a separate file, let's call test
, and use chmod +x test
, I do not get the same results running ./test
as I do running ./hello
?
Here is my C program:
#include <stdio.h>
int main(void)
{
int a;
a = 5;
printf("Memory address: %p\n", (void*) &a);
return 0;
}
then compiled to (first 20 lines only...)
cffa edfe 0700 0001 0300 0080 0200 0000
1000 0000 1005 0000 8500 2000 0000 0000
1900 0000 4800 0000 5f5f 5041 4745 5a45
524f 0000 0000 0000 0000 0000 0000 0000
0000 0000 0100 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 1900 0000 2802 0000
5f5f 5445 5854 0000 0000 0000 0000 0000
0000 0000 0100 0000 0010 0000 0000 0000
0000 0000 0000 0000 0010 0000 0000 0000
0700 0000 0500 0000 0600 0000 0000 0000
5f5f 7465 7874 0000 0000 0000 0000 0000
5f5f 5445 5854 0000 0000 0000 0000 0000
300f 0000 0100 0000 3800 0000 0000 0000
300f 0000 0400 0000 0000 0000 0000 0000
0004 0080 0000 0000 0000 0000 0000 0000
5f5f 7374 7562 7300 0000 0000 0000 0000
5f5f 5445 5854 0000 0000 0000 0000 0000
680f 0000 0100 0000 0600 0000 0000 0000
680f 0000 0100 0000 0000 0000 0000 0000
I copy this file exactly as is using a text editor.
Looking into it using diff
, I realize there is a binary difference?
running ./test
returns: (first 20 lines again)
./test: line 1: cffa: command not found
./test: line 2: 1000: command not found
./test: line 3: 1900: command not found
./test: line 4: 524f: command not found
./test: line 5: 0000: command not found
./test: line 6: 0000: command not found
./test: line 7: 0000: command not found
./test: line 8: 5f5f: command not found
./test: line 9: 0000: command not found
./test: line 10: 0000: command not found
./test: line 11: 0700: command not found
./test: line 12: 5f5f: command not found
./test: line 13: 5f5f: command not found
./test: line 14: 300f: command not found
./test: line 15: 300f: command not found
./test: line 16: 0004: command not found
./test: line 17: 5f5f: command not found
./test: line 18: 5f5f: command not found
./test: line 19: 680f: command not found
./test: line 20: 680f: command not found