{"componentChunkName":"component---src-templates-post-template-js","path":"/windows-windbg-007-memory-spoofing-en","result":{"data":{"markdownRemark":{"id":"d6a9edc2-25ea-549d-a7cf-b2db7e644a8d","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/windows-windbg-007-memory-spoofing\">original page</a>.</p>\n</blockquote>\n<p>My goal is to become proficient with WinDbg for Windows debugging and dump-based troubleshooting.</p>\n<p>In <a href=\"/windows-windbg-002-tutorial-en\">Trying the WinDbg User-Mode Debugging Tutorial</a>, I covered how to debug user-mode applications with WinDbg.</p>\n<p>This time, as a practical use case, I’ll show how to inspect memory and register information during live debugging of a user-mode application with WinDbg.</p>\n<p>For a full list of articles on Windows debugging and dump analysis with WinDbg, see the index page:</p>\n<p>Reference: <a href=\"/windows-windbg-001-index-en\">Debugging and Troubleshooting Techniques with WinDbg</a></p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li><a href=\"#goals-for-this-article\">Goals for This Article</a></li>\n<li><a href=\"#sample-program-used-in-this-article\">Sample Program Used in This Article</a></li>\n<li><a href=\"#launching-the-application-in-windbg\">Launching the Application in WinDbg</a></li>\n<li><a href=\"#setting-a-breakpoint-at-the-address-of-the-main-function\">Setting a Breakpoint at the Address of the main Function</a></li>\n<li><a href=\"#setting-a-breakpoint-at-the-return_addr-function\">Setting a Breakpoint at the return_addr Function</a></li>\n<li><a href=\"#inspecting-memory\">Inspecting Memory</a></li>\n<li><a href=\"#tampering-with-memory\">Tampering with Memory</a></li>\n<li><a href=\"#wrap-up\">Wrap-up</a></li>\n</ul>\n<h2 id=\"goals-for-this-article\" style=\"position:relative;\"><a href=\"#goals-for-this-article\" aria-label=\"goals for this article permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Goals for This Article</h2>\n<p>This article has two goals:</p>\n<ol>\n<li>Confirm that, when a function is called, the address of the instruction to be executed after the function returns is stored in RSP/BSP.</li>\n<li>Tamper with the memory referenced by RSP to cause an arbitrary function to execute.</li>\n</ol>\n<p>I’ll set breakpoints at various points in the program during live user-mode debugging with WinDbg and inspect the stack information at the time of each function call.</p>\n<p>I’ll also tamper with memory from WinDbg to make an arbitrary piece of code execute.</p>\n<h2 id=\"sample-program-used-in-this-article\" style=\"position:relative;\"><a href=\"#sample-program-used-in-this-article\" aria-label=\"sample program used in this article permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Sample Program Used in This Article</h2>\n<p>The program used in this test is made up of the following source code.</p>\n<p>When run, it calls the <code class=\"language-text\">ret_func</code> function, prints a few strings, and then exits.</p>\n<div class=\"gatsby-highlight\" data-language=\"cpp\"><pre class=\"language-cpp\"><code class=\"language-cpp\"><span class=\"token comment\">// return_addr.cpp</span>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">&lt;stdio.h></span></span>\n\n<span class=\"token keyword\">int</span> <span class=\"token function\">ret_func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Call ret_func\\n\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">int</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Start main\\n\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">ret_func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Return ret_func\\n\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The sample code is available at <a href=\"https://github.com/kash1064/Try2WinDbg\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">kash1064/Try2WinDbg</a>.</p>\n<p>For instructions on how to compile the sample program with a symbol file (.pdb), refer to the following article:</p>\n<p>Reference: <a href=\"/windows-windbg-006-symbol-en\">How to Generate Symbol Files (.pdb) in a Linux Environment Using llvm-mingw</a></p>\n<p>Let’s get started with the analysis using <code class=\"language-text\">return_addr.exe</code>, the compiled binary from this source code.</p>\n<h2 id=\"launching-the-application-in-windbg\" style=\"position:relative;\"><a href=\"#launching-the-application-in-windbg\" aria-label=\"launching the application in windbg permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Launching the Application in WinDbg</h2>\n<p>I’m using the UWP version, WinDbg Preview, for this analysis. It is available from the Windows Store.</p>\n<p>First, launch the compiled <code class=\"language-text\">return_addr.exe</code> from WinDbg.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/8f30de1343e57c5f98ceb1fe263c893d/0b533/image-39.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 55.00000000000001%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAARlAAAEZQAGA43XUAAACM0lEQVQoz5WSS28SURiGJ+qGQiqX2gXlfhPBdBQEBk0lKQsv3fgvCLeNsbiQiImbbizwAxrX/Aa7NsaFMcbYFBhgZijQaaEQoGFTXuecGi+JGj3Jk+9cvnnP+31nGEkUIApNSEILDb6Gk0Ef8/kZyJjP8V9jNpuB2W/J2GsegpcGaPXG2OO72Nl5je3tVyiXy5RSqUQpFovf579SxtbWFnZ334D5Igzw/nML7z7y+FSX8fZDFZ6rXuh1l7G8vITFxUXodDpoNBqoVCrKwsICjWq1mu5fWVrChYuX8PhJDszxkQyx1YTQbCjlHqPV5BFdi8Fms2GVZREOh8EqkRAKhRCNRhEMBhGJRBAIBCjXvF4YV8x4/uIlmCP5AIIootPpYHp6inq9Di5+X0lYAXszgAcPN6gA+ZDjoojH4+AU0VgsRi/jOA4ulwtarRb5/DMw8uEBOt0uer0eToZDVKtV3F6/B4fLDY/HQ52aTCaK2WyGxWKhkUD2yNrpdEKv1yuCeTBCo44DxV273YYsy6jVarizdhdWmxVepRSr1UpF/4bD4fghWG/wSrnnDieTCXieR0TpIXHn9/v/SZA4NBgM54L7UgeiJEIQBIzHY9rD9Y1HuL7K0maTkojonyDndrud/glUcNDvo/+N6XRKHQaDt2A0GuHz+SjErdvt/i3knGVv0PxCoQBmNBqBMFQehDiUJAm5zU0kEglkMhlks1mk02mkUikafyaZTCKXe0qdkbxKpYKvCaUEELLRkZkAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/8f30de1343e57c5f98ceb1fe263c893d/8ac56/image-39.webp 240w,\n/static/8f30de1343e57c5f98ceb1fe263c893d/d3be9/image-39.webp 480w,\n/static/8f30de1343e57c5f98ceb1fe263c893d/b0a15/image-39.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/8f30de1343e57c5f98ceb1fe263c893d/8ff5a/image-39.png 240w,\n/static/8f30de1343e57c5f98ceb1fe263c893d/e85cb/image-39.png 480w,\n/static/8f30de1343e57c5f98ceb1fe263c893d/0b533/image-39.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/8f30de1343e57c5f98ceb1fe263c893d/0b533/image-39.png\"\n            alt=\"image-39.png\"\n            title=\"image-39.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>The debugger stops before execution begins, and the debug command prompt becomes available.</p>\n<p>Let’s load the symbol file first.</p>\n<p>In my environment, <code class=\"language-text\">return_addr.pdb</code> is placed on the Desktop, so I use <code class=\"language-text\">.sympath+ &lt;desktop path></code>.\nAfter adding the symbol file path, run the <code class=\"language-text\">.reload</code> command.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\"><span class=\"token punctuation\">.</span>sympath+ C:\\Users\\Tadpole01\\Desktop\n<span class=\"token punctuation\">.</span>reload</code></pre></div>\n<p>When the symbol file is loaded correctly, WinDbg can interpret and display function names and other symbols for <code class=\"language-text\">ttd_tutorial.exe</code>, as shown in the image below.</p>\n<p>When you run the <code class=\"language-text\">lm</code> command to list modules, you should see <code class=\"language-text\">(pdb symbols)</code> as shown here:</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> lm\n<span class=\"token function\">start</span>             <span class=\"token keyword\">end</span>                 module name\n00007ff7`cd710000 00007ff7`cd72a000   return_addr C <span class=\"token punctuation\">(</span>pdb symbols<span class=\"token punctuation\">)</span>          C:\\ProgramData\\Dbg\\sym\\return_addr<span class=\"token punctuation\">.</span>pdb\\28CEC53415E7CD7D4C4C44205044422E1\\return_addr<span class=\"token punctuation\">.</span>pdb\n00007ffd`ef320000 00007ffd`ef5e9000   KERNELBASE   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ffd`ef5f0000 00007ffd`ef6f0000   ucrtbase   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ffd`f01b0000 00007ffd`f026e000   KERNEL32   <span class=\"token punctuation\">(</span>deferred<span class=\"token punctuation\">)</span>             \n00007ffd`f18d0000 00007ffd`f1ac5000   ntdll      <span class=\"token punctuation\">(</span>pdb symbols<span class=\"token punctuation\">)</span>          C:\\ProgramData\\Dbg\\sym\\ntdll<span class=\"token punctuation\">.</span>pdb\\96EF4ED537402DAAA51D4A4212EA4B2C1\\ntdll<span class=\"token punctuation\">.</span>pdb</code></pre></div>\n<h2 id=\"setting-a-breakpoint-at-the-address-of-the-main-function\" style=\"position:relative;\"><a href=\"#setting-a-breakpoint-at-the-address-of-the-main-function\" aria-label=\"setting a breakpoint at the address of the main function permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setting a Breakpoint at the Address of the main Function</h2>\n<p>To set a breakpoint for debugging, first identify the address of the <code class=\"language-text\">main</code> function.</p>\n<p>Running <code class=\"language-text\">x /D /f return_addr!m*</code> displays all symbols starting with <code class=\"language-text\">m</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> x <span class=\"token operator\">/</span>D <span class=\"token operator\">/</span>f return_addr!m*\n A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n\n00007ff6`96451490 return_addr!main <span class=\"token punctuation\">(</span>main<span class=\"token punctuation\">)</span>\n00007ff6`964527b0 return_addr!memcpy <span class=\"token punctuation\">(</span>memcpy<span class=\"token punctuation\">)</span>\n00007ff6`96452790 return_addr!malloc <span class=\"token punctuation\">(</span>malloc<span class=\"token punctuation\">)</span>\n00007ff6`96451420 return_addr!mainCRTStartup <span class=\"token punctuation\">(</span>mainCRTStartup<span class=\"token punctuation\">)</span>\n00007ff6`964516a0 return_addr!matherr <span class=\"token punctuation\">(</span>_matherr<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We can see that the <code class=\"language-text\">main</code> function is at <code class=\"language-text\">00007ff7 cd711490</code>.</p>\n<p>Use the <code class=\"language-text\">bu</code> command to set a breakpoint, then confirm it with <code class=\"language-text\">bl</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> bu 00007ff7`cd711490\n0:000> bl\n     1 e Disable Clear  00007ff7`cd711490     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> return_addr!main</code></pre></div>\n<p>Running the program with the <code class=\"language-text\">g</code> command, execution stopped at the start of the <code class=\"language-text\">main</code> function.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/3d5add2849ffd712de4c9b1b90999cec/0b533/image-40.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 44.99999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAARlAAAEZQAGA43XUAAABwElEQVQoz3WS2a6bMBRF+f9f6W9UqtSXVrlqEsKUQIBg5sHMZPVAVfWhupa2bGR7s473Mb58tfl28rCdANuLiV4FSZrzEiVZQRQrfD+gKiumaaJre9qmRetevuf/ZDw9F9eyud1s7p5Pmma0bYPuOvpeUxQFpnlFqYR99P3Ctm18NoyHr7jfEx4PRRSV5Hkrhi2NqBPTPC+wLIebaVPXrRhCXQmdXhnbhUHPjOPM338YHx8nLpcPzudfQmmSJIlQlXK5pm4aIU6xbj9xnZOUG9HWKXUZsgwFLA2sNbxFW81bZHhSpm0nhGFElqVClFNKmftcVRXZbmj+4Hr+LmsH3cp+7KNVxFJkzDplnjK2pRTTCsNxfDyv4fVS8k7qINrnMAyPdZIoXPd+vLGSoHQH1bOjew7oYKRLBzo9sCzvPyVfrxeez4cYvojjmCAIyIVwXVc5tFBKujfTPOj30bUT0zx/Eskbw3UcbMvCvJxxHFta5CEmJdu6HEf2tE0xdF33CGscNoZBiMR0nv5pb6kdwIiiFyqTEKS/yrpDDzPDtNJ0I8O8kcqe67h4Yri/bVn2qFCCURVjI7S1SKjHcTpMfwPouqnJpSj4BwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/3d5add2849ffd712de4c9b1b90999cec/8ac56/image-40.webp 240w,\n/static/3d5add2849ffd712de4c9b1b90999cec/d3be9/image-40.webp 480w,\n/static/3d5add2849ffd712de4c9b1b90999cec/b0a15/image-40.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/3d5add2849ffd712de4c9b1b90999cec/8ff5a/image-40.png 240w,\n/static/3d5add2849ffd712de4c9b1b90999cec/e85cb/image-40.png 480w,\n/static/3d5add2849ffd712de4c9b1b90999cec/0b533/image-40.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/3d5add2849ffd712de4c9b1b90999cec/0b533/image-40.png\"\n            alt=\"image-40.png\"\n            title=\"image-40.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"setting-a-breakpoint-at-the-return_addr-function\" style=\"position:relative;\"><a href=\"#setting-a-breakpoint-at-the-return_addr-function\" aria-label=\"setting a breakpoint at the return_addr function permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setting a Breakpoint at the return_addr Function</h2>\n<p>My goal here is to observe the value stored in the base pointer at the time of a function call.</p>\n<p>Next, set a breakpoint at the first address of the <code class=\"language-text\">ret_func</code> function, identified using the Disassembly window:</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> bu 00007ff6`96451470\n0:000> bl\n     0 e Disable Clear  00007ff6`96451470     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> return_addr!Z8ret_funcv\n     1 e Disable Clear  00007ff6`96451490     0001 <span class=\"token punctuation\">(</span>0001<span class=\"token punctuation\">)</span>  0:<span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span><span class=\"token operator\">*</span> return_addr!main</code></pre></div>\n<p>After running with <code class=\"language-text\">g</code> and hitting the breakpoint, use the <code class=\"language-text\">r</code> command to print register information:</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">0:000> g\nBreakpoint 0 hit\nreturn_addr!Z8ret_funcv:\n00007ff6`96451470 4883ec28        sub     rsp<span class=\"token punctuation\">,</span>28h\n\n0:000> r\nrax=000000000000000b rbx=0000000000000001 rcx=00000000ffffffff\nrdx=00007ffdef6e0980 rsi=0000021d4c3134d0 rdi=000000000000002b\nrip=00007ff696451470 rsp=0000002e738ff748 <span class=\"token function\">rbp</span>=0000002e738ff780\n r8=0000002e738fdb78  r9=0000021d4c31a47b r10=0000000000000000\nr11=0000002e738ff660 r12=0000000000000000 r13=0000000000000000\nr14=0000021d4c315230 r15=0000000000000001\niopl=0         <span class=\"token function\">nv</span> up ei pl nz na pe nc\ncs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202\nreturn_addr!Z8ret_funcv:\n00007ff6`96451470 4883ec28        sub     rsp<span class=\"token punctuation\">,</span>28h</code></pre></div>\n<p>We can see that the value of the <code class=\"language-text\">rbp</code> register immediately after the function call is <code class=\"language-text\">0x2e738ff780</code>.</p>\n<h2 id=\"inspecting-memory\" style=\"position:relative;\"><a href=\"#inspecting-memory\" aria-label=\"inspecting memory permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Inspecting Memory</h2>\n<p>Next, enter the address pointed to by the <code class=\"language-text\">rbp</code> register in the Memory window’s address bar to inspect memory.</p>\n<p>The value stored there appears to be <code class=\"language-text\">0x7FF6964513DA</code> (note: read in reverse, as values are stored in little-endian format).</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 554px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/1cabcf6604be115fac70bf2636e0bf95/04abd/image-41.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 43.75%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAABxElEQVQoz4WR227TUBBF/ZfwEMoP8FXwALS0FImXEtFULUkaJ67tXJo0vh1fjh07tFVVhFRouxgnEeIBhKWlPT6zZ86Mbez3Y3YHmp2+5l0/F83Y7qf/x/yTTY2o8WI/pvE65Okrjycv5zTehDS2Axpv/84zyW3thGxtK9FINNrEIc9Fje8319zdXvPtquT2soT7O+Dnhvu1Pm54+CHvD/z7ecRwXYe80ASBT7WsWH5dUhQFVVVRlguSJBEUl8uFUHJztWSRp+gkIlYhi7KgrEqpq/ADmfBzq4NpjWh3LSx7ypk748yZYjkzYYo5kFzP5aB3wSfTo9n3+die8OF4RLPtSs1kVWMPL+j1xxjNwzY9KTrpWNJ4Qtd0aZ/aa7o2nZ7Dcdfh/ZHD3pHLbstlr1XHQw5OHLo9my+nzsp32DIxbNsi1ymz2TlFrkmTmDD0iaLgN/VqeaqEiCyOyGVdHcu5+JTaeOR85MqEA8sijELG4xFJmkkywvN8fH9NHYehNMo0mdbiSVcaRor5fL769p74giDAHZ5jjKRRnudS7KF1TiZNlVKoWMlk8Yr6x2RZRirNaq+uN0kTlFwex7F4157p1OMXnoZz0M48/4oAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/1cabcf6604be115fac70bf2636e0bf95/8ac56/image-41.webp 240w,\n/static/1cabcf6604be115fac70bf2636e0bf95/d3be9/image-41.webp 480w,\n/static/1cabcf6604be115fac70bf2636e0bf95/5e3e0/image-41.webp 554w\"\n              sizes=\"(max-width: 554px) 100vw, 554px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/1cabcf6604be115fac70bf2636e0bf95/8ff5a/image-41.png 240w,\n/static/1cabcf6604be115fac70bf2636e0bf95/e85cb/image-41.png 480w,\n/static/1cabcf6604be115fac70bf2636e0bf95/04abd/image-41.png 554w\"\n            sizes=\"(max-width: 554px) 100vw, 554px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/1cabcf6604be115fac70bf2636e0bf95/04abd/image-41.png\"\n            alt=\"image-41.png\"\n            title=\"image-41.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Checking this address in the Disassembly window confirms it is the address of the instruction to be executed after the <code class=\"language-text\">main</code> function completes and returns.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/40941ec5ef1fd3456d2071540c9f93f0/75609/image-42.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 60%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAAsTAAALEwEAmpwYAAACRElEQVQoz3WSC2/TMBSF8++RgDHBj+BXoGkPNCQYg3bL2qRJ0yTOY3nYead5NIfrbFDEhKVP17Gdo3OPrXz8yvDhiuHVJxtvzz2cXPh4febSnOHNmY2TcwfvLhycXjK8/+zP9fTSw+mFhL2oimntoBkW1qYN3XLgxwLtCCT5iCguENopgl2K0OEooj26fEJXEwdifImiaxo2ug5ru4WhaxCcQ45M9GjKBrEXoc1q1LxCKxqgo0368X9D0UhQom82s2ieF/NGmvaosxZ1WAMlLcjlHJj4hKkgOmJPkNNpOjILzi43BjzPQ9vuMQw9EhJs8hbZLsPe36MPe0wpORMkHD0TS7f/ONSpXcmW3FnWFqqqIssycnpALmSGAWI/RsxiJF4C7nPwhMgIkSKO45kkSVBW5VOGuqbDMMy5ddt20HV7iGxAXTQISDB0Q8RuDB6QiMchEgEhBMVyFJQmuq6DYlB2hmHMQjJDlzGM44iScqvrBsxj8AMfj9EjsjwjVyTKU6RcVj47i6Loj6iyXCxwc3ODxXKJH7e3uL7+gjAM4NAz8cmduTBh3Vswf5rQv+vQvq2hqRrWz9k/qA9YrVZYr9dkyoai3t9jSWJ3VOUB2bogF0FY0pNJEKx8BGoAducRDM7SAVtQXbhw71w4W4e6ornLqKvfGc6XYtGlSHZ0/Qdq74CuGFDZJVrWonEa1Lsa1bZC5RFJhTqh77KahaqqOmZomubsTObAuUDfd1QHFEUJXnB6GSOGw3Bk/IthoPM9+uFp/gstOXoteJ6MiAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/40941ec5ef1fd3456d2071540c9f93f0/8ac56/image-42.webp 240w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/d3be9/image-42.webp 480w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/e46b2/image-42.webp 960w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/fd213/image-42.webp 994w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/40941ec5ef1fd3456d2071540c9f93f0/8ff5a/image-42.png 240w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/e85cb/image-42.png 480w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/d9199/image-42.png 960w,\n/static/40941ec5ef1fd3456d2071540c9f93f0/75609/image-42.png 994w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/40941ec5ef1fd3456d2071540c9f93f0/d9199/image-42.png\"\n            alt=\"image-42.png\"\n            title=\"image-42.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Next, to find the address that will be called after <code class=\"language-text\">ret_func</code> finishes, inspect the value of the <code class=\"language-text\">rsp</code> register at the moment the function was called.</p>\n<p>From the register information, the stack pointer address is <code class=\"language-text\">0xa74d0ffd58</code>, so let’s check the Memory window.</p>\n<p>The value stored there appears to be <code class=\"language-text\">0x7FF6964514B7</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 450px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/edbc69403a43689b53084056d7218281/fc2a6/image-43.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 108.74999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAWCAYAAADAQbwGAAAACXBIWXMAAAsTAAALEwEAmpwYAAAD3ElEQVQ4y3VVa3eiWBDk//+j7J7MZI3GGAXkJU9BBBSfM2bPJJqTpKa6Mbv7ZT/0udzm0l3VXX0xoihFmhZYt3vsdkdstwfaUW2z2WO72dH2/7Gd+luel/XfM50Zm80Wx+NPnJ7/xo8fJ5xOz7qK/fr1itfX8//ay8sZl/Mb3t5ol84YcEM0WxwOByzLJZqmQVVVWFY1P3jpDl/tcvmyCy7cn89nvL+/4+PjA5+fn2qG53qYjCcoigU810WSZJqgXBT0lRq8rmtdkyRBkqZMXCLLMt3P5zkWi5JrhjzPYURhCJeB6rpBEsca+LDfX5HWkJJsyWK322G5XKKktes11rS6rrDiulqt+K7U88bjcIjb22/MlmL0OMTU8dAQUcrsMX3iLxcLNi7RxJ7vIwjEAkynU/hcffp8z8NsFsKIowgeN0IriSNCL9iko6JomHm1WrOjrSIqSXVJ6pJQkghFoat+IleE5sREvz9AzlrYlskskX6csyYZfUVRKP0F1xnLE8UJfTkRp4gJIJvP9TkisDTNYMxmM0J3NEPI5zTLsWNTqmrJ+rSKvOValouuAUSzYoKmqVET7Zrv2k2rKEuqxLAtCw8PQ22Gy5qEUYwNKRb5HMWVjiJk18Mw0i4L3YVQJjopgVCP2dAsm8OwrgHnV8qeF7CzrVLOKRtJJAGjKGQjZkgoF6EvpZCAIif5VnqhAZWy7eiLmB9JV0Uispcii3UUGw1SEJkKnyUq8kJLIM8LJpbVGD+N0Ov1CHsOczKiNDzqbk3ZsMhZyqykWBZI2YAZ5ZIkMZpKAsyJMNXatu0KGWUlOjbsaYDB0ILjJRibnBozgOtnsJ0IUy+jpXADJrNDjK0ZzKn4Ez3jXN85fqrvw5iT8sBgN3/20RvYuP0+xLe7JwyffPzFff/RwwOfh08B7u5NfKfd9S09ez900B+6POPTXNz1JgShwg7ZCJftJ+wk0gI/n35SKg2bs2Y9NzgetljVSx0vkUu7rrFe1UpVGrjbbnQvgv9H2F2XrW702AARuvhErAVlIdIIKewZpSMilmeZsIDjJiMnd4I01JB5HI2e+EEBZ2rDYcBWddiNlfiXZafHr9tGGvU1HbKX54wmAIyAg22ZFulUOilyIcjtooeoM0Emo5ZpINFmp0Ex8UnCbp9T8CWMyWSC/v1AD5uTMWzb1etIEslkCDWZAtGr3DBh1FEWk1tG9l8+pSw0fD/QIEJFMh4Oe80mqLsLtrrOanfb1FXnl/H7OtOda2AM+n3c3PyhaB4GfYwnlv4KLNPUS8NxHFWBbVuwtGkuxe/Apd+UM053RvYC7DdDEyxIDRyupgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/edbc69403a43689b53084056d7218281/8ac56/image-43.webp 240w,\n/static/edbc69403a43689b53084056d7218281/8626f/image-43.webp 450w\"\n              sizes=\"(max-width: 450px) 100vw, 450px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/edbc69403a43689b53084056d7218281/8ff5a/image-43.png 240w,\n/static/edbc69403a43689b53084056d7218281/fc2a6/image-43.png 450w\"\n            sizes=\"(max-width: 450px) 100vw, 450px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/edbc69403a43689b53084056d7218281/fc2a6/image-43.png\"\n            alt=\"image-43.png\"\n            title=\"image-43.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Checking the Disassembly window again confirms this is the address of the instruction scheduled to be called after <code class=\"language-text\">ret_func</code> finishes.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 840px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/859de4dce43eae51c0392542e57f1b70/1e088/image-44.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 35%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsTAAALEwEAmpwYAAABaUlEQVQoz42PXXOaUBRF+f+/p51MpzNJbBILlqo1RiNcvm5BiFIxQEFFWL2R9LXTfWbNPnPOy95atBKMP31G/3iF/uGK5fUA+8sQe3CPb0yQ5hRHNxAPQ8TdEF8fIb+ZBCMT+YbeE7y7tpjNmZnfmY8nLKY/mHzVCSxBU+SsvZQ0TImWDnIp+BXEVOGe6mdGHSmP99R7RdZTKTTPdZHSJwg8wijE8Tws4dCpKSs4HKFIC/ZJzm6dUaYVTd5y2B055Wf1P3FsGuVHmrZFM8aPXBszbhQPozGD21tMlThNN9h2gu8mbB4TQiNUlQJV2UfeS5wbB//Ox525eCqE46gWUqLNlxaTJ4vpwubp2cK2LF5eNhwOFXGcs92+Ertrtv6WclNSxAVFpEiKfs8VpaLo0azVCmFbCGuFDAKqquavdrsz1e+G1yLjRMP/SLNtW1UTCCFUovhy7Lru4ll2oq4b2vO5v7fd5fcv/gDlFAXQng7N7gAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/859de4dce43eae51c0392542e57f1b70/8ac56/image-44.webp 240w,\n/static/859de4dce43eae51c0392542e57f1b70/d3be9/image-44.webp 480w,\n/static/859de4dce43eae51c0392542e57f1b70/ed60d/image-44.webp 840w\"\n              sizes=\"(max-width: 840px) 100vw, 840px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/859de4dce43eae51c0392542e57f1b70/8ff5a/image-44.png 240w,\n/static/859de4dce43eae51c0392542e57f1b70/e85cb/image-44.png 480w,\n/static/859de4dce43eae51c0392542e57f1b70/1e088/image-44.png 840w\"\n            sizes=\"(max-width: 840px) 100vw, 840px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/859de4dce43eae51c0392542e57f1b70/1e088/image-44.png\"\n            alt=\"image-44.png\"\n            title=\"image-44.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"tampering-with-memory\" style=\"position:relative;\"><a href=\"#tampering-with-memory\" aria-label=\"tampering with memory permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tampering with Memory</h2>\n<p>Finally, I’ll tamper with the memory at the address pointed to by the <code class=\"language-text\">rsp</code> register — the address to jump to after <code class=\"language-text\">ret_func</code> returns — and make an arbitrary function execute.</p>\n<p>In WinDbg, you can tamper with memory by directly editing values in the Memory window. (WinDbg must be launched with administrator privileges.)</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/memory-window\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Viewing and Editing Memory in WinDbg - Windows drivers | Microsoft Docs</a></p>\n<p>Note: in the version of WinDbg Preview I’m using, editing values directly from the Memory window did not work. (It did work in WinDbg X64 included with Windows Debug Tools, so this may be a limitation or a bug in the Preview version.)</p>\n<p>Therefore, I’ll use the <code class=\"language-text\">e</code> command instead of the Memory window to tamper with the memory.</p>\n<p>Reference: <a href=\"https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/e--ea--eb--ed--ed--ef--ep--eq--eu--ew--eza--ezu--enter-values-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">e, ea, eb, ed, eD, ef, ep, eq, eu, ew, eza (Enter Values) - Windows drivers | Microsoft Docs</a></p>\n<p>The address I want to modify is <code class=\"language-text\">0x000000150acffb58</code>, the address currently pointed to by the <code class=\"language-text\">rsp</code> register.</p>\n<p>I’ll change the value at that address to the call address of the <code class=\"language-text\">ret_func</code> function so that <code class=\"language-text\">ret_func</code> is called one more time.</p>\n<p>The call address of <code class=\"language-text\">ret_func</code> is <code class=\"language-text\">0x00007ff7 81df1470</code>.</p>\n<p>The following command tampers with the memory in one shot. (Values are entered in reverse because of little-endian notation.)</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">eb 000000150acffb58 0x70 0x14 0xdf 0x81 0xf7 0x7f 0x00 0x00</code></pre></div>\n<p>After running the command, the memory was successfully overwritten!</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 470px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/1457b24c4c4f8accce704bebb69e8587/f96db/image-45.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 97.50000000000001%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAACzElEQVQ4y4VU2XLbMAzU//9aJo2P2JmJ60OOrYMiKcmy5COWUexKcj3tTPuwAx4guMASDBaLlez2iThXirMF4V0hNvOSGfc3sh46NsYrhrnVM06CLLNSlpV4n2tQTxiTSV038v39Ldfr9Qk6v1zlojifL7rfyu0G3KRtW/oHy+VSkiSR7TaU9XolYRjKZrORNE31olLyvJCiKDkuikIOh4NeVnN8Op00+IXA2v0uEnzM5wyY57kySzVlz02MjQYF2yzLeAH8kBGCWWs1K89zmBtj5KYsydBaxw3v1Wrqx+ORTAZbVRXXEQCHMS/LQ8f2WKtfxfW2vUvw/j7lzc5ZZdQxqOujBvB6COnmtNaCqSGzPPdSaTDvHP1ABOdbzTl4GS3lY7GX0ftGpvOtTGahvLz9lLfpmhgpXsdL+TFZyWQeylj34fs6XtE+ozzUGvB1KtuvvXztYgm3O0UkSWplH6USKbAO7BTbr4jAPI6N2kSfXExg7aKvIAjDDVNAPYrcU83L+cy0GxWnqrpa1gqkjvpxr6m7dR2jhvC7I+XZbKY1TFkbKOVUIDg61wkFhTEGoDT8IMCgMKzDWfWjKIvFgkIMh62Om6ZhABzGC4DFRZ4CDCJ08G4Y+06Uz89PBoIjlMTBqk8B6QO4oGNtH0EZ5ElhzBlwPp8xFSzgMWdkWEupz6XouwMBUTuUBPtWCZjMkAiAdYApb9Zr0sVBiIMH3LVW/mg3BMO7w5htSPsELVeOhw2G4/FIn0fEm6JoT4HgFMexjuPeJg8gmzT9c9z5kCGeDVuqLCgMWLFT0KO4ue/V3/gPw+l0IrFGhyDdTd0vg9sNGfQfRF8nk3UtONSN6/AbaogvC4LgJqgFRlCU76xXNO+ZDij+mFN5tQ+GURTztpSfQ8bgrNFT3Qa2KZn142EdfmrJEEXH74yn0bXU6fFhovVom+bfgJ9atN4vRkDkIouePKcAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/1457b24c4c4f8accce704bebb69e8587/8ac56/image-45.webp 240w,\n/static/1457b24c4c4f8accce704bebb69e8587/4424c/image-45.webp 470w\"\n              sizes=\"(max-width: 470px) 100vw, 470px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/1457b24c4c4f8accce704bebb69e8587/8ff5a/image-45.png 240w,\n/static/1457b24c4c4f8accce704bebb69e8587/f96db/image-45.png 470w\"\n            sizes=\"(max-width: 470px) 100vw, 470px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/1457b24c4c4f8accce704bebb69e8587/f96db/image-45.png\"\n            alt=\"image-45.png\"\n            title=\"image-45.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Resuming execution with the <code class=\"language-text\">g</code> command, <code class=\"language-text\">ret_func</code> was called again after its first execution ended, and the text <code class=\"language-text\">Call ret_func</code> — which would normally appear only once — was printed twice.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/2e8be04956866299fe714ccb045afd39/0b533/image-46.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 50%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAARlAAAEZQAGA43XUAAAAtUlEQVQoz7WTWwqDMBBFJxHsjxAfGIkg/qjVbqIP0JKswLr/fdzGtKUUCgW1H4dJCDlMuBM6nS/ougPatkXT7FHXNcqyhFIKeZ7b+puiKJAkCcbxBlL20s73QUSr6fsrKI5jt2GMW9giPM9zjmE4goQQqzvjnLtqdA8Kw3AzodZma6H+gzCKomcobLHwFYox9slBEGwyMo+UB1BVVW4opZRI0/Qr81mWZR9I+V7Pn2BubJom3AHwb93Jg1cUsQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/2e8be04956866299fe714ccb045afd39/8ac56/image-46.webp 240w,\n/static/2e8be04956866299fe714ccb045afd39/d3be9/image-46.webp 480w,\n/static/2e8be04956866299fe714ccb045afd39/b0a15/image-46.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/2e8be04956866299fe714ccb045afd39/8ff5a/image-46.png 240w,\n/static/2e8be04956866299fe714ccb045afd39/e85cb/image-46.png 480w,\n/static/2e8be04956866299fe714ccb045afd39/0b533/image-46.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/2e8be04956866299fe714ccb045afd39/0b533/image-46.png\"\n            alt=\"image-46.png\"\n            title=\"image-46.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"wrap-up\" style=\"position:relative;\"><a href=\"#wrap-up\" aria-label=\"wrap up permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Wrap-up</h2>\n<p>In this article, I introduced how to inspect and tamper with memory using WinDbg.</p>\n<p>For other articles on Windows debugging and dump analysis with WinDbg, see the list on the following page:</p>\n<p>Reference: <a href=\"/windows-windbg-001-index-en\">Debugging and Troubleshooting Techniques with WinDbg</a></p>","fields":{"slug":"/windows-windbg-007-memory-spoofing-en","tagSlugs":["/tag/win-dbg-en/","/tag/kernel-en/","/tag/reversing-en/","/tag/english/"]},"frontmatter":{"date":"2021-10-18","description":"","tags":["WinDbg (en)","Kernel (en)","Reversing (en)","English"],"title":"Overwriting the Memory Pointed to by the Stack Pointer in WinDbg to Execute an Arbitrary Function","socialImage":{"publicURL":"/static/d0c4232665b4646dc19e54bd760ebe95/windows-windbg-007-memory-spoofing.png"}}}},"pageContext":{"slug":"/windows-windbg-007-memory-spoofing-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}