diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-05-24 21:45:53 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-05-24 21:46:04 (GMT) |
commit | 0e2849345be5018152d60b5aa27eebb2de75e1df (patch) | |
tree | 524c6f7e5a5a32fa65427c44d8baa2e6204eb732 /src/arch | |
parent | 3a77653d347c8e60a1c80bd4d57a4fd5e317490f (diff) |
Attached priority levels with disassembly starting points.
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/arm/v7/context.c | 7 | ||||
-rw-r--r-- | src/arch/arm/v7/fetch.c | 19 | ||||
-rw-r--r-- | src/arch/context-int.h | 8 | ||||
-rw-r--r-- | src/arch/context.c | 62 | ||||
-rw-r--r-- | src/arch/context.h | 16 | ||||
-rw-r--r-- | src/arch/dalvik/fetch.c | 2 |
6 files changed, 74 insertions, 40 deletions
diff --git a/src/arch/arm/v7/context.c b/src/arch/arm/v7/context.c index 446a972..659fdd1 100644 --- a/src/arch/arm/v7/context.c +++ b/src/arch/arm/v7/context.c @@ -63,7 +63,7 @@ static void g_armv7_context_dispose(GArmV7Context *); static void g_armv7_context_finalize(GArmV7Context *); /* Ajoute une adresse virtuelle comme point de départ de code. */ -static void g_armv7_context_push_drop_point(GArmV7Context *, unsigned int, virt_t, va_list); +static void g_armv7_context_push_drop_point(GArmV7Context *, DisassPriorityLevel, virt_t, va_list); @@ -209,13 +209,14 @@ GArmV7Context *g_armv7_context_new(void) * * ******************************************************************************/ -static void g_armv7_context_push_drop_point(GArmV7Context *ctx, unsigned int level, virt_t addr, va_list ap) +static void g_armv7_context_push_drop_point(GArmV7Context *ctx, DisassPriorityLevel level, virt_t addr, va_list ap) { ArmV7InstrSet marker; /* Type de jeu d'instructions */ switch (level) { - case 0: + case DPL_ENTRY_POINT: + case DPL_SYMBOL: if (addr & 0x1) { diff --git a/src/arch/arm/v7/fetch.c b/src/arch/arm/v7/fetch.c index 206e6e6..67129b2 100644 --- a/src/arch/arm/v7/fetch.c +++ b/src/arch/arm/v7/fetch.c @@ -99,7 +99,7 @@ void help_fetching_with_instruction_b_with_orig(GArchInstruction *instr, GArchPr target = pc + offset; //g_armv7_context_define_encoding(context, target, iset); - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, target, iset); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target, iset); } @@ -168,7 +168,7 @@ void help_fetching_with_instruction_bl_with_orig(GArchInstruction *instr, GArchP target = pc + offset; //g_armv7_context_define_encoding(context, target, iset); - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, target, iset); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target, iset); } @@ -227,7 +227,7 @@ void help_fetching_with_instruction_blx_with_dest(GArchInstruction *instr, GArch target = pc + offset; //g_armv7_context_define_encoding(context, target, iset); - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, target, iset); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target, iset); } @@ -280,12 +280,12 @@ void help_fetching_with_instruction_bx_with_orig(GArchInstruction *instr, GArchP case AV7IS_ARM: pc += 8; //g_armv7_context_define_encoding(context, - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, pc, AV7IS_THUMB); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, pc, AV7IS_THUMB); break; case AV7IS_THUMB: pc += 4; //g_armv7_context_define_encoding(context, - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, pc, AV7IS_ARM); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, pc, AV7IS_ARM); break; default: assert(0); @@ -342,7 +342,7 @@ void help_fetching_with_instruction_cb_n_z(GArchInstruction *instr, GArchProcess target = pc + offset; //g_armv7_context_define_encoding(context, target, AV7IS_THUMB); - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, target, AV7IS_THUMB); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target, AV7IS_THUMB); } @@ -518,8 +518,13 @@ void help_fetching_with_instruction_ldr_literal_with_orig(GArchInstruction *inst //target = pc + offset; + if (target & 0x1) + iset = AV7IS_THUMB; + //else + // iset = AV7IS_ARM; + //g_armv7_context_define_encoding(context, target, AV7IS_THUMB); - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 0/*FIXME*/, target); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target, iset); //exit(0); diff --git a/src/arch/context-int.h b/src/arch/context-int.h index 59a06bb..1ea8b6c 100644 --- a/src/arch/context-int.h +++ b/src/arch/context-int.h @@ -37,7 +37,7 @@ /* Ajoute une adresse virtuelle comme point de départ de code. */ -typedef void (* push_drop_point_fc) (GProcContext *, unsigned int, virt_t, va_list); +typedef void (* push_drop_point_fc) (GProcContext *, DisassPriorityLevel, virt_t, va_list); /* Définition d'un contexte pour processeur (instance) */ @@ -45,9 +45,9 @@ struct _GProcContext { GObject parent; /* A laisser en premier */ - virt_t *drop_points; /* Liste de points de départ */ - size_t dp_allocated; /* Taille de liste allouée */ - size_t dp_count; /* Quantité utile de la liste */ + virt_t *drop_points[DPL_COUNT]; /* Liste de points de départ */ + size_t dp_allocated[DPL_COUNT]; /* Taille de liste allouée */ + size_t dp_count[DPL_COUNT]; /* Quantité utile de la liste */ GMutex dp_access; /* Accès à la liste FIFO */ vmpa2t *extra_symbols; /* Adresses de symboles */ diff --git a/src/arch/context.c b/src/arch/context.c index 98eebb2..979a403 100644 --- a/src/arch/context.c +++ b/src/arch/context.c @@ -40,7 +40,7 @@ static void g_proc_context_class_init(GProcContextClass *); static void g_proc_context_init(GProcContext *); /* Ajoute une adresse virtuelle comme point de départ de code. */ -static void _g_proc_context_push_drop_point(GProcContext *, unsigned int, virt_t, va_list); +static void _g_proc_context_push_drop_point(GProcContext *, DisassPriorityLevel, virt_t, va_list); @@ -90,9 +90,15 @@ static void g_proc_context_class_init(GProcContextClass *klass) static void g_proc_context_init(GProcContext *ctx) { - ctx->drop_points = NULL; - ctx->dp_allocated = 0; - ctx->dp_count = 0; + DisassPriorityLevel i; /* Boucle de parcours */ + + for (i = 0; i < DPL_COUNT; i++) + { + ctx->drop_points[i] = NULL; + ctx->dp_allocated[i] = 0; + ctx->dp_count[i] = 0; + } + g_mutex_init(&ctx->dp_access); ctx->extra_symbols = NULL; @@ -137,17 +143,22 @@ void g_proc_context_attach_counter(GProcContext *ctx, gint *counter) * * ******************************************************************************/ -static void _g_proc_context_push_drop_point(GProcContext *ctx, unsigned int level, virt_t addr, va_list ap) +static void _g_proc_context_push_drop_point(GProcContext *ctx, DisassPriorityLevel level, virt_t addr, va_list ap) { - if (ctx->dp_count >= ctx->dp_allocated) + assert(level < DPL_COUNT); + + if (ctx->dp_count[level] >= ctx->dp_allocated[level]) { - ctx->dp_allocated += DP_ALLOC_BLOCK; + ctx->dp_allocated[level] += DP_ALLOC_BLOCK; - ctx->drop_points = (virt_t *)realloc(ctx->drop_points, ctx->dp_allocated * sizeof(virt_t)); + ctx->drop_points[level] = (virt_t *)realloc(ctx->drop_points[level], + ctx->dp_allocated[level] * sizeof(virt_t)); } - ctx->drop_points[ctx->dp_count++] = addr; + ctx->drop_points[level][ctx->dp_count[level]] = addr; + + ctx->dp_count[level]++; } @@ -167,7 +178,7 @@ static void _g_proc_context_push_drop_point(GProcContext *ctx, unsigned int leve * * ******************************************************************************/ -void g_proc_context_push_drop_point(GProcContext *ctx, unsigned int level, virt_t addr, ...) +void g_proc_context_push_drop_point(GProcContext *ctx, DisassPriorityLevel level, virt_t addr, ...) { va_list ap; /* Arguments complémentaires ? */ @@ -191,8 +202,9 @@ void g_proc_context_push_drop_point(GProcContext *ctx, unsigned int level, virt_ /****************************************************************************** * * -* Paramètres : ctx = contexte de désassemblage à compléter. * -* virt = adresse d'un point de départ de code à traiter. * +* Paramètres : ctx = contexte de désassemblage à compléter. * +* level = degré d'importance de l'adresse retournée. [OUT] * +* virt = adresse d'un point de départ de code à traiter. [OUT]* * * * Description : Fournit une adresse virtuelle comme point de départ de code. * * * @@ -202,26 +214,30 @@ void g_proc_context_push_drop_point(GProcContext *ctx, unsigned int level, virt_ * * ******************************************************************************/ -bool g_proc_context_pop_drop_point(GProcContext *ctx, virt_t *virt) +bool g_proc_context_pop_drop_point(GProcContext *ctx, DisassPriorityLevel *level, virt_t *virt) { bool result; /* Bilan d'accès à retourner */ + DisassPriorityLevel i; /* Boucle de parcours */ + + result = false; g_mutex_lock(&ctx->dp_access); - if (ctx->dp_count > 0) - { - result = true; + for (i = 0; i < DPL_COUNT && !result; i++) + if (ctx->dp_count[i] > 0) + { + result = true; - *virt = ctx->drop_points[0]; + *level = i; + *virt = ctx->drop_points[i][0]; - if (ctx->dp_count > 1) - memmove(&ctx->drop_points[0], &ctx->drop_points[1], (ctx->dp_count - 1) * sizeof(virt_t)); + if (ctx->dp_count[i] > 1) + memmove(&ctx->drop_points[i][0], &ctx->drop_points[i][1], + (ctx->dp_count[i] - 1) * sizeof(virt_t)); - ctx->dp_count--; + ctx->dp_count[i]--; - } - else - result = false; + } g_mutex_unlock(&ctx->dp_access); diff --git a/src/arch/context.h b/src/arch/context.h index 334eaf1..d8b5793 100644 --- a/src/arch/context.h +++ b/src/arch/context.h @@ -48,6 +48,18 @@ typedef struct _GProcContext GProcContext; typedef struct _GProcContextClass GProcContextClass; +/* Degré de priorité des points à désassembler */ +typedef enum _DisassPriorityLevel +{ + DPL_ENTRY_POINT, /* Validité indiscutable */ + DPL_SYMBOL, /* Symboles utilisés */ + DPL_OTHER, /* Injections complémentaires */ + + DPL_COUNT + +} DisassPriorityLevel; + + /* Indique le type définit par la GLib pour le contexte de processeur. */ GType g_proc_context_get_type(void); @@ -55,10 +67,10 @@ GType g_proc_context_get_type(void); void g_proc_context_attach_counter(GProcContext *, gint *); /* Ajoute une adresse virtuelle comme point de départ de code. */ -void g_proc_context_push_drop_point(GProcContext *, unsigned int, virt_t, ...); +void g_proc_context_push_drop_point(GProcContext *, DisassPriorityLevel, virt_t, ...); /* Fournit une adresse virtuelle comme point de départ de code. */ -bool g_proc_context_pop_drop_point(GProcContext *, virt_t *); +bool g_proc_context_pop_drop_point(GProcContext *, DisassPriorityLevel *, virt_t *); /* Empile une adresse de nouveau symbole à prendre en compte. */ void g_proc_context_push_new_symbol_at(GProcContext *, const vmpa2t *); diff --git a/src/arch/dalvik/fetch.c b/src/arch/dalvik/fetch.c index a557601..d9bbf9b 100644 --- a/src/arch/dalvik/fetch.c +++ b/src/arch/dalvik/fetch.c @@ -57,6 +57,6 @@ void help_fetching_with_dalvik_instruction(GArchInstruction *instr, GArchProcess assert(status); if (status) - g_proc_context_push_drop_point(G_PROC_CONTEXT(context), 3, target); + g_proc_context_push_drop_point(G_PROC_CONTEXT(context), DPL_OTHER, target); } |