Skip to content

Commit 3e8dced

Browse files
committed
new axml parser with bugfixes and ported the Eclipse project to Maven
1 parent 6df1d0f commit 3e8dced

18 files changed

+120
-85
lines changed

.classpath

+47-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" path="generated/jastadd"/>
4-
<classpathentry excluding="soot/jimple/toolkits/ctl/CTLEvaluator.java|soot/jimple/toolkits/ctl/CopyOfCTLAnalysis.java|soot/jimple/toolkits/ctl/formula/AF.java|soot/jimple/toolkits/ctl/formula/AG.java|soot/jimple/toolkits/ctl/formula/AU.java|soot/jimple/toolkits/ctl/formula/AX.java|soot/jimple/toolkits/ctl/formula/EF.java|soot/jimple/toolkits/ctl/formula/And.java" kind="src" path="src"/>
5-
<classpathentry kind="src" output="testclasses" path="tests"/>
6-
<classpathentry excluding="soot/AntTask.java" kind="src" path="generated/options"/>
7-
<classpathentry kind="src" path="generated/sablecc"/>
8-
<classpathentry kind="src" path="generated/singletons"/>
9-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
3+
<classpathentry kind="src" output="target/classes" path="generated/jastadd">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="target/test-classes" path="tests">
16+
<attributes>
17+
<attribute name="optional" value="true"/>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="src" output="target/classes" path="generated/options">
22+
<attributes>
23+
<attribute name="optional" value="true"/>
24+
<attribute name="maven.pomderived" value="true"/>
25+
</attributes>
26+
</classpathentry>
27+
<classpathentry including="**/*.java" kind="src" output="target/classes" path="generated/sablecc">
28+
<attributes>
29+
<attribute name="optional" value="true"/>
30+
<attribute name="maven.pomderived" value="true"/>
31+
</attributes>
32+
</classpathentry>
33+
<classpathentry kind="src" output="target/classes" path="generated/singletons">
34+
<attributes>
35+
<attribute name="optional" value="true"/>
36+
<attribute name="maven.pomderived" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
40+
<attributes>
41+
<attribute name="maven.pomderived" value="true"/>
42+
</attributes>
43+
</classpathentry>
1044
<classpathentry combineaccessrules="false" kind="src" path="/jasmin"/>
1145
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/heros"/>
12-
<classpathentry kind="lib" path="libs/polyglot.jar"/>
13-
<classpathentry kind="lib" path="libs/AXMLPrinter2.jar"/>
14-
<classpathentry kind="lib" path="libs/hamcrest-all-1.3.jar"/>
15-
<classpathentry kind="lib" path="libs/junit-4.11.jar"/>
16-
<classpathentry kind="lib" path="libs/mockito-all-1.10.8.jar"/>
17-
<classpathentry kind="lib" path="libs/powermock-mockito-1.6.1-full.jar"/>
18-
<classpathentry kind="lib" path="libs/jboss-common-core-2.5.0.Final.jar"/>
19-
<classpathentry kind="lib" path="libs/asm-debug-all-5.1.jar"/>
20-
<classpathentry kind="lib" path="libs/javassist-3.18.2-GA.jar"/>
21-
<classpathentry kind="lib" path="libs/dexlib2-2.2.1.jar"/>
22-
<classpathentry kind="lib" path="libs/util-2.2.1.jar"/>
23-
<classpathentry kind="output" path="classes"/>
46+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
47+
<attributes>
48+
<attribute name="maven.pomderived" value="true"/>
49+
</attributes>
50+
</classpathentry>
51+
<classpathentry kind="output" path="target/classes"/>
2452
</classpath>

.project

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
<arguments>
1111
</arguments>
1212
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
1318
</buildSpec>
1419
<natures>
15-
<nature>net.sourceforge.texlipse.builder.TexlipseNature</nature>
1620
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
1722
</natures>
1823
</projectDescription>

libs/AXMLPrinter2.jar

-27.4 KB
Binary file not shown.

libs/asm-debug-all-5.1.jar

-376 KB
Binary file not shown.

libs/dexlib2-2.2.1.jar

-918 KB
Binary file not shown.

libs/guava-18.0.jar

-2.15 MB
Binary file not shown.

libs/hamcrest-all-1.3.jar

-299 KB
Binary file not shown.

libs/javassist-3.18.2-GA.jar

-698 KB
Binary file not shown.
-563 KB
Binary file not shown.

libs/junit-4.11.jar

-239 KB
Binary file not shown.

libs/mockito-all-1.10.8.jar

-1.16 MB
Binary file not shown.

libs/polyglot.jar

-845 KB
Binary file not shown.

libs/powermock-mockito-1.6.1-full.jar

