none
Quiero usar un codigo de C# en VB.net RRS feed

  • Pregunta

  • Este es el codigo en C# :

    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Text;

    public class MemoryRead
    {
        const int PROCESS_WM_READ = 0x0010;

        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll")]
        public static extern bool ReadProcessMemory(int hProcess,
          int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);

        public static void Main()
        {
            Process process = Process.GetProcessesByName("Wolfteam.bin")[0];
            IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);

            int bytesRead = 0;
            byte[] buffer = new byte[24]; //'Hello World!' takes 12*2 bytes because of Unicode 


            // 0x0046A3B8 is the address where I found the string, replace it with what you found
            ReadProcessMemory((int)processHandle, 0x0015B7D6, buffer, buffer.Length, ref bytesRead);

            Console.WriteLine(Encoding.Unicode.GetString(buffer) +
               " (" + bytesRead.ToString() + "bytes)");
            Console.ReadLine();
        }
    }

    Y tambien quisiera que lo que leee el ReadProcessMemory se ponga en un textbox y no en una consola 

    domingo, 15 de julio de 2018 17:01

Respuestas

  • Imports System
    Imports System.Diagnostics
    Imports System.Runtime.InteropServices
    Imports System.Text
    
    Public Class MemoryRead
        Const PROCESS_WM_READ As Integer = &H0010
        <DllImport("kernel32.dll")>
        Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
        <DllImport("kernel32.dll")>
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Byte(), ByVal dwSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
    
        Public Shared Sub Main()
            Dim process As Process = Process.GetProcessesByName("Wolfteam.bin")(0)
            Dim processHandle As IntPtr = OpenProcess(PROCESS_WM_READ, False, process.Id)
            Dim bytesRead As Integer = 0
            Dim buffer As Byte() = New Byte(23) {}
            ReadProcessMemory(CInt(processHandle), &H0015B7D6, buffer, buffer.Length, bytesRead)
            Console.WriteLine(Encoding.Unicode.GetString(buffer) & " (" & bytesRead.ToString() & "bytes)")
            Console.ReadLine()
        End Sub
    End Class
    
    Solo cambia lo que se imprime en consola por el TextBox.Text y ya
    • Marcado como respuesta azangel1999 lunes, 16 de julio de 2018 2:48
    domingo, 15 de julio de 2018 17:55

Todas las respuestas

  • Imports System
    Imports System.Diagnostics
    Imports System.Runtime.InteropServices
    Imports System.Text
    
    Public Class MemoryRead
        Const PROCESS_WM_READ As Integer = &H0010
        <DllImport("kernel32.dll")>
        Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
        <DllImport("kernel32.dll")>
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Byte(), ByVal dwSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
    
        Public Shared Sub Main()
            Dim process As Process = Process.GetProcessesByName("Wolfteam.bin")(0)
            Dim processHandle As IntPtr = OpenProcess(PROCESS_WM_READ, False, process.Id)
            Dim bytesRead As Integer = 0
            Dim buffer As Byte() = New Byte(23) {}
            ReadProcessMemory(CInt(processHandle), &H0015B7D6, buffer, buffer.Length, bytesRead)
            Console.WriteLine(Encoding.Unicode.GetString(buffer) & " (" & bytesRead.ToString() & "bytes)")
            Console.ReadLine()
        End Sub
    End Class
    
    Solo cambia lo que se imprime en consola por el TextBox.Text y ya
    • Marcado como respuesta azangel1999 lunes, 16 de julio de 2018 2:48
    domingo, 15 de julio de 2018 17:55
  • y como lo cambio lo que se imprime en consola por el TextBox.Text ?

    Imports System
    Imports System.Diagnostics
    Imports System.Runtime.InteropServices
    Imports System.Text
    Public Class MemoryRead
        Const PROCESS_WM_READ As Integer = &H10
        <DllImport("kernel32.dll")>
        Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
        End Function
        <DllImport("kernel32.dll")>
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Byte(), ByVal dwSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
        End Function
        Public Shared Sub Main()
            Dim process As Process = process.GetProcessesByName("Wolfteam.bin")(0)
            Dim processHandle As IntPtr = OpenProcess(PROCESS_WM_READ, False, process.Id)
            Dim bytesRead As Integer = 0
            Dim buffer As Byte() = New Byte(23) {}
            ReadProcessMemory(CInt(processHandle), &H15B7D6, buffer, buffer.Length, bytesRead)
            TextBox1.text = (Encoding.Unicode.GetString(buffer) & " (" & bytesRead.ToString() & "bytes)")
        End Sub
    End Class

    Lo hice asi pero sale que : que no se puede hacer referencia a un miembro de instancia de una clase del mismo metodo...

    domingo, 15 de julio de 2018 18:08
  • Intenta colocandole un .ToString al final a ver que sale :/
    domingo, 15 de julio de 2018 18:14
  • Asi ?

    Imports System
    Imports System.Diagnostics
    Imports System.Runtime.InteropServices
    Imports System.Text
    
    Public Class MemoryRead
        Const PROCESS_WM_READ As Integer = &H10
        <DllImport("kernel32.dll")>
        Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
        End Function
        <DllImport("kernel32.dll")>
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Byte(), ByVal dwSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
        End Function
        Public Shared Sub Main()
            Dim process As Process = process.GetProcessesByName("Wolfteam.bin")(0)
            Dim processHandle As IntPtr = OpenProcess(PROCESS_WM_READ, False, process.Id)
            Dim bytesRead As Integer = 0
            Dim buffer As Byte() = New Byte(23) {}
            ReadProcessMemory(CInt(processHandle), &H15B7D6, buffer, buffer.Length, bytesRead)
            TextBox1.text = (Encoding.Unicode.GetString(buffer) & " (" & bytesRead.ToString() & "bytes)").ToString()
        End Sub
    End Class

    Lo puse asi pero igual me sale el error :/ :(

    domingo, 15 de julio de 2018 18:21
  • En que parte estas colocando el codigo? Porque si la clase donde esta creado el textbox no es la misma clase MemoryRead quizas ese sea al problema
    domingo, 15 de julio de 2018 18:25
  • Lo estoy haciendo en el codigo fuente de un windows form en vb.net 
    domingo, 15 de julio de 2018 18:30
  • Quitale el Shared a la funcion Main()


    domingo, 15 de julio de 2018 18:35
  • ya no me sale ningun error gracias , pero no me lee el codigo que puse :/ , el textbox aparece vacio 

    domingo, 15 de julio de 2018 18:41
  • Bueno revisa la logica del codigo entonces
    domingo, 15 de julio de 2018 18:43
  • Amigo disculpe , usted no tendra skype o algun correo? , esque quisiera que me ayudara con algunas dudas 
    lunes, 16 de julio de 2018 4:48