So basically I am trying to re-use some assembly code/data dumped by objdump
from 32 bit ELF binary on Linux.
So basically, in the disassembled binary, I found some symbol referring to .bss
section like this:
80486b7: mov 0x804b264,%eax <- 0x804b264 is an addr in .bss
80486bc: movl $0x0,0x4(%esp)
80486c3:
80486c4: mov %eax,(%esp)
80486c7: call 804876c <sum>
By digging into the original source code, I find out that 0x804b264
is used for stdin
in .bss
section.
IMHO, there are basically two situations on .bss
section's data:
uninitialized data, will be uninitialized in the source code
some global/system related data (such as stdin in the above situation)
So when trying to re-use .bss
section's data, I have tried this way:
.section .bss
S_0x804B260 : .byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00
S_0x804B264 : .byte 0x00 <- I lift addr into symbol!
.byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00
and in the .text
section, I will also lift corresponding addr into symbol.
same situation works fine for .rodata
and .data
section
But the problem is that, there are some global variables (such as stdin stdout), locating in .bss
section, while are not initialized by user defined code, which means that in my re-used asm code, this symbol variable will always be zero!
I tried to manually substitute symbols corresponding to stdin, and it seems that it works fine.
But the problem is that:
How can I identify which symbol in the
.bss
section is some variables that initialized by system? such as stdin, stdout* and others?If it is not possible, then is there anyway that I can enforce system to use memory in the
.bss
section where I want it to use?
Am I clear? Could anyone give me some help?