summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-08-23 00:34:20 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:25 -0400
commitb6442a914783cb2861ff8d1cd6a3865fed29e0f7 (patch)
tree2b45fe796746d52f32132447948b34092b5523d6
parent0725c6fbd58b3d40ffefdb319121a29ba4168517 (diff)
DebugInfo: take entire Type for function instead of by-parts
-rw-r--r--binaryninjaapi.h11
-rw-r--r--binaryninjacore.h7
-rw-r--r--debuginfo.cpp28
-rw-r--r--rust/src/debuginfo.rs128
-rw-r--r--rust/src/types.rs6
5 files changed, 33 insertions, 147 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index a01ab998..3d29520f 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -11927,18 +11927,13 @@ namespace BinaryNinja {
std::string fullName;
std::string rawName;
uint64_t address;
- Ref<Type> returnType;
- std::vector<std::tuple<std::string, Ref<Type>>> parameters;
- bool variableParameters;
- Ref<CallingConvention> callingConvention;
+ Ref<Type> type;
Ref<Platform> platform;
DebugFunctionInfo(std::string shortName, std::string fullName, std::string rawName, uint64_t address,
- Ref<Type> returnType, std::vector<std::tuple<std::string, Ref<Type>>> parameters, bool variableParameters,
- Ref<CallingConvention> callingConvention, Ref<Platform> platform) :
+ Ref<Type> type, Ref<Platform> platform) :
shortName(shortName),
- fullName(fullName), rawName(rawName), address(address), returnType(returnType), parameters(parameters),
- variableParameters(variableParameters), callingConvention(callingConvention), platform(platform)
+ fullName(fullName), rawName(rawName), address(address), platform(platform)
{}
};
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 421a6d23..f9571a4f 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -2843,12 +2843,7 @@ extern "C"
char* fullName;
char* rawName;
uint64_t address;
- BNType* returnType;
- char** parameterNames;
- BNType** parameterTypes;
- size_t parameterCount;
- bool variableParameters;
- BNCallingConvention* callingConvention;
+ BNType* type;
BNPlatform* platform;
};
diff --git a/debuginfo.cpp b/debuginfo.cpp
index c67582cb..c9a6f319 100644
--- a/debuginfo.cpp
+++ b/debuginfo.cpp
@@ -81,19 +81,10 @@ vector<DebugFunctionInfo> DebugInfo::GetFunctions(const string& parserName) cons
vector<DebugFunctionInfo> result;
for (size_t i = 0; i < count; ++i)
{
- vector<tuple<string, Ref<Type>>> parameters;
- for (size_t j = 0; j < functions[i].parameterCount; ++j)
- parameters.emplace_back(
- functions[i].parameterNames[j], new Type(BNNewTypeReference(functions[i].parameterTypes[j])));
-
result.emplace_back(functions[i].shortName ? functions[i].shortName : "",
functions[i].fullName ? functions[i].fullName : "", functions[i].rawName ? functions[i].rawName : "",
functions[i].address,
- functions[i].returnType ? new Type(BNNewTypeReference(functions[i].returnType)) : nullptr, parameters,
- functions[i].variableParameters,
- functions[i].callingConvention ?
- new CoreCallingConvention(BNNewCallingConventionReference(functions[i].callingConvention)) :
- nullptr,
+ functions[i].type ? new Type(BNNewTypeReference(functions[i].type)) : nullptr,
functions[i].platform ? new Platform(BNNewPlatformReference(functions[i].platform)) : nullptr);
}
@@ -267,30 +258,15 @@ bool DebugInfo::AddFunction(const DebugFunctionInfo& function)
input->fullName = function.fullName.size() ? BNAllocString(function.fullName.c_str()) : nullptr;
input->rawName = function.rawName.size() ? BNAllocString(function.rawName.c_str()) : nullptr;
input->address = function.address;
- input->returnType = function.returnType ? function.returnType->GetObject() : nullptr;
- input->variableParameters = function.variableParameters;
- input->callingConvention = function.callingConvention ? function.callingConvention->GetObject() : nullptr;
+ input->type = function.type ? function.type->GetObject() : nullptr;
input->platform = function.platform ? function.platform->GetObject() : nullptr;
- size_t parameterCount = function.parameters.size();
- input->parameterCount = parameterCount;
- input->parameterNames = new char*[parameterCount];
- input->parameterTypes = new BNType*[parameterCount];
- for (size_t i = 0; i < parameterCount; ++i)
- {
- input->parameterNames[i] = BNAllocString(std::get<0>(function.parameters[i]).c_str());
- input->parameterTypes[i] = std::get<1>(function.parameters[i])->GetObject();
- }
-
bool result = BNAddDebugFunction(m_object, input);
BNFreeString(input->shortName);
BNFreeString(input->fullName);
BNFreeString(input->rawName);
- for (size_t i = 0; i < parameterCount; ++i)
- BNFreeString(input->parameterNames[i]);
-
return result;
}
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index 7ce2c485..4e33e009 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -244,58 +244,28 @@ unsafe impl CoreOwnedArrayProvider for DebugInfoParser {
/// When contributing function info, provide only what you know - BinaryNinja will figure out everything else that it can, as it usually does.
///
/// Functions will not be created if an address is not provided, but will be able to be queried from debug info for later user analysis.
-pub struct DebugFunctionInfo<A: Architecture, S1: BnStrCompatible, S2: BnStrCompatible> {
- short_name: Option<S1>,
- full_name: Option<S1>,
- raw_name: Option<S1>,
- return_type: Option<Ref<Type>>,
+pub struct DebugFunctionInfo<S: BnStrCompatible> {
+ short_name: Option<S>,
+ full_name: Option<S>,
+ raw_name: Option<S>,
+ type_: Option<Ref<Type>>,
address: u64,
- parameters: Vec<(S2, Ref<Type>)>,
- variable_parameters: bool,
- calling_convention: Option<Ref<CallingConvention<A>>>,
platform: Option<Ref<Platform>>,
}
-impl From<&BNDebugFunctionInfo> for DebugFunctionInfo<CoreArchitecture, String, String> {
+impl From<&BNDebugFunctionInfo> for DebugFunctionInfo<String> {
fn from(raw: &BNDebugFunctionInfo) -> Self {
- let raw_parameter_names: &[*mut ::std::os::raw::c_char] =
- unsafe { slice::from_raw_parts(raw.parameterNames as *mut _, raw.parameterCount) };
- let raw_parameter_types: &[*mut BNType] =
- unsafe { slice::from_raw_parts(raw.parameterTypes as *mut _, raw.parameterCount) };
-
- let parameters: Vec<(String, Ref<Type>)> = (0..raw.parameterCount)
- .map(|i| {
- (raw_to_string(raw_parameter_names[i]).unwrap(), unsafe {
- Type::ref_from_raw(raw_parameter_types[i])
- })
- })
- .collect();
-
Self {
short_name: raw_to_string(raw.shortName),
full_name: raw_to_string(raw.fullName),
raw_name: raw_to_string(raw.rawName),
- return_type: if raw.returnType.is_null() {
+ type_: if raw.type_.is_null() {
None
} else {
- Some(unsafe { Type::ref_from_raw(raw.returnType) })
+ Some(unsafe { Type::ref_from_raw(raw.type_) })
},
address: raw.address,
- parameters,
- variable_parameters: raw.variableParameters,
- calling_convention: if raw.callingConvention.is_null() {
- None
- } else {
- Some(unsafe {
- CallingConvention::ref_from_raw(
- raw.callingConvention,
- CoreArchitecture::from_raw(BNGetCallingConventionArchitecture(
- raw.callingConvention,
- )),
- )
- })
- },
- platform: if raw.returnType.is_null() {
+ platform: if raw.platform.is_null() {
None
} else {
Some(unsafe { Platform::ref_from_raw(raw.platform) })
@@ -304,36 +274,24 @@ impl From<&BNDebugFunctionInfo> for DebugFunctionInfo<CoreArchitecture, String,
}
}
-impl<A: Architecture, S1: BnStrCompatible, S2: BnStrCompatible> DebugFunctionInfo<A, S1, S2> {
+impl<S: BnStrCompatible> DebugFunctionInfo<S> {
pub fn new(
- short_name: Option<S1>,
- full_name: Option<S1>,
- raw_name: Option<S1>,
- return_type: Option<Ref<Type>>,
+ short_name: Option<S>,
+ full_name: Option<S>,
+ raw_name: Option<S>,
+ type_: Option<Ref<Type>>,
address: Option<u64>,
- parameters: Option<Vec<(S2, Ref<Type>)>>,
- variable_parameters: Option<bool>,
- calling_convention: Option<Ref<CallingConvention<A>>>,
platform: Option<Ref<Platform>>,
) -> Self {
Self {
short_name,
full_name,
raw_name,
- return_type,
+ type_,
address: match address {
Some(address) => address,
_ => 0,
},
- parameters: match parameters {
- Some(parameters) => parameters,
- _ => vec![],
- },
- variable_parameters: match variable_parameters {
- Some(variable_parameters) => variable_parameters,
- _ => false,
- },
- calling_convention,
platform,
}
}
@@ -409,7 +367,7 @@ impl DebugInfo {
pub fn functions_by_name<S: BnStrCompatible>(
&self,
parser_name: S,
- ) -> Vec<DebugFunctionInfo<CoreArchitecture, String, String>> {
+ ) -> Vec<DebugFunctionInfo<String>> {
let parser_name = parser_name.into_bytes_with_nul();
let mut count: usize = 0;
@@ -421,10 +379,10 @@ impl DebugInfo {
)
};
- let result: Vec<DebugFunctionInfo<CoreArchitecture, String, String>> = unsafe {
+ let result: Vec<DebugFunctionInfo<String>> = unsafe {
slice::from_raw_parts_mut(functions_ptr, count)
.iter()
- .map(DebugFunctionInfo::<CoreArchitecture, String, String>::from)
+ .map(DebugFunctionInfo::<String>::from)
.collect()
};
@@ -433,15 +391,15 @@ impl DebugInfo {
}
/// A generator of all functions provided by DebugInfoParsers
- pub fn functions(&self) -> Vec<DebugFunctionInfo<CoreArchitecture, String, String>> {
+ pub fn functions(&self) -> Vec<DebugFunctionInfo<String>> {
let mut count: usize = 0;
let functions_ptr =
unsafe { BNGetDebugFunctions(self.handle, ptr::null_mut(), &mut count) };
- let result: Vec<DebugFunctionInfo<CoreArchitecture, String, String>> = unsafe {
+ let result: Vec<DebugFunctionInfo<String>> = unsafe {
slice::from_raw_parts_mut(functions_ptr, count)
.iter()
- .map(DebugFunctionInfo::<CoreArchitecture, String, String>::from)
+ .map(DebugFunctionInfo::<String>::from)
.collect()
};
@@ -730,12 +688,7 @@ impl DebugInfo {
}
/// Adds a function scoped under the current parser's name to the debug info
- pub fn add_function<A: Architecture, S1: BnStrCompatible, S2: BnStrCompatible>(
- &mut self,
- new_func: DebugFunctionInfo<A, S1, S2>,
- ) -> bool {
- let parameter_count: usize = new_func.parameters.len();
-
+ pub fn add_function<S: BnStrCompatible>(&mut self, new_func: DebugFunctionInfo<S>) -> bool {
let short_name_bytes = new_func.short_name.map(|name| name.into_bytes_with_nul());
let short_name = short_name_bytes
.as_ref()
@@ -755,25 +708,6 @@ impl DebugInfo {
name.as_ref().as_ptr() as *mut _
});
- let (mut parameter_names, mut parameter_types, _name_refs): (
- Vec<*mut ::std::os::raw::c_char>,
- Vec<*mut BNType>,
- _,
- ) = new_func.parameters.into_iter().fold(
- (
- Vec::with_capacity(parameter_count),
- Vec::with_capacity(parameter_count),
- Vec::with_capacity(parameter_count),
- ),
- |(mut parameter_names, mut parameter_types, mut name_refs), (n, t)| {
- let name_ref = n.into_bytes_with_nul();
- parameter_names.push(name_ref.as_ref().as_ptr() as *mut _);
- name_refs.push(name_ref);
- parameter_types.push(t.handle);
- (parameter_names, parameter_types, name_refs)
- },
- );
-
unsafe {
BNAddDebugFunction(
self.handle,
@@ -782,22 +716,8 @@ impl DebugInfo {
fullName: full_name,
rawName: raw_name,
address: new_func.address,
- returnType: match new_func.return_type {
- Some(return_type) => return_type.handle,
- _ => ptr::null_mut(),
- },
- parameterNames: match parameter_count {
- 0 => ptr::null_mut(),
- _ => parameter_names.as_mut_ptr(),
- },
- parameterTypes: match parameter_count {
- 0 => ptr::null_mut(),
- _ => parameter_types.as_mut_ptr(),
- },
- parameterCount: parameter_count,
- variableParameters: new_func.variable_parameters,
- callingConvention: match new_func.calling_convention {
- Some(calling_convention) => calling_convention.handle,
+ type_: match new_func.type_ {
+ Some(type_) => type_.handle,
_ => ptr::null_mut(),
},
platform: match new_func.platform {
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 4f9d8bff..37a1330b 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -954,7 +954,7 @@ impl Type {
}
}
- pub fn function<'a, S: BnStrCompatible + Copy, T: Into<Conf<&'a Type>>>(
+ pub fn function<'a, S: BnStrCompatible + Clone, T: Into<Conf<&'a Type>>>(
return_type: T,
parameters: &[FunctionParameter<S>],
variable_arguments: bool,
@@ -998,7 +998,7 @@ impl Type {
};
unsafe {
- Self::ref_from_raw(BNCreateFunctionType(
+ Self::ref_from_raw(BNNewTypeReference(BNCreateFunctionType(
&mut return_type,
&mut raw_calling_convention,
raw_parameters.as_mut_ptr(),
@@ -1011,7 +1011,7 @@ impl Type {
0,
&mut return_regs,
BNNameType::NoNameType,
- ))
+ )))
}
}