Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ReadProcessMemory中与Int32等效的字符串_C#_Kernel32_Readprocessmemory - Fatal编程技术网

C# ReadProcessMemory中与Int32等效的字符串

C# ReadProcessMemory中与Int32等效的字符串,c#,kernel32,readprocessmemory,C#,Kernel32,Readprocessmemory,这将从我的程序中返回一个整数,计算游戏中的总经验量。它是可操作的,而且有效 class Program { [DllImport("kernel32.dll")] public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpN

这将从我的程序中返回一个整数,计算游戏中的总经验量。它是可操作的,而且有效

class Program
    {
        [DllImport("kernel32.dll")]
        public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
            [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);

        static void Main(string[] args)
        {
            int add_base;
            int add_player_exp = 0x3C1200;

            Process p = Process.GetProcessesByName("Game")[0];

            if (p != null)
            {
                add_base = p.MainModule.BaseAddress.ToInt32();
                add_player_exp += add_base;

                string output;
                int exp;

                exp = ReadInt32(p.Handle, add_player_exp);

                output = String.Concat("Exp: ", exp.ToString());

                Console.WriteLine(output);
                Console.ReadKey();

            }
        }

        private static int ReadInt32(IntPtr handle, long address)
        {
            return BitConverter.ToInt32(ReadBytes(handle, address, 4), 0);
        }

        private static byte[] ReadBytes(IntPtr handle, long address, uint bytesToRead)
        {
            IntPtr ptrBytesRead;
            byte[] buffer = new byte[bytesToRead];

            ReadProcessMemory(handle, new IntPtr(address), buffer, bytesToRead, out ptrBytesRead);

            return buffer;
        }
    }

从ReadProcessMemory中检索字符串的等效代码是什么?

从内存中读取空终止字符串常规c字符串(字符数组):

public static string ReadNullTerminatedString(IntPtr handle, IntPtr addr, int maxlength)
{
    var bytearray = new byte[maxlength];

    IntPtr bytesread = IntPtr.Zero;

    ReadProcessMemory(handle, addr, bytearray, maxlength, out bytesread);

    int nullterm = 0;
    while (nullterm < bytesread.ToInt64() && bytearray[nullterm] != 0)
    {
        nullterm++;
    }

    string s = Encoding.ASCII.GetString(bytearray, 0, nullterm);

    return s;
}
公共静态字符串ReadNullTerminatedString(IntPtr handle、IntPtr addr、int maxlength)
{
var bytearray=新字节[maxlength];
IntPtr bytesread=IntPtr.Zero;
ReadProcessMemory(句柄、地址、字节数组、maxlength、out字节读取);
int nullterm=0;
while(nullterm
要从内存中读取空终止字符串常规c字符串(字符数组),请执行以下操作:

public static string ReadNullTerminatedString(IntPtr handle, IntPtr addr, int maxlength)
{
    var bytearray = new byte[maxlength];

    IntPtr bytesread = IntPtr.Zero;

    ReadProcessMemory(handle, addr, bytearray, maxlength, out bytesread);

    int nullterm = 0;
    while (nullterm < bytesread.ToInt64() && bytearray[nullterm] != 0)
    {
        nullterm++;
    }

    string s = Encoding.ASCII.GetString(bytearray, 0, nullterm);

    return s;
}
公共静态字符串ReadNullTerminatedString(IntPtr handle、IntPtr addr、int maxlength)
{
var bytearray=新字节[maxlength];
IntPtr bytesread=IntPtr.Zero;
ReadProcessMemory(句柄、地址、字节数组、maxlength、out字节读取);
int nullterm=0;
while(nullterm
您所缺少的只是字节数组到字符串的转换,类似于
Encoding.ASCII.ToString(ReadBytes(…)
这取决于它是什么类型的字符串。它是一个简单的ASCIIZ字符串,每个字符有一个字节,以0字节结尾吗?Unicode字符串?一个Pascal类型的字符串,其前导长度的单词后跟那么多字符,怎么样?大约有一百万根弦和三种不同类型的弦。您必须更明确地说明您要查找的字符串类型。您所缺少的只是字节数组到字符串的转换,类似于
Encoding.ASCII.ToString(ReadBytes(…)
这种类型取决于它是什么类型的字符串。它是一个简单的ASCIIZ字符串,每个字符有一个字节,以0字节结尾吗?Unicode字符串?一个Pascal类型的字符串,其前导长度的单词后跟那么多字符,怎么样?大约有一百万根弦和三种不同类型的弦。你必须更明确地知道你在寻找什么样的字符串。