summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-04-18 12:38:09 -0400
committerKyleMiles <krm504@nyu.edu>2023-07-10 12:58:35 -0400
commit6325884782a47e0c89154cf7ce0952368e25ea2a (patch)
treeaacb435dc9e386035b75471715abcc912ce18697 /rust/src
parent068a2ff42ef4e15e67d2904166e53a51420b65a1 (diff)
DWARF Import DebugInfo Plugin
Resolves #3206
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/lib.rs1
-rw-r--r--rust/src/string.rs6
-rw-r--r--rust/src/templatesimplifier.rs15
3 files changed, 22 insertions, 0 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index f5d96592..7039a69d 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -162,6 +162,7 @@ pub mod settings;
pub mod string;
pub mod symbol;
pub mod tags;
+pub mod templatesimplifier;
pub mod types;
use std::path::PathBuf;
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 21972b34..5bfddcee 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -33,6 +33,8 @@ pub(crate) fn raw_to_string(ptr: *const raw::c_char) -> Option<String> {
}
}
+/// These are strings that the core will both allocate and free.
+/// We just have a reference to these strings and want to be able use them, but aren't responsible for cleanup
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[repr(C)]
pub struct BnStr {
@@ -95,6 +97,10 @@ pub struct BnString {
/// Received from a variety of core function calls, and
/// must be used when giving strings to the core from many
/// core-invoked callbacks.
+///
+/// These are strings we're responsible for freeing, such as
+/// strings allocated by the core and given to us through the API
+/// and then forgotten about by the core.
impl BnString {
pub fn new<S: BnStrCompatible>(s: S) -> Self {
use binaryninjacore_sys::BNAllocString;
diff --git a/rust/src/templatesimplifier.rs b/rust/src/templatesimplifier.rs
new file mode 100644
index 00000000..2f7bba92
--- /dev/null
+++ b/rust/src/templatesimplifier.rs
@@ -0,0 +1,15 @@
+use crate::{
+ string::{BnStrCompatible, BnString},
+ types::{QualifiedName},
+};
+use binaryninjacore_sys::{BNRustSimplifyStrToFQN, BNRustSimplifyStrToStr};
+
+pub fn simplify_str_to_str<S: BnStrCompatible>(input: S) -> BnString {
+ let name = input.into_bytes_with_nul();
+ unsafe { BnString::from_raw(BNRustSimplifyStrToStr(name.as_ref().as_ptr() as *mut _)) }
+}
+
+pub fn simplify_str_to_fqn<S: BnStrCompatible>(input: S, simplify: bool) -> QualifiedName {
+ let name = input.into_bytes_with_nul();
+ unsafe { QualifiedName(BNRustSimplifyStrToFQN(name.as_ref().as_ptr() as *mut _, simplify)) }
+}