- Code: Select all
// globals
LPVOID beginAddy = (LPVOID)0x00400000;
LPVOID endAddy = (LPVOID)0x40000000;
DWORD compareAddys[1];
DWORD compareIndex = -1;
// Search for a pointer.
// This function does a bit of logical processing
// for us. It accepts the lowest known address in
// a structure and creates a suitable search range.
bool FindPointer( LPVOID lpvFinalAddy, DWORD dwMaxOffset0, DWORD dwMaxOffset1, DWORD dwCurrentOffset ) {
// The structure holds all the information we will
// pass to the function.
MHS_API_SEARCH_PARMS pSearch;
// Firstly, we are doing a pointer search.
pSearch.dwType = LS_POINTER;
// Cover the search range.
pSearch.lpvStart = beginAddy;
pSearch.lpvEnd = endAddy;
// pSearch.bAligned is not used in Pointer Searches.
// Now to the pointer-specific data.
// We will search for a range of pointers.
pSearch.TypeParms.pParms.dwSubType = ST_RANGE;
// We don't need the Same as Original sub search.
pSearch.TypeParms.pParms.bEnableSame = false;
// We are not interested in only static pointers.
pSearch.TypeParms.pParms.bStatic = false;
// Save the offset from the value passed to us.
// This should always be done in Pointer Searches.
// This allows us to see how far away pointers are
// from this addres in the address list.
pSearch.TypeParms.pParms.lpvSaveOffset = lpvFinalAddy;
if (dwCurrentOffset == 0)
{
pSearch.TypeParms.pParms.atValue.UInt = (DWORD)lpvFinalAddy - dwMaxOffset0;
}
else if (dwCurrentOffset == 1)
{
if (dwMaxOffset1 > -1)
pSearch.TypeParms.pParms.atValue.UInt = (DWORD)lpvFinalAddy - dwMaxOffset1;
}
// Set the high value to the actual address specified.
pSearch.TypeParms.pParms.atTo.UInt = (DWORD)lpvFinalAddy;
// Now search.
if (RAMSearch( &pSearch ))
{
if (dwCurrentOffset == 0)
{
if (ComparePointer(lpvFinalAddy, dwMaxOffset0, 0))
{
}
}
else if (dwCurrentOffset == 1)
{
if (dwMaxOffset1 > -1)
{
if (ComparePointer(lpvFinalAddy, dwMaxOffset1, 1))
{
}
}
}
return true;
}
else
{
return false;
}
}
bool ComparePointer(LPVOID pointerAddress, DWORD distance, DWORD current)
{
if ( !LockScanForRead() ) { return false; }
compareIndex = 0;
DWORD scanTotal = GetScanTotal();
PrintF("Total Pointer Results: %d", scanTotal);
PrintF(" ");
for ( DWORD i = 0; i < scanTotal; i++ )
{
DWORD retValue;
LPVOID retAddress;
if ( GetScanValue(i, &retAddress, &retValue) )
{
DWORD retDistance = (DWORD)pointerAddress - retValue;
//PrintF("Distance: %d", retDistance);
if (retDistance == distance)
{
compareAddys[compareIndex] = retAddress;
compareIndex++;
PrintF("Compare Address: %d", compareAddys[compareIndex - 1]);
}
}
}
return UnlockScanForRead();
}
void On_HK_0( DWORD dw1, DWORD dw2 )
{
LPVOID initialAddy = (LPVOID)0x05ECD96C;
DWORD offset0 = 0x74C;
DWORD offset1 = -1;
FindPointer(initialAddy, offset0, offset1, 0);
}
As you can see, I set up the initial address to do the pointer search on followed by the first offset (just to test), then call the function to do the search. Everything works fine until the function ComparePointer is called. When we get to the scan result iteration, MHS seems to crash for me everytime after the first address is put into the array, only once it went through without a crash but I had to change some things and it hasn't worked since.
I was under the impression that even if an array is declared with a length of 1, you can still add more elements to it without problems. Is there another, maybe better, way of storing the addresses to use later in a subsequent pointer search; to search for any other offsets?
Thanks to whoever can lend a helping hand, I'm sure this is something that everyone can benefit from when it's working properly.
PS: Is it possible to store an array of arrays, or should I just create a structure of an array and put that structure into an array? This would be to store as many offsets as possible without declaring lots of global variables.