我可以使用”Go dlv exec ./go-server”来反编译所有的Go代码吗?

huangapple go评论78阅读模式
英文:

Can I use Go dlv exec ./go-server to decompile all go code?

问题

假设一个go-server文件是在Windows系统上使用Linux操作系统编译的,我可以使用"Go dlv exec ./go-server"来反编译所有的Go代码吗?

当我尝试设置断点时,我得到了下面的消息,但它没有打印代码,有没有其他方法可以反编译它,除了使用"IDA",因为它太贵了。

(dlv) b main.main
在 main.main() 函数的 E:/Code/GoCode/go-server/main.go 文件的第10行设置断点
(dlv) c
> main.main() D:/Go/main.go:10 (命中 goroutine(1):1 总共:1) (PC: 0x845ecf)
警告: 调试优化函数
(dlv) n
> main.main() D:/Go/main.go:11 (PC: 0x845ee6)
警告: 调试优化函数
(dlv) n
配置文件: ./dev.json 加载成功!
> main.main() D:/Go/main.go:12 (PC: 0x845f00)
警告: 调试优化函数
英文:

Supposed a go-server file was compiled by Windows system with linux OS, and Can I use Go dlv exec ./go-server to decompile all go code?

When I try to break some points, I got below message, but it didn't print the code, is there any way to decompile it except for IDA, cause it's too expensive to but it.

(dlv) b main.main
Breakpoint 1 set at 0x845ecf for main.main() E:/Code/GoCode/go-server/main.go:10
(dlv) c
> main.main() D:/Go/main.go:10 (hits goroutine(1):1 total:1) (PC: 0x845ecf)
Warning: debugging optimized function
(dlv) n
> main.main() D:/Go/main.go:11 (PC: 0x845ee6)
Warning: debugging optimized function
(dlv) n
Config file: ./dev.json Load success!
> main.main() D:/Go/main.go:12 (PC: 0x845f00)
Warning: debugging optimized function

答案1

得分: 1

不,dlv没有反编译器,尽管Go在运行时比C或C++有更多关于程序的元数据,但很难还原编译过程,使用反编译器得到的源代码与原始程序相似的可能性很小。

我认为你在问的是是否可以使用来自另一台主机的源代码清单进行调试,注意通常调试器不会反编译程序(除非它们用于没有源代码的调试,比如IDA),而是编译器会为每个指令创建元数据,其中包含对原始源代码文件及其行的引用,然后调试器可以加载这个源代码文件并构建其特性,比如源代码级别的步进。你需要将所有源代码复制到Linux机器上的某个文件系统位置,并配置dlv以知道如何定位这些源代码:

config substitute-path E:/Code/GoCode/go-server/ /home/user/somewhere/

请记住,你需要保持可执行文件与其编译时使用的原始源代码同步,否则调试器可能显示错误的行偏移量。

英文:

No, dlv does not have a decompiler, although Go has much more metadata about the program at runtime in comparison with C or C++ it's very hard to revert the compilation process, it's unlikely you will end up with anything alike the original program in source code from a decompiler.

I think what you're questioning is that if you can debug with source code listing from another host, note that usually debuggers do not decompile the program (unless they're meant for debugging without source code, like IDA), instead compilers create metadata with references for each instruction to the original source code file along with its lines, then debuggers can load this source code file and build its features like source code level stepping from there, what you need is to copy all the source code to your Linux machine somewhere on its file system, and configure dlv to know how to locate this source code:

config substitute-path E:/Code/GoCode/go-server/ /home/user/somewhere/

Keep in mind that you need to maintain the executable in sync with the original source code it was compiled with, otherwise the debugger may display wrong line offsets

huangapple
  • 本文由 发表于 2022年6月24日 23:23:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/72746241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定