static void apply_effect (patch_effect_t *effect, test_entry_t *entry, guint32 offset) { gint32 value = 0; char *ptr = entry->data + offset; if (effect->expression) value = expression_eval (effect->expression, entry); switch (effect->type) { case EFFECT_SET_BYTE: DEBUG_PARSER (printf("\tset-byte effect old value [%x] new value [%x]\n", READ_VAR (guint8, ptr), value)); SET_VAR (guint8, ptr, value); break; case EFFECT_SET_USHORT: DEBUG_PARSER (printf("\tset-ushort effect old value [%x] new value [%x]\n", READ_VAR (guint16, ptr), value)); SET_VAR (guint16, ptr, value); break; case EFFECT_SET_UINT: DEBUG_PARSER (printf("\tset-uint effect old value [%x] new value [%x]\n", READ_VAR (guint32, ptr), value)); SET_VAR (guint32, ptr, value); break; case EFFECT_SET_TRUNC: DEBUG_PARSER (printf("\ttrunc effect [%d]\n", offset)); entry->data_size = offset; break; case EFFECT_SET_BIT: DEBUG_PARSER (printf("\tset-bit effect bit %d old value [%x]\n", value, READ_BIT (ptr, value))); SET_BIT (ptr, value); break; case EFFECT_OR_BYTE: DEBUG_PARSER (printf("\tor-byte effect old value [%x] new value [%x]\n", READ_VAR (guint8, ptr), value)); SET_VAR (guint8, ptr, READ_VAR (guint8, ptr) | value); break; case EFFECT_OR_USHORT: DEBUG_PARSER (printf("\tor-ushort effect old value [%x] new value [%x]\n", READ_VAR (guint16, ptr), value)); SET_VAR (guint16, ptr, READ_VAR (guint16, ptr) | value); break; case EFFECT_OR_UINT: DEBUG_PARSER (printf("\tor-uint effect old value [%x] new value [%x]\n", READ_VAR (guint32, ptr), value)); SET_VAR (guint32, ptr, READ_VAR (guint32, ptr) | value); break; default: printf ("Invalid effect type %d\n", effect->type); exit (INVALID_EFFECT); } }
static guint32 apply_selector (patch_selector_t *selector, test_entry_t *entry) { guint32 value = 0; if (selector->expression) value = expression_eval (selector->expression, entry); switch (selector->type) { case SELECTOR_ABS_OFFSET: DEBUG_PARSER (printf("\tabsolute offset selector [%04x]\n", value)); return value; default: printf ("Invalid selector type %d\n", selector->type); exit (INVALID_SELECTOR); } }
void print_ast(ast_node *node, int level) { ast_node *child; char *name = "(n/a)"; char info[AST_NODE_INFO_STR_LEN] = "(n/a)"; switch(node->type) { case NUMBER_NODE: snprintf(info, AST_NODE_INFO_STR_LEN-1, "%d", node->number); break; } if(node->name) { name = node->name; } DEBUG_PARSER("%*s+ AST node at %p, type %s, name %s, info %s\n", level*2, "", node, NGS_AST_NODE_TYPES_NAMES[node->type], name, info); for(child = node->first_child; child; child=child->next_sibling) { print_ast(child, level+1); } }
static void parse_test (scanner_t *scanner) { test_set_t set = { 0 }; CONSUME_IDENTIFIER (set.name); CONSUME_SPECIFIC_PUNCT ("{"); CONSUME_SPECIFIC_IDENTIFIER ("assembly"); CONSUME_IDENTIFIER (set.assembly); DEBUG_PARSER (printf ("RULE %s using assembly %s\n", set.name, set.assembly)); while (!match_current_type (scanner, TOKEN_EOF) && !match_current_type_and_text (scanner, TOKEN_PUNC, "}")) parse_test_entry (scanner, &set); CONSUME_SPECIFIC_PUNCT ("}"); test_set_free (&set); }
static void process_test_entry (test_set_t *test_set, test_entry_t *entry) { GSList *tmp; char *file_name; FILE *f; init_test_set (test_set); entry->data = g_memdup (test_set->assembly_data, test_set->assembly_size); entry->data_size = test_set->assembly_size; entry->test_set = test_set; DEBUG_PARSER (printf("(%d)%s\n", test_set->count, test_validity_name (entry->validity))); for (tmp = entry->patches; tmp; tmp = tmp->next) apply_patch (entry, tmp->data); file_name = make_test_name (entry, test_set); f = fopen (file_name, "wo"); fwrite (entry->data, entry->data_size, 1, f); fclose (f); g_free (file_name); }