Skip to content

Commit 43c4c92

Browse files
LoveSykotori2
LoveSy
authored andcommitted
Use AXML instead of Apkparser
1 parent 76f438f commit 43c4c92

31 files changed

+2805
-26
lines changed

Diff for: .gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[submodule "edxp-core/src/main/cpp/external/Dobby"]
22
path = edxp-core/src/main/cpp/external/Dobby
33
url = https://github.com/jmpews/Dobby.git
4-
[submodule "apk-parser"]
5-
path = apk-parser
6-
url = https://github.com/jaredrummler/APKParser.git

Diff for: edxp-common/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies {
2525
api project(':xposed-bridge')
2626
compileOnly project(':dexmaker')
2727
compileOnly 'com.android.support:support-annotations:28.0.0'
28-
implementation project(':apk-parser:library')
2928
}
3029

3130

Diff for: edxp-common/src/main/java/com/elderdrivers/riru/edxp/_hooker/impl/HandleBindApp.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313
import com.elderdrivers.riru.edxp.config.ConfigManager;
1414
import com.elderdrivers.riru.edxp.util.Hookers;
15+
import com.elderdrivers.riru.edxp.util.MetaDataReader;
1516
import com.elderdrivers.riru.edxp.util.Utils;
16-
import com.jaredrummler.apkparser.ApkParser;
1717

1818
import java.io.File;
1919
import java.io.IOException;
20+
import java.util.Map;
2021

