Skip to content

Commit 17e5221

Browse files
authored
feat: make loadSystemRoots() use exit code to test command success (#104)
* feat: loadSystemRoots use ExitCode to test cmd success * update workflow to test more go versions * print log * add go 1.22 to unit tests * revert security_test.go * fix dumping CLR modTableRows * fix conflicts
1 parent e222fd1 commit 17e5221

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

.github/workflows/ci.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x]
11+
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Install Go
19-
uses: actions/setup-go@v3
19+
uses: actions/setup-go@v5
2020
with:
2121
go-version: ${{ matrix.go-version }}
2222

@@ -37,17 +37,17 @@ jobs:
3737
uses: codecov/codecov-action@v2
3838
with:
3939
files: ./coverage
40-
if: matrix.os == 'windows-latest' && matrix.go-version == '1.19.x'
40+
if: matrix.os == 'windows-latest' && matrix.go-version == '1.23.x'
4141

4242
- name: Go vet
4343
run: |
4444
go vet .
45-
if: matrix.os == 'windows-latest' && matrix.go-version == '1.19.x'
45+
if: matrix.os == 'windows-latest' && matrix.go-version == '1.23.x'
4646

4747
- name: Staticcheck
48-
uses: dominikh/[email protected].0
48+
uses: dominikh/[email protected].1
4949
with:
50-
version: "2022.1"
50+
version: "2024.1"
5151
install-go: false
5252
cache-key: ${{ matrix.go }}
53-
if: matrix.os == 'windows-latest' && matrix.go-version == '1.19.x'
53+
if: matrix.os == 'windows-latest' && matrix.go-version == '1.23.x'

cmd/dump.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -854,15 +854,17 @@ func parsePE(filename string, cfg config) {
854854
switch table {
855855
case peparser.Module:
856856
fmt.Print("\n\t[Modules]\n\t---------\n")
857-
modTableRow := modTable.Content.(peparser.ModuleTableRow)
858-
modName := pe.GetStringFromData(modTableRow.Name, pe.CLR.MetadataStreams["#Strings"])
859-
Mvid := pe.GetStringFromData(modTableRow.Mvid, pe.CLR.MetadataStreams["#GUID"])
860-
MvidStr := hex.EncodeToString(Mvid)
861-
fmt.Fprintf(w, "Generation:\t 0x%x\n", modTableRow.Generation)
862-
fmt.Fprintf(w, "Name:\t 0x%x (%s)\n", modTableRow.Name, string(modName))
863-
fmt.Fprintf(w, "Mvid:\t 0x%x (%s)\n", modTableRow.Mvid, MvidStr)
864-
fmt.Fprintf(w, "EncID:\t 0x%x\n", modTableRow.EncID)
865-
fmt.Fprintf(w, "EncBaseID:\t 0x%x\n", modTableRow.EncBaseID)
857+
modTableRows := modTable.Content.([]peparser.ModuleTableRow)
858+
for _, modTableRow := range modTableRows {
859+
modName := pe.GetStringFromData(modTableRow.Name, pe.CLR.MetadataStreams["#Strings"])
860+
Mvid := pe.GetStringFromData(modTableRow.Mvid, pe.CLR.MetadataStreams["#GUID"])
861+
MvidStr := hex.EncodeToString(Mvid)
862+
fmt.Fprintf(w, "Generation:\t 0x%x\n", modTableRow.Generation)
863+
fmt.Fprintf(w, "Name:\t 0x%x (%s)\n", modTableRow.Name, string(modName))
864+
fmt.Fprintf(w, "Mvid:\t 0x%x (%s)\n", modTableRow.Mvid, MvidStr)
865+
fmt.Fprintf(w, "EncID:\t 0x%x\n", modTableRow.EncID)
866+
fmt.Fprintf(w, "EncBaseID:\t 0x%x\n", modTableRow.EncBaseID)
867+
}
866868
w.Flush()
867869

868870
}

dotnet.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,14 @@ func (pe *File) parseCLRHeaderDirectory(rva, size uint32) error {
724724
table.Content, n, err = pe.parseMetadataMethodSpecTable(offset)
725725
case GenericParamConstraint: // 0x2c
726726
table.Content, n, err = pe.parseMetadataGenericParamConstraintTable(offset)
727-
728727
default:
729728
pe.logger.Warnf("unhandled metadata table %d %s offset 0x%x cols %d",
730729
tableIndex, MetadataTableIndexToString(tableIndex), offset, table.CountCols)
731730
}
731+
if err != nil {
732+
pe.logger.Warnf("parsing metadata table %s failed with %v",
733+
MetadataTableIndexToString(tableIndex), err)
734+
}
732735
offset += n
733736

734737
}

