cargar bytes de la memoria de un proceso en un textbox...

Iniciado por jonniemaxxx, 7 Septiembre 2011, 21:57 PM

0 Miembros y 1 Visitante están viendo este tema.

jonniemaxxx

hola pues es que soy nuevo en este tipo de aplicaciones y me gustaria saber que hago para crear una aplicacion que me cargue los bytes de una direccion de la memoria de un proceso... utilize findwindow para hallar el proceso pero no se como leer los bytes la y cargarlos en un textbox son muy pocos solo 30 asi que si se pueden cargar ... porfa ayuda !!!

BlackZeroX

The Dark Shadow is my passion.

jonniemaxxx


jonniemaxxx



Option Explicit
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
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 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 CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * 260
End Type



Private Sub Command1_Click()
    Dim pId As Long, Buffer(1 To 5000) As Byte, BytesLeidos As Long
    Dim hProcess As Long, Address As Long
 
    pId = ElPID("StarCraft.exe")
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
    If hProcess = 0 Then
       MsgBox "Ocurrio un error al intentar abrir el processo StarCraft.exe", vbCritical, ""
    End If

    Address = &H4FD13C

    Call ReadProcessMemory(hProcess, Address, Buffer(15), 15, BytesLeidos)
    Call CloseHandle(hProcess)
    Text1.Text = BytesLeidos
End Sub


Public Function ElPID(sProcess As String) As Long


Dim uProcess As PROCESSENTRY32
Dim hSnapShot As Long
Dim m32 As Long
Dim i As Integer

uProcess.dwSize = Len(uProcess)
hSnapShot = CreateToolhelp32Snapshot(2&, 0&)
m32 = Process32First(hSnapShot, uProcess)
Do While m32
m32 = Process32Next(hSnapShot, uProcess)
If InStr(1, uProcess.szExeFile, sProcess) Then ElPID = uProcess.th32ProcessID
Loop
End Function


y me pregunto yo ... aunke soy un muy novato ... que rayos estoy haciendo mal para que esta linea  "hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pId)"
siempre me tire el "0" y por lo tanto no me pueda leer la memoria del processo ayuda ... no tengo modulos solo es un form con un textbox y un cmdbuttn ... les agradeceria que me ayudaran

Hasseds

Hola , pueden ser por varios motivos, pero dejo el tema para los que mas saben, aún así... te conviene cambiar la siguiente linea:



If InStr(1, uProcess.szExeFile, sProcess) Then ElPID = uProcess.th32ProcessID




por esta:



If InStr(1, uProcess.szExeFile, sProcess, vbTextCompare) Then ElPID = uProcess.th32ProcessID





Saludos


Sergio Desanti