Skip to content

Commit 1f0d13f

Browse files
committed
fix build on newest stable
1 parent 7f1069d commit 1f0d13f

3 files changed

Lines changed: 25 additions & 39 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ binary-search = "0.1.2"
2626
# Dev
2727
# binaryninja = { git = "https://github.com/Vector35/binaryninja-api", branch = "dev" }
2828
# Stable
29-
binaryninja = { git = "https://github.com/Vector35/binaryninja-api", branch = "master" }
29+
binaryninja = { git = "https://github.com/Vector35/binaryninja-api", tag = "v5.0.7486-stable" }

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ Check the blog post above for a step-by-step.
4141

4242
Checkout the branch of the repository matching the channel of binja you are building for.
4343

44+
If necessary, adjust the `binaryninja` dependency line in `Cargo.toml` to refer to your specific desired version, e.g. replace `branch = "master"` with ` tag = "v5.0.7486-stable"`
45+
4446
You are now one `cargo b` away from greatness.

src/lib.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ use binary_search::{binary_search, Direction};
3131
use binaryninja::settings::Settings;
3232
use binaryninja::{
3333
architecture::Architecture,
34-
binaryninjacore_sys::{BNBinaryView, BNFreeRelocationRanges, BNGetRelocationRanges},
35-
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
34+
binary_view::{BinaryView, BinaryViewBase, BinaryViewExt},
3635
command::{self, AddressCommand, Command},
3736
};
3837

@@ -287,27 +286,13 @@ trait FromSignature {
287286
}
288287

289288
fn get_relocation_ranges(bv: &BinaryView) -> Vec<Range<u64>> {
290-
let mut count = 0usize;
291-
let ptr = unsafe {
292-
BNGetRelocationRanges(
293-
*std::mem::transmute::<_, *mut *mut BNBinaryView>(bv),
294-
&mut count as *mut usize,
295-
)
296-
};
297-
298-
let ranges = unsafe { std::slice::from_raw_parts(ptr, count) };
299-
300-
let ret = ranges
289+
bv.relocation_ranges()
301290
.iter()
302291
.map(|range| Range {
303292
start: range.start,
304293
end: range.end,
305294
})
306-
.collect::<Vec<_>>();
307-
308-
unsafe { BNFreeRelocationRanges(ptr) };
309-
310-
ret
295+
.collect::<Vec<_>>()
311296
}
312297

313298
fn get_code(bv: &BinaryView) -> Vec<(u64, Vec<u8>)> {
@@ -558,7 +543,7 @@ fn create_pattern_internal_binarysearch(
558543
// the range we were in at the start is still the same range as we are currently scanning
559544
if !bv.functions_containing(addr as u64).iter().any(|func| {
560545
func.address_ranges().iter().any(|range| {
561-
range.start() <= addr && range.end() >= (instr_addr + instr.len() as u64) as u64
546+
range.start <= addr && range.end >= (instr_addr + instr.len() as u64) as u64
562547
})
563548
}) {
564549
break;
@@ -692,7 +677,7 @@ fn create_pattern_internal(
692677
// the range we were in at the start is still the same range as we are currently scanning
693678
if !bv.functions_containing(addr as u64).iter().any(|func| {
694679
func.address_ranges().iter().any(|range| {
695-
range.start() <= addr && range.end() >= (instr_addr + instr.len() as u64) as u64
680+
range.start <= addr && range.end >= (instr_addr + instr.len() as u64) as u64
696681
})
697682
}) {
698683
break;
@@ -790,26 +775,24 @@ fn get_clipboard_contents() -> Result<String, Box<dyn std::error::Error>> {
790775
ctx.get_contents()
791776
}
792777

793-
fn get_maximum_signature_size(bv: &BinaryView) -> u64 {
794-
Settings::new("default").get_integer("coolsigmaker.maximum_size", Some(bv), None)
778+
fn get_maximum_signature_size(_bv: &BinaryView) -> u64 {
779+
Settings::new().get_integer("coolsigmaker.maximum_size")
795780
}
796781

797-
fn get_include_operands(bv: &BinaryView) -> bool {
798-
Settings::new("default").get_bool("coolsigmaker.include_operands", Some(bv), None)
782+
fn get_include_operands(_bv: &BinaryView) -> bool {
783+
Settings::new().get_bool("coolsigmaker.include_operands")
799784
}
800785

801-
fn get_binary_search(bv: &BinaryView) -> bool {
802-
Settings::new("default").get_bool("coolsigmaker.binary_search", Some(bv), None)
786+
fn get_binary_search(_bv: &BinaryView) -> bool {
787+
Settings::new().get_bool("coolsigmaker.binary_search")
803788
}
804789

805-
fn get_signature_type(bv: &BinaryView) -> SignatureType {
806-
SignatureType::from_str(
807-
Settings::new("default")
808-
.get_string("coolsigmaker.sig_type", Some(bv), None)
809-
.as_str(),
810-
)
811-
.map_err(|_| log::error!("invalid value for coolsigmaker.sig_type! falling back to default!"))
812-
.unwrap_or(SignatureType::IDATwo)
790+
fn get_signature_type(_bv: &BinaryView) -> SignatureType {
791+
SignatureType::from_str(Settings::new().get_string("coolsigmaker.sig_type").as_str())
792+
.map_err(|_| {
793+
log::error!("invalid value for coolsigmaker.sig_type! falling back to default!")
794+
})
795+
.unwrap_or(SignatureType::IDATwo)
813796
}
814797

815798
fn register_settings() {
@@ -873,7 +856,7 @@ fn register_settings() {
873856
settings.register_setting_json(name, properties);
874857
}
875858

876-
let settings = Settings::new("default");
859+
let settings = Settings::new();
877860

878861
settings.register_group("coolsigmaker", "CoolSigMaker");
879862

@@ -987,7 +970,8 @@ impl Command for SigFinderCommand {
987970

988971
#[no_mangle]
989972
pub extern "C" fn CorePluginInit() -> bool {
990-
binaryninja::logger::init(log::LevelFilter::Info).unwrap();
973+
let logger = binaryninja::logger::Logger::new("CoolSigMaker");
974+
logger.with_level(log::LevelFilter::Info).init();
991975

992976
// TODO: (maybe) if signature not found, maybe go back a few instructions and attempt to create a signature with an offset.
993977
// TODO: introduce a setting for "dumb" searches, where we also search non-executable segments for uniqueness, incase the user doesn't want to check the segments before scanning them.
@@ -1013,13 +997,13 @@ pub extern "C" fn CorePluginInit() -> bool {
1013997

1014998
register_settings();
1015999

1016-
command::register_for_address(
1000+
command::register_command_for_address(
10171001
"CSM - Create Signature from Address",
10181002
"Creates a Signature from the currently selected address",
10191003
SigMakerCommand {},
10201004
);
10211005

1022-
command::register(
1006+
command::register_command(
10231007
"CSM - Find Signature",
10241008
"Finds a signature in the binary.",
10251009
SigFinderCommand {},

0 commit comments

Comments
 (0)