# Path: mayhem/utilities.py
# def architecture_is_32bit(arch):
# def architecture_is_64bit(arch):
# def align_down(number, alignment=16):
# def align_up(number, alignment=16):
# def eval_number(number):
# def print_hexdump(data, address=0, stream=None):
# def struct_pack(structure):
# def struct_unpack(structure, raw_data):
# def bytes_to_ctarray(bytes_, member_type=ctypes.c_byte):
# def ctarray_to_bytes(ctarray):
# 
# Path: mayhem/windll/kernel32.py
# def _patch_winfunctype(function, restype, argtypes=(), **kwargs):
# 
# Path: mayhem/windll/user32.py



import ctypes
import platform
import struct
from mayhem import utilities
from mayhem.windll import kernel32 as m_k32
from mayhem.windll import user32 as m_u32


def py_GetClipboardData(uFormat):
	m_u32.MessageBoxW(None, 'Hooked!', 'Hooked!', 0)
	return -1

prototype = ctypes.WINFUNCTYPE(ctypes.c_void_p, ctypes.c_uint)
GetClipboardData = prototype(py_GetClipboardData)

def jump_stub(address):
	arch = platform.machine()
	if utilities.architecture_is_32bit(arch):
		stub = b'\xb8' + struct.pack('I', address)      # mov eax, address
		stub += b'\xff\xe0'                             # jmp eax
	elif utilities.architecture_is_64bit(arch):
		stub = b'\x48\xb8' + struct.pack('Q', address)  # mov rax, address
		stub += b'\xff\xe0'                             # jmp rax
	return stub

def mayhem():
	handle = -1  # -1 is always a handle to the current process
	module_handle = m_k32.GetModuleHandleW('user32.dll')
	if not module_handle:
		print('user32.dll is not loaded')
		return

# Path: mayhem/utilities.py
# def architecture_is_32bit(arch):
# def architecture_is_64bit(arch):
# def align_down(number, alignment=16):
# def align_up(number, alignment=16):
# def eval_number(number):
# def print_hexdump(data, address=0, stream=None):
# def struct_pack(structure):
# def struct_unpack(structure, raw_data):
# def bytes_to_ctarray(bytes_, member_type=ctypes.c_byte):
# def ctarray_to_bytes(ctarray):
# 
# Path: mayhem/windll/kernel32.py
# def _patch_winfunctype(function, restype, argtypes=(), **kwargs):
# 
# Path: mayhem/windll/user32.py



# Path: examples/inject_hook_getclipboarddata.py
import ctypes
import platform
import struct
from mayhem import utilities
from mayhem.windll import kernel32 as m_k32
from mayhem.windll import user32 as m_u32



def py_GetClipboardData(uFormat):
	m_u32.MessageBoxW(None, 'Hooked!', 'Hooked!', 0)
	return -1

prototype = ctypes.WINFUNCTYPE(ctypes.c_void_p, ctypes.c_uint)
GetClipboardData = prototype(py_GetClipboardData)

def jump_stub(address):
	arch = platform.machine()
	if utilities.architecture_is_32bit(arch):
		stub = b'\xb8' + struct.pack('I', address)      # mov eax, address
		stub += b'\xff\xe0'                             # jmp eax
	elif utilities.architecture_is_64bit(arch):
		stub = b'\x48\xb8' + struct.pack('Q', address)  # mov rax, address
		stub += b'\xff\xe0'                             # jmp rax
	return stub

def mayhem():
	handle = -1  # -1 is always a handle to the current process
	module_handle = m_k32.GetModuleHandleW('user32.dll')
	if not module_handle:
		print('user32.dll is not loaded')
		return

	address = m_k32.GetProcAddress(module_handle, b'GetClipboardData')