Skip to content

Commit

Permalink
add: LC_DYLD_ENVIRONMENT
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jul 9, 2020
1 parent 9654907 commit 1acbc5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
17 changes: 15 additions & 2 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ type CodeSignature struct {
ID string
TeamID string
CodeDirectory types.CsCodeDirectory
Requirements types.CsRequirement
Requirements []types.CsRequirement
CMSSignature []byte
Entitlements string
}
Expand Down Expand Up @@ -843,7 +843,20 @@ func (f *FunctionStarts) String() string {
return fmt.Sprintf("offset=0x%08x-0x%08x, size=%5d, count=%d", f.Offset, f.Offset+f.Size, f.Size, len(f.VMAddrs))
}

// TODO: LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat like environment variable */
/*******************************************************************************
* LC_DYLD_ENVIRONMENT
*******************************************************************************/

// A DyldEnvironment is a string for dyld to treat like environment variable
type DyldEnvironment struct {
LoadBytes
types.DyldEnvironmentCmd
Name string
}

func (d *DyldEnvironment) String() string {
return d.Name
}

/*******************************************************************************
* LC_MAIN
Expand Down
19 changes: 16 additions & 3 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,20 @@ func NewFile(r io.ReaderAt, loads ...types.LoadCmd) (*File, error) {
l.NextFuncOffsets = append(l.NextFuncOffsets, offset)
}
f.Loads[i] = l
// TODO: case types.LcDyldEnvironment:
case types.LC_DYLD_ENVIRONMENT:
var hdr types.DyldEnvironmentCmd
b := bytes.NewReader(cmddat)
if err := binary.Read(b, bo, &hdr); err != nil {
return nil, err
}
l := new(DyldEnvironment)
l.LoadCmd = cmd
if hdr.Name >= uint32(len(cmddat)) {
return nil, &FormatError{offset, "invalid name in dyld environment command", hdr.Name}
}
l.Name = cstring(cmddat[hdr.Name:])
l.LoadBytes = LoadBytes(cmddat)
f.Loads[i] = l
case types.LC_MAIN:
var hdr types.EntryPointCmd
b := bytes.NewReader(cmddat)
Expand Down Expand Up @@ -1273,7 +1286,7 @@ func (f *File) parseCodeSignature(cmddat []byte, hdr *types.CodeSignatureCmd, of
case 0x13:
reqPart = "named subroutine"
default:
fmt.Printf("Unknown requirement set opcode 0x%x, please notify author\n", reqOpCode)
// fmt.Printf("Unknown requirement set opcode 0x%x, please notify author\n", reqOpCode)
}
if len(reqPart) > 0 {
reqSet = append(reqSet, reqPart)
Expand All @@ -1296,7 +1309,7 @@ func (f *File) parseCodeSignature(cmddat []byte, hdr *types.CodeSignatureCmd, of
req.CsRequirements.Type = types.CsRequirementType(reqType)
req.Detail = "empty requirement set"
}
cs.Requirements = req
cs.Requirements = append(cs.Requirements, req)
case types.CSSLOT_ENTITLEMENTS:
entBlob := types.CsBlob{}
if err := binary.Read(csr, binary.BigEndian, &entBlob); err != nil {
Expand Down

0 comments on commit 1acbc5a

Please sign in to comment.