Skip to content

Commit 746f8dd

Browse files
committed
添加跨进程数据共享
1 parent 4370092 commit 746f8dd

File tree

19 files changed

+320
-40
lines changed

19 files changed

+320
-40
lines changed

app/src/main/java/com/wrbug/developerhelper/DeveloperApplication.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.wrbug.developerhelper
22

33
import android.os.Handler
44
import android.os.Looper
5+
import com.elvishew.xlog.LogConfiguration
56
import com.elvishew.xlog.LogLevel
67
import com.elvishew.xlog.XLog
8+
import com.elvishew.xlog.internal.DefaultsFactory
79
import com.wrbug.developerhelper.basecommon.BaseApp
810
import com.wrbug.developerhelper.commonutil.CommonUtils
911
import com.wrbug.developerhelper.mmkv.manager.MMKVManager
@@ -35,7 +37,10 @@ class DeveloperApplication : BaseApp() {
3537
super.onCreate()
3638
registerModule()
3739
instance = this
38-
XLog.init(LogLevel.ALL)
40+
XLog.init(
41+
LogConfiguration.Builder().logLevel(LogLevel.ALL).tag("developerHelper-->").build(),
42+
DefaultsFactory.createPrinter()
43+
)
3944
releaseAssetsFile()
4045
}
4146

app/src/main/java/com/wrbug/developerhelper/util/FileUtils.kt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,6 @@ object FileUtils {
3232

3333
}
3434

35-
fun readFile(file: File): String {
36-
val builder = StringBuilder()
37-
try {
38-
val fr = FileReader(file)
39-
var ch = fr.read()
40-
while (ch != -1) {
41-
builder.append(ch.toChar())
42-
ch = fr.read()
43-
}
44-
} catch (e: IOException) {
45-
}
46-
47-
return builder.toString()
48-
}
49-
50-
fun whiteFile(file: File, data: String) {
51-
try {
52-
if (!file.exists()) {
53-
file.createNewFile()
54-
}
55-
val fw = FileWriter(file)
56-
fw.write(data)
57-
fw.flush()
58-
} catch (e: IOException) {
59-
}
60-
61-
}
6235

