Skip to content

Commit 650cb22

Browse files
committed
More cleanup regarding BnString in the Rust API
- Removed `to_string` shortcut from `BnString`. - Misc formatting
1 parent 884839e commit 650cb22

File tree

20 files changed

+49
-73
lines changed

20 files changed

+49
-73
lines changed

plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl DebugInfoBuilder {
622622
.items
623623
.len()
624624
{
625-
func.full_name = Some(symbol_full_name.to_string());
625+
func.full_name = Some(symbol_full_name.to_string_lossy().to_string());
626626
}
627627
}
628628
}

plugins/dwarf/dwarf_import/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(crate) fn parse_function_entry<R: ReaderType>(
117117
if let Ok(demangled) = sym.demangle(demangle_options) {
118118
let cleaned = abi_regex.replace_all(&demangled, "");
119119
let simplified = simplify_str_to_str(&cleaned);
120-
full_name = Some(simplified.to_string());
120+
full_name = Some(simplified.to_string_lossy().to_string());
121121
}
122122
}
123123
}

plugins/dwarf/dwarf_import/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ fn recover_names_internal<R: ReaderType>(
234234
.collect::<Vec<String>>()
235235
.join("::"),
236236
)
237+
.to_string_lossy()
237238
.to_string(),
238239
);
239240
}
@@ -251,6 +252,7 @@ fn recover_names_internal<R: ReaderType>(
251252
.collect::<Vec<String>>()
252253
.join("::"),
253254
)
255+
.to_string_lossy()
254256
.to_string(),
255257
);
256258
}

plugins/warp/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub struct TypeRefID(u64);
439439
impl From<&BNNamedTypeReference> for TypeRefID {
440440
fn from(value: &BNNamedTypeReference) -> Self {
441441
let mut hasher = DefaultHasher::new();
442-
hasher.write(value.id().to_bytes());
442+
hasher.write(value.id().as_bytes());
443443
Self(hasher.finish())
444444
}
445445
}

plugins/warp/src/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use warp::symbol::{Symbol, SymbolModifiers};
3535
pub fn from_bn_symbol(raw_symbol: &BNSymbol) -> Symbol {
3636
// TODO: Use this?
3737
let _is_export = raw_symbol.external();
38-
let symbol_name = raw_symbol.raw_name().to_string();
38+
let symbol_name = raw_symbol.raw_name().to_string_lossy().to_string();
3939
match raw_symbol.sym_type() {
4040
BNSymbolType::ImportAddress => {
4141
Symbol::new(

plugins/warp/src/plugin/copy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ impl FunctionCommand for CopyFunctionGUID {
1414
};
1515
let guid = cached_function_guid(func, &llil);
1616
log::info!(
17-
"Function GUID for {}... {}",
18-
func.symbol().short_name().to_string(),
17+
"Function GUID for {:?}... {}",
18+
func.symbol().short_name(),
1919
guid
2020
);
2121
if let Ok(mut clipboard) = arboard::Clipboard::new() {

rust/src/binary_view/memory_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ impl MemoryMap {
2121
/// JSON string representation of the base [`MemoryMap`], consisting of unresolved auto and user segments.
2222
pub fn base_description(&self) -> String {
2323
let desc_raw = unsafe { BNGetBaseMemoryMapDescription(self.view.handle) };
24-
unsafe { BnString::from_raw(desc_raw) }.to_string()
24+
unsafe { BnString::into_string(desc_raw) }
2525
}
2626

2727
/// JSON string representation of the [`MemoryMap`].
2828
pub fn description(&self) -> String {
2929
let desc_raw = unsafe { BNGetMemoryMapDescription(self.view.handle) };
30-
unsafe { BnString::from_raw(desc_raw) }.to_string()
30+
unsafe { BnString::into_string(desc_raw) }
3131
}
3232

3333
// When enabled, the memory map will present a simplified, logical view that merges and abstracts virtual memory

rust/src/collaboration/remote.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Remote {
167167
&self,
168168
username: U,
169169
password: P,
170-
) -> Option<BnString> {
170+
) -> Option<String> {
171171
let username = username.to_cstr();
172172
let password = password.to_cstr();
173173
let token = unsafe {
@@ -180,7 +180,7 @@ impl Remote {
180180
if token.is_null() {
181181
None
182182
} else {
183-
Some(unsafe { BnString::from_raw(token) })
183+
Some(unsafe { BnString::into_string(token) })
184184
}
185185
}
186186

@@ -226,7 +226,8 @@ impl Remote {
226226
};
227227
let username = options.username.to_cstr();
228228
let token = token.to_cstr();
229-
let success = unsafe { BNRemoteConnect(self.handle.as_ptr(), username.as_ptr(), token.as_ptr()) };
229+
let success =
230+
unsafe { BNRemoteConnect(self.handle.as_ptr(), username.as_ptr(), token.as_ptr()) };
230231
success.then_some(()).ok_or(())
231232
}
232233

rust/src/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ impl Database {
147147
}
148148

149149
/// Get a dictionary of all globals
150-
pub fn globals(&self) -> HashMap<String, String> {
150+
pub fn globals(&self) -> HashMap<String, BnString> {
151151
self.global_keys()
152152
.iter()
153-
.filter_map(|key| Some((key.to_string(), self.read_global(key)?.to_string())))
153+
.filter_map(|key| Some((key.to_string(), self.read_global(key)?)))
154154
.collect()
155155
}
156156

rust/src/debuginfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ unsafe impl CoreArrayProviderInner for DebugInfoParser {
319319
///
320320
/// Functions will not be created if an address is not provided, but will be able to be queried from debug info for later user analysis.
321321
pub struct DebugFunctionInfo {
322+
// TODO: These need to be BnString if we want to support invalid UTF-8
322323
short_name: Option<String>,
323324
full_name: Option<String>,
324325
raw_name: Option<String>,

0 commit comments

Comments
 (0)