Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:58:52+00:00 2026-05-30T18:58:52+00:00

I am writing a program that creates a process and then read some bits

  • 0

I am writing a program that creates a process and then read some bits of his memory. To get the address, I used the debugger OllyDbg.

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

namespace winapi
{
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool ReadProcessMemory(
          IntPtr hProcess,
          IntPtr lpBaseAddress,
          [Out] byte[] lpBuffer,
          int dwSize,
          out UInt32 lpNumberOfBytesRead
         );


        static void Main()
        {
            Console.WriteLine("WinAPI test");
            Console.WriteLine("---");
            Console.WriteLine();

            var startInfo = new ProcessStartInfo { FileName = "Program.exe" };
            Process p = Process.Start(startInfo);
            var bytes = new byte[4];
            uint read = 0;
            p.WaitForInputIdle();
            //  

            while (read == 0)
            {
                ReadProcessMemory(p.MainWindowHandle, (IntPtr)0x052f820, bytes, bytes.Length, out read);    
                System.Threading.Thread.Sleep(10);
            }

            Console.WriteLine(read.ToString());
            Console.ReadLine();
        }
    }
}

after the process started, my loop never ends.
data from the debugger:

0052F820 | 75 2F 3F 72 61 67 65 5F 69 64 3D 31 33

where is my mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:58:53+00:00Added an answer on May 30, 2026 at 6:58 pm

    Answer is already provided by @zmbq. ReadProcessMemory does not behave like Stream, where every read operation adds the total read count to the stream position.

    I can still see another problem with the code, you are passing Window handle instead of the process handle. So even if you get the result, it is not actually reading memory of your target process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that creates and edits directories and files in a file
I'm writing a program that creates a 2D array from a integer n. I
I am contemplating writing a program that will move some newly created dirs to
Im writing a program that should read input via stdin, so I have the
I am writing a program that must register time of starting a process such
I'm writing a c# program that will launch many child processes. At some time
I've created a script that by default creates one multiprocessing Process; then it works
I used to think that metaprogramming involved modifying the program, and (as do some
I'm writing a utility program with C# in WPF that allows users to create
I'm writing a program that sends an email out at a client's specific local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.