Advertisement
test12333

Untitled

Nov 3rd, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. std::uintptr_t util::FindPattern( const char* smodule, const char* pattern, bool only_text_or_code, bool format ) {
  2.     const auto mod_p = (uintptr_t)util::get_module_base_ansi( smodule );
  3.     PIMAGE_DOS_HEADER pe_headers = (PIMAGE_DOS_HEADER)mod_p;
  4.     PIMAGE_NT_HEADERS new_pe_headers = PIMAGE_NT_HEADERS( (uint8_t*)( mod_p + pe_headers->e_lfanew ) );
  5.    
  6.     DWORD dwSizeOfImage;
  7.     DWORD end;
  8.     uintptr_t begin;
  9.  
  10.     if ( only_text_or_code ) {
  11.         PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION( new_pe_headers );
  12.  
  13.         for ( WORD i = 0; i < new_pe_headers->FileHeader.NumberOfSections; i++ ) {
  14.  
  15.             if ( !fast_strcmp( (char*)Section->Name, ".code" ) || !fast_strcmp( (char*)Section->Name, ".text" ) ) {
  16.  
  17.                 begin = Section->VirtualAddress;
  18.                 dwSizeOfImage = Section->SizeOfRawData;
  19.                 end = begin + dwSizeOfImage;
  20.  
  21.                 //printf( "%-8s\t%x\t%x\t%x\n", Section->Name, Section->VirtualAddress,
  22.                     //   Section->PointerToRawData, Section->SizeOfRawData );
  23.  
  24.             }
  25.             Section++;
  26.         }
  27.     }
  28.  
  29.     else {
  30.         begin = mod_p;
  31.         dwSizeOfImage = new_pe_headers->OptionalHeader.SizeOfImage;
  32.         end = begin + dwSizeOfImage;
  33.     }
  34.  
  35.  
  36.     if ( const auto result = reinterpret_cast<std::uintptr_t>( find_pattern_internal( begin, end, format ? ParseCombo( pattern ).c_str( ) : pattern ) ); result ) {
  37.         return result;
  38.     }
  39.     return NULL;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement