How do I get the underlying value on a unsafe.Pointer?

agolangf · · 698 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>This is what I have for code</p> <pre><code>jesus = unsafe.Pointer(uintptr(jesus) + 0xAADDEC) //shifting a memory address w/ pointer arithmetic fmt.Println(*jesus) </code></pre> <p>and this is my error</p> <pre><code>.\main.go:118:14: invalid indirect of jesus (type unsafe.Pointer) </code></pre> <p>What gives, man? I need that juicy value it is pointing to (It&#39;s a memory address)</p> <hr/>**评论:**<br/><br/>NoEffex: <pre><p>You need to cast the <code>unsafe.Pointer</code> to a pointer to the type you want then deference it. Here&#39;s an example of getting the second element in an array by pointer arithmetic</p> <pre><code>var ints = [42]int{1, 2, 3, 4, 5} firstPtr := uintptr(unsafe.Pointer(&amp;ints)) size := unsafe.Sizeof(ints[0]) secondPtr := firstPtr + size // do pointer arithmetic // cast to pointer to data type you want then derference to get value secondValue := *(*int)(unsafe.Pointer(secondPtr)) fmt.Println(secondValue) //Prints &#34;2&#34; </code></pre></pre>exch: <pre><p>if <code>ints</code> is a slice instead of an array, one should use <code>unsafe.Pointer(&amp;ints[0])</code> instead (provided <code>ints</code> is not empty).</p></pre>69beards: <pre><p>How do I dereference a pointer that is outside of my Golang program?</p> <p>I might be asking the wrong question because what I am trying to do in, &#34;pseudo-code&#34;, is:</p> <pre><code>var myPointer = 0x0000CB5 //a pointer to a DLL outside of my Golang program var firstOffset = myPointer + 0x0A //shift to a localPlayer &#34;chapter&#34; in the DLL var deReferencedMemoryAddress = *myPointer //this causes an nil pointer error code (0x0000005) when fmt.println&#39;d var secondOffset = dereferencedMemoryAddress + 0xFC //offsetting a second time to get localPlayer&#39;s Health, cannot get to this point w32.ReadProccessMemory(secondOffset,gamePID) // cannot get this point </code></pre> <p>So I think what I am doing now is not making a pointer to this DLL in another proccess (not my goprogram proccess)</p> <p>Is there anything I can do?</p> <p>EDIT: Here is some more context <a href="https://i.imgur.com/X3hMKF6.png" rel="nofollow">https://i.imgur.com/X3hMKF6.png</a></p></pre>kostix: <pre><p>Care to elaborate on that</p> <blockquote> <p>a pointer to a DLL outside of my Golang program</p> </blockquote> <p>bit?</p></pre>69beards: <pre><p>The DLL I am looking to get the memory address of is of one inside the proccess csgo.exe</p> <p>I have elaborated my whole issue by comments in this pastebin.com link. <a href="https://pastebin.com/zdEz7VKe" rel="nofollow">https://pastebin.com/zdEz7VKe</a></p> <p>The English language cannot express my appreciation for you taking your time with me. edit: changed pastebin link</p></pre>kostix: <pre><p>I might misunderstand the approach, but the address spaces of separate processes are fully virtualized; I mean, each process gets some 0x0..0x7fffffffff (or so, 48 bit) address space and the address 0xdeadbeef in a process A has no bearing on the memory at the same address in a process B.</p> <p>I, for one, know of no possibility to somehow programmatically access the address space of B from A—except unless both of them explicitly use some sort of shared memory IPC (such as memory-mapped files etc).</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

698 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传