Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion idalib-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ include_cpp! {
generate!("is_in_nlist")
generate!("is_public_name")
generate!("is_weak_name")
generate!("set_name")

}

pub mod hexrays {
Expand Down Expand Up @@ -1234,7 +1236,7 @@ pub mod nalt {
pub mod name {
pub use super::ffi::{
get_nlist_ea, get_nlist_idx, get_nlist_name, get_nlist_size, is_in_nlist, is_public_name,
is_weak_name,
is_weak_name, set_name,
};
}

Expand Down
20 changes: 19 additions & 1 deletion idalib/src/idb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ffi::ida::{
};
use crate::ffi::insn::decode;
use crate::ffi::loader::find_plugin;
use crate::ffi::name::set_name;
use crate::ffi::processor::get_ph;
use crate::ffi::search::{idalib_find_defined, idalib_find_imm, idalib_find_text};
use crate::ffi::segment::{get_segm_by_name, get_segm_qty, getnseg, getseg};
Expand All @@ -28,7 +29,7 @@ use crate::decompiler::CFunction;
use crate::func::{Function, FunctionId};
use crate::insn::{Insn, Register};
use crate::meta::{Metadata, MetadataMut};
use crate::name::NameList;
use crate::name::{NameList, SetNameFlags};
use crate::plugin::Plugin;
use crate::processor::Processor;
use crate::segment::{Segment, SegmentId};
Expand Down Expand Up @@ -343,6 +344,23 @@ impl IDB {
}
}

pub fn set_name(
&self,
ea: Address,
name: impl AsRef<str>,
flags: SetNameFlags,
) -> Result<(), IDAError> {
let c_name = CString::new(name.as_ref()).map_err(IDAError::ffi)?;

if unsafe { set_name(ea.into(), c_name.as_ptr(), flags.bits().into()) } {
return Ok(());
}

Err(IDAError::ffi_with(format!(
"failed to set name with {flags:?} at {ea:#x}"
)))
}

pub fn get_cmt(&self, ea: Address) -> Option<String> {
self.get_cmt_with(ea, false)
}
Expand Down
27 changes: 26 additions & 1 deletion idalib/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ bitflags! {
}
}

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SetNameFlags: i32 {
const SN_CHECK = 0x00;
const SN_NOCHECK = 0x01;
const SN_PUBLIC = 0x02;
const SN_NON_PUBLIC = 0x04;
const SN_WEAK = 0x08;
const SN_NON_WEAK = 0x10;
const SN_AUTO = 0x20;
const SN_NON_AUTO = 0x40;
const SN_NOLIST = 0x80;
const SN_NOWARN = 0x100;
const SN_LOCAL = 0x200;
const SN_IDBENC = 0x400;
const SN_FORCE = 0x800;
const SN_NODUMMY = 0x1000;
const SN_DELTAIL = 0x2000;
const SN_MULTI = 0x4000;
const SN_MULTI_FORCE = 0x8000;
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Name {
address: Address,
Expand Down Expand Up @@ -66,7 +89,9 @@ impl<'a> NameList<'a> {
return None;
}

let name = unsafe { CStr::from_ptr(name) }.to_string_lossy().into_owned();
let name = unsafe { CStr::from_ptr(name) }
.to_string_lossy()
.into_owned();

let mut properties = NameProperties::empty();

Expand Down