void Initialize() { DWORD mainThreadId = GetMainThreadId(); if (mainThreadId == 0) { MessageBox(NULL, L"ERROR: Main thread not found!", modName, MB_OK); return; } HANDLE mainThreadHandle = OpenThread(THREAD_ALL_ACCESS, false, mainThreadId); // TODO consider using THREAD_SUSPEND_RESUME if (mainThreadHandle == NULL) { MessageBox(NULL, L"ERROR: Cannot open the main thread!", modName, MB_OK); return; } void* patternCheckAutoSwingLocation = ScanPattern(0, 0xffffffff, patternCheckAutoSwing, sizeof(patternCheckAutoSwing)); // TODO make this faster if (patternCheckAutoSwingLocation == NULL) { MessageBox(NULL, L"ERROR: patternCheckAutoSwingLocation not found. Are you playing a different version?", modName, MB_OK); return; } SuspendThread(mainThreadHandle); NopMemory((void*)((unsigned int)patternCheckAutoSwingLocation + 7), 6, nullptr); ResumeThread(mainThreadHandle); CloseHandle(mainThreadHandle); MessageBox(NULL, L"Ready!", modName, MB_OK); }
void ReadOpeningSequences (short *pindex, const char* patternfile) { FILE *fd; char s[256]; short max_pattern = 0; short max_opening_sequence = 0; fd = fopen (patternfile, "r"); if (fd == NULL) { sprintf(s, "no pattern file '%s'", patternfile); dsp->ShowMessage(s); return; } *pindex = 0; while (fgets (s, 256, fd) != NULL) { if (*s == '#') { /* comment, skip line */ } else if (is_alpha(*s)) { if (max_opening_sequence++ > 0) { pattern_data[(*pindex)++] = END_OF_PATTERNS; } pattern_data[(*pindex)++] = ValueOfOpeningName(s); } else { if (ScanPattern(s, pindex)) { dsp->ShowMessage("error in pattern sequence..."); exit(1); } else { max_pattern++; } } } pattern_data[(*pindex)++] = END_OF_PATTERNS; pattern_data[(*pindex)++] = END_OF_SEQUENCES; sprintf(s, "Pattern: %d bytes for %d sequences with %d patterns.\n", *pindex, max_opening_sequence, max_pattern); dsp->ShowMessage(s); fclose(fd); }
void test(void) { std::list<PROCESSENTRY32> lProcess; std::list<MODULEENTRY32> lModules; DWORD dwPid = 0; std::list<MEMORY_BASIC_INFORMATION> lMemBI; std::list<THREADENTRY32> lThreads; std::list<LPCVOID> lAddress; DWORD dwBaseAddress = 0; IMAGE_DOS_HEADER DosHeader; IMAGE_NT_HEADERS NTHeader; lProcess = GetProcessList(); PrintProcessList(lProcess); dwPid = GetPidProcess("notepad++.exe"); PrintPidProcess("notepad++.exe", dwPid); lModules = GetModuleList(dwPid); PrintModulesList(lModules); lMemBI = GetMemoryInformation(dwPid); PrintMemoryInfo(lMemBI); lThreads = GetThreadsList(dwPid); PrintThreadsInfo(lThreads); SuspendAllThread(dwPid); Sleep(1000); ResumeAllThread(dwPid); lAddress = ScanPattern("\x42\x42\x42", 3, dwPid); PrintPatternMatch(lAddress); dwBaseAddress = GetRemoteBaseAddress(dwPid); printf("BaseAddress = %08X\n", dwBaseAddress); DosHeader = GetDosHeader(dwPid); PrintDosHeader(&DosHeader); NTHeader = GetNTHeader(dwPid); PrintNTHeader(&NTHeader); }