This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BFD and global variables


Sorry for my last post.
I have figured it out now.

DUH!  The VMA of the .data section is not going to correspond to
anything in the binary, becuase the .data section doesn't really exist!

I have used the section->filepos to correct my offset calculation.

Brian

Brian Blietz wrote:

Is there anyway to change the .data section of a file
using BFD?

I have the following code that does not work:
file_buffer is an array filled with fread() of the file that the BFD corresponds to.


-----------------------------------------------------------------------------------------------

#define ELF_BASE_VMA 0x8048000
unsigned int *data_section_ptr;
int offset;

offset = symbol_table[i]->section->vma + symbol_table[i]->value
- ELF_BASE_VMA;
(unsigned int)data_section_ptr = (unsigned int)file_buffer + offset;
*data_section_ptr = some_value;
-----------------------------------------------------------------------------------------------



BUT, this code does work for changing the .text section:
it changes the value that a pushl instruction will use.
-----------------------------------------------------------------------------------------------


unsigned int *pushl_id_ptr;
int offset;

offset = symbol_table[i]->section->vma + symbol_table[i]->value
- ELF_BASE_VMA;
(unsigned int)pushl_id_ptr = (unsigned int)file_buffer + offset + 4;
*pushl_id_ptr = rand(); -----------------------------------------------------------------------------------------------



After I have updated file_buffer, I write it off to another file with fwrite().


For some reason, my pointer into the file array is pointing at
a bunch of 0's.  If I do objdump -s and look at the .data section,
there is plenty of (non-zero) data there.



Regards,
Brian


--
Brian Blietz
bblietz@iastate.edu

"There are 10 types of people in the world...
Those who understand binary, and those who don't."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]