Add REPL set_offset and search_offset commands - #7
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51f684dcaf
ℹ️ 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".
| void* lib_handle = getOrLoadLibrary(library_name); | ||
| void* offset = getAddressFromAddressStringOrNameOfCoercableVariable(offset_str); | ||
| storeOffsetForLibLoadedAtAddress(lib_handle, offset); |
There was a problem hiding this comment.
Fail set_offset when getOrLoadLibrary returns NULL
parseSetOffset stores an offset even if getOrLoadLibrary fails, so a bad or non-loadable library name silently writes liboffset_(nil) and reports success; this can corrupt later offset-based lookups that also use a null handle instead of surfacing a load error. Add a null-handle check before calling storeOffsetForLibLoadedAtAddress.
Useful? React with 👍 / 👎.
| while (*clean_path && isspace((unsigned char)*clean_path)) { | ||
| clean_path++; | ||
| } | ||
| if (path_ends_with(clean_path, library_path)) { |
There was a problem hiding this comment.
Canonicalize library path before region-path suffix checks
The Linux/macOS region matcher requires mapped paths to end with resolve_library_path output, but that resolver can return non-canonical symlink paths (for example libfoo.so) while mapped image paths are canonicalized targets (for example libfoo.so.1), causing search_offset to report no readable regions even when the library is loaded. Canonicalizing the resolved path (or matching by inode/basename) avoids this false negative.
Useful? React with 👍 / 👎.
Motivation
calculate_offset.Description
set_offset <library> <offset>andsearch_offset [<variable>] <library> <bytestring> <address>with parsersparseSetOffsetandparseSearchOffsetinsrc/main.c.parse_search_bytes,append_region,find_bytes_in_regions, anddump_match_contextand smallMemoryRegion/MemoryMatchtypes to support searching and context dumping.search_offset: Linux via/proc/self/maps, Windows viaGetModuleInformation+VirtualQuery, and macOS via dyld image lookup +mach_vm_region.printVariableWithArgInfoand included required platform headers.address_in_memory - address_providedand stores it viastoreOffsetForLibLoadedAtAddress; if a variable name is supplied, the offset is also stored in that variable.Testing
cmake -S . -B buildandcmake --build build -j4, which completed successfully.ctest --test-dir build --output-on-failure, and all tests passed (156/156 passed).Codex Task