j-h-k / mod-elf-symbol Goto Github PK
View Code? Open in Web Editor NEWreplace or modify symbol names in elf object files (relocatable and executable)
replace or modify symbol names in elf object files (relocatable and executable)
In src/mod-elf-symbol.c:294 there is a switch:
switch(ehdr->e_type) {
case ET_EXEC:
printf("WARNING: The ELf type is that of an executable. (%s)\n", objFileName);
break;
case ET_REL:
printf("SUCCESS: The ELF type is that of an relocatable. (%s)\n", objFileName);
break;
Does the ET_DYN case require a different approach? Or is it simply not possible to do it?
Hi,
Trying to run this on an Arm platform and it's not working. When I run it I get the following:
./mod-elf-symbol -o foo.o -c foo --completestr=asdf
+++++++++++++++++++++++++++++++++ Started replace-symbols-name Program
The object files to modify are:
(0) foo.o
Complete Symbols planned on changing:
(0) foo --> asdf
SUCCESS: The ELF type is that of an relocatable. (foo.o)
mod-elf-symbol: src/mod-elf-symbol.c:736: main: Assertion `findSymtabAndStrtabAndShdr(objList[i], ehdr, &shdr, &symtab, &strtab) != -1' failed.
Aborted
HI,
We're doing some cross-compiling to RISC-V and trying to use Mod-ELF-Symbol to change some of the symbols in the resulting ELF file. Unfortunately it is crashing at:
mod-elf-symbol: src/mod-elf-symbol.c:546: extendAndFixAfterStrtab: Assertion `end_of_sections <= ehdr->e_shoff' failed.
I compiled with debug = 1
and also added one more printf
to display the header shoff, ran it, and got:
./mod-elf-symbol -o /tmp/foo.o -c dsa_sub --completestr=asdfasdf
+++++++++++++++++++++++++++++++++ Started replace-symbols-name Program
The object files to modify are:
(0) /tmp/foo.o
Complete Symbols planned on changing:
(0) dsa_sub --> asdfasdf
SUCCESS: The ELF type is that of an relocatable. (foo.o)
symtab: size=3384 offset=0x17a4
strtab: size=4945 offset=0x3c0
0x40cd90 0x40cd10 Found Symbol table and String Table
symtab: size=3384 offset=0x17a4
strtab: size=4945 offset=0x3c0
In file foo.o symbols checked:
Complete Symbols
symbol: dsa_sub | sym->st_value: 0x14
ADD_SPACE is: 40
e_shoff:0x80
bns:0x1711 eos:0x1711
bns:0x1711 eos:0x1711 ptr:0x40ccd0
bns:0x1711 eos:0x1751 ptr:0x40cd10
bns:0x1711 eos:0x17a4 ptr:0x40cd50
bns:0x1711 eos:0x24dc ptr:0x40cd90
bns:0x1711 eos:0x38a8 ptr:0x40cdd0
bns:0x1711 eos:0x38b9 ptr:0x40ce10
bns:0x1711 eos:0x38bd ptr:0x40ce50
bns:0x1711 eos:0x38ef ptr:0x40ce90
bns:0x1711 eos:0x3b87 ptr:0x40ced0
bns:0x1711 eos:0x3b98 ptr:0x40cf10
bns:0x1711 eos:0x43ef ptr:0x40cf50
bns:0x1711 eos:0x84e7 ptr:0x40cf90
bns:0x1711 eos:0x84ff ptr:0x40cfd0
bns:0x1711 eos:0x867f ptr:0x40d010
bns:0x1711 eos:0x867f
mod-elf-symbol: src/mod-elf-symbol.c:546: extendAndFixAfterStrtab: Assertion `end_of_sections <= ehdr->e_shoff' failed.
For kicks I ran it under GDB
and after the assertion failure I printed out:
(gdb) p end_of_sections
$2 = 34431
(gdb) p *ehdr
$3 = {e_ident = "\177ELF\002\001\001\377\000\000\000\000\000\000\000",
e_type = 1, e_machine = 192, e_version = 1, e_entry = 0, e_phoff = 0,
e_shoff = 128, e_flags = 0, e_ehsize = 64, e_phentsize = 0, e_phnum = 0,
e_shentsize = 64, e_shnum = 14, e_shstrndx = 2}
So, not sure why the end_of_section is at 34K whereas the offset is only 128? In case it makes a difference:
od -t x1 foo.o | head
0000000 7f 45 4c 46 02 01 01 ff 00 00 00 00 00 00 00 00
0000020 01 00 c0 00 01 00 00 00 00 00 00 00 00 00 00 00
0000040 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
0000060 00 00 00 00 40 00 00 00 00 00 40 00 0e 00 02 00
0000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0000200 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00
0000220 00 00 00 00 00 00 00 00 c0 03 00 00 00 00 00 00
0000240 51 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000260 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
For what it's worth, the ELF header, when it is first read into the program in checkAndFindElfFile
, looks like:
$6 = {e_ident = "\177ELF\002\001\001\377\000\000\000\000\000\000\000",
e_type = 1, e_machine = 192, e_version = 1, e_entry = 0, e_phoff = 0,
e_shoff = 64, e_flags = 0, e_ehsize = 64, e_phentsize = 0, e_phnum = 0,
e_shentsize = 64, e_shnum = 14, e_shstrndx = 2}
The address should be changed to https://github.com/j-h-k/Mod-ELF-Symbol.git
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.