示例#1
0
文件: autorun.c 项目: HTshandou/clink
//------------------------------------------------------------------------------
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;
}
示例#2
0
文件: autorun.c 项目: HTshandou/clink
//------------------------------------------------------------------------------
static int uninstall_autorun(const char* clink_path, int wow64)
{
    HKEY cmd_proc_key;
    char* key_value;
    int ret;
    int left, right;

    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);

    ret = 1;
    if (key_value && find_clink_entry(key_value, &left, &right))
    {
        const char* read;
        char* write;
        int i, n;

        // Copy the key value into itself, skipping clink's entry.
        read = write = key_value;
        for (i = 0, n = (int)strlen(key_value); i <= n; ++i)
        {
            if (i < left || i >= right)
            {
                *write++ = *read;
            }

            ++read;
        }

        read = get_cmd_start(key_value);
        if (*read == '\0')
        {
            // Empty key. We might as well delete it.
            if (!delete_value(cmd_proc_key, "AutoRun"))
            {
                ret = 0;
            }
        }
        else if (!set_value(cmd_proc_key, "AutoRun", read))
        {
            ret = 0;
        }
    }

    // Delete legacy values.
    delete_value(cmd_proc_key, "AutoRunPreClinkInstall");

    // Tidy up.
    close_key(cmd_proc_key);
    free(key_value);
    return ret;
}
示例#3
0
//------------------------------------------------------------------------------
static int uninstall_autorun(const char* clink_path, int wow64)
{
    HKEY cmd_proc_key;
    char* key_value;
    int ret;
    int left, right;

    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);

    ret = 1;
    if (key_value && find_clink_entry(key_value, &left, &right))
    {
        const char* read;
        char* write;
        int i, n;

        // Copy the key value into itself, skipping clink's entry.
        read = write = key_value;
        for (i = 0, n = (int)strlen(key_value); i <= n; ++i)
        {
            if (i < left || i >= right)
            {
                *write++ = *read;
            }

            ++read;
        }

        read = get_cmd_start(key_value);
        if (*read == '\0')
        {
            // Empty key. We might as well delete it.
            if (!delete_value(cmd_proc_key, "AutoRun"))
            {
                ret = 0;
            }
        }
        else if (!set_value(cmd_proc_key, "AutoRun", read))
        {
            ret = 0;
        }
    }

    // Tidy up.
    close_key(cmd_proc_key);
    free(key_value);
    return ret;
}
示例#4
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;
}