6336
fun whiteXml(file: File, document: Document) {
6437
try {
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.wrbug.developerhelper.commonutil
2+
3+
object Base64 {
4+
5+
private val alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
6+
.toCharArray()
7+
private val codes = ByteArray(256)
8+
/* 将原始数据编码为base64编码
9+
*/
10+
fun encodeAsString(data: ByteArray): String {
11+
return String(encode(data))
12+
}
13+
14+
fun encode(data: ByteArray): CharArray {
15+
val out = CharArray((data.size + 2) / 3 * 4)
16+
var i = 0
17+
var index = 0
18+
while (i < data.size) {
19+
var quad = false
20+
var trip = false
21+
var value = 0xFF and data[i].toInt()
22+
value = value shl 8
23+
if (i + 1 < data.size) {
24+
value = value or (0xFF and data[i + 1].toInt())
25+
trip = true
26+
}
27+
value = value shl 8
28+
if (i + 2 < data.size) {
29+
value = value or (0xFF and data[i + 2].toInt())
30+
quad = true
31+
}
32+
out[index + 3] = alphabet[if (quad) value and 0x3F else 64]
33+
value = value shr 6
34+
out[index + 2] = alphabet[if (trip) value and 0x3F else 64]
35+
value = value shr 6
36+
out[index + 1] = alphabet[value and 0x3F]
37+
value = value shr 6
38+
out[index + 0] = alphabet[value and 0x3F]
39+
i += 3
40+
index += 4
41+
}
42+
return out
43+
}
44+
45+
/**
46+
* 将base64编码的数据解码成原始数据
47+
*/
48+
fun decode(data: CharArray): ByteArray {
49+
var len = (data.size + 3) / 4 * 3
50+
if (data.size > 0 && data[data.size - 1] == '=')
51+
--len
52+
if (data.size > 1 && data[data.size - 2] == '=')
53+
--len
54+
val out = ByteArray(len)
55+
var shift = 0
56+
var accum = 0
57+
var index = 0
58+
for (ix in data.indices) {
59+
val value = codes[data[ix].toInt() and 0xFF].toInt()
60+
if (value >= 0) {
61+
accum = accum shl 6
62+
shift += 6
63+
accum = accum or value
64+
if (shift >= 8) {
65+
shift -= 8
66+
out[index++] = (accum shr shift and 0xff).toByte()
67+
}
68+
}
69+
}
70+
if (index != out.size)
71+
throw Error("miscalculated data length!")
72+
return out
73+
}
74+
75+
fun decode(data: String?): String {
76+
if (data.isNullOrEmpty()) {
77+
return ""
78+
}
79+
return String(decode(data.toCharArray()))
80+
}
81+
82+
init {
83+
for (i in 0..255)
84+
codes[i] = -1
85+
run {
86+
var i: Int = 'A'.toInt()
87+
while (i <= 'Z'.toInt()) {
88+
codes[i] = (i - 'A'.toInt()).toByte()
89+
i++
90+
}
91+
}
92+
run {
93+
var i: Int = 'a'.toInt()
94+
while (i <= 'z'.toInt()) {
95+
codes[i] = (26 + i - 'a'.toInt()).toByte()
96+
i++
97+
}
98+
}
99+
var i: Int = '0'.toInt()
100+
while (i <= '9'.toInt()) {
101+
codes[i] = (52 + i - '0'.toInt()).toByte()
102+
i++
103+
}
104+
codes['+'.toInt()] = 62
105+
codes['/'.toInt()] = 63
106+
}
107+
// public static void main(String[] args) throws Exception {
108+
// // 加密成base64
109+
// String strSrc = "林";
110+
// String strOut = new String(Base64.encode(strSrc.getBytes("GB18030")));
111+
// System.out.println(strOut);
112+
//
113+
// }
114+
115+
}

xposedmodule/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ dependencies {
4949
implementation project(':mmkv')
5050
compileOnly 'de.robv.android.xposed:api:82'
5151
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
52+
implementation 'com.google.code.gson:gson:2.8.5'
53+
5254
}
5355
repositories {
5456
mavenCentral()

xposedmodule/src/main/cpp/inlineHook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ created time: 2015-11-30
2525
#ifndef PAGE_SIZE
2626
#define PAGE_SIZE 4096
2727
#endif
28-
#define TAG "developerhelper.native-->"
28+
#define TAG "developerhelper.xposed.inlineHook.native-->"
2929

3030
#define PAGE_START(addr) (~(PAGE_SIZE - 1) & (addr))
3131
#define SET_BIT0(addr) (addr | 1)

xposedmodule/src/main/cpp/native.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "native.h"
55
#include "inlineHook.h"
66

7-
#define TAG "developerhelper.native-->"
7+
#define TAG "developerhelper.xposed.native.native-->"
88

99

1010
JNIEXPORT void JNICALL Java_com_wrbug_developerhelper_xposed_dumpdex_Native_dump

xposedmodule/src/main/cpp/util/deviceutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "deviceutils.h"
77
#include "fileutils.h"
88

9-
#define TAG "developerhelper.native-->"
9+
#define TAG "developerhelper.xposed.deviceutils.native-->"
1010

1111
const static long DEX_MIN_LEN = 102400L;
1212
static int sdk_int = 0;

xposedmodule/src/main/cpp/util/fileutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "fileutils.h"
77

8-
#define TAG "developerhelper.native-->"
8+
#define TAG "developerhelper.xposed.fileutils.native-->"
99

1010
static char pname[256];
1111

xposedmodule/src/main/java/com/wrbug/developerhelper/xposed/Exts.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun Throwable.xposedLog() {
1010
}
1111

1212

13-
fun String.xposedLog(tag: String = "developerhelper--> ") {
13+
fun String.xposedLog(tag: String = "developerhelper.xposed--> ") {
1414
XposedBridge.log(tag + this)
1515
}
1616

xposedmodule/src/main/java/com/wrbug/developerhelper/xposed/developerhelper/DeveloperHelper.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import android.view.View
66
import com.jaredrummler.android.shell.Shell
77
import com.wrbug.developerhelper.commonutil.shell.ShellManager
88
import com.wrbug.developerhelper.xposed.dumpdex.Native
9+
import com.wrbug.developerhelper.xposed.processshare.DumpDexListProcessData
10+
import com.wrbug.developerhelper.xposed.processshare.ProcessDataManager
911
import com.wrbug.developerhelper.xposed.saveToFile
1012
import com.wrbug.developerhelper.xposed.xposedLog
1113
import de.robv.android.xposed.XC_MethodHook
@@ -52,6 +54,7 @@ object DeveloperHelper {
5254
if (result) {
5355
"设备已root,开始释放so文件".xposedLog()
5456
doAsync {
57+
initProcessDataDir()
5558
saveSo(activity, Native.SO_FILE)
5659
saveSo(activity, Native.SO_FILE_V7a)
5760
saveSo(activity, Native.SO_FILE_V8a)
@@ -62,6 +65,19 @@ object DeveloperHelper {
6265
})
6366
}
6467

68+
private fun initProcessDataDir() {
69+
"创建processdata目录".xposedLog()
70+
val dir = "/data/local/tmp/developerHelper"
71+
val commandResult = Shell.SU.run("mkdir -p $dir && chmod -R 777 $dir")
72+
if (commandResult.isSuccessful) {
73+
"processdata目录创建成功".xposedLog()
74+
} else {
75+
"processdata目录创建失败:${commandResult.getStderr()}".xposedLog()
76+
}
77+
val data = ProcessDataManager.get(DumpDexListProcessData::class.java)
78+
data.setData(listOf("com.qihoo.yunzuanbao"))
79+
}
80+
6581

6682
private fun saveSo(activity: Activity, fileName: String) {
6783
"正在释放$fileName".xposedLog()
@@ -71,6 +87,14 @@ object DeveloperHelper {
7187
"已获取asset".xposedLog()
7288
val tmpFile = File(activity.cacheDir, fileName)
7389
inputStream.saveToFile(tmpFile)
74-
Shell.SU.run("mv ${tmpFile.absolutePath} ${soFile.absolutePath}", "chmod 777 ${soFile.absolutePath}")
90+
val commandResult =
91+
Shell.SU.run("mv ${tmpFile.absolutePath} ${soFile.absolutePath}", "chmod 777 ${soFile.absolutePath}")
92+
if (commandResult.isSuccessful) {
93+
"$fileName 释放成功".xposedLog()
94+
} else {
95+
"$fileName 释放失败:${commandResult.getStderr()}".xposedLog()
96+
97+
}
98+
7599
}
76100
}

0 commit comments

Comments
 (0)