Added Data() method to Stream to get a base binary image

This commit is contained in:
DataHoarder 2023-10-08 11:51:44 +02:00
parent a3860c8a97
commit efe295d8df
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -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
}