mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
feature: remove addingrelocation by making function hijack a relative jmp
This commit is contained in:
+11
-5
@@ -77,14 +77,12 @@ def assemble_lea(current_address: int, destination_address: int, reg: str) -> by
|
||||
machine_code = bytes(encoding)
|
||||
return machine_code
|
||||
|
||||
def assemble_and_disassemble_jump(current_address: int, destination_address: int) -> bytes:
|
||||
#logger.info(" Make jmp from 0x{:X} to 0x{:X}".format(
|
||||
# current_address, destination_address
|
||||
#))
|
||||
|
||||
def assemble_relative_call(current_address: int, destination_address: int) -> bytes:
|
||||
# Calculate the relative offset
|
||||
# For a near jump, the instruction length is typically 5 bytes (E9 xx xx xx xx)
|
||||
offset = destination_address - current_address
|
||||
|
||||
|
||||
# Assemble the jump instruction using Keystone
|
||||
ks = Ks(KS_ARCH_X86, KS_MODE_64)
|
||||
encoding, _ = ks.asm(f"call qword ptr ds:[{offset}]")
|
||||
@@ -98,6 +96,14 @@ def assemble_and_disassemble_jump(current_address: int, destination_address: int
|
||||
return machine_code
|
||||
|
||||
|
||||
def assemble_relative_jmp(current_address: int, destination_address: int) -> bytes:
|
||||
offset = destination_address - current_address
|
||||
ks = Ks(KS_ARCH_X86, KS_MODE_64)
|
||||
encoding, _ = ks.asm(f"jmp {offset}")
|
||||
machine_code = bytes(encoding)
|
||||
return machine_code
|
||||
|
||||
|
||||
## Utils
|
||||
|
||||
def remove_trailing_null_bytes(data: bytes) -> bytes:
|
||||
|
||||
Reference in New Issue
Block a user