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.
* Several lea offset(%rsp),%reg build output pointers, %esi holds the format string (read with x/s), then call
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:
%rdi= input string (1st argument)%esi= format string address (2nd argument) — examine withx/s%rdx,%rcx,%r8, ... = pointers to where parsed values are stored- Return value in
%eax= number of items successfully parsed - The
cmpafter 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:
C stdio — scanf/sscanf family (Wikipedia) — Documents the sscanf format specifiers and the return value (count of items parsed) that the cmp checks.
Stack frame layout on x86-64 (Eli Bendersky) — Explains the argument registers (%rdi,%rsi,%rdx,%rcx,%r8) and stack-slot addressing behind the lea output pointers.