691 words
3 minutes
FLARE Learning Hub - Chapter 3: Basic Flow Control

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.

mandiant
/
flare-learning-hub
Waiting for api.github.com...
00K
0K
0K
Waiting...

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:

  1. PUSH the address of the instruction immediately after CALL (the return address) onto the stack
  2. JMP to target

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#

  1. Prepare parameters — the caller PUSHes parameters onto the stack (usually right-to-left)
  2. Call the function — CALL pushes the return address and jumps into the function
  3. Function executes — the function body runs
  4. Return — RET pops the return address and jumps back there
  5. 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 0x00 byte. For example "Hello" appears in hex as 48 65 6C 6C 6F followed by the terminating 00 byte.
  • Wide/Unicode (UTF-16LE) — 2 bytes per character (supports nearly every language), terminated by 2 0x00 0x00 bytes. For example "Hel" in wide form is 48 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).

FLARE Learning Hub - Chapter 3: Basic Flow Control
https://stewmalwarehunter.id.vn/posts/flare-macc-ch3---flow-control-en/
Author
Stew
Published at
2026-08-24
License
CC BY-NC-SA 4.0