souramoo / unapkm

APKM file decryptor
Apache License 2.0
176 stars 19 forks source link

Request: split UnApkm function to use streams instead of files #1

Closed AndroidDeveloperLB closed 4 years ago

AndroidDeveloperLB commented 4 years ago

Not forcing to save to a file, and not forcing to have an input file. Streams are more general, and this one could be useful in case the input is from SAF or even inside a zipped file.

AndroidDeveloperLB commented 4 years ago

Maybe even provide a way to get to the various APKs inside, to be able to choose which to extract, before actually extracting them. This could be useful in case we want to extract only the base APK, for example. However, sadly I don't think there is an easy&reliable way to determine which is the base APK, without actually parsing its manifest file...

souramoo commented 4 years ago

I will try to think about how best to do this!

Maybe even provide a way to get to the various APKs inside, to be able to choose which to extract, before actually extracting them.

This I think would be beyond the scope of this project, it should be fairly simple to do with a ZipInputStream

souramoo commented 4 years ago

Added to af1e936 and the function to read/write from files has been rewritten to use this Streams interface instead.

AndroidDeveloperLB commented 4 years ago

I see. This is a nice approach. Thank you for this.

As for ZipInputStream, this is a good idea, but I wonder if the current code could be better for this, as on some scenarios it might take a toll on performance. Could it cache the data from before the loop, so that the ZipInputStream could be created quickly, over and over, after the first initialization? Or does it need to be re-initialized each time you want to go over the file content?

The purpose of what I write is to reach the same performance as ZipFile, at least after the initialization .

souramoo commented 4 years ago

Thanks. Have added some convenience functions in 2f85794 to allow for processing the header and then re-using this.

decryptStream(InputStream i) process normally, while decryptStream(InputStream i, Header h) uses the provided key and skips the header, but expects a similar input stream to the first one (skips over the first few bytes and avoids the expensive operation)

AndroidDeveloperLB commented 4 years ago

Oh this is actually great, as I actually asked about this here: https://github.com/souramoo/unapkm/issues/4#issuecomment-604933953