Skip to content

Commit

Permalink
use arrays for reqs and code dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jul 22, 2020
1 parent c54bd65 commit 9fa24f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func TestNewFile(t *testing.T) {

cs := got.CodeSignature()
if cs != nil {
fmt.Println(cs.Requirements.Detail)
fmt.Println(cs.Requirements[0].Detail)
}

fmt.Println(got.FileTOC.String())
Expand Down
11 changes: 4 additions & 7 deletions pkg/codesign/codesign.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

// ParseCodeSignature parses the LC_CODE_SIGNATURE data
func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {
var err error
r := bytes.NewReader(cmddat)
cs := &types.CodeSignature{}

Expand All @@ -36,15 +35,13 @@ func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {

switch index.Type {
case types.CSSLOT_CODEDIRECTORY:
cs.CodeDirectory, err = parseCodeDirectory(r, index.Offset)
if err != nil {
return nil, err
}
fallthrough
case types.CSSLOT_ALTERNATE_CODEDIRECTORIES:
cs.AltCodeDirectory, err = parseCodeDirectory(r, index.Offset)
cd, err := parseCodeDirectory(r, index.Offset)
if err != nil {
return nil, err
}
cs.CodeDirectories = append(cs.CodeDirectories, *cd)
case types.CSSLOT_REQUIREMENTS:
req := types.Requirement{}
if err := binary.Read(r, binary.BigEndian, &req.RequirementsBlob); err != nil {
Expand All @@ -68,7 +65,7 @@ func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {
} else {
req.Detail = "empty requirement set"
}
cs.Requirements = &req
cs.Requirements = append(cs.Requirements, req)
case types.CSSLOT_ENTITLEMENTS:
entBlob := types.Blob{}
if err := binary.Read(r, binary.BigEndian, &entBlob); err != nil {
Expand Down
9 changes: 4 additions & 5 deletions pkg/codesign/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

// CodeSignature highlevel object
type CodeSignature struct {
CodeDirectory *CodeDirectory
AltCodeDirectory *CodeDirectory
Requirements *Requirement
CMSSignature []byte
Entitlements string
CodeDirectories []CodeDirectory
Requirements []Requirement
CMSSignature []byte
Entitlements string
}

type magic uint32
Expand Down

0 comments on commit 9fa24f0

Please sign in to comment.