2022.6.8: go version go1.18.3 windows/amd64 高版本适用 1.20
搜索 go.build 查找交叉引用
go.build 在新版本中一定位于 函数名称的第一个。
https://go.dev/src/runtime/symtab.go 阅读源码,获取 moduledata 结构
pclntable 一般等于 ftab, 参照上图, ftab 与 pclntable 填充的是 pclntable 的值。
funcnametab 填充的是 函数名称 filetab 填充的是 文件名称
与函数名称相关的是 ftab 和 pclntable
适用于下面的结构体
entryoff 为 以代码段为起始位置 的偏移。表示该函数实际的位置。 代码段在windows为 text
funcoff 为 以 pclntable 为起始位置的偏移。
对应着一个 funcInfo 结构体, 里面包含一个 _func 类型,该类型中有我们想要的信息。
意思就是: func 的 _func = pclntable + funcOff 通过上图的信息计算:
发现刚好可以对得上信息
第一个函数 go.build
第二个函数 internal_cpu_Initialize
知道了这些就可以编写简单的脚本来还原go符号名了
ida python 脚本
其中 moduledata_addr 需要手动填充。
还原效果
https://github.com/Abyss-emmm/goparse 跳跳糖
/
/
pcHeader holds data used by the pclntab lookups.
type
pcHeader struct {
magic uint32
/
/
0xFFFFFFF0
pad1, pad2 uint8
/
/
0
,
0
minLC uint8
/
/
min
instruction size
ptrSize uint8
/
/
size of a ptr
in
bytes
nfunc
int
/
/
number of functions
in
the module
nfiles uint
/
/
number of entries
in
the
file
tab
textStart uintptr
/
/
base
for
function entry PC offsets
in
this module, equal to moduledata.text
funcnameOffset uintptr
/
/
offset to the funcnametab variable
from
pcHeader
cuOffset uintptr
/
/
offset to the cutab variable
from
pcHeader
filetabOffset uintptr
/
/
offset to the filetab variable
from
pcHeader
pctabOffset uintptr
/
/
offset to the pctab variable
from
pcHeader
pclnOffset uintptr
/
/
offset to the pclntab variable
from
pcHeader
}
type
moduledata struct {
pcHeader
*
pcHeader
funcnametab []byte
cutab []uint32
filetab []byte
pctab []byte
pclntable []byte
ftab []functab
findfunctab uintptr
minpc, maxpc uintptr
text, etext uintptr
noptrdata, enoptrdata uintptr
data, edata uintptr
bss, ebss uintptr
noptrbss, enoptrbss uintptr
end, gcdata, gcbss uintptr
types, etypes uintptr
rodata uintptr
gofunc uintptr
/
/
go.func.
*
textsectmap []textsect
typelinks []int32
/
/
offsets
from
types
itablinks []
*
itab
ptab []ptabEntry
pluginpath string
pkghashes []modulehash
modulename string
modulehashes []modulehash
hasmain uint8
/
/
1
if
module contains the main function,
0
otherwise
gcdatamask, gcbssmask bitvector
typemap
map
[typeOff]
*
_type
/
/
offset to
*
_rtype
in
previous module
bad
bool
/
/
module failed to load
and
should be ignored
next
*
moduledata
}
/
/
pcHeader holds data used by the pclntab lookups.
type
pcHeader struct {
magic uint32
/
/
0xFFFFFFF0
pad1, pad2 uint8
/
/
0
,
0
minLC uint8
/
/
min
instruction size
ptrSize uint8
/
/
size of a ptr
in
bytes
nfunc
int
/
/
number of functions
in
the module
nfiles uint
/
/
number of entries
in
the
file
tab
textStart uintptr
/
/
base
for
function entry PC offsets
in
this module, equal to moduledata.text
funcnameOffset uintptr
/
/
offset to the funcnametab variable
from
pcHeader
cuOffset uintptr
/
/
offset to the cutab variable
from
pcHeader
filetabOffset uintptr
/
/
offset to the filetab variable
from
pcHeader
pctabOffset uintptr
/
/
offset to the pctab variable
from
pcHeader
pclnOffset uintptr
/
/
offset to the pclntab variable
from
pcHeader
}
type
moduledata struct {
pcHeader
*
pcHeader
funcnametab []byte
cutab []uint32
filetab []byte
pctab []byte
pclntable []byte
ftab []functab
findfunctab uintptr
minpc, maxpc uintptr
text, etext uintptr
noptrdata, enoptrdata uintptr
data, edata uintptr
bss, ebss uintptr
noptrbss, enoptrbss uintptr
end, gcdata, gcbss uintptr
types, etypes uintptr
rodata uintptr
gofunc uintptr
/
/
go.func.
*
textsectmap []textsect
typelinks []int32
/
/
offsets
from
types
itablinks []
*
itab
ptab []ptabEntry
pluginpath string
pkghashes []modulehash
modulename string
modulehashes []modulehash
hasmain uint8
/
/
1
if
module contains the main function,
0
otherwise
gcdatamask, gcbssmask bitvector
typemap
map
[typeOff]
*
_type
/
/
offset to
*
_rtype
in
previous module
bad
bool
/
/
module failed to load
and
should be ignored
next
*
moduledata
}
type
functab struct {
entryoff uint32
/
/
relative to runtime.text
funcoff uint32
}
type
functab struct {
entryoff uint32
/
/
relative to runtime.text
funcoff uint32
}
/
/
src\runtime\symtab.go
type
functab struct {
entry uintptr
funcoff uintptr
}
type
funcInfo struct {
*
_func
datap
*
moduledata
}
/
/
src\runtime\runtime2.go
type
_func struct {
entry uintptr
/
/
start pc
nameoff int32
/
/
function name
args int32
/
/
in
/
out args size
deferreturn uint32
/
/
offset of start of a deferreturn call instruction
from
entry,
if
any
.
pcsp uint32
pcfile uint32
pcln uint32
npcdata uint32
cuOffset uint32
/
/
runtime.cutab offset of this function's CU
funcID funcID
/
/
set
for
certain special runtime functions
_ [
2
]byte
/
/
pad
nfuncdata uint8
/
/
must be last
}
/
/
src\runtime\symtab.go
type
functab struct {
entry uintptr
funcoff uintptr
}
type
funcInfo struct {
*
_func
datap
*
moduledata
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
最后于 2023-6-5 17:07
被mingyuexc编辑
,原因: