@@ -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,22 @@ 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+
10395+ /*! Whether the return value is in the default location
10396+ */
10397+ bool IsReturnValueDefaultLocation() const;
10398+
10399+ /*! Get the return value location for this Type
10400+
10401+ \return The return value location
10402+ */
10403+ Confidence<ValueLocation> GetReturnValueLocation() const;
10404+
1031910405 /*! For Function Types, get the calling convention
1032010406
1032110407 \return The CallingConvention
@@ -10530,14 +10616,14 @@ namespace BinaryNinja {
1053010616 auto functionType = Type::FunctionType(retType, cc, params);
1053110617 \endcode
1053210618
10533- \param returnValue Return value Type
10619+ \param returnValue Return value type and location
1053410620 \param callingConvention Calling convention for the function
1053510621 \param params list of FunctionParameter s
1053610622 \param varArg Whether this function has variadic arguments, default false
1053710623 \param stackAdjust Stack adjustment for this function, default 0
1053810624 \return The created function types
1053910625 */
10540- static Ref<Type> FunctionType(const Confidence<Ref<Type>> & returnValue,
10626+ static Ref<Type> FunctionType(const ReturnValue & returnValue,
1054110627 const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1054210628 const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1054310629 const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
@@ -10558,23 +10644,21 @@ namespace BinaryNinja {
1055810644 auto functionType = Type::FunctionType(retType, cc, params);
1055910645 \endcode
1056010646
10561- \param returnValue Return value Type
10647+ \param returnValue Return value type and location
1056210648 \param callingConvention Calling convention for the function
1056310649 \param params list of FunctionParameters
1056410650 \param varArg Whether this function has variadic arguments, default false
1056510651 \param stackAdjust Stack adjustment for this function, default 0
10566- \param regStackAdjust Register stack adjustmemt
10567- \param returnRegs Return registers
10652+ \param regStackAdjust Register stack adjustmemt
1056810653 \return The created function types
1056910654 */
10570- static Ref<Type> FunctionType(const Confidence<Ref<Type>> & returnValue,
10655+ static Ref<Type> FunctionType(const ReturnValue & returnValue,
1057110656 const Confidence<Ref<CallingConvention>>& callingConvention,
1057210657 const std::vector<FunctionParameter>& params,
1057310658 const Confidence<bool>& hasVariableArguments,
1057410659 const Confidence<bool>& canReturn,
1057510660 const Confidence<int64_t>& stackAdjust,
1057610661 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),
1057810662 BNNameType ft = NoNameType,
1057910663 const Confidence<bool>& pure = Confidence<bool>(false, 0));
1058010664 static Ref<Type> VarArgsType();
@@ -10770,6 +10854,9 @@ namespace BinaryNinja {
1077010854 void SetIntegerTypeDisplayType(BNIntegerDisplayType displayType);
1077110855
1077210856 Confidence<Ref<Type>> GetChildType() const;
10857+ ReturnValue GetReturnValue() const;
10858+ bool IsReturnValueDefaultLocation() const;
10859+ Confidence<ValueLocation> GetReturnValueLocation() const;
1077310860 Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1077410861 BNCallingConventionName GetCallingConventionName() const;
1077510862 std::vector<FunctionParameter> GetParameters() const;
@@ -10789,6 +10876,9 @@ namespace BinaryNinja {
1078910876 TypeBuilder& SetConst(const Confidence<bool>& cnst);
1079010877 TypeBuilder& SetVolatile(const Confidence<bool>& vltl);
1079110878 TypeBuilder& SetChildType(const Confidence<Ref<Type>>& child);
10879+ TypeBuilder& SetReturnValue(const ReturnValue& rv);
10880+ TypeBuilder& SetIsReturnValueDefaultLocation(bool defaultLocation);
10881+ TypeBuilder& SetReturnValueLocation(const Confidence<ValueLocation>& location);
1079210882 TypeBuilder& SetCallingConvention(const Confidence<Ref<CallingConvention>>& cc);
1079310883 TypeBuilder& SetCallingConventionName(BNCallingConventionName cc);
1079410884 TypeBuilder& SetSigned(const Confidence<bool>& vltl);
@@ -10864,18 +10954,17 @@ namespace BinaryNinja {
1086410954 const Confidence<bool>& cnst = Confidence<bool>(false, 0),
1086510955 const Confidence<bool>& vltl = Confidence<bool>(false, 0), BNReferenceType refType = PointerReferenceType);
1086610956 static TypeBuilder ArrayType(const Confidence<Ref<Type>>& type, uint64_t elem);
10867- static TypeBuilder FunctionType(const Confidence<Ref<Type>> & returnValue,
10957+ static TypeBuilder FunctionType(const ReturnValue & returnValue,
1086810958 const Confidence<Ref<CallingConvention>>& callingConvention, const std::vector<FunctionParameter>& params,
1086910959 const Confidence<bool>& varArg = Confidence<bool>(false, 0),
1087010960 const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
10871- static TypeBuilder FunctionType(const Confidence<Ref<Type>> & returnValue,
10961+ static TypeBuilder FunctionType(const ReturnValue & returnValue,
1087210962 const Confidence<Ref<CallingConvention>>& callingConvention,
1087310963 const std::vector<FunctionParameter>& params,
1087410964 const Confidence<bool>& hasVariableArguments,
1087510965 const Confidence<bool>& canReturn,
1087610966 const Confidence<int64_t>& stackAdjust,
1087710967 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),
1087910968 BNNameType ft = NoNameType,
1088010969 const Confidence<bool>& pure = Confidence<bool>(false, 0));
1088110970 static TypeBuilder VarArgsType();
@@ -12706,19 +12795,25 @@ namespace BinaryNinja {
1270612795
1270712796 Ref<Type> GetType() const;
1270812797 Confidence<Ref<Type>> GetReturnType() const;
12798+ ReturnValue GetReturnValue() const;
12799+ bool IsReturnValueDefaultLocation() const;
12800+ Confidence<ValueLocation> GetReturnValueLocation() const;
1270912801 Confidence<std::vector<uint32_t>> GetReturnRegisters() const;
1271012802 Confidence<Ref<CallingConvention>> GetCallingConvention() const;
1271112803 Confidence<std::vector<Variable>> GetParameterVariables() const;
12804+ Confidence<std::vector<ValueLocation>> GetParameterLocations() const;
1271212805 Confidence<bool> HasVariableArguments() const;
1271312806 Confidence<int64_t> GetStackAdjustment() const;
1271412807 std::map<uint32_t, Confidence<int32_t>> GetRegisterStackAdjustments() const;
1271512808 Confidence<std::set<uint32_t>> GetClobberedRegisters() const;
1271612809
1271712810 void SetAutoType(Type* type);
1271812811 void SetAutoReturnType(const Confidence<Ref<Type>>& type);
12719- void SetAutoReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12812+ void SetAutoReturnValue(const ReturnValue& rv);
12813+ void SetAutoIsReturnValueDefaultLocation(bool defaultLocation);
12814+ void SetAutoReturnValueLocation(const Confidence<ValueLocation>& location);
1272012815 void SetAutoCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12721- void SetAutoParameterVariables (const Confidence<std::vector<Variable >>& vars );
12816+ void SetAutoParameterLocations (const Confidence<std::vector<ValueLocation >>& locations );
1272212817 void SetAutoHasVariableArguments(const Confidence<bool>& varArgs);
1272312818 void SetAutoCanReturn(const Confidence<bool>& returns);
1272412819 void SetAutoPure(const Confidence<bool>& pure);
@@ -12728,9 +12823,11 @@ namespace BinaryNinja {
1272812823
1272912824 void SetUserType(Type* type);
1273012825 void SetReturnType(const Confidence<Ref<Type>>& type);
12731- void SetReturnRegisters(const Confidence<std::vector<uint32_t>>& returnRegs);
12826+ void SetReturnValue(const ReturnValue& rv);
12827+ void SetIsReturnValueDefaultLocation(bool defaultLocation);
12828+ void SetReturnValueLocation(const Confidence<ValueLocation>& location);
1273212829 void SetCallingConvention(const Confidence<Ref<CallingConvention>>& convention);
12733- void SetParameterVariables (const Confidence<std::vector<Variable >>& vars );
12830+ void SetParameterLocations (const Confidence<std::vector<ValueLocation >>& locations );
1273412831 void SetHasVariableArguments(const Confidence<bool>& varArgs);
1273512832 void SetCanReturn(const Confidence<bool>& returns);
1273612833 void SetPure(const Confidence<bool>& pure);
0 commit comments