From 7aca46984dd3591e860f0afec44607f173ad87b4 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 15 Feb 2014 17:40:08 +0200 Subject: [PATCH] handle decorated symbols better --- tools/asmproc.c | 40 +++++++++++++++++++++------------------- tools/protoparse.h | 6 ++++++ tools/translate.c | 19 +++++++++++-------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/tools/asmproc.c b/tools/asmproc.c index 6f1e3d5..c016fd5 100644 --- a/tools/asmproc.c +++ b/tools/asmproc.c @@ -18,6 +18,11 @@ static int cmp_sym(const void *p1_, const void *p2_) const char *s1 = p1->name, *s2 = p2->name; int i; + if (*s1 == '_') + s1++; + if (*s2 == '_') + s2++; + for (i = 0; ; i++) { if ((s1[i] | s2[i]) == 0) break; @@ -81,12 +86,13 @@ void read_list(struct sl_item **sl_in, int *cnt, int *alloc, *cnt = c; } -const char *sym_use(const struct sl_item *sym) +const char *sym_use(const struct sl_item *sym, int is_rm) { static char buf[256+3]; int ret; - ret = snprintf(buf, sizeof(buf), "rm_%s", sym->name); + ret = snprintf(buf, sizeof(buf), "%s%s", + is_rm ? "rm_" : "", sym->name); if (ret >= sizeof(buf)) { printf("truncation detected: '%s'\n", buf); exit(1); @@ -188,7 +194,7 @@ int main(int argc, char *argv[]) sizeof(symlist[0]), cmp_sym); if (sym != NULL) { sym->found = 1; - fprintf(fout, "rm_%s\t%s%s", word, word2, p); + fprintf(fout, "%s\t%s%s", sym_use(sym, 1), word2, p); continue; } } @@ -197,11 +203,9 @@ int main(int argc, char *argv[]) ssym.name = word2; sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); - if (sym != NULL - && (sym->callsites || IS(word2, func))) - { + if (sym != NULL) { fprintf(fout, "\t\t%s\t%s%s", word, - sym_use(sym), p); + sym_use(sym, sym->callsites || IS(word2, func)), p); continue; } } @@ -211,7 +215,7 @@ int main(int argc, char *argv[]) sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); if (sym != NULL) { - fprintf(fout, "\t\tpublic %s%s", sym_use(sym), p); + fprintf(fout, "\t\tpublic %s%s", sym_use(sym, 1), p); continue; } } @@ -225,15 +229,13 @@ int main(int argc, char *argv[]) // push offset // jcc short if ( (IS(word, "push") && IS(word2, "offset")) - || (word[0] == 'j' && IS(word2, "short")) ) { + || (word[0] == 'j' && IS(word2, "short") && !IS(word3, "exit")) ) { ssym.name = word3; sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); - if (sym != NULL - && (sym->callsites || IS(word3, func))) - { - fprintf(fout, "\t\t%s %s %s%s", - word, word2, sym_use(sym), p); + if (sym != NULL) { + fprintf(fout, "\t\t%s %s %s%s", word, word2, + sym_use(sym, sym->callsites || IS(word3, func)), p); continue; } } @@ -270,10 +272,10 @@ int main(int argc, char *argv[]) ssym.name = word4; sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); - if (sym != NULL && sym->callsites) { + if (sym != NULL) { fprintf(fout, "\t\t%s\t%s %s %s%s", word, word2, word3, - sym_use(sym), p); + sym_use(sym, sym->callsites), p); continue; } } @@ -296,9 +298,9 @@ int main(int argc, char *argv[]) ssym.name = word6; sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); - if (sym != NULL && sym->callsites) { + if (sym != NULL) { fprintf(fout, "\t\t%s\tdword ptr %s offset %s%s", - word, word4, sym_use(sym), p); + word, word4, sym_use(sym, sym->callsites), p); continue; } } @@ -330,7 +332,7 @@ offset_loop: sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); fprintf(fout, " offset %s%s", - (sym != NULL && sym->callsites) ? sym_use(sym) : word, + (sym != NULL) ? sym_use(sym, sym->callsites) : word, p2 ? "," : ""); } fprintf(fout, "%s", p); diff --git a/tools/protoparse.h b/tools/protoparse.h index 9a126cc..d58bf83 100644 --- a/tools/protoparse.h +++ b/tools/protoparse.h @@ -162,6 +162,7 @@ static const char *known_ptr_types[] = { "HRSRC", "HKEY", "HMENU", + "HWAVEOUT", "HWND", "PBYTE", "PCRITICAL_SECTION", @@ -664,6 +665,7 @@ static const struct parsed_proto *proto_parse(FILE *fhdr, const char *sym, { const struct parsed_proto *pp_ret; struct parsed_proto pp_search; + char *p; if (pp_cache == NULL) build_pp_cache(fhdr); @@ -672,6 +674,10 @@ static const struct parsed_proto *proto_parse(FILE *fhdr, const char *sym, sym++; strcpy(pp_search.name, sym); + p = strchr(pp_search.name, '@'); + if (p != NULL) + *p = 0; + pp_ret = bsearch(&pp_search, pp_cache, pp_cache_size, sizeof(pp_cache[0]), pp_name_cmp); if (pp_ret == NULL && !quiet) diff --git a/tools/translate.c b/tools/translate.c index f5674ca..97f2595 100644 --- a/tools/translate.c +++ b/tools/translate.c @@ -1504,7 +1504,8 @@ static void check_func_pp(struct parsed_op *po, } } -static void check_label_read_ref(struct parsed_op *po, const char *name) +static const char *check_label_read_ref(struct parsed_op *po, + const char *name) { const struct parsed_proto *pp; @@ -1514,6 +1515,8 @@ static void check_label_read_ref(struct parsed_op *po, const char *name) if (pp->is_func) check_func_pp(po, pp, "ref"); + + return pp->name; } static char *out_src_opr(char *buf, size_t buf_size, @@ -1522,6 +1525,7 @@ static char *out_src_opr(char *buf, size_t buf_size, { char tmp1[256], tmp2[256]; char expr[256]; + const char *name; char *p; int ret; @@ -1589,29 +1593,28 @@ static char *out_src_opr(char *buf, size_t buf_size, break; case OPT_LABEL: - check_label_read_ref(po, popr->name); + name = check_label_read_ref(po, popr->name); if (cast[0] == 0 && popr->is_ptr) cast = "(u32)"; if (is_lea) - snprintf(buf, buf_size, "(u32)&%s", popr->name); + snprintf(buf, buf_size, "(u32)&%s", name); else if (popr->size_lt) snprintf(buf, buf_size, "%s%s%s%s", cast, lmod_cast_u_ptr(po, popr->lmod), - popr->is_array ? "" : "&", - popr->name); + popr->is_array ? "" : "&", name); else - snprintf(buf, buf_size, "%s%s%s", cast, popr->name, + snprintf(buf, buf_size, "%s%s%s", cast, name, popr->is_array ? "[0]" : ""); break; case OPT_OFFSET: - check_label_read_ref(po, popr->name); + name = check_label_read_ref(po, popr->name); if (cast[0] == 0) cast = "(u32)"; if (is_lea) ferr(po, "lea an offset?\n"); - snprintf(buf, buf_size, "%s&%s", cast, popr->name); + snprintf(buf, buf_size, "%s&%s", cast, name); break; case OPT_CONST: -- 2.39.5