{"id":12190,"date":"2024-03-01T11:21:00","date_gmt":"2024-03-01T03:21:00","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=12190"},"modified":"2024-03-01T11:30:51","modified_gmt":"2024-03-01T03:30:51","slug":"archive-zip","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=12190","title":{"rendered":"archive\/zip(zip\u89e3\u538b\u7f29)"},"content":{"rendered":"<p><a href=\"https:\/\/blog.csdn.net\/luduoyuan\/article\/details\/132504248\">https:\/\/blog.csdn.net\/luduoyuan\/article\/details\/132504248<\/a><br \/>\n<a href=\"https:\/\/blog.csdn.net\/ddrfan\/article\/details\/133812076\">https:\/\/blog.csdn.net\/ddrfan\/article\/details\/133812076<\/a><br \/>\n<a href=\"https:\/\/www.cnblogs.com\/victorfengming\/p\/11931042.html\">https:\/\/www.cnblogs.com\/victorfengming\/p\/11931042.html<\/a><\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;archive\/zip&quot;\n    _ &quot;archive\/zip&quot;\n    &quot;flag&quot;\n    &quot;fmt&quot;\n    &quot;io\/ioutil&quot;\n    &quot;os\/exec&quot;\n    &quot;path&quot;\n    &quot;strconv&quot;\n)\n\nvar (\n    zipFile string\n)\n\nfunc main() {\n    flag.StringVar(&amp;zipFile, &quot;f&quot;, &quot;&quot;, &quot;zipFile to parse(\u9ed8\u8ba4\u503c\u7a7a)&quot;)\n    flag.Parse()\n    fmt.Println(&quot;zipFile:&quot; + zipFile)\n    filename := path.Base(zipFile)\n    payload_location := &quot;\/data\/ota_package\/&quot; + filename\n    fmt.Println(&quot;payload_location:&quot;, payload_location)\n\n    zipReader, err := zip.OpenReader(zipFile)\n    if err != nil {\n        panic(err)\n    }\n    defer func(zipReader *zip.ReadCloser) {\n        err := zipReader.Close()\n        if err != nil {\n            panic(err)\n        }\n    }(zipReader)\n    var binFile *zip.File\n    var propFile *zip.File\n    for _, f := range zipReader.File {\n        if f.Name == &quot;payload.bin&quot; {\n            binFile = f\n            fmt.Println(&quot;find payload.bin file:&quot; + binFile.Name)\n        }\n        if f.Name == &quot;payload_properties.txt&quot; {\n            propFile = f\n            fmt.Println(&quot;find payload_properties.txt file:&quot; + propFile.Name)\n        }\n    }\n    payload_offset, err := binFile.DataOffset()\n    fmt.Println(&quot;header offset size:&quot; + strconv.FormatInt(payload_offset, 10))\n    fmt.Println(&quot;header file len:&quot; + strconv.FormatInt(binFile.FileHeader.FileInfo().Size(), 10))\n    payload_size := binFile.FileInfo().Size()\n    payload_size_str := strconv.FormatInt(payload_size, 10)\n    fmt.Println(&quot;payload size:&quot; + payload_size_str)\n\n    inFile, err := propFile.Open()\n    if err != nil {\n        panic(err)\n    }\n    defer inFile.Close()\n    contentBytes, err := ioutil.ReadAll(inFile)\n    if err != nil {\n        panic(&quot;\u65e0\u6cd5\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9&quot;)\n    }\n    headers := string(contentBytes)\n    fmt.Println(&quot;headers:&quot; + headers)\n    var cmd string = fmt.Sprintf(&quot;update_engine_client --update --follow --payload=file:\/\/%s --offset=%d --size=%d --headers=\\&quot;%s\\&quot;&quot;, payload_location, payload_offset, payload_size, headers)\n    writeHostToConfig(&quot;persist.sys.board.otainfo&quot;, cmd)\n    fmt.Println(&quot;cmd:&quot; + cmd)\n}\n<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"12190\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>https:\/\/blog.csdn.net\/luduoyuan\/article\/details\/13 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[939],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12190"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12190"}],"version-history":[{"count":5,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12190\/revisions"}],"predecessor-version":[{"id":12197,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12190\/revisions\/12197"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12190"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}