Basic memory-scanning in DLL
Header with functions for searching thru the current applications memory for a certain value.
The add_log function is just a function which prints to a log-file using a stream.
/*
Memory-scanner/searcher
Syntax
dwScanMemory(
DWORD dwScanStart,
DWORD dwScanEnd,
int fValueToScanFor,
int iValueType
);
Parameters
dwScanStart
offset to start scanning from, eg. 0x00400000
dwScanEnd
offset to end scanning on, eg. 0x00500000
fValueToScanFor
the value to scan for
iValueType
Data-type of the value
0: char (1 byte)
1: short (2 bytes)
2: int (4 bytes)
3: float (4 bytes & decimals)
4: double (8 bytes & decimals)
Return
If it finds value it returns the offset, if not found returns 0.
<novcain@gmail.com>
*/
DWORD dwScanMemory( DWORD dwScanStart, DWORD dwScanEnd, float fValueToScanFor, int iValueType )
{
DWORD dwScanOffset = dwScanStart; //holds current offset
char* cScanValue; //temporary variable.. holds value of current offset
bool bScan = true; //if true, end scanning
if( iValueType == 1 ){ short vScanFor = fValueToScanFor; }
else if( iValueType == 2 ){ int vScanFor = fValueToScanFor; }
else if( iValueType == 3 ){ float vScanFor = fValueToScanFor; }
else if( iValueType == 4 ){ double vScanFor = fValueToScanFor; }
else{ char vScanFor = fValueToScanFor; }
add_log("Starting to scan memory for %i",vScanFor);
while(bScan == true){ //while we're scanning, no result found
dwScanOffset += 0x00000001; //move to next offset
cScanValue = (char*)dwScanOffset; //set cScanValue to the current value
if(*cScanValue == vScanFor){ //if the current value is same as the one we're scanning for
add_log("Value found (%i) * %d",vScanFor,dwScanOffset); } //add it to the log
if(dwScanOffset == dwScanEnd){ //if we reached the end of the scan-range
add_log("Reached end of scan-range"); bScan = false; } //end scanning
}
return dwScanOffset; //return the offset that was found
}
Author: Mr. Novocain