mirror of
https://github.com/ssut/payload-dumper-go.git
synced 2024-05-13 19:19:11 +00:00
chore: working proto
This commit is contained in:
commit
6b4c8bfec2
36
.editorconfig
Normal file
36
.editorconfig
Normal file
|
@ -0,0 +1,36 @@
|
|||
# http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
# Use 4 spaces for the Python files
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
max_line_length = 80
|
||||
|
||||
# The JSON files contain newlines inconsistently
|
||||
[*.json]
|
||||
insert_final_newline = ignore
|
||||
|
||||
# Minified JavaScript files shouldn't be changed
|
||||
[**.min.js]
|
||||
indent_style = ignore
|
||||
insert_final_newline = ignore
|
||||
|
||||
# Makefiles always use tabs for indentation
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
# Batch files use tabs for indentation
|
||||
[*.bat]
|
||||
indent_style = tab
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/go,vscode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=go,vscode
|
||||
|
||||
### Go ###
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
### Go Patch ###
|
||||
/vendor/
|
||||
/Godeps/
|
||||
|
||||
### vscode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/go,vscode
|
||||
|
||||
*.zip
|
||||
**/payload.bin
|
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
|||
https://android.googlesource.com/platform/system/update_engine/+/master/update_metadata.proto
|
1847
chromeos_update_engine/update_metadata.pb.go
Normal file
1847
chromeos_update_engine/update_metadata.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
9
go.mod
Normal file
9
go.mod
Normal file
|
@ -0,0 +1,9 @@
|
|||
module github.com/ssut/payload-dumper-go
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/golang/protobuf v1.4.2
|
||||
google.golang.org/protobuf v1.25.0
|
||||
)
|
70
go.sum
Normal file
70
go.sum
Normal file
|
@ -0,0 +1,70 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
74
main.go
Normal file
74
main.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func extractPayloadBin(filename string) string {
|
||||
zipReader, err := zip.OpenReader(filename)
|
||||
if err != nil {
|
||||
log.Fatalf("Not a valid zip archive: %s\n", filename)
|
||||
}
|
||||
defer zipReader.Close()
|
||||
|
||||
for _, file := range zipReader.Reader.File {
|
||||
if file.Name == "payload.bin" && file.UncompressedSize64 > 0 {
|
||||
zippedFile, err := file.Open()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read zipped file: %s\n", file.Name)
|
||||
}
|
||||
|
||||
tempfile, err := ioutil.TempFile(os.TempDir(), "payload_*.bin")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create a temp file located at %s\n", tempfile.Name())
|
||||
}
|
||||
defer tempfile.Close()
|
||||
|
||||
_, err = io.Copy(tempfile, zippedFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return tempfile.Name()
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func main() {
|
||||
filename := os.Args[1]
|
||||
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
log.Fatalf("File does not exist: %s\n", filename)
|
||||
}
|
||||
|
||||
payloadBin := filename
|
||||
if strings.HasSuffix(filename, ".zip") {
|
||||
fmt.Println("Please wait while extracting payload.bin from the archive.")
|
||||
payloadBin = extractPayloadBin(filename)
|
||||
if payloadBin == "" {
|
||||
log.Fatal("Failed to extract payload.bin from the archive.")
|
||||
}
|
||||
}
|
||||
fmt.Printf("payload.bin: %s\n", payloadBin)
|
||||
|
||||
payload := NewPayload(payloadBin)
|
||||
if err := payload.Open(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
payload.Init()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [inputfile]\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
169
payload.go
Normal file
169
payload.go
Normal file
|
@ -0,0 +1,169 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/ssut/payload-dumper-go/chromeos_update_engine"
|
||||
)
|
||||
|
||||
// Payload is a new format for the Android OTA/Firmware update files since Android Oreo
|
||||
type Payload struct {
|
||||
Filename string
|
||||
|
||||
file *os.File
|
||||
header *payloadHeader
|
||||
deltaArchiveManifest *chromeos_update_engine.DeltaArchiveManifest
|
||||
signatures *chromeos_update_engine.Signatures
|
||||
|
||||
metadataSize int64
|
||||
dataOffset int64
|
||||
}
|
||||
|
||||
const payloadHeaderMagic = "CrAU"
|
||||
const brilloMajorPayloadVersion = 2
|
||||
|
||||
type payloadHeader struct {
|
||||
Version uint64
|
||||
ManifestLen uint64
|
||||
MetadataSignatureLen uint32
|
||||
Size uint64
|
||||
|
||||
payload *Payload
|
||||
}
|
||||
|
||||
func (ph *payloadHeader) ReadFromPayload() error {
|
||||
buf := make([]byte, 4)
|
||||
if _, err := ph.payload.file.Read(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
if string(buf) != payloadHeaderMagic {
|
||||
return fmt.Errorf("Invalid payload magic: %s", buf)
|
||||
}
|
||||
|
||||
// Read Version
|
||||
buf = make([]byte, 8)
|
||||
if _, err := ph.payload.file.Read(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
ph.Version = binary.BigEndian.Uint64(buf)
|
||||
fmt.Printf("Payload Version: %d\n", ph.Version)
|
||||
|
||||
if ph.Version != brilloMajorPayloadVersion {
|
||||
return fmt.Errorf("Unsupported payload version: %d", ph.Version)
|
||||
}
|
||||
|
||||
// Read Manifest Len
|
||||
buf = make([]byte, 8)
|
||||
if _, err := ph.payload.file.Read(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
ph.ManifestLen = binary.BigEndian.Uint64(buf)
|
||||
fmt.Printf("Payload Manifest Length: %d\n", ph.ManifestLen)
|
||||
|
||||
ph.Size = 24
|
||||
|
||||
// Read Manifest Signature Length
|
||||
buf = make([]byte, 4)
|
||||
if _, err := ph.payload.file.Read(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
ph.MetadataSignatureLen = binary.BigEndian.Uint32(buf)
|
||||
fmt.Printf("Payload Manifest Signature Length: %d\n", ph.MetadataSignatureLen)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewPayload creates a new Payload struct
|
||||
func NewPayload(filename string) Payload {
|
||||
payload := Payload{
|
||||
Filename: filename,
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
// Open tries to open payload.bin file defined by Filename
|
||||
func (p *Payload) Open() error {
|
||||
file, err := os.Open(p.Filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.file = file
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Payload) readManifest() (*chromeos_update_engine.DeltaArchiveManifest, error) {
|
||||
buf := make([]byte, p.header.ManifestLen)
|
||||
if _, err := p.file.Read(buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
deltaArchiveManifest := &chromeos_update_engine.DeltaArchiveManifest{}
|
||||
if err := proto.Unmarshal(buf, deltaArchiveManifest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deltaArchiveManifest, nil
|
||||
}
|
||||
|
||||
func (p *Payload) readMetadataSignature() (*chromeos_update_engine.Signatures, error) {
|
||||
if _, err := p.file.Seek(int64(p.header.Size+p.header.ManifestLen), 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := make([]byte, p.header.MetadataSignatureLen)
|
||||
if _, err := p.file.Read(buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signatures := &chromeos_update_engine.Signatures{}
|
||||
if err := proto.Unmarshal(buf, signatures); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return signatures, nil
|
||||
}
|
||||
|
||||
func (p *Payload) Init() error {
|
||||
// Read Header
|
||||
p.header = &payloadHeader{
|
||||
payload: p,
|
||||
}
|
||||
if err := p.header.ReadFromPayload(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read Manifest
|
||||
deltaArchiveManifest, err := p.readManifest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.deltaArchiveManifest = deltaArchiveManifest
|
||||
|
||||
// Read Signatures
|
||||
signatures, err := p.readMetadataSignature()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.signatures = signatures
|
||||
|
||||
// Update sizes
|
||||
p.metadataSize = int64(p.header.Size + p.header.ManifestLen)
|
||||
p.dataOffset = p.metadataSize + int64(p.header.MetadataSignatureLen)
|
||||
|
||||
fmt.Println("Found partitions:")
|
||||
for i, partition := range p.deltaArchiveManifest.Partitions {
|
||||
fmt.Printf("%s (%s)", partition.GetPartitionName(), humanize.Bytes(*partition.GetNewPartitionInfo().Size))
|
||||
|
||||
if i < len(deltaArchiveManifest.Partitions)-1 {
|
||||
fmt.Printf(", ")
|
||||
} else {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
339
update_metadata.proto
Normal file
339
update_metadata.proto
Normal file
|
@ -0,0 +1,339 @@
|
|||
//
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Update file format: An update file contains all the operations needed
|
||||
// to update a system to a specific version. It can be a full payload which
|
||||
// can update from any version, or a delta payload which can only update
|
||||
// from a specific version.
|
||||
// The update format is represented by this struct pseudocode:
|
||||
// struct delta_update_file {
|
||||
// char magic[4] = "CrAU";
|
||||
// uint64 file_format_version; // payload major version
|
||||
// uint64 manifest_size; // Size of protobuf DeltaArchiveManifest
|
||||
//
|
||||
// // Only present if format_version >= 2:
|
||||
// uint32 metadata_signature_size;
|
||||
//
|
||||
// // The DeltaArchiveManifest protobuf serialized, not compressed.
|
||||
// char manifest[manifest_size];
|
||||
//
|
||||
// // The signature of the metadata (from the beginning of the payload up to
|
||||
// // this location, not including the signature itself). This is a serialized
|
||||
// // Signatures message.
|
||||
// char metadata_signature_message[metadata_signature_size];
|
||||
//
|
||||
// // Data blobs for files, no specific format. The specific offset
|
||||
// // and length of each data blob is recorded in the DeltaArchiveManifest.
|
||||
// struct {
|
||||
// char data[];
|
||||
// } blobs[];
|
||||
//
|
||||
// // The signature of the entire payload, everything up to this location,
|
||||
// // except that metadata_signature_message is skipped to simplify signing
|
||||
// // process. These two are not signed:
|
||||
// uint64 payload_signatures_message_size;
|
||||
// // This is a serialized Signatures message.
|
||||
// char payload_signatures_message[payload_signatures_message_size];
|
||||
//
|
||||
// };
|
||||
// The DeltaArchiveManifest protobuf is an ordered list of InstallOperation
|
||||
// objects. These objects are stored in a linear array in the
|
||||
// DeltaArchiveManifest. Each operation is applied in order by the client.
|
||||
// The DeltaArchiveManifest also contains the initial and final
|
||||
// checksums for the device.
|
||||
// The client will perform each InstallOperation in order, beginning even
|
||||
// before the entire delta file is downloaded (but after at least the
|
||||
// protobuf is downloaded). The types of operations are explained:
|
||||
// - REPLACE: Replace the dst_extents on the drive with the attached data,
|
||||
// zero padding out to block size.
|
||||
// - REPLACE_BZ: bzip2-uncompress the attached data and write it into
|
||||
// dst_extents on the drive, zero padding to block size.
|
||||
// - MOVE: Copy the data in src_extents to dst_extents. Extents may overlap,
|
||||
// so it may be desirable to read all src_extents data into memory before
|
||||
// writing it out. (deprecated)
|
||||
// - SOURCE_COPY: Copy the data in src_extents in the old partition to
|
||||
// dst_extents in the new partition. There's no overlapping of data because
|
||||
// the extents are in different partitions.
|
||||
// - BSDIFF: Read src_length bytes from src_extents into memory, perform
|
||||
// bspatch with attached data, write new data to dst_extents, zero padding
|
||||
// to block size. (deprecated)
|
||||
// - SOURCE_BSDIFF: Read the data in src_extents in the old partition, perform
|
||||
// bspatch with the attached data and write the new data to dst_extents in the
|
||||
// new partition.
|
||||
// - ZERO: Write zeros to the destination dst_extents.
|
||||
// - DISCARD: Discard the destination dst_extents blocks on the physical medium.
|
||||
// the data read from those blocks is undefined.
|
||||
// - REPLACE_XZ: Replace the dst_extents with the contents of the attached
|
||||
// xz file after decompression. The xz file should only use crc32 or no crc at
|
||||
// all to be compatible with xz-embedded.
|
||||
// - PUFFDIFF: Read the data in src_extents in the old partition, perform
|
||||
// puffpatch with the attached data and write the new data to dst_extents in
|
||||
// the new partition.
|
||||
//
|
||||
// The operations allowed in the payload (supported by the client) depend on the
|
||||
// major and minor version. See InstallOperation.Type below for details.
|
||||
syntax = "proto2";
|
||||
package chromeos_update_engine;
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
// Data is packed into blocks on disk, always starting from the beginning
|
||||
// of the block. If a file's data is too large for one block, it overflows
|
||||
// into another block, which may or may not be the following block on the
|
||||
// physical partition. An ordered list of extents is another
|
||||
// representation of an ordered list of blocks. For example, a file stored
|
||||
// in blocks 9, 10, 11, 2, 18, 12 (in that order) would be stored in
|
||||
// extents { {9, 3}, {2, 1}, {18, 1}, {12, 1} } (in that order).
|
||||
// In general, files are stored sequentially on disk, so it's more efficient
|
||||
// to use extents to encode the block lists (this is effectively
|
||||
// run-length encoding).
|
||||
// A sentinel value (kuint64max) as the start block denotes a sparse-hole
|
||||
// in a file whose block-length is specified by num_blocks.
|
||||
message Extent {
|
||||
optional uint64 start_block = 1;
|
||||
optional uint64 num_blocks = 2;
|
||||
}
|
||||
// Signatures: Updates may be signed by the OS vendor. The client verifies
|
||||
// an update's signature by hashing the entire download. The section of the
|
||||
// download that contains the signature is at the end of the file, so when
|
||||
// signing a file, only the part up to the signature part is signed.
|
||||
// Then, the client looks inside the download's Signatures message for a
|
||||
// Signature message that it knows how to handle. Generally, a client will
|
||||
// only know how to handle one type of signature, but an update may contain
|
||||
// many signatures to support many different types of client. Then client
|
||||
// selects a Signature message and uses that, along with a known public key,
|
||||
// to verify the download. The public key is expected to be part of the
|
||||
// client.
|
||||
message Signatures {
|
||||
message Signature {
|
||||
optional uint32 version = 1 [deprecated = true];
|
||||
optional bytes data = 2;
|
||||
// The DER encoded signature size of EC keys is nondeterministic for
|
||||
// different input of sha256 hash. However, we need the size of the
|
||||
// serialized signatures protobuf string to be fixed before signing;
|
||||
// because this size is part of the content to be signed. Therefore, we
|
||||
// always pad the signature data to the maximum possible signature size of
|
||||
// a given key. And the payload verifier will truncate the signature to
|
||||
// its correct size based on the value of |unpadded_signature_size|.
|
||||
optional fixed32 unpadded_signature_size = 3;
|
||||
}
|
||||
repeated Signature signatures = 1;
|
||||
}
|
||||
message PartitionInfo {
|
||||
optional uint64 size = 1;
|
||||
optional bytes hash = 2;
|
||||
}
|
||||
// Describe an image we are based on in a human friendly way.
|
||||
// Examples:
|
||||
// dev-channel, x86-alex, 1.2.3, mp-v3
|
||||
// nplusone-channel, x86-alex, 1.2.4, mp-v3, dev-channel, 1.2.3
|
||||
//
|
||||
// All fields will be set, if this message is present.
|
||||
message ImageInfo {
|
||||
optional string board = 1;
|
||||
optional string key = 2;
|
||||
optional string channel = 3;
|
||||
optional string version = 4;
|
||||
// If these values aren't present, they should be assumed to match
|
||||
// the equivalent value above. They are normally only different for
|
||||
// special image types such as nplusone images.
|
||||
optional string build_channel = 5;
|
||||
optional string build_version = 6;
|
||||
}
|
||||
message InstallOperation {
|
||||
enum Type {
|
||||
REPLACE = 0; // Replace destination extents w/ attached data.
|
||||
REPLACE_BZ = 1; // Replace destination extents w/ attached bzipped data.
|
||||
MOVE = 2 [deprecated = true]; // Move source extents to target extents.
|
||||
BSDIFF = 3 [deprecated = true]; // The data is a bsdiff binary diff.
|
||||
// On minor version 2 or newer, these operations are supported:
|
||||
SOURCE_COPY = 4; // Copy from source to target partition
|
||||
SOURCE_BSDIFF = 5; // Like BSDIFF, but read from source partition
|
||||
// On minor version 3 or newer and on major version 2 or newer, these
|
||||
// operations are supported:
|
||||
REPLACE_XZ = 8; // Replace destination extents w/ attached xz data.
|
||||
// On minor version 4 or newer, these operations are supported:
|
||||
ZERO = 6; // Write zeros in the destination.
|
||||
DISCARD = 7; // Discard the destination blocks, reading as undefined.
|
||||
BROTLI_BSDIFF = 10; // Like SOURCE_BSDIFF, but compressed with brotli.
|
||||
// On minor version 5 or newer, these operations are supported:
|
||||
PUFFDIFF = 9; // The data is in puffdiff format.
|
||||
}
|
||||
required Type type = 1;
|
||||
// Only minor version 6 or newer support 64 bits |data_offset| and
|
||||
// |data_length|, older client will read them as uint32.
|
||||
// The offset into the delta file (after the protobuf)
|
||||
// where the data (if any) is stored
|
||||
optional uint64 data_offset = 2;
|
||||
// The length of the data in the delta file
|
||||
optional uint64 data_length = 3;
|
||||
// Ordered list of extents that are read from (if any) and written to.
|
||||
repeated Extent src_extents = 4;
|
||||
// Byte length of src, equal to the number of blocks in src_extents *
|
||||
// block_size. It is used for BSDIFF and SOURCE_BSDIFF, because we need to
|
||||
// pass that external program the number of bytes to read from the blocks we
|
||||
// pass it. This is not used in any other operation.
|
||||
optional uint64 src_length = 5;
|
||||
repeated Extent dst_extents = 6;
|
||||
// Byte length of dst, equal to the number of blocks in dst_extents *
|
||||
// block_size. Used for BSDIFF and SOURCE_BSDIFF, but not in any other
|
||||
// operation.
|
||||
optional uint64 dst_length = 7;
|
||||
// Optional SHA 256 hash of the blob associated with this operation.
|
||||
// This is used as a primary validation for http-based downloads and
|
||||
// as a defense-in-depth validation for https-based downloads. If
|
||||
// the operation doesn't refer to any blob, this field will have
|
||||
// zero bytes.
|
||||
optional bytes data_sha256_hash = 8;
|
||||
// Indicates the SHA 256 hash of the source data referenced in src_extents at
|
||||
// the time of applying the operation. If present, the update_engine daemon
|
||||
// MUST read and verify the source data before applying the operation.
|
||||
optional bytes src_sha256_hash = 9;
|
||||
}
|
||||
// Hints to VAB snapshot to skip writing some blocks if these blocks are
|
||||
// identical to the ones on the source image. The src & dst extents for each
|
||||
// CowMergeOperation should be contiguous, and they're a subset of an OTA
|
||||
// InstallOperation.
|
||||
// During merge time, we need to follow the pre-computed sequence to avoid
|
||||
// read after write, similar to the inplace update schema.
|
||||
message CowMergeOperation {
|
||||
enum Type {
|
||||
COW_COPY = 0; // identical blocks
|
||||
}
|
||||
optional Type type = 1;
|
||||
optional Extent src_extent = 2;
|
||||
optional Extent dst_extent = 3;
|
||||
}
|
||||
// Describes the update to apply to a single partition.
|
||||
message PartitionUpdate {
|
||||
// A platform-specific name to identify the partition set being updated. For
|
||||
// example, in Chrome OS this could be "ROOT" or "KERNEL".
|
||||
required string partition_name = 1;
|
||||
// Whether this partition carries a filesystem with post-install program that
|
||||
// must be run to finalize the update process. See also |postinstall_path| and
|
||||
// |filesystem_type|.
|
||||
optional bool run_postinstall = 2;
|
||||
// The path of the executable program to run during the post-install step,
|
||||
// relative to the root of this filesystem. If not set, the default "postinst"
|
||||
// will be used. This setting is only used when |run_postinstall| is set and
|
||||
// true.
|
||||
optional string postinstall_path = 3;
|
||||
// The filesystem type as passed to the mount(2) syscall when mounting the new
|
||||
// filesystem to run the post-install program. If not set, a fixed list of
|
||||
// filesystems will be attempted. This setting is only used if
|
||||
// |run_postinstall| is set and true.
|
||||
optional string filesystem_type = 4;
|
||||
// If present, a list of signatures of the new_partition_info.hash signed with
|
||||
// different keys. If the update_engine daemon requires vendor-signed images
|
||||
// and has its public key installed, one of the signatures should be valid
|
||||
// for /postinstall to run.
|
||||
repeated Signatures.Signature new_partition_signature = 5;
|
||||
optional PartitionInfo old_partition_info = 6;
|
||||
optional PartitionInfo new_partition_info = 7;
|
||||
// The list of operations to be performed to apply this PartitionUpdate. The
|
||||
// associated operation blobs (in operations[i].data_offset, data_length)
|
||||
// should be stored contiguously and in the same order.
|
||||
repeated InstallOperation operations = 8;
|
||||
// Whether a failure in the postinstall step for this partition should be
|
||||
// ignored.
|
||||
optional bool postinstall_optional = 9;
|
||||
// On minor version 6 or newer, these fields are supported:
|
||||
// The extent for data covered by verity hash tree.
|
||||
optional Extent hash_tree_data_extent = 10;
|
||||
// The extent to store verity hash tree.
|
||||
optional Extent hash_tree_extent = 11;
|
||||
// The hash algorithm used in verity hash tree.
|
||||
optional string hash_tree_algorithm = 12;
|
||||
// The salt used for verity hash tree.
|
||||
optional bytes hash_tree_salt = 13;
|
||||
// The extent for data covered by FEC.
|
||||
optional Extent fec_data_extent = 14;
|
||||
// The extent to store FEC.
|
||||
optional Extent fec_extent = 15;
|
||||
// The number of FEC roots.
|
||||
optional uint32 fec_roots = 16 [default = 2];
|
||||
// Per-partition version used for downgrade detection, added
|
||||
// as an effort to support partial updates. For most partitions,
|
||||
// this is the build timestamp.
|
||||
optional string version = 17;
|
||||
// A sorted list of CowMergeOperation. When writing cow, we can choose to
|
||||
// skip writing the raw bytes for these extents. During snapshot merge, the
|
||||
// bytes will read from the source partitions instead.
|
||||
repeated CowMergeOperation merge_operations = 18;
|
||||
}
|
||||
message DynamicPartitionGroup {
|
||||
// Name of the group.
|
||||
required string name = 1;
|
||||
// Maximum size of the group. The sum of sizes of all partitions in the group
|
||||
// must not exceed the maximum size of the group.
|
||||
optional uint64 size = 2;
|
||||
// A list of partitions that belong to the group.
|
||||
repeated string partition_names = 3;
|
||||
}
|
||||
// Metadata related to all dynamic partitions.
|
||||
message DynamicPartitionMetadata {
|
||||
// All updatable groups present in |partitions| of this DeltaArchiveManifest.
|
||||
// - If an updatable group is on the device but not in the manifest, it is
|
||||
// not updated. Hence, the group will not be resized, and partitions cannot
|
||||
// be added to or removed from the group.
|
||||
// - If an updatable group is in the manifest but not on the device, the group
|
||||
// is added to the device.
|
||||
repeated DynamicPartitionGroup groups = 1;
|
||||
// Whether dynamic partitions have snapshots during the update. If this is
|
||||
// set to true, the update_engine daemon creates snapshots for all dynamic
|
||||
// partitions if possible. If this is unset, the update_engine daemon MUST
|
||||
// NOT create snapshots for dynamic partitions.
|
||||
optional bool snapshot_enabled = 2;
|
||||
}
|
||||
message DeltaArchiveManifest {
|
||||
// Only present in major version = 1. List of install operations for the
|
||||
// kernel and rootfs partitions. For major version = 2 see the |partitions|
|
||||
// field.
|
||||
repeated InstallOperation install_operations = 1 [deprecated = true];
|
||||
repeated InstallOperation kernel_install_operations = 2 [deprecated = true];
|
||||
// (At time of writing) usually 4096
|
||||
optional uint32 block_size = 3 [default = 4096];
|
||||
// If signatures are present, the offset into the blobs, generally
|
||||
// tacked onto the end of the file, and the length. We use an offset
|
||||
// rather than a bool to allow for more flexibility in future file formats.
|
||||
// If either is absent, it means signatures aren't supported in this
|
||||
// file.
|
||||
optional uint64 signatures_offset = 4;
|
||||
optional uint64 signatures_size = 5;
|
||||
// Only present in major version = 1. Partition metadata used to validate the
|
||||
// update. For major version = 2 see the |partitions| field.
|
||||
optional PartitionInfo old_kernel_info = 6 [deprecated = true];
|
||||
optional PartitionInfo new_kernel_info = 7 [deprecated = true];
|
||||
optional PartitionInfo old_rootfs_info = 8 [deprecated = true];
|
||||
optional PartitionInfo new_rootfs_info = 9 [deprecated = true];
|
||||
// old_image_info will only be present for delta images.
|
||||
optional ImageInfo old_image_info = 10;
|
||||
optional ImageInfo new_image_info = 11;
|
||||
// The minor version, also referred as "delta version", of the payload.
|
||||
// Minor version 0 is full payload, everything else is delta payload.
|
||||
optional uint32 minor_version = 12 [default = 0];
|
||||
// Only present in major version >= 2. List of partitions that will be
|
||||
// updated, in the order they will be updated. This field replaces the
|
||||
// |install_operations|, |kernel_install_operations| and the
|
||||
// |{old,new}_{kernel,rootfs}_info| fields used in major version = 1. This
|
||||
// array can have more than two partitions if needed, and they are identified
|
||||
// by the partition name.
|
||||
repeated PartitionUpdate partitions = 13;
|
||||
// The maximum timestamp of the OS allowed to apply this payload.
|
||||
// Can be used to prevent downgrading the OS.
|
||||
optional int64 max_timestamp = 14;
|
||||
// Metadata related to all dynamic partitions.
|
||||
optional DynamicPartitionMetadata dynamic_partition_metadata = 15;
|
||||
// If the payload only updates a subset of partitions on the device.
|
||||
optional bool partial_update = 16;
|
||||
}
|
Loading…
Reference in New Issue
Block a user