finish fix for source archives

also update deps

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 2 years ago
parent 9e76087d94
commit 0ac2779bb0

@ -338,15 +338,13 @@ dependencies {
implementation "io.sentry:sentry-android-ndk" implementation "io.sentry:sentry-android-ndk"
// Markdown // Markdown
// TODO: switch to an updated implementation
implementation "io.noties.markwon:core:4.6.2" implementation "io.noties.markwon:core:4.6.2"
implementation "io.noties.markwon:html:4.6.2" implementation "io.noties.markwon:html:4.6.2"
implementation "io.noties.markwon:image:4.6.2" implementation "io.noties.markwon:image:4.6.2"
implementation "io.noties.markwon:syntax-highlight:4.6.2" implementation "io.noties.markwon:syntax-highlight:4.6.2"
implementation 'com.google.net.cronet:cronet-okhttp:0.1.0' implementation 'com.google.net.cronet:cronet-okhttp:0.1.0'
implementation "com.caverock:androidsvg:1.4" implementation "com.caverock:androidsvg:1.4"
// Icons
// implementation "com.mikepenz:iconics-core:3.2.5"
//implementation "androidx.appcompat:appcompat:${versions.appCompat}"
implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.core:core-ktx:1.9.0'
@ -360,6 +358,8 @@ dependencies {
// some utils // some utils
implementation 'commons-io:commons-io:2.11.0' implementation 'commons-io:commons-io:2.11.0'
implementation 'org.apache.commons:commons-compress:1.23.0'
} }
if (hasSentryConfig) { if (hasSentryConfig) {

@ -15,6 +15,9 @@ import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileInputStream; import com.topjohnwu.superuser.io.SuFileInputStream;
import com.topjohnwu.superuser.io.SuFileOutputStream; import com.topjohnwu.superuser.io.SuFileOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -26,8 +29,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Path; import java.util.Enumeration;
import java.nio.file.Paths; import java.util.Objects;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -111,7 +114,8 @@ public enum Files {
if (file.isFile() && file.canRead()) { if (file.isFile() && file.canRead()) {
try { // Read as app if su not required try { // Read as app if su not required
return read(file); return read(file);
} catch (IOException ignored) {} } catch (IOException ignored) {
}
} }
try (InputStream inputStream = SuFileInputStream.open(file)) { try (InputStream inputStream = SuFileInputStream.open(file)) {
return readAllBytes(inputStream); return readAllBytes(inputStream);
@ -122,7 +126,7 @@ public enum Files {
return file.exists() || new SuFile(file.getAbsolutePath()).exists(); return file.exists() || new SuFile(file.getAbsolutePath()).exists();
} }
public static void copy(InputStream inputStream,OutputStream outputStream) throws IOException { public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
int nRead; int nRead;
byte[] data = new byte[16384]; byte[] data = new byte[16384];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) { while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
@ -134,7 +138,8 @@ public enum Files {
public static void closeSilently(Closeable closeable) { public static void closeSilently(Closeable closeable) {
try { try {
if (closeable != null) closeable.close(); if (closeable != null) closeable.close();
} catch (IOException ignored) {} } catch (IOException ignored) {
}
} }
public static ByteArrayOutputStream makeBuffer(long capacity) { public static ByteArrayOutputStream makeBuffer(long capacity) {
@ -164,11 +169,12 @@ public enum Files {
bytes[0x7] = 0x8; // Known hax to prevent java zip file read bytes[0x7] = 0x8; // Known hax to prevent java zip file read
} }
public static void patchModuleSimple(byte[] bytes,OutputStream outputStream) throws IOException { public static void patchModuleSimple(byte[] bytes, OutputStream outputStream) throws IOException {
fixJavaZipHax(bytes); patchModuleSimple(new ByteArrayInputStream(bytes), outputStream); fixJavaZipHax(bytes);
patchModuleSimple(new ByteArrayInputStream(bytes), outputStream);
} }
public static void patchModuleSimple(InputStream inputStream,OutputStream outputStream) throws IOException { public static void patchModuleSimple(InputStream inputStream, OutputStream outputStream) throws IOException {
ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipInputStream zipInputStream = new ZipInputStream(inputStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
int nRead; int nRead;
@ -201,47 +207,72 @@ public enum Files {
if (tempDir.exists()) { if (tempDir.exists()) {
FileUtils.deleteDirectory(tempDir); FileUtils.deleteDirectory(tempDir);
} }
tempDir.mkdirs(); if (!tempDir.mkdirs()) {
throw new IOException("Unable to create temp dir");
}
File tempFile = new File(tempDir, "module.zip"); File tempFile = new File(tempDir, "module.zip");
Files.write(tempFile, rawModule); Files.write(tempFile, rawModule);
File tempUnzipDir = new File(tempDir, "unzip"); File tempUnzipDir = new File(tempDir, "unzip");
tempUnzipDir.mkdirs(); if (!tempUnzipDir.mkdirs()) {
throw new IOException("Unable to create temp unzip dir");
}
// unzip // unzip
try (ZipInputStream zipInputStream = new ZipInputStream( Timber.d("Unzipping module to %s", tempUnzipDir.getAbsolutePath());
new ByteArrayInputStream(rawModule))) { try (ZipFile zipFile = new ZipFile(tempFile)) {
ZipEntry zipEntry; Enumeration<ZipArchiveEntry> files = zipFile.getEntries();
while ((zipEntry = zipInputStream.getNextEntry()) != null) { // check if there is only one folder in the top level
String name = zipEntry.getName(); int folderCount = 0;
File file = new File(tempUnzipDir, name); while (files.hasMoreElements()) {
if (zipEntry.isDirectory()) { ZipArchiveEntry entry = files.nextElement();
file.mkdirs(); if (entry.isDirectory()) {
} else { folderCount++;
file.getParentFile().mkdirs(); }
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { }
int nRead; if (folderCount == 1) {
byte[] data = new byte[16384]; files = zipFile.getEntries();
while ((nRead = zipInputStream.read(data, 0, data.length)) != -1) { while (files.hasMoreElements()) {
fileOutputStream.write(data, 0, nRead); ZipArchiveEntry entry = files.nextElement();
if (entry.isDirectory()) {
continue;
}
File file = new File(tempUnzipDir, entry.getName());
if (!Objects.requireNonNull(file.getParentFile()).exists()) {
if (!file.getParentFile().mkdirs()) {
throw new IOException("Unable to create parent dir");
}
}
try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(file)) {
zipArchiveOutputStream.putArchiveEntry(entry);
try (InputStream inputStream = zipFile.getInputStream(entry)) {
copy(inputStream, zipArchiveOutputStream);
} }
fileOutputStream.flush(); zipArchiveOutputStream.closeArchiveEntry();
} }
} }
// zip up the contents of the folder but not the folder itself
File[] filesInFolder = Objects.requireNonNull(tempUnzipDir.listFiles());
// create a new zip file
try (ZipArchiveOutputStream archive = new ZipArchiveOutputStream(new FileOutputStream("new.zip"))) {
for (File files2 : filesInFolder) {
// create a new ZipArchiveEntry and add it to the ZipArchiveOutputStream
ZipArchiveEntry entry = new ZipArchiveEntry(files2, files2.getName());
archive.putArchiveEntry(entry);
try (InputStream input = new FileInputStream(files2)) {
copy(input, archive);
}
archive.closeArchiveEntry();
}
} catch (IOException e) {
Timber.e(e, "Unable to zip up module");
}
} else {
Timber.d("Module does not have a single folder in the top level, skipping");
} }
} catch (Exception e) { } catch (IOException e) {
Timber.e(Log.getStackTraceString(e)); Timber.e(e, "Unable to unzip module");
}
File[] files = tempUnzipDir.listFiles();
if (files != null && files.length == 1 && files[0].isDirectory()) {
File[] files2 = files[0].listFiles();
if (files2 != null && files2.length > 0) {
File tempZipFile = new File(tempDir, "module2.zip");
// TODO: zip the contents of the folder
Files.write(tempFile, Files.read(tempZipFile));
}
} }
rawModule = Files.read(tempFile); } catch (IOException e) {
} catch (Exception e) { Timber.e(e, "Unable to create temp dir");
Timber.e(Log.getStackTraceString(e));
} }
} }
} }

@ -158,7 +158,8 @@ public enum Http {
} }
// for debug builds, add a logging interceptor // for debug builds, add a logging interceptor
if (BuildConfig.DEBUG) { // this spams the logcat, so it's disabled by default and hidden behind a build config flag
if (BuildConfig.DEBUG && BuildConfig.DEBUG_HTTP) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpclientBuilder.addInterceptor(loggingInterceptor); httpclientBuilder.addInterceptor(loggingInterceptor);
@ -182,6 +183,7 @@ public enum Http {
} }
builder.setStoragePath(mainApplication.getCacheDir().getAbsolutePath() + "/cronet"); builder.setStoragePath(mainApplication.getCacheDir().getAbsolutePath() + "/cronet");
builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 * 1024 * 1024); builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 * 1024 * 1024);
builder.enableNetworkQualityEstimator(true);
// Add quic hint // Add quic hint
builder.addQuicHint("github.com", 443, 443); builder.addQuicHint("github.com", 443, 443);
builder.addQuicHint("githubusercontent.com", 443, 443); builder.addQuicHint("githubusercontent.com", 443, 443);

Loading…
Cancel
Save