From ce7099536765fec8ba0a62aa0b7de467b13726ea Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:48:33 -0500 Subject: [PATCH] feat(android-stl): FIx std::vector implementation --- broma_ida/broma/codegen.py | 2 +- broma_ida/broma/importer.py | 13 ++++++++++--- broma_ida/types/stl_includes.hpp | 28 +++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/broma_ida/broma/codegen.py b/broma_ida/broma/codegen.py index 4320eed..1a86d10 100644 --- a/broma_ida/broma/codegen.py +++ b/broma_ida/broma/codegen.py @@ -12,7 +12,7 @@ class BromaCodegen: FILE_HEADER = """// Generated by BromaIDA, do not modify #include -#define BROMAIDA_PLATFORM_MACRO_NAME +#define {BROMAIDA_PLATFORM_MACRO_NAME} #define BROMAIDA_USE_CUSTOM_GNUSTL {BROMAIDA_USE_CUSTOM_GNUSTL_VALUE} // platform shorthands #define BROMAIDA_IS_PLATFORM_MACHO {BROMAIDA_IS_PLATFORM_MACHO_VALUE} diff --git a/broma_ida/broma/importer.py b/broma_ida/broma/importer.py index b402b2d..dda9a0b 100644 --- a/broma_ida/broma/importer.py +++ b/broma_ida/broma/importer.py @@ -320,9 +320,16 @@ def set_function_signature(ea: int, binding: Binding): if "const" in binding.parameters[idx].type: stl_type.set_const() - function_data[ - idx + (0 if binding.is_static else 1) - ].type = stl_type + try: + function_data[ + idx + (0 if binding.is_static else 1) + ].type = stl_type + except IndexError: + ida_warning( + "Couldn't fix STL parameters for " + f"""function {binding.qualified_name}!""", + ) + return if ret_has_stl_type: stl_type = ida_tinfo_t() diff --git a/broma_ida/types/stl_includes.hpp b/broma_ida/types/stl_includes.hpp index d980d10..1947ae8 100644 --- a/broma_ida/types/stl_includes.hpp +++ b/broma_ida/types/stl_includes.hpp @@ -188,6 +188,16 @@ struct custom_less : std::less bool pad; }; +#if BROMAIDA_IS_PLATFORM_ANDROID +namespace stl +{ + struct _bit_iterator { + std::uintptr_t* m_bitptr; + unsigned int m_offset; + }; +} +#endif + namespace std { // providing custom specializations for standard library templates is @@ -216,12 +226,20 @@ namespace std #if BROMAIDA_IS_PLATFORM_ANDROID template <> - class vector> - { - _Bit_iterator _M_start; - _Bit_iterator _M_finish; - _Bit_type* _M_end_of_storage; + class vector { + protected: + stl::_bit_iterator m_start; + stl::_bit_iterator m_end; + std::uintptr_t* m_capacity_end; }; + + // template <> + // class vector> + // { + // _Bit_iterator _M_start; + // _Bit_iterator _M_finish; + // _Bit_type* _M_end_of_storage; + // }; #elif BROMAIDA_IS_PLATFORM_MACHO template <> class vector>