Skip to content

Commit

Permalink
Expose "set show" family of functions (#16)
Browse files Browse the repository at this point in the history
* add inf_set_show_ functions
* update comments example
  • Loading branch information
xorpse authored Nov 16, 2024
1 parent 32445b9 commit 8dc31a7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
4 changes: 4 additions & 0 deletions idalib-sys/src/inf_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,21 @@ std::uint8_t idalib_inf_get_cmtflg() { return inf_get_cmtflg(); }
bool idalib_inf_show_repeatables() { return inf_show_repeatables(); }

bool idalib_inf_show_all_comments() { return inf_show_all_comments(); }
bool idalib_inf_set_show_all_comments() { return inf_set_show_all_comments(); }

bool idalib_inf_hide_comments() { return inf_hide_comments(); }

bool idalib_inf_show_src_linnum() { return inf_show_src_linnum(); }

bool idalib_inf_test_mode() { return inf_test_mode(); }
bool idalib_inf_show_hidden_insns() { return inf_show_hidden_insns(); }
bool idalib_inf_set_show_hidden_insns() { return inf_set_show_hidden_insns(); }

bool idalib_inf_show_hidden_funcs() { return inf_show_hidden_funcs(); }
bool idalib_inf_set_show_hidden_funcs() { return inf_set_show_hidden_funcs(); }

bool idalib_inf_show_hidden_segms() { return inf_show_hidden_segms(); }
bool idalib_inf_set_show_hidden_segms() { return inf_set_show_hidden_segms(); }


std::uint8_t idalib_inf_get_limiter() { return inf_get_limiter(); }
Expand Down
8 changes: 7 additions & 1 deletion idalib-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ pub mod inf {
idalib_inf_pack_stkargs, idalib_inf_prefix_show_funcoff, idalib_inf_prefix_show_segaddr,
idalib_inf_prefix_show_stack, idalib_inf_prefix_truncate_opcode_bytes,
idalib_inf_propagate_regargs, idalib_inf_propagate_stkargs, idalib_inf_readonly_idb,
idalib_inf_rename_jumpfunc, idalib_inf_rename_nullsub, idalib_inf_should_create_stkvars,
idalib_inf_rename_jumpfunc, idalib_inf_rename_nullsub, idalib_inf_set_show_all_comments,
idalib_inf_set_show_hidden_funcs, idalib_inf_set_show_hidden_insns,
idalib_inf_set_show_hidden_segms, idalib_inf_should_create_stkvars,
idalib_inf_should_trace_sp, idalib_inf_show_all_comments, idalib_inf_show_auto,
idalib_inf_show_hidden_funcs, idalib_inf_show_hidden_insns, idalib_inf_show_hidden_segms,
idalib_inf_show_line_pref, idalib_inf_show_repeatables, idalib_inf_show_src_linnum,
Expand Down Expand Up @@ -673,12 +675,16 @@ mod ffix {
unsafe fn idalib_inf_get_cmtflg() -> u8;
unsafe fn idalib_inf_show_repeatables() -> bool;
unsafe fn idalib_inf_show_all_comments() -> bool;
unsafe fn idalib_inf_set_show_all_comments() -> bool;
unsafe fn idalib_inf_hide_comments() -> bool;
unsafe fn idalib_inf_show_src_linnum() -> bool;
unsafe fn idalib_inf_test_mode() -> bool;
unsafe fn idalib_inf_show_hidden_insns() -> bool;
unsafe fn idalib_inf_set_show_hidden_insns() -> bool;
unsafe fn idalib_inf_show_hidden_funcs() -> bool;
unsafe fn idalib_inf_set_show_hidden_funcs() -> bool;
unsafe fn idalib_inf_show_hidden_segms() -> bool;
unsafe fn idalib_inf_set_show_hidden_segms() -> bool;
unsafe fn idalib_inf_get_limiter() -> u8;
unsafe fn idalib_inf_is_limiter_thin() -> bool;
unsafe fn idalib_inf_is_limiter_thick() -> bool;
Expand Down
11 changes: 8 additions & 3 deletions idalib/examples/comments_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ fn main() -> anyhow::Result<()> {
println!("Trying to open IDA database...");

// Open IDA database
let idb = IDB::open("./tests/ls")?;
let mut idb = IDB::open("./tests/ls")?;

// Show everything
idb.meta_mut().set_show_all_comments();
idb.meta_mut().set_show_hidden_funcs();
idb.meta_mut().set_show_hidden_insns();
idb.meta_mut().set_show_hidden_segms();

println!("Testing remove_cmt() and get_cmt() (pass 1; clear old comments)");
for (_id, f) in idb.functions() {
Expand Down Expand Up @@ -38,8 +44,7 @@ fn main() -> anyhow::Result<()> {
println!("Testing find_text_iter()");
let results: Vec<_> = idb.find_text_iter("added by idalib").collect();
assert!(!results.is_empty());
// FIXME: text search doesn't display results located in collapsed functions
// assert_eq!(results.len(), idb.functions().count());
assert_eq!(results.len(), idb.functions().count());

println!("Testing append_cmt() and get_cmt()");
for (_id, f) in idb.functions() {
Expand Down
6 changes: 5 additions & 1 deletion idalib/src/idb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::bookmarks::Bookmarks;
use crate::decompiler::CFunction;
use crate::func::{Function, FunctionId};
use crate::insn::{Insn, Register};
use crate::meta::Metadata;
use crate::meta::{Metadata, MetadataMut};
use crate::plugin::Plugin;
use crate::processor::Processor;
use crate::segment::{Segment, SegmentId};
Expand Down Expand Up @@ -93,6 +93,10 @@ impl IDB {
Metadata::new()
}

pub fn meta_mut<'a>(&'a mut self) -> MetadataMut<'a> {
MetadataMut::new()
}

pub fn processor<'a>(&'a self) -> Processor<'a> {
let ptr = unsafe { get_ph() };
Processor::from_ptr(ptr)
Expand Down
28 changes: 28 additions & 0 deletions idalib/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,31 @@ impl<'a> Metadata<'a> {
unsafe { idalib_inf_get_strlit_pref() }
}
}

pub struct MetadataMut<'a> {
_marker: PhantomData<&'a mut IDB>,
}

impl<'a> MetadataMut<'a> {
pub(crate) fn new() -> Self {
Self {
_marker: PhantomData,
}
}

pub fn set_show_all_comments(&mut self) -> bool {
unsafe { idalib_inf_set_show_all_comments() }
}

pub fn set_show_hidden_insns(&mut self) -> bool {
unsafe { idalib_inf_set_show_hidden_insns() }
}

pub fn set_show_hidden_funcs(&mut self) -> bool {
unsafe { idalib_inf_set_show_hidden_funcs() }
}

pub fn set_show_hidden_segms(&mut self) -> bool {
unsafe { idalib_inf_set_show_hidden_segms() }
}
}

0 comments on commit 8dc31a7

Please sign in to comment.