@@ -10136,23 +10136,93 @@ namespace BinaryNinja {
1013610136 ILReferenceSource source;
1013710137 };
1013810138
10139+ struct ValueLocationComponent
10140+ {
10141+ Variable variable;
10142+ int64_t offset = 0;
10143+ std::optional<uint64_t> size;
10144+ bool indirect = false;
10145+
10146+ ValueLocationComponent() = default;
10147+ ValueLocationComponent(Variable var, int64_t ofs = 0, std::optional<uint64_t> sz = std::nullopt,
10148+ bool indir = false) : variable(var), offset(ofs), size(sz), indirect(indir)
10149+ {}
10150+
10151+ ValueLocationComponent RemapVariables(const std::function<Variable(Variable)>& remap) const;
10152+
10153+ bool operator==(const ValueLocationComponent& component) const;
10154+ bool operator!=(const ValueLocationComponent& component) const;
10155+
10156+ static ValueLocationComponent FromAPIObject(const BNValueLocationComponent* loc);
10157+ BNValueLocationComponent ToAPIObject() const;
10158+ };
10159+
10160+ struct ValueLocation
10161+ {
10162+ std::vector<ValueLocationComponent> components;
10163+
10164+ ValueLocation() {}
10165+ ValueLocation(Variable var) : components {var} {}
10166+ ValueLocation(const std::vector<ValueLocationComponent>& components) : components(components) {}
10167+ ValueLocation(std::vector<ValueLocationComponent>&& components) : components(std::move(components)) {}
10168+
10169+ ValueLocation(BNVariableSourceType type, uint64_t storage) : components {Variable(type, storage)} {}
10170+ ValueLocation(BNVariableSourceType type, uint32_t index, uint64_t storage) :
10171+ components {Variable(type, index, storage)}
10172+ {}
10173+
10174+ std::optional<Variable> GetVariable() const;
10175+ ValueLocation RemapVariables(const std::function<Variable(Variable)>& remap) const;
10176+ void ForEachVariable(const std::function<void(Variable var, bool indirect)>& func) const;
10177+ bool ContainsVariable(Variable var) const;
10178+ bool IsValid() const { return !components.empty(); }
10179+
10180+ bool operator==(const ValueLocation& loc) const;
10181+ bool operator!=(const ValueLocation& loc) const;
10182+
10183+ static ValueLocation FromAPIObject(const BNValueLocation* loc);
10184+ BNValueLocation ToAPIObject() const;
10185+ static void FreeAPIObject(BNValueLocation* loc);
10186+ };
10187+
1013910188 struct FunctionParameter
1014010189 {
1014110190 std::string name;
1014210191 Confidence<Ref<Type>> type;
1014310192 bool defaultLocation;
10144- Variable location;
10193+ ValueLocation location;
1014510194
1014610195 FunctionParameter() = default;
1014710196 FunctionParameter(const std::string& name, Confidence<Ref<Type>> type): name(name), type(type), defaultLocation(true)
1014810197 {}
1014910198
1015010199 FunctionParameter(const std::string& name, const Confidence<Ref<Type>>& type, bool defaultLocation,
10151- const Variable & location):
10200+ const ValueLocation & location) :
1015210201 name(name), type(type), defaultLocation(defaultLocation), location(location)
1015310202 {}
1015410203 };
1015510204
10205+ struct ReturnValue
10206+ {
10207+ Confidence<Ref<Type>> type;
10208+ bool defaultLocation = true;
10209+ Confidence<ValueLocation> location;
10210+
10211+ ReturnValue(Type* ty) : type(ty) {}
10212+ ReturnValue(Ref<Type> ty) : type(ty) {}
10213+ ReturnValue(const Confidence<Ref<Type>>& ty) : type(ty) {}
10214+ ReturnValue(const Confidence<Ref<Type>>& ty, bool defaultLoc, const Confidence<ValueLocation>& loc) :
10215+ type(ty), defaultLocation(defaultLoc), location(loc) {};
10216+ ReturnValue() = default;
10217+
10218+ bool operator==(const ReturnValue& nt) const;
10219+ bool operator!=(const ReturnValue& nt) const;
10220+
10221+ static ReturnValue FromAPIObject(const BNReturnValue* returnValue);
10222+ BNReturnValue ToAPIObject() const;
10223+ static void FreeAPIObject(BNReturnValue* returnValue);
10224+ };
10225+
1015610226 class FieldResolutionInfo : public CoreRefCountObject<BNFieldResolutionInfo, BNNewFieldResolutionInfoReference, BNFreeFieldResolutionInfo>
1015710227 {
1015810228 public:
@@ -10316,6 +10386,12 @@ namespace BinaryNinja {
1031610386 */
1031710387 Confidence<Ref<Type>> GetChildType() const;
1031810388
10389+ /*! Get the return value type and location for this Type if one exists
10390+
10391+ \return The return value type and location
10392+ */
10393+ ReturnValue GetReturnValue() const;
10394+
1031910395 /*! For Function Types, get the calling convention
1032010396
1032110397 \return The CallingConvention
@@ -10530,14 +10606,14 @@ namespace BinaryNinja {
1053010606 auto functionType = Type::FunctionType(retType, cc, params);
1053110607 \endcode
1053210608
10533- \param returnValue Return value Type
10609+ \param returnValue Return value type and location
1053410610 \param callingConvention Calling convention for the function
1053510611 \param params list of FunctionParameter s
1053610612 \param varArg Whether this function has variadic arguments, default false
1053710613 \param stackAdjust Stack adjustment for this function, default 0
1053810614 \return The created function types
1053910615 */
10540- static Ref<Type> FunctionType(const Confidence<Ref<Type>> & returnValue,
10616+ static Ref<Type> FunctionType(const ReturnValue & returnValue,
1054110617 const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1054210618 const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1054310619 const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
@@ -10558,23 +10634,21 @@ namespace BinaryNinja {
1055810634 auto functionType = Type::FunctionType(retType, cc, params);
1055910635 \endcode
1056010636
10561- \param returnValue Return value Type
10637+ \param returnValue Return value type and location
1056210638 \param callingConvention Calling convention for the function
1056310639 \param params list of FunctionParameters
1056410640 \param varArg Whether this function has variadic arguments, default false
1056510641 \param stackAdjust Stack adjustment for this function, default 0
10566- \param regStackAdjust Register stack adjustmemt
10567- \param returnRegs Return registers
10642+ \param regStackAdjust Register stack adjustmemt
1056810643 \return The created function types
1056910644 */
10570- static Ref<Type> FunctionType(const Confidence<Ref<Type>> & returnValue,
10645+ static Ref<Type> FunctionType(const ReturnValue & returnValue,
1057110646 const Confidence<Ref<CallingConvention>>& callingConvention,
1057210647 const std::vector<FunctionParameter>& params,
1057310648 const Confidence<bool>& hasVariableArguments,
1057410649 const Confidence<bool>& canReturn,
1057510650 const Confidence<int64_t>& stackAdjust,
1057610651 const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust = std::map<uint32_t, Confidence<int32_t>>(),
10577- const Confidence<std::vector<uint32_t>>& returnRegs = Confidence<std::vector<uint32_t>>(std::vector<uint32_t>(), 0),
1057810652 BNNameType ft = NoNameType,
1057910653 const Confidence<bool>& pure = Confidence<bool>(false, 0));
1058010654 static Ref<Type> VarArgsType();
@@ -10770,6 +10844,7 @@ namespace BinaryNinja {
1077010844 void SetIntegerTypeDisplayType(BNIntegerDisplayType displayType);
1077110845
1077210846 Confidence<Ref<Type>> GetChildType() const;
10847+ ReturnValue GetReturnValue() const;
1077310848 Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1077410849 BNCallingConventionName GetCallingConventionName() const;
1077510850 std::vector<FunctionParameter> GetParameters() const;
@@ -10789,6 +10864,7 @@ namespace BinaryNinja {
1078910864 TypeBuilder& SetConst(const Confidence<bool>& cnst);
1079010865 TypeBuilder& SetVolatile(const Confidence<bool>& vltl);
1079110866 TypeBuilder& SetChildType(const Confidence<Ref<Type>>& child);
10867+ TypeBuilder& SetReturnValue(const ReturnValue& rv);
1079210868 TypeBuilder& SetCallingConvention(const Confidence<Ref<CallingConvention>>& cc);
1079310869 TypeBuilder& SetCallingConventionName(BNCallingConventionName cc);
1079410870 TypeBuilder& SetSigned(const Confidence<bool>& vltl);
@@ -10864,18 +10940,17 @@ namespace BinaryNinja {
1086410940 const Confidence<bool>& cnst = Confidence<bool>(false, 0),
1086510941 const Confidence<bool>& vltl = Confidence<bool>(false, 0), BNReferenceType refType = PointerReferenceType);
1086610942 static TypeBuilder ArrayType(const Confidence<Ref<Type>>& type, uint64_t elem);
10867- static TypeBuilder FunctionType(const Confidence<Ref<Type>> & returnValue,
10943+ static TypeBuilder FunctionType(const ReturnValue & returnValue,
1086810944 const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1086910945 const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1087010946 const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
10871- static TypeBuilder FunctionType(const Confidence<Ref<Type>> & returnValue,
10947+ static TypeBuilder FunctionType(const ReturnValue & returnValue,
1087210948 const Confidence<Ref<CallingConvention>>& callingConvention,
1087310949 const std::vector<FunctionParameter>& params,
1087410950 const Confidence<bool>& hasVariableArguments,
1087510951 const Confidence<bool>& canReturn,
1087610952 const Confidence<int64_t>& stackAdjust,
1087710953 const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust = std::map<uint32_t, Confidence<int32_t>>(),
10878- const Confidence<std::vector<uint32_t>>& returnRegs = Confidence<std::vector<uint32_t>>(std::vector<uint32_t>(), 0),
1087910954 BNNameType ft = NoNameType,
1088010955 const Confidence<bool>& pure = Confidence<bool>(false, 0));
1088110956 static TypeBuilder VarArgsType();
@@ -12706,19 +12781,22 @@ namespace BinaryNinja {
1270612781
1270712782 Ref<Type> GetType() const;
1270812783 Confidence<Ref<Type>> GetReturnType() const;
12784+ ReturnValue GetReturnValue() const;
1270912785 Confidence<std::vector<uint32_t>> GetReturnRegisters() const;
1271012786 Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1271112787 Confidence<std::vector<Variable>> GetParameterVariables() const;
12788+ Confidence<std::vector<ValueLocation>> GetParameterLocations() const;
1271212789 Confidence<bool> HasVariableArguments() const;
1271312790 Confidence<int64_t> GetStackAdjustment() const;
1271412791 std::map<uint32_t, Confidence<int32_t>> GetRegisterStackAdjustments() const;
1271512792 Confidence<std::set<uint32_t>> GetClobberedRegisters() const;
1271612793
1271712794 void SetAutoType(Type* type);
1271812795 void SetAutoReturnType(const Confidence<Ref<Type>>& type);
12719- void SetAutoReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12796+ void SetAutoReturnValue(const ReturnValue& rv);
12797+ void SetAutoReturnValueLocation(const Confidence<ValueLocation>& location);
1272012798 void SetAutoCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12721- void SetAutoParameterVariables (const Confidence<std::vector<Variable >>& vars );
12799+ void SetAutoParameterLocations (const Confidence<std::vector<ValueLocation >>& locations );
1272212800 void SetAutoHasVariableArguments(const Confidence<bool>& varArgs);
1272312801 void SetAutoCanReturn(const Confidence<bool>& returns);
1272412802 void SetAutoPure(const Confidence<bool>& pure);
@@ -12728,9 +12806,10 @@ namespace BinaryNinja {
1272812806
1272912807 void SetUserType(Type* type);
1273012808 void SetReturnType(const Confidence<Ref<Type>>& type);
12731- void SetReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12809+ void SetReturnValue(const ReturnValue& rv);
12810+ void SetReturnValueLocation(const Confidence<ValueLocation>& location);
1273212811 void SetCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12733- void SetParameterVariables (const Confidence<std::vector<Variable >>& vars );
12812+ void SetParameterLocations (const Confidence<std::vector<ValueLocation >>& locations );
1273412813 void SetHasVariableArguments(const Confidence<bool>& varArgs);
1273512814 void SetCanReturn(const Confidence<bool>& returns);
1273612815 void SetPure(const Confidence<bool>& pure);
0 commit comments