blob: 0b67ef0bbc4510510177a3d76034cba0f9e5fd02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package eu.chainfire.librootjava;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import androidx.annotation.NonNull;
/**
* A helper to create custom broadcasts
* Should be synced with {@link eu.chainfire.librootjava.RootIPC}.
*/
public class IPCBroadcastHelper {
public static Intent buildStickyBroadcastIntent (@NonNull RootIPC rootIPC) throws NoSuchFieldException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// RootIPC.java part
Field fIBinder = rootIPC.getClass().getDeclaredField("binder");
Field fCode = rootIPC.getClass().getDeclaredField("code");
Field fPackageName = rootIPC.getClass().getDeclaredField("packageName");
fIBinder.setAccessible(true);
fCode.setAccessible(true);
fPackageName.setAccessible(true);
Intent intent = new Intent();
intent.setPackage((String) fPackageName.get(rootIPC));
intent.setAction(RootIPCReceiver.BROADCAST_ACTION);
Bundle bundle = new Bundle();
bundle.putBinder(RootIPCReceiver.BROADCAST_BINDER, (IBinder) fIBinder.get(rootIPC));
bundle.putInt(RootIPCReceiver.BROADCAST_CODE, fCode.getInt(rootIPC));
intent.putExtra(RootIPCReceiver.BROADCAST_EXTRA, bundle);
// Reflection.java part
Method mGetFlagReceiverFromShell = Reflection.class.getDeclaredMethod("getFlagReceiverFromShell");
mGetFlagReceiverFromShell.setAccessible(true);
intent.setFlags((int) mGetFlagReceiverFromShell.invoke(null));
return intent;
}
}
|