Skip to content

Fix cmp hook #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ where
block_hook: UcHookId,
/// Stored for deleting hook when dropping
sub_hook: UcHookId,
/// Stored for deleting hook when dropping
cmp_hook: UcHookId,
dumb_ob: tuple_list_type!(ValueObserver<'static, bool>),
}

Expand Down Expand Up @@ -274,15 +276,28 @@ where
let sub_hook = uc
.add_tcg_hook(
TcgOpCode::SUB,
TcgOpFlag::CMP | TcgOpFlag::DIRECT,
TcgOpFlag::DIRECT,
1,
0,
|uc, address, arg1, arg2, size| {
hook_opcode_cmpcov(uc, address, arg1, arg2, size);
},
)
.inspect_err(|ret| {
warn!("Fail to add sub hooks due to {ret:?}");
})?;
let cmp_hook = uc
.add_tcg_hook(
TcgOpCode::SUB,
TcgOpFlag::CMP,
1,
0,
|uc, address, arg1, arg2, size| {
hook_opcode_cmpcov(uc, address, arg1, arg2, size);
},
)
.inspect_err(|ret| {
warn!("Fail to add cmp and sub hooks due to {ret:?}");
warn!("Fail to add cmp hooks due to {ret:?}");
})?;

Ok(Self {
Expand All @@ -293,6 +308,7 @@ where
always_validate,
block_hook,
sub_hook,
cmp_hook,
dumb_ob: tuple_list!(ValueObserver::new("dumb_ob", OwnedRef::Owned(false.into()))),
})
}
Expand Down Expand Up @@ -329,7 +345,10 @@ where
warn!("Fail to uninstall block hook due to {ret:?}");
}
if let Err(ret) = self.uc.remove_hook(self.sub_hook) {
warn!("Fail to uninstall cmp and sub tcg opcode hook due to {ret:?}");
warn!("Fail to uninstall sub tcg opcode hook due to {ret:?}");
}
if let Err(ret) = self.uc.remove_hook(self.cmp_hook) {
warn!("Fail to uninstall cmp tcg opcode hook due to {ret:?}");
}
}
}
Expand Down