dotnet_metadata_tables.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ type AssemblyRefProcessorTableRow struct {
11951195

11961196
// AssemblyRefOS 0x25
11971197
type AssemblyRefOSTableRow struct {
1198-
OSPlatformId uint32 `json:"os_platform_id"` // a 4-byte constant
1198+
OSPlatformID uint32 `json:"os_platform_id"` // a 4-byte constant
11991199
OSMajorVersion uint32 `json:"os_major_version"` // a 4-byte constant
12001200
OSMinorVersion uint32 `json:"os_minor_version"` // a 4-byte constan)
12011201
AssemblyRef uint32 `json:"assembly_ref"` // an index into the AssemblyRef table

security.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ func (pe *File) parseSecurityDirectory(rva, size uint32) error {
386386

387387
// Verify the signature. This will also verify the chain of trust of the
388388
// the end-entity signer cert to one of the root in the trust store.
389-
if err == nil {
389+
if err != nil {
390+
pe.logger.Errorf("failed to loadSystemRoots: %v", err)
391+
} else {
390392
err = pkcs.VerifyWithChain(certPool)
391393
if err == nil {
392394
certValid = true
@@ -467,11 +469,11 @@ func loadSystemRoots() (*x509.CertPool, error) {
467469
if needSync {
468470
cmd := exec.Command("certutil", "-syncWithWU", dir)
469471
hideWindow(cmd)
470-
out, err := cmd.Output()
472+
err := cmd.Run()
471473
if err != nil {
472474
return roots, err
473475
}
474-
if !strings.Contains(string(out), "command completed successfully") {
476+
if cmd.ProcessState.ExitCode() != 0 {
475477
return roots, err
476478
}
477479
}
@@ -563,12 +565,12 @@ func parseAuthenticodeContent(content []byte) (AuthenticodeContent, error) {
563565
if err != nil {
564566
return AuthenticodeContent{}, err
565567
}
566-
hashFunction, algorithmId, err := parseHashAlgorithm(authenticodeContent.MessageDigest.DigestAlgorithm)
568+
hashFunction, algorithmID, err := parseHashAlgorithm(authenticodeContent.MessageDigest.DigestAlgorithm)
567569
if err != nil {
568570
return AuthenticodeContent{}, err
569571
}
570572
return AuthenticodeContent{
571-
Algorithm: algorithmId,
573+
Algorithm: algorithmID,
572574
HashFunction: hashFunction,
573575
HashResult: authenticodeContent.MessageDigest.Digest,
574576
}, nil

security_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func TestParseSecurityDirectory(t *testing.T) {
204204
t.Fatalf("certificate verification %d failed, cert %v, want %v", i, cert.Verified, expected.Verified)
205205
}
206206
}
207+
207208
}
208209
})
209210
}

version.go

-2
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ func (pe *File) parseVersionEntry(e ResourceDirectoryEntry, vers map[string]stri
372372
}
373373
}
374374
case VarFileInfoString:
375-
break
376375
default:
377-
break
378376
}
379377

380378
offset += uint32(f.Length)

0 commit comments

Comments
 (0)