-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the array implementation using GAT
- Loading branch information
Showing
18 changed files
with
224 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use binaryninjacore_sys::*; | ||
|
||
use crate::{ | ||
binaryview::BinaryView, | ||
disassembly::{DisassemblyTextLine, InstructionTextToken}, | ||
rc::Array, | ||
types::Type, | ||
}; | ||
|
||
//pub struct BNCustomDataRenderer { | ||
// pub context: *mut ::std::os::raw::c_void, | ||
// pub freeObject: ::std::option::Option<unsafe extern "C" fn(ctxt: *mut ::std::os::raw::c_void)>, | ||
// pub isValidForData: ::std::option::Option< | ||
// unsafe extern "C" fn( | ||
// ctxt: *mut ::std::os::raw::c_void, | ||
// view: *mut BNBinaryView, | ||
// addr: u64, | ||
// type_: *mut BNType, | ||
// typeCtx: *mut BNTypeContext, | ||
// ctxCount: usize, | ||
// ) -> bool, | ||
// >, | ||
// pub getLinesForData: ::std::option::Option< | ||
// unsafe extern "C" fn( | ||
// ctxt: *mut ::std::os::raw::c_void, | ||
// view: *mut BNBinaryView, | ||
// addr: u64, | ||
// type_: *mut BNType, | ||
// prefix: *const BNInstructionTextToken, | ||
// prefixCount: usize, | ||
// width: usize, | ||
// count: *mut usize, | ||
// typeCtx: *mut BNTypeContext, | ||
// ctxCount: usize, | ||
// ) -> *mut BNDisassemblyTextLine, | ||
// >, | ||
// pub freeLines: ::std::option::Option< | ||
// unsafe extern "C" fn( | ||
// ctx: *mut ::std::os::raw::c_void, | ||
// lines: *mut BNDisassemblyTextLine, | ||
// count: usize, | ||
// ), | ||
// >, | ||
//} | ||
|
||
pub struct DataRenderer(*mut BNDataRenderer); | ||
|
||
pub fn new_data_renderer() -> DataRenderer { | ||
let dr = Box::new(BNCustomDataRenderer { | ||
context: std::ptr::null_mut(), | ||
freeObject: Some(default_free_object), | ||
isValidForData: None, | ||
getLinesForData: None, | ||
freeLines: None, | ||
}); | ||
let handle = unsafe { BNCreateDataRenderer(Box::leak(dr)) }; | ||
assert!(!handle.is_null()); | ||
DataRenderer(handle) | ||
} | ||
|
||
unsafe extern "C" fn default_free_object(ctxt: *mut ::std::os::raw::c_void) { | ||
drop(Box::from_raw(ctxt)) | ||
} | ||
|
||
unsafe extern "C" fn default_free_lines( | ||
ctx: *mut ::std::os::raw::c_void, | ||
lines: *mut BNDisassemblyTextLine, | ||
count: usize, | ||
) { | ||
let lines: *mut [BNDisassemblyTextLine] = core::ptr::slice_from_raw_parts_mut(lines, count); | ||
let lines: Box<[BNDisassemblyTextLine]> = Box::from_raw(lines); | ||
// TODO: make DisassemblyTextLine transparent | ||
let lines: Box<[DisassemblyTextLine]> = core::mem::transmute(lines); | ||
for _ in 0..count { | ||
drop(Box::from_raw(ctx)) | ||
} | ||
} | ||
|
||
pub trait CustomDataRenderer { | ||
fn is_valid_for_data( | ||
// TODO mutable??? | ||
&mut self, | ||
view: &BinaryView, | ||
addr: u64, | ||
type_: *mut BNType, | ||
typeCtx: *mut BNTypeContext, | ||
ctxCount: usize, | ||
) -> bool; | ||
fn get_lines_for_data( | ||
&mut self, | ||
view: &BNBinaryView, | ||
addr: u64, | ||
type_: *mut BNType, | ||
prefix: Box<[InstructionTextToken]>, | ||
width: usize, | ||
count: *mut usize, | ||
typeCtx: *mut BNTypeContext, | ||
ctxCount: usize, | ||
) -> Vec<DisassemblyTextLine>; | ||
} | ||
|
||
pub struct MyDataRenderer {} | ||
|
||
impl CustomDataRenderer for MyDataRenderer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.