Repository navigation
Scylla: support MOV-based IAT discovery and clear stale OFT=0 imports - #254
Open
doomedraven wants to merge 1 commit into
Open
doomedraven wants to merge 1 commit into
doomedraven wants to merge 1 commit into
Conversation
Go binaries on Windows (386 and amd64) load //go:cgo_import_dynamic Win32 API addresses via MOV reg, [IAT_slot] (8B /r disp32 on x86, RIP-relative MOV on x64) and dispatch them through runtime.asmstdcall (CALL reg) rather than emitting CALL [IAT] or JMP [IAT] thunks. Because IATSearch::findIATPointers() filtered strictly on FC_CALL || FC_UNC_BRANCH, Scylla missed unpacked Go IATs during OEP dumping (e.g. UPX step2oep with imprec=1) and fell back to an unfixed PeParser::dumpProcess() dump. In addition, when PeParser::dumpProcess() or dumpProcessToHandle() ran without rebuilt imports, removeIatDirectory() zeroed IMAGE_DIRECTORY_ENTRY_IAT while leaving IMAGE_DIRECTORY_ENTRY_IMPORT intact. For packers such as UPX whose stub import descriptor sets OriginalFirstThunk = 0, the OS loader had already overwritten FirstThunk in memory with live DLL virtual addresses; leaving that descriptor active caused ntdll!LdrpSnapThunk to treat snapped VAs as RVA import-by-name offsets and crash immediately with STATUS_ACCESS_VIOLATION on re-execution. Changes: - Extend IATSearch::findIATPointers() with an optional movPointers collector for flat-segment I_MOV memory-to-register loads targeting pointer-aligned in-image slots when CALL/JMP IAT scanning finds no entries. - Validate, cluster (<= 0x100 stride), and extend contiguous MOV-referenced API pointer ranges across adjacent valid thunks and single-NULL module separators in IATSearch::findIATAdvanced(), and free dataBuffer immediately after disassembly to fix three early-return leaks. - Add PeParser::sanitizeUnrebuiltImportDirectory() on unfixed dumpProcess() / dumpProcessToHandle() paths to clear IMAGE_DIRECTORY_ENTRY_IMPORT when an OriginalFirstThunk == 0 descriptor has FirstThunk entries pointing outside mapped image sections, while leaving OriginalFirstThunk != 0 and ImportRebuilder outputs untouched.
doomedraven
marked this pull request as ready for review
November 18, 2026 07:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two coupled failure modes when dumping unpacked Go / UPX binaries at OEP with Scylla:
MOV-based IAT discovery (CAPE/Scylla/IATSearch.{h,cpp}):386andamd64) load//go:cgo_import_dynamicWin32 API pointers from the IAT viaMOV reg, [IAT_slot](8B /r disp32on x86, RIP-relativeMOVon x64) and invoke them throughruntime.asmstdcall(CALL reg) without emittingCALL [IAT]orJMP [IAT]thunks.IATSearch::findIATPointers()previously inspected onlyFC_CALL || FC_UNC_BRANCH, causingfindIATAdvanced()to miss Go's unpacked IAT completely even withimprec=1(UPX.yarstep2oep).R_NONE/R_DS), pointer-aligned, in-imageI_MOV->O_REGmemory load targets during the existing disassembly pass and uses them strictly as a fallback whenCALL/JMPIAT discovery yields no entries. Candidate slots are validated viaisIATPointerValid(), grouped into<= 0x100-byte contiguous clusters (requiring>= 2resolved APIs), and extended across adjacent valid thunks and single-NULLmodule separators.dataBufferimmediately after the disassembly loop infindIATAdvanced(), fixing three early-returnnew BYTE[]leaks.Stale
OriginalFirstThunk == 0import directory cleanup on unfixed dump fallback (CAPE/Scylla/PeParser.{h,cpp}):PeParser::dumpProcess()ordumpProcessToHandle()runs withoutImportRebuilder(eitherFixImports == FALSEor IAT discovery fails),removeIatDirectory()zeroesIMAGE_DIRECTORY_ENTRY_IATwhile leavingIMAGE_DIRECTORY_ENTRY_IMPORTuntouched.OriginalFirstThunk == 0, the Windows loader overwritesFirstThunkin RAM with live DLL virtual addresses (0x777fxxxx/0x00007ff...). LeavingIMAGE_DIRECTORY_ENTRY_IMPORTpointing at snappedOriginalFirstThunk == 0thunks causesntdll!LdrpSnapThunkto interpret live VAs asIMAGE_IMPORT_BY_NAMERVAs and crash immediately withSTATUS_ACCESS_VIOLATION(0xC0000005) if the dumped PE is executed.PeParser::sanitizeUnrebuiltImportDirectory()inspectsOriginalFirstThunk == 0descriptors on unfixed dump paths and zeroesIMAGE_DIRECTORY_ENTRY_IMPORTwhenFirstThunkentries point outside mapped image sections, while preservingOriginalFirstThunk != 0descriptors andImportRebuilder::rebuildImportTable()outputs untouched.Are these related?
Yes — unlike the coupled
NDEBUGcase where build flags alter macro semantics across translation units, both changes here sit directly on theScyllaDumpProcess()OEP unpacker path for UPX/packed binaries:IATSearchreconstructsMOV-referenced IATs into.CAPEwhenimprec=1is active, andPeParser::sanitizeUnrebuiltImportDirectory()ensures the unfixed dump path (imprec=0or dynamic-only imports) never emits a loader-crashingOriginalFirstThunk == 0directory.Verification
Win32/x64) are unverified beyond source inspection.distormASan/UBSan harness: Compileddistorm+IATSearch/PeParserlogic underg++ -std=c++17 -O1 -g -Wall -Wextra -Werror -fsanitize=address,undefinedin both 64-bit (-D_WIN64) and 32-bit (-m32 -U_WIN64) modes coveringMOVIAT clustering,.bssnoise rejection,FS:/GS:segment override filtering, single-NULLseparator extension,CALL/JMPprecedence, and 32/64-bitOriginalFirstThunk == 0stale-thunk sanitization (0warnings,0ASan/UBSan findings).Series
Builds cleanly on latest
upstream/capemon(28c990f) with zero conflicts against open PRs (#207, #209, #210, #213, #214, #215, #243, #251, #253).