Menu

Create a ELF file with ELFIO

2013-05-25
2013-07-21
  • Alexandre Bencz

    Alexandre Bencz - 2013-05-25

    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

     
  • Serge Lamikhov-Center

    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

Anonymous
Anonymous

Add attachments
Cancel