Skip to content

RED HAT Linux & GCC – How to Compile a C program into Assembly code

28/02/2014

There is a correlation between C code and Assembly code, that shows what exactly is happening on the machine.  Assembly code is seriously enjoyable to read.

Step 1 – Create the C code.  (Pico/Gedit/Nano).

Create a program called main.c

main.c

Step 2 – Compile into an executable.

gcc main.c -o userid

./userid

main.c compiled

Step 3 – Compile into Assembly code

gcc -S main.c -o userassembly

main assembly

cat userassembly | more

assembly

more…

assembly more

****

nm to obtain Memory locations (nod to Xerocrypt)

nm userid | more

nm userid

Objdump -D userid  (nod to Xerocrypt)

objdump -D

Love those opcodes 🙂

opcodes

objdump -S userid | more

objdump -S

To display the Symbol table

objdump -t ./userid | more

objdump -t symbol table

Objdump Options – Happy reading 🙂

objdump options

*****

How to use objdump – Intel Syntax – The Visual Guide

https://uwnthesis.wordpress.com/2014/03/06/how-to-use-objdump-using-gcc-and-c-the-visual-guide/

Advertisements
3 Comments
  1. You know, if you run the compiled program through objdump (or was it nm?), you get the assembly aongside the opcodes for the program, which could then be used as a payload in an exploit.

    Like

Trackbacks & Pingbacks

  1. How to use Objdump – Intel Syntax – The Visual Guide | University of South Wales: Information Security and Privacy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: