Skip to content

Commit

Permalink
Fix STL types not getting set for functions that use/return them and …
Browse files Browse the repository at this point in the history
…fix exporter again
  • Loading branch information
SpaghettDev committed Jul 20, 2024
1 parent db12d76 commit a7a6a6f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 72 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.1.0"
VERSION = "5.2.0"
__AUTHOR__ = "SpaghettDev"

PLUGIN_NAME = "BromaIDA"
Expand Down
60 changes: 34 additions & 26 deletions broma_ida/broma/argtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,32 @@ class ArgType:
"""An argument type"""
btype: BaseArgType

def _expand_stl_type(self, t: str) -> str:
def _expand_stl_type(self, stl_type: str) -> str:
"""Expands STL types because IDA is retarded and likes to expand them
Args:
t (str): _description_
stl_type (str)
Returns:
str: _description_
str
"""
# IDA likes spaces after types
format_pointer = lambda pt: sub(r"([^ ])\*", r"\1 *", pt) # noqa: E731
format_pointer = lambda pt: sub(
r"([^ ])\*", r"\1 *", pt
) # noqa: E731

if "std::" not in t:
return t
if "std::" not in stl_type:
return stl_type

if sub(
"(?: )?const(?: )?", "", t
).removesuffix("&").removesuffix("*") == "std::string":
return t
"(?: )?const(?: )?", "", stl_type
).removesuffix("&").removesuffix("*") == "std::string":
return stl_type

if t.startswith("std::vector"):
split_type = match(r"std::vector<(.*)>", t)
if stl_type.startswith("std::vector"):
split_type = match(r"std::vector<(.*)>", stl_type)

assert split_type is not None, "impossible"
assert split_type is not None, f"Couldn't get contained type for '{stl_type}'"

if split_type.group(1) in EXPANDED_STL_TYPES:
return format_pointer(f"""std::vector{
Expand All @@ -72,12 +74,12 @@ def _expand_stl_type(self, t: str) -> str:

# this should never happen, but it causes the below code
# to go ham
if "std::allocator" in t:
return t
if "std::allocator" in stl_type:
return stl_type

# "it just works"
# credit to henrysck075 i couldnt figure out this shit :D
ret = t
ret = stl_type
vec_to_contained = [[ret, ret]]
while True:
try:
Expand Down Expand Up @@ -110,8 +112,11 @@ def _expand_stl_type(self, t: str) -> str:

return format_pointer(vec_to_contained[0][1])

if t.startswith("std::map"):
split_type = split(r"std::map<(.*), (.*)>", t)
if stl_type.startswith("std::map"):
split_type = split(r"std::map<(.*),(?: )?(.*)>", stl_type)

assert split_type is not None, f"Couldn't get contained types for '{stl_type}'"

map_key_type = ""
map_value_type = ""

Expand Down Expand Up @@ -164,8 +169,11 @@ def _expand_stl_type(self, t: str) -> str:
"{1}", map_value_type
))

if t.startswith("std::unordered_map"):
split_type = split(r"std::unordered_map<(.*), (.*)>", t)
if stl_type.startswith("std::unordered_map"):
split_type = split(r"std::unordered_map<(.*),(?: )?(.*)>", stl_type)

assert split_type is not None, f"Couldn't get contained types for {stl_type}"

map_key_type = ""
map_value_type = ""

Expand Down Expand Up @@ -217,29 +225,29 @@ def _expand_stl_type(self, t: str) -> str:
"{1}", map_value_type
))

if t.startswith("std::set"):
contained = match("std::set<(.*)>", t)
if stl_type.startswith("std::set"):
contained = match("std::set<(.*)>", stl_type)

assert contained is not None, "impossible"
assert contained is not None, f"Couldn't get contained type for {stl_type}"

return format_pointer(f"""std::set{
BASE_EXPANDED_STL_TYPES["std::set"]
}""".replace(
"{}", contained.group(1)
))

if t.startswith("std::unordered_set"):
contained = match("std::unordered_set<(.*)>", t)
if stl_type.startswith("std::unordered_set"):
contained = match("std::unordered_set<(.*)>", stl_type)

assert contained is not None, "impossible"
assert contained is not None, f"Couldn't get contained type for {stl_type}"

return format_pointer(f"""std::unordered_set{
BASE_EXPANDED_STL_TYPES["std::unordered_set"]
}""".replace(
"{}", contained.group(1)
))

raise BaseException(f"[!] Couldn't expand STL type: '{t}'")
raise BaseException(f"[!] Couldn't expand STL type: '{stl_type}'")

def __init__(self, btype: Union[BaseArgType, BaseShortArgType]):
if btype.get("reg"):
Expand Down
2 changes: 1 addition & 1 deletion broma_ida/broma/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _get_ida_qualified_name(
The binding
Returns:
str: _description_
str
"""
if not is_visible_cp(ord("~")) and \
binding["class_name"] == binding["name"][1:]:
Expand Down
2 changes: 1 addition & 1 deletion broma_ida/broma/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _get_broma_string(
broma_line_no_address.string[
broma_line_no_address.span(0)[0]:
][2:]
}"""
};"""

broma_binding_platforms = self._parse_method_platforms(
parsed_broma_line.group(5)
Expand Down
Loading

0 comments on commit a7a6a6f

Please sign in to comment.