Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help understanding E8 asm call instruction x86

I need a helping hand in order to understand the following assembly instruction. It seems to me that I am calling a address at someUnknownValue += 20994A?

E8 32F6FFFF - call std::_Init_locks::operator=+20994A
like image 216
Michael Avatar asked Apr 29 '12 23:04

Michael


People also ask

What does the assembly instruction in line 8 do?

Line 8 is also fixed up so that, rather than adding one, it adds the global offset table (GOT) "relative to PC" address. So, after all that, eax contains the absolute address of the global offset table, so you can call whatever functions you want from there.

What is x86 assembly instructions?

The x86 instruction set refers to the set of instructions that x86-compatible microprocessors support. The instructions are usually part of an executable program, often stored as a computer file and executed on the processor.

What does x86 call do?

Call/return are used to transfer control between functions. The callq instruction takes one operand, the address of the function being called. It pushes the return address (current value of %rip , which is the next instruction after the call) onto the stack and then jumps to the address of the function being called.

What are the two main parts of an x86 instruction called?

Arithmetic and Logic Instructions. The add instruction adds together its two operands, storing the result in its first operand. Note, whereas both operands may be registers, at most one operand may be a memory location.


1 Answers

Whatever you're using to obtain the disassembly is trying to be helpful, by giving the target of the call as an offset from some symbol that it knows about -- but given that the offset is so large, it's probably confused.

The actual target of the call can be calculated as follows:

  • E8 is a call with a relative offset.
  • In a 32-bit code segment, the offset is specified as a signed 32-bit value.
  • This value is in little-endian byte order.
  • The offset is measured from the address of the following instruction.

e.g.

<some address>       E8 32 F6 FF FF         call <somewhere>
<some address>+5     (next instruction)
  • The offset is 0xFFFFF632.
  • Interpreted as a signed 32-bit value, this is -0x9CE.
  • The call instruction is at <some address> and is 5 bytes long; the next instruction is at <some address> + 5.
  • So the target address of the call is <some address> + 5 - 0x9CE.
like image 155
Matthew Slattery Avatar answered Oct 04 '22 12:10

Matthew Slattery