https://blog.csdn.net/luduoyuan/article/details/132504248
https://blog.csdn.net/ddrfan/article/details/133812076
https://www.cnblogs.com/victorfengming/p/11931042.html

package main

import (
    "archive/zip"
    _ "archive/zip"
    "flag"
    "fmt"
    "io/ioutil"
    "os/exec"
    "path"
    "strconv"
)

var (
    zipFile string
)

func main() {
    flag.StringVar(&zipFile, "f", "", "zipFile to parse(默认值空)")
    flag.Parse()
    fmt.Println("zipFile:" + zipFile)
    filename := path.Base(zipFile)
    payload_location := "/data/ota_package/" + filename
    fmt.Println("payload_location:", payload_location)

    zipReader, err := zip.OpenReader(zipFile)
    if err != nil {
        panic(err)
    }
    defer func(zipReader *zip.ReadCloser) {
        err := zipReader.Close()
        if err != nil {
            panic(err)
        }
    }(zipReader)
    var binFile *zip.File
    var propFile *zip.File
    for _, f := range zipReader.File {
        if f.Name == "payload.bin" {
            binFile = f
            fmt.Println("find payload.bin file:" + binFile.Name)
        }
        if f.Name == "payload_properties.txt" {
            propFile = f
            fmt.Println("find payload_properties.txt file:" + propFile.Name)
        }
    }
    payload_offset, err := binFile.DataOffset()
    fmt.Println("header offset size:" + strconv.FormatInt(payload_offset, 10))
    fmt.Println("header file len:" + strconv.FormatInt(binFile.FileHeader.FileInfo().Size(), 10))
    payload_size := binFile.FileInfo().Size()
    payload_size_str := strconv.FormatInt(payload_size, 10)
    fmt.Println("payload size:" + payload_size_str)

    inFile, err := propFile.Open()
    if err != nil {
        panic(err)
    }
    defer inFile.Close()
    contentBytes, err := ioutil.ReadAll(inFile)
    if err != nil {
        panic("无法读取文件内容")
    }
    headers := string(contentBytes)
    fmt.Println("headers:" + headers)
    var cmd string = fmt.Sprintf("update_engine_client --update --follow --payload=file://%s --offset=%d --size=%d --headers=\"%s\"", payload_location, payload_offset, payload_size, headers)
    writeHostToConfig("persist.sys.board.otainfo", cmd)
    fmt.Println("cmd:" + cmd)
}
分类: 文件

0 条评论

发表回复

您的电子邮箱地址不会被公开。