Skip to content

Support IDA 9.5 databases, IDAS sparse flags, and IDA 9 argument locations - #61

Open
coleleavitt wants to merge 2 commits into
Vector35:mainfrom
coleleavitt:v950-support
Open

coleleavitt wants to merge 2 commits into
Vector35:mainfrom
coleleavitt:v950-support

Conversation

@coleleavitt

Copy link
Copy Markdown

Adds support for IDA 9.5 databases and fixes two gaps that already affect 9.1–9.4 files.

Changes

  • IDA 9.5 (header version 950). Same header as 910. The ID1 and NAM VA* headers have kind 4 since 9.5:
    • ID1 kind 4 lists (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.
    • NAM kind 4 adds a u64 page size (0x2000) after the name count.
  • IDAS section (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_address now falls back to it, so names and flags of extern symbols resolve. The layout is documented in doc/fileformat.md.
  • ArgLoc 0xFF form. The extended form is a dt: 0x80 | n starts n scattered parts (location dt(off) de(size)); otherwise it is 0x20 | ALOC_*. One register is followed by dt(reg) dt(offset); 64-bit values (stack, static, register-relative offset) are two de, low half first. The old reading made __usercall prototypes fail with Type::Function (for example on iOS kernelcaches).

API change: ArgLoc now carries what is stored: Reg1 { reg, off }, Stack(i64), Static(u64), RRel { reg, off: i64 }, and ArgLocDist { loc, off, size } for scattered parts.

Testing

  • cargo test: 53/53 passed; no snapshot changes. All argument locations in the existing snapshots are None, so they never covered the 0xFF form.
  • 237 local databases (IDA 6.x through 9.5): every one now decodes with dump-functions and dump-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.
  • Compared with IDA 9.5's own answers through IDAlib on 9 databases (ELF, MIPS kernel module, Mach-O arm64e, PE, up to 1.25 GB): function starts and ends, stored names, NAM lists, and per-byte flags (including .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 __usercall prototypes in a kernelcache match IDA's argument locations, including scattered ones.
  • The ArgLoc encoding was also checked against tinfo_t::serialize output for each location kind.

…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.
@emesare
emesare requested review from emesare and a balanced review from Copilot October 28, 2026 15:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Sparse ranges are omitted from iteration and navigation, while malformed data can trigger arithmetic overflow or unbounded recursion.

7 open issues
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

Comment thread src/id1.rs Outdated
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>,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/id1.rs
Comment on lines +291 to +295
.or_else(|| {
self.sparse
.as_ref()?
.flags(address.into_raw().into())
.map(ByteInfo)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/id1/sparse.rs Outdated
Comment on lines +115 to +116
let start = end + input.unpack_dq()?;
end = start + input.unpack_dq()?;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 14b1e56 with checked_add; an overflowing range is an error. Added a unit test.

Comment thread src/til/function.rs Outdated
Comment on lines +258 to +260
let parts = (0..parts)
.map(|_| {
let loc = Self::read(&mut *input)?;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/id1.rs
// sort segments by address
let mut overlay_check = match &seglist_raw {
SegInfoRaw::VaN(segs) => {
SegInfoRaw::VaN(segs) | SegInfoRaw::VaXOffsets(segs) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 14b1e56: the overlap check is now strict, so half-open ranges can share an endpoint.

Comment thread src/id1.rs Outdated
Comment on lines +113 to +114
let mut body = Vec::new();
input.read_to_end(&mut body)?;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/id1/sparse.rs Outdated
Comment on lines +87 to +90
let in_item = self.records[..idx]
.iter()
.rev()
.find(|r| r.2 > 0)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants