samples: code style for sample_x86_32_gdt_and_seg_regs.c

This commit is contained in:
Nguyen Anh Quynh
2016-03-27 10:25:46 +08:00
parent cf793122be
commit e44f8f2981

View File

@ -103,7 +103,8 @@ do { \
/******************************************************************************/ /******************************************************************************/
void hook_mem(uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data) { static void hook_mem(uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data)
{
switch(type) { switch(type) {
case UC_MEM_WRITE: case UC_MEM_WRITE:
printf("mem write at 0x%"PRIx64 ", size = %u, value = 0x%"PRIx64 "\n", address, size, value); printf("mem write at 0x%"PRIx64 ", size = %u, value = 0x%"PRIx64 "\n", address, size, value);
@ -112,12 +113,14 @@ void hook_mem(uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64
} }
} }
void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user_data) { static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
{
printf("Executing at 0x%"PRIx64 ", ilen = 0x%x\n", address, size); printf("Executing at 0x%"PRIx64 ", ilen = 0x%x\n", address, size);
} }
//VERY basic descriptor init function, sets many fields to user space sane defaults //VERY basic descriptor init function, sets many fields to user space sane defaults
void init_descriptor(struct SegmentDescriptor *desc, uint32_t base, uint32_t limit, uint8_t is_code) { static void init_descriptor(struct SegmentDescriptor *desc, uint32_t base, uint32_t limit, uint8_t is_code)
{
desc->desc = 0; //clear the descriptor desc->desc = 0; //clear the descriptor
desc->base0 = base & 0xffff; desc->base0 = base & 0xffff;
desc->base1 = (base >> 16) & 0xff; desc->base1 = (base >> 16) & 0xff;
@ -138,7 +141,9 @@ void init_descriptor(struct SegmentDescriptor *desc, uint32_t base, uint32_t lim
desc->system = 1; //code or data desc->system = 1; //code or data
} }
void hex_dump(unsigned char *ptr, unsigned int len) { /*
static void hex_dump(unsigned char *ptr, unsigned int len)
{
int i; int i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (i != 0 && (i & 0xf) == 0) { if (i != 0 && (i & 0xf) == 0) {
@ -148,8 +153,10 @@ void hex_dump(unsigned char *ptr, unsigned int len) {
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
*/
static void gdt_demo() { static void gdt_demo()
{
uc_engine *uc; uc_engine *uc;
uc_hook hook1, hook2; uc_hook hook1, hook2;
uc_err err; uc_err err;
@ -273,12 +280,12 @@ mov dword [fs:4], 0x89abcdef
assert(memcmp(buf, "\x67\x45\x23\x01\xef\xcd\xab\x89", 8) == 0); assert(memcmp(buf, "\x67\x45\x23\x01\xef\xcd\xab\x89", 8) == 0);
uc_close(uc); uc_close(uc);
} }
/******************************************************************************/ /******************************************************************************/
int main(int argc, char **argv) { int main(int argc, char **argv)
{
gdt_demo(); gdt_demo();
fprintf(stderr, "success\n"); fprintf(stderr, "success\n");