douyuan5600 2017-02-13 17:09
浏览 62
已采纳

如何通过go程序未分配的fmt.Println()内存?

I’d like to print the virtual memory content of the current program from 0x10000 to 0x50000 (an area containing a syscall trampoline on my system).

package main

import (
    "syscall"
    "unsafe"
)
func main() {
    syscall.Syscall(SYS_WRITE, uintptr(1), uintptr(unsafe.Pointer(0x10000)), uintptr(0x40000))
}

However when I tried to compile I’m getting that error :

cannot convert 65536 (type int) to type unsafe.Pointer

In my case,cgo is disabled (import "C" fails at compile time).
Also does syscall.Syscall(SYS_WRITE is the only way to do it ?

  • 写回答

2条回答 默认 最新

  • doulin9679 2017-02-13 17:42
    关注

    You can convert that address to a slice of bytes, which can then be passed to any Write method.

    To convert the address 0x10000 to a slice of bytes with a length of 0x30000, you would use

    mem := (*[1 << 30]byte)(unsafe.Pointer(uintptr(0x10000)))[:0x30000:0x30000]
    

    If the size is always static, you could just set the array to the proper size to start

    mem := (*[0x30000]byte)(unsafe.Pointer(uintptr(0x10000)))[:]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)