summaryrefslogtreecommitdiff
path: root/rust/src/lib.rs
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-01-21 18:35:20 +0000
committerKyleMiles <krm504@nyu.edu>2021-01-21 19:07:07 +0000
commit2fcacc55d5466a7d17bdc0b3ce988772aa6d0653 (patch)
tree9d0f2ba19117843575936f2b93e0b6a578a84dc8 /rust/src/lib.rs
parenta0da07c5c2860a5bd69921d38e438bbc1d43912f (diff)
cargo fmt and all my changes
Diffstat (limited to 'rust/src/lib.rs')
-rw-r--r--rust/src/lib.rs88
1 files changed, 67 insertions, 21 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 68df9948..bdef8368 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,9 +1,28 @@
+// Copyright 2021 Vector 35 Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! # Warning
+//! > ⚠️ **These bindings are in a very early beta, only have partial support for the core APIs and are still actively under development. Compatibility _will_ break and conventions _will_ change! They are being used for core Binary Ninja features however, so we expect much of what is already there to be reliable enough to build on, just don't be surprised if your plugins/scripts need to hit a moving target.**
+
#[macro_use]
extern crate log;
+pub extern crate binaryninjacore_sys; // For testing functions and stuff
+#[cfg(feature = "ui")]
+pub extern crate binaryninjaui_sys; // For testing functions and stuff
+extern crate libc;
#[cfg(feature = "rayon")]
extern crate rayon;
-extern crate libc;
-extern crate binaryninjacore_sys;
// TODO
// move some options to results
@@ -22,34 +41,58 @@ mod ffi;
pub mod architecture;
pub mod basicblock;
pub mod binaryview;
-pub mod segment;
-pub mod section;
-pub mod symbol;
pub mod callingconvention;
pub mod command;
+pub mod custombinaryview;
+pub mod databuffer;
+pub mod disassembly;
pub mod fileaccessor;
pub mod filemetadata;
+pub mod flowgraph;
pub mod function;
-pub mod platform;
+pub mod headless;
pub mod llil;
-pub mod types;
+pub mod platform;
pub mod rc;
-pub mod headless;
-pub mod string;
+pub mod section;
+pub mod segment;
pub mod settings;
+pub mod string;
+pub mod symbol;
+pub mod types;
-pub use binaryninjacore_sys::BNEndianness as Endianness;
pub use binaryninjacore_sys::BNBranchType as BranchType;
+pub use binaryninjacore_sys::BNEndianness as Endianness;
+
+// Commented out to suppress unused warnings
+// const BN_MAX_INSTRUCTION_LENGTH: u64 = 256;
+// const BN_DEFAULT_NSTRUCTION_LENGTH: u64 = 16;
+// const BN_DEFAULT_OPCODE_DISPLAY: u64 = 8;
+// const BN_MAX_INSTRUCTION_BRANCHES: u64 = 3;
+// const BN_MAX_STORED_DATA_LENGTH: u64 = 0x3fffffff;
+// const BN_NULL_ID: i64 = -1;
+// const BN_INVALID_REGISTER: usize = 0xffffffff;
+// const BN_AUTOCOERCE_EXTERN_PTR: u64 = 0xfffffffd;
+// const BN_NOCOERCE_EXTERN_PTR: u64 = 0xfffffffe;
+// const BN_INVALID_OPERAND: u64 = 0xffffffff;
+// const BN_MAX_STRING_LENGTH: u64 = 128;
+// const BN_MAX_VARIABLE_OFFSET: u64 = 0x7fffffffff;
+// const BN_MAX_VARIABLE_INDEX: u64 = 0xfffff;
+// const BN_MINIMUM_CONFIDENCE: u8 = 1;
+// const BN_HEURISTIC_CONFIDENCE: u8 = 192;
+
+const BN_FULL_CONFIDENCE: u8 = 255;
+const BN_INVALID_EXPR: usize = usize::MAX;
pub mod logger {
- use std::os::raw::{c_void, c_char};
+ use std::os::raw::{c_char, c_void};
use log;
use crate::string::BnStr;
- use binaryninjacore_sys::{BNLogListener, BNUpdateLogListeners};
pub use binaryninjacore_sys::BNLogLevel as Level;
+ use binaryninjacore_sys::{BNLogListener, BNUpdateLogListeners};
struct Logger;
static LOGGER: Logger = Logger;
@@ -60,21 +103,22 @@ pub mod logger {
}
fn log(&self, record: &log::Record) {
- use binaryninjacore_sys::BNLog;
- use std::ffi::CString;
use self::Level::*;
+ use binaryninjacore_sys::BNLog;
use log::Level;
+ use std::ffi::CString;
let level = match record.level() {
Level::Error => ErrorLog,
Level::Warn => WarningLog,
Level::Info => InfoLog,
- Level::Debug |
- Level::Trace => DebugLog,
+ Level::Debug | Level::Trace => DebugLog,
};
if let Ok(msg) = CString::new(format!("{}", record.args())) {
- unsafe { BNLog(level, msg.as_ptr()); }
+ unsafe {
+ BNLog(level, msg.as_ptr());
+ }
};
}
@@ -134,9 +178,7 @@ pub mod logger {
BNUpdateLogListeners();
}
- LogGuard {
- ctxt: raw,
- }
+ LogGuard { ctxt: raw }
}
extern "C" fn cb_log<L>(ctxt: *mut c_void, level: Level, msg: *const c_char)
@@ -158,7 +200,7 @@ pub mod logger {
listener.close();
})
}
-
+
extern "C" fn cb_level<L>(ctxt: *mut c_void) -> Level
where
L: LogListener,
@@ -169,3 +211,7 @@ pub mod logger {
})
}
}
+
+pub fn version() -> string::BnString {
+ unsafe { string::BnString::from_raw(binaryninjacore_sys::BNGetVersionString()) }
+}