Hosted by the courtesy of GitHub |
The stars ASAP
Durée du voyage intersidéral Résolutions de l'ONU en HTML Bussard Ramjet |
DWARF : dwarf2xml
ELF : libelf examples Code presentation : ctoohtml |
The first source example is a demo that copies an elf to an new one. The result it produce from a running executable is an non-running Elf executable.
elf_copy.c (source file) (build : gcc -o elf_copy -lelf elf_copy.c)The second also produce non-running Elf executable, but this time the result is more usefull. The only Elf type it accepts is relocatable object from which it produces a new Elf that can be used with a disassembler, like objdump. As a trivial link pass have been done on the result, objdump is fed with adresses synchronized with symbol table and can thus produce a far better output.
elf_obj_loc.c (souce file) (build : gcc -o elf_obj_loc -lelf elf_obj_loc.c)Example :
And have a look on objdump disassembly output :
shell$ > objdump -d sample.o
|
|
3: a1 00 00 00 00 mov 0x0,%eax
|
variable "who" |
8: 5d pop %ebp
|
|
d: a1 00 00 00 00 mov 0x0,%eax
|
variable "hello" |
12: 5d pop %ebp
|
|
26: e8 fc ff ff ff call 27 <main+0x13>
|
defined function (whois) |
2b: 89 c3 mov %eax,%ebx
|
|
2d: e8 fc ff ff ff call 2e <main+0x1a>
|
defined function (what) |
32: 89 5c 24 08 mov %ebx,0x8(%esp)
|
|
41: e8 fc ff ff ff call 42 <main+0x2e>
|
undefine function (printf) |
46: b8 00 00 00 00 mov $0x0,%eax
|
shell$ > ./elf_obj_loc sample.o sample.reloc
|
|
8048003: a1 5c 80 04 08 mov 0x804805c,%eax
|
variable who |
8048008: 5d pop %ebp
|
|
804800d: a1 58 80 04 08 mov 0x8048058,%eax
|
variable hello |
8048012: 5d pop %ebp
|
|
8048026: e8 d5 ff ff ff call 8048000 <whois>
|
defined function |
804802b: 89 c3 mov %eax,%ebx
|
|
804802d: e8 d8 ff ff ff call 804800a <what>
|
defined function |
8048032: 89 5c 24 08 mov %ebx,0x8(%esp)
|
|
804803a: c7 04 24 60 80 04 08 movl $0x8048060,(%esp)
|
|
8048041: e8 ca 7f 4b fa call 2500010 <printf>
|
undefined function |
8048046: b8 00 00 00 00 mov $0x0,%eax
|
Hosted by the courtesy of GitHub |
The stars ASAP
Durée du voyage intersidéral Résolutions de l'ONU en HTML Bussard Ramjet |
DWARF : dwarf2xml
ELF : libelf examples Code presentation : ctoohtml |