elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  ayuda, uso del ReadProcessMemory VB6.0
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda, uso del ReadProcessMemory VB6.0  (Leído 2,805 veces)
AlxSpy

Desconectado Desconectado

Mensajes: 137


Ver Perfil
ayuda, uso del ReadProcessMemory VB6.0
« en: 7 Junio 2011, 20:54 pm »

estoy haciendo un code para buscar datos en la memoria de un proceso uso el readprocessmemory:

Código
  1. Option Explicit
  2.  
  3. Dim hProcess As Long
  4.  
  5. Private Sub cmdBusqueda_Click()
  6.    Dim Data As String, Buffer As String, Target As Long
  7.    Dim TmpByte As Byte, TmpInteger As Integer, TmpLong As Long, TmpString As String
  8.    Dim Pos As Long, Address As Long, FirstByte As String
  9.    Dim Fin As Boolean, BytesLeidos As Long, BytesRead As Long
  10.    Dim TotalBytes As Long
  11.    Fin = False
  12.    Address = 0
  13.    If optByte.Value = True Then
  14.        TmpByte = Val(txtData.Text)
  15.        Data = Space(1)
  16.        Call CopyMemory(ByVal Data, TmpByte, 1)
  17.    ElseIf optInteger.Value = True Then
  18.        TmpInteger = Val(txtData.Text)
  19.        Data = Space(2)
  20.        Call CopyMemory(ByVal Data, TmpInteger, 2)
  21.    ElseIf optLong.Value = True Then
  22.        TmpLong = Val(txtData.Text)
  23.        Data = Space(4)
  24.        Call CopyMemory(ByVal Data, TmpLong, 4)
  25.    Else   'String
  26.        Data = txtData.Text
  27.        If optStringUnicode.Value = True Then
  28.            Data = Unicode(Data)
  29.        End If
  30.    End If
  31.    Dim Tmp As String, X As Integer, PID As Long
  32.    X = lstProcesos.ListIndex
  33.    If X = -1 Then Exit Sub
  34.    Tmp = lstProcesos.List(X)
  35.    Pos = InStr(1, Tmp, "*")
  36.    If Pos > 0 Then Tmp = Mid(Tmp, Pos + 1)
  37.    PID = Val(Tmp)
  38.    hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
  39.    If hProcess = 0 Then
  40.        MsgBox "No se pudo abrir el proceso", vbCritical, ""
  41.        Exit Sub
  42.    End If
  43.    lstDirecciones.Clear
  44.    FirstByte = Mid(Data, 1, 1)
  45.    While (Fin = False)
  46.        Buffer = Space(5000)
  47.        Call ReadProcessMemory(hProcess, Address, Buffer, Len(Buffer), BytesLeidos)
  48.        DoEvents
  49.        If BytesLeidos > 0 Then
  50.            Buffer = Left(Buffer, BytesLeidos)
  51.            Pos = InStr(1, Buffer, FirstByte)
  52.            If Pos > 0 Then
  53.                Call ReadProcessMemory(hProcess, Address + Pos - 1, Buffer, Len(Buffer), BytesRead)
  54.                If BytesRead > 0 Then Buffer = Left(Buffer, BytesRead)
  55.                If Buffer = Data Then
  56.                    Target = Target + Pos - 1 'dato encontrado
  57.                    lstDirecciones.AddItem Target
  58.                    Address = Target + Len(Data)
  59.                Else
  60.                    Address = Address + 1
  61.                End If
  62.            Else
  63.                Address = Address + BytesLeidos
  64.            End If
  65.        End If
  66.        TotalBytes = TotalBytes + BytesLeidos
  67.        If TotalBytes >= 150000000 Then Fin = True
  68.        If BytesLeidos < 5000 Then Fin = True
  69.    Wend
  70.  
  71.    Call CloseHandle(hProcess)
  72.    Me.Caption = TotalBytes
  73. End Sub
  74.  
  75. Private Sub cmdRefrescar_Click()
  76.    Dim Proceso As String, pShot As PROCESSENTRY32
  77.    Dim ProcessID As Long, P As Long
  78.    Dim R32Next As Long, hHelp32 As Long
  79.    lstProcesos.Clear
  80.    hHelp32 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
  81.    pShot.dwSize = Len(pShot)
  82.    R32Next = Process32First(hHelp32, pShot)
  83.    While (R32Next <> 0)
  84.        Proceso = pShot.szExeFile
  85.        P = InStr(1, Proceso, Chr(0))
  86.        If P > 0 Then Proceso = Left(Proceso, P - 1)
  87.        ProcessID = pShot.th32ProcessID
  88.        lstProcesos.AddItem Proceso & Space(5) & "*" & ProcessID
  89.        R32Next = Process32Next(hHelp32, pShot)
  90.    Wend
  91.    Call CloseHandle(hHelp32)
  92. End Sub
  93.  
  94. Private Sub Form_Load()
  95.    Call cmdRefrescar_Click
  96. End Sub
  97.  

