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 8422133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:21:18+00:00 2026-06-10T03:21:18+00:00

I would like to attach to a running process using WinDbg, and modify a

  • 0

I would like to attach to a running process using WinDbg, and modify a certain function’s code to simply return on invocation (for educational purposes).

I have used the following commands:

uf dll!name

This gives me a disassembly of the function.

I have picked a specific address at a certain location and modified it to ret:

ew addr c3

This crashes every time, what am i doing wrong?

  • 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-06-10T03:21:19+00:00Added an answer on June 10, 2026 at 3:21 am

    You need to make sure you do the appropriate clean up so the stack is left in a proper state. Depending on the calling convention the method usually pushes stuff on the stack as part of the prologue. This must be undone as part of the epilogue.

    Here’s an example of changing a JIT compiled method using WinDbg.

    The code:

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Message();
                Console.ReadLine();
                Message();
                Console.WriteLine("done");
            }
    
            private static void Message()
            {
                Console.WriteLine("message");
            }
        }
    }
    

    I compiled this as Debug to prevent the compiler from inlining the calls to Message.

    Then I ran the executable and attached the debugger at the call to ReadLine.

    For managed code I need to use SOS.dll to locate the JIT compiled code. So I loaded SOS and found the address for the code as follows.

    0:004> .loadby sos clr
    0:004> !name2ee *!ConsoleApplication1.Program
    Module:      04a11000
    Assembly:    mscorlib.dll
    --------------------------------------
    Module:      001b2e94
    Assembly:    ConsoleApplication1.exe
    Token:       02000002
    MethodTable: 001b37b4
    EEClass:     001b125c
    Name:        ConsoleApplication1.Program
    0:004> !dumpmt -md 001b37b4
    EEClass:         001b125c
    Module:          001b2e94
    Name:            ConsoleApplication1.Program
    mdToken:         02000002
    File:            c:\temp\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
    BaseSize:        0xc
    ComponentSize:   0x0
    Slots in VTable: 7
    Number of IFaces in IFaceMap: 0
    --------------------------------------
    MethodDesc Table
       Entry MethodDe    JIT Name
    04d14960 04a16728 PreJIT System.Object.ToString()
    04d08790 04a16730 PreJIT System.Object.Equals(System.Object)
    04d08360 04a16750 PreJIT System.Object.GetHashCode()
    04d016f0 04a16764 PreJIT System.Object.Finalize()
    001bc019 001b37ac   NONE ConsoleApplication1.Program..ctor()
    002a0050 001b3794    JIT ConsoleApplication1.Program.Main(System.String[])
    002a00a8 001b37a0    JIT ConsoleApplication1.Program.Message()
    0:004> !u 001b37a0    
    Normal JIT generated code
    ConsoleApplication1.Program.Message()
    Begin 002a00a8, size 21
    *** WARNING: Unable to verify checksum for c:\temp\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
    
    c:\temp\ConsoleApplication1\ConsoleApplication1\Program.cs @ 20:
    002a00a8 55              push    ebp        <-- prologue
    002a00a9 8bec            mov     ebp,esp    
    002a00ab 833d60311b0000  cmp     dword ptr ds:[1B3160h],0   <-- start of method
    002a00b2 7405            je      ConsoleApplication1!ConsoleApplication1.Program.Message()+0x11 (002a00b9)
    002a00b4 e8fb6ff570      call    clr!JIT_DbgIsJustMyCode (711f70b4)
    002a00b9 90              nop
    
    c:\temp\ConsoleApplication1\ConsoleApplication1\Program.cs @ 21:
    002a00ba 8b0d34217403    mov     ecx,dword ptr ds:[3742134h] ("message")
    002a00c0 e82bd3ad04      call    mscorlib_ni!System.Console.WriteLine(System.String) (04d7d3f0)
    002a00c5 90              nop
    
    c:\temp\ConsoleApplication1\ConsoleApplication1\Program.cs @ 22:
    002a00c6 90              nop
    002a00c7 5d              pop     ebp   <-- epilogue
    002a00c8 c3              ret
    

    Then I opened the Memory window and pointed it to 002a00ab which is the first part of the actual method body of Message and changed the two opcodes to 5d and c3 for pop edb and ret respectively. If I skipped the pop edb part the stack would be messed up and I would get an exception.

    I hit Go and the application continued without printing “message” a second time.

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

Sidebar

Related Questions

I would like to attach an error to a formItem. In spark, it appears
I have a well div, and I would like to attach a small text/image
Would like to know the c# code to actually retrieve the IP type: Static
I'm running an application (firefox) and I would like to know if it's possible
I use Runtime.getRuntime().exec() to execute my native cpp application and would like to attach/debug
i would like to attach html controls like textboxes to a midi controller, is
In my WPF application I would like to attach an input gesture to a
I would like to run a console application with elevated permissions. Running it from
Normally to attach a debuger to a running jvm you would need start the
I would like to attach screen or tmux inside emacs, in shell mode. I

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.