Skip to content

Commit

Permalink
fixed bug with gnustl std::vector and mismatch trigger (#3)
Browse files Browse the repository at this point in the history
also moved holy_shit to the bottom as it needs some definitions
  • Loading branch information
AngelDev06 authored Aug 16, 2024
1 parent 090c47e commit dc8860c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
62 changes: 41 additions & 21 deletions broma_ida/broma/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class BromaCodegen:
"""Codegen for Broma"""

FILE_HEADER = f"""// Generated by BromaIDA, do not modify
#include <array>
Expand All @@ -32,7 +33,7 @@ def __init__(
use_custom_gnustl: bool,
broma_classes: dict[str, Class],
path: Path,
broma_path: Path
broma_path: Path,
):
self._target_platform = platform
self._use_custom_gnustl = use_custom_gnustl
Expand All @@ -52,16 +53,17 @@ def write(self):
with open(
self._path / "codegen" / f"{self._target_platform}.hpp",
"w",
buffering=10*1024*1024
buffering=10 * 1024 * 1024,
) as f:
f.write(
self.FILE_HEADER.replace(
"BROMAIDA_PLATFORM_MACRO_NAME",
self._get_bromaida_platform_macro()
self._get_bromaida_platform_macro(),
).replace(
"BROMAIDA_USE_CUSTOM_GNUSTL_MACRO",
"BROMAIDA_USE_CUSTOM_GNUSTL" if self._use_custom_gnustl \
else "BROMAIDA_DONT_USE_CUSTOM_GNUSTL"
"BROMAIDA_USE_CUSTOM_GNUSTL"
if self._use_custom_gnustl
else "BROMAIDA_DONT_USE_CUSTOM_GNUSTL",
)
)

Expand All @@ -75,11 +77,23 @@ def write(self):
f.write("// gnustl.hpp\n")
f.writelines(gnustl.readlines())
f.write("\n\n")
else:
f.write("// standard headers\n")
for header in (
"string",
"vector",
"map",
"unordered_map",
"set",
"unordered_set",
):
f.write(f"#include <{header}>\n")
f.write("\n")

with open(self._path / "cocos2d.hpp") as cocos:
f.write("// cocos2d.hpp\n")
for line in cocos.readlines():
if line.startswith("#include \""):
if line.startswith('#include "'):
line = f"// {line}"

f.write(line)
Expand All @@ -90,15 +104,6 @@ def write(self):
f.writelines(fmod.readlines())
f.write("\n\n")

with open(self._path / "stl_types.hpp") as stl_types:
f.write("// stl_types.hpp\n")
for line in stl_types.readlines():
if line.startswith("#include \""):
line = f"// {line}"

f.write(line)
f.write("\n\n")

with open(self._path / "helpers.hpp") as helpers:
f.write("// helpers.hpp\n")
f.writelines(helpers.readlines())
Expand All @@ -121,19 +126,25 @@ def write(self):
split_c = c.split("::")

if len(split_c) == 2:
f.write(f"""namespace {split_c[0]} {{ class {split_c[1]}; }};\n""")
f.write(
f"""namespace {split_c[0]} {{ class {split_c[1]}; }};\n"""
)
elif len(split_c) == 3:
f.write(f"""namespace {split_c[0]} {{ namespace {split_c[1]} {{ class {split_c[2]}; }} }}\n""")
f.write(
f"""namespace {split_c[0]} {{ namespace {split_c[1]} {{ class {split_c[2]}; }} }}\n"""
)
else:
f.write(f"class {c};\n")
f.write("\n")

f.flush()

f.write("// extras\n")
for name, broma_class in Root(
str(self._broma_path / "Extras.bro")
).classesAsDict().items():
for name, broma_class in (
Root(str(self._broma_path / "Extras.bro"))
.classesAsDict()
.items()
):
f.write(
ClassBuilder(self._target_platform, broma_class).get_str()
)
Expand Down Expand Up @@ -163,6 +174,15 @@ def write(self):
f.write(
ClassBuilder(self._target_platform, broma_class).get_str()
)
f.write("\n")

with open(self._path / "stl_types.hpp") as stl_types:
f.write("// stl_types.hpp\n")
for line in stl_types.readlines():
if line.startswith('#include "'):
line = f"// {line}"

f.write(line)

def _get_bromaida_platform_macro(self) -> str:
"""Gets the BromaIDA platform macro name (shocker)"""
Expand All @@ -172,7 +192,7 @@ def _get_bromaida_platform_macro(self) -> str:
"m1": "M1_MACOS",
"ios": "IOS",
"android32": "ANDROID32",
"android64": "ANDROID64"
"android64": "ANDROID64",
}

return f"""BROMAIDA_PLATFORM_{plat_to_macro_suffix[self._target_platform]}"""
4 changes: 2 additions & 2 deletions broma_ida/broma/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def verify_type(t: Optional[ida_tinfo_t]) -> bool:
if t is None:
return True

if t.get_size() == 0xFFFFFFFFFFFFFFFF:
if t.get_size() == 0xFFFFFFFFFFFFFFFF or t.is_forward_decl():
return True

return False
Expand All @@ -152,7 +152,7 @@ def verify_types(platform: BROMA_PLATFORMS) -> bool:
)
return False

if any([
if not all([
BIUtils.verify_type(BIUtils.get_type_info(t))
for t in (
"cocos2d::CCObject", "cocos2d::CCImage",
Expand Down
18 changes: 18 additions & 0 deletions broma_ida/types/gnustl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ namespace std

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

// std::vector implementation of gnustl breaks idaclang (errors when determining
// the size in local types)
template <typename T>
class vector<T, allocator<T>>
{
T* _M_start;
T* _M_finish;
T* _M_end_of_storage;
};

template <>
class vector<bool, allocator<bool>>
{
_Bit_iterator _M_start;
_Bit_iterator _M_finish;
_Bit_type* _M_end_of_storage;
};
}

#else
Expand Down
4 changes: 2 additions & 2 deletions broma_ida/types/stl_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

namespace cocos2d
{
class CCObject;
class CCArray;
class CCObject;
class CCArray;
}

class EnterEffectInstance;
Expand Down

0 comments on commit dc8860c

Please sign in to comment.