Skip to content

Commit 6d61aec

Browse files
committed
Format code
1 parent fdd129f commit 6d61aec

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

include/uc_priv.h

+21-12
Original file line numberDiff line numberDiff line change
@@ -422,33 +422,39 @@ typedef struct HookedRegion {
422422
} HookedRegion;
423423

424424
// hooked_regions related functions
425-
static inline guint hooked_regions_hash(const void* p) {
426-
HookedRegion *region = (HookedRegion*)p;
425+
static inline guint hooked_regions_hash(const void *p)
426+
{
427+
HookedRegion *region = (HookedRegion *)p;
427428

428429
return qemu_xxhash4(region->start, region->length);
429430
}
430431

431-
static inline gboolean hooked_regions_equal(const void* lhs, const void* rhs) {
432-
HookedRegion *l = (HookedRegion*)lhs;
433-
HookedRegion *r = (HookedRegion*)rhs;
432+
static inline gboolean hooked_regions_equal(const void *lhs, const void *rhs)
433+
{
434+
HookedRegion *l = (HookedRegion *)lhs;
435+
HookedRegion *r = (HookedRegion *)rhs;
434436

435437
return l->start == r->start && l->length == r->length;
436438
}
437439

438-
static inline void hooked_regions_add(struct hook* h, uint64_t start, uint64_t length) {
440+
static inline void hooked_regions_add(struct hook *h, uint64_t start,
441+
uint64_t length)
442+
{
439443
HookedRegion tmp;
440444
tmp.start = start;
441445
tmp.length = length;
442446

443-
if (!g_hash_table_lookup(h->hooked_regions, (void*)&tmp)) {
444-
HookedRegion* r = malloc(sizeof(HookedRegion));
447+
if (!g_hash_table_lookup(h->hooked_regions, (void *)&tmp)) {
448+
HookedRegion *r = malloc(sizeof(HookedRegion));
445449
r->start = start;
446450
r->length = length;
447-
g_hash_table_insert(h->hooked_regions, (void*)r, (void*)1);
451+
g_hash_table_insert(h->hooked_regions, (void *)r, (void *)1);
448452
}
449453
}
450454

451-
static inline void hooked_regions_check_single(struct list_item *cur, uint64_t start, uint64_t length) {
455+
static inline void hooked_regions_check_single(struct list_item *cur,
456+
uint64_t start, uint64_t length)
457+
{
452458
while (cur != NULL) {
453459
if (HOOK_BOUND_CHECK((struct hook *)cur->data, start)) {
454460
hooked_regions_add((struct hook *)cur->data, start, length);
@@ -457,10 +463,13 @@ static inline void hooked_regions_check_single(struct list_item *cur, uint64_t s
457463
}
458464
}
459465

460-
static inline void hooked_regions_check(uc_engine *uc, uint64_t start, uint64_t length) {
466+
static inline void hooked_regions_check(uc_engine *uc, uint64_t start,
467+
uint64_t length)
468+
{
461469
// Only UC_HOOK_BLOCK and UC_HOOK_CODE might be wrongle cached!
462470
hooked_regions_check_single(uc->hook[UC_HOOK_CODE_IDX].head, start, length);
463-
hooked_regions_check_single(uc->hook[UC_HOOK_BLOCK_IDX].head, start, length);
471+
hooked_regions_check_single(uc->hook[UC_HOOK_BLOCK_IDX].head, start,
472+
length);
464473
}
465474

466475
#ifdef UNICORN_TRACER

tests/unit/test_ctl.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -227,31 +227,37 @@ static void test_uc_ctl_arm_cpu(void)
227227
OK(uc_close(uc));
228228
}
229229

230-
static void test_uc_hook_cached_cb(uc_engine* uc, uint64_t addr, size_t size, void* user_data) {
231-
// Don't add any TEST_CHECK here since we can't refer to the global variable here.
232-
uint64_t* p = (uint64_t*)user_data;
230+
static void test_uc_hook_cached_cb(uc_engine *uc, uint64_t addr, size_t size,
231+
void *user_data)
232+
{
233+
// Don't add any TEST_CHECK here since we can't refer to the global variable
234+
// here.
235+
uint64_t *p = (uint64_t *)user_data;
233236
(*p)++;
234237
return;
235238
}
236239

237240
static void test_uc_hook_cached_uaf(void)
238241
{
239-
uc_engine* uc;
242+
uc_engine *uc;
240243
// "INC ecx; DEC edx; jmp t; t: nop"
241244
char code[] = "\x41\x4a\xeb\x00\x90";
242245
uc_hook h;
243246
uint64_t count = 0;
244247
#ifndef _WIN32
245-
void* callback = mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
248+
void *callback = mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC,
249+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
246250
#else
247-
void* callback = VirtualAlloc(NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)
251+
void *callback = VirtualAlloc(NULL, 4096, MEM_RESERVE | MEM_COMMIT,
252+
PAGE_EXECUTE_READWRITE)
248253
#endif
249254

250-
memcpy(callback, (void*)test_uc_hook_cached_cb, 4096);
255+
memcpy(callback, (void *)test_uc_hook_cached_cb, 4096);
251256

252257
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1);
253258

254-
OK(uc_hook_add(uc, &h, UC_HOOK_CODE, (void*)callback, (void*)&count, 1, 0));
259+
OK(uc_hook_add(uc, &h, UC_HOOK_CODE, (void *)callback, (void *)&count, 1,
260+
0));
255261

256262
OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
257263

@@ -275,7 +281,6 @@ static void test_uc_hook_cached_uaf(void)
275281
#else
276282
VirtualFree(callback, 0, MEM_RELEASE);
277283
#endif
278-
279284
}
280285

281286
TEST_LIST = {{"test_uc_ctl_mode", test_uc_ctl_mode},

uc.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ static void *hook_append(struct list *l, struct hook *h)
4949
return item;
5050
}
5151

52-
static void hook_invalidate_region(void* key, void* data, void* opaq)
52+
static void hook_invalidate_region(void *key, void *data, void *opaq)
5353
{
54-
uc_engine* uc = (uc_engine*)opaq;
55-
HookedRegion* region = (HookedRegion*)key;
54+
uc_engine *uc = (uc_engine *)opaq;
55+
HookedRegion *region = (HookedRegion *)key;
5656

5757
uc->uc_invalidate_tb(uc, region->start, region->length);
5858
}
@@ -1570,7 +1570,8 @@ uc_err uc_hook_add(uc_engine *uc, uc_hook *hh, int type, void *callback,
15701570
hook->user_data = user_data;
15711571
hook->refs = 0;
15721572
hook->to_delete = false;
1573-
hook->hooked_regions = g_hash_table_new_full(hooked_regions_hash, hooked_regions_equal, g_free, NULL);
1573+
hook->hooked_regions = g_hash_table_new_full(
1574+
hooked_regions_hash, hooked_regions_equal, g_free, NULL);
15741575
*hh = (uc_hook)hook;
15751576

15761577
// UC_HOOK_INSN has an extra argument for instruction ID
@@ -1680,7 +1681,8 @@ uc_err uc_hook_del(uc_engine *uc, uc_hook hh)
16801681
// and store the type mask in the hook pointer.
16811682
for (i = 0; i < UC_HOOK_MAX; i++) {
16821683
if (list_exists(&uc->hook[i], (void *)hook)) {
1683-
g_hash_table_foreach(hook->hooked_regions, hook_invalidate_region, uc);
1684+
g_hash_table_foreach(hook->hooked_regions, hook_invalidate_region,
1685+
uc);
16841686
g_hash_table_remove_all(hook->hooked_regions);
16851687
hook->to_delete = true;
16861688
uc->hooks_count[i]--;

0 commit comments

Comments
 (0)