<p>Link: <a href="https://github.com/EricLagergren/patch">https://github.com/EricLagergren/patch</a></p>
<p>Test file: <a href="https://gist.github.com/EricLagergren/933e43282a62174ccdf5">https://gist.github.com/EricLagergren/933e43282a62174ccdf5</a></p>
<p>I saw that MS post the other day about the compiler adding
<code>mov %edi, %edi</code> so it could hot patch the code to jump back to another, longer jump to another function.</p>
<p>So, I got bored and tried doing the same with Go.</p>
<p>It's pretty simple. Just compile a shared object file and find where in the file the function you want to use as the patch starts. Then, when your binary is running, edit the mmapped memory where the function you want to replace is (the actual running binary) with jump instructions to the address of the function inside the mmaped shared object code.</p>
<p>It's not exactly the same as how MS does it (since I haven't fiddled with the compiler yet) but it essentially does the same thing.</p>
<p>Also, fwiw the above code is machine-specific. (I have an x86_64 Linux 4.4 box.) It's just a fun little exercise.</p>
<hr/>**评论:**<br/><br/>sinatosk: <pre><p>your code at <a href="https://github.com/EricLagergren/proc">https://github.com/EricLagergren/proc</a> is out of sync with what you have</p>
<p>on line 39 at <a href="https://github.com/EricLagergren/patch/blob/master/patch.go">https://github.com/EricLagergren/patch/blob/master/patch.go</a> your using doing</p>
<p>m, ok := proc.Find(fnAddr)</p>
<p>but cannot see the function "Find" in your proc package anywhere at <a href="https://github.com/EricLagergren/proc">https://github.com/EricLagergren/proc</a> including looking at all your commits</p></pre>barsonme: <pre><p>I forgot to push my changes to the proc package to GitHub. I'll go do so
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传