sábado, 17 de julio de 2010

Depurar binarios con strace y ltrace

Como siempre cuando se programa es necesario tener diferente herramientas para depuracion como strace y ltrace.
strace permite interceptar y grabar las llamadas al sistema. Mas informacion consulte al manual "man strace"

ltrace permite interceptar y grabar las llamadas a las librerias dinamicas. Mas informacion consulte al manual "man ltrace"

Uso de strace:
strace -i -o binariofile.strace binariofile
Donde:
binariofile.strace: puede ser cualquier archivo donde se grabara la informacion que proporciona strace.
binariofile: Es cualquier binario que se quiere depurar
Salida que se muestra contiene:
[ffffe410] execve("./mc", ["./mc"], [/* 65 vars */]) = 0
[b7f8544b] brk(0) = 0x812a000
[b7f85db1] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[b7f85c74] open("/etc/ld.so.cache", O_RDONLY) = 3
[b7f85c3e] fstat64(3, {st_mode=S_IFREG|0644, st_size=102714, ...}) = 0
[b7f86273] mmap2(NULL, 102714, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f57000
[b7f85cad] close(3) = 0
[b7f85c74] open("/opt/gnome/lib/libgmodule-2.0.so.0", O_RDONLY) = 3
[b7f85cf4] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`\r\0\0004\0\0\0"..., 512) = 512
[b7f85c3e] fstat64(3, {st_mode=S_IFREG|0755, st_size=13928, ...}) = 0
[b7f86273] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f56000
[b7f86273] mmap2(NULL, 16664, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7f51000
[b7f85ef9] fadvise64(3, 0, 16664, POSIX_FADV_WILLNEED) = 0
[b7f86273] mmap2(0xb7f54000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2) = 0xb7f54000
[b7f85cad] close(3) = 0
[b7f85c74] open("/lib/libdl.so.2", O_RDONLY) = 3
[b7f85cf4] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240\n\0\0004\0\0\0"..., 512) = 512
[b7f85c3e] fstat64(3, {st_mode=S_IFREG|0755, st_size=10288, ...}) = 0
[b7f86273] mmap2(NULL, 12412, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7f4d000
[b7f85ef9] fadvise64(3, 0, 12412, POSIX_FADV_WILLNEED) = 0
[b7f86273] mmap2(0xb7f4f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xb7f4f000
[b7f85cad] close(3) = 0
...........................
.....................

Uso de ltrace:
ltrace -i -o binariofile.ltrace binariofile
Donde:
binariofile.ltrace: puede ser cualquier archivo donde se grabara la informacion que proporciona strace.
binariofile: Es cualquier binario que se quiere depurar
Salida que se muestra contiene:
[0x805cc21] __libc_start_main(0x8082670, 1, 0xbfe522f4, 0x80ee4f0, 0x80ee4e0
[0x808269e] getenv("LANG") = "POSIX"
[0x80826ac] strlen("POSIX") = 5
[0x8082969] strcasecmp("POSIX", "UTF-8") = -5
[0x80826c9] setlocale(6, "") = "LC_CTYPE=en_US.UTF-8;LC_NUMERIC="...
[0x80826dd] bindtextdomain("mc", "/usr/share/locale") = "/usr/share/locale"
[0x80826e9] textdomain("mc") = "mc"
[0x809b354] getenv("TMPDIR") = NULL
[0x809b369] getuid() = 0
[0x809b371] getpwuid(0, 0xbfe520dc, 0xbfe520ac, 130953, 55) = 0xb7d269b8
[0x809b39f] g_snprintf(0x81185a0, 64, 0x80f6906, 0x80f6901, 0x812b080) = 12
[0x809afe1] strlen("/tmp/mc-root") = 12
[0x809b032] strlen("/tmp/mc-root") = 12
[0x809b3c3] __lxstat64(3, "/tmp/mc-root", 0xbfe520b8) = 0
[0x809b5a0] getuid() = 0
[0x809b550] setenv("MC_TMPDIR", "/tmp/mc-root", 1) = 0
[0x80826fa] getenv("SHELL") = "/bin/bash"
..............
.............

No hay comentarios:

Publicar un comentario