-578 KB
Binary file not shown.

libs/slf4j-api-1.7.5.jar

-25.5 KB
Binary file not shown.

libs/slf4j-simple-1.7.5.jar

-10.4 KB
Binary file not shown.

libs/util-2.2.1.jar

-70.6 KB
Binary file not shown.

pom.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@
257257
</plugins>
258258
</build>
259259
<dependencies>
260+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
261+
<dependency>
262+
<groupId>commons-io</groupId>
263+
<artifactId>commons-io</artifactId>
264+
<version>2.6</version>
265+
</dependency>
260266
<dependency>
261267
<groupId>org.smali</groupId>
262268
<artifactId>dexlib2</artifactId>
@@ -311,9 +317,9 @@
311317
</dependency>
312318
<!-- local dependency -->
313319
<dependency>
314-
<groupId>ca.mcgill.sable</groupId>
315-
<artifactId>axmlprinter</artifactId>
316-
<version>2016-07-27</version>
320+
<groupId>pxb.android</groupId>
321+
<artifactId>axml</artifactId>
322+
<version>2.0.0-SNAPSHOT</version>
317323
</dependency>
318324
<!-- Testing dependencies -->
319325
<dependency>

src/soot/Scene.java

+58-62
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@
4949
import java.util.zip.ZipEntry;
5050
import java.util.zip.ZipFile;
5151

52-
import org.xmlpull.v1.XmlPullParser;
52+
import org.apache.commons.io.IOUtils;
5353

54-
import android.content.res.AXmlResourceParser;
54+
import pxb.android.axml.AxmlReader;
55+
import pxb.android.axml.AxmlVisitor;
56+
import pxb.android.axml.NodeVisitor;
5557
import soot.dexpler.DalvikThrowAnalysis;
5658
import soot.jimple.spark.internal.ClientAccessibilityOracle;
5759
import soot.jimple.spark.internal.PublicAndProtectedAccessibility;
@@ -72,7 +74,6 @@
7274
import soot.util.MapNumberer;
7375
import soot.util.Numberer;
7476
import soot.util.StringNumberer;
75-
import test.AXMLPrinter;
7677

7778
/** Manages the SootClasses of the application being analyzed. */
7879
public class Scene // extends AbstractHost
@@ -395,6 +396,14 @@ else if (apk != null)
395396
return androidAPIVersion;
396397
}
397398

