Item *SelectProcesses(const Item *processes, const char *process_name, ProcessSelect a, bool attrselect) { Item *result = NULL; if (processes == NULL) { return result; } char *names[CF_PROCCOLS]; int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; GetProcessColumnNames(processes->name, &names[0], start, end); pcre *rx = CompileRegex(process_name); if (rx) { /* TODO: use actual time of ps-run, as time(NULL) may be later. */ time_t pstime = time(NULL); for (Item *ip = processes->next; ip != NULL; ip = ip->next) { int s, e; if (StringMatchWithPrecompiledRegex(rx, ip->name, &s, &e)) { if (NULL_OR_EMPTY(ip->name)) { continue; } if (attrselect && !SelectProcess(ip->name, pstime, names, start, end, a)) { continue; } pid_t pid = ExtractPid(ip->name, names, end); if (pid == -1) { Log(LOG_LEVEL_VERBOSE, "Unable to extract pid while looking for %s", process_name); continue; } PrependItem(&result, ip->name, ""); result->counter = (int)pid; } } pcre_free(rx); } for (int i = 0; i < CF_PROCCOLS; i++) { free(names[i]); } return result; }
int main(int argc, char* argv[]) { // nice title :) SetConsoleTitle("SzimatSzatyor, WoW injector sniffer"); // some info printf("Welcome to SzimatSzatyor2, a WoW injector sniffer.\n"); printf("SzimatSzatyor2 is distributed under the GNU GPLv3 license.\n"); printf("Source code is available at: "); printf("https://github.com/ChipLeo/SzimatSzatyor\n\n"); if (argc > 2) { printf("ERROR: Invalid parameters. "); printf("\"szatyor.exe [wow_exe_name]\" should be used.\n\n"); system("pause"); return 0; } // custom process' name else if (argc == 2) lookingProcessName[0] = std::string(argv[1]); // this process will be injected DWORD processID = SelectProcess(); if (!processID) return 0; // stores where the injector is, so location/path of the current process char injectorPath[MAX_PATH] = { 0 }; // gets where the injector is DWORD injectorPathSize = GetModuleFileName(NULL, injectorPath, MAX_PATH); if (!injectorPathSize) { printf("ERROR: Can't get the injector's path, "); printf("ErrorCode: %u\n\n", GetLastError()); system("pause"); return 0; } // full path of the DLL char* dllPath = new char[MAX_PATH]; // copies injector's full path to dllPath strncpy_s(dllPath, MAX_PATH, injectorPath, injectorPathSize); // some magic to replace path/szatyor.exe to path/szimat.dll // removes injector's name PathRemoveFileSpec(dllPath); // appends DLL's name PathAppend(dllPath, injectDLLName); printf("DLL: %s\n", dllPath); if (InjectDLL(processID, dllPath)) printf("\nInjection of '%s' is successful.\n\n", injectDLLName); else printf("\nInjection of '%s' is NOT successful.\n\n", injectDLLName); delete[] dllPath; //system("pause"); return 0; }
void TUI_CustomControl::Move (TShiftState _Shift){ switch(action){ case etaSelect: SelectProcess(_Shift); break; case etaAdd: AddProcess(_Shift); break; case etaMove: MovingProcess(_Shift); break; case etaRotate: RotateProcess(_Shift); break; case etaScale: ScaleProcess(_Shift); break; } }
Item *SelectProcesses(EvalContext *ctx, const Item *processes, const char *process_name, ProcessSelect a, bool attrselect) { Item *result = NULL; if (processes == NULL) { return result; } char *names[CF_PROCCOLS]; int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; GetProcessColumnNames(processes->name, &names[0], start, end); for (Item *ip = processes->next; ip != NULL; ip = ip->next) { int s, e; if (BlockTextMatch(ctx, process_name, ip->name, &s, &e)) { if (NULL_OR_EMPTY(ip->name)) { continue; } if (attrselect && !SelectProcess(ctx, ip->name, names, start, end, a)) { continue; } pid_t pid = ExtractPid(ip->name, names, end); if (pid == -1) { Log(LOG_LEVEL_VERBOSE, "Unable to extract pid while looking for %s", process_name); continue; } PrependItem(&result, ip->name, ""); result->counter = (int)pid; } } for (int i = 0; i < CF_PROCCOLS; i++) { free(names[i]); } return result; }
Item *SelectProcesses(const char *process_name, const ProcessSelect *a, bool attrselect) { assert(a != NULL); const Item *processes = PROCESSTABLE; Item *result = NULL; if (processes == NULL) { return result; } char *names[CF_PROCCOLS]; int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; GetProcessColumnNames(processes->name, names, start, end); /* TODO: use actual time of ps-run, as time(NULL) may be later. */ time_t pstime = time(NULL); for (Item *ip = processes->next; ip != NULL; ip = ip->next) { if (NULL_OR_EMPTY(ip->name)) { continue; } if (!SelectProcess(ip->name, pstime, names, start, end, process_name, a, attrselect)) { continue; } pid_t pid = ExtractPid(ip->name, names, end); if (pid == -1) { Log(LOG_LEVEL_VERBOSE, "Unable to extract pid while looking for %s", process_name); continue; } PrependItem(&result, ip->name, ""); result->counter = (int)pid; } for (int i = 0; i < CF_PROCCOLS; i++) { free(names[i]); } return result; }
static int FindPidMatches(Item *procdata, Item **killlist, Attributes a, Promise *pp) { Item *ip; int pid = -1, matches = 0, i, s, e, promised_zero; pid_t cfengine_pid = getpid(); char *names[CF_PROCCOLS]; /* ps headers */ int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; if (procdata == NULL) { return 0; } GetProcessColumnNames(procdata->name, (char **) names, start, end); for (ip = procdata->next; ip != NULL; ip = ip->next) { CF_OCCUR++; if (BlockTextMatch(pp->promiser, ip->name, &s, &e)) { if (NULL_OR_EMPTY(ip->name)) { continue; } if (!SelectProcess(ip->name, names, start, end, a, pp)) { continue; } pid = ExtractPid(ip->name, names, start, end); if (pid == -1) { CfOut(cf_verbose, "", "Unable to extract pid while looking for %s\n", pp->promiser); continue; } CfOut(cf_verbose, "", " -> Found matching pid %d\n (%s)", pid, ip->name); matches++; if (pid == 1) { if ((RlistLen(a.signals) == 1) && IsStringIn(a.signals, "hup")) { CfOut(cf_verbose, "", "(Okay to send only HUP to init)\n"); } else { continue; } } if (pid < 4 && a.signals) { CfOut(cf_verbose, "", "Will not signal or restart processes 0,1,2,3 (occurred while looking for %s)\n", pp->promiser); continue; } promised_zero = a.process_count.min_range == 0 && a.process_count.max_range == 0; if (a.transaction.action == cfa_warn && promised_zero) { CfOut(cf_error, "", "Process alert: %s\n", procdata->name); /* legend */ CfOut(cf_error, "", "Process alert: %s\n", ip->name); continue; } if (pid == cfengine_pid && a.signals) { CfOut(cf_verbose, "", " !! cf-agent will not signal itself!\n"); continue; } PrependItem(killlist, ip->name, ""); (*killlist)->counter = pid; } } // Free up allocated memory for (i = 0; i < CF_PROCCOLS; i++) { if (names[i] != NULL) { free(names[i]); } } return matches; }