This is an old revision of the document!
Table of Contents
Development
This page lists some hints and tricks for setting up a development environment.
Editor
I suggest using Vim. It provides many features to edit text and syntax highlighting. On Debian-based systems, install vim-gnome
to get the graphical interface gvim
.
Default configuration
Vim stores its configuration in ~/.vimrc
. This file contains a list of commands. These commands are executed whenever vim starts. The following example enables syntax highlighting, sets tabs to four spaces width, and replaces all tabs by spaces. The autoindent
option causes Vim to start the next line with the same indentation the previous line had.
syn on set tabstop=4 set shiftwidth=4 set expandtab set autoindent
C/C++ Development
To get help on C functions like printf
, install manpages-dev
. Having it installed, one can issue man printf
on the console to get the function's description.
Make
To simplify building C (or other) projects, make can be used (or any derivative.) A simple make file would be:
program: gcc -o program -Wall -g -O1 program.c
Note that commands must start with a tab character.
Working with assembly
Example to disable a function call in a compiled application. Assume the binary is called prog
and inside there is a call to a function that needs to be disabled. The tools required are objdump
, a hex editor and diff
for correctness checking.
- Disassemble the whole program:
$ objdump -D prog > prog.s
- Find the function call assuming it is in
<main>
:less prog.s
and search for
main
:/main
Something like this should appear:
080489a4 <main>: 80489a4: 8d 4c 24 04 lea 0x4(%esp),%ecx 80489a8: 83 e4 f0 and $0xfffffff0,%esp 80489ab: ff 71 fc pushl -0x4(%ecx) 80489ae: 55 push %ebp 80489af: 89 e5 mov %esp,%ebp
- Now look for the instruction to be replaced. In our example, we want to get rid of some call. So we look for
8048a30: e8 40 0b 00 00 call 8049575 <some_function>
- Now the code that needs to be replaced is identified, it is the byte sequence
e8 40 0b 00 00
. Open a hex editor, and search for this sequence. It is not possible to map the addresses created byobjdump
to addresses in the binary file, that's why we just have to stick to do a plain search. Make sure that it is the right function call by checking that the surrounding bytes match the ones in theobjdump
output. - Now replace
e8 40 0b 00 00
by90 90 90 90 90
, the Intel command for NOP. - To test if the patch was successful, use
$ objdump -D prog > prog.s2 diff prog.s prog.s2
The output should be something like this:
< 8048a30: e8 40 0b 00 00 call 8049575 <some_function> --- > 8048a30: 90 nop > 8048a31: 90 nop > 8048a32: 90 nop > 8048a33: 90 nop > 8048a34: 90 nop
- Test your program and see if it behaves correctly. All other instructions can be changed using the same mechanism. Be careful not to change something to a wrong value, and always backup between patching. It is very easy to introduce errors that are later hard to correct.