Skip to content

Commit

Permalink
Refactor newProc
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Oct 12, 2023
1 parent 4516f5d commit 0af6b36
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ func newProc(r io.Reader) (*proc, error) {

remain := header.Size - binaryHeaderSize
for remain > sectionHeaderSize {
var header sectionHeader
err := binaryRead(r, &header)
if err != nil {
return nil, err
}

isOverSize := header.Size > remain
if isOverSize {
return nil, ErrSectionOverSize
}
header, err := readSectionHeader(r, remain)

switch header.String() {
case sectionTypeIRep:
Expand All @@ -54,3 +45,18 @@ func newProc(r io.Reader) (*proc, error) {
executable: executable,
}, nil
}

func readSectionHeader(r io.Reader, remain uint32) (*sectionHeader, error) {
var header sectionHeader
err := binaryRead(r, &header)
if err != nil {
return nil, err
}

isOverSize := header.Size > remain
if isOverSize {
return nil, ErrSectionOverSize
}

return &header, nil
}

0 comments on commit 0af6b36

Please sign in to comment.