The address of 'msg' string is encoded into the 'mov' instruction itself:
'\x20', '\x80', '\x04', '\x08' == 0x08048020
This is the exact address of the data segment for this program.
It is done for demonstration and simplification purposes.
Alternatively, it is possible to use a relocation entry and corresponding symbol definition.
An example of the alternative method can be found in 'write_obj' example directory.
Best regards,
Serge
Last edit: Serge Lamikhov-Center 2013-07-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi :)
I see the sample of ELF file creation, but, I did not understand how you get the offset of "Hello World!" string:
"'\xB9', '\x20', '\x80', '\x04', '\x08', // mov ecx, msg"
I have created a lib in C++, and, C# to create a MZ PE ( coff ), and, i solve this problem with something very intresting, look that sample:
"
...
mov(ebx, 0);
Address label2(0, Abs);
jmp(label2);
auto label1 = curtext->addr();
push(ebx);
push(pe.str("%d\n"));
call(ptr[pe.import("msvcrt.dll", "printf")]);
add(esp, 8);
curtext->put(label2);
inc(ebx);
cmp(ebx, 10);
jnz(label1);
push(0);
call(ptr[pe.import("msvcrt.dll", "exit")]);
jmp(curtext->addr());
...
"
See the code here :)
https://gist.github.com/bencz/4414040
Hi,
The address of 'msg' string is encoded into the 'mov' instruction itself:
'\x20', '\x80', '\x04', '\x08' == 0x08048020
This is the exact address of the data segment for this program.
It is done for demonstration and simplification purposes.
Alternatively, it is possible to use a relocation entry and corresponding symbol definition.
An example of the alternative method can be found in 'write_obj' example directory.
Best regards,
Serge
Last edit: Serge Lamikhov-Center 2013-07-21