Conversation
e4c04f1 to
e5875d7
Compare
|
How about this refactor? :> |
Hook callbacks previously reconstructed Unicorn values from shared Rc<UnsafeCell<_>> state, which could create multiple mutable aliases to the same emulator state. Introduce HookContext as the callback API, and use Box for the emulator. Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
e5875d7 to
68de01a
Compare
|
I just had a quick look. I'm not quite sure what exactly you want to make more sound. Can you explain a bit more what is the problem you want to solve. Also with this patch the user_data is practical disabled. For small examples it is not that bad to replace the user_data with closure, but for bigger code it quickly gets ugly. |
|
Another problem is that you need now to implement every api twiche (one time for the Unicorn struct and one time for the HookContext). |
To be honest, the goal of this patch is to fix an aliasing problem in the old callback.
We can see the an example: In the old imp. The callback could modify the same internal state through a second Unicorn while the original Unicorn was still in use by emu_start.
let mut uc = Unicorn::new(Arch::X86, Mode::MODE_64).unwrap();
uc.add_code_hook(0x1000, 0x2000, |callback_uc, _, _| {
callback_uc
.reg_write(RegisterX86::RAX, 1)
.unwrap();
})
.unwrap();
uc.emu_start(0x1000, 0x2000, 0, 0).unwrap();I wonder if there have a better way?
Yes, I have also thought about this question. I think this PR just a draft. |
|
It might work using |
Yes, it's a good idea. But from a user experience perspective, these approaches would seem very strange. Maybe you mean: let mut uc = Unicorn::new_with_data(Arch::X86, Mode::MODE_32, 0u64).unwrap();
// it's strange
uc = uc_emu_start(uc, CODE_START, CODE_START + code.len() as u64, 0, 0);
// or like
uc = uc.emu_start(CODE_START, CODE_START + code.len() as u64, 0, 0); |
Ref #14
HookContextas the callback API.BoxreplaceRcthe emulator.what's more: Perhaps we should rename new_with_data to new and make it take only arch and mode.