From: Jay Freeman (saurik) Date: Sun, 21 Jul 2013 02:58:04 +0000 (-0700) Subject: Initial version of Backport to go with my article. X-Git-Tag: v0.8^0 X-Git-Url: https://git.saurik.com/backport.git/commitdiff_plain/6e682be61e8d6b70d2937cf72c67553fc41be820 Initial version of Backport to go with my article. --- 6e682be61e8d6b70d2937cf72c67553fc41be820 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5959f86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +ant.properties +bin +gen +local.properties +release.keystore +substrate-api.jar diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..2c06657 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..8913a0c --- /dev/null +++ b/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/custom_rules.xml b/custom_rules.xml new file mode 100644 index 0000000..e20066b --- /dev/null +++ b/custom_rules.xml @@ -0,0 +1,4 @@ + + + + diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..c6998b3 --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-9 diff --git a/src/com/saurik/backport/Hook.java b/src/com/saurik/backport/Hook.java new file mode 100644 index 0000000..5c0173a --- /dev/null +++ b/src/com/saurik/backport/Hook.java @@ -0,0 +1,85 @@ +/* Backport - Bring New Fixes to old Androids + * Copyright (C) 2013 Jay Freeman (saurik) +*/ + +/* GNU Lesser General Public License, Version 3 {{{ */ +/* + * Substrate is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Substrate is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Substrate. If not, see . +**/ +/* }}} */ + +package com.saurik.backport; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import java.util.LinkedHashMap; + +import java.util.jar.JarFile; + +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import android.util.Log; + +import com.saurik.substrate.MS; + +public class Hook { + 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) {} + } + + if (entries == null) + return; + final Field ZipFile$entries = entries; + ZipFile$entries.setAccessible(true); + + final Method ZipFile$readCentralDir; try { + ZipFile$readCentralDir = ZipFile$.getDeclaredMethod("readCentralDir"); + } catch (NoSuchMethodException e) { + Log.e("Backport", "ZipFile$readCentralDir", e); + return; + } + + MS.hookMethod(ZipFile$, ZipFile$readCentralDir, + new MS.MethodAlteration() { + public Void invoked(ZipFile thiz, Object... args) + throws Throwable + { + ZipFile$entries.set(thiz, new LinkedHashMap() { + public ZipEntry put(String key, ZipEntry value) { + if (super.put(key, value) != null) + throw new WrongException(new ZipException("Duplicate entry name: " + key)); + return null; + } + }); + + return invoke(thiz, args); + } + } + ); + } + }); + } +}