LOGBOOK

HELP

Quiz Entry - updated: 2026.07.06

How do you recognize sscanf input parsing in assembly?

Look for several lea offset(%rsp), %reg instructions (the output pointers), a format-string address in %esi, then call <sscanf> and a check on the return count.

sscanf call setup: %rdi input string, %esi format-string address, several lea offset(%rsp) output pointers writing to stack slots, then a cmp on the return count.

* Several lea offset(%rsp),%reg build output pointers, %esi holds the format string (read with x/s), then call and a cmp on %eax (items parsed). Slot offsets reveal each field's size. *

lea  0x8(%rsp), %r8
lea  0x7(%rsp), %rcx
lea  0xc(%rsp), %rdx
mov  $0x4024de, %esi
mov  %rbx, %rdi
mov  $0x0, %eax
call <sscanf>
cmp  $0x2, %eax
jg   ok_label

How to read it:

  1. %rdi = input string (1st argument)
  2. %esi = format string address (2nd argument) — examine with x/s
  3. %rdx, %rcx, %r8, ... = pointers to where parsed values are stored
  4. Return value in %eax = number of items successfully parsed
  5. The cmp after checks if enough items were parsed

Examine the format string:

(gdb) x/s 0x4024de
"%d %c %d"

Stack layout tip: The lea offsets tell you where each value lives on the stack and its size (1 byte for %c, 4 bytes for %d).

Go deeper:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 06, 2026