Repository navigation
Support IDA 9.5 databases, IDAS sparse flags, and IDA 9 argument locations - #61
coleleavitt wants to merge 2 commits into
Conversation
…locations v950 uses the V910 header. ID1 and NAM VA* headers have kind 4 since 9.5; ID1 kind 4 ranges carry their data offset and are not stored in address order. Since 9.1 the sixth section (IDAS) holds the flags of ranges without file data (.bss, extern, padding); ID1Section::byte_by_address falls back to it. The 0xFF ArgLoc form is 0x20|ALOC_* or 0x80|n scattered parts, with a register offset after the register and 64-bit values as two de. Checked against IDA 9.5 through IDAlib on 9 databases (flags, functions, names, NAM, __usercall locations) and against tinfo_t::serialize.
There was a problem hiding this comment.
🟡 Changes recommended
Sparse ranges are omitted from iteration and navigation, while malformed data can trigger arithmetic overflow or unbounded recursion.
7 open issues
Include sparse ranges in SDK navigation · New Include sparse ranges in byte iterators · New Check range arithmetic for overflow · New Limit recursive scattered-part decoding · New Allow adjacent half-open kind-4 ranges · New Avoid buffering the entire kind-4 ID1 body · New Avoid quadratic implicit-tail lookups · New
What changed in this PR
Extends the database reader to support IDA 9.5 and improves decoding of sparse flags and argument locations in IDA 9.x files.
Changes:
- Accepts version 950 headers and kind-4 ID1/NAM layouts.
- Reads IDAS sparse flags and adds fallback support to address lookups.
- Corrects extended argument-location decoding, updates its public types, and documents the formats.
| File | Description |
|---|---|
src/til/function.rs |
Updates argument-location types and extended decoding. |
src/nam.rs |
Supports kind-4 headers with an explicit page size. |
src/lib.rs |
Recognizes version 950 and loads the IDAS section. |
src/id1/sparse.rs |
Adds sparse flag parsing and lookup. |
src/id1.rs |
Reads offset-based kind-4 ranges and adds sparse lookups. |
doc/fileformat.md |
Documents IDA 9.5 layouts, IDAS, and argument locations. |
Review effort: Balanced
| pub struct ID1Section<K: IDAKind> { | ||
| pub seglist: Vec<SegInfo<K>>, | ||
| /// Flags of the ranges without file data, 9.1+ databases only. | ||
| pub sparse: Option<SparseFlags>, |
There was a problem hiding this comment.
Fixed in 14b1e56. ID1Section now looks up ranges over both ID1 and IDAS (compiled code search on each list), and range.rs, chunk_start/chunk_size, next_addr/prev_addr and find_free_chunk use it.
ranges() and the chunk functions return contiguous ranges: across 237 local databases, ID1 and IDAS never store touching ranges themselves, but an ID1 range often touches an IDAS one (.data followed by .bss), and IDA's rangeset merges adjacent ranges.
While there I also fixed two older bugs: rangeset_t_prev_range returned the next range, and find_free_chunk returned the free size instead of the address and panicked past the last range.
| .or_else(|| { | ||
| self.sparse | ||
| .as_ref()? | ||
| .flags(address.into_raw().into()) | ||
| .map(ByteInfo) |
There was a problem hiding this comment.
Fixed in 14b1e56. all_bytes, all_bytes_no_tails, prev_not_tail and next_not_tail walk the ID1 and IDAS ranges in address order. IDAS bytes are produced lazily, one lookup per address, so .bss ranges are never materialized.
all_address_info now filters before it collects, so dump-address-info/produce-idc also use less memory than before (iOS kernelcache: 29 s / 5.7 GB → 18 s / 5.0 GB).
| let start = end + input.unpack_dq()?; | ||
| end = start + input.unpack_dq()?; |
There was a problem hiding this comment.
Fixed in 14b1e56 with checked_add; an overflowing range is an error. Added a unit test.
| let parts = (0..parts) | ||
| .map(|_| { | ||
| let loc = Self::read(&mut *input)?; |
There was a problem hiding this comment.
Fixed in 14b1e56. IDA doesn't allow a part of a scattered location to be scattered itself, so a nested distribution is now an error and the depth is at most 2. Added a unit test.
| // sort segments by address | ||
| let mut overlay_check = match &seglist_raw { | ||
| SegInfoRaw::VaN(segs) => { | ||
| SegInfoRaw::VaN(segs) | SegInfoRaw::VaXOffsets(segs) => { |
There was a problem hiding this comment.
Fixed in 14b1e56: the overlap check is now strict, so half-open ranges can share an endpoint.
| let mut body = Vec::new(); | ||
| input.read_to_end(&mut body)?; |
There was a problem hiding this comment.
Fixed in 14b1e56. Kind 4 and VaN now share one reader: it reads the ranges in file-offset order, skips the gaps as a stream (only VaN requires them to be zero), then sorts the ranges by address.
| let in_item = self.records[..idx] | ||
| .iter() | ||
| .rev() | ||
| .find(|r| r.2 > 0) |
There was a problem hiding this comment.
Fixed in 14b1e56. Each record now stores the end of the item that covers the bytes after it, computed once when reading, so a lookup is one compiled code search. The range and value-range checks are compiled code searches too.
Address the review of Vector35#61: - all_bytes, all_bytes_no_tails, prev/next_not_tail, the rangeset helpers, chunk_start/chunk_size and find_free_chunk now cover the ranges stored in IDAS. ranges() and the chunk functions return contiguous ranges: ID1 and IDAS never store touching ranges themselves, but a range of one often touches a range of the other. - IDAS bytes are produced lazily; each lookup is a binary search, the item that covers a tail is precomputed per record. - IDAS range deltas use checked arithmetic. - A scattered ArgLoc part can't be scattered itself, so nesting is an error instead of unbounded recursion. - Kind-4 ID1 ranges are read in file-offset order, skipping the gaps, instead of buffering the whole section; adjacent ranges are allowed. - all_address_info filters before collecting, so large .bss ranges no longer grow peak memory. Also fixes rangeset_t_prev_range (it returned the next range) and find_free_chunk (it returned the free size instead of the address, and panicked past the last range).


Adds support for IDA 9.5 databases and fixes two gaps that already affect 9.1–9.4 files.
Changes
VA*headers have kind 4 since 9.5:(start, end, offset)per range. Ranges are not stored in address order, and the space between them can hold stale data from moved ranges, so the reader slices by offset.u64page size (0x2000) after the name count.IDASsection (since 9.1). The sixth inline section holds the flags of address ranges that have no bytes in ID1 (.bss,extern, alignment padding) as sparse records.ID1Section::byte_by_addressnow falls back to it, so names and flags of extern symbols resolve. The layout is documented indoc/fileformat.md.ArgLoc0xFF form. The extended form is a dt:0x80 | nstartsnscattered parts (location dt(off) de(size)); otherwise it is0x20 | ALOC_*. One register is followed bydt(reg) dt(offset); 64-bit values (stack, static, register-relative offset) are twode, low half first. The old reading made__usercallprototypes fail withType::Function(for example on iOS kernelcaches).API change:
ArgLocnow carries what is stored:Reg1 { reg, off },Stack(i64),Static(u64),RRel { reg, off: i64 }, andArgLocDist { loc, off, size }for scattered parts.Testing
cargo test: 53/53 passed; no snapshot changes. All argument locations in the existing snapshots areNone, so they never covered the 0xFF form.dump-functionsanddump-dirtree-funcs. Upstream fails on the 35 9.5 files and 3 kernelcaches. On the 171 9.1–9.4 databases, about 28,000 more function prototypes decode, and none decode worse..bss/extern) all match. One database differs on 41 sampled bytes, which IDA rewrites itself while opening; after IDA re-saves it, those match too. All 447__usercallprototypes in a kernelcache match IDA's argument locations, including scattered ones.ArgLocencoding was also checked againsttinfo_t::serializeoutput for each location kind.