avast / retdec

RetDec is a retargetable machine-code decompiler based on LLVM.
https://retdec.com/
MIT License
7.96k stars 939 forks source link

Variadic function decompilation #140

Open PeterMatula opened 6 years ago

PeterMatula commented 6 years ago

Analyze if it is somehow possible to correctly decompile something like this?

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

void print_error(const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    fprintf(stderr, "error: ");
    vfprintf(stderr, fmt, args);
    va_end(args);

    exit(1);
}

int main(int argc, char *argv[]) {
    print_error("argc = %d, argv[0] = %sn", argc, argv[0]);
    return 0;
}
nihilus commented 5 years ago

Even standard printf()-functions get incorrectly decompiled for MIPS. Any clues?

PeterMatula commented 5 years ago

@nihilus Getting the variadic functions right is very hard in general, but we should do better if we know that the function is printf(), or some of its variant we have type information for. So, if you have a case when it id bad even in such a case, please report it - provide a sample and we will look into it.