-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpeutils.go
57 lines (52 loc) · 1.66 KB
/
peutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
peparser "github.com/saferwall/pe"
)
func LocateRCDataEnd(pe_path string) int64 {
pe, err := peparser.New(pe_path, &peparser.Options{
Fast: false,
SectionEntropy: false,
DisableCertValidation: true,
DisableSignatureValidation: true,
OmitExportDirectory: true,
OmitResourceDirectory: false,
OmitSecurityDirectory: true,
OmitRelocDirectory: true,
OmitDebugDirectory: true,
OmitArchitectureDirectory: true,
OmitGlobalPtrDirectory: true,
OmitTLSDirectory: true,
OmitLoadConfigDirectory: true,
OmitBoundImportDirectory: true,
OmitIATDirectory: true,
OmitDelayImportDirectory: true,
OmitCLRHeaderDirectory: true,
})
if err != nil {
fmt.Println("[!] Error while opening file!")
return -1
}
defer pe.Close()
if err = pe.Parse(); err != nil {
fmt.Println("[!] Error while parsing file!")
return -1
}
// https://github.com/Nuitka/Nuitka/blob/b4ae0b6701533c22be732837db49ce5b5f5a90ce/nuitka/build/static_src/OnefileBootstrap.c#L216
if pe.HasResource {
for _, entry := range pe.Resources.Entries {
if entry.ID == peparser.RTRCdata &&
entry.IsResourceDir &&
len(entry.Directory.Entries) == 1 &&
entry.Directory.Entries[0].ID == 27 {
rcdataEntry := entry.Directory.Entries[0]
if rcdataEntry.IsResourceDir &&
len(rcdataEntry.Directory.Entries) == 1 &&
!rcdataEntry.Directory.Entries[0].IsResourceDir {
return int64(pe.GetOffsetFromRva(rcdataEntry.Directory.Entries[0].Data.Struct.OffsetToData) + rcdataEntry.Directory.Entries[0].Data.Struct.Size)
}
}
}
}
return -1
}