After having found the handle of the windows, you need to gain access on the process to read or write in the memory.
Found the handle of window
You need to set debug privilege first
Create a function
Code:
PROCEDURE SetsPrivilege(sPrivilege est une chaîne, bActive est un booléen)
// The SetsPrivilege function will accept a handle to a token, a
// sPrivilege, and a flag to either enable/disable that sPrivilege. The
// function will attempt to perform the desired action upon the token
// returning TRUE if it succeeded, or FALSE if it failed.
LUID est une structure
lowpart est un entier
highpart est un entier
FIN
LUID_AND_ATTRIBUTES est une structure
pLuid est une LUID
Attributes est un entier
FIN
TOKEN_PRIVILEGES est une structure
PrivilegeCount est un entier
Privileges est un tableau dynamique
FIN
nHdwl est un entier
nRes est un entier
nToken est un entier = 0
TP est une TOKEN_PRIVILEGES // Used in getting the current token sPrivileges
TPPrevious est une TOKEN_PRIVILEGES // Used in setting the new token sPrivileges
sLuid est une LUID // Stores the Local Unique Identifier - refer to MSDN
cbPrevious est un entier // Previous size of the TOKEN_sPrivilegeS structure
lResult est un entier // Result of various API calls
bSetsPrivilege est un booléen
nTOKEN_ADJUST_PRIVILEGES est un entier = 0x0020
nTOKEN_QUERY est un entier = 0x0008
nSE_PRIVILEGE_ENABLED est un entier = 0x0002
nANYSIZE_ARRAY est un entier = 1
nPROCESS_ALL_ACCESS est un entier = 0x1F0FFF
TP:Privileges = allouer un tableau de nANYSIZE_ARRAY LUID_AND_ATTRIBUTES
TPPrevious:Privileges = allouer un tableau de nANYSIZE_ARRAY LUID_AND_ATTRIBUTES
nHdwl = API("kernel32", "GetCurrentProcess")
SI API("advapi32.dll", "OpenProcessToken", nHdwl, OUBinaire(nTOKEN_ADJUST_PRIVILEGES,nTOKEN_QUERY), &nToken) <> 1 ALORS
Erreur("Erreur OpenProcessToken")
FIN
// Grab the size of the TOKEN_sPrivilegeS structure,
// used in making the API calls.
cbPrevious = Dimension(TP)
// Grab the LUID for the request sPrivilege.
lResult = API("advapi32", "LookupPrivilegeValueA", "", sPrivilege, &sLuid)
// If LoopupsPrivilegeValue fails, the return result will be zero.
// Test to make sure that the call succeeded.
SI (lResult = 0) ALORS
bSetsPrivilege = Faux
FIN
// Set up basic information for a call.
// You want to retrieve the current sPrivileges
// of the token under concern before you can modify them.
TP:PrivilegeCount = 1
TP:Privileges[1]:pLuid = sLuid
TP:Privileges[1]:Attributes = nSE_PRIVILEGE_ENABLED
bSetsPrivilege = lResult
// You need to acquire the current sPrivileges first
lResult = API("advapi32.dll", "AdjustTokenPrivileges", nToken, Faux, &TP, 0, 0, 0)
// If AdjustTokensPrivileges fails, the return result is zero,
// test for success.
SI (lResult = 0) ALORS
bSetsPrivilege = False
FIN
// Now you can set the token sPrivilege information
// to what the user is requesting.
TPPrevious:PrivilegeCount = 1
TPPrevious:Privileges[1]:pLuid = sLuid
// either enable or disable the sPrivilege,
// depending on what the user wants.
SELON bActive
CAS Vrai
TPPrevious:Privileges[1]:Attributes = OUBinaire(TPPrevious:Privileges[1]:Attributes,nSE_PRIVILEGE_ENABLED)
CASE Faux
TPPrevious:Privileges[1]:Attributes = OUExclusifBinaire(TPPrevious:Privileges[1]:Attributes, ETBinaire(nSE_PRIVILEGE_ENABLED, TPPrevious:Privileges[1]:Attributes))
FIN
// Call adjust the token sPrivilege information.
//lResult = AdjustTokensPrivileges(nHandle, -1, TPPrevious, cbPrevious, TP, cbPrevious)
API("kernel32", "CloseHandle", nToken)
API("kernel32", "CloseHandle", nHdwl)
// Determine your final result of this function.
SI (lResult = 0) ALORS
// You were not able to set the sPrivilege on this token.
RENVOYER Faux
SINON
// You managed to modify the token sPrivilege
RENVOYER Vrai
FIN
And then, you need to get the access and get an ID.
Simply execute this code
Code:
//On autorise la lecture de la mémorie sur le jeu
SetsPrivilege("SeDebugPrivilege", Vrai)
//On crée un ID avec tous les droits qui pointe vers le handle de WoW
nRes = API("user32", "GetWindowThreadProcessId", gnWOW_HANDLE, &gnWOW_ID)
//On ouvre l'ID avec tous les droits
gnWOW = API("kernel32", "OpenProcess", 0x1F0FFF, Faux, gnWOW_ID)
SI gnWOW <> 0 ALORS
Info("OK on a récupéré l'id avec les droits " + gnwow)
SINON
Erreur("Erreur : " + API("kernel32", "GetLastError"))
FIN
So, let's go, you can now read or write in the memory !!!
ATTENTION !!!
If you are developping with Windev 12, you can't get access on the process under Windows Vista and Windows Seven
You can only get the access with Windev 14.
But, under Windows XP, all is fine with Windev 12