User Tools

Site Tools


info:development

This is an old revision of the document!


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.

  1. Disassemble the whole program:
    $ objdump -D prog > prog.s
  2. 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
  3. 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>
  4. 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 by objdump 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 the objdump output.
  5. Now replace e8 40 0b 00 00 by 90 90 90 90 90, the Intel command for NOP.
  6. 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
  7. 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.
info/development.1257977240.txt.gz · Last modified: 2009/11/11 23:07 by moritz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki