Skip to content

Commit

Permalink
fix(importer): Fix importer for 64bit and actually change function ar…
Browse files Browse the repository at this point in the history
…guments types
  • Loading branch information
SpaghettDev committed Jun 16, 2024
1 parent 2b20809 commit df0e32e
Show file tree
Hide file tree
Showing 11 changed files with 1,275 additions and 740 deletions.
10 changes: 8 additions & 2 deletions BromaIDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from idautils import Names

from broma_ida.pybroma_installer import install_pybroma
install_pybroma()

from broma_ida.utils import (
popup, stop, get_platform, get_platform_printable
Expand Down Expand Up @@ -60,6 +59,13 @@ def bida_main():
)

elif import_export_prompt == ASKBTN_BTN2:
popup(
"Ok", "Ok", None,
"Exporter is currently broken! "
"Don't rely on it exporting correctly...\n"
"But hey, I won't judge."
)

platform = get_platform()

# for_saving is not True because we need to read the file first
Expand Down Expand Up @@ -98,7 +104,7 @@ def init(self):
"""Ran on plugin load"""
self._register_action()

if install_pybroma() != 0:
if not install_pybroma():
popup(
"Ok", "Ok", None,
"Couldn't install PyBroma! "
Expand Down
6 changes: 4 additions & 2 deletions broma_ida/broma/argtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def _expand_stl_type(self, t: str) -> str:
if "std::" not in t:
return t

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

if t.startswith("std::vector"):
Expand Down Expand Up @@ -237,7 +239,7 @@ def _expand_stl_type(self, t: str) -> str:
"{}", contained.group(1)
))

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

def __init__(self, btype: Union[BaseArgType, BaseShortArgType]):
if btype.get("reg"):
Expand Down
13 changes: 0 additions & 13 deletions broma_ida/broma/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ida_name import is_visible_cp

from broma_ida.broma.constants import BROMA_CALLING_CONVENTIONS
from broma_ida.broma.argtype import ArgType, RetType


Expand All @@ -16,7 +15,6 @@ class BaseBindingType(TypedDict):

return_type: RetType
parameters: list[ArgType]
calling_convention: BROMA_CALLING_CONVENTIONS
is_virtual: bool
is_static: bool

Expand All @@ -32,7 +30,6 @@ class BaseShortBindingTypeWithMD(BaseShortBindingType):
"""Base binding type (shorter, with metadata about the function)"""
return_type: RetType
parameters: list[ArgType]
calling_convention: BROMA_CALLING_CONVENTIONS
is_virtual: bool
is_static: bool

Expand Down Expand Up @@ -93,8 +90,6 @@ def __init__(
"name": "", "type": "", "reg": ""
}),
"parameters": binding.get("parameters") or [],
"calling_convention":
binding.get("calling_convention") or "default",
"is_virtual": binding.get("is_virtual") or False,
"is_static": binding.get("is_static") or False
})
Expand Down Expand Up @@ -138,13 +133,6 @@ def __getitem__(self, key: Literal["parameters"]) -> list[ArgType]:
def __getitem__(self, key: Literal["return_type"]) -> RetType:
...

@overload
def __getitem__(
self,
key: Literal["calling_convention"]
) -> BROMA_CALLING_CONVENTIONS:
...

def __getitem__(self, key):
return self.binding.__getitem__(key)

Expand All @@ -155,7 +143,6 @@ def __str__(self) -> str:
return f"""{"virtual " if self.binding["is_virtual"] else ""}""" \
f"""{"static " if self.binding["is_static"] else ""}""" \
f"""{self.binding["return_type"]["type"]} """ \
f"""__{self.binding["calling_convention"]} """ \
f"""{self.binding["class_name"]}::{self.binding["name"]}""" \
f"""({", ".join([
str(arg) for arg in self.binding["parameters"]
Expand Down
12 changes: 8 additions & 4 deletions broma_ida/broma/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def write(self):
f.write("using TodoReturn = void; // :troll:\n")
f.write("\n")

f.flush()

f.write("// class fwddec\n")
f.writelines([f"class {c};\n" for c in self._classes.keys()])
f.write("\n")

f.flush()

f.write("// extras\n")
for name, broma_class in Root(
str(self._broma_path / "Extras.bro")
Expand All @@ -98,10 +106,6 @@ def write(self):
)
f.write("\n")

f.write("// class fwddec\n")
f.writelines([f"class {c};\n" for c in self._classes.keys()])
f.write("\n")

f.flush()

f.write("// delegates and non-polymorphic classes\n")
Expand Down
3 changes: 1 addition & 2 deletions broma_ida/broma/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Literal

# no android32 nor android64 because they have symbols
BROMA_PLATFORMS = Literal["win", "mac", "ios"]
BROMA_PLATFORMS = Literal["win", "imac", "m1", "ios"]

BROMA_CALLING_CONVENTIONS = Literal[
"default", "thiscall",
Expand Down
Loading

0 comments on commit df0e32e

Please sign in to comment.