Skip to content

Commit 4b57fca

Browse files
authored
Merge pull request #34 from Evian-Zhang/fix-cmp-hook
Fix cmp hook
2 parents a782a26 + f135fc5 commit 4b57fca

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/executor.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ where
235235
block_hook: UcHookId,
236236
/// Stored for deleting hook when dropping
237237
sub_hook: UcHookId,
238+
/// Stored for deleting hook when dropping
239+
cmp_hook: UcHookId,
238240
dumb_ob: tuple_list_type!(ValueObserver<'static, bool>),
239241
}
240242

@@ -274,15 +276,28 @@ where
274276
let sub_hook = uc
275277
.add_tcg_hook(
276278
TcgOpCode::SUB,
277-
TcgOpFlag::CMP | TcgOpFlag::DIRECT,
279+
TcgOpFlag::DIRECT,
280+
1,
281+
0,
282+
|uc, address, arg1, arg2, size| {
283+
hook_opcode_cmpcov(uc, address, arg1, arg2, size);
284+
},
285+
)
286+
.inspect_err(|ret| {
287+
warn!("Fail to add sub hooks due to {ret:?}");
288+
})?;
289+
let cmp_hook = uc
290+
.add_tcg_hook(
291+
TcgOpCode::SUB,
292+
TcgOpFlag::CMP,
278293
1,
279294
0,
280295
|uc, address, arg1, arg2, size| {
281296
hook_opcode_cmpcov(uc, address, arg1, arg2, size);
282297
},
283298
)
284299
.inspect_err(|ret| {
285-
warn!("Fail to add cmp and sub hooks due to {ret:?}");
300+
warn!("Fail to add cmp hooks due to {ret:?}");
286301
})?;
287302

288303
Ok(Self {
@@ -293,6 +308,7 @@ where
293308
always_validate,
294309
block_hook,
295310
sub_hook,
311+
cmp_hook,
296312
dumb_ob: tuple_list!(ValueObserver::new("dumb_ob", OwnedRef::Owned(false.into()))),
297313
})
298314
}
@@ -329,7 +345,10 @@ where
329345
warn!("Fail to uninstall block hook due to {ret:?}");
330346
}
331347
if let Err(ret) = self.uc.remove_hook(self.sub_hook) {
332-
warn!("Fail to uninstall cmp and sub tcg opcode hook due to {ret:?}");
348+
warn!("Fail to uninstall sub tcg opcode hook due to {ret:?}");
349+
}
350+
if let Err(ret) = self.uc.remove_hook(self.cmp_hook) {
351+
warn!("Fail to uninstall cmp tcg opcode hook due to {ret:?}");
333352
}
334353
}
335354
}

0 commit comments

Comments
 (0)