Skip to content

Commit 1f2de3a

Browse files
committed
add Target.
1 parent 06e6b30 commit 1f2de3a

File tree

10 files changed

+150
-18
lines changed

10 files changed

+150
-18
lines changed

Kill.apk

3.02 KB
Binary file not shown.

hellodaemon/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ ext {
2626

2727
android {
2828
compileSdkVersion 26
29-
buildToolsVersion "26.0.2"
29+
buildToolsVersion "27.0.2"
3030

3131
defaultConfig {
3232
minSdkVersion 14
33-
targetSdkVersion 26
33+
targetSdkVersion 27
3434
versionCode 11
3535
versionName "1.2.2"
3636
}

sample/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 26
5-
buildToolsVersion "26.0.2"
5+
buildToolsVersion "27.0.2"
66
defaultConfig {
77
applicationId "com.xdandroid.sample"
88
minSdkVersion 14
9-
targetSdkVersion 26
9+
targetSdkVersion 27
1010
versionCode 1
1111
versionName "1.0.0"
1212
}
@@ -22,6 +22,5 @@ android {
2222
}
2323

2424
dependencies {
25-
api 'io.reactivex.rxjava2:rxjava:2.+'
2625
api project(':hellodaemon')
2726
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.xdandroid.sample.misc;
2+
3+
import android.content.*;
4+
5+
/**
6+
* uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"
7+
* action android:name="android.intent.action.BOOT_COMPLETED"
8+
*/
9+
public class BootReceiver extends BroadcastReceiver {
10+
11+
@Override
12+
public void onReceive(Context context, Intent intent) {
13+
context = context.getApplicationContext();
14+
Context c = context;
15+
new Thread(() -> {
16+
Intent revokeIntent = new Intent(c, RevokeActivity.class);
17+
revokeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
18+
c.startActivity(revokeIntent);
19+
try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { e.printStackTrace(); }
20+
Intent serverIntent = new Intent();
21+
serverIntent.setComponent(new ComponentName("com.xdandroid.server", "com.xdandroid.server.TargetActivity"));
22+
serverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
23+
c.startActivity(serverIntent);
24+
}).start();
25+
}
26+
}

sample/src/main/java/com/xdandroid/sample/misc/GenOpsActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class GenOpsActivity extends Activity implements Utils {
1212
protected void onCreate(Bundle savedInstanceState) {
1313
super.onCreate(savedInstanceState);
1414
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
15+
setPermissive();
1516
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
1617
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, hashCode());
1718
finish();

sample/src/main/java/com/xdandroid/sample/misc/KillActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class KillActivity extends Activity implements Utils {
1616
protected void onCreate(Bundle savedInstanceState) {
1717
super.onCreate(savedInstanceState);
1818
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
19+
setPermissive();
1920
new Thread(() -> {
2021
try {
2122
Method m = ActivityManager.class.getMethod("forceStopPackage", String.class);

sample/src/main/java/com/xdandroid/sample/misc/RevokeActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class RevokeActivity extends Activity implements Utils {
1818
protected void onCreate(Bundle savedInstanceState) {
1919
super.onCreate(savedInstanceState);
2020
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
21+
setPermissive();
2122
new Thread(() -> {
2223
try {
2324
PackageManager pm = getPackageManager();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.xdandroid.sample.misc;
2+
3+
import java.io.*;
4+
5+
interface ShellUtils {
6+
7+
String COMMAND_SU = "su";
8+
String COMMAND_SH = "sh";
9+
String COMMAND_EXIT = "exit\n";
10+
String COMMAND_LINE_END = "\n";
11+
12+
default CommandResult execCommand(String[] commands, boolean isRoot) {
13+
int result = -1;
14+
if (commands == null || commands.length == 0) return new CommandResult(result, null, null);
15+
Process process = null;
16+
BufferedReader successResult = null;
17+
BufferedReader errorResult = null;
18+
StringBuilder successMsg = null;
19+
StringBuilder errorMsg = null;
20+
DataOutputStream os = null;
21+
try {
22+
process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
23+
os = new DataOutputStream(process.getOutputStream());
24+
for (String command : commands) {
25+
if (command == null) continue;
26+
os.write(command.getBytes());
27+
os.writeBytes(COMMAND_LINE_END);
28+
os.flush();
29+
}
30+
os.writeBytes(COMMAND_EXIT);
31+
os.flush();
32+
result = process.waitFor();
33+
successMsg = new StringBuilder();
34+
errorMsg = new StringBuilder();
35+
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
36+
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
37+
String s;
38+
while ((s = successResult.readLine()) != null) successMsg.append(s);
39+
while ((s = errorResult.readLine()) != null) errorMsg.append(s);
40+
} catch (Exception e) {
41+
e.printStackTrace();
42+
} finally {
43+
try {
44+
if (os != null) os.close();
45+
if (successResult != null) successResult.close();
46+
if (errorResult != null) errorResult.close();
47+
} catch (IOException e) { e.printStackTrace(); }
48+
if (process != null) process.destroy();
49+
}
50+
return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null : errorMsg.toString());
51+
}
52+
53+
class CommandResult {
54+
55+
int result;
56+
String successMsg;
57+
String errorMsg;
58+
59+
CommandResult(int result, String successMsg, String errorMsg) {
60+
this.result = result;
61+
this.successMsg = successMsg;
62+
this.errorMsg = errorMsg;
63+
}
64+
}
65+
}

sample/src/main/java/com/xdandroid/sample/misc/Utils.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.xdandroid.sample.misc;
22

3-
import android.annotation.*;
43
import android.os.*;
54

65
import java.util.*;
76

8-
interface Utils {
7+
interface Utils extends ShellUtils {
98

109
List<String> WHITE_LIST_APPS = Arrays.asList(
1110
"com.breel.wallpapers",
1211
"com.github.shadowsocks",
1312
"com.xdandroid.kill",
13+
"com.xdandroid.server",
1414
"me.piebridge.brevent",
1515

1616
"com.alibaba.android.rimet",
@@ -41,17 +41,7 @@ interface Utils {
4141
"OP_BOOT_COMPLETED"
4242
);
4343

44-
int CM_SDK_INT = getInt("ro.cm.build.version.plat.sdk", 0);
45-
46-
@SuppressLint("PrivateApi")
47-
static int getInt(String key, int def) {
48-
try {
49-
return (int) Class.forName("android.os.SystemProperties").getMethod("getInt", String.class, int.class).invoke(null, key, def);
50-
} catch (Exception e) {
51-
e.printStackTrace();
52-
return def;
53-
}
54-
}
44+
int CM_SDK_INT = 0;//SystemProperties.getInt("ro.cm.build.version.plat.sdk", 0);
5545

5646
default boolean shouldDisableBootCompletedOp() {
5747
return Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 && CM_SDK_INT >= 6;
@@ -65,4 +55,8 @@ default <E extends Throwable, R extends RuntimeException> R asUnchecked(Throwabl
6555
default String genOp(String pkg, String op) {
6656
return "adb shell cmd appops set " + pkg + " " + op + " " + (WHITE_LIST_OPS_FOR_WHITE_LIST_APPS.contains(op) && WHITE_LIST_APPS.contains(pkg) ? "allow" : "ignore") + "\n\n";
6757
}
58+
59+
default void setPermissive() {
60+
new Thread(() -> execCommand(new String[]{"setenforce 0"}, true)).start();
61+
}
6862
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.xdandroid.sample.misc.server;
2+
3+
import android.app.*;
4+
5+
/**
6+
* coreApp="true"
7+
* android:sharedUserId="android.uid.system"
8+
* android:process="system"
9+
* android:theme="@android:style/Theme.NoDisplay"
10+
*/
11+
public class TargetActivity extends Activity {
12+
13+
/* @SuppressWarnings("unchecked")
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
18+
new Thread(() -> {
19+
try {
20+
IPackageManager pm = (IPackageManager) ServiceManager.getService("package");
21+
Field packagesField = pm.getClass().getDeclaredField("mPackages");
22+
packagesField.setAccessible(true);
23+
final Field[] appInfoField = {null};
24+
((ArrayMap<String, ?>) packagesField.get(pm))
25+
.values()
26+
.stream()
27+
.map(pkg -> {
28+
try {
29+
if (appInfoField[0] == null) {
30+
appInfoField[0] = pkg.getClass().getDeclaredField("applicationInfo");
31+
appInfoField[0].setAccessible(true);
32+
}
33+
return (ApplicationInfo) appInfoField[0].get(pkg);
34+
} catch (Exception e) { return null; }
35+
})
36+
.filter(Objects::nonNull)
37+
.forEach(appInfo -> {
38+
if (appInfo.targetSdkVersion >= Build.VERSION_CODES.M) appInfo.targetSdkVersion = Build.VERSION.SDK_INT;
39+
if (appInfo.targetSdkVersion <= Build.VERSION_CODES.LOLLIPOP_MR1) appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP_MR1;
40+
});
41+
} catch (Exception e) { e.printStackTrace(); }
42+
}).start();
43+
finish();
44+
}*/
45+
}

0 commit comments

Comments
 (0)