flat assembler
Message board for the users of flat assembler.
Index
> Linux > Detecting program load address on Linux & Haiku x64 |
Author |
|
redsock 25 Dec 2021, 20:09
HeavyThing code:
Code: include '../ht_defaults.inc' include '../ht.inc' public _start falign _start: call ht$init mov edi, .codeseg call string$to_stdout mov edi, ht$codeseg mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .loadaddr call string$to_stdout mov edi, _start mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .dsaddr call string$to_stdout mov rdi, ht$dataseg mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov eax, syscall_exit xor edi, edi syscall cleartext .codeseg, 'code segment is at: 0x' cleartext .loadaddr, '_start is at: 0x' cleartext .dsaddr, 'data segment is at: 0x' include '../ht_data.inc' Code: # ./test code segment is at: 0x4000b0 _start is at: 0x401740 data segment is at: 0x4018e0 Code: # objdump -dx -M intel ./test |more ./test: file format elf64-x86-64 ./test architecture: i386:x86-64, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0000000000401740 Program Header: LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**21 filesz 0x00000000000018e0 memsz 0x00000000000018e0 flags r-x LOAD off 0x00000000000018e0 vaddr 0x00000000006018e0 paddr 0x00000000006018e0 align 2**21 filesz 0x0000000000000160 memsz 0x0000000000000160 flags rw- Sections: Idx Name Size VMA LMA File off Algn 0 .text 00001830 00000000004000b0 00000000004000b0 000000b0 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000160 00000000006018e0 00000000006018e0 000018e0 2**4 CONTENTS, ALLOC, LOAD, DATA Is this what you were after? |
|||
25 Dec 2021, 20:09 |
|
ProMiNick 25 Dec 2021, 20:56
Quote: data segment is at: 0x4018e0 Quote: # objdump -dx -M intel ./test |more redsock, why solutions are think different about data segment/section |
|||
25 Dec 2021, 20:56 |
|
redsock 25 Dec 2021, 21:09
ProMiNick wrote: redsock, why solutions are think different about data segment/section Code: ; ------------------------------------------------------------------------ ; ; ht_data.inc: globals macro to define a global writeable data segment ; ; to use: globals { ; someglobal dq 0 ; } ; anywhere throughout your code, and it will all end up inside our single datasegment ; ; this is meant to be included _last_ (and our marker here defines the end of ; the code section) ht$dataseg = $ section '.data' writeable align 16 ht$actual_dataseg = $ globalVars Code: include '../ht_defaults.inc' include '../ht.inc' globals { _dsaddr dq 0 } public _start falign _start: call ht$init mov edi, .codeseg call string$to_stdout mov edi, ht$codeseg mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .loadaddr call string$to_stdout mov edi, _start mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .dsaddr call string$to_stdout mov rdi, ht$dataseg mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .actualds call string$to_stdout mov rdi, ht$actual_dataseg mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov edi, .postht call string$to_stdout mov rdi, _dsaddr mov esi, 16 call string$from_unsigned push rax mov rdi, rax call string$to_stdoutln pop rdi call heap$free mov eax, syscall_exit xor edi, edi syscall cleartext .codeseg, 'code segment is at: 0x' cleartext .loadaddr, '_start is at: 0x' cleartext .dsaddr, 'end of code segment is at: 0x' cleartext .actualds, 'start of data segment is at: 0x' cleartext .postht, 'after HeavyThing globals, our dataseg is at: 0x' include '../ht_data.inc' Code: # ./test code segment is at: 0x4000b0 _start is at: 0x401740 end of code segment is at: 0x401ab4 start of data segment is at: 0x601ac0 after HeavyThing globals, our dataseg is at: 0x601c20 Code: # objdump -dx -M intel ./test |more ./test: file format elf64-x86-64 ./test architecture: i386:x86-64, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0000000000401740 Program Header: LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**21 filesz 0x0000000000001ab4 memsz 0x0000000000001ab4 flags r-x LOAD off 0x0000000000001ac0 vaddr 0x0000000000601ac0 paddr 0x0000000000601ac0 align 2**21 filesz 0x0000000000000168 memsz 0x0000000000000168 flags rw- Sections: Idx Name Size VMA LMA File off Algn 0 .text 00001a04 00000000004000b0 00000000004000b0 000000b0 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000168 0000000000601ac0 0000000000601ac0 00001ac0 2**4 CONTENTS, ALLOC, LOAD, DATA |
|||
25 Dec 2021, 21:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.