If anyone on here knows a good amount about messing with system memory then please lend me a hand. I'm writing a program that reads a string found in memory and then is supposed to write a replacement string to that memory location. I have no problem finding the
first location referencing the string and the
WriteProcessMemory function does not fail (in the sense that it actually claims to have written the bytes to memory) but I never see anything change because I'm only finding the first reference rather than the one I need. Here is my code so far which uses the
PeekPoke library attached. Note: The program can run out of memory depending on the program you are targeting. I've found that notepad++ works fine (in the sense that it doesn't run out of memory finding the
first occurence of the string in its memory) so give that a try if you have it installed.
CONST PROCESS_VM_READ
= &H0010 CONST PROCESS_QUERY_INFORMATION
= &H0400 CONST PROCESS_VM_WRITE
= &H0020 CONST PROCESS_VM_OPERATION
= &H0008
dwAllocationGranularity
AS LONG
TYPE MEMORY_BASIC_INFORMATION
TYPE MEMORY_BASIC_INFORMATION
'SUB pokeb (BYVAL p AS _UNSIGNED _OFFSET, BYVAL n AS _UNSIGNED _BYTE)
'RelaunchAsAdmin 'if uncommented, will make the program launch as administrator (if not already running as administrator)
someData
= "Basic options" + CHR$(0) 'Whatever string you are searching for
'pid = GetCurrentProcessId
pid = 14264 'Whatever PID for program you want to change
ret
= GetAddressOfData
(pid
, someData
, LEN(someData
), "hello!") 'replace "hello!" with whatever you want to attempt
PRINT PointerToString
(ret
) PRINT "Length of pointer string:"; PointerLen
(ret
)
process
= OpenProcess
(PROCESS_VM_READ
OR PROCESS_QUERY_INFORMATION
OR PROCESS_VM_WRITE
OR PROCESS_VM_OPERATION
, FALSE
, pid
) DIM info
AS MEMORY_BASIC_INFORMATION
p = info.BaseAddress
PRINT "Bytes Read:"; bytesRead
FOR i
= 0 TO bytesRead
- plen
IF pdata
= PointerToString
(p
+ i
) THEN GetAddressOfData = p + i
writes
= WriteProcessMemory
(process
, p
+ i
, _OFFSET(change
), LEN(change
), _OFFSET(bytesWritten
)) chunk(i) = "" 'I don't know if this helps. I just figured it "might" free memory?
p = p + info.RegionSize
LOOP WHILE p
< si.lpMaximumApplicationAddress
FOR x
= 0 TO PointerLen
(value
) offtostring
= offtostring
+ CHR$(peekb
(value
+ x
)) PointerToString = offtostring
PointerLen = strlen(value)
adminCheck
= _SHELLHIDE(">nul 2>&1 " + CHR$(34) + "%SYSTEMROOT%\system32\cacls.exe" + CHR$(34) + " " + CHR$(34) + "%SYSTEMROOT%\system32\config\system" + CHR$(34)) IF adminCheck
= 5 THEN 'Not running as administrator