Skip to content

archive/zip: no such file/directory Java-generated zip (apk) files #9943

Description

@gophry

Error while unzipping a apk and jar files. Normal zip files are getting unzipped perfect.
:no such file or directory error

package main

import (
"archive/zip"
"flag"
"fmt"
"os"
"io"
"path/filepath"
//"strings"
//"log"
)

func main() {
flag.Parse() //parse command line arguments
zipfile := flag.Arg(0)
//check zip file name is passed as argument
if zipfile == "" {
fmt.Println("Usage: godex pathofapk")
os.Exit(1)
}
//open reader to read zip file
reader, err := zip.OpenReader(zipfile)
if err != nil {
fmt.Println(err)
os.Exit(1)
} // check for valid zip file
defer reader.Close()

for _, f := range reader.Reader.File {
    zipped, err := f.Open()
    //fmt.Println(f)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    defer zipped.Close()
    path := filepath.Join("", f.Name)
    if f.FileInfo().IsDir() {
        os.MkdirAll(path, f.Mode())
        fmt.Println("Creating Directory", path)
    } else {
        writer, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, f.Mode())
        if err != nil {

                fmt.Println(err)
                os.Exit(1)

        }
        defer writer.Close()
        if _, err = io.Copy(writer, zipped); err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
        fmt.Println("Decompressing: ", path)
    }
}
//os.Rename("goSwiff_v3.1.1_UAT.apk","goSwiff_v3.1.1_UAT.zip")

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions