From 65f756d21c2bea17a35a5049976919154dbc867a Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Wed, 14 Oct 2015 07:39:07 -0500 Subject: [PATCH] add smali patches --- .../smali-patches/001-baksmali-diffpre.patch | 68 +++++++++ .../002-dexlib2-dontloadclasspath.patch | 58 +++++++ .../003-baksmali-buildgradle.patch | 69 +++++++++ .../smali-patches/004-base-buildgradle.patch | 142 ++++++++++++++++++ .../005-dexlib2-buildgradle.patch | 55 +++++++ .../smali-patches/006-smali-buildgradle.patch | 69 +++++++++ .../smali-patches/007-util-buildgradle.patch | 32 ++++ 7 files changed, 493 insertions(+) create mode 100644 gradle/smali-patches/001-baksmali-diffpre.patch create mode 100644 gradle/smali-patches/002-dexlib2-dontloadclasspath.patch create mode 100644 gradle/smali-patches/003-baksmali-buildgradle.patch create mode 100644 gradle/smali-patches/004-base-buildgradle.patch create mode 100644 gradle/smali-patches/005-dexlib2-buildgradle.patch create mode 100644 gradle/smali-patches/006-smali-buildgradle.patch create mode 100644 gradle/smali-patches/007-util-buildgradle.patch diff --git a/gradle/smali-patches/001-baksmali-diffpre.patch b/gradle/smali-patches/001-baksmali-diffpre.patch new file mode 100644 index 00000000..4e85faae --- /dev/null +++ b/gradle/smali-patches/001-baksmali-diffpre.patch @@ -0,0 +1,68 @@ +From 687b92094889a90a70afc4e153ac24659a7e2beb Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:08:13 -0500 +Subject: baksmali: added DIFFPRE reg info + +--- + .../Adaptors/PreInstructionRegisterInfoMethodItem.java | 18 ++++++++++++++++++ + .../src/main/java/org/jf/baksmali/baksmaliOptions.java | 2 ++ + 2 files changed, 20 insertions(+) + +diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java +index f532938..5699cf0 100644 +--- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java ++++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/PreInstructionRegisterInfoMethodItem.java +@@ -40,6 +40,8 @@ import java.io.IOException; + import java.util.BitSet; + + public class PreInstructionRegisterInfoMethodItem extends MethodItem { ++ private static AnalyzedInstruction lastInstruction; ++ + private final int registerInfo; + @Nonnull private final MethodAnalyzer methodAnalyzer; + @Nonnull private final RegisterFormatter registerFormatter; +@@ -77,6 +79,9 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem { + if ((registerInfo & baksmaliOptions.ARGS) != 0) { + addArgsRegs(registers); + } ++ if ((registerInfo & baksmaliOptions.DIFFPRE) != 0) { ++ addDiffRegs(registers); ++ } + if ((registerInfo & baksmaliOptions.MERGE) != 0) { + if (analyzedInstruction.isBeginningInstruction()) { + addParamRegs(registers, registerCount); +@@ -144,6 +149,19 @@ public class PreInstructionRegisterInfoMethodItem extends MethodItem { + } + } + ++ private void addDiffRegs(BitSet registers) { ++ if (! analyzedInstruction.isBeginningInstruction()) { ++ for (int i = 0; i < analyzedInstruction.getRegisterCount(); i++) { ++ if (lastInstruction.getPreInstructionRegisterType(i).category != ++ analyzedInstruction.getPreInstructionRegisterType(i).category) { ++ registers.set(i); ++ } ++ } ++ } ++ ++ lastInstruction = analyzedInstruction; ++ } ++ + private void addMergeRegs(BitSet registers, int registerCount) { + if (analyzedInstruction.getPredecessorCount() <= 1) { + //in the common case of an instruction that only has a single predecessor which is the previous +diff --git a/baksmali/src/main/java/org/jf/baksmali/baksmaliOptions.java b/baksmali/src/main/java/org/jf/baksmali/baksmaliOptions.java +index 5dd060f..fc2ffc5 100644 +--- a/baksmali/src/main/java/org/jf/baksmali/baksmaliOptions.java ++++ b/baksmali/src/main/java/org/jf/baksmali/baksmaliOptions.java +@@ -53,6 +53,8 @@ public class baksmaliOptions { + public static final int MERGE = 32; + public static final int FULLMERGE = 64; + ++ public static final int DIFFPRE = 128; ++ + public int apiLevel = 15; + public String outputDirectory = "out"; + @Nullable public String dexEntry = null; +-- +2.1.4 diff --git a/gradle/smali-patches/002-dexlib2-dontloadclasspath.patch b/gradle/smali-patches/002-dexlib2-dontloadclasspath.patch new file mode 100644 index 00000000..71a7a06a --- /dev/null +++ b/gradle/smali-patches/002-dexlib2-dontloadclasspath.patch @@ -0,0 +1,58 @@ +From eaa6a9f04b582644a40054532dac3a93c01a5fe7 Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:09:38 -0500 +Subject: dexlib2: added "dontLoadClassPath" + +--- + dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java | 6 ++++++ + dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java | 4 ++-- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java b/dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java +index 9d0bb2d..513e73f 100644 +--- a/dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java ++++ b/dexlib2/src/main/java/org/jf/dexlib2/analysis/ClassPath.java +@@ -58,6 +58,8 @@ import java.util.regex.Matcher; + import java.util.regex.Pattern; + + public class ClassPath { ++ public static boolean dontLoadClassPath = false; ++ + @Nonnull private final TypeProto unknownClass; + @Nonnull private HashMap availableClasses = Maps.newHashMap(); + private final boolean checkPackagePrivateAccess; +@@ -171,6 +173,10 @@ public class ClassPath { + + @Nonnull + public ClassDef getClassDef(String type) { ++ if (dontLoadClassPath) { ++ throw new UnresolvedClassException("Could not resolve class %s", type); ++ } ++ + ClassDef ret = availableClasses.get(type); + if (ret == null) { + throw new UnresolvedClassException("Could not resolve class %s", type); +diff --git a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java +index e634297..d853133 100644 +--- a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java ++++ b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java +@@ -1230,7 +1230,7 @@ public class MethodAnalyzer { + ThreeRegisterInstruction instruction = (ThreeRegisterInstruction)analyzedInstruction.instruction; + + RegisterType arrayRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterB()); +- if (arrayRegisterType.category != RegisterType.NULL) { ++ if (! ClassPath.dontLoadClassPath && arrayRegisterType.category != RegisterType.NULL) { + if (arrayRegisterType.category != RegisterType.REFERENCE || + !(arrayRegisterType.type instanceof ArrayProto)) { + throw new AnalysisException("aget-wide used with non-array register: %s", arrayRegisterType.toString()); +@@ -1261,7 +1261,7 @@ public class MethodAnalyzer { + ThreeRegisterInstruction instruction = (ThreeRegisterInstruction)analyzedInstruction.instruction; + + RegisterType arrayRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterB()); +- if (arrayRegisterType.category != RegisterType.NULL) { ++ if (! ClassPath.dontLoadClassPath && arrayRegisterType.category != RegisterType.NULL) { + if (arrayRegisterType.category != RegisterType.REFERENCE || + !(arrayRegisterType.type instanceof ArrayProto)) { + throw new AnalysisException("aget-object used with non-array register: %s", +-- +2.1.4 diff --git a/gradle/smali-patches/003-baksmali-buildgradle.patch b/gradle/smali-patches/003-baksmali-buildgradle.patch new file mode 100644 index 00000000..e5cdc60d --- /dev/null +++ b/gradle/smali-patches/003-baksmali-buildgradle.patch @@ -0,0 +1,69 @@ +From 3d810d1b2b0f8f08286bf5c4e8d27cbd43ae21ed Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:15:45 -0500 +Subject: baksmali: add apktool build.gradle changes + +--- + baksmali/build.gradle | 29 ++++------------------------- + 1 file changed, 4 insertions(+), 25 deletions(-) + +diff --git a/baksmali/build.gradle b/baksmali/build.gradle +index 4780cd7..59eb352 100644 +--- a/baksmali/build.gradle ++++ b/baksmali/build.gradle +@@ -39,23 +39,18 @@ buildscript { + } + + dependencies { +- compile project(':util') +- compile project(':dexlib2') ++ compile project(':brut.apktool.smali:util') ++ compile project(':brut.apktool.smali:dexlib2') + compile depends.commons_cli + compile depends.guava + + testCompile depends.junit +- testCompile project(':smali') ++ testCompile project(':brut.apktool.smali:smali') + } + + processResources.inputs.property('version', version) + processResources.expand('version': version) + +-// This is the jar that gets uploaded to maven +-jar { +- baseName = 'maven' +-} +- + // Build a separate jar that contains all dependencies + task fatJar(type: Jar) { + from sourceSets.main.output +@@ -64,25 +59,9 @@ task fatJar(type: Jar) { + manifest { + attributes('Main-Class': 'org.jf.baksmali.main') + } +- +- doLast { +- if (!System.getProperty('os.name').toLowerCase().contains('windows')) { +- ant.symlink(link: file("${destinationDir}/baksmali.jar"), resource: archivePath, overwrite: true) +- } +- } + } +-tasks.getByPath('build').dependsOn(fatJar) + +-uploadArchives { +- repositories.mavenDeployer { +- pom.project { +- description 'baksmali is a disassembler for dalvik bytecode' +- scm { +- url 'https://github.com/JesusFreke/smali/tree/master/baksmali' +- } +- } +- } +-} ++tasks.getByPath('build').dependsOn(fatJar) + + task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) { + def outFile = fatJar.destinationDir.getPath() + '/' + fatJar.baseName + '-' + fatJar.version + '-small' + '.' + fatJar.extension +-- +2.1.4 diff --git a/gradle/smali-patches/004-base-buildgradle.patch b/gradle/smali-patches/004-base-buildgradle.patch new file mode 100644 index 00000000..e7d1ad14 --- /dev/null +++ b/gradle/smali-patches/004-base-buildgradle.patch @@ -0,0 +1,142 @@ +From 915202a77b6a3d5af044b2ad487f4ce02c2edd7c Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:16:41 -0500 +Subject: base: add apktool build.gradle changes + +--- + build.gradle | 97 +----------------------------------------------------------- + 1 file changed, 1 insertion(+), 96 deletions(-) + +diff --git a/build.gradle b/build.gradle +index 237d30e..36af3a7 100644 +--- a/build.gradle ++++ b/build.gradle +@@ -38,7 +38,7 @@ def jarVersion = version + if (!('release' in gradle.startParameter.taskNames)) { + def versionSuffix + try { +- def git = org.eclipse.jgit.api.Git.open(file('.')) ++ def git = org.eclipse.jgit.api.Git.open(file('../.')) + def head = git.getRepository().getRef('HEAD') + versionSuffix = head.getObjectId().abbreviate(8).name() + +@@ -57,21 +57,8 @@ if (!('release' in gradle.startParameter.taskNames)) { + // use something like module-1.2.3-dev.jar for the jar name, rather than the full + // module-1.2.3-001afe02-dirty.jar + jarVersion = baseVersion + '-dev' +-} else { +- if (System.env.JDK6_HOME == null && !JavaVersion.current().isJava6()) { +- throw new InvalidUserDataException("bzzzzzzzt. Release builds must be performed with java 6. " + +- "Either run gradle with java 6, or define the JDK6_HOME environment variable.") +- } +-} +- +-// Note: please don't use this. This is strictly for the official releases +-// that are posted on, e.g. the bitbucket download page. +-task release() { + } + +-// The projects that get pushed to maven +-def maven_release_projects = ['smali', 'baksmali', 'dexlib2', 'util'] +- + subprojects { + apply plugin: 'java' + apply plugin: 'idea' +@@ -84,19 +71,6 @@ subprojects { + } + } + +- if (System.env.JDK6_HOME != null) { +- sourceCompatibility = 1.6 +- targetCompatibility = 1.6 +- +- tasks.withType(JavaCompile) { +- doFirst { +- options.fork = true +- options.bootClasspath = "$System.env.JDK6_HOME/jre/lib/rt.jar" +- options.bootClasspath += "$File.pathSeparator$System.env.JDK6_HOME/jre/lib/jsse.jar" +- } +- } +- } +- + version = parent.version + + ext { +@@ -121,75 +95,6 @@ subprojects { + repositories { + mavenCentral() + } +- +- if (project.name in maven_release_projects) { +- apply plugin: 'maven' +- apply plugin: 'signing' +- +- group = 'org.smali' +- +- task javadocJar(type: Jar, dependsOn: javadoc) { +- classifier = 'javadoc' +- from 'build/docs/javadoc' +- } +- +- task sourcesJar(type: Jar) { +- classifier = 'sources' +- from sourceSets.main.allJava +- } +- +- artifacts { +- archives javadocJar +- archives sourcesJar +- } +- +- signing { +- required { gradle.taskGraph.hasTask('uploadArchives') } +- sign configurations.archives +- } +- +- uploadArchives { +- repositories.mavenDeployer { +- configuration = configurations.archives +- +- beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } +- +- if (rootProject.hasProperty('sonatypeUsername') && rootProject.hasProperty('sonatypePassword')) { +- repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') { +- authentication(userName: sonatypeUsername, password: sonatypePassword) +- } +- } +- +- pom.artifactId = project.name +- +- pom.project { +- name project.name +- url 'http://smali.org' +- packaging 'jar' +- licenses { +- license { +- name 'The BSD 3-Clause License' +- url 'http://opensource.org/licenses/BSD-3-Clause' +- distribution 'repo' +- } +- } +- scm { +- connection 'scm:git:git://github.com/JesusFreke/smali.git' +- developerConnection 'scm:git:git@github.com:JesusFreke/smali.git' +- } +- developers { +- developer { +- id 'jesusfreke' +- name 'Ben Gruver' +- email 'jesusfreke@jesusfreke.com' +- } +- } +- } +- } +- } +- +- tasks.getByPath(':release').dependsOn(uploadArchives) +- } + } + + buildscript { +-- +2.1.4 diff --git a/gradle/smali-patches/005-dexlib2-buildgradle.patch b/gradle/smali-patches/005-dexlib2-buildgradle.patch new file mode 100644 index 00000000..8e4d5f88 --- /dev/null +++ b/gradle/smali-patches/005-dexlib2-buildgradle.patch @@ -0,0 +1,55 @@ +From 88ad24a648ca190e0e39e69fcb9fc9687edb58ec Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:17:13 -0500 +Subject: dexlib2: add apktool build.gradle changes + +--- + dexlib2/accessorTestGenerator/build.gradle | 2 +- + dexlib2/build.gradle | 13 +------------ + 2 files changed, 2 insertions(+), 13 deletions(-) + +diff --git a/dexlib2/accessorTestGenerator/build.gradle b/dexlib2/accessorTestGenerator/build.gradle +index e50bdc0..e242ae0 100644 +--- a/dexlib2/accessorTestGenerator/build.gradle ++++ b/dexlib2/accessorTestGenerator/build.gradle +@@ -30,7 +30,7 @@ + */ + + dependencies { +- compile project(':util') ++ compile project(':brut.apktool.smali:util') + compile 'com.google.code.findbugs:jsr305:1.3.9' + compile 'com.google.guava:guava:13.0.1' + compile 'org.antlr:ST4:4.0.7' +diff --git a/dexlib2/build.gradle b/dexlib2/build.gradle +index 8fbe5ff..82b71b5 100644 +--- a/dexlib2/build.gradle ++++ b/dexlib2/build.gradle +@@ -46,7 +46,7 @@ configurations { + } + + dependencies { +- compile project(':util') ++ compile project(':brut.apktool.smali:util') + compile depends.findbugs + compile depends.guava + +@@ -91,15 +91,4 @@ task generateAccessorTestDex(type: JavaExec, dependsOn: compileAccessorTestJava) + args '--no-strict' + args "--output=${outputDex}" + args sourceSets.accessorTest.output.classesDir +-} +- +-uploadArchives { +- repositories.mavenDeployer { +- pom.project { +- description 'dexlib2 is a library for reading/modifying/writing Android dex files' +- scm { +- url 'https://github.com/JesusFreke/smali/tree/master/dexlib2' +- } +- } +- } + } +\ No newline at end of file +-- +2.1.4 diff --git a/gradle/smali-patches/006-smali-buildgradle.patch b/gradle/smali-patches/006-smali-buildgradle.patch new file mode 100644 index 00000000..a9aaee42 --- /dev/null +++ b/gradle/smali-patches/006-smali-buildgradle.patch @@ -0,0 +1,69 @@ +From b23132a5a7b5bc7f6d267e621194565a607cab85 Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:17:39 -0500 +Subject: smali: add apktool build.gradle changes + +--- + smali/build.gradle | 26 ++------------------------ + 1 file changed, 2 insertions(+), 24 deletions(-) + +diff --git a/smali/build.gradle b/smali/build.gradle +index 0e5cbf2..d387c7f 100644 +--- a/smali/build.gradle ++++ b/smali/build.gradle +@@ -68,8 +68,8 @@ idea { + } + + dependencies { +- compile project(':util') +- compile project(':dexlib2') ++ compile project(':brut.apktool.smali:util') ++ compile project(':brut.apktool.smali:dexlib2') + compile depends.antlr_runtime + compile depends.stringtemplate + compile depends.commons_cli +@@ -83,11 +83,6 @@ dependencies { + processResources.inputs.property('version', version) + processResources.expand('version': version) + +-// This is the jar that gets uploaded to maven +-jar { +- baseName = 'maven' +-} +- + // Build a separate jar that contains all dependencies + task fatJar(type: Jar, dependsOn: jar) { + from sourceSets.main.output +@@ -96,12 +91,6 @@ task fatJar(type: Jar, dependsOn: jar) { + manifest { + attributes('Main-Class': 'org.jf.smali.main') + } +- +- doLast { +- if (!System.getProperty('os.name').toLowerCase().contains('windows')) { +- ant.symlink(link: file("${destinationDir}/smali.jar"), resource: archivePath, overwrite: true) +- } +- } + } + tasks.getByPath('build').dependsOn(fatJar) + +@@ -117,17 +106,6 @@ generateJFlexSource { + outputDirectory = new File(outputDirectory, 'org/jf/smali') + } + +-uploadArchives { +- repositories.mavenDeployer { +- pom.project { +- description 'smali is an assembler for dalvik bytecode' +- scm { +- url 'https://github.com/JesusFreke/smali/tree/master/smali' +- } +- } +- } +-} +- + task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) { + def outFile = fatJar.destinationDir.getPath() + '/' + fatJar.baseName + '-' + + fatJar.version + '-small' + '.' + fatJar.extension +-- +2.1.4 diff --git a/gradle/smali-patches/007-util-buildgradle.patch b/gradle/smali-patches/007-util-buildgradle.patch new file mode 100644 index 00000000..b5a2749a --- /dev/null +++ b/gradle/smali-patches/007-util-buildgradle.patch @@ -0,0 +1,32 @@ +From cee3b393b9477db6047e489bc0e4ba89c687f723 Mon Sep 17 00:00:00 2001 +From: Connor Tumbleson +Date: Wed, 14 Oct 2015 06:18:02 -0500 +Subject: util: add apktool build.gradle changes + +--- + util/build.gradle | 11 ----------- + 1 file changed, 11 deletions(-) + +diff --git a/util/build.gradle b/util/build.gradle +index 407ef71..6dbd7a0 100644 +--- a/util/build.gradle ++++ b/util/build.gradle +@@ -34,15 +34,4 @@ dependencies { + compile depends.findbugs + compile depends.guava + testCompile depends.junit +-} +- +-uploadArchives { +- repositories.mavenDeployer { +- pom.project { +- description 'This library contains random utilities used by smali/baksmali/dexlib2' +- scm { +- url 'https://github.com/JesusFreke/smali/tree/master/util' +- } +- } +- } + } +\ No newline at end of file +-- +2.1.4