@@ -61,13 +61,10 @@ pub const DT_STRTAB: u64 = 5;
6161pub const PT_DYNAMIC : u32 = 2 ;
6262pub const STT_FUNC : u8 = 2 ;
6363pub const STT_OBJECT : u8 = 1 ;
64- pub const ELF64_DYN_BASE : u64 = 0x555555554000 ;
65- pub const ELF64_STA_BASE : u64 = 0x400000 ;
66- pub const LIBC_BASE : u64 = 0x7ffff7da7000 ;
67- pub const LD_BASE : u64 = 0x7ffff7fd2000 ;
6864
6965#[ derive( Debug ) ]
7066pub struct Elf64 {
67+ pub base : u64 ,
7168 pub bin : Vec < u8 > ,
7269 pub elf_hdr : Elf64Ehdr ,
7370 pub elf_phdr : Vec < Elf64Phdr > ,
@@ -122,6 +119,7 @@ impl Elf64 {
122119 let dynstr: Vec < String > = Vec :: new ( ) ;
123120
124121 Ok ( Elf64 {
122+ base : 0 ,
125123 bin,
126124 elf_hdr : ehdr,
127125 elf_phdr : ephdr,
@@ -245,15 +243,15 @@ impl Elf64 {
245243 force_base : u64 ,
246244 ) {
247245
248- let mut elf64_base: u64 ;
249-
246+ let elf64_base: u64 ;
250247
251248 if dynamic_linking {
252- elf64_base = ELF64_DYN_BASE ;
249+ elf64_base = constants :: ELF64_DYN_BASE ;
253250 self . load_programs ( maps, name, is_lib, dynamic_linking) ;
254251 } else {
255- elf64_base = ELF64_STA_BASE ;
256- if force_base != constants:: CFG_DEFAULT_BASE {
252+ if force_base == constants:: CFG_DEFAULT_BASE {
253+ elf64_base = constants:: ELF64_STA_BASE ;
254+ } else {
257255 elf64_base = force_base;
258256 }
259257
@@ -264,6 +262,8 @@ impl Elf64 {
264262 hdr. write_bytes ( elf64_base, & self . bin [ ..512 ] ) ;
265263 }
266264
265+ self . base = elf64_base;
266+
267267 // pre-load .dynstr
268268 for shdr in & self . elf_shdr {
269269 let sname = self . get_section_name ( shdr. sh_name as usize ) ;
@@ -381,7 +381,7 @@ impl Elf64 {
381381 pub fn craft_got_sym ( & self , addr : u64 , got : & mut Mem64 , sym_name : & str ) {
382382 if let Some ( mut sym_addr) = self . sym_get_addr_from_name ( sym_name) {
383383 if sym_name. contains ( "libc" ) {
384- sym_addr += LIBC_BASE ;
384+ sym_addr += constants :: LIBC_BASE ;
385385 }
386386 log:: info!( "crafting got 0x{:x} <- 0x{:x} {}" , addr, sym_addr, sym_name) ;
387387 got. write_qword ( addr, sym_addr) ;
0 commit comments