399+
private static class AndroidVersionInfo {
400+
401+
public int sdkTargetVersion = -1;
402+
public int minSdkVersion = -1;
403+
public int platformBuildVersionCode = -1;
404+
405+
}
406+
398407
private int getTargetSDKVersion(String apkFile, String platformJARs) {
399408
// get AndroidManifest
400409
InputStream manifestIS = null;
@@ -423,75 +432,63 @@ private int getTargetSDKVersion(String apkFile, String platformJARs) {
423432

424433
// process AndroidManifest.xml
425434
int maxAPI = getMaxAPIAvailable(platformJARs);
426-
int sdkTargetVersion = -1;
427-
int minSdkVersion = -1;
428-
int platformBuildVersionCode = -1;
435+
final AndroidVersionInfo versionInfo = new AndroidVersionInfo();
429436
try {
430-
AXmlResourceParser parser = new AXmlResourceParser();
431-
parser.open(manifestIS);
432-
int depth = 0;
433-
loop: while (true) {
434-
int type = parser.next();
435-
switch (type) {
436-
case XmlPullParser.START_DOCUMENT: {
437-
break;
438-
}
439-
case XmlPullParser.END_DOCUMENT:
440-
break loop;
441-
case XmlPullParser.START_TAG: {
442-
depth++;
443-
String tagName = parser.getName();
444-
if (depth == 1 && tagName.equals("manifest")) {
445-
for (int i = 0; i != parser.getAttributeCount(); ++i) {
446-
String attributeName = parser.getAttributeName(i);
447-
String attributeValue = AXMLPrinter.getAttributeValue(parser, i);
448-
if (attributeName.equals("platformBuildVersionCode")) {
449-
platformBuildVersionCode = Integer.parseInt(attributeValue);
450-
}
451-
}
452-
} else if (depth == 2 && tagName.equals("uses-sdk")) {
453-
for (int i = 0; i != parser.getAttributeCount(); ++i) {
454-
String attributeName = parser.getAttributeName(i);
455-
String attributeValue = AXMLPrinter.getAttributeValue(parser, i);
456-
if (attributeName.equals("targetSdkVersion")) {
457-
sdkTargetVersion = Integer.parseInt(attributeValue);
458-
} else if (attributeName.equals("minSdkVersion")) {
459-
minSdkVersion = Integer.parseInt(attributeValue);
460-
}
437+
AxmlReader xmlReader = new AxmlReader(IOUtils.toByteArray(manifestIS));
438+
xmlReader.accept(new AxmlVisitor() {
439+
440+
private String nodeName = null;
441+
442+
@Override
443+
public void attr(String ns, String name, int resourceId, int type, Object obj) {
444+
super.attr(ns, name, resourceId, type, obj);
445+
446+
if (nodeName != null && name != null) {
447+
if (nodeName.equals("manifest")) {
448+
if (name.equals("platformBuildVersionCode"))
449+
versionInfo.platformBuildVersionCode = Integer.valueOf("" + obj);
450+
} else if (nodeName.equals("uses-sdk")) {
451+
if (name.equals("targetSdkVersion"))
452+
versionInfo.sdkTargetVersion = Integer.valueOf("" + obj);
453+
else if (name.equals("minSdkVersion"))
454+
versionInfo.minSdkVersion = Integer.valueOf("" + obj);
461455
}
462456
}
463-
break;
464457
}
465-
case XmlPullParser.END_TAG:
466-
depth--;
467-
break;
468-
case XmlPullParser.TEXT:
469-
break;
458+
459+
@Override
460+
public NodeVisitor child(String ns, String name) {
461+
nodeName = name;
462+
463+
return this;
470464
}
471-
}
465+
466+
});
472467
} catch (Exception e) {
473468
e.printStackTrace();
474469
}
475470

476471
int APIVersion = -1;
477-
if (sdkTargetVersion != -1) {
478-
if (sdkTargetVersion > maxAPI && minSdkVersion != -1 && minSdkVersion <= maxAPI) {
479-
G.v().out.println("warning: Android API version '" + sdkTargetVersion
480-
+ "' not available, using minApkVersion '" + minSdkVersion + "' instead");
481-
APIVersion = minSdkVersion;
472+
if (versionInfo.sdkTargetVersion != -1) {
473+
if (versionInfo.sdkTargetVersion > maxAPI && versionInfo.minSdkVersion != -1
474+
&& versionInfo.minSdkVersion <= maxAPI) {
475+
G.v().out.println("warning: Android API version '" + versionInfo.sdkTargetVersion
476+
+ "' not available, using minApkVersion '" + versionInfo.minSdkVersion + "' instead");
477+
APIVersion = versionInfo.minSdkVersion;
482478
} else {
483-
APIVersion = sdkTargetVersion;
479+
APIVersion = versionInfo.sdkTargetVersion;
484480
}
485-
} else if (platformBuildVersionCode != -1) {
486-
if (platformBuildVersionCode > maxAPI && minSdkVersion != -1 && minSdkVersion <= maxAPI) {
487-
G.v().out.println("warning: Android API version '" + platformBuildVersionCode
488-
+ "' not available, using minApkVersion '" + minSdkVersion + "' instead");
489-
APIVersion = minSdkVersion;
481+
} else if (versionInfo.platformBuildVersionCode != -1) {
482+
if (versionInfo.platformBuildVersionCode > maxAPI && versionInfo.minSdkVersion != -1
483+
&& versionInfo.minSdkVersion <= maxAPI) {
484+
G.v().out.println("warning: Android API version '" + versionInfo.platformBuildVersionCode
485+
+ "' not available, using minApkVersion '" + versionInfo.minSdkVersion + "' instead");
486+
APIVersion = versionInfo.minSdkVersion;
490487
} else {
491-
APIVersion = platformBuildVersionCode;
488+
APIVersion = versionInfo.platformBuildVersionCode;
492489
}
493-
} else if (minSdkVersion != -1) {
494-
APIVersion = minSdkVersion;
490+
} else if (versionInfo.minSdkVersion != -1) {
491+
APIVersion = versionInfo.minSdkVersion;
495492
} else {
496493
G.v().out
497494
.println("Could not find sdk version in Android manifest! Using default: " + defaultSdkVersion);
@@ -928,7 +925,7 @@ public RefType getRefType(String className) {
928925
* with the given name can be found.
929926
*/
930927
public RefType getRefTypeUnsafe(String className) {
931-
RefType refType = nameToClass.get(className);
928+
RefType refType = nameToClass.get(className);
932929
return refType;
933930
}
934931

@@ -961,9 +958,8 @@ public SootClass getSootClassUnsafe(String className) {
961958
if (tsc != null)
962959
return tsc;
963960
}
964-
965-
if (allowsPhantomRefs() ||
966-
className.equals(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME)) {
961+
962+
if (allowsPhantomRefs() || className.equals(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME)) {
967963
SootClass c = new SootClass(className);
968964
c.isPhantom = true;
969965
addClassSilent(c);

0 commit comments

Comments
 (0)