From 53b50c908bc9c910d3ab8130f8b0e668121918ec Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 7 Nov 2015 03:06:42 +0200 Subject: [PATCH] new header tool outputs a header IDA is almost happy with --- tools/Makefile | 6 ++-- tools/cvt_hdr.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 tools/cvt_hdr.c diff --git a/tools/Makefile b/tools/Makefile index ef94fce..2f0a1ef 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,7 +3,8 @@ ifndef DEBUG CFLAGS += -O2 endif -T = asmproc cmpmrg_text mkbridge translate cvt_data mkdef_ord +T += asmproc cmpmrg_text mkbridge translate +T += cvt_data cvt_hdr mkdef_ord all: $(T) @@ -13,8 +14,9 @@ clean: translate: translate.o mkbridge: mkbridge.o cvt_data: cvt_data.o +cvt_hdr: cvt_hdr.o mkdef_ord: mkdef_ord.o -mkbridge.o translate.o cvt_data.o mkdef_ord.o: \ +mkbridge.o translate.o cvt_data.o cvt_hdr.o mkdef_ord.o: \ protoparse.h my_assert.h my_str.h translate: LDLIBS += -lm diff --git a/tools/cvt_hdr.c b/tools/cvt_hdr.c new file mode 100644 index 0000000..c698c19 --- /dev/null +++ b/tools/cvt_hdr.c @@ -0,0 +1,91 @@ +/* + * ia32rtools + * header simplification - + * output only stack args forced to basic types + * + * (C) notaz, 2013-2015 + * + * This work is licensed under the terms of 3-clause BSD license. + * See COPYING file in the top-level directory. + */ + +#include +#include +#include + +#include "my_assert.h" +#include "my_str.h" +#include "common.h" + +#include "protoparse.h" + +static const char *output_type(const struct parsed_type *type) +{ + if (type->is_float) + return "float"; + else if (type->is_64bit) + return "__int64"; + else if (IS(type->name, "void")) + return "void"; + else + return "int"; +} + +int main(int argc, char *argv[]) +{ + const struct parsed_proto *pp; + FILE *fhdr, *fout; + int i, a, a_out; + + if (argc != 3) { + printf("usage:\n%s \n", argv[0]); + return 1; + } + + hdrfn = argv[2]; + fhdr = fopen(hdrfn, "r"); + my_assert_not(fhdr, NULL); + fout = fopen(argv[1], "w"); + my_assert_not(fout, NULL); + + build_caches(fhdr); + + for (i = 0; i < pp_cache_size; i++) { + pp = &pp_cache[i]; + if (!pp->is_func || pp->is_fptr || pp->is_osinc) + continue; + + if (pp->argc_reg != 0) + fprintf(fout, "// %d reg args\n", pp->argc_reg); + fprintf(fout, "%-4s ", output_type(&pp->ret_type)); + if (!pp->is_stdcall || pp->argc_stack == 0) + fprintf(fout, "__cdecl "); + else + fprintf(fout, "__stdcall "); + fprintf(fout, "%s(", pp->name); + + for (a = a_out = 0; a < pp->argc; a++) { + if (pp->arg[a].reg != NULL || pp->arg[a].type.is_retreg) + continue; + if (a_out++ > 0) + fprintf(fout, ", "); + fprintf(fout, "%s", output_type(&pp->arg[a].type)); + if (pp->arg[a].type.is_64bit) + a++; + } + if (pp->is_vararg) { + if (a_out > 0) + fprintf(fout, ", "); + fprintf(fout, "..."); + } + fprintf(fout, ");\n"); + } + + fclose(fhdr); + fclose(fout); + (void)proto_parse; + + return 0; +} + +// vim:ts=2:shiftwidth=2:expandtab -- 2.39.2