TL;DR: In Part 1 we compared STITCH with libFuzzer on three open-source libraries. We have since built a new version of STITCH that can fuzz closed-source libraries: it rebuilds a binary-only library as C and proves the rebuild behaves like the original, function by function. On Samsung’s JPEG decoder, the 282 rebuilt functions produce 4,059 of 4,059 outputs identical to the phone and reproduce CVE-2026-21096 on all 143 of 143 crashing inputs. On the latest versions of Samsung’s media libraries, the same method found four previously unknown vulnerabilities.
STITCH compiles its target with its own coverage and sanitizer instrumentation, so it cannot fuzz a library that exists only as a binary. Most of the parsing code on a phone is exactly that. This post takes one such library, Samsung's image codec libimagecodec.quram.so, and turns it back into C that STITCH can build. We show every command we ran, and we put the decompiler's output next to the code we ended up compiling, so you can judge how much of the work the decompiler does and where it fails.
Every number on this page comes from logs of the runs described here.
The technique we investigated
We call the technique rehosting: rebuild a binary library as C source that compiles for another machine, here x86-64 Linux with AddressSanitizer. A decompiler gets most of the way there. The hard part is knowing whether the result still behaves like the original, because decompiled code that compiles can be wrong in ways that look like bugs in the target. A rehosted library that crashes where the phone does not is worse than no library at all.
So the pipeline has two halves. The first half produces C: Ghidra decompiles, a generator makes the output buildable, and an LLM repairs what does not compile. The second half checks that C against the original binary and repairs it until the two agree:
- Per-function swap-in. Each rebuilt function is compiled for arm64 and patched into the original library, alone, with every other function still Samsung's code. The decoder then runs over a corpus and every output must be byte-identical.
- Instruction-level lifting. Where the decompiler and the LLM both fail (hand-written NEON, branch islands), each AArch64 instruction is translated to C that performs exactly that instruction.
- Whole-library differential. The finished rebuild runs alone on arm64 and on x86-64, and its outputs are compared with the original's.
- Crash ground truth. Inputs that crash the real phone must be reported by the rebuild, at the same root cause.
We added the pipeline to STITCH as a subcommand, stitch rehost. As in Part 1, the LLM runs only while the target is being prepared. Nothing in the fuzzing loop calls a model.
flowchart TD A["libimagecodec.quram.so
AArch64 binary, no source"] --> B["rehost decompile
Ghidra headless: libc prototypes,
parameter ID, call-graph export"] B --> C["rehost generate
one C file per function, data image,
relocation fixups, frame rebuild"] C --> D["rehost llm
repair, port, recover return values
until it compiles"] D --> V["rehost verify
swap each function alone into the
original on arm64: same output?"] V -->|"differs or crashes"| L["rehost improve
1. instruction-level lift (no LLM)
2. LLM repair with the evidence"] L -->|"try again"| V V -->|"all exact"| W["whole library, three ways
alone on arm64 · swapped into the
original · alone on Linux x86-64"] W --> G["ground truth
known crashes replayed on the
phone and on the rebuild (ASan)"] G --> P["rehost package
stitch test · infer · fuzz"] P --> R["confirm
every fuzzer finding replayed
on the Galaxy S25"]
Our experimental setup
| Item | What we used |
|---|---|
| Target | /system/lib64/libimagecodec.quram.so, SHA-256 083c240f…93ca. Stripped of debug info; exported symbols only. |
| Scope | The JPEG path behind the two calls the platform makes, QuramGetImageInfoFromBuffer and QuramDecodeBuffer: 282 functions, 474,684 bytes of machine code. BMP, PNG, GIF, WBMP, TIFF, DNG and ICC are left out. |
| Phone | Samsung Galaxy S25 (SM-S931B), build S931BXXSCCZH1, security patch 2026-08-05. Nothing on it was modified; test drivers live in /data/local/tmp. |
| Output reference | The same library file run on an arm64 Android emulator: 341 JPEGs × 3 colour formats × 4 scales = 4,059 output hashes. |
| Crash reference | 207 inputs for CVE-2026-21096, the heap overflow in this JPEG decoder that Samsung fixed in the September 2026 update. 185 are hand-crafted variants, 5 are fuzzer finds and reduced crashes from our earlier work on the original library, and 17 are control files. The phone is at the August patch level, so the bug is still present on it. |
| Tools | Ghidra (headless), Android NDK r29, Unicorn, clang-17 with ASan in the same Docker base image as Part 1, openai/gpt-5 through OpenRouter. |
Ground-truth rules
- A rebuilt function counts as exact only if the corpus actually called it and every output was byte-identical with it swapped into the original. A function the corpus never reaches is reported as not reached, never as passing.
- No LLM output is accepted because it compiles. It is accepted when the original binary agrees with it.
- The LLM is told not to fix bugs. Every bounds check, access width and loop bound has to match the machine code, because the bugs in the binary are what we want to find.
- A crash on the rebuild counts only after the same input is replayed on the phone.
- The fuzzers get synthetic seeds only. None of the 207 CVE-2026-21096 inputs is in a seed corpus.
The host is an Apple Silicon Mac, so the x86-64 fuzzing containers ran under emulation, as in Part 1. Absolute speeds are lower than on native Linux for both fuzzers.
Reproducing the technique
Each step below gives the command, then a terminal capture from our run. The stitch rehost stages are thin wrappers around scripts in the project's rec/ directory. Several captures were taken while those scripts were still being developed, so they show the script name the stage runs.
1. Install STITCH and the rehost tools
STITCH is set up as in Part 1. The rehost stages also need Ghidra, the Android NDK, adb and one arm64 Android device or emulator.
# Run from work/. Same checkout, patches and OpenRouter settings as Part 1.
./venv/bin/pip install ./src/STITCH/stitch
export OPENAI_API_KEY=$OPENROUTER_API_KEY OPENAI_BASE_URL=https://openrouter.ai/api/v1
./venv/bin/stitch rehost --help

2. Pull the library and pin the reference
The library comes straight from the phone. We record the build fingerprint and the hash, because every later claim is about this exact file.
# The phone is only read here. Nothing is written outside /data/local/tmp at any point.
adb -s RFCY81FTGYT shell getprop ro.build.fingerprint
adb -s RFCY81FTGYT shell sha256sum /system/lib64/libimagecodec.quram.so
adb -s RFCY81FTGYT pull /system/lib64/libimagecodec.quram.so quram/bin/
shasum -a 256 quram/bin/libimagecodec.quram.so # must print the same hash: 083c240f...93ca
3. Create the rehost project
--entries names the exported functions to rebuild; the project will contain everything reachable from them. --stop cuts the call graph at the other image formats. We recovered the two public prototypes from the platform's caller, SimbaDecoderJpeg::internalDecode.
# Run from work/. Creates quram/rehost.json and copies the kit into quram/rec/.
./venv/bin/stitch rehost init quram --lib quram/bin/libimagecodec.quram.so \
--entries QuramDecodeBuffer,QuramGetImageInfoFromBuffer,QURAMWINK_CreateDecInfo,QURAMWINK_Parser,QURAMWINK_PDecodeJPEG,QURAMWINK_DestroyDecInfo \
--stop QURAMWINKI_DecodeBMP,decodeQPNG,decodeTIFF,QURAMWINKI_DecodeGIF,QURAMWINKI_DecodeWBMP,TransformICC,QDngParseMetaData,QDngParseMetaDataBA,getTIFFImageInfo \
--device emulator-5554 -m openai/gpt-5
4. Decompile with Ghidra
This stage is fully automated. One command starts Ghidra in headless mode, with no GUI and no manual steps. It imports the library, gives the bionic imports real prototypes, analyses it, and decompiles everything reachable from the entry points, including functions that are only reached through pointer tables. The entry points come from the project file written by init, and the Ghidra scripts ship with STITCH.
# Run from work/. No LLM is used in this stage. Needs GHIDRA_HOME to point at a Ghidra install.
./venv/bin/stitch rehost decompile quram
You do not type anything else. For reference, this is the Ghidra invocation the command builds and runs for you:
$GHIDRA_HOME/support/analyzeHeadless quram/ghidra_proj rehost -import quram/bin/libimagecodec.quram.so -overwrite \
-scriptPath quram/ghidra_scripts \
-preScript ApplyLibcSigs.java -preScript EnableParamId.java \
-postScript ApplyLibcSigs.java -postScript ExportJpegPath.java quram/export5 <entry points>
| Ghidra script | What it automates |
|---|---|
ApplyLibcSigs.java | Applies real prototypes to the libc imports before and after analysis |
EnableParamId.java | Turns on Decompiler Parameter ID so argument counts are recovered |
ExportJpegPath.java | Walks the call graph from the entry points and writes one C file per function, plus the function list, call graph and externals |

The pre-script matters more than it looks. Our first exports had malloc typed as returning nothing, because Ghidra's C parser dropped the * of void *malloc(size_t). Every caller then lost the allocated pointer. 27 files had this pattern. It compiled, and crashed the first time a decoder was created.
Ghidra, malloc typed as void
gQURAMWINK_Error = 0;
QURAMWINK_OsMalloc(0x440); /* result dropped */
if (d == (undefined8 *)0x0) { /* d is never assigned */
Ghidra, prototype forced to a pointer
gQURAMWINK_Error = 0;
d = (undefined8 *)QURAMWINK_OsMalloc(0x440);
if (d == (undefined8 *)0x0) {
5. Generate a tree that builds
The generator writes one C file per function, with unprototyped declarations of its callees, so a call passes whatever the caller passes, as the machine code does. The original .data and .bss become one 3 MB blob. A constructor re-applies the library's relocations: pointers into data are rebased, pointers to code point at the recompiled function, and pointers to code outside the rebuilt path point at a trap that ends the run cleanly.
# Run from work/. No LLM is used in this stage.
./venv/bin/stitch rehost generate quram

This is the first place to compare code. WINKJ_GetHInfo is one of 200 functions that go from Ghidra to the compiler with only mechanical changes. Ghidra names stack slots after their offset and declares them as separate variables. The function passes &local_2d8 to a callee that fills a struct, so on another compiler those writes land on unrelated variables. The generator rebuilds the original frame as one block and turns each local into a view of it. The function body is untouched.
Ghidra output: locals of WINKJ_GetHInfo
int *local_2d8;
undefined4 local_2cc;
undefined *local_2c0;
undefined8 local_2b8;
undefined8 local_2b0;
undefined8 uStack_2a8;
undefined4 local_2a0;
undefined4 local_258;
int iStack_254;
undefined1 auStack_250 [256];
undefined1 auStack_150 [256];
undefined8 local_50;
long local_48;
Generated C: the same locals, original stack layout
/* stack frame rebuilt from Ghidra offsets (gen.py unify_frame) */
#define local_2d8 (*(int * *)(quram_frame + 0x8))
#define local_2cc (*(undefined4 *)(quram_frame + 0x14))
#define local_2c0 (*(undefined * *)(quram_frame + 0x20))
#define local_2b8 (*(undefined8 *)(quram_frame + 0x28))
#define local_2b0 (*(undefined8 *)(quram_frame + 0x30))
#define uStack_2a8 (*(undefined8 *)(quram_frame + 0x38))
#define local_2a0 (*(undefined4 *)(quram_frame + 0x40))
#define local_258 (*(undefined4 *)(quram_frame + 0x88))
#define iStack_254 (*(int *)(quram_frame + 0x8c))
#define auStack_250 ((undefined1 *)(quram_frame + 0x90))
#define auStack_150 ((undefined1 *)(quram_frame + 0x190))
#define local_50 (*(undefined8 *)(quram_frame + 0x290))
#define local_48 (*(long *)(quram_frame + 0x298))
...
unsigned char quram_frame[0x2e0] __attribute__((aligned(16))); /* original frame: sp-0x2e0..sp */
6. Let the LLM repair what does not compile
About 40 functions came out of Ghidra with NEON pseudo-calls, register artefacts or plain syntax errors. Each is sent to the model with Ghidra's output, the AArch64 disassembly and the compiler errors. A reply is accepted at this stage only if it compiles and passes a plausibility check against the disassembly (statement, store and call counts).
# Run from work/. Three modes: repair compile errors, port functions Ghidra could not express,
# and recover return values Ghidra typed as void.
./venv/bin/stitch rehost llm quram --mode repair
./venv/bin/stitch rehost llm quram --mode port --budget 11.5
./venv/bin/stitch rehost llm quram --mode retval
./venv/bin/stitch rehost generate quram # rebuild the tree with the accepted replies

51 model calls cost $8.63, measured per call from OpenRouter's usage field. The model failed on the largest function, the 8.7 KB JPEG marker parser; we fixed that one by hand.
The exported entry points. The two functions an application calls are small, and they show the most common decompiler error on AArch64. Here is the machine code of QuramGetImageInfoFromBuffer, Ghidra's output, and what we compile:
AArch64 machine code (llvm-objdump)
1a9900: paciasp
1a9904: stp x29, x30, [sp, #-0x40]!
1a9908: stp x28, x23, [sp, #0x10]
1a990c: stp x22, x21, [sp, #0x20]
1a9910: stp x20, x19, [sp, #0x30]
1a9914: mov x29, sp
1a9918: sub sp, sp, #0x250
1a991c: mrs x23, TPIDR_EL0
1a9920: add x1, x0, w1, sxtw
1a9924: mov x19, x4
1a9928: ldr x8, [x23, #0x28]
1a992c: mov x20, x3
1a9930: mov w0, #0x1 // =1
1a9934: mov w3, #0x7 // =7
1a9938: mov w4, wzr
1a993c: stur x8, [x29, #-0x8]
1a9940: bl 0x2d1c10 <QURAMWINK_CreateDecInfo@plt>
1a9944: cbz x0, 0x1a999c <QuramGetImageInfoFromBuffer+0x9c>
1a9948: mov x1, sp
1a994c: mov x22, x0
1a9950: bl 0x2d1c20 <QURAMWINK_Parser@plt>
1a9954: ldp w8, w9, [sp]
1a9958: mov w21, w0
1a995c: mov x0, x22
1a9960: str w8, [x20]
1a9964: str w9, [x19]
1a9968: bl 0x2d1c50 <QURAMWINK_DestroyDecInfo@plt>
1a996c: ldr x8, [x23, #0x28]
1a9970: ldur x9, [x29, #-0x8]
1a9974: cmp x8, x9
1a9978: b.ne 0x1a99d4 <QuramGetImageInfoFromBuffer+0xd4>
1a997c: mov w0, w21
1a9980: add sp, sp, #0x250
1a9984: ldp x20, x19, [sp, #0x30]
1a9988: ldp x22, x21, [sp, #0x20]
1a998c: ldp x28, x23, [sp, #0x10]
1a9990: ldp x29, x30, [sp], #0x40
1a9994: autiasp
1a9998: ret
Ghidra output
int QuramGetImageInfoFromBuffer
(undefined1 param_1 [16],double param_2,long param_3,int param_4,undefined8 param_5,
uint *param_6,undefined4 *param_7,undefined *param_8,undefined *param_9,
undefined *param_10)
{
long lVar1;
int iVar2;
long *plVar3;
undefined8 uVar4;
undefined *puVar5;
undefined1 extraout_q0 [16];
uint local_290;
undefined4 uStack_28c;
long local_48;
lVar1 = tpidr_el0;
local_48 = *(long *)(lVar1 + 0x28);
uVar4 = 7;
puVar5 = (undefined *)0x0;
plVar3 = QURAMWINK_CreateDecInfo(1,(char *)(param_3 + param_4),(uint)param_5,7,0);
if (plVar3 == (long *)0x0) {
__android_log_print(4,"QURAM_STAT","[%s:%d]\n");
iVar2 = 0;
if (*(long *)(lVar1 + 0x28) != local_48) goto LAB_002a99d4;
}
else {
iVar2 = QURAMWINK_Parser(extraout_q0,param_2,plVar3,&local_290,param_5,uVar4,puVar5,param_8,
param_9,param_10);
*param_6 = local_290;
*param_7 = uStack_28c;
QURAMWINK_DestroyDecInfo(plVar3);
if (*(long *)(lVar1 + 0x28) != local_48) {
LAB_002a99d4:
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
}
return iVar2;
}
Rebuilt C (rec/override/QuramGetImageInfoFromBuffer.c)
/* rehost manual: Ghidra output from before Decompiler Parameter ID (which mistyped the
arguments as q0/d0), with the prototype the platform uses (see harness/harness.c).
QURAMWINK_Parser fills a 0x248-byte info block on the stack; width/height are its first two words. */
int QuramGetImageInfoFromBuffer(const unsigned char *param_1, int param_2, int param_3,
int *param_4, int *param_5)
{
long lVar3;
int uVar2;
uint32_t info[0x248 / 4];
lVar3 = (long)QURAMWINK_CreateDecInfo(1, param_1 + param_2, param_3, 7, 0);
if (lVar3 == 0) {
__android_log_print(4, "QURAM_STAT", "[%s:%d]\n", "QuramGetImageInfoFromBuffer", 0x5a);
return 0;
}
uVar2 = (int)QURAMWINK_Parser(lVar3, info);
*param_4 = (int)info[0];
*param_5 = (int)info[1];
QURAMWINK_DestroyDecInfo(lVar3);
return uVar2;
}
What changed, and why
- Ghidra gives the function ten parameters. The first two are the SIMD registers
v0andd1, which the machine code never reads. On x86-64 they would shift every real argument by one slot. The rebuilt prototype has the five the code uses:x0tox4. - Ghidra passes ten arguments to
QURAMWINK_Parser. The machine code passes two: the decoder (x22) and the stack block (sp). - Ghidra saw two 4-byte locals. The machine code reserves 0x250 bytes and the parser fills a 0x248-byte block, so the rebuild declares the whole block.
- The log call lost its last two arguments (
x3,w4). - The stack-protector check is dropped; the host compiler adds its own.
QuramDecodeBuffer has the same problem. Ghidra's version returns a 16-byte vector pointer and takes ten parameters; the real function returns an int and takes five. The body is otherwise the decompiler's:
Ghidra output
undefined1 (*) [16]
QuramDecodeBuffer(undefined1 param_1 [16],double param_2,char *param_3,undefined1 (*param_4) [16],
undefined8 param_5,ulong param_6,uint param_7,undefined *param_8,undefined *param_9
,undefined *param_10)
{
...
pbVar6 = (byte *)QURAMWINK_CreateDecInfo(1,param_3,uVar5,uVar8,0);
if (pbVar6 != (byte *)0x0) {
iVar4 = QURAMWINK_Parser(extraout_q0,param_2,(long *)pbVar6,&local_2b0,param_5,param_6,puVar9,
param_8,param_9,param_10);
uVar1 = 0;
if (param_7 != 0) {
uVar1 = local_2b0 / param_7;
}
uVar2 = 0;
if (param_7 != 0) {
uVar2 = uStack_2ac / param_7;
Rebuilt C
int QuramDecodeBuffer(const unsigned char *param_1_, void *param_2_, int param_3_, int param_4_, int param_5)
{
...
uint info_2b0[0x248 / 4]; /* QURAMWINK_Parser output block (stack 0x2b0..0x68) */
#define local_2b0 info_2b0[0]
#define uStack_2ac info_2b0[1]
...
lVar6 = QURAMWINK_CreateDecInfo(1,param_1,param_3,param_4,0);
if (lVar6 != 0) {
iVar5 = QURAMWINK_Parser(lVar6,info_2b0);
uVar2 = 0;
if (param_5 != 0) {
uVar2 = local_2b0 / param_5;
}
uVar3 = 0;
if (param_5 != 0) {
uVar3 = uStack_2ac / param_5;
}
7. Record what the original does
A small driver decodes every corpus file in three colour formats at four scales and prints one hash per output. Run against the original library on arm64 Android, that list is the reference for everything that follows.
# Run from work/quram. Pushes the driver and corpus to /data/local/tmp/q and pulls the hashes back.
zsh rec/fidelity_android.sh # the original library -> fidelity/android.txt
zsh rec/fidelity_header.sh # first check: header parsing only, rebuild vs original

8. Verify every function inside the original binary
Comparing the whole rebuild with the original tells you that something differs, not where. With 282 functions that is not enough. The library's internal calls go through the PLT, and the remaining direct calls can be redirected by patching a function's first instructions. That lets us run one rebuilt function inside Samsung's binary with everything else original.
flowchart TD D["differential driver"] --> O["original library
libimagecodec.quram.so on arm64"] O -->|"call to F"| P["F's entry patched
ldr x16, #8 ; br x16"] P --> R["rebuilt F
compiled for arm64, using the
original's live .data / .bss"] R -->|"callees via dispatch slots"| O D --> H["one hash per output
(file, format, scale)"] H --> C["identical to the
pure original?"]
# Run from work/. Screens every rebuilt function, alone, over the whole corpus.
./venv/bin/stitch rehost verify quram
# One function by hand, on the device (emulator-5554):
QSWAP=QURAMWINK_DecodeJPEG LD_PRELOAD=libqhybrid.so qdiff_android src_127x255_s1x1_q50.jpg
# Symbolize the crash frames it prints against the original library:
llvm-symbolizer --obj=bin/libimagecodec.quram.so 0x148f04 0x148a50 0x199320 0x129680 0x132fa4

The capture shows the first failure the screen found. With only QURAMWINK_DecodeJPEG swapped in, the original library crashed in WINKJ_FastYcbcrWriteOutput. The function builds a 24-byte output descriptor on the stack and passes its address. The decompiler had split it into an 8-byte array and three unrelated locals, so the callee read the output buffer, width and height from stack garbage:
Decompiled (compiles, crashes)
uint auStack_2f8[2]; /* 8 bytes */
void *local_2f0 = param2_save; /* never seen by the callee */
uint local_2e8 = saved_w;
uint uStack_2e4 = saved_h;
QURAMWINK_OsMemset(auStack_2f8, 0, 0x18);
After the verify-gated fix (exact)
unsigned char auStack_2f8[0x18]; /* the struct the machine code builds */
QURAMWINK_OsMemset(auStack_2f8, 0, 0x18);
*(void **)(auStack_2f8 + 8) = param2_save;
*(uint *)(auStack_2f8 + 16) = saved_w;
*(uint *)(auStack_2f8 + 20) = saved_h;
| Screen | Exact | Differs | Crash / hang | Fragment | Not reached |
|---|
Fragment marks two Ghidra "functions" that are really a branch island and its continuation inside QURAMWINK_PDecodeJPEG_No_RST. Nothing calls them, so they are verified as part of their parent. Not reached means the corpus never calls the function: mostly CMYK and grey writers, resize variants for output formats the platform does not use, error paths, and the restart-marker decoder.
9. Repair until the original agrees
For every function the screen flags, improve tries an instruction-level lift first, then up to four LLM repairs. The model gets the current C, Ghidra's output, the disassembly and the evidence: the differing rows and first differing bytes, or the symbolized crash frames. A candidate is kept only if it is exact in the swap-in screen. Otherwise the previous version is restored and the attempt is logged.
# Run from work/. Stops when the budget (USD) is spent.
./venv/bin/stitch rehost improve quram --budget 60
# Lift one function and check it against the original machine code in Unicorn:
./venv/bin/stitch rehost lift quram FUN_0034db60 --check

Where the decompiler and the LLM both fail. FUN_0034db60 is a hand-written NEON inverse-DCT kernel of 117 instructions, called 466,101 times on the corpus. Ghidra flags bad instruction data and expresses the vector code as byte concatenations. The LLM read that and wrote a clean scalar routine. It failed four attempts in a row with the same 714 differing outputs. The lifter does not interpret anything: each instruction becomes one C statement on a modelled register file, with the instruction kept as a comment.
AArch64 machine code
24dba0: mul v4.4h, v4.4h, v8.4h
24dba4: mul v5.4h, v5.4h, v9.4h
24dba8: mul v6.4h, v6.4h, v10.4h
24dbac: mul v7.4h, v7.4h, v11.4h
24dbb0: add v10.8h, v4.8h, v6.8h
24dbb4: sshll v10.4s, v10.4h, #0x2
24dbb8: sub v11.8h, v4.8h, v6.8h
24dbbc: sshll v8.4s, v11.4h, #0x2
24dbc0: add v9.8h, v5.8h, v7.8h
24dbc4: smull v9.4s, v9.4h, v0.h[0]
Ghidra output (excerpt)
void FUN_0034db60(undefined4 *param_1,short *param_2,long *param_3,long param_4)
...
sVar6 = CONCAT11((char)(iVar41 >> 0x1a),(char)(iVar41 >> 0x12));
sVar8 = CONCAT11((char)(iVar43 >> 0x1a),(char)(iVar43 >> 0x12));
sVar27 = CONCAT11((char)(iVar44 >> 0x1a),(char)(short)(iVar44 >> 0x12));
sVar28 = CONCAT11((char)(iVar40 >> 0x1a),(char)(short)(iVar40 >> 0x12));
uVar10 = CONCAT12((char)(iVar46 >> 0x12),sVar8);
...
auVar5._14_2_ = (short)(CONCAT17(cVar26,CONCAT16(uVar25,uVar12)) >> 0x30) + 0x80;
uVar7 = NEON_sqxtun(CONCAT17(uVar21,CONCAT16(uVar20,CONCAT15(uVar19,CONCAT14(uVar18,CONCAT13(
uVar17,CONCAT12(uVar16,sVar9)))))),auVar5,2);
LLM rewrite (rejected: 714 outputs differ)
/* rehost verify-fix: LLM-corrected against swap-in evidence (rec/verify_fix.jsonl) */
void FUN_0034db60(short *param_1, short *param_2, long *param_3, long param_4)
{
// Load constants v0.h[0..3], v1.h[0..3] from image at 0x24db50
const int16_t *kptr = (const int16_t *)QADDR(0x24db50);
int16_t v0_0 = kptr[0];
int16_t v0_1 = kptr[1];
int16_t v0_2 = kptr[2];
int16_t v0_3 = kptr[3];
int16_t v1_0 = kptr[4];
Instruction-level lift (exact)
/* rehost lift: instruction-level C translation of the AArch64 code (117 instructions, rec/lift_neon.py) */
...
/* 24dba0: mul v4.4h, v4.4h, v8.4h */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.h[i] = (uint16_t)((uint64_t)v[4].h[i] * v[8].h[i]); v[4] = r_; }
/* 24dba4: mul v5.4h, v5.4h, v9.4h */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.h[i] = (uint16_t)((uint64_t)v[5].h[i] * v[9].h[i]); v[5] = r_; }
/* 24dba8: mul v6.4h, v6.4h, v10.4h */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.h[i] = (uint16_t)((uint64_t)v[6].h[i] * v[10].h[i]); v[6] = r_; }
/* 24dbac: mul v7.4h, v7.4h, v11.4h */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.h[i] = (uint16_t)((uint64_t)v[7].h[i] * v[11].h[i]); v[7] = r_; }
/* 24dbb0: add v10.8h, v4.8h, v6.8h */
{ qv r_ = {0}; for (int i = 0; i < 8; i++) r_.h[i] = (uint16_t)(v[4].h[i] + v[6].h[i]); v[10] = r_; }
/* 24dbb4: sshll v10.4s, v10.4h, #0x2 */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.s[i] = (uint32_t)((uint64_t)((int64_t)v[10].sh[i + 0]) << 2); v[10] = r_; }
/* 24dbb8: sub v11.8h, v4.8h, v6.8h */
{ qv r_ = {0}; for (int i = 0; i < 8; i++) r_.h[i] = (uint16_t)(v[4].h[i] - v[6].h[i]); v[11] = r_; }
/* 24dbbc: sshll v8.4s, v11.4h, #0x2 */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.s[i] = (uint32_t)((uint64_t)((int64_t)v[11].sh[i + 0]) << 2); v[8] = r_; }
/* 24dbc0: add v9.8h, v5.8h, v7.8h */
{ qv r_ = {0}; for (int i = 0; i < 8; i++) r_.h[i] = (uint16_t)(v[5].h[i] + v[7].h[i]); v[9] = r_; }
/* 24dbc4: smull v9.4s, v9.4h, v0.h[0] */
{ qv r_ = {0}; for (int i = 0; i < 4; i++) r_.s[i] = (uint32_t)(((int64_t)v[9].sh[i + 0] * (int64_t)v[0].sh[0])); v[9] = r_; }
For kernels the corpus does not reach, the Unicorn check runs the original machine code in a CPU emulator and the lifted C natively on the same random coefficient blocks:
The gate also caught our own mistakes. The first verification build compiled the C for arm64 without -fsigned-char. Ghidra's C assumes a signed char, and on AArch64 plain char is unsigned, so the marker parser never found a marker. Two LLM fixes accepted under that build had adapted to the wrong semantics. After the switch both functions were exact without any change, so we withdrew the fixes and screened everything again.
10. Check the whole library three ways
The screen proves each function on its own. Three whole-library runs prove that the functions work together and that nothing around them (data image, relocations, runtime shims, the host compiler and libc) changes behaviour.
# Run from work/. The rebuilt library alone on arm64, with no original code loaded:
./venv/bin/stitch rehost verify quram --standalone-only
# Run from work/quram. The x86-64 build that gets fuzzed, in the stitch_base image:
zsh rec/fidelity_linux.sh
| Run | Files | Bit-identical files | Rows identical | Crashes |
|---|
For most of the night the Linux build stopped at 97.3%. Thirteen large files differed, always with the same wrong hash. A pixel dump showed that most of the image was never written:

Two functions, SAVE_MID_POINT and LOAD_MID_POINT, had been put on the stop list on the first day as "not JPEG" and stubbed to return 0. They save and restore the decoder's position partway through a large scan. The swap-in screen could not see this, because it calls the original for anything outside the rebuilt set. The standalone arm64 run can, and it is now part of verify.
# Run from work/quram. Lift the two functions, then repeat both whole-library runs.
for f in SAVE_MID_POINT LOAD_MID_POINT; do python3 rec/lift_neon.py export5 bin/libimagecodec.quram.so $f; done
zsh rec/fidelity_linux.sh
zsh rec/fidelity_android_standalone.sh

11. Replay known crashes: phone first, then the rebuild
Identical output on valid images says nothing about invalid ones. For that we used a bug we already knew: CVE-2026-21096. We replayed the 207 inputs on the library installed on the S25 and kept the phone's own backtrace for each crash.
# Run from work/quram. Replays each input on the phone's installed library.
DEV=RFCY81FTGYT zsh rec/replay_device.sh ground_truth/inputs ground_truth/device_S931B.tsv
zsh rec/device_signatures.sh # debuggerd backtraces, symbolized on the phone
# The same inputs on the rebuilt library with AddressSanitizer:
zsh rec/replay_known.sh


12. Package, infer, fuzz
package writes a normal STITCH project whose header exposes the two calls the platform makes. From there it is the Part 1 workflow.
# Run from work/.
./venv/bin/stitch rehost package quram --project proj/quram_decode
# Run from proj/quram_decode.
../../venv/bin/stitch test
../../venv/bin/stitch infer --name harn1 -m openai/gpt-5
# No LLM is used in the fuzzing stage. Two hours, one CPU.
STITCH_DOCKER_EXTRA="--cpus=1" ../../venv/bin/stitch fuzz --name harn1 --no-triage \
--hard-rss-limit-mb 2048 -o ../../out/quram_decode/stitch/r1 --time-limit-seconds 7200

The libFuzzer baseline uses a classic harness that makes the platform's call (harness/harness.c), built from the same rebuilt tree with the same compiler and ASan, in fork mode as in Part 1.
# Run from work/. Arguments: repetition, seconds.
zsh quram/lf/run_lf_decode.sh 1 7200
# What it runs inside the stitch_base container:
./lf_quram_decode -fork=1 -ignore_crashes=1 -ignore_ooms=1 -ignore_timeouts=1 \
-max_total_time=7200 -rss_limit_mb=2048 -timeout=10 -max_len=65536 \
-artifact_prefix=/o/crashes/ /o/corpus
# Every artifact goes back to the phone before it counts:
DEV=RFCY81FTGYT zsh quram/rec/replay_device.sh quram/ground_truth/fuzz_timeouts quram/ground_truth/device_fuzz_timeouts.tsv
What we found
How much of the decompiler’s output survives
We compared, line by line, what Ghidra exported for each function with the C that is in the final tree. Whitespace, comments and the generated preamble are ignored.
| Where the final code came from | Functions | Machine code | Ghidra lines | Ghidra lines unchanged |
|---|---|---|---|---|
| Ghidra output, mechanical changes only (declarations, globals, frame rebuild) | 200 | 233,796 B | 45,830 | 99.3% |
| LLM rewrite of Ghidra output (repair, port, return value, verify-gated fix) | 38 | 98,596 B | 24,160 | 77.1% |
| Instruction-level lift from the machine code | 39 | 130,900 B | 34,847 | 0.2% |
| Fixed by hand | 5 | 11,392 B | 3,499 | 31.2% |
The decompiler alone is enough for 71% of the functions, which hold 49% of the machine code. The other half of the code is where the difficulty is. Even inside the LLM-rewritten functions, three lines in four are still Ghidra's. For the lifted functions almost nothing of Ghidra's text survives, because the lift starts again from the instructions.
The numbers also show why compiling is not a useful test. All 257 files compiled at step 5. At that point the rebuild decoded 1 of 302 files correctly and crashed on 238.
Fidelity: the rebuild against the original
The table in step 10 is the result: 341 of 341 files and 4,059 of 4,059 outputs are bit-identical, on arm64 alone, with every function swapped into Samsung's binary, and as the x86-64 build that gets fuzzed. Getting there took one night. Each row is one class of fix found by the loop:
| Step | Files | Bit-identical files | Rows identical | Files that crash the rebuild |
|---|
Four classes of error compiled cleanly and changed behaviour. All are now handled by the generator:
- Lost return values. Fixed at the source by correcting prototypes in Ghidra (step 4).
- Phantom SIMD parameters. Shown above for the exported functions. On x86-64 a
chararray ordoubleparameter shifts the integer arguments. - Split stack frames. Shown above for
WINKJ_GetHInfoandQURAMWINK_DecodeJPEG. 73 frames are rebuilt. - Relocations not applied. The constructor that fixes up code pointers lived in an object nothing referenced, so the linker dropped it and every function-pointer table held raw addresses.
Ground truth: does the rebuild reproduce CVE-2026-21096?
143 of the 207 inputs crash the phone. The phone's backtraces put all of them in the progressive-JPEG path:
| Signal | Crash site on the phone (innermost frames) | Files |
|---|
We replayed the 198 distinct inputs on the rebuilt library with ASan and compared each with what the phone did:
| Rebuilt + ASan reports a bug | Rebuilt runs clean |
|---|
| On the phone | On the rebuilt library (ASan) | Files |
|---|
Every input that crashes the phone is reported by the rebuild, at the same root cause: the progressive IDCT writes outside its output rows (FUN_0034b800, the NEON kernel called from WINKJ_ProgIDct). ASan reports the write itself, where the phone faults a few instructions later or aborts in free() on a corrupted heap. The rebuild also flags 32 inputs that overflow without crashing the phone. Before the fixes in steps 8 to 10 the same replay reported : the rebuild crashed early, in the wrong place, on every file.
Fuzzing the rebuild
| Fuzzer | Exec/s | Own coverage counter | Crash files | Other artifacts | On the phone |
|---|
No memory-safety crash in three and a half hours, from either fuzzer. The only artifacts are five libFuzzer timeouts: large images that took more than 10 s under ASan and x86 emulation. On the S25 each decodes normally in 92 to 221 ms, so we did not count them.
Neither fuzzer rediscovered CVE-2026-21096, which the rebuild reports 143 times out of 143 when it is given a crashing input. The ground truth says why. Every phone-crashing file is a progressive JPEG in which a chroma component is sampled at something other than 1×1. None of the 301 seeds is:
We tried two cheap improvements for 30 minutes each. A dictionary of sampling-factor tokens changed nothing. 80 valid JPEGs with non-1×1 chroma sampling raised coverage, and all 80 decode normally on the phone. The overflow needs that sampling and malformed progressive scan data together, and byte mutation did not build that combination.
STITCH was handicapped twice on this target. It ran at 27 executions per second, because every call sequence starts a decoder from scratch on an emulated CPU. And the inferred harness capped the output buffer at 2,048 bytes, so most generated images were refused before decoding. Its generator writes JPEG data from scratch instead of mutating real files, and it reached 662 of 25,017 edges.
What the LLM buys, and what it costs
| Stage | Model calls | Cost | Acceptance test |
|---|---|---|---|
| Repair, port and return-value recovery (step 6) | 51 | $8.63 | Compiles and matches the disassembly's statement, store and call counts |
| Verify-gated fixes (step 9) | 82 | $21.81 | Exact when swapped alone into the original binary |
| Instruction-level lift (39 functions) | 0 | $0 | Exact in the swap-in screen; kernels also checked in Unicorn |
| Total | 133 | $30.44 |
The model is good at the tedious middle: 38 functions where the decompiler's output is nearly right and needs a prototype, a struct or a return value corrected. It is not reliable on code where the decompiler's output is misleading. It rewrote a NEON kernel as a clean scalar routine that was wrong four times, picked a different colour converter because the right one was a stub at the time, and shortened a stream block by eight bytes. Each of these compiled. What made the model usable was the gate behind it, not the prompt.
Which known CVEs the rebuilds reproduce
A rebuild reproduces a CVE when inputs that trigger the bug on the phone's installed library are reported by the rebuilt library under AddressSanitizer, at the same root cause, and inputs that do not trigger it run clean. By that test, stitch rehost reproduced two CVEs:
| Reproduced on a verified rebuild | Library | Bug | Evidence |
|---|---|---|---|
| CVE-2026-21096 | libimagecodec.quram.so | Heap overflow in the JPEG decoder (progressive IDCT) | 143 of 143 phone-crashing inputs reported by the rebuild, all at FUN_0034b800 called from WINKJ_ProgIDct |
| CVE-2026-21114 | libsmkvextractor.so | Out-of-bounds write when 8-bit PCM is widened in place | The rebuild flags exactly the two hand-built files that crash the phone, and none of the control files |
CVE-2026-21096 is the JPEG result above. For the rest, we took six more CVEs from Samsung's September and October 2026 bulletins, all in closed-source media libraries, and ran the same stages on the same phone, where they are still present. The question for each: can we rebuild the library, does the rebuild match the phone, does the known bug show up on the rebuild, and does a fuzzer find it?
# Run from the library's work directory. The same stages; '*' makes every export an entry point.
stitch rehost init rehost --lib libsmkvextractor.so --entries '*' --device RFCY81FTGYT -m openai/gpt-5
stitch rehost decompile rehost
stitch rehost generate rehost
stitch rehost llm rehost --mode port
stitch rehost verify rehost
stitch rehost package rehost --project ../smkv_rehosted
| CVE | Library | Rebuild vs phone | Known bug reproduced | Found by a fuzzer |
|---|---|---|---|---|
| CVE-2026-21114 | libsmkvextractor.so (Matroska) | 238 functions; 35 / 35 files and 7,010 / 7,010 seek-and-read lines identical | yes Two hand-built files crash the phone; the ASan rebuild flags exactly those two | yes libFuzzer 2 h (18.4 M execs), STITCH 3 runs |
| CVE-2026-21088 | libsubextractor.so (subtitles) | 176 functions; 45 / 45 files identical | yes | yes STITCH 1 h 49 min, 161 k execs, 40% of edges, 4 crashes |
| CVE-2026-21089 | no | |||
| CVE-2026-21090 | libsaviextractor.so (AVI) | 389 functions; 29 / 29 files identical | yes | yes STITCH 2 h, 156 k execs, 21% of edges, 2 crashes |
Caveats
- 143 functions are not reached by the corpus. They are part of the three whole-library runs and the hand-written kernels among them pass the Unicorn check, but they have no per-function proof. A bug the fuzzer reports in one of them needs the phone replay more than any other.
- Fidelity is measured on valid images. The crash replay covers one bug class in one code path. Agreement on other malformed inputs is not measured.
- One library version. The rebuild is of the file with the hash above. A firmware update needs the stages run again.
- The output reference ran on an emulator. It is the phone's library file, byte for byte, on an arm64 Android emulator. Crash ground truth ran on the phone itself.
- Short campaigns. One two-hour run per fuzzer plus two 30-minute rounds, on an emulated CPU. This is not a measurement of what longer runs or better seeds would find.
- Threads. The decoder uses a thread pool for large images. Outputs were deterministic in all our runs, but we did not test for races.
Conclusion
A decompiled library can be made trustworthy enough to fuzz, but only by checking it against the binary. Ghidra's output carried 200 of 282 functions almost untouched, an LLM carried 38 more for $30, and the remaining 39 had to be translated instruction by instruction. None of those three sources was reliable on its own: each produced code that compiled and was wrong. The per-function swap-in screen is what turned them into a rebuild that matches the original on 4,059 of 4,059 outputs and reproduces CVE-2026-21096 on all 143 phone-crashing inputs. The same stages reproduced CVE-2026-21114 in a second library.
The rebuild does not make the fuzzer smarter. With full sanitizers and coverage on the target, neither STITCH nor libFuzzer found CVE-2026-21096 in 3.5 hours, because it needs a combination of header fields and malformed scan data that none of the seeds had. For closed-source parsers the practical recommendation is to spend the first effort on the rebuild and its ground truth, and the second on seeds and generators that cover the format's options. A crash on a verified rebuild can be replayed on the phone the same day.
The follow-up is already running. The same rebuilds, on the current versions of these libraries, produced four previously unknown vulnerabilities, reported to the vendor. Once they are patched we will publish what they are, and how much the rebuild did — or did not — help in finding them.
Credits
- Harrison Green, Fraser Brown and Claire Le Goues (Carnegie Mellon University) for STITCH.
- The Ghidra and Unicorn projects, which the decompile and lift-check stages are built on.
Reproduce it
The code is open source: mobilehackinglab/stitch-rehost, a fork of STITCH that adds the stitch rehost command. It contains no Samsung binaries, decompiled code or crash inputs; you supply the library you want to rebuild.
All scripts used here are in the project's rec/ directory: Ghidra scripts (ghidra_scripts/), the generator (gen.py), the LLM stages (llm_stage.py, verify_fix.py), the swap-in build and screen (hybrid/), the lifter and its Unicorn check (lift_neon.py, lift_check.py), the differentials (fidelity_*.sh) and the replays (replay_device.sh, replay_known.sh). The page itself is built by blog/build_part2.py, which cuts every code excerpt above out of the Ghidra export, the generated tree and llvm-objdump.
| Stage | What it adds | What it guarantees |
|---|---|---|
verify | Swap-in build on arm64 (PLT and entry patching), call counters, crash frames | A function is exact only if it ran and every output over the corpus is byte-identical to the original's |
lift | AArch64 to C lifter (NEON lanes, saturation, flags, calls, jump tables, branch islands) | One statement per instruction; checked against Unicorn and by the swap-in screen |
improve | Verification-gated repair loop: lift first, then LLM with evidence | Rejected attempts and costs are logged; the previous version is restored |
verify --standalone | The rebuilt library alone on arm64 Android | Catches wrong stubs and functions missing from the closure |
generate | Signed char, archive-safe fixups, frame rebuild, SIMD parameter retyping | The error classes found here cannot come back |