将 Go 将二进制文件反编译成汇编代码,同时打印 Go 源码。
go tool objdump usage: go tool objdump [-S] [-gnu] [-s symregexp] binary [start end] -S print Go code alongside assembly -gnu print GNU assembly next to Go assembly (where supported) -s string only dump symbols matching this regexp
通常用法
go tool objdump -S -s "main.fun1" main
-S:打印在旁边 Go 源码。
-s :可选,匹配要打印的具体片段,支持正则表达式。
main:可执行文件的编译。
package main func main() {
example(make([]string, 2, 4), "hello", 10) } func example(slice []string, str string, i int) {
panic("Want stack trace") }
go build main64.go go tool objdump -S -s "main.main" main64.exe TEXT main.main(SB) D:/dev/php/magook/trunk/server/golang/project/demo1/main64.go func main() {
0x459ec0 493b6610 CMPQ 0x10(R14), SP 0x459ec4 7622 JBE 0x459ee8 0x459ec6 4883ec18 SUBQ $0x18, SP 0x459eca 48896c2410 MOVQ BP, 0x10(SP) 0x459ecf 488d6c2410 LEAQ 0x10(SP), BP example(make([]string, 2, 4), "hello", 10) 0x459ed4 488d0565460000 LEAQ type.* 17728(SB), AX panic("Want stack trace") 0x459edb 488d1dae260200 LEAQ runtime.buildVersion.str+16(SB), BX
0x459ee2 e8b943fdff CALL runtime.gopanic(SB)
0x459ee7 90 NOPL
func main() {
0x459ee8 e85387ffff CALL runtime.morestack_noctxt.abi0(SB)
0x459eed ebd1 JMP main.main(SB)