Added Data() method to Stream to get a base binary image
This commit is contained in:
parent
a3860c8a97
commit
efe295d8df
22
region.go
22
region.go
|
@ -20,3 +20,25 @@ type Stream struct {
|
|||
StartSegmentAddress uint32
|
||||
StartLinearAddress uint32
|
||||
}
|
||||
|
||||
// Data Returns a binary image, from the lowest base address
|
||||
func (s *Stream) Data() (data []byte, baseAddress uint32) {
|
||||
if len(s.Regions) == 0 {
|
||||
return nil, 0
|
||||
}
|
||||
baseAddress = s.Regions[0].Address
|
||||
topAddress := s.Regions[0].Address + uint32(len(s.Regions[0].Data))
|
||||
|
||||
for _, r := range s.Regions[1:] {
|
||||
baseAddress = min(baseAddress, r.Address)
|
||||
topAddress = min(topAddress, r.Address+uint32(len(r.Data)))
|
||||
}
|
||||
|
||||
data = make([]byte, topAddress-baseAddress)
|
||||
|
||||
for _, r := range s.Regions {
|
||||
copy(data[r.Address:], r.Data)
|
||||
}
|
||||
|
||||
return data, baseAddress
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue