Skip to content

Commit ab23dac

Browse files
authored
feat: annotate structs missing json tags (#90)
* add json tags for iat structs * fix dosheader.go json tag in dos header * add json tags for DataDirectory struct * add json tags for delay import structs * add json tags for ImageExportDirectory * add json tags for reloc structs * add json tags for version info in resources * add json tags for missing structs in load config * return empty array instead of null when json encoding * add json tags for dotnet metadata tables * make tls callbacks an array instead of null * update loadconfig struct fields
1 parent 54ec8e8 commit ab23dac

14 files changed

+333
-226
lines changed

boundimports.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (pe *File) parseBoundImportDirectory(rva, size uint32) (err error) {
109109
bndFrwdRefSize := uint32(binary.Size(bndFrwdRef))
110110
count := min(uint32(bndDesc.NumberOfModuleForwarderRefs), safetyBoundary/bndFrwdRefSize)
111111

112-
var forwarderRefs []BoundForwardedRefData
112+
forwarderRefs := make([]BoundForwardedRefData, 0)
113113
for i := uint32(0); i < count; i++ {
114114
err = pe.structUnpack(&bndFrwdRef, rva, bndFrwdRefSize)
115115
if err != nil {

delayimports.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ type ImageDelayImportDescriptor struct {
1414
// in the image. This field can be used to extend the record by indicating
1515
// the presence of new fields, or it can be used to indicate behaviors to
1616
// the delay or unload helper functions.
17-
Attributes uint32
17+
Attributes uint32 `json:"attributes"`
1818

1919
// The name of the DLL to be delay-loaded resides in the read-only data
2020
// section of the image. It is referenced through the szName field.
21-
Name uint32
21+
Name uint32 `json:"name"`
2222

2323
// The handle of the DLL to be delay-loaded is in the data section of the
2424
// image. The phmod field points to the handle. The supplied delay-load
2525
// helper uses this location to store the handle to the loaded DLL.
26-
ModuleHandleRVA uint32
26+
ModuleHandleRVA uint32 `json:"module_handle_rva"`
2727

2828
// The delay import address table (IAT) is referenced by the delay import
2929
// descriptor through the pIAT field. The delay-load helper updates these
3030
// pointers with the real entry points so that the thunks are no longer in
3131
// the calling loop
32-
ImportAddressTableRVA uint32
32+
ImportAddressTableRVA uint32 `json:"import_address_table_rva"`
3333

3434
// The delay import name table (INT) contains the names of the imports that
3535
// might require loading. They are ordered in the same fashion as the
3636
// function pointers in the IAT.
37-
ImportNameTableRVA uint32
37+
ImportNameTableRVA uint32 `json:"import_name_table_rva"`
3838

3939
// The delay bound import address table (BIAT) is an optional table of
4040
// IMAGE_THUNK_DATA items that is used along with the timestamp field
4141
// of the delay-load directory table by a post-process binding phase.
42-
BoundImportAddressTableRVA uint32
42+
BoundImportAddressTableRVA uint32 `json:"bound_import_address_table_rva"`
4343

4444
// The delay unload import address table (UIAT) is an optional table of
4545
// IMAGE_THUNK_DATA items that the unload code uses to handle an explicit
@@ -48,18 +48,18 @@ type ImageDelayImportDescriptor struct {
4848
// delay-load thunks. On the unload request, the library can be freed,
4949
// the *phmod cleared, and the UIAT written over the IAT to restore
5050
// everything to its preload state.
51-
UnloadInformationTableRVA uint32
51+
UnloadInformationTableRVA uint32 `json:"unload_information_table_rva"`
5252

5353
// 0 if not bound, otherwise, date/time of the target DLL.
54-
TimeDateStamp uint32
54+
TimeDateStamp uint32 `json:"time_date_stamp"`
5555
}
5656

5757
// DelayImport represents an entry in the delay import table.
5858
type DelayImport struct {
59-
Offset uint32
60-
Name string
61-
Functions []ImportFunction
62-
Descriptor ImageDelayImportDescriptor
59+
Offset uint32 `json:"offset"`
60+
Name string `json:"name"`
61+
Functions []ImportFunction `json:"functions"`
62+
Descriptor ImageDelayImportDescriptor `json:"descriptor"`
6363
}
6464

6565
// Delay-Load Import Tables tables were added to the image to support a uniform

dosheader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type ImageDOSHeader struct {
6565
ReservedWords2 [10]uint16 `json:"reserved_words_2"`
6666

6767
// File address of new exe header (Elfanew).
68-
AddressOfNewEXEHeader uint32 `json:"address_of__new_exe_header"`
68+
AddressOfNewEXEHeader uint32 `json:"address_of_new_exe_header"`
6969
}
7070

7171
// ParseDOSHeader parses the DOS header stub. Every PE file begins with a small

dotnet_helper.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2018 Saferwall. All rights reserved.
2+
// Use of this source code is governed by Apache v2 license
3+
// license that can be found in the LICENSE file.
4+
15
package pe
26

37
const (

0 commit comments

Comments
 (0)