1
1
mirror of https://github.com/ssut/payload-dumper-go.git synced 2024-05-13 19:19:11 +00:00

feat: Add support for InstallOperation_ZERO (#31)

Closes: #29
This commit is contained in:
luk1337 2022-05-30 17:49:55 +02:00 committed by GitHub
parent d100a4b3a0
commit b36ebf31e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"compress/bzip2"
"crypto/sha256"
"encoding/binary"
@ -286,6 +287,18 @@ func (p *Payload) Extract(partition *chromeos_update_engine.PartitionUpdate, out
}
break
case chromeos_update_engine.InstallOperation_ZERO:
reader := bytes.NewReader(make([]byte, expectedUncompressedBlockSize))
n, err := io.Copy(out, reader)
if err != nil {
return err
}
if n != expectedUncompressedBlockSize {
return fmt.Errorf("Verify failed (Unexpected bytes written): %s (%d != %d)", name, n, expectedUncompressedBlockSize)
}
break
default:
return fmt.Errorf("Unhandled operation type: %s", operation.GetType().String())
}
@ -293,7 +306,7 @@ func (p *Payload) Extract(partition *chromeos_update_engine.PartitionUpdate, out
// verify hash
hash := hex.EncodeToString(bufSha.Sum(nil))
expectedHash := hex.EncodeToString(operation.GetDataSha256Hash())
if hash != expectedHash {
if expectedHash != "" && hash != expectedHash {
return fmt.Errorf("Verify failed (Checksum mismatch): %s (%s != %s)", name, hash, expectedHash)
}
}