2122
import de.robv.android.xposed.XC_MethodHook;
2223
import de.robv.android.xposed.XposedBridge;
@@ -61,11 +62,12 @@ protected void beforeHookedMethod(MethodHookParam param) {
6162
boolean isModule = false;
6263
int xposedminversion = -1;
6364
boolean xposedsharedprefs = false;
64-
try (ApkParser ap = ApkParser.create(new File(appInfo.sourceDir))){
65-
isModule = ap.getApkMeta().metaData.containsKey("xposedmodule");
65+
try {
66+
Map<String, Object> metaData = MetaDataReader.getMetaData(new File(appInfo.sourceDir));
67+
isModule = metaData.containsKey("xposedmodule");
6668
if (isModule) {
67-
xposedminversion = Integer.parseInt(ap.getApkMeta().metaData.get("xposedminversion"));
68-
xposedsharedprefs = ap.getApkMeta().metaData.containsKey("xposedsharedprefs");
69+
xposedminversion = (Integer) metaData.get("xposedminversion");
70+
xposedsharedprefs = metaData.containsKey("xposedsharedprefs");
6971
}
7072
} catch (NumberFormatException | IOException e) {
7173
Hookers.logE("ApkParser fails", e);

Diff for: settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':edxp-core', ':xposed-bridge', ':hiddenapi-stubs', ':dexmaker', ':dalvikdx', ':edxp-common', ':edxp-yahfa', ':edxp-sandhook', ':edxp-service', ':apk-parser:library', ':sandhook-hooklib', ':sandhook-annotation'
1+
include ':edxp-core', ':xposed-bridge', ':hiddenapi-stubs', ':dexmaker', ':dalvikdx', ':edxp-common', ':edxp-yahfa', ':edxp-sandhook', ':edxp-service', ':sandhook-hooklib', ':sandhook-annotation'

Diff for: xposed-bridge/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ preBuild.doLast {
4343
}
4444

4545
dependencies {
46-
compileOnly project(':apk-parser:library')
4746
compileOnly files(project(":dexmaker").tasks.getByName("makeJarRelease").outputs)
4847
compileOnly files(project(":hiddenapi-stubs").tasks.getByName("makeStubJar").outputs)
4948
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.elderdrivers.riru.edxp.util;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.jar.JarFile;
10+
11+
import pxb.android.axml.AxmlReader;
12+
import pxb.android.axml.AxmlVisitor;
13+
import pxb.android.axml.NodeVisitor;
14+
15+
public class MetaDataReader {
16+
private final HashMap<String, Object> metaData = new HashMap<>();
17+
18+
public static Map<String, Object> getMetaData(File apk) throws IOException {
19+
return new MetaDataReader(apk).metaData;
20+
}
21+
22+
private MetaDataReader(File apk) throws IOException {
23+
JarFile zip = new JarFile(apk);
24+
InputStream is = zip.getInputStream(zip.getEntry("AndroidManifest.xml"));
25+
byte[] bytes = getBytesFromInputStream(is);
26+
AxmlReader reader = new AxmlReader(bytes);
27+
reader.accept(new AxmlVisitor() {
28+
@Override
29+
public NodeVisitor child(String ns, String name) {
30+
NodeVisitor child = super.child(ns, name);
31+
return new ManifestTagVisitor(child);
32+
}
33+
});
34+
}
35+
36+
public static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException {
37+
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
38+
byte[] b = new byte[1024];
39+
int n;
40+
while ((n = inputStream.read(b)) != -1) {
41+
bos.write(b, 0, n);
42+
}
43+
byte[] data = bos.toByteArray();
44+
return data;
45+
} catch (Exception e) {
46+
e.printStackTrace();
47+
}
48+
return null;
49+
}
50+
51+
private class ManifestTagVisitor extends NodeVisitor {
52+
public ManifestTagVisitor(NodeVisitor child) {
53+
super(child);
54+
}
55+
56+
@Override
57+
public NodeVisitor child(String ns, String name) {
58+
NodeVisitor child = super.child(ns, name);
59+
if ("application".equals(name)) {
60+
return new ApplicationTagVisitor(child);
61+
}
62+
return child;
63+
}
64+
65+
private class ApplicationTagVisitor extends NodeVisitor {
66+
public ApplicationTagVisitor(NodeVisitor child) {
67+
super(child);
68+
}
69+
70+
@Override
71+
public NodeVisitor child(String ns, String name) {
72+
NodeVisitor child = super.child(ns, name);
73+
if("meta-data".equals(name)) {
74+
return new MetaDataVisitor(child);
75+
}
76+
return child;
77+
}
78+
}
79+
}
80+
81+
private class MetaDataVisitor extends NodeVisitor {
82+
public String name = null;
83+
public Object value = null;
84+
public MetaDataVisitor(NodeVisitor child) {
85+
super(child);
86+
}
87+
88+
@Override
89+
public void attr(String ns, String name, int resourceId, int type, Object obj) {
90+
if (type == 3 && "name".equals(name)) {
91+
this.name = (String)obj;
92+
}
93+
if ("value".equals(name) ) {
94+
value = obj;
95+
}
96+
super.attr(ns, name, resourceId, type, obj);
97+
}
98+
99+
@Override
100+
public void end() {
101+
if(name != null && value != null) {
102+
metaData.put(name, value);
103+
}
104+
super.end();
105+
}
106+
}
107+
}

Diff for: xposed-bridge/src/main/java/de/robv/android/xposed/PendingHooks.java

-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package de.robv.android.xposed;
22

3-
import com.elderdrivers.riru.edxp.config.EdXpConfigGlobal;
4-
import com.jaredrummler.apkparser.utils.Utils;
5-
63
import java.lang.reflect.Member;
7-
import java.lang.reflect.Modifier;
8-
import java.util.HashSet;
94
import java.util.Map;
105
import java.util.concurrent.ConcurrentHashMap;
116
import java.util.function.Function;
127

138
import static de.robv.android.xposed.XposedBridge.hookMethodNative;
14-
import static de.robv.android.xposed.XposedBridge.log;
159

1610
public final class PendingHooks {
1711

Diff for: xposed-bridge/src/main/java/de/robv/android/xposed/XSharedPreferences.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package de.robv.android.xposed;
22

33
import android.annotation.SuppressLint;
4-
import android.app.ActivityThread;
54
import android.content.Context;
65
import android.content.SharedPreferences;
7-
import android.content.pm.PackageInfo;
8-
import android.content.pm.PackageManager;
96
import android.os.Environment;
107
import android.preference.PreferenceManager;
118
import android.util.Log;
129

1310
import com.android.internal.util.XmlUtils;
14-
import com.jaredrummler.apkparser.ApkParser;
11+
import com.elderdrivers.riru.edxp.util.MetaDataReader;
1512

1613
import org.xmlpull.v1.XmlPullParserException;
1714

@@ -76,11 +73,12 @@ public XSharedPreferences(String packageName, String prefFileName) {
7673
boolean isModule = false;
7774
int xposedminversion = -1;
7875
boolean xposedsharedprefs = false;
79-
try (ApkParser ap = ApkParser.create(new File(m))) {
80-
isModule = ap.getApkMeta().metaData.containsKey("xposedmodule");
81-
if(isModule) {
82-
xposedminversion = Integer.parseInt(ap.getApkMeta().metaData.get("xposedminversion"));
83-
xposedsharedprefs = ap.getApkMeta().metaData.containsKey("xposedsharedprefs");
76+
try {
77+
Map<String, Object> metaData = MetaDataReader.getMetaData(new File(m));
78+
isModule = metaData.containsKey("xposedmodule");
79+
if (isModule) {
80+
xposedminversion = (Integer) metaData.get("xposedminversion");
81+
xposedsharedprefs = metaData.containsKey("xposedsharedprefs");
8482
}
8583
} catch (NumberFormatException | IOException e) {
8684
Log.w(TAG, "Apk parser fails: " + e);
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2009-2013 Panxiaobo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pxb.android;
17+
18+
public interface ResConst {
19+
int RES_STRING_POOL_TYPE = 0x0001;
20+
int RES_TABLE_TYPE = 0x0002;
21+
int RES_TABLE_PACKAGE_TYPE = 0x0200;
22+
int RES_TABLE_TYPE_SPEC_TYPE = 0x0202;
23+
int RES_TABLE_TYPE_TYPE = 0x0201;
24+
25+
int RES_XML_TYPE = 0x0003;
26+
int RES_XML_RESOURCE_MAP_TYPE = 0x0180;
27+
int RES_XML_END_NAMESPACE_TYPE = 0x0101;
28+
int RES_XML_END_ELEMENT_TYPE = 0x0103;
29+
int RES_XML_START_NAMESPACE_TYPE = 0x0100;
30+
int RES_XML_START_ELEMENT_TYPE = 0x0102;
31+
int RES_XML_CDATA_TYPE = 0x0104;
32+
33+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2009-2013 Panxiaobo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pxb.android;
17+
18+
public class StringItem {
19+
public String data;
20+
public int dataOffset;
21+
public int index;
22+
23+
public StringItem() {
24+
super();
25+
}
26+
27+
public StringItem(String data) {
28+
super();
29+
this.data = data;
30+
}
31+
32+
@Override
33+
public boolean equals(Object obj) {
34+
if (this == obj)
35+
return true;
36+
if (obj == null)
37+
return false;
38+
if (getClass() != obj.getClass())
39+
return false;
40+
StringItem other = (StringItem) obj;
41+
if (data == null) {
42+
if (other.data != null)
43+
return false;
44+
} else if (!data.equals(other.data))
45+
return false;
46+
return true;
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
final int prime = 31;
52+
int result = 1;
53+
result = prime * result + ((data == null) ? 0 : data.hashCode());
54+
return result;
55+
}
56+
57+
public String toString() {
58+
return String.format("S%04d %s", index, data);
59+
}
60+
61+
}

0 commit comments

Comments
 (0)