el codigo abre el proceso seleccionado normalmente pero al ejecutar el readprocessmemory , este no lee nada de memoria, al final del cmdBusqueda_Click agregue "me.caption = TotalBytes" (total de bytes leidos) para ver cuantos bytes lee pero siempre me da "0", intente usar el string buffer con byval y sin byval pero igual no lee:

Código
  1. Call ReadProcessMemory(hProcess, Address, ByVal Buffer, Len(Buffer), BytesLeidos)

Código
  1. Call ReadProcessMemory(hProcess, Address, Buffer, Len(Buffer), BytesLeidos)


en google encontre esta declaracion del api:

Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long

tambien encontre otra casi  igual excepto que el parametro lpBuffer no tiene byval, he intentado con ambas formas pero no da resultado.


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: ayuda, uso del ReadProcessMemory VB6.0
« Respuesta #1 en: 7 Junio 2011, 22:34 pm »

El buffer debe ser tipo byte ya que un string es en medida el doble que un byte... por otro lado no le entiendo a tu código esta muiy enredado, Separa-lo por funciones por que asi no se que es que.

Declara las variables siempre debajo de la declaración del proceso, no las declaras a la mitad del proceso, no se entiende o cuesta entenderlo.


En línea

The Dark Shadow is my passion.
AlxSpy

Desconectado Desconectado

Mensajes: 137


Ver Perfil
Re: ayuda, uso del ReadProcessMemory VB6.0
« Respuesta #2 en: 8 Junio 2011, 00:39 am »

cambie el string buffer a array de bytes, este code mas chico y mas entendible:

Código
  1. 'Form1.frm
  2. Option Explicit
  3.  
  4. Private Sub Command1_Click()
  5.    Dim PID As Long, Buffer(1 To 5000) As Byte, BytesLeidos As Long
  6.    Dim hProcess As Long, Address As Long
  7.    PID = Val(txtPID.Text)
  8.    hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
  9.    If hProcess = 0 Then
  10.        MsgBox "No se pudo abrir el proceso", vbCritical, ""
  11.        Exit Sub
  12.    End If
  13.  
  14.    Address = 10
  15.  
  16.    Call ReadProcessMemory(hProcess, Address, Buffer(1), 5000, BytesLeidos)
  17.    Call CloseHandle(hProcess)
  18.    Me.Caption = BytesLeidos
  19. End Sub
  20.  

y las apis:
Código
  1. 'module1.bas
  2. Option Explicit
  3.  
  4. Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
  5. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  6.  
  7.  
  8. 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
  9.  
  10. Public Const PROCESS_ALL_ACCESS = &H1F0FFF

pero es extraño lo he chequeado una y otra ves y no anda, no lee.Lo he ejecutadoo en mi pc y en mi maquina virt. y nada. ¿que podra ser?
Incluso intente cambiando la declaracion del parametro "lpBuffer as any" a typo Byte pero tampoco.
« Última modificación: 8 Junio 2011, 00:46 am por alxspy » En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: ayuda, uso del ReadProcessMemory VB6.0
« Respuesta #3 en: 8 Junio 2011, 03:43 am »

.
yo lo haria asi:

Nesesitas un Boton y pegar lo siguiente en un form.

Nunca me a gustado declarar las apis como as Any asi que lo modifico para que trabaje con punteros en lugar de referencias.

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
  5. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
  6. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  7. Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Long, ByVal nSize As Long, lpNumberOfBytesRead As Long) As Long
  8. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  9.  
  10. Private Memoria(0 To 100)   As Long
  11.  
  12. Private Sub Command1_Click()
  13. Dim i As Long
  14. Dim bToFind()               As Byte
  15.    For i = 20 To 35
  16.        Memoria(i) = (i + 4658984)
  17.    Next
  18.    bToFind() = LongToByte(4658984 + 20)
  19.    ' // tiene que dar la dirrecion en memoria del indice de    varptr(Memoria(20))
  20.    MsgBox VarPtr(Memoria(20)) = FindInMemory(Me.hWnd, bToFind, VarPtr(Memoria(0)), (VarPtr(Memoria(100))) + LenB(Memoria(100)))
  21. End Sub
  22.  
  23. Public Function FindInMemory(ByVal hWnd As Long, _
  24.                             ByRef bToFind() As Byte, _
  25.                             ByVal lptrIni As Long, _
  26.                             ByVal lptrend As Long) As Long
  27. ' No termine bien la funcion solo es un pequeño Esbozo para el tema.
  28. Dim hproc                   As Long
  29. Dim babuff()                As Byte
  30. Dim llnbuff                 As Long
  31. Dim llnread                 As Long
  32. Dim lret                    As Long
  33. Dim lptradd                 As Long
  34. Dim pId                     As Long
  35.  
  36. Dim q                       As Long
  37. Dim c                       As Long
  38.  
  39.    FindInMemory = 0
  40.    llnbuff = ArrayCount(bToFind())
  41.    If Not ((lptrIni = 0) And (hWnd = 0) And (llnbuff = 0) And (lptrend = 0)) And (llnbuff <= (lptrend - lptrIni)) Then
  42.        GetWindowThreadProcessId hWnd, pId
  43.        hproc = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
  44.        If Not (hproc = 0) Then
  45.            ReDim babuff(0 To (llnbuff - 1))
  46.            lptradd = 0
  47.            Do  '   //  Se puede optimizar bastante...
  48.                ReadProcessMemory hproc, ByVal (lptrIni + lptradd), ByVal VarPtr(babuff(0)), llnbuff, llnread
  49.                lret = InByteArray(0, bToFind, babuff)
  50.                If (lret >= 0) Then
  51.                    FindInMemory = ((lptrIni + lptradd) + lret)
  52.                    Exit Do
  53.                End If
  54.                lptradd = (lptradd + 1)
  55.                DoEvents
  56.            Loop Until ((lptrIni + lptradd) = (lptrend - llnbuff))
  57.            CloseHandle hproc
  58.        End If
  59.    End If
  60. End Function
  61.  
  62.  

en un modulo:

Código
  1.  
  2. Option Explicit
  3.  
  4. Public Declare Function VarPtrA Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long
  5. Public Declare Sub lCopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
  6.  
  7. Public Const InvalidValueArray = -1
  8.  
  9. Public Function InByteArray(ByVal lStart As Long, ByRef bArray1() As Byte, ByRef bArray2() As Byte) As Long
  10. Dim llna1               As Long
  11. Dim llna2               As Long
  12. Dim llimt               As Long
  13. Dim q                   As Long
  14. Dim c                   As Long
  15.    InByteArray = (-1)
  16.    If (lStart >= 0) Then
  17.        llna1 = ArrayCount(bArray1())
  18.        llna2 = ArrayCount(bArray2())
  19.        If Not ((llna1 = 0) And (llna2 = 0)) Then
  20.            llimt = (llna1 - llna2)
  21.            If (llimt >= 0) Then
  22.                q = lStart
  23.                Do While (q <= llimt)
  24.                    Do While (bArray1(q + c) = bArray2(c))
  25.                        c = (c + 1)
  26.                        If (c = llna2) Then
  27.                            InByteArray = q
  28.                            GoTo ExitFunc
  29.                        End If
  30.                    Loop
  31.                    q = ((q + c) + 1)
  32.                    c = 0
  33.                Loop
  34.            End If
  35.        End If
  36.    End If
  37. ExitFunc:
  38. End Function
  39.  
  40. Public Function LongToByte(ByVal lVal As Long) As Byte()
  41. Dim bRet(0 To 3)        As Byte
  42.    bRet(3) = (lVal And &HFF000000) \ &H1000000
  43.    bRet(2) = (lVal And &HFF0000) \ &H10000
  44.    bRet(1) = (lVal And &HFF00&) \ &H100
  45.    bRet(0) = (lVal And &HFF)
  46.    LongToByte = bRet
  47. End Function
  48.  
  49. Public Function ArrayCount(ByRef vArray() As Byte)
  50.    If Itsarrayini(VarPtrA(vArray)) Then
  51.        If LBound(vArray) = 0 Then
  52.            ArrayCount = 1
  53.        End If
  54.        ArrayCount = ArrayCount + UBound(vArray)
  55.    Else
  56.        ArrayCount = 0
  57.    End If
  58. End Function
  59.  
  60. Public Function Itsarrayini(ByVal lngPtr As Long, Optional LnBytes As Long = 4) As Boolean
  61. Dim lng_PtrSA                   As Long
  62.    If lngPtr <> 0 And LnBytes > 0 Then
  63.        Call lCopyMemory(ByVal VarPtr(lng_PtrSA), ByVal lngPtr, LnBytes)
  64.        Itsarrayini = Not lng_PtrSA = 0
  65.    End If
  66. End Function
  67.  
  68.  

Temibles Lunas!¡.
« Última modificación: 8 Junio 2011, 04:01 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
AlxSpy

Desconectado Desconectado

Mensajes: 137


Ver Perfil
Re: ayuda, uso del ReadProcessMemory VB6.0
« Respuesta #4 en: 8 Junio 2011, 16:04 pm »

eso debe ser el fallo.   ;-) thanks
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ReadProcessMemory [VB6] ??? « 1 2 »
Programación Visual Basic
Xhelar 10 8,798 Último mensaje 8 Enero 2010, 05:01 am
por engel lex
[Ayuda] ReadProcessMemory Address Dinamico
.NET (C#, VB.NET, ASP)
.mokk. 4 6,604 Último mensaje 18 Marzo 2014, 00:30 am
por Eleкtro
ReadProcessMemory en Windows 7
.NET (C#, VB.NET, ASP)
Keyen Night 1 3,106 Último mensaje 28 Febrero 2011, 06:00 am
por BlackZeroX
[AYUDA] ReadProcessMemory
Programación Visual Basic
ŞCØRPIØN-X3 5 2,650 Último mensaje 2 Agosto 2011, 21:43 pm
por ŞCØRPIØN-X3
[Ayuda] Usando La api ReadProcessMemory
Programación Visual Basic
Flamer 6 2,606 Último mensaje 26 Junio 2014, 18:19 pm
por Flamer
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines