Execute binary code in memory

HW Yang
1 min readJan 10, 2020

--

I have found the following code from here. However I do not know what the binary code in mya[] means. Lets see if the objdump and gdb can help me.

The following is the disassembly code of mya[] by using objdump -D ./a.out

The code mainly invokes the syscall sys_write by assigning %rax to 1, and its arguments %rdi with 1 means writing to stdout, %rdx means the length of “Hello, World!”, %rsi means the address of “Hello, World!”.

It is very clear that “Hello, World!“ is located from 0x60108d ~0x601098. But how to calculate the address of “Hello, World!”? We cannot hardcode this address because the address of mya[] is different every time we run the program.

The key seems to be in 0x601064. Let’s use gdb to find out the value of %rsi during the run-time.

It is very clear that the “e8 00 00 00 00 in 0x601064 can help me get the address of next instruction. Do some math and I can get the start address of “Hello, World!”.

--

--

HW Yang
HW Yang

No responses yet