none
how fix funtion RRS feed

  • Question

  • hello how fix funtion error ihere 

                ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out var read);
    

     [DllImport("kernel32.dll", SetLastError = true)]
            private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);
    
        public static IntPtr FindDMAAddy(IntPtr hProc, IntPtr ptr, int[] offsets)
        {
            var buffer = new byte[IntPtr.Size];
            foreach (int i in offsets)
            {
                ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out var read);
    
                ptr = (IntPtr.Size == 4)
                ? IntPtr.Add(new IntPtr(BitConverter.ToInt32(buffer, 0)), i)
                : ptr = IntPtr.Add(new IntPtr(BitConverter.ToInt64(buffer, 0)), i);
            }
            return ptr;
        }
    

    Sunday, September 15, 2019 1:24 PM

Answers

  • "out var read" has no sense , and where is read defined ?

    You ask me? I added the question for this reason

    You use a variable and you don't declare it, it is normal that it does not compile ...

    :

    IntPtr read;
    ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out read);


    • Edited by Castorix31 Sunday, September 15, 2019 3:25 PM
    • Marked as answer by programmervb.net Sunday, September 15, 2019 10:20 PM
    Sunday, September 15, 2019 3:24 PM

All replies

  • What error are you talking about?
    Sunday, September 15, 2019 1:49 PM
  • What error are you talking about?

    Sunday, September 15, 2019 1:54 PM
  • Well the ReadPtocess function has prsm problem with the parms you are trying to give it. You can hover the mouse pointer ovrr the red line or compile the program to get the compiler error that may tell you what is wrong with the parms you are trying to pass yo the functionl.

    Or the error could be about something else you are not doing right concerning the function usage, but do one or both  on how to detect and get the error message based on how I explained on how to get it.

    Sunday, September 15, 2019 2:26 PM
  • Well the ReadPtocess function has prsm problem with the parms you are trying to give it. You can hover the mouse pointer ovrr the red line or compile the program to get the compiler error that may tell you what is wrong with the parms you are trying to pass yo the functionl.

    Or the error could be about something else you are not doing right concerning the function usage, but do one or both  on how to detect and get the error message based on how I explained on how to get it.

    how fix
    Sunday, September 15, 2019 2:35 PM
  • You cannot fix a problem if you don't know what the error is about. I have given you two was to have Visual Stuido two expose the error with an error message by you using the mouse pointer over the red line that is under the code line on error or doing a compile of the program and and get the compile error message, which you should be able to do and post the error message.

    .

     

    Sunday, September 15, 2019 2:54 PM
  • You cannot fix a problem if you don't know what the error is about. I have given you two was to have Visual Stuido two expose the error with an error message by you using the mouse pointer over the red line that is under the code line on error or doing a compile of the program and and get the compile error message, which you should be able to do and post the error message.

    .

     


    Sunday, September 15, 2019 2:58 PM
  • "out var read" has no sense , and where is read defined ?
    Sunday, September 15, 2019 3:06 PM
  • "out var read" has no sense , and where is read defined ?
    You ask me? I added the question for this reason
    Sunday, September 15, 2019 3:17 PM
  • I suggest that you review articles about the function. I would think that 'out var read' is not correct. What does 'var' have to do with anything? Put the mouse pointer over the read line under 'read' to expose the error message.

    https://codingvision.net/security/c-read-write-another-process-memory

     

    Sunday, September 15, 2019 3:21 PM
  • "out var read" has no sense , and where is read defined ?

    You ask me? I added the question for this reason

    You use a variable and you don't declare it, it is normal that it does not compile ...

    :

    IntPtr read;
    ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out read);


    • Edited by Castorix31 Sunday, September 15, 2019 3:25 PM
    • Marked as answer by programmervb.net Sunday, September 15, 2019 10:20 PM
    Sunday, September 15, 2019 3:24 PM
  • I would point out another problem in your code.  You wrote this:

        ptr = (IntPtr.Size == 4)
                ? IntPtr.Add(new IntPtr(BitConverter.ToInt32(buffer, 0)), i)
                : ptr = IntPtr.Add(new IntPtr(BitConverter.ToInt64(buffer, 0)), i);

    Extra points for knowing that the size of a pointer can vary.  HOWEVER, IntPtr.Size tells you the size of a pointer in YOUR process.  It doesn't tell you anything about the size of a pointer in the process you are reading from, and that's what you need to know here.  You have to fetch information about the process to figure out whether it is a 32-bit or 64-bit process.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, September 16, 2019 4:51 PM