Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Guard API and reduce its use in CoreArrayProvider #5880

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8589a3
Delete duplicate rust example
emesare Jul 28, 2024
248bfd4
Untrack Cargo.lock for rust libraries
emesare Jul 28, 2024
a5a2c75
Add MSRV field to Cargo.toml
emesare Jul 28, 2024
472bca1
Misc changes to rust README
emesare Jul 28, 2024
73d58a0
Add FindRust cmake utility
emesare Jul 29, 2024
8a24a43
Link core in rust
emesare Jul 29, 2024
d4df5ca
Use /bin/cat as the example binary in docs
emesare Jul 29, 2024
f2d7542
Fix crash when using projects API in rust with enterprise
emesare Jul 29, 2024
995ec20
Canonicalize path in `create_delete_empty` test
emesare Jul 29, 2024
4b686d2
Mark well-formed doc snippets as runnable in rust api
emesare Jul 29, 2024
b93b2ce
Revert temporary fix for enterprise crashing on rust project API
emesare Jul 29, 2024
db2ee69
Fix project tests in rust accessing to the same single project file
emesare Jul 29, 2024
3bdc4ef
Remove vendored pdb crate
emesare Jul 29, 2024
00a1ee5
Remove Cargo.lock from examples
emesare Jul 29, 2024
1cbfb03
Format rust api
emesare Jul 30, 2024
e2a57bb
improve the CustomBinaryView init process
rbran May 6, 2024
bdbd96a
Reference type within rust docs
emesare Jul 30, 2024
dc4a204
Update lib.rs docs on building/linking a plugin or script
emesare Jul 30, 2024
21fd88d
Reference types in BnString docs
emesare Jul 31, 2024
ec43516
Pass length to free register list callback
emesare Aug 1, 2024
ce5995c
Pass length to free flag conditions list callback and remove libc fro…
emesare Aug 1, 2024
9bddf13
Simplify `Guard` API and reduce its use in `CoreArrayProvider`
mkrasnitski Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ plugins/
rust/**/*.swp
rust/**/*.rs.bk
rust/target/
rust/binaryninjacore-sys/target/
rust/examples/*/target/
rust/examples/dwarf/*/target/
rust/**/*/target/
rust/binaryninjacore-sys/Cargo.lock
rust/Cargo.lock

# Debugger docs
docs/img/debugger
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@
[submodule "arch/x86/mbuild"]
path = arch/x86/mbuild
url = https://github.com/intelxed/mbuild.git
[submodule "rust/examples/pdb-ng/pdb-0.8.0-patched"]
path = rust/examples/pdb-ng/pdb-0.8.0-patched
url = https://github.com/Vector35/pdb-rs.git
1 change: 0 additions & 1 deletion arch/riscv/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ BNFlagConditionForSemanticClass* Architecture::GetFlagConditionsForSemanticFlagG
}


void Architecture::FreeFlagConditionsForSemanticFlagGroupCallback(void*, BNFlagConditionForSemanticClass* conditions)
void Architecture::FreeFlagConditionsForSemanticFlagGroupCallback(void*, BNFlagConditionForSemanticClass* conditions, size_t)
{
delete[] conditions;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ size_t Architecture::GetSemanticFlagGroupLowLevelILCallback(void* ctxt, uint32_t
}


void Architecture::FreeRegisterListCallback(void*, uint32_t* regs)
void Architecture::FreeRegisterListCallback(void*, uint32_t* regs, size_t)
{
delete[] regs;
}
Expand Down
6 changes: 3 additions & 3 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7743,7 +7743,7 @@ namespace BinaryNinja {
static BNFlagConditionForSemanticClass* GetFlagConditionsForSemanticFlagGroupCallback(
void* ctxt, uint32_t semGroup, size_t* count);
static void FreeFlagConditionsForSemanticFlagGroupCallback(
void* ctxt, BNFlagConditionForSemanticClass* conditions);
void* ctxt, BNFlagConditionForSemanticClass* conditions, size_t count);
static uint32_t* GetFlagsWrittenByFlagWriteTypeCallback(void* ctxt, uint32_t writeType, size_t* count);
static uint32_t GetSemanticClassForFlagWriteTypeCallback(void* ctxt, uint32_t writeType);
static size_t GetFlagWriteLowLevelILCallback(void* ctxt, BNLowLevelILOperation op, size_t size,
Expand All @@ -7752,7 +7752,7 @@ namespace BinaryNinja {
static size_t GetFlagConditionLowLevelILCallback(
void* ctxt, BNLowLevelILFlagCondition cond, uint32_t semClass, BNLowLevelILFunction* il);
static size_t GetSemanticFlagGroupLowLevelILCallback(void* ctxt, uint32_t semGroup, BNLowLevelILFunction* il);
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs);
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs, size_t len);
static void GetRegisterInfoCallback(void* ctxt, uint32_t reg, BNRegisterInfo* result);
static uint32_t GetStackPointerRegisterCallback(void* ctxt);
static uint32_t GetLinkRegisterCallback(void* ctxt);
Expand Down Expand Up @@ -14505,7 +14505,7 @@ namespace BinaryNinja {
static uint32_t* GetCalleeSavedRegistersCallback(void* ctxt, size_t* count);
static uint32_t* GetIntegerArgumentRegistersCallback(void* ctxt, size_t* count);
static uint32_t* GetFloatArgumentRegistersCallback(void* ctxt, size_t* count);
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs);
static void FreeRegisterListCallback(void* ctxt, uint32_t* regs, size_t len);

static bool AreArgumentRegistersSharedIndexCallback(void* ctxt);
static bool AreArgumentRegistersUsedForVarArgsCallback(void* ctxt);
Expand Down
10 changes: 5 additions & 5 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 71
#define BN_CURRENT_CORE_ABI_VERSION 72

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
#define BN_MINIMUM_CORE_ABI_VERSION 71
#define BN_MINIMUM_CORE_ABI_VERSION 72

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down Expand Up @@ -1831,15 +1831,15 @@ extern "C"
uint32_t* (*getFlagsRequiredForSemanticFlagGroup)(void* ctxt, uint32_t semGroup, size_t* count);
BNFlagConditionForSemanticClass* (*getFlagConditionsForSemanticFlagGroup)(
void* ctxt, uint32_t semGroup, size_t* count);
void (*freeFlagConditionsForSemanticFlagGroup)(void* ctxt, BNFlagConditionForSemanticClass* conditions);
void (*freeFlagConditionsForSemanticFlagGroup)(void* ctxt, BNFlagConditionForSemanticClass* conditions, size_t count);
uint32_t* (*getFlagsWrittenByFlagWriteType)(void* ctxt, uint32_t writeType, size_t* count);
uint32_t (*getSemanticClassForFlagWriteType)(void* ctxt, uint32_t writeType);
size_t (*getFlagWriteLowLevelIL)(void* ctxt, BNLowLevelILOperation op, size_t size, uint32_t flagWriteType,
uint32_t flag, BNRegisterOrConstant* operands, size_t operandCount, BNLowLevelILFunction* il);
size_t (*getFlagConditionLowLevelIL)(
void* ctxt, BNLowLevelILFlagCondition cond, uint32_t semClass, BNLowLevelILFunction* il);
size_t (*getSemanticFlagGroupLowLevelIL)(void* ctxt, uint32_t semGroup, BNLowLevelILFunction* il);
void (*freeRegisterList)(void* ctxt, uint32_t* regs);
void (*freeRegisterList)(void* ctxt, uint32_t* regs, size_t count);
void (*getRegisterInfo)(void* ctxt, uint32_t reg, BNRegisterInfo* result);
uint32_t (*getStackPointerRegister)(void* ctxt);
uint32_t (*getLinkRegister)(void* ctxt);
Expand Down Expand Up @@ -2518,7 +2518,7 @@ extern "C"
uint32_t* (*getCalleeSavedRegisters)(void* ctxt, size_t* count);
uint32_t* (*getIntegerArgumentRegisters)(void* ctxt, size_t* count);
uint32_t* (*getFloatArgumentRegisters)(void* ctxt, size_t* count);
void (*freeRegisterList)(void* ctxt, uint32_t* regs);
void (*freeRegisterList)(void* ctxt, uint32_t* regs, size_t len);

bool (*areArgumentRegistersSharedIndex)(void* ctxt);
bool (*isStackReservedForArgumentRegisters)(void* ctxt);
Expand Down
2 changes: 1 addition & 1 deletion callingconvention.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ uint32_t* CallingConvention::GetFloatArgumentRegistersCallback(void* ctxt, size_
}


void CallingConvention::FreeRegisterListCallback(void*, uint32_t* regs)
void CallingConvention::FreeRegisterListCallback(void*, uint32_t* regs, size_t)
{
delete[] regs;
}
Expand Down
28 changes: 28 additions & 0 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Try to find compatible Rust toolchain
# Once done this will define
# RUST_FOUND - If a compatible toolchain was found
# RUST_CARGO_DIR - The path to the cargo executable
# RUST_CARGO - The path to the cargo executable
# RUST_VERSION - The toolchain version

set(PATH_HINTS "$ENV{USERPROFILE}" "${HOME}")
if(NOT RUST_CARGO_DIR)
set(RUST_CARGO_DIR "${USER_HOME}/.cargo")
elseif()
message(STATUS "Using supplied rust cargo directory: ${RUST_CARGO_DIR}")
endif()
find_program(RUST_CARGO cargo HINTS ${RUST_CARGO_DIR} PATH_SUFFIXES "bin")

set(RUST_FOUND FALSE CACHE INTERNAL "")

if(RUST_CARGO)
set(RUST_FOUND TRUE CACHE INTERNAL "")
execute_process(COMMAND ${RUST_CARGO} --version OUTPUT_VARIABLE RUST_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "cargo ([^ ]+) .*" "\\1" RUST_VERSION "${RUST_VERSION}")
endif()

if(NOT RUST_FOUND)
message(FATAL_ERROR "Could NOT find Rust toolchain. Please configure with -RUST_CARGO_DIR=<path to cargo directory> or set the RUST_CARGO_DIR environment variable.")
endif()

message(STATUS "Found Rust: ${RUST_CARGO_DIR} (${RUST_VERSION})")
4 changes: 2 additions & 2 deletions python/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def _get_flag_conditions_for_semantic_flag_group(self, ctxt, sem_group, count):
count[0] = 0
return None

def _free_flag_conditions_for_semantic_flag_group(self, ctxt, conditions):
def _free_flag_conditions_for_semantic_flag_group(self, ctxt, conditions, count):
try:
buf = ctypes.cast(conditions, ctypes.c_void_p)
if buf.value not in self._pending_condition_lists:
Expand Down Expand Up @@ -999,7 +999,7 @@ def _get_semantic_flag_group_low_level_il(self, ctxt, sem_group, il):
log_error(traceback.format_exc())
return 0

def _free_register_list(self, ctxt, regs):
def _free_register_list(self, ctxt, regs, count):
try:
buf = ctypes.cast(regs, ctypes.c_void_p)
if buf.value not in self._pending_reg_lists:
Expand Down
2 changes: 1 addition & 1 deletion python/callingconvention.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _get_float_arg_regs(self, ctxt, count):
count[0] = 0
return None

def _free_register_list(self, ctxt, regs):
def _free_register_list(self, ctxt, regs, count):
try:
buf = ctypes.cast(regs, ctypes.c_void_p)
if buf.value not in self._pending_reg_lists:
Expand Down
Loading
Loading