assembly - Faulty compilation of string constant in ASM -
i'm writing program hashes of function-names in asm.
the function fetch string constants following:
get_strings: call get_curr_addr pop esi add esi, 9 jmp str_return db "loadlibrarya" db 0x00
this produces following string constant in bytecode (xxd output):
... 00000040: 2424 61c3 e8bc ffff ff5e 83c6 09eb 7d4c $$a......^....}l 00000050: 6f61 644c 6962 7261 7279 4100 .... .... oadlibrarya.
ollydbg interprets as:
ascii "dlibrarya",0
when change code following:
get_strings: call get_curr_addr pop esi add esi, 9 jmp str_return db "jibberish" db 0x00 db "loadlibrarya" db 0x00
the compilation done "right" (the way expect be).
xxd output:
... 00000050: 0000 4a69 6262 6572 6973 6800 4c6f 6164 ..jibberish.load 00000060: 4c69 6272 6172 7941 00.. .... .... .... librarya.
and there's no
7dbyte anymore in front of loadlibrarya string literal.
ofcourse debugger sees strings should be
ascii "jibberish",0 ascii "loadlibrarya",0
is cygwin nasm compiler that's acting weird or growing mad?
as pointed out lurker , michael in comments:
there no problem apart fact debugger attempts interpret "loa" part of "loadlibrarya" actual instruction because i've put string literals in .text (code) section.
in second example, not reproduce "jib" in "jibberish" string, can't translated instruction.
issue resolved putting literals in .data section (where belong).
in code, snippet:
get_strings: call get_curr_addr pop esi add esi, 9 jmp str_return db "loadlibrarya" db 0x00
now becomes:
get_strings: call get_curr_addr pop esi add esi, 9 jmp str_return [section .data] db "loadlibrarya" db 0x00
Comments
Post a Comment