Skip to content

Commit

Permalink
32bit version support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollie Whitehouse authored and Ollie Whitehouse committed Oct 17, 2013
1 parent e84eb25 commit 9451b0d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 19 additions & 5 deletions windows/Memgrep/Memgrep.cpp
Expand Up @@ -66,8 +66,12 @@ void printhex( unsigned char *buf, int size ) {
printf( "\n" );
}


#ifdef WIN64
void PrintMemInfo(MEMORY_BASIC_INFORMATION64 memMeminfo)
#endif
#ifdef WIN32
void PrintMemInfo(MEMORY_BASIC_INFORMATION memMeminfo)
#endif
{

switch (memMeminfo.AllocationProtect)
Expand Down Expand Up @@ -116,7 +120,12 @@ void PrintMemInfo(MEMORY_BASIC_INFORMATION64 memMeminfo)
// Role : Reads the process memory into our address space then we search it...
// Notes :
//
#ifdef WIN64
void ReadAndGrep(SIZE_T szSize, ULONG_PTR lngAddress, HANDLE hProcess, char *strString, MEMORY_BASIC_INFORMATION64 memMeminfo)
#endif
#ifdef WIN32
void ReadAndGrep(SIZE_T szSize, ULONG_PTR lngAddress, HANDLE hProcess, char *strString, MEMORY_BASIC_INFORMATION memMeminfo)
#endif
{
SIZE_T szBytesRead=0;
unsigned char *strBuffer=(unsigned char *)VirtualAlloc(0,szSize+1024,MEM_COMMIT,PAGE_READWRITE);
Expand Down Expand Up @@ -230,19 +239,24 @@ void OpenAndGrep(bool bASCII, bool bUNICODE, char* strString, DWORD dwPID)

for(;;)
{
MEMORY_BASIC_INFORMATION64 memMeminfo;
#ifdef WIN64
MEMORY_BASIC_INFORMATION64 memMeminfo;
#endif
#ifdef WIN32
MEMORY_BASIC_INFORMATION memMeminfo;
#endif
VirtualQueryEx(hProcess, reinterpret_cast<LPVOID>(addrCurrent), reinterpret_cast<PMEMORY_BASIC_INFORMATION>(&memMeminfo), sizeof(memMeminfo) );

if(lastBase == memMeminfo.BaseAddress) {
if(lastBase == (ULONG_PTR) memMeminfo.BaseAddress) {
break;
}

lastBase = memMeminfo.BaseAddress;
lastBase = (ULONG_PTR) memMeminfo.BaseAddress;

if(memMeminfo.State == MEM_COMMIT) {
//fprintf(stdout,"[i] %p\n", memMeminfo.BaseAddress);
//fprintf(stdout,"[i] %ld\n", memMeminfo.RegionSize);
ReadAndGrep(memMeminfo.RegionSize,memMeminfo.BaseAddress,hProcess,strString,memMeminfo);
ReadAndGrep(memMeminfo.RegionSize,(ULONG_PTR) memMeminfo.BaseAddress,hProcess,strString,memMeminfo);
}

addrCurrent += memMeminfo.RegionSize;
Expand Down
5 changes: 4 additions & 1 deletion windows/Memgrep/Memgrep.vcxproj
Expand Up @@ -38,7 +38,9 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<UseOfAtl>false</UseOfAtl>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -112,6 +114,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>psapi.lib;advapi32.lib;kernel32.lib;wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down

0 comments on commit 9451b0d

Please sign in to comment.