Example #1
0
//------------------------------------------------------------------------------
static int install_autorun(const char* clink_path, int wow64)
{
    HKEY cmd_proc_key;
    const char* value;
    char* new_value;
    char* key_value;
    int i;

    // Remove any previous autorun entries so we never have more than one. We
    // could just check for an exisiting entry, but by always uninstalling and
    // reinstalling, we ensure clink's last in the chain, which allows it to
    // play nicely with other projects that hook cmd.exe and install autoruns.
    uninstall_autorun(clink_path, wow64);

    cmd_proc_key = open_software_key("Microsoft\\Command Processor", wow64, 1);
    if (cmd_proc_key == NULL)
    {
        return 0;
    }

    key_value = NULL;
    get_value(cmd_proc_key, "AutoRun", &key_value);

    i = key_value ? (int)strlen(key_value) : 0;
    i += 2048;
    new_value = malloc(i);

    // Build the new autorun entry by appending clink's entry to the current one.
    new_value[0] = '\0';
    if (key_value != NULL && *key_value != '\0')
    {
        str_cat(new_value, key_value, i);
        str_cat(new_value, "&&", i);
    }
    str_cat(new_value, "\"", i);
    str_cat(new_value, clink_path, i);
    str_cat(new_value, "\\clink\" inject", i);

    if (g_clink_args != NULL)
    {
        str_cat(new_value, " ", i);
        str_cat(new_value, g_clink_args, i);
    }

    // Set it
    value = get_cmd_start(new_value);
    i = 1;
    if (!set_value(cmd_proc_key, "AutoRun", value))
    {
        i = 0;
    }

    // Tidy up.
    close_key(cmd_proc_key);
    free(new_value);
    free(key_value);
    return i;
}
Example #2
0
//------------------------------------------------------------------------------
static int install_autorun(const char* clink_path, int wow64)
{
    HKEY cmd_proc_key;
    const char* value;
    char* key_value;
    int i;

    // Remove any previous autorun entries so we never have more than one. We
    // could just check for an exisiting entry, but by always uninstalling and
    // reinstalling, we ensure clink's last in the chain, which allows it to
    // play nicely with other projects that hook cmd.exe and install autoruns.
    uninstall_autorun(clink_path, wow64);

    cmd_proc_key = open_cmd_proc_key(g_all_users, wow64, 1);
    if (cmd_proc_key == nullptr)
    {
        printf("ERROR: Failed to open registry key (%d)\n", GetLastError());
        return 0;
    }

    key_value = nullptr;
    get_value(cmd_proc_key, "AutoRun", &key_value);

    i = key_value ? (int)strlen(key_value) : 0;
    i += 2048;
    str_base new_value((char*)malloc(i), i);
    new_value.clear();

    // Build the new autorun entry by appending clink's entry to the current one.
    if (key_value != nullptr && *key_value != '\0')
        new_value << key_value << "&";
    new_value << "\"" << clink_path << "\\clink.bat\" inject --autorun";

    if (!g_clink_args.empty())
        new_value << " " << g_clink_args;

    // Set it
    value = get_cmd_start(new_value.c_str());
    i = 1;
    if (!set_value(cmd_proc_key, "AutoRun", value))
        i = 0;

    // Tidy up.
    close_key(cmd_proc_key);
    free(new_value.data());
    free(key_value);
    return i;
}