Add REPL set_offset and search_offset commands - #6
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d263c66866
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ((info.protection & VM_PROT_READ) != 0) { | ||
| appendMemoryRange(ranges, (uintptr_t)addr, (uintptr_t)(addr + size)); |
There was a problem hiding this comment.
Restrict macOS range collection to the requested library
In the __APPLE__ branch, every readable VM region is appended without checking whether it belongs to the requested library, so search_offset can match bytes from unrelated images and either compute a wrong offset or fail as "multiple times" even when the target library has a unique match. This affects macOS runs whenever the pattern exists outside the requested module.
Useful? React with 👍 / 👎.
| return; | ||
| } | ||
|
|
||
| ptrdiff_t offset = (uintptr_t)firstMatch - (uintptr_t)providedAddress; |
There was a problem hiding this comment.
Normalize ARM Thumb addresses before offset subtraction
parseSearchOffset subtracts providedAddress directly, but unlike parseCalculateOffset it never clears the Thumb bit on ARM. When the user supplies a function/symbol pointer in Thumb mode (LSB set), the stored offset becomes off by one byte, which breaks later address reconstruction for relative calls on ARM targets.
Useful? React with 👍 / 👎.
Motivation
calculate_offsetworkflow.Description
parseSetOffsetto implementset_offset <library> <offset>which stores an offset via the existingstoreOffsetForLibLoadedAtAddressmechanism.parseSearchOffsetto implementsearch_offset [<variable>] <library> <bytestring> <address>which parsesbytestring(plain text or0x..hex), locates readable memory ranges for the target library, searches for the pattern, hex-dumps context around the first (and second) matches, verifies uniqueness, computesaddress_in_memory - address_provided, stores the offset and optionally stores it in the given variable.src/main.c:parseByteString,MemoryRangeListmanagement,collectReadableLibraryRangeswith platform-specific memory discovery (/proc/self/mapsfor Linux,VirtualQueryfor Windows, Mach VM region walking for macOS),findSubsequence, anddumpMatchContext.set_offsetandsearch_offsetcommands.Testing
cmake -S . -B build && cmake --build build -j4, which completed successfully (compile succeeded, warnings only).ctest --test-dir build --output-on-failureand all tests passed (156/156tests passed).Codex Task