1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
|
#include <windows.h> #include <strsafe.h> #include <Dbghelp.h> #include <shlwapi.h> #pragma comment(lib,"Dbghelp.lib") #pragma comment(lib,"shlwapi.lib") #define CV_SIGNATURE_NB10 '01BN' #define CV_SIGNATURE_RSDS 'SDSR'
#define RESET "\033[0m" #define BLACK "\033[30m" #define RED "\033[31m" #define GREEN "\033[32m" #define YELLOW "\033[33m" #define BLUE "\033[34m" #define MAGENTA "\033[35m" #define CYAN "\033[36m" #define WHITE "\033[37m" #define BOLDGREEN "\033[1m\033[32m"
#include <vector> #include <set> #include <iostream> #include <fstream> using namespace std;
typedef struct CV_HEADER { DWORD CvSignature; LONG Offset; } * PCV_HEADER;
typedef struct CV_INFO_PDB20 { CV_HEADER Header; DWORD Signature; DWORD Age; BYTE PdbFileName[1]; } * PCV_INFO_PDB20;
typedef struct CV_INFO_PDB70 { DWORD CvSignature; GUID Signature; DWORD Age; BYTE PdbFileName[1]; } * PCV_INFO_PDB70;
LPBYTE GetRVAOffset(LPBYTE pBuffer, DWORD dwVirtualOffset) { PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pBuffer; PIMAGE_NT_HEADERS32 pNtHeader32 = (PIMAGE_NT_HEADERS32)(pBuffer + pDosHeader->e_lfanew); PIMAGE_NT_HEADERS64 pNtHeader64 = (PIMAGE_NT_HEADERS64)(pBuffer + pDosHeader->e_lfanew); BOOL bIsX64 = pNtHeader32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC;
int nSectionNum = bIsX64 ? pNtHeader64->FileHeader.NumberOfSections : pNtHeader32->FileHeader.NumberOfSections; PIMAGE_SECTION_HEADER pSection = (PIMAGE_SECTION_HEADER)(pBuffer + pDosHeader->e_lfanew + (bIsX64 ? sizeof(IMAGE_NT_HEADERS64) : sizeof(IMAGE_NT_HEADERS32)));
for( int i = 0; i < nSectionNum; i++) { DWORD dwStart = pSection->VirtualAddress; if( dwStart <= dwVirtualOffset && dwVirtualOffset < dwStart + pSection->SizeOfRawData){ return pBuffer + pSection->PointerToRawData + (dwVirtualOffset - dwStart); } pSection++; }
return 0; }
DWORD GetImageSize(LPBYTE pBuffer, BOOL& bIsX64) { PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pBuffer; PIMAGE_NT_HEADERS32 pNtHeader32 = (PIMAGE_NT_HEADERS32)(pBuffer + pDosHeader->e_lfanew); PIMAGE_NT_HEADERS64 pNtHeader64 = (PIMAGE_NT_HEADERS64)(pBuffer + pDosHeader->e_lfanew); bIsX64 = pNtHeader32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC;
DWORD SizeOfImage = bIsX64 ? pNtHeader64->OptionalHeader.SizeOfImage: pNtHeader32->OptionalHeader.SizeOfImage;
return SizeOfImage; }
WCHAR* CharToWchar(CHAR* sSour) { size_t len = strlen(sSour) + 1; size_t converted = 0; WCHAR *wzDest = NULL; wzDest = (WCHAR*)new WCHAR[len]; mbstowcs_s(&converted, wzDest, len, sSour, _TRUNCATE); return wzDest; }
char* WCharToChar(WCHAR* wzSour) { ULONG ulLength = 0; char* szDest = NULL;
if (wzSour != NULL) { ulLength = WideCharToMultiByte(CP_ACP,NULL, wzSour,-1,NULL,0,NULL,FALSE); szDest = new char[ulLength + 1]; if (szDest == NULL) { return NULL; } memset(szDest, 0, ulLength + 1); WideCharToMultiByte(CP_OEMCP, NULL, wzSour, -1, szDest, ulLength, NULL, FALSE); } return szDest; }
BOOL GetPdbFileInfo(LPCWSTR lpszFilePath , LPWSTR szPdbFileName , DWORD dwPdbFileNameCch , LPWSTR szPdbGuid , DWORD dwPdbGuidCch , LPWSTR szChecksum , DWORD dwChecksumCch ) {
DWORD dwTotalRead = 0, dwRead = 0; DWORD dwSize = 0; BOOL bFound = FALSE; HANDLE hFile = INVALID_HANDLE_VALUE; LPBYTE pBuffer = NULL; do { HANDLE hFile = ::CreateFileW( lpszFilePath , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL ); if( hFile == INVALID_HANDLE_VALUE ) { break; }
dwSize = GetFileSize( hFile, NULL); if( dwSize < 4096 ) { break; }
pBuffer = (LPBYTE)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize); if(!pBuffer) { break; }
while( dwTotalRead < dwSize && ReadFile( hFile, pBuffer + dwTotalRead, dwSize - dwTotalRead, &dwRead, NULL) ) { dwTotalRead += dwRead; }
}while(0);
if(hFile != INVALID_HANDLE_VALUE) { ::CloseHandle(hFile); }
if(pBuffer == NULL) { return FALSE; }
if(dwTotalRead != dwSize) { if(pBuffer) { HeapFree( GetProcessHeap(), 0, pBuffer); } return FALSE; }
LPWSTR lpszpdbInfo = NULL;
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pBuffer; if( pDosHeader->e_magic == IMAGE_DOS_SIGNATURE ) { PIMAGE_DATA_DIRECTORY pDataDic; PIMAGE_NT_HEADERS32 pNtHeader32 = (PIMAGE_NT_HEADERS32)(pBuffer + pDosHeader->e_lfanew); PIMAGE_NT_HEADERS64 pNtHeader64 = (PIMAGE_NT_HEADERS64)(pBuffer + pDosHeader->e_lfanew); if( pNtHeader32->Signature == IMAGE_NT_SIGNATURE ) { BOOL bIsX64 = pNtHeader32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC; if( !bIsX64 ) pDataDic = &pNtHeader32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG]; else pDataDic = &pNtHeader64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
if( pDataDic && pDataDic->Size > 0 ) { int nNumberOfEntries = pDataDic->Size / sizeof(IMAGE_DEBUG_DIRECTORY); PIMAGE_DEBUG_DIRECTORY pDebugDic = (PIMAGE_DEBUG_DIRECTORY)GetRVAOffset( pBuffer, pDataDic->VirtualAddress);
for( int i = 0; i < nNumberOfEntries && !bFound ; i++) { if( pDebugDic->Type == IMAGE_DEBUG_TYPE_CODEVIEW ) { LPBYTE pDebugData = pBuffer + pDebugDic->PointerToRawData; DWORD dwCVSignature = *(LPDWORD)pDebugData; if( dwCVSignature == CV_SIGNATURE_RSDS ) { PCV_INFO_PDB70 pCvInfo = (PCV_INFO_PDB70)pDebugData; StringCbPrintfW( szPdbGuid, dwPdbFileNameCch , L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X%d" , pCvInfo->Signature.Data1 , pCvInfo->Signature.Data2 , pCvInfo->Signature.Data3 , pCvInfo->Signature.Data4[0] , pCvInfo->Signature.Data4[1] , pCvInfo->Signature.Data4[2] , pCvInfo->Signature.Data4[3] , pCvInfo->Signature.Data4[4] , pCvInfo->Signature.Data4[5] , pCvInfo->Signature.Data4[6] , pCvInfo->Signature.Data4[7] , pCvInfo->Age );
lpszpdbInfo = CharToWchar((LPSTR)pCvInfo->PdbFileName); StringCbCopy( szPdbFileName, dwPdbFileNameCch, lpszpdbInfo); delete[]lpszpdbInfo;
if( bIsX64 ) { StringCbPrintfW( szChecksum, dwChecksumCch , L"%x%x" , pNtHeader64->FileHeader.TimeDateStamp , pNtHeader64->OptionalHeader.SizeOfImage ); } else { StringCbPrintfW( szChecksum, dwChecksumCch , L"%x%x" , pNtHeader32->FileHeader.TimeDateStamp , pNtHeader32->OptionalHeader.SizeOfImage ); }
bFound = TRUE; } }
pDebugDic++; } } } }
HeapFree( GetProcessHeap(), 0, pBuffer);
return bFound; }
DWORD RunTheSymchk(LPWSTR szCommandLine) { DWORD dwMbrId = 0;
STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi));
BOOL bResult = ::CreateProcess(NULL,szCommandLine , NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (!bResult) return 0;
if (WaitForSingleObject(pi.hProcess,180*1000) == WAIT_TIMEOUT) return 0;
int dwCode = 0; if (!GetExitCodeProcess(pi.hProcess,(DWORD*)&dwCode)) { return 0; }
CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 1; }
#define WINDBG_INSTALLPATH L"D:\\Windows Kits\\10\\Debuggers\\x64" #define NT_SYMBOLS_DIR L"d:\\symbols\\" #define NT_SYMBOLS_FORMATS L"SRV*%ws*http://msdl.microsoft.com/download/symbols" #define TEST_PATH L"D:\\Documents\\D_IDA\\SHClient\\SHClient.exe" #define SYMCHCKCMD_LINE_FORMATS L"%ws\\symchk.exe /r %ws /s %ws" #define LDR_IS_DATAFILE(handle) (((ULONG_PTR)(handle)) & (ULONG_PTR)1) #define LDR_IS_IMAGEMAPPING(handle) (((ULONG_PTR)(handle)) & (ULONG_PTR)2) #define LDR_IS_RESOURCE(handle) (LDR_IS_IMAGEMAPPING(handle) || LDR_IS_DATAFILE(handle)) #if 0
#define SYMBOL_NAME L"*Payload*" #define ENUM_PATH L"D:\\Documents\\TestScanPath" #define ENEABLE_DEEP_CALL 1 #else #define SYMBOL_NAME L"*Payload*" #define ENUM_PATH L"C:\\Windows\\System32" #define ENEABLE_DEEP_CALL 1 #endif
void* GetNtdllBase() { #if defined(_WIN64) ULONG64 peb = __readgsqword(0x60); #else ULONG64 peb = __readfsdword(0x30); #endif
ULONG64 ldr = *(ULONG64*)(peb + 0x18); PLIST_ENTRY modlist = *(PLIST_ENTRY*)(ldr + 0x10); return *(void**)((ULONG64)modlist->Flink + 0x30); }
vector<std::pair<wstring, wstring>> g_FindReslt; BOOL CALLBACK PsymEnumeratesymbolsCallback( _In_ PSYMBOL_INFOW pSymInfo, _In_ ULONG SymbolSize, _In_opt_ PVOID UserContext ) { wprintf(GREEN L"%s->%s, Size:%d\n" WHITE, (WCHAR*)UserContext, pSymInfo->Name, SymbolSize);
g_FindReslt.emplace_back(std::make_pair<wstring, wstring>((WCHAR*)UserContext, pSymInfo->Name));
return TRUE; }
int IsExeOrDll(const WCHAR* path) { const WCHAR* patterns[] = { L"*.exe", L"*.dll", NULL }; #if 0 if (PathMatchSpecW(path, patterns[0]) == TRUE) return 1; #endif if (PathMatchSpecW(path, patterns[1]) == TRUE) return 2; return 0; }
int g_idx = 0;
void FindAllDlls(const WCHAR* Path, int iDeep) { if (iDeep > 6) { return; }
WCHAR TargetPath[MAX_PATH] = {}; WCHAR szTempPath[MAX_PATH] = { 0 }; LPCWSTR lpszFilePath = TEST_PATH; DWORD dwLastError = 0; DWORD ModuleSize = 0; WCHAR szPdbFileName[MAX_PATH] = { 0 }; WCHAR szPdbGuid[MAX_PATH] = { 0 }; WCHAR szChecksum[MAX_PATH] = { 0 }; WCHAR szCommandLine[MAX_PATH] = { 0 }; WCHAR szNtSymbolUrl[MAX_PATH] = { 0 }; WCHAR szPdbSymbolPath[MAX_PATH] = { 0 }; LPSTR lpszPdbPath = NULL; WCHAR szSymbolName[MAX_SYM_NAME]; DWORD dwSizeOfSymbol = sizeof(SYMBOL_INFOW) + MAX_SYM_NAME * sizeof(WCHAR); PBYTE pBuffer = new BYTE[dwSizeOfSymbol]; PSYMBOL_INFOW pSymbol = (PSYMBOL_INFOW)pBuffer; HMODULE hModuleBase = NULL; PBYTE pModuleBase = NULL; PBYTE pSymAdr = NULL; PBYTE lpDestCall = NULL; LPWSTR lpszCFile = NULL; MEMORY_BASIC_INFORMATION MbInfo = { 0 };
BOOL bIsX64 = FALSE; StringCbCopy(TargetPath, MAX_PATH, Path); StringCbCat(TargetPath, MAX_PATH, L"\\*.*");
WIN32_FIND_DATA fd = { 0 }; HANDLE hFind = FindFirstFile(TargetPath, &fd); do {
if (StrCmpCW(L"AppVStreamingUX.exe", fd.cFileName) == 0) { cout << endl; } if (StrCmpCW(L"SIHClient.exe", fd.cFileName) == 0) { cout << endl; }
if (hFind != INVALID_HANDLE_VALUE) { if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { int iFileExFlag = 0; const WCHAR* filename = fd.cFileName;
if (!(iFileExFlag = IsExeOrDll(filename))) { continue; }
szTempPath[0] = 0; StringCbCopy(szTempPath, MAX_PATH, Path); PathAppend(szTempPath, fd.cFileName); lpszFilePath = szTempPath; GetPdbFileInfo(lpszFilePath, szPdbFileName, MAX_PATH, szPdbGuid, MAX_PATH, szChecksum, MAX_PATH);
StringCbPrintf(szNtSymbolUrl, MAX_PATH * sizeof(WCHAR), NT_SYMBOLS_FORMATS, NT_SYMBOLS_DIR); StringCbPrintf(szCommandLine, MAX_PATH * sizeof(WCHAR), SYMCHCKCMD_LINE_FORMATS, WINDBG_INSTALLPATH, lpszFilePath, szNtSymbolUrl);
StringCbCopy(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), NT_SYMBOLS_DIR); StringCbCat(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), szPdbFileName); StringCbCat(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), L"\\"); StringCbCat(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), szPdbGuid); StringCbCat(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), L"\\"); StringCbCat(szPdbSymbolPath, MAX_PATH * sizeof(WCHAR), szPdbFileName); { std::cout << (iFileExFlag == 1 ? MAGENTA : CYAN); wprintf(L"%d Load:%ws\r\n", g_idx++, lpszFilePath); std::cout << WHITE; } hModuleBase = LoadLibraryExW(lpszFilePath, NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE); pModuleBase = (PBYTE)hModuleBase;
BOOL bNeedUnload = TRUE; if (GetModuleHandle(filename)) { bNeedUnload = FALSE; }
if (LDR_IS_RESOURCE(hModuleBase)) { ULONG_PTR ulTemp = (ULONG_PTR)hModuleBase; ulTemp = ulTemp - 2; pModuleBase = (PBYTE)ulTemp; }
if (pModuleBase == NULL) { continue; }
ModuleSize = GetImageSize((LPBYTE)pModuleBase, bIsX64); #if 0 if (!bIsX64) { FreeLibrary(hModuleBase); continue; } #endif if (!PathFileExists(szPdbSymbolPath)) { }
DWORD64 baseAddr = 0; lpszPdbPath = WCharToChar(szPdbSymbolPath);
if (!(baseAddr = SymLoadModuleExW(GetCurrentProcess(), NULL, (PCWSTR)szPdbSymbolPath, NULL, (DWORD64)pModuleBase, ModuleSize, NULL, 0))) { dwLastError = GetLastError(); delete[] lpszPdbPath; FreeLibrary(hModuleBase); SymUnloadModule(GetCurrentProcess(), (DWORD64)pModuleBase); continue; }
delete[] lpszPdbPath;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);; pSymbol->MaxNameLen = MAX_SYM_NAME; if (!SymFromNameW(GetCurrentProcess(), SYMBOL_NAME, pSymbol)) { dwLastError = GetLastError(); FreeLibrary(hModuleBase); continue; }
if (!SymEnumSymbolsW(GetCurrentProcess(), baseAddr, SYMBOL_NAME, PsymEnumeratesymbolsCallback, (PVOID)lpszFilePath)) { dwLastError = GetLastError(); FreeLibrary(hModuleBase); continue; }
#if 0 pSymAdr = (PBYTE)pSymbol->Address;
if (VirtualQuery(pSymAdr, &MbInfo, sizeof(MbInfo)) == sizeof(MbInfo)) { if (MbInfo.State != MEM_COMMIT) { dwLastError = GetLastError(); FreeLibrary(hModuleBase); continue; } }
for (int i = 0; i < 0x150; i++) { if (*(pSymAdr + i) == 0x4c && *(pSymAdr + i + 1) == 0x8d && *(pSymAdr + i + 2) == 0x5) {
int jmpadr = *(int*)(pSymAdr + i + 3); jmpadr = jmpadr + 7; lpDestCall = jmpadr + pSymAdr + i; lpszCFile = CharToWchar((char*)lpDestCall); wprintf(L"Find:%ws %ws\r\n", lpszFilePath, lpszCFile); break; } } #endif
FreeLibrary(hModuleBase);
} else if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (StrCmpCW(fd.cFileName, L".") != 0 && StrCmpCW(fd.cFileName, L"..") != 0) { TCHAR subDirectory[MAX_PATH]; StringCbCopy(subDirectory, MAX_PATH, Path); StringCbCat(subDirectory, MAX_PATH, L"\\"); StringCbCat(subDirectory, MAX_PATH, fd.cFileName);
if (ENEABLE_DEEP_CALL) { FindAllDlls(subDirectory, iDeep + 1); } } } } } while (FindNextFile(hFind, &fd));
FindClose(hFind); }
BOOL EnableXXXPrivilege(LPCTSTR pszPrivilegeName) { HANDLE hToken; LUID seXXXNameValue; TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { wprintf(L"OpenProcessToken() failed, Error = %d %s is not available.\n", GetLastError(), pszPrivilegeName); return FALSE; }
if (!LookupPrivilegeValue(NULL, pszPrivilegeName, &seXXXNameValue)) { wprintf(L"LookupPrivilegeValue() failed, Error = %d %s is not available.\n", GetLastError(), pszPrivilegeName); CloseHandle(hToken); return FALSE; }
tkp.PrivilegeCount = 1; tkp.Privileges[0].Luid = seXXXNameValue; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof tkp, NULL, NULL)) { wprintf(L"AdjustTokenPrivileges() failed, Error = %d %s is not available.\n", GetLastError(), pszPrivilegeName); CloseHandle(hToken); return FALSE; }
CloseHandle(hToken);
return TRUE; }
string wstring2string(wstring wstr) { string result; int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); char* buffer = new char[len + 1]; WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL); buffer[len] = '\0'; result.append(buffer); delete[] buffer; return result; }
void OutputToFile(std::vector<std::pair<wstring, wstring>>& vec) { ofstream outfile("output.txt");
if (!outfile.is_open()) { std::cerr << "无法打开文件" << std::endl; return; }
for (auto res : g_FindReslt) { outfile << wstring2string(res.first) << "\t" << wstring2string(res.second) << endl; }
outfile.close(); }
int main(int argc, char* argv[]) { PVOID OldValue; if (Wow64DisableWow64FsRedirection(&OldValue)) std::cout << "File system redirection disabled." << std::endl; wcout << WHITE << endl;
EnableXXXPrivilege(SE_DEBUG_NAME);
if (!SymInitializeW(GetCurrentProcess(), NULL, FALSE)) { return 0; }
DWORD dwSymOpt = SymGetOptions();
int iDeep = 0; FindAllDlls(ENUM_PATH, iDeep);
cout << endl<< endl;
wcout << WHITE << endl; if (Wow64RevertWow64FsRedirection(OldValue)) { std::cout << "File system redirection re-enabled." << std::endl; } else { std::cerr << "Failed to re-enable file system redirection." << std::endl; }
OutputToFile(g_FindReslt);
HWND consoleWindow = GetConsoleWindow(); ShowWindow(consoleWindow, SW_SHOW); SetForegroundWindow(consoleWindow);
return 0; }
|