Skip to content

Commit ca7d7d5

Browse files
committed
WIP
1 parent 8383957 commit ca7d7d5

File tree

17 files changed

+1478
-398
lines changed

17 files changed

+1478
-398
lines changed

binaryninjaapi.h

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10201,23 +10201,93 @@ namespace BinaryNinja {
1020110201
ILReferenceSource source;
1020210202
};
1020310203

10204+
struct ValueLocationComponent
10205+
{
10206+
Variable variable;
10207+
int64_t offset = 0;
10208+
std::optional<uint64_t> size;
10209+
bool indirect = false;
10210+
10211+
ValueLocationComponent() = default;
10212+
ValueLocationComponent(Variable var, int64_t ofs = 0, std::optional<uint64_t> sz = std::nullopt,
10213+
bool indir = false) : variable(var), offset(ofs), size(sz), indirect(indir)
10214+
{}
10215+
10216+
ValueLocationComponent RemapVariables(const std::function<Variable(Variable)>& remap) const;
10217+
10218+
bool operator==(const ValueLocationComponent& component) const;
10219+
bool operator!=(const ValueLocationComponent& component) const;
10220+
10221+
static ValueLocationComponent FromAPIObject(const BNValueLocationComponent* loc);
10222+
BNValueLocationComponent ToAPIObject() const;
10223+
};
10224+
10225+
struct ValueLocation
10226+
{
10227+
std::vector<ValueLocationComponent> components;
10228+
10229+
ValueLocation() {}
10230+
ValueLocation(Variable var) : components {var} {}
10231+
ValueLocation(const std::vector<ValueLocationComponent>& components) : components(components) {}
10232+
ValueLocation(std::vector<ValueLocationComponent>&& components) : components(std::move(components)) {}
10233+
10234+
ValueLocation(BNVariableSourceType type, uint64_t storage) : components {Variable(type, storage)} {}
10235+
ValueLocation(BNVariableSourceType type, uint32_t index, uint64_t storage) :
10236+
components {Variable(type, index, storage)}
10237+
{}
10238+
10239+
std::optional<Variable> GetVariable() const;
10240+
ValueLocation RemapVariables(const std::function<Variable(Variable)>& remap) const;
10241+
void ForEachVariable(const std::function<void(Variable var, bool indirect)>& func) const;
10242+
bool ContainsVariable(Variable var) const;
10243+
bool IsValid() const { return !components.empty(); }
10244+
10245+
bool operator==(const ValueLocation& loc) const;
10246+
bool operator!=(const ValueLocation& loc) const;
10247+
10248+
static ValueLocation FromAPIObject(const BNValueLocation* loc);
10249+
BNValueLocation ToAPIObject() const;
10250+
static void FreeAPIObject(BNValueLocation* loc);
10251+
};
10252+
1020410253
struct FunctionParameter
1020510254
{
1020610255
std::string name;
1020710256
Confidence<Ref<Type>> type;
1020810257
bool defaultLocation;
10209-
Variable location;
10258+
ValueLocation location;
1021010259

1021110260
FunctionParameter() = default;
1021210261
FunctionParameter(const std::string& name, Confidence<Ref<Type>> type): name(name), type(type), defaultLocation(true)
1021310262
{}
1021410263

1021510264
FunctionParameter(const std::string& name, const Confidence<Ref<Type>>& type, bool defaultLocation,
10216-
const Variable& location):
10265+
const ValueLocation& location) :
1021710266
name(name), type(type), defaultLocation(defaultLocation), location(location)
1021810267
{}
1021910268
};
1022010269

10270+
struct ReturnValue
10271+
{
10272+
Confidence<Ref<Type>> type;
10273+
bool defaultLocation = true;
10274+
Confidence<ValueLocation> location;
10275+
10276+
ReturnValue(Type* ty) : type(ty) {}
10277+
ReturnValue(Ref<Type> ty) : type(ty) {}
10278+
ReturnValue(const Confidence<Ref<Type>>& ty) : type(ty) {}
10279+
ReturnValue(const Confidence<Ref<Type>>& ty, bool defaultLoc, const Confidence<ValueLocation>& loc) :
10280+
type(ty), defaultLocation(defaultLoc), location(loc) {};
10281+
ReturnValue() = default;
10282+
10283+
bool operator==(const ReturnValue& nt) const;
10284+
bool operator!=(const ReturnValue& nt) const;
10285+
10286+
static ReturnValue FromAPIObject(const BNReturnValue* returnValue);
10287+
BNReturnValue ToAPIObject() const;
10288+
static void FreeAPIObject(BNReturnValue* returnValue);
10289+
};
10290+
1022110291
class FieldResolutionInfo : public CoreRefCountObject<BNFieldResolutionInfo, BNNewFieldResolutionInfoReference, BNFreeFieldResolutionInfo>
1022210292
{
1022310293
public:
@@ -10381,6 +10451,22 @@ namespace BinaryNinja {
1038110451
*/
1038210452
Confidence<Ref<Type>> GetChildType() const;
1038310453

10454+
/*! Get the return value type and location for this Type if one exists
10455+
10456+
\return The return value type and location
10457+
*/
10458+
ReturnValue GetReturnValue() const;
10459+
10460+
/*! Whether the return value is in the default location
10461+
*/
10462+
bool IsReturnValueDefaultLocation() const;
10463+
10464+
/*! Get the return value location for this Type
10465+
10466+
\return The return value location
10467+
*/
10468+
Confidence<ValueLocation> GetReturnValueLocation() const;
10469+
1038410470
/*! For Function Types, get the calling convention
1038510471

1038610472
\return The CallingConvention
@@ -10595,14 +10681,14 @@ namespace BinaryNinja {
1059510681
auto functionType = Type::FunctionType(retType, cc, params);
1059610682
\endcode
1059710683

10598-
\param returnValue Return value Type
10684+
\param returnValue Return value type and location
1059910685
\param callingConvention Calling convention for the function
1060010686
\param params list of FunctionParameter s
1060110687
\param varArg Whether this function has variadic arguments, default false
1060210688
\param stackAdjust Stack adjustment for this function, default 0
1060310689
\return The created function types
1060410690
*/
10605-
static Ref<Type> FunctionType(const Confidence<Ref<Type>>& returnValue,
10691+
static Ref<Type> FunctionType(const ReturnValue& returnValue,
1060610692
const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1060710693
const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1060810694
const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
@@ -10623,23 +10709,21 @@ namespace BinaryNinja {
1062310709
auto functionType = Type::FunctionType(retType, cc, params);
1062410710
\endcode
1062510711

10626-
\param returnValue Return value Type
10712+
\param returnValue Return value type and location
1062710713
\param callingConvention Calling convention for the function
1062810714
\param params list of FunctionParameters
1062910715
\param varArg Whether this function has variadic arguments, default false
1063010716
\param stackAdjust Stack adjustment for this function, default 0
10631-
\param regStackAdjust Register stack adjustmemt
10632-
\param returnRegs Return registers
10717+
\param regStackAdjust Register stack adjustmemt
1063310718
\return The created function types
1063410719
*/
10635-
static Ref<Type> FunctionType(const Confidence<Ref<Type>>& returnValue,
10720+
static Ref<Type> FunctionType(const ReturnValue& returnValue,
1063610721
const Confidence<Ref<CallingConvention>>& callingConvention,
1063710722
const std::vector<FunctionParameter>& params,
1063810723
const Confidence<bool>& hasVariableArguments,
1063910724
const Confidence<bool>& canReturn,
1064010725
const Confidence<int64_t>& stackAdjust,
1064110726
const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust = std::map<uint32_t, Confidence<int32_t>>(),
10642-
const Confidence<std::vector<uint32_t>>& returnRegs = Confidence<std::vector<uint32_t>>(std::vector<uint32_t>(), 0),
1064310727
BNNameType ft = NoNameType,
1064410728
const Confidence<bool>& pure = Confidence<bool>(false, 0));
1064510729
static Ref<Type> VarArgsType();
@@ -10835,6 +10919,9 @@ namespace BinaryNinja {
1083510919
void SetIntegerTypeDisplayType(BNIntegerDisplayType displayType);
1083610920

1083710921
Confidence<Ref<Type>> GetChildType() const;
10922+
ReturnValue GetReturnValue() const;
10923+
bool IsReturnValueDefaultLocation() const;
10924+
Confidence<ValueLocation> GetReturnValueLocation() const;
1083810925
Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1083910926
BNCallingConventionName GetCallingConventionName() const;
1084010927
std::vector<FunctionParameter> GetParameters() const;
@@ -10854,6 +10941,9 @@ namespace BinaryNinja {
1085410941
TypeBuilder& SetConst(const Confidence<bool>& cnst);
1085510942
TypeBuilder& SetVolatile(const Confidence<bool>& vltl);
1085610943
TypeBuilder& SetChildType(const Confidence<Ref<Type>>& child);
10944+
TypeBuilder& SetReturnValue(const ReturnValue& rv);
10945+
TypeBuilder& SetIsReturnValueDefaultLocation(bool defaultLocation);
10946+
TypeBuilder& SetReturnValueLocation(const Confidence<ValueLocation>& location);
1085710947
TypeBuilder& SetCallingConvention(const Confidence<Ref<CallingConvention>>& cc);
1085810948
TypeBuilder& SetCallingConventionName(BNCallingConventionName cc);
1085910949
TypeBuilder& SetSigned(const Confidence<bool>& vltl);
@@ -10929,18 +11019,17 @@ namespace BinaryNinja {
1092911019
const Confidence<bool>& cnst = Confidence<bool>(false, 0),
1093011020
const Confidence<bool>& vltl = Confidence<bool>(false, 0), BNReferenceType refType = PointerReferenceType);
1093111021
static TypeBuilder ArrayType(const Confidence<Ref<Type>>& type, uint64_t elem);
10932-
static TypeBuilder FunctionType(const Confidence<Ref<Type>>& returnValue,
11022+
static TypeBuilder FunctionType(const ReturnValue& returnValue,
1093311023
const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1093411024
const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1093511025
const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
10936-
static TypeBuilder FunctionType(const Confidence<Ref<Type>>& returnValue,
11026+
static TypeBuilder FunctionType(const ReturnValue& returnValue,
1093711027
const Confidence<Ref<CallingConvention>>& callingConvention,
1093811028
const std::vector<FunctionParameter>& params,
1093911029
const Confidence<bool>& hasVariableArguments,
1094011030
const Confidence<bool>& canReturn,
1094111031
const Confidence<int64_t>& stackAdjust,
1094211032
const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust = std::map<uint32_t, Confidence<int32_t>>(),
10943-
const Confidence<std::vector<uint32_t>>& returnRegs = Confidence<std::vector<uint32_t>>(std::vector<uint32_t>(), 0),
1094411033
BNNameType ft = NoNameType,
1094511034
const Confidence<bool>& pure = Confidence<bool>(false, 0));
1094611035
static TypeBuilder VarArgsType();
@@ -12771,19 +12860,25 @@ namespace BinaryNinja {
1277112860

1277212861
Ref<Type> GetType() const;
1277312862
Confidence<Ref<Type>> GetReturnType() const;
12863+
ReturnValue GetReturnValue() const;
12864+
bool IsReturnValueDefaultLocation() const;
12865+
Confidence<ValueLocation> GetReturnValueLocation() const;
1277412866
Confidence<std::vector<uint32_t>> GetReturnRegisters() const;
1277512867
Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1277612868
Confidence<std::vector<Variable>> GetParameterVariables() const;
12869+
Confidence<std::vector<ValueLocation>> GetParameterLocations() const;
1277712870
Confidence<bool> HasVariableArguments() const;
1277812871
Confidence<int64_t> GetStackAdjustment() const;
1277912872
std::map<uint32_t, Confidence<int32_t>> GetRegisterStackAdjustments() const;
1278012873
Confidence<std::set<uint32_t>> GetClobberedRegisters() const;
1278112874

1278212875
void SetAutoType(Type* type);
1278312876
void SetAutoReturnType(const Confidence<Ref<Type>>& type);
12784-
void SetAutoReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12877+
void SetAutoReturnValue(const ReturnValue& rv);
12878+
void SetAutoIsReturnValueDefaultLocation(bool defaultLocation);
12879+
void SetAutoReturnValueLocation(const Confidence<ValueLocation>& location);
1278512880
void SetAutoCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12786-
void SetAutoParameterVariables(const Confidence<std::vector<Variable>>& vars);
12881+
void SetAutoParameterLocations(const Confidence<std::vector<ValueLocation>>& locations);
1278712882
void SetAutoHasVariableArguments(const Confidence<bool>& varArgs);
1278812883
void SetAutoCanReturn(const Confidence<bool>& returns);
1278912884
void SetAutoPure(const Confidence<bool>& pure);
@@ -12793,9 +12888,11 @@ namespace BinaryNinja {
1279312888

1279412889
void SetUserType(Type* type);
1279512890
void SetReturnType(const Confidence<Ref<Type>>& type);
12796-
void SetReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12891+
void SetReturnValue(const ReturnValue& rv);
12892+
void SetIsReturnValueDefaultLocation(bool defaultLocation);
12893+
void SetReturnValueLocation(const Confidence<ValueLocation>& location);
1279712894
void SetCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12798-
void SetParameterVariables(const Confidence<std::vector<Variable>>& vars);
12895+
void SetParameterLocations(const Confidence<std::vector<ValueLocation>>& locations);
1279912896
void SetHasVariableArguments(const Confidence<bool>& varArgs);
1280012897
void SetCanReturn(const Confidence<bool>& returns);
1280112898
void SetPure(const Confidence<bool>& pure);

0 commit comments

Comments
 (0)