how could i unzip an apk?
Closed this issue · 2 comments
0x41337 commented
well, I'm creating a tool that involves apk, and I can unzip the apk using unzip, however, I want to do it using dart, I made these functions for that, but it didn't work.
bool apk2zip(String apkName) {
try {
print("(*) reading apk");
final apk = File(apkName);
print("(*) converting \"$apkName\" to zip");
apk.copy(apkName.replaceAll(".apk", ".zip"));
return true;
} catch (e) {
return false;
}
}
bool unzipApk(String apkName) {
try {
apk2zip(apkName);
print("(*) unzipping $apkName");
String apkFinal = apkName.replaceAll(".apk", ".zip");
final bytes = File(apkFinal).readAsBytesSync();
final archive = ZipDecoder().decodeBytes(bytes);
for (final file in archive) {
final filename = file.name;
if (file.isFile) {
final data = file.content as List<int>;
File('$apkFinal-files/' + filename)
..createSync(recursive: true)
..writeAsBytesSync(data);
} else {
Directory('$apkFinal-files/' + filename).create(recursive: false);
}
}
return true;
} catch (e) {
print(e);
return false;
}
}
expected:
$ ls
zap.apk zap.zip zap-files
what i get:
$./mytool zap.apk
(*) reading apk
(*) converting "zap.apk" to zip
(*) unzipping zap.apk
FormatException: Could not find End of Central Directory Record
how could i do that, sorry for the dirty code, i'll still do the lint.
0x41337 commented
0x41337 commented
I closed insue, due to timeout in the response.