forked from RIscRIpt/pecoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
optionalheader.go
85 lines (81 loc) · 3.97 KB
/
optionalheader.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package pecoff
import "github.com/RIscRIpt/pecoff/windef"
// OptionalHeader embedds windef.OptionalHeaderCommon, and stores DataDirs.
type OptionalHeader struct {
windef.OptionalHeaderCommon
DataDirs DataDirs
}
// From32 sets values of OptionalHeaderCommon
// from a 32-bit version of an optional header.
func (oh *OptionalHeader) From32(oh32 *windef.OptionalHeader32) {
oh.OptionalHeaderCommon = windef.OptionalHeaderCommon{
Magic: oh32.Magic,
MajorLinkerVersion: oh32.MajorLinkerVersion,
MinorLinkerVersion: oh32.MinorLinkerVersion,
SizeOfCode: oh32.SizeOfCode,
SizeOfInitializedData: oh32.SizeOfInitializedData,
SizeOfUninitializedData: oh32.SizeOfUninitializedData,
AddressOfEntryPoint: oh32.AddressOfEntryPoint,
BaseOfCode: oh32.BaseOfCode,
BaseOfData: oh32.BaseOfData,
ImageBase: uint64(oh32.ImageBase),
SectionAlignment: oh32.SectionAlignment,
FileAlignment: oh32.FileAlignment,
MajorOperatingSystemVersion: oh32.MajorOperatingSystemVersion,
MinorOperatingSystemVersion: oh32.MinorOperatingSystemVersion,
MajorImageVersion: oh32.MajorImageVersion,
MinorImageVersion: oh32.MinorImageVersion,
MajorSubsystemVersion: oh32.MajorSubsystemVersion,
MinorSubsystemVersion: oh32.MinorSubsystemVersion,
Win32VersionValue: oh32.Win32VersionValue,
SizeOfImage: oh32.SizeOfImage,
SizeOfHeaders: oh32.SizeOfHeaders,
CheckSum: oh32.CheckSum,
Subsystem: oh32.Subsystem,
DllCharacteristics: oh32.DllCharacteristics,
SizeOfStackReserve: uint64(oh32.SizeOfStackReserve),
SizeOfStackCommit: uint64(oh32.SizeOfStackCommit),
SizeOfHeapReserve: uint64(oh32.SizeOfHeapReserve),
SizeOfHeapCommit: uint64(oh32.SizeOfHeapCommit),
LoaderFlags: oh32.LoaderFlags,
NumberOfRvaAndSizes: oh32.NumberOfRvaAndSizes,
DataDirectory: oh32.DataDirectory,
}
}
// From64 sets values of OptionalHeaderCommon
// from a 64-bit version of an optional header.
func (oh *OptionalHeader) From64(oh64 *windef.OptionalHeader64) {
oh.OptionalHeaderCommon = windef.OptionalHeaderCommon{
Magic: oh64.Magic,
MajorLinkerVersion: oh64.MajorLinkerVersion,
MinorLinkerVersion: oh64.MinorLinkerVersion,
SizeOfCode: oh64.SizeOfCode,
SizeOfInitializedData: oh64.SizeOfInitializedData,
SizeOfUninitializedData: oh64.SizeOfUninitializedData,
AddressOfEntryPoint: oh64.AddressOfEntryPoint,
BaseOfCode: oh64.BaseOfCode,
BaseOfData: uint32(0),
ImageBase: uint64(oh64.ImageBase),
SectionAlignment: oh64.SectionAlignment,
FileAlignment: oh64.FileAlignment,
MajorOperatingSystemVersion: oh64.MajorOperatingSystemVersion,
MinorOperatingSystemVersion: oh64.MinorOperatingSystemVersion,
MajorImageVersion: oh64.MajorImageVersion,
MinorImageVersion: oh64.MinorImageVersion,
MajorSubsystemVersion: oh64.MajorSubsystemVersion,
MinorSubsystemVersion: oh64.MinorSubsystemVersion,
Win32VersionValue: oh64.Win32VersionValue,
SizeOfImage: oh64.SizeOfImage,
SizeOfHeaders: oh64.SizeOfHeaders,
CheckSum: oh64.CheckSum,
Subsystem: oh64.Subsystem,
DllCharacteristics: oh64.DllCharacteristics,
SizeOfStackReserve: uint64(oh64.SizeOfStackReserve),
SizeOfStackCommit: uint64(oh64.SizeOfStackCommit),
SizeOfHeapReserve: uint64(oh64.SizeOfHeapReserve),
SizeOfHeapCommit: uint64(oh64.SizeOfHeapCommit),
LoaderFlags: oh64.LoaderFlags,
NumberOfRvaAndSizes: oh64.NumberOfRvaAndSizes,
DataDirectory: oh64.DataDirectory,
}
}