mirror of
https://github.com/zeldaret/tp
synced 2026-07-11 15:28:38 -04:00
moved strings + decompile simple store functions
This commit is contained in:
@@ -3,3 +3,5 @@ from .base import *
|
||||
from .asm import *
|
||||
from .ret import *
|
||||
from .sinit import *
|
||||
from .store import *
|
||||
from .small_asm import *
|
||||
|
||||
@@ -132,12 +132,19 @@ class Function(Symbol):
|
||||
for line in lines:
|
||||
await builder.write(line)
|
||||
|
||||
arg_type = ""
|
||||
arg_type = []
|
||||
if forward:
|
||||
arg_type = ", ".join([x.type(specialize_templates=True) for x in self.argument_types])
|
||||
arg_type = [x.type(specialize_templates=True) for x in self.argument_types]
|
||||
else:
|
||||
arg_type = ", ".join([x.decl(f"param_{i}",specialize_templates=True) for i, x in zip(
|
||||
range(len(self.argument_types)), self.argument_types)])
|
||||
arg_type = [
|
||||
x.decl(f"param_{i}",specialize_templates=True)
|
||||
for i, x in enumerate(self.argument_types)
|
||||
]
|
||||
|
||||
if self.demangled_name and self.demangled_name.require_specialization:
|
||||
arg_type = [f"void* _this", *arg_type]
|
||||
|
||||
arg_type = ", ".join(arg_type)
|
||||
|
||||
if self._section == ".init":
|
||||
await builder.write_nonewline(f"SECTION_INIT ")
|
||||
|
||||
@@ -29,6 +29,8 @@ class CustomReturnFunction(ReturnFunction):
|
||||
class SymbolReturnFunction(ReturnFunction):
|
||||
symbol_addr: int = 0
|
||||
load_or_reference: bool = True
|
||||
load_type: Type = None
|
||||
cast_type: Type = None
|
||||
|
||||
def gather_references(self, context, valid_range):
|
||||
self.references = set([ self.symbol_addr ])
|
||||
@@ -37,8 +39,11 @@ class SymbolReturnFunction(ReturnFunction):
|
||||
symbol = symbol_table[-1, self.symbol_addr]
|
||||
assert symbol
|
||||
name = symbol.cpp_reference(self, self.symbol_addr)
|
||||
type = PointerType(self.return_type)
|
||||
load_type = PointerType(self.load_type)
|
||||
dereference = ""
|
||||
cast = ""
|
||||
if self.load_or_reference:
|
||||
dereference = "*"
|
||||
return f"{dereference}({type.type()})({name})"
|
||||
if self.cast_type:
|
||||
cast = f"({self.cast_type.type()})"
|
||||
return f"{cast}{dereference}({load_type.type()})({name})"
|
||||
|
||||
@@ -20,7 +20,7 @@ class SInitFunction(ASMFunction):
|
||||
|
||||
await builder.write("#pragma push")
|
||||
await builder.write("#pragma force_active on")
|
||||
await builder.write(f"SECTION_CTORS void* const _ctors_{self.addr:08X} = (void*){self.label};")
|
||||
await builder.write(f"REGISTER_CTORS(0x{self.addr:08X}, {self.label});")
|
||||
await builder.write("#pragma pop")
|
||||
await builder.write("")
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from ...builder import AsyncBuilder
|
||||
from .base import *
|
||||
|
||||
@dataclass(eq=False)
|
||||
class SmallASMFunction(Function):
|
||||
asm: bool = True
|
||||
insts: List[str] = field(default_factory=list)
|
||||
|
||||
async def export_function_body(self, exporter, builder: AsyncBuilder):
|
||||
await builder.write(f" {{")
|
||||
await builder.write(f"\t// clang-format off")
|
||||
await builder.write(f"\tnofralloc")
|
||||
for inst in self.insts:
|
||||
await builder.write(f"\t{inst}")
|
||||
await builder.write(f"\t// clang-format on")
|
||||
await builder.write(f"}}")
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from capstone import *
|
||||
from capstone.ppc import *
|
||||
|
||||
from ...builder import AsyncBuilder
|
||||
from ...types import *
|
||||
from .base import *
|
||||
|
||||
|
||||
@dataclass(eq=False)
|
||||
class StoreFunction(Function):
|
||||
async def export_store(self, exporter, builder):
|
||||
assert False
|
||||
|
||||
async def export_function_body(self, exporter, builder: AsyncBuilder):
|
||||
await builder.write(f" {{")
|
||||
await self.export_store(exporter, builder)
|
||||
await builder.write(f"}}")
|
||||
|
||||
|
||||
@dataclass(eq=False)
|
||||
class Store_R3_OffsetRX_Function(StoreFunction):
|
||||
dst: int = 0
|
||||
dst_offset: int = 0
|
||||
src: int = 0
|
||||
store_type: Type = None
|
||||
|
||||
def calculate_params(self):
|
||||
params = {}
|
||||
|
||||
gr = PPC_REG_R3
|
||||
if self.has_class:
|
||||
if self.demangled_name and self.demangled_name.require_specialization:
|
||||
params[gr] = "_this"
|
||||
else:
|
||||
params[gr] = "this"
|
||||
gr += 1
|
||||
|
||||
for i, arg in enumerate(self.argument_types):
|
||||
params[gr] = f"param_{i}"
|
||||
gr += 1
|
||||
|
||||
return params
|
||||
|
||||
async def export_store(self, exporter, builder):
|
||||
params = self.calculate_params()
|
||||
dst = params[self.dst]
|
||||
src = params[self.src]
|
||||
if self.dst_offset > 0:
|
||||
dst = f"(((u8*){params[self.dst]})+{self.dst_offset}) /* {params[self.dst]}->field_0x{self.dst_offset:x} */"
|
||||
|
||||
pointer_type = PointerType(self.store_type)
|
||||
await builder.write(f"\t*({pointer_type.type()}){dst} = ({self.store_type.type()})({src});")
|
||||
Reference in New Issue
Block a user