rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.
https://rizin.re
GNU Lesser General Public License v3.0
2.7k stars 361 forks source link

Convert `bin_versioninfo()` from `librz/core/cbin.c` into the proper API #1732

Open XVilka opened 3 years ago

XVilka commented 3 years ago

Currently it just prints. This whole chunk of functions should be split in two main pieces: one to extract all information and another to print it:

Note, that the actual API function to get the information about versions could be moved to librz/bin/version.c, for example, since it doesn't require anything RzCore-specific. The printing functions we can keep in librz/core/cbin.c as before.

RZ_API bool rz_core_bin_versions_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state) {
    rz_return_val_if_fail(core && state, false);

    // TODO: add rz_bin_object_get_versions and switch to table + json output
    switch (state->mode) {
    case RZ_OUTPUT_MODE_STANDARD:
        bin_versioninfo(core, NULL, RZ_MODE_PRINT);
        break;
    case RZ_OUTPUT_MODE_JSON:
        bin_versioninfo(core, state->d.pj, RZ_MODE_JSON);
        break;
    default:
        rz_warn_if_reached();
        break;
    }
    return true;
}

static int bin_versioninfo(RzCore *r, PJ *pj, int mode) {
    const RzBinInfo *info = rz_bin_get_info(r->bin);
    if (!info || !info->rclass) {
        return false;
    }
    if (!strncmp("pe", info->rclass, 2)) {
        bin_pe_versioninfo(r, pj, mode);
    } else if (!strncmp("elf", info->rclass, 3)) {
        bin_elf_versioninfo(r, pj, mode);
    } else if (!strncmp("mach0", info->rclass, 5)) {
        bin_mach0_versioninfo(r);
    } else {
        rz_cons_println("Unknown format");
        return false;
    }
    return true;
}
ret2libc commented 3 years ago

At this point I think I'm going to skip this for now... To better define the problem, this is not only about refactoring those functions, but to properly do that we would need to create the right RzBinVersion structure, that is generic enough to contain information from all major file formats (right now we support pe, mach0, elf). Then, we will need to add a .version method to RzBinPlugins and provide those info from the plugins themselves.

The main problem I see is that version information are very different from one format to the other. I don't think it is a must right now to have this information well formed.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. Considering a lot has probably changed since its creation, we kindly ask you to check again if the issue you reported is still relevant in the current version of rizin. If it is, update this issue with a comment, otherwise it will be automatically closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because marked as stale and it has not been updated since then. If the issue is still relevant, feel free to re-open it or open a new one.