Chapter 3 of “Malware Analysis Crash Course” (FLARE/Mandiant) covers basic flow control — how a program jumps from one place to another, and how a function call actually happens at the assembly level.
JMP
JMP target — an unconditional jump that directly overwrites EIP with the address target, equivalent to goto. No condition is checked at all, and it doesn’t save where it jumped from to return later (unlike CALL). The simplest infinite loop is essentially nothing more than: increment a register, then JMP back to that exact increment instruction.
Cross References (Xrefs) in IDA
An xref is a bidirectional link between where an address is referenced from and where it’s defined — IDA builds this entire table automatically while analyzing a binary. There are 2 types:
- Code xref — links between instructions, generated by
JMP/CALL/branches. In the UI, an upward arrow means it’s referenced from a lower address, a downward arrow means from a higher address. - Data xref — links data (strings, constants, variables) to the code that operates on it.
Commonly used actions: double-click an xref to jump straight to it, hover to preview without leaving your current position, and press X on an element to list every place that references it — the fastest way to answer “where is this function/variable used?”
CALL
CALL target combines 2 operations that happen together:
PUSHthe address of the instruction immediately afterCALL(the return address) onto the stackJMPtotarget
Functionally identical to: push <next instruction's address>; jmp target. If the function takes parameters, the caller must PUSH them onto the stack before CALL executes — so right after CALL runs, the top of the stack (top-down) is: the return address, then the parameters in the reverse order they were pushed (usually right-to-left).
RET
RET does the reverse: POPs the value off the top of the stack and jumps EIP there — since that value is exactly the return address that CALL pushed earlier.
An important detail that’s easy to miss: RET can take an optional operand — a byte count, e.g. ret 8. With this operand, after popping the return address, RET also adds that many bytes to ESP, effectively cleaning up the parameters on the stack itself. This mechanism is called callee cleanup (the called function cleans up after itself) — we’ll come back to this in more depth with the STDCALL calling convention (Chapter 4).
ret ; just pops the return address and jumps
ret 8 ; pops the return address, jumps, THEN adds 8 to ESP (cleaning up 2 4-byte parameters)This is also why a vulnerability like a stack buffer overflow is dangerous: if an attacker can overwrite the return address sitting on the stack before RET runs, they control where the program jumps to next.
The Full Lifecycle of a Function Call
- Prepare parameters — the caller
PUSHes parameters onto the stack (usually right-to-left) - Call the function —
CALLpushes the return address and jumps into the function - Function executes — the function body runs
- Return —
RETpops the return address and jumps back there - Clean up the stack — depending on the calling convention, either the caller or the callee is responsible for cleaning up the pushed parameters
Strings
Strings in a binary typically appear in 2 encodings:
- Narrow/ASCII — 1 byte per character, terminated by a single
0x00byte. For example"Hello"appears in hex as48 65 6C 6C 6Ffollowed by the terminating00byte. - Wide/Unicode (UTF-16LE) — 2 bytes per character (supports nearly every language), terminated by 2
0x00 0x00bytes. For example"Hel"in wide form is48 00 65 00 6C 00.
When a function needs to use a string, the program only passes the string’s starting address (not the content itself) — the function receiving that address reads sequentially from there until it hits the matching NUL byte(s). When IDA/Ghidra recognizes a string, it automatically assigns a label and displays it right in the code — this is one of the first “quick win” leads when opening a new sample: skim the strings list to guess at functionality before digging into individual functions.
Understanding CALL/RET is a required stepping stone for Chapter 4 — where I cover how a function organizes its own parameters and local variables on the stack (the stack frame).