| 2746 | |
| 2747 | class ArchitectureHook(CoreArchitecture): |
| 2748 | def __init__(self, base_arch: 'Architecture'): |
| 2749 | self._base_arch = base_arch |
| 2750 | super(ArchitectureHook, self).__init__(base_arch.handle) |
| 2751 | |
| 2752 | # To improve performance of simpler hooks, use null callback for functions that are not being overridden |
| 2753 | if self.get_associated_arch_by_address.__code__ == CoreArchitecture.get_associated_arch_by_address.__code__: |
| 2754 | self._cb.getAssociatedArchitectureByAddress = self._cb.getAssociatedArchitectureByAddress.__class__() |
| 2755 | if self.get_instruction_info.__code__ == CoreArchitecture.get_instruction_info.__code__: |
| 2756 | self._cb.getInstructionInfo = self._cb.getInstructionInfo.__class__() |
| 2757 | if self.get_instruction_text.__code__ == CoreArchitecture.get_instruction_text.__code__: |
| 2758 | self._cb.getInstructionText = self._cb.getInstructionText.__class__() |
| 2759 | if self.__class__.stack_pointer is None: |
| 2760 | self._cb.getStackPointerRegister = self._cb.getStackPointerRegister.__class__() |
| 2761 | if self.__class__.link_reg is None: |
| 2762 | self._cb.getLinkRegister = self._cb.getLinkRegister.__class__() |
| 2763 | if len(self.__class__.regs) == 0: |
| 2764 | self._cb.getRegisterInfo = self._cb.getRegisterInfo.__class__() |
| 2765 | self._cb.getRegisterName = self._cb.getRegisterName.__class__() |
| 2766 | if len(self.__class__.reg_stacks) == 0: |
| 2767 | self._cb.getRegisterStackName = self._cb.getRegisterStackName.__class__() |
| 2768 | self._cb.getRegisterStackInfo = self._cb.getRegisterStackInfo.__class__() |
| 2769 | if len(self.__class__.intrinsics) == 0: |
| 2770 | self._cb.getIntrinsicClass = self._cb.getIntrinsicClass.__class__() |
| 2771 | self._cb.getIntrinsicName = self._cb.getIntrinsicName.__class__() |
| 2772 | self._cb.getIntrinsicInputs = self._cb.getIntrinsicInputs.__class__() |
| 2773 | self._cb.freeNameAndTypeList = self._cb.freeNameAndTypeList.__class__() |
| 2774 | self._cb.getIntrinsicOutputs = self._cb.getIntrinsicOutputs.__class__() |
| 2775 | self._cb.freeTypeList = self._cb.freeTypeList.__class__() |
| 2776 | |
| 2777 | def register(self) -> None: |
| 2778 | self.__class__._registered_cb = self._cb |