C-ASM
C-ASM
Platform: CUSTOM | Category: Reversing | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: algorithm_fingerprinting, control_flow_analysis, disassembly_pattern_matching
Summary
Walkthrough of the CUSTOM Reversing C-ASM. Task: given 5 C sources (c1..c5) and 5 x86-64 disassembly listings (asm1..asm5), pair each C file with the semantically equivalent ASM. Solution: recognize classic algorithm fingerprints in disassembl
Description
c_asm.zipcontains 5 C source files (c1.c..c5.c) and 5 x86-64 disassembly listings (asm1.s..asm5.s). Each C file is functionally identical to exactly one of the ASM listings. Match them. Answer format example:1-1, 2-2, 3-3, 4-4, 5-5(i.e.Ci-ASMjpairs). Submit via POSTflag.
A beginner reverse-engineering / source-matching task. The goal is to read each C source, identify the algorithm it implements, then find the disassembly listing that implements the same algorithm. The "flag" is the pairing string.
Analysis
C sources
| File | Algorithm | Key signature |
|---|---|---|
c1.c | Bubble sort of int a[10]={0..9} | nested loops + swap via temp; swaps when a[j] <= a[j+1] (descending) |
c2.c | minimum(a,b) | if (a<b) return a; else return b; |
c3.c | gcd_iter(u,v) | abs both, then while ((u%=v) && (v%=u)); return u+v (Euclid by modulo) |
c4.c | find_elem(array,size,elem) | linear search, returns index or -1 |
c5.c | is_even(num) | num%2 then switch: case 0 → 1, case 1 → 0 |
| |
ASM listings
Each listing was identified purely by its algorithmic fingerprint:
- asm1.s — initializes
VAR[0..9] = 0..9, nested loops overVAR_I/VAR_J, compares adjacent elements and swaps via a temp at[rbp-0x34]. Classic bubble sort → matches c1. - asm2.s —
function(rdi=ptr, esi=size, edx=elem); loopsi=0..size-1, loadsarray[i], compares toelem, returnsion match else returns0xffffffff(-1). Linear search → matches c4. - asm3.s —
function(edi, esi); a singlecmp edi,esi; jge ...selects and returns the smaller operand. minimum → matches c2. - asm4.s —
function(edi=VAR_1, esi=VAR_2);negon negative inputs (abs), then a loop usingidivto take remainders alternately intoVAR_1/VAR_2until zero, returningVAR_1+VAR_2. Euclid GCD → matches c3. - asm5.s —
function(edi); computesnum%2via the standard signed-modulo idiomshr edx,0x1f; add; and 0x1; sub edx, then tests:0→ return1,1→ return0. Parity check → matches c5.
Solution
Match each C algorithm to its ASM fingerprint:
| C file | Algorithm | ASM listing |
|---|---|---|
| c1 (bubble sort) | nested-loop swap | asm1 |
| c2 (minimum) | single branch selecting smaller | asm3 |
| c3 (gcd) | idiv remainder loop returning sum | asm4 |
| c4 (find_elem) | linear scan, 0xffffffff sentinel | asm2 |
| c5 (is_even) | % 2 + switch/branch | asm5 |
Resulting pairing string:
REDACTED
POST this as the flag parameter; the server accepts it.
Key Takeaways / Lessons
- Mastering algorithm_fingerprinting, control_flow_analysis, disassembly_pattern_matching was key to this challenge.
- Always check for common misconfigurations and verify assumptions.
Crafted by XESXOR Research • 2026-06-13 • CUSTOM • C-ASM • Difficulty: Easy