Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gophry opened this issue Feb 20, 2015 · 6 comments
Closed

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

gophry opened this issue Feb 20, 2015 · 6 comments

Comments

@gophry
Copy link

gophry commented Feb 20, 2015

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")

}

@gophry
Copy link
Author

gophry commented Feb 20, 2015

go version go1.4.1 darwin/amd64

@crawshaw
Copy link
Member

Can you share an example file that's failing to open?

@gophry
Copy link
Author

gophry commented Feb 21, 2015

https://www.dropbox.com/sh/qwkkzdyn3g7alef/AABGTMQOsVfOLgm1ct-S7tXfa?dl=0

Two apk files and the code file godex.go are both available.

@ebfe
Copy link
Contributor

ebfe commented Feb 21, 2015

$ go run godex.go Contacts.apk
open META-INF/MANIFEST.MF: no such file or directory

I don't think thats a problem with the zip package. The error comes from the os.OpenFile("META-INF/MANIFEST.MF",...) call. Note that the META-INF directory does not exist.

@crawshaw
Copy link
Member

I tried your program on one of the files provided, and there appears to be no problem opening the file with the zip package. You need to create the directories as @ebfe said, and close file descriptors sooner.

@gophry
Copy link
Author

gophry commented Feb 22, 2015

apologies but i tried this with 2 zip files which are getting unzipped fine with relevant folders getting created.

also in goswiff apk file dex and xml files are getting uncompressed if i do a continue instead of printing the error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants