regomne / ilhook-rs

A library that provides methods to inline hook binary codes in x86 and x86_64 architecture
MIT License
71 stars 10 forks source link

[Feature request]add support for custom assembly code #6

Closed CzBiX closed 1 year ago

CzBiX commented 1 year ago

add support for custom assembly code, expected signature:

// will jump to user code, then jump back
JumpBackWithCode(code: Vec[u8])

it's even better support in form of generate stub:

pub type GenerateStub = fn(
    buf: &mut Cursor<&mut [u8]>,
    stub_base_addr: u32,
    moving_code: &Vec<Instruction>,
    ori_addr: u32,
    ori_len: u8,
) -> Result<(), HookError>;

// just jump to generated code
JumpToGeneratedCode(stub: GenerateStub)
regomne commented 1 year ago

For the JumpToGeneratedCode feature, since the stub generation function is the core of this lib, users may not need to use this lib if they want to implement the stub generation themselves. If you have this requiment, you may implement it by reusing or modifying parts of this lib's code as needed.

For the JumpBackWithCode feature, you can use JmpBack hooking type to let it jumps to anywhere and jumps back, even the JmpBackRoutine is a C function or any types of code pointer (you can std::transmute any memory addresses to a JmpBackRoutine pointer).

CzBiX commented 1 year ago

I encountered a program that checks the SEH record, so I need to be careful about maintaining the stack, hence the need for this feature. I do now copy the code and modify it to achieve the purpose. but I want official support so that I don't have to deal with the boilerplate code myself.😆

Thank you for your detailed answers, and for providing such a good library.