//------------------------------------------------------------------------------ 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; }
//------------------------------------------------------------------------------ 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; }
//------------------------------------------------------------------------------ static int force_autorun(const char* value, int wow64) { HKEY cmd_proc_key; int i; cmd_proc_key = open_software_key("Microsoft\\Command Processor", wow64, 1); if (cmd_proc_key == NULL) { return 0; } i = set_value(cmd_proc_key, "AutoRun", value); close_key(cmd_proc_key); return 0; }
//------------------------------------------------------------------------------ static int show_autorun(const char* clink_path, int wow64) { HKEY cmd_proc_key; char* key_value; cmd_proc_key = open_software_key("Microsoft\\Command Processor", wow64, 0); if (cmd_proc_key == NULL) { return 0; } key_value = NULL; get_value(cmd_proc_key, "AutoRun", &key_value); printf("%6s : %s\n", wow64 ? "wow64" : "native", key_value ? key_value : "<unset>" ); close_key(cmd_proc_key); free(key_value); return 0; }
//------------------------------------------------------------------------------ static HKEY open_cmd_proc_key(int all_users, int wow64, int writable) { return open_software_key(all_users, "Microsoft\\Command Processor", wow64, writable); }