Code:
'//=======================================================
'// Compiler Options
'//=======================================================
Option Explicit
'//=======================================================
'// Author Information
'//=======================================================
'//Author: NAATYE
'//Date: 3/13/2002
'//Enhanced by: Logos
'//Date: 10/24/2007
'//Description: It should work with SC & BW v1.15+ now
'//Thanks to: hure (for his working DebugPrivilege module)
'//=======================================================
'// Notes
'//=======================================================
'//Undocumented Visual Basic Functions
'//VarPtr() - Finds the address any type but string
'//StrPtr() - Find the address of a string
'//ObjPtr() - Find the address for a object
'//Remember the &H in front of a number converts it from hex
'//=======================================================
'// Private Constants
'//=======================================================
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const ANYSIZE_ARRAY = 1
Private Const SE_DEBUG_NAME = "SeDebugPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2
'//=======================================================
'// Public API Functions
'//=======================================================
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
'//=======================================================
'// Private Types
'//=======================================================
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
'//=======================================================
'// Private API Functions
'//=======================================================
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteString Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteValue Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, BufferLength As Any, PreviousState As Any, ReturnLength As Any) As Long
'//=======================================================
'// Support Functions
'//=======================================================
Public Function getProcessHandle(pid As Long) As Long
EnableDebugPrivilege (True)
getProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
EnableDebugPrivilege (False)
End Function
Public Function EnableDebugPrivilege(bOnOff As Boolean) As Boolean
Dim tp As TOKEN_PRIVILEGES
Dim tpPrev As TOKEN_PRIVILEGES
Dim lid As LUID
Dim tpSize As Long
Dim lRet As Long
Dim hCurProc As Long
Dim hToken As Long
tpSize = Len(tp)
hCurProc = GetCurrentProcess()
lRet = OpenProcessToken(hCurProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken)
lRet = LookupPrivilegeValue("", SE_DEBUG_NAME, lid)
tp.PrivilegeCount = 1
tp.Privileges(0).pLuid = lid
tp.Privileges(0).Attributes = 0
'//Get Attributes
lRet = AdjustTokenPrivileges(hToken, 0, tp, tpSize, tpPrev, tpSize)
tpPrev.PrivilegeCount = 1
tpPrev.Privileges(0).pLuid = lid
If bOnOff = True Then
tpPrev.Privileges(0).Attributes = tpPrev.Privileges(0).Attributes Or (SE_PRIVILEGE_ENABLED)
Else
tpPrev.Privileges(0).Attributes = tpPrev.Privileges(0).Attributes Xor _
(SE_PRIVILEGE_ENABLED And tpPrev.Privileges(0).Attributes)
End If
'//Set Attributes
lRet = AdjustTokenPrivileges(hToken, 0, tpPrev, tpSize, ByVal CLng(0), ByVal CLng(0))
CloseHandle (hToken)
EnableDebugPrivilege = CBool(lRet)
End Function
'//=======================================================
'// Peek Functions
'//=======================================================
Public Function PeekString(hWnd As Long, Address As Long, Length As Long, Optional TrimString As Boolean = True) As String '//A string is usually terminated by a double null or &h0 therefore if trim string is enabled it will stop looping if a double null is found
Dim pHandle As Long, ByteValue As Byte, I As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
For I = 0 To Length - 1 Step 1
ReadProcessMemory pHandle, Address + I, ByteValue, 1&, 0&
If (ByteValue = 0) And (TrimString = True) Then
Exit For
End If
PeekString = PeekString & Chr$(ByteValue)
Next
End If
CloseHandle pHandle
End Function
Public Function PeekLong(hWnd As Long, Address As Long) As Long
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
ReadProcessMemory pHandle, Address, PeekLong, 4&, 0&
End If
CloseHandle pHandle
End Function
Public Function PeekInteger(hWnd As Long, Address As Long) As Integer
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
ReadProcessMemory pHandle, Address, PeekInteger, 2&, 0&
End If
CloseHandle pHandle
End Function
Public Function PeekBytes(hWnd As Long, Address As Long, Length As Long) As Byte()
Dim pHandle As Long, Bytes() As Byte, I As Long
ReDim Bytes(Length - 1)
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
For I = 0 To Length - 1 Step 1
ReadProcessMemory pHandle, Address + I, Bytes(I), 1&, 0&
Next
End If
CloseHandle pHandle
End Function
Public Function PeekByte(hWnd As Long, Address As Long) As Byte
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
ReadProcessMemory pHandle, Address, PeekByte, 1&, 0&
End If
CloseHandle pHandle
End Function
'//=======================================================
'// Poke Functions
'//=======================================================
Public Function PokeString(hWnd As Long, Address As Long, Value As String)
Dim X() As Byte, Z As Long
ReDim X(Len(Value) - 1)
For Z = 0 To UBound(X)
X(Z) = Asc(Mid(Value, Z + 1, 1))
Next Z
PokeString = PokeBytes(hWnd, Address, X())
End Function
Public Function PokeLong(hWnd As Long, Address As Long, Value As Long)
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
PokeLong = WriteValue(pHandle, Address, Value, 4&, 0&)
End If
CloseHandle pHandle
End Function
Public Function PokeInteger(hWnd As Long, Address As Long, Value As Integer)
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
PokeInteger = WriteValue(pHandle, Address, Value, 2&, 0&)
End If
CloseHandle pHandle
End Function
Public Function PokeBytes(ByVal hWnd As Long, ByVal Address As Long, ByRef Value() As Byte)
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
PokeBytes = WriteProcessMemory(pHandle, Address, Value(0), CLng(UBound(Value) + 1), 0&)
End If
CloseHandle pHandle
End Function
Public Function PokeByte(ByVal hWnd As Long, ByVal Address As Long, ByRef Value As Byte)
Dim pHandle As Long
GetWindowThreadProcessId hWnd, pHandle
pHandle = getProcessHandle(pHandle)
If (pHandle <> 0) And (Address <> 0) Then
PokeByte = WriteProcessMemory(pHandle, Address, Value, 1&, 0&)
End If
CloseHandle pHandle
End Function
Now for the CD KEY-NUMBER grabber tutorial for 1.15.1. This is for when you're at the battle.net login screen in StarCraft or Brood War. (Don't login, just alt+tab from there.)