Skip to content

Commit 7945efd

Browse files
committed
[Rust] Parent type related modules to types
- Improves the discoverability - Seperated out much of the types code into more subfiles, such as `structure`, `enumeration` and `qualified_name
1 parent 4d72e4c commit 7945efd

22 files changed

+1235
-1199
lines changed

rust/examples/dump_type_library.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
use binaryninja::binary_view::BinaryView;
44
use binaryninja::file_metadata::FileMetadata;
5-
use binaryninja::type_library::TypeLibrary;
6-
use binaryninja::type_printer::{CoreTypePrinter, TokenEscapingType};
5+
use binaryninja::types::{CoreTypePrinter, TokenEscapingType, TypeLibrary};
76

87
fn main() {
98
let type_lib_str = std::env::args().nth(1).expect("No type library provided");

rust/examples/type_printer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use binaryninja::type_printer::{CoreTypePrinter, TokenEscapingType};
2-
use binaryninja::types::{MemberAccess, MemberScope, Structure, StructureMember, Type};
1+
use binaryninja::types::{
2+
CoreTypePrinter, MemberAccess, MemberScope, Structure, StructureMember, TokenEscapingType, Type,
3+
};
34

45
fn main() {
56
println!("Starting session...");

rust/src/binary_view.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ use crate::settings::Settings;
4949
use crate::string::*;
5050
use crate::symbol::{Symbol, SymbolType};
5151
use crate::tags::{Tag, TagType};
52-
use crate::type_container::TypeContainer;
53-
use crate::type_library::TypeLibrary;
5452
use crate::types::{
5553
NamedTypeReference, QualifiedName, QualifiedNameAndType, QualifiedNameTypeAndId, Type,
54+
TypeArchive, TypeContainer, TypeLibrary,
5655
};
5756
use crate::variable::DataVariable;
5857
use crate::Endianness;

rust/src/collaboration/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::progress::{NoProgressCallback, ProgressCallback};
1313
use crate::project::file::ProjectFile;
1414
use crate::rc::Ref;
1515
use crate::string::{raw_to_string, BnString, IntoCStr};
16-
use crate::type_archive::{TypeArchive, TypeArchiveMergeConflict};
16+
use crate::types::{TypeArchive, TypeArchiveMergeConflict};
1717

1818
/// Get the default directory path for a remote Project. This is based off the Setting for
1919
/// collaboration.directory, the project's id, and the project's remote's id.

rust/src/component.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use crate::binary_view::{BinaryView, BinaryViewExt};
2-
use crate::function::Function;
3-
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
4-
use crate::string::{BnString, IntoCStr};
5-
use crate::types::ComponentReferencedType;
61
use std::ffi::c_char;
72
use std::fmt::Debug;
83
use std::ptr::NonNull;
94

10-
use crate::variable::DataVariable;
115
use binaryninjacore_sys::*;
126

7+
use crate::binary_view::{BinaryView, BinaryViewExt};
8+
use crate::function::Function;
9+
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
10+
use crate::string::{BnString, IntoCStr};
11+
use crate::types::Type;
12+
use crate::variable::DataVariable;
13+
1314
pub struct ComponentBuilder {
1415
view: Ref<BinaryView>,
1516
parent: Option<String>,
@@ -304,3 +305,24 @@ unsafe impl CoreArrayProviderInner for Component {
304305
Guard::new(Self::from_raw(raw_ptr), context)
305306
}
306307
}
308+
309+
// TODO: Remove this struct, or make it not a ZST with a terrible array provider.
310+
/// ZST used only for `Array<ComponentReferencedType>`.
311+
pub struct ComponentReferencedType;
312+
313+
impl CoreArrayProvider for ComponentReferencedType {
314+
type Raw = *mut BNType;
315+
type Context = ();
316+
type Wrapped<'a> = &'a Type;
317+
}
318+
319+
unsafe impl CoreArrayProviderInner for ComponentReferencedType {
320+
unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) {
321+
BNComponentFreeReferencedTypes(raw, count)
322+
}
323+
324+
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> {
325+
// SAFETY: &*mut BNType == &Type (*mut BNType == Type)
326+
std::mem::transmute(raw)
327+
}
328+
}

rust/src/language_representation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use crate::high_level_il::{HighLevelExpressionIndex, HighLevelILFunction};
1414
use crate::line_formatter::CoreLineFormatter;
1515
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref, RefCountable};
1616
use crate::string::{BnString, IntoCStr};
17-
use crate::type_parser::CoreTypeParser;
18-
use crate::type_printer::CoreTypePrinter;
17+
use crate::types::{CoreTypeParser, CoreTypePrinter};
1918

2019
pub type InstructionTextTokenContext = BNInstructionTextTokenContext;
2120
pub type ScopeType = BNScopeType;

rust/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ pub mod string;
7979
pub mod symbol;
8080
pub mod tags;
8181
pub mod template_simplifier;
82-
pub mod type_archive;
83-
pub mod type_container;
84-
pub mod type_library;
85-
pub mod type_parser;
86-
pub mod type_printer;
8782
pub mod types;
8883
pub mod update;
8984
pub mod variable;

rust/src/platform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
//! Contains all information related to the execution environment of the binary, mainly the calling conventions used
1616
17-
use crate::type_container::TypeContainer;
18-
use crate::type_parser::{TypeParserError, TypeParserErrorSeverity, TypeParserResult};
17+
use crate::types::{
18+
TypeContainer, TypeLibrary, TypeParserError, TypeParserErrorSeverity, TypeParserResult,
19+
};
1920
use crate::{
2021
architecture::{Architecture, CoreArchitecture},
2122
calling_convention::CoreCallingConvention,
2223
rc::*,
2324
string::*,
24-
type_library::TypeLibrary,
2525
types::QualifiedNameAndType,
2626
};
2727
use binaryninjacore_sys::*;

rust/src/string.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use std::ops::Deref;
2424
use std::path::{Path, PathBuf};
2525

2626
use crate::rc::*;
27-
use crate::type_archive::TypeArchiveSnapshotId;
28-
use crate::types::QualifiedName;
2927

3028
// TODO: Remove or refactor this.
3129
pub(crate) fn raw_to_string(ptr: *const c_char) -> Option<String> {
@@ -263,14 +261,6 @@ impl IntoCStr for Cow<'_, str> {
263261
}
264262
}
265263

266-
impl IntoCStr for &QualifiedName {
267-
type Result = CString;
268-
269-
fn to_cstr(self) -> Self::Result {
270-
self.to_string().to_cstr()
271-
}
272-
}
273-
274264
impl IntoCStr for PathBuf {
275265
type Result = CString;
276266

@@ -288,14 +278,6 @@ impl IntoCStr for &Path {
288278
}
289279
}
290280

291-
impl IntoCStr for TypeArchiveSnapshotId {
292-
type Result = CString;
293-
294-
fn to_cstr(self) -> Self::Result {
295-
self.to_string().to_cstr()
296-
}
297-
}
298-
299281
pub trait IntoJson {
300282
type Output: IntoCStr;
301283

0 commit comments

Comments
 (0)