Reverse Engineering x86 assembly
Intro
For those of you not familiar with the C toolchain, it goes something like this:
Source -> preprocessed source -> assembly -> object file -> binary
The second step (preprocessed -> assembly) is the hardest to undo. It removes labels, debug symbols, and turns a high-level control flow into assembly instructions. However, since you need a binary to run a program, if you can undo that step, you can see what's going on.
GDB Basics
GDB is a debugger. It steps through a compiled program, line by line, and shows you the changes after every step.
Let's take a simple hello-world program and step through it.
int
Passing -g
to gcc
means preserve debug symbols, so we know where we are in the original source code.
Passing -q
to gdb
means don't print 10 lines of copyright info.
Note that we have to add a breakpoint in the main function, or it will run without ever stopping.
()
{
) ;
);
}
()
()
)
;
)()
;
()
}
()
)
You can also show variables as you step through.
(Note that return 0
is optional in the main function)
int
()
()
)
;
()
()
;
()
()
;
)()
()
}
()
)
This post is continued in Buffer Overflows and Stacks and Assembly, Oh My.