Skip to content

Commit

Permalink
fix(gnustl): Not using custom gnustl doesnt fix std::less<K>
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettDev committed Aug 1, 2024
1 parent b115714 commit 090c47e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion BromaIDA.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "5.5.1"
VERSION = "5.6.0"
__AUTHOR__ = "SpaghettDev"

PLUGIN_NAME = "BromaIDA"
Expand Down
2 changes: 1 addition & 1 deletion broma_ida/types/cocos2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <climits>
#include <cctype>

#if !defined(BROMAIDA_DONT_USE_CUSTOM_GNUSTL) && (defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64))
#if defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64)

#include "gnustl.hpp"

Expand Down
36 changes: 34 additions & 2 deletions broma_ida/types/gnustl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
// taken from: https://github.com/geode-sdk/geode/blob/main/loader/include/Geode/c++stl/string.hpp

#if !defined(BROMAIDA_DONT_USE_CUSTOM_GNUSTL) && (defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64))
#if defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64)

#ifdef BROMAIDA_DONT_USE_CUSTOM_GNUSTL

#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

// idaclang thinks empty classes occupy 0 bytes of space therefore breaking the
// implementation of std::map/std::set (caused by the empty class std::less)
template <typename T>
struct custom_less : std::less<T>
{
bool pad;
};

namespace std
{
// providing custom specializations for standard library templates is
// technically UB but clang allows it
template <typename Key, typename T, typename Alloc>
class map<Key, T, less<Key>, Alloc> : public map<Key, T, custom_less<Key>, Alloc> {};

template <typename Key, typename Alloc>
class set<Key, less<Key>, Alloc> : public set<Key, custom_less<Key>, Alloc> {};
}

#else

#include <cstdint>
#include <cstddef>
Expand Down Expand Up @@ -115,4 +145,6 @@ namespace std
using unordered_set = void*[7];
}

#endif
#endif // !BROMAIDA_DONT_USE_CUSTOM_GNUSTL

#endif // !BROMAIDA_PLATFORM_ANDROID32 || BROMAIDA_PLATFORM_ANDROID64
25 changes: 1 addition & 24 deletions broma_ida/types/stl_types.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <utility>

#if !defined(BROMAIDA_DONT_USE_CUSTOM_GNUSTL) && (defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64))
#if defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64)

#include "gnustl.hpp"

Expand All @@ -13,29 +13,6 @@
#include <set>
#include <unordered_set>

#if defined(BROMAIDA_PLATFORM_ANDROID32) || defined(BROMAIDA_PLATFORM_ANDROID64)

// idaclang thinks empty classes occupy 0 bytes of space therefore breaking the
// implementation of std::map/std::set (caused by the empty class std::less)
template <typename T>
struct custom_less : std::less<T>
{
bool pad;
};

namespace std
{
// providing custom specializations for standard library templates is
// technically UB but clang allows it
template <typename Key, typename T, typename Alloc>
class map<Key, T, less<Key>, Alloc> : public map<Key, T, custom_less<Key>, Alloc> {};

template <typename Key, typename Alloc>
class set<Key, less<Key>, Alloc> : public set<Key, custom_less<Key>, Alloc> {};
}

#endif

#endif

#include "enums.hpp"
Expand Down

0 comments on commit 090c47e

Please sign in to comment.