Very few people are really symbol manipulators. If they are they become professional mathematicians, not data processors. It’s much easier for most people to write an English statement than it is to use symbols. So I decided data processors ought to be able to write their programs in English, and the computers would translate them into machine code.
$gcc --save-temps -masm=intel example.c
#include
#include
#define BUFFSIZE 30
#define PASSWORD "EasyPassword"
void main(void){
char buffer[BUFFSIZE];
printf("Enter Password> ");
fgets(buffer, BUFFSIZE, stdin);
//Remove the Newlines
buffer[strcspn(buffer, "\r\n")] = 0;
printf("\nYou put %s\n", buffer);
if (strcmp(buffer, PASSWORD) == 0){
printf("Win!!\n");
}
else
printf("Lose\n");
}
.i file
printf("Hello World");
printf
(
and )
"Hello World"
;
x, y, printf
if, while
{, (, ;
+, -, *
true, 3.14, "hello"
https://keleshev.com/abstract-syntax-tree-an-example-in-c/
Convert intermediate to a executable
Intermediate full of References to functions
$ readelf -d Password DDynamic section at offset 0x2de0 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Labs/Asm$ ldd Password
linux-vdso.so.1 => linux-vdso.so.1 (0x00007fff5bff4000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007ffa1fcdd000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ffa1fefc000)
Examine PLT to get details of GOT entry
Ask GOT for address