示例#1
0
static void
get_full_path(const char *app, char *buf, size_t buflen/*# elements*/)
{
    drfront_status_t sc = drfront_get_app_full_path(app, buf, buflen);
    if (sc != DRFRONT_SUCCESS)
        FATAL_ERROR("drfront_get_app_full_path failed on %s: %d\n", app, sc);
}
示例#2
0
static void
get_full_path(const char *app, char *buf, size_t buflen/*# elements*/)
{
    drfront_status_t sc = drfront_get_app_full_path(app, buf, buflen);
    if (sc != DRFRONT_SUCCESS)
        warn("failed (status=%d) to find application %s", sc, app);
}
示例#3
0
static bool
check_architecture(const char *dll, char **argv)
{
    bool is_64bit, also_32bit;
    if (drfront_is_64bit_app(dll, &is_64bit, &also_32bit) != DRFRONT_SUCCESS) {
        printf("ERROR: unable to get the architecture infomation of"
               " the target module %s\n", dll);
        return false;
    }
    if (IF_X64_ELSE(!is_64bit, is_64bit && !also_32bit)) {
        char *orig_argv0 = argv[0];
        char root[MAXIMUM_PATH];
        char buf[MAXIMUM_PATH];
        char *basename;
        int errcode;
        void *inject_data;
        bool is_readable;
        if (drfront_get_app_full_path(argv[0], root, BUFFER_SIZE_ELEMENTS(root)) !=
            DRFRONT_SUCCESS) {
            printf("ERROR: unable to get base dir of %s\n", argv[0]);
            return false;
        }
        basename = root + strlen(root) - 1;
        while (*basename != DIRSEP && *basename != ALT_DIRSEP && basename > root)
            basename--;
        if (basename <= root) {
            printf("ERROR: unable to get base dir of %s\n", argv[0]);
            return false;
        }
        *basename = '\0';
        basename++;
        _snprintf(buf, BUFFER_SIZE_ELEMENTS(buf) ,
                  "%s%c..%c%s%c%s", root, DIRSEP, DIRSEP,
                  IF_X64_ELSE("bin", "bin64"), DIRSEP, basename);
        NULL_TERMINATE_BUFFER(buf);
        if (drfront_access(buf, DRFRONT_READ, &is_readable) != DRFRONT_SUCCESS ||
            !is_readable) {
            printf("ERROR: unable to find frontend %s to match target file bitwidth: "
                   "is this an incomplete installation?\n", buf);
        }
        argv[0] = buf;
#ifdef UNIX
        errcode = dr_inject_prepare_to_exec(buf, (const char **)argv, &inject_data);
        if (errcode == 0 || errcode == WARN_IMAGE_MACHINE_TYPE_MISMATCH_EXE)
            dr_inject_process_run(inject_data); /* shouldn't return */
        printf("ERROR (%d): unable to launch frontend to match target file bitwidth\n",
               errcode);
        argv[0] = orig_argv0;
        return false;
#else
        errcode = dr_inject_process_create(buf, argv, &inject_data);
        if (errcode == 0 || errcode == WARN_IMAGE_MACHINE_TYPE_MISMATCH_EXE) {
            dr_inject_process_run(inject_data);
            /* Wait for the child so user's shell prompt doesn't come back early */
            errcode = WaitForSingleObject(dr_inject_get_process_handle(inject_data),
                                          INFINITE);
            if (errcode != WAIT_OBJECT_0)
                printf("WARNING: failed to wait for cross-arch frontend\n");
            dr_inject_process_exit(inject_data, false);
            argv[0] = orig_argv0;
            return false;
        } else {
            printf("ERROR (%d): unable to launch frontend to match target file bitwidth\n",
                  errcode);
            argv[0] = orig_argv0;
            return false;
        }
#endif
    }
    return true;
}