- public static void initialize() {
- MS.hookClassLoad("java.util.zip.ZipFile", new MS.ClassLoadHook() {
- public void classLoaded(Class<?> ZipFile$) {
- Field entries = null; {
- if (entries == null) try {
- entries = ZipFile$.getDeclaredField("entries");
- } catch (NoSuchFieldException e) {}
-
- if (entries == null) try {
- entries = ZipFile$.getDeclaredField("mEntries");
- } catch (NoSuchFieldException e) {}
+ private static Field scanField(Class clazz, String... names) {
+ for (String name : names) try {
+ return clazz.getDeclaredField(name);
+ } catch (NoSuchFieldException e) {}
+ return null;
+ }
+
+ private static Method findMethod(Class<?> clazz, String name, Class... args) {
+ try {
+ return clazz.getDeclaredMethod(name, args);
+ } catch (NoSuchMethodException e) {
+ return null;
+ }
+ }
+
+ private static Constructor findConstructor(Class<?> clazz, Class... args) {
+ try {
+ return clazz.getDeclaredConstructor(args);
+ } catch (NoSuchMethodException e) {
+ return null;
+ }
+ }
+
+ private static void fixZipEntry$init$() {
+ final Constructor ZipEntry$init$ = findConstructor(ZipEntry.class, byte[].class, InputStream.class);
+ if (ZipEntry$init$ == null)
+ return;
+
+ MS.hookMethod(ZipEntry.class, ZipEntry$init$,
+ new MS.MethodAlteration<ZipEntry, Void>() {
+ public Void invoked(ZipEntry thiz, Object... args)
+ throws Throwable
+ {
+ byte[] header = (byte[]) args[0];
+
+ invoke(thiz, args);
+
+ DataInputStream in = new DataInputStream(new ByteArrayInputStream(header));
+
+ in.skip(8);
+ for (int i = 0; i != 2; ++i)
+ if ((in.readShort() & 0x0080) != 0)
+ throw new ZipException("bug #99695860 [" + thiz.getName() + "]");
+
+ in.skip(16);
+ for (int i = 0; i != 3; ++i)
+ if ((in.readShort() & 0x0080) != 0)
+ throw new ZipException("bug #99695860 [" + thiz.getName() + "]");
+
+ return null;