1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
//! End-to-end cycle against a real database: open, read, write, re-read.
//!
//! A `#[kernel_test]` against the corpus manifest's canonical fixture. It renames and restores, so
//! it declares that it writes and gets a database reopened for it; skips when no corpus is
//! configured.
use assert2::assert;
use idakit::prelude::*;
use idakit_runner_macros::kernel_test;
#[kernel_test]
fn roundtrip() {
crate::common::with_canonical_db(run);
}
// The SDK's QMAXPATH (pro.h): 260 on Windows, PATH_MAX elsewhere. get_root_filename's facade
// buffer is this exact size.
#[cfg(windows)]
const QMAXPATH: usize = 260;
#[cfg(not(windows))]
const QMAXPATH: usize = libc::PATH_MAX as usize;
#[expect(
clippy::too_many_lines,
reason = "one end-to-end test body kept at a single indent level, per project test convention"
)]
fn run(idb: &mut Database) {
let func_count = idb.functions().count();
let seg_count = idb.segments().count();
assert!(func_count > 0, "expected at least one function");
assert!(seg_count > 0, "expected at least one segment");
// Segment domain: idakit's `Segment` view rides the generated seg bridge, so the generated qty
// must equal the iterator's count.
{
use idakit_sys as sys;
assert_eq!(
sys::gen_seg_qty(),
seg_count,
"generated gen_seg_qty disagrees with the Segments iterator"
);
println!("cxx segment bridge OK: {seg_count} segments");
}
// Function domain: idakit's `Function` view rides the generated func bridge. The generated qty
// must equal the iterator's count, and `func_start` of any entry is that entry.
{
use idakit_sys as sys;
assert_eq!(
sys::func_qty(),
func_count,
"generated func_qty disagrees with the Functions iterator"
);
for func in idb.functions() {
let ea = func.address().get();
assert_eq!(
sys::func_start(ea),
ea,
"func_start of an entry should be the entry at {ea:#x}"
);
assert!(
sys::func_end(ea) > ea,
"func_end should be past the entry at {ea:#x}"
);
let _ = sys::func_name(ea);
let _ = sys::func_flags(ea);
}
println!("cxx function bridge OK: {func_count} functions");
}
// Export domain: idakit's `Exports` iterator rides the generated export bridge, so the generated
// qty must equal its count; every generated accessor is exercised per entry.
{
use idakit_sys as sys;
assert_eq!(
sys::export_qty(),
idb.exports().count(),
"generated export_qty disagrees with the Exports iterator"
);
for e in idb.exports() {
let _ = (e.address(), e.ordinal(), e.name(), e.forwarder());
}
println!("cxx export bridge OK: {} exports", idb.exports().count());
}
// Import domain: idakit's `Imports` iterator materializes the generated import snapshot, dropping
// slots with no usable address, so its count never exceeds the snapshot's row count.
{
use idakit_sys as sys;
let snapshot = sys::imports_build();
let live = idb.imports().count();
assert!(
live <= snapshot.len(),
"Imports iterator yields more than the import snapshot has rows"
);
println!(
"cxx import bridge OK: {live} imports of {} snapshot rows",
snapshot.len()
);
}
// Name domain: idakit's `Names` iterator rides the generated nlist bridge (its count never
// exceeds `nlist_size`, since a `BADADDR` slot is skipped). The generated name accessors and the
// `has_*_name` predicates (fed each function's flags word) are exercised for consistency: a user
// name and a dummy name are mutually exclusive by construction.
{
use idakit_sys as sys;
assert!(
idb.names().count() <= sys::nlist_size(),
"Names iterator yields more than nlist_size entries"
);
for func in idb.functions() {
let ea = func.address().get();
let flags = sys::get_flags(ea);
let (user, dummy) = (sys::has_user_name(flags), sys::has_dummy_name(flags));
let _ = sys::has_auto_name(flags);
assert!(
!(user && dummy),
"a name cannot be both user-given and dummy at {ea:#x}"
);
if let Ok(name) = sys::get_ea_name(ea) {
let _ = sys::get_name_ea(&name);
let _ = sys::demangle_name(&name);
}
}
println!("cxx name bridge OK");
}
// Meta domain: database-wide metadata through the generated bridge (idakit's meta accessors ride
// these). Sanity-check the scalars and confirm the string getters resolve.
{
use idakit_sys as sys;
assert!(sys::bitness() > 0, "bitness should be positive");
assert!(
sys::proc_name().is_ok_and(|s| !s.is_empty()),
"a real database names its processor"
);
let _ = sys::image_base();
// The facade clamps get_file_type_name's return to its fixed 256-byte buffer, whose
// header promises no "bytes stored" count; nothing may come back past the cap.
if let Ok(ft) = sys::file_type_name() {
assert!(
ft.len() <= 256,
"file type name past the facade buffer cap: {ft:?}"
);
}
let _ = sys::input_path();
// get_root_filename is clamped to a QMAXPATH buffer (pro.h); the facade's clamp caps at
// the buffer size, so the string can equal it.
if let Ok(rf) = sys::root_filename() {
assert!(
rf.len() <= QMAXPATH,
"root filename past the facade buffer cap: {rf:?}"
);
}
println!("cxx meta bridge OK: proc={:?}", sys::proc_name().ok());
}
// Strings domain: IDA's string list built and walked through the generated bridge. Capped at the
// first 200 entries so a corpus with a huge string list stays cheap; the walk is uniform per
// entry, so the cap costs no coverage.
{
use idakit_sys as sys;
sys::strlist_build();
let qty = sys::strlist_qty().min(200);
for n in 0..qty {
let item = sys::strlist_item(n).expect("strlist_item within range");
let _ = sys::strlit_contents(item.ea, item.length as usize, item.type_);
}
assert!(
sys::strlist_item(sys::strlist_qty()).is_err(),
"strlist_item should Err past the end"
);
println!("cxx strings bridge OK: {qty} string-list entries walked");
}
let first = idb.functions().next().expect("a function");
let address = first.address();
let original = first.name();
assert!(!original.is_empty());
let bytes = idb.bytes(address, 16);
assert!(!bytes.is_empty(), "expected readable bytes at the entry");
// cxx opaque-handle bridge: the cxx `FlowChart` path (opaque type owned by UniquePtr, BlockInfo
// shared struct, Result-shaped bounds) walked through the generated bridge. The per-index
// accessors are cross-checked against the whole-edge-list copy, the Opaque intvec_t container,
// and the `self:`-member `size()`. The `UniquePtr<FlowChart>` frees the qflow_chart_t via
// cxx's generated deleter glue on drop.
{
use idakit_sys as sys;
let ea = address.get();
let flags = 0i32;
let fc = sys::cfg_build(ea, flags).expect("cxx cfg_build on the first function");
let n = sys::cfg_nblocks(&fc);
for b in 0..n {
let info = sys::cfg_block(&fc, b).expect("cxx cfg_block in range");
assert!(info.end >= info.start, "block {b} end precedes its start");
let ns = sys::cfg_nsucc(&fc, b);
let np = sys::cfg_npred(&fc, b);
// qvector<scalar> -> Vec<u32>: the whole-edge-list cxx path (one copy) must equal the
// per-index accessors it retires, element for element.
let succs = sys::cfg_succs(&fc, b).expect("cxx cfg_succs in range");
assert_eq!(succs.len(), ns, "cfg_succs length disagrees at block {b}");
for (i, s) in succs.iter().enumerate() {
assert_eq!(
*s as usize,
sys::cfg_succ(&fc, b, i).unwrap(),
"cfg_succs[{i}] disagrees at block {b}"
);
}
let preds = sys::cfg_preds(&fc, b).expect("cxx cfg_preds in range");
assert_eq!(preds.len(), np, "cfg_preds length disagrees at block {b}");
for (i, p) in preds.iter().enumerate() {
assert_eq!(
*p as usize,
sys::cfg_pred(&fc, b, i).unwrap(),
"cfg_preds[{i}] disagrees at block {b}"
);
}
// qvector<int>: the block's successor intvec_t bound as an Opaque cxx
// container, borrowed out of the live flow chart. Read it BOTH ways (a copying shim to
// Vec<i32>, and a zero-copy &[i32] borrowed from the container's {array, n}) and cross-
// check both against the cfg_succs copy and per-index cfg_succ paths.
let sv = sys::cfg_succ_vec(&fc, b).expect("cxx cfg_succ_vec in range");
assert_eq!(sys::intvec_len(sv), ns, "intvec_len disagrees at block {b}");
let copied = sys::intvec_copy(sv);
let slice = sys::intvec_slice(sv);
assert_eq!(copied.len(), ns, "intvec_copy len disagrees at block {b}");
assert_eq!(slice.len(), ns, "intvec_slice len disagrees at block {b}");
for (i, (c, s)) in copied.iter().zip(slice).enumerate() {
assert_eq!(
*c, *s,
"intvec copy vs slice disagree at block {b} elem {i}"
);
assert_eq!(
*s as usize,
sys::cfg_succ(&fc, b, i).unwrap(),
"intvec_slice vs cfg_succ disagree at block {b} elem {i}"
);
assert_eq!(
*s as u32, succs[i],
"intvec_slice vs cfg_succs disagree at block {b} elem {i}"
);
}
}
// Out-of-range bounds surface as `Err` on the cxx path.
assert!(
sys::cfg_block(&fc, n).is_err(),
"cxx cfg_block should Err past the last block"
);
assert!(
sys::cfg_succs(&fc, n).is_err(),
"cxx cfg_succs should Err past the last block"
);
assert!(
sys::cfg_succ_vec(&fc, n).is_err(),
"cxx cfg_succ_vec should Err past the last block"
);
// Proper (reachable) blocks never exceed the total.
assert!(
sys::cfg_nproper(&fc) <= n,
"cfg_nproper exceeds the total block count"
);
// A `self:`-receiver method binds to a real C++ *member* (`qflow_chart_t::size`);
// a free function (`cfg_nblocks`) binds to a namespaced free function. Both count blocks,
// so they must agree, proving the two accessor shapes map to the two C++ call forms.
assert_eq!(
fc.size() as usize,
n,
"member-fn size() disagrees with free-fn cfg_nblocks()"
);
// `fc` drops here: cxx's UniquePtr glue runs qflow_chart_t's destructor, no manual free.
println!("cxx cfg bridge cross-check OK: {n} blocks");
}
// cxx nested-struct bridge: the generated `decode_insn` returns an owned InstructionData (a
// right-sized Vec<OperandData> nesting RegisterData by value, `status` standing in for the raw
// return code). Walk real instructions and validate its internal shape. Skips gracefully off
// x86 (status -2), since the decoder is x86-only.
{
use idakit_sys as sys;
if sys::decode_insn(address.get()).status == -2 {
println!("skipping instruction decode: non-x86 processor (status -2)");
} else {
let mut ea = address.get();
let mut decoded = 0u32;
while decoded < 64 {
let data = sys::decode_insn(ea);
if data.status != 0 {
break;
}
assert!(
data.len > 0,
"a decoded instruction has non-zero length at {ea:#x}"
);
assert_eq!(
data.nops as usize,
data.ops.len(),
"nops vs ops.len() disagree at {ea:#x}"
);
ea += data.len as u64;
decoded += 1;
}
assert!(decoded > 0, "decoded no instructions in the first function");
println!("cxx instruction bridge OK: {decoded} instructions decoded");
}
}
// cxx ExternType bridge: the `range_t` Trivial ExternType crosses by value four ways
// (returned bare, taken by value, a by-value shared-struct field, and a Vec element). Its four
// shapes are cross-checked against each other, then against the qvector<range_t> Opaque path.
{
use idakit_sys as sys;
let ea = address.get();
// range_entry_chunk (by-value return).
let entry =
sys::range_entry_chunk(ea).expect("cxx range_entry_chunk on the first function");
assert!(
entry.end >= entry.start,
"entry chunk end precedes its start"
);
// range_size (by-value argument): a Trivial ExternType passed into C++ by value.
assert_eq!(
sys::range_size(entry),
entry.end - entry.start,
"range_size disagrees with end - start"
);
// range_chunk_info (by-value ExternType field of a shared struct).
let info = sys::range_chunk_info(ea, 0).expect("cxx range_chunk_info(0)");
assert_eq!(info.index, 0, "chunk info index");
assert_eq!(
info.range, entry,
"ChunkInfo.range disagrees with range_entry_chunk"
);
// range_all_chunks (Vec<RangeT>): a Trivial ExternType as a Vec element, one row per chunk.
let chunks = sys::range_all_chunks(ea).expect("cxx range_all_chunks");
assert!(
!chunks.is_empty(),
"a real function has at least an entry chunk"
);
assert_eq!(
chunks.first().copied(),
Some(entry),
"range_all_chunks[0] should be the entry chunk"
);
// Out-of-range chunk index surfaces as Err on the cxx path.
assert!(
sys::range_chunk_info(ea, chunks.len()).is_err(),
"range_chunk_info should Err past the last chunk"
);
// qvector<range_t>: the recipe generalized from scalar to a Trivial-struct
// element. rangevec_build_chunks yields a rangevec_t owned by UniquePtr (so the zero-copy
// borrow ties to a container Rust controls); rangevec_slice borrows it as &[RangeT] with no
// copy. Cross-check element-for-element against the range_all_chunks Vec<RangeT> copy path.
let rv = sys::rangevec_build_chunks(ea).expect("cxx rangevec_build_chunks");
let rvref = rv.as_ref().expect("rangevec UniquePtr is non-null");
assert_eq!(
sys::rangevec_len(rvref),
chunks.len(),
"rangevec_len disagrees with range_all_chunks"
);
let rslice = sys::rangevec_slice(rvref);
assert_eq!(
rslice.len(),
chunks.len(),
"rangevec_slice len disagrees with range_all_chunks"
);
for (i, r) in rslice.iter().enumerate() {
assert_eq!(
*r, chunks[i],
"rangevec_slice[{i}] (zero-copy) disagrees with range_all_chunks (copy)"
);
}
println!(
"cxx range_t ExternType cross-check OK: {} chunks",
chunks.len()
);
}
// cxx bytes bridge: the generated bytes accessors (Result-shaped typed reads, the Vec<u8> range
// read, item navigation, flags, comment) exercised over the first 300 function entries plus the
// database bounds, each result checked for internal consistency.
{
use idakit_sys as sys;
let (min_ea, max_ea) = (sys::min_ea(), sys::max_ea());
assert!(min_ea < max_ea, "database bounds are degenerate");
let sample = sys::func_qty().min(300);
for n in 0..sample {
let ea = sys::func_ea(n);
assert!(
sys::get_item_head(ea) <= ea,
"get_item_head past ea at {ea:#x}"
);
assert!(
sys::get_item_end(ea) > ea,
"get_item_end not past ea at {ea:#x}"
);
let _ = sys::get_flags(ea);
let _ = sys::get_next_head(ea, max_ea);
let _ = sys::get_prev_head(ea, min_ea);
// A typed byte read and a 1-byte range read must agree when both succeed.
if let (Ok(v8), Ok(bytes)) = (sys::get_u8(ea), sys::get_bytes(ea, 1)) {
assert_eq!(
v8, bytes[0],
"get_u8 disagrees with get_bytes[0] at {ea:#x}"
);
}
let _ = sys::get_u64(ea);
let _ = sys::get_cmt(ea, false);
}
println!(
"cxx bytes bridge OK: typed reads, range reads, and navigation over {sample} functions"
);
}
// Best-effort; just exercise the paths (consume the lazy reference cursors).
let _ = first.xrefs_to().count();
let _ = first.xrefs_from().count();
let _ = first.prototype();
// Structured prototype walk: drive idakit_func_type_walk over real functions. Not every
// function is typed, so scan for the first that resolves and validate its shape end-to-end.
{
let mut typed = 0usize;
let mut example = None;
for f in idb.functions().take(2000) {
if let Some(image) = f.prototype_type().expect("prototype walk") {
typed += 1;
if example.is_none() {
example = Some((f.address(), image));
}
}
}
if let Some((ea, image)) = example {
assert!(let TypeShape::Function { ret, params, .. } = image.shape());
// Every child handle resolves against the image's own table.
let _ = image.get(*ret);
for p in params {
let _ = image.get(*p);
}
println!(
"prototype at {ea:#x}: {} params, {typed} typed functions in sample",
params.len()
);
} else {
println!("no typed function prototypes in sample");
}
}
// The cxx opaque-visitor type walk over every named local type: resolve each through the
// production path (`NamedType::resolve` -> the cxx `TypeWalkVisitor`, names crossing as
// `rust::Str`, struct members as a `rust::Slice<const MemberInfo>` of a lifetime-generic shared
// struct with a borrowed `&str` name) and confirm it structures real aggregates, so the
// borrowed-name-in-array fill_struct/fill_enum path is exercised on the corpus.
{
let mut resolved = 0usize;
let mut saw_struct_member = false;
let mut saw_named_or_opaque = false;
for nt in idb.named_types().take(2000) {
let Ok(ty) = nt.resolve() else { continue };
resolved += 1;
for (_, val) in ty.types().iter() {
match &val.shape {
TypeShape::Struct { members, .. } | TypeShape::Union { members, .. } => {
if members.iter().any(|m| !m.name.is_empty()) {
saw_struct_member = true;
}
}
TypeShape::Opaque(_) | TypeShape::Typedef { .. } => saw_named_or_opaque = true,
_ => {}
}
}
}
// Guard against a vacuous pass: the canonical DB carries named types, so the walk must have
// structured something for the coverage to mean anything.
assert!(resolved > 0, "the cxx type walk resolved no named types");
println!(
"cxx type walk resolved {resolved} named types (struct-member names seen: \
{saw_struct_member}, named/opaque refs seen: {saw_named_or_opaque})"
);
}
// cxx opaque-handle bridge: the generated decompile -> UniquePtr<CFunc> + cfunc_* accessors,
// exercised on the first function. The UniquePtr's cxx deleter runs ~cfuncptr_t on drop.
{
use idakit_sys as sys;
if let Ok(cf) = sys::decompile(address.get()) {
let cref = cf.as_ref().expect("non-null cxx handle");
let gc = sys::cfunc_counts(cref);
assert!(
gc.statements >= 0 && gc.expressions >= 0 && gc.calls >= 0,
"ctree counts should be non-negative"
);
let gp = sys::cfunc_pseudocode(cref).expect("cxx pseudocode");
assert!(
!gp.is_empty(),
"pseudocode should be non-empty for a decompiled function"
);
// `cf` (UniquePtr<CFunc>) drops here, running the cxx deleter (~cfuncptr_t / release()).
println!(
"cxx hexrays bridge OK: {} statements, {} expressions, {} calls",
gc.statements, gc.expressions, gc.calls
);
}
}
// Exercise the RAII owned-handle path (best-effort).
match first.decompile() {
Ok(cf) => {
use idakit::decompiler::ctree::{ExpressionKind, NodeRef, StatementKind};
let c = cf.counts();
assert!(c.expressions >= 0 && c.statements >= 0);
println!(
"decompiled first fn: {} statements, {} expressions, {} calls",
c.statements, c.expressions, c.calls
);
// Materialize the whole ctree and cross-check it against the
// independent visitor counts: two separate traversals of the same
// cfunc must agree, node-for-node.
let tree = cf.ctree().expect("ctree extraction");
let root = tree.root();
assert!(let StatementKind::Block(_) = &tree.statement(root).kind);
assert_eq!(
tree.expressions().count(),
c.expressions as usize,
"extracted expression count should match the visitor"
);
assert_eq!(
tree.statements().count(),
c.statements as usize,
"extracted statement count should match the visitor"
);
// Every allocated node is reachable from the root: confirms the
// post-order image and parent wiring are sound.
let reachable = tree.descendants(NodeRef::Statement(root)).count();
assert_eq!(
reachable,
tree.expressions().count() + tree.statements().count(),
"every node should be reachable from the root"
);
println!(
"ctree extracted: {} expressions, {} statements, {} types; root is a block",
tree.expressions().count(),
tree.statements().count(),
tree.types().count()
);
// Round-trip the owned tree back to C-like pseudocode and check it
// against IDA's own rendering. Exact text won't match (IDA has its own
// formatting), but every local our tree references must appear in IDA's
// pseudocode: the names come from the same local table, so a dropped or
// misresolved `Var` surfaces here as a missing name.
let rendered = tree.to_pseudocode();
if let Some(ida_pc) = cf.pseudocode() {
let mut referenced: Vec<String> = tree
.expressions()
.filter_map(|(_, e)| match &e.kind {
ExpressionKind::Var(v) => Some(tree.local(*v).name.clone()),
_ => None,
})
.collect();
referenced.sort();
referenced.dedup();
let missing: Vec<&String> = referenced
.iter()
.filter(|name| !ida_pc.contains(name.as_str()))
.collect();
assert!(
missing.is_empty(),
"local names referenced by the tree but absent from IDA's \
pseudocode (extraction dropped or misresolved a Var): {missing:?}"
);
println!(
"round-trip OK: {} referenced locals all present in IDA's pseudocode",
referenced.len()
);
println!("--- idakit render ---\n{rendered}\n--- IDA pseudocode ---\n{ida_pc}");
} else {
println!("round-trip: IDA pseudocode unavailable; rendered:\n{rendered}");
}
// The still-experimental inline moveit value type CfuncVal mirrors cfuncptr_t
// (qrefcnt_t<cfunc_t>, the decompiler's intrusive-refcounted smart pointer) as a
// pure-moveit stack value (no cxx): the C++ copy-ctor bumps the intrusive refcount and
// the C++ destructor releases it. Deltas, not absolutes, since the cfunc_t may be
// shared/cached.
{
use idakit_sys as sys;
let ea = address.get();
let [i0, i1, i2] = sys::cfunc_moveit_inline_probe(ea)
.expect("moveit inline probe (decompile succeeded above)");
assert_eq!(
i1,
i0 + 1,
"inline moveit copy-ctor must bump refcount ({i0} -> {i1})"
);
assert_eq!(
i2, i0,
"dropping the inline moveit clone must release ({i1} -> {i2})"
);
println!("moveit inline CfuncVal OK: refcnt {i0} -> {i1} (clone) -> {i2} (drop)");
}
}
Err(e) => println!("decompile unavailable ({e})"),
}
// Decompile-failure path: an unmapped address has no function, so the
// kernel returns null and the facade reports the reason. Confirm a real
// reason (sourced from the facade buffer, not a stale qerrno) propagates.
let nowhere = Address::new_const(0xffff_ffff_f000);
match idb.decompile(nowhere) {
Ok(_) => panic!("expected decompile to fail at unmapped {nowhere:#x}"),
Err(e) => {
let msg = e.to_string();
assert!(
msg.contains("no function at address"),
"decompile failure should carry the facade reason, got: {msg}"
);
println!("decompile-failure reason propagated: {msg}");
}
}
// Rename via the write cursor (first's borrow has ended), then confirm.
let renamed = "idakit_roundtrip_probe";
idb.at_mut(address).rename(renamed).expect("rename failed");
let after = idb.function(address).name();
assert_eq!(after.as_str(), renamed, "rename did not stick");
assert!(after.is_user(), "a user rename yields a user name");
idb.at_mut(address)
.set_comment("touched by idakit roundtrip", false)
.expect("set_comment failed");
// Leave the DB as found.
idb.at_mut(address)
.rename(original.as_str())
.expect("restore rename failed");
println!("roundtrip OK: {func_count} funcs, {seg_count} segs, rename/comment verified");
}