How to save & load module settings after MODE_WORLD_READABLE is gone? - Xposed General

According to document, trying to use MODE_WORLD_READABLE will crash the module UI with a SecurityException.
I've tried to use a ContentProvider, but unable to get the Context object in handleLoadPackage (Illegal state).
Is there any better way?

Tried to downgrade targetSdkVersion, the app no longer crashes but XSharedPreferences still can't read the file (the preferences file is already world readable)

You can use Remotepreferences (awesome library!). You will need a context however, so it is not suitable for methods in initzigote or where you can't access the context. I think is the only way as of now.

Massi-X said:
You can use Remotepreferences (awesome library!). You will need a context however, so it is not suitable for methods in initzigote or where you can't access the context. I think is the only way as of now.
Click to expand...
Click to collapse
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
And add the following on class level.
Code:
@Override
public void onPause() {
super.onPause();
// Set preferences permissions to be world readable
// Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
final File prefsDir = new File(dataDir, "shared_prefs");
final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (prefsFile.exists()) {
dataDir.setReadable(true, false);
dataDir.setExecutable(true, false);
prefsDir.setReadable(true, false);
prefsDir.setExecutable(true, false);
prefsFile.setReadable(true, false);
prefsFile.setExecutable(true, false);
}
}
This method will work on any sdk :good:
I tested it myself and it is working fine.
Thanks to @PunchUp @pyler

laura almeida said:
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
And add the following on class level.
Code:
@Override
public void onPause() {
super.onPause();
// Set preferences permissions to be world readable
// Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
final File prefsDir = new File(dataDir, "shared_prefs");
final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (prefsFile.exists()) {
dataDir.setReadable(true, false);
dataDir.setExecutable(true, false);
prefsDir.setReadable(true, false);
prefsDir.setExecutable(true, false);
prefsFile.setReadable(true, false);
prefsFile.setExecutable(true, false);
}
}
This method will work on any sdk :good:
I tested it myself and it is working fine.
Thanks to @PunchUp @pyler
Click to expand...
Click to collapse
Yeah but it seems an hacky thing. It will work with any Android? With selinux enabled? On custom ROMs? Surely Remotepreferences complicate things but is the best way (also for previous Android versions) of reading the preferences file. Anyway this can be another solution :good:
EDIT: I also found in marshmallow my apps was randomly failing reading the preferences (no real reason) and Remotepreferences solved the problem.

Massi-X said:
Remotepreferences will complicate things.
The easiest way to do is to remove the below line
And add the following on class level.
Yeah but it seems an hacky thing. It will work with any Android? With selinux enabled? On custom ROMs? Surely Remotepreferences complicate things but is the best way (also for previous Android versions) of reading the preferences file. Anyway this can be another solution :highfive:
Click to expand...
Click to collapse
With any android version - Yes
Will it work with previous android version - Yes
On custom ROMs - Yes
With selinux enabled ? - not tested yet. But I think it works.

laura almeida said:
With any android version - Yes
Will it work with previous android version - Yes
On custom ROMs - Yes
With selinux enabled ? - not tested yet. But I think it works.
Click to expand...
Click to collapse
Previous versions: I was speaking about another thing. See edit. Anyway it's another way, 2 is always better than 1.

Related

Development team V2

Hello everyone,
I want to start again with a development team. After miroslav decided to finish the project on his own, I want to try it again. But this time with a real team Only with people who want to participate, and not just type make. Who wants to join?
miroslav_mm said:
So, I opened your eyes and showed real face our "superstar"!?
Ok! Let's stop this stupid discussion and continuous develop ROM.
At this moment I have main part:
Torchscreen +
BT (BT-calling) +
WiFi (need to test) +
Sensor +
GSM (Waiting call) +
Mobile Data +
Audio +
Vibrate +
HW + 3D ??? (need new kernel or port new 3D kernel driver (kgsl) (in progress))
usb storage ??? (only with special app (native in progress))
Camera ??? (in progress)
Video codec ??? (in progress)
Anyone doing something? Maybe fix some stuff?
Click to expand...
Click to collapse
He just want to clean his topic. Send him a PM.
I understand that but there is still no team. He just made his project open for patches. And I think, personally, a team could help the speed on development of a ROM So please join
Sent from my GT540 using Tapatalk
So join his team , and start patching?
wwenigma said:
So join his team , and start patching?
Click to expand...
Click to collapse
Since when does he have a team? What I know about it, is that he just made some kind of open-source project where you can add your own updates and where he gets no credit.
Sent from my GT540 using Tapatalk
I can help you with Java stuff!
I think miroslav_mm wants to release ICS under name of SWIFT-TEAM, with developer names in credits.... may you ask him about it?
Do not split guys...
Miroslav said that it's only him on the team...so i don't see any team there..if we are more than 1 guy in a team we can get faster a daily ROM for our Phones
rexes13 said:
Miroslav said that it's only him on the team
Click to expand...
Click to collapse
Jep, because PCF+MGP join then leave and jasper580 cant make neccessary steps... ask him. All two, ask him about it.
wwenigma said:
Jep, because PCF+MGP join then leave and jasper580 cant make neccessary steps... ask him. All two, ask him about it.
Click to expand...
Click to collapse
I can make nesseccary steps if I want, but I don't want to. I want to start cleaned up. That's why I created this topic. So:
If you want to join: welcome.
If you don't want to: stop spamming
@rexes13 Welcome to the team!
Sent from my GT540 using Tapatalk
Good news.
Yesterday I successfully ported 3d kernel driver (kgsl) from 35, so now we have full functionality kernel with OpenGL ES-CM 1.1.
So HW, 3D and other stuff with support OpenGL working, not excellent but working, need improve source code Surfaceflinger and HardwareDisplay.
Maybe next weak I will make new thread and publish first public test version, but all development moments we can discus here.
Before I need redownload all sources CM9 again. Yesterday I had the same error like in wwenigma and aaa801
Code:
target thumb C: libhardware_legacy <= hardware/libhardware_legacy/power/power.c
arm-linux-androideabi-gcc: ": No such file or directory
<command-line>: warning: missing terminating " character
and I dont know WTF, so delete all source tree. Maybe today will try download again and build again.
hell yeah! im just another non-dev member LOL sry
Need help!
Look on code:
Code:
//static int32_t msm_tscal_scaler = 65536;
static int32_t msm_tscal_xscale = 70046;
static int32_t msm_tscal_xoffset = -4191987;
static int32_t msm_tscal_yscale = 71735;
static int32_t msm_tscal_yoffset = -3004437;
this pointers for torch 320*240. So when I using that I need tap on 2mm high on icon for open something. This pointer need for screen calibration. Need find right pointer.
I can't find a logic in this numbers.
miroslav_mm said:
Need help!
Look on code:
Code:
//static int32_t msm_tscal_scaler = 65536;
static int32_t msm_tscal_xscale = 70046;
static int32_t msm_tscal_xoffset = -4191987;
static int32_t msm_tscal_yscale = 71735;
static int32_t msm_tscal_yoffset = -3004437;
this pointers for torch 320*240. So when I using that I need tap on 2mm high on icon for open something. This pointer need for screen calibration. Need find right pointer.
I can't find a logic in this numbers.
Click to expand...
Click to collapse
The offsets appear to have a ~4:3 ratio. It doesn't make sense though why it's x:y=4:3, and not the other way around, since the screen is usually 3:4(e.g. 320x480 or 240x320). Also, considering our screen is 320x480, which is a ratio of 1,5 and not 1,(3), I think those would be totally wrong for our phone. Maybe try to modify one of the two to match 1,5 ratio. E.g. make xoffset=-4506655. I don't know. :/
Please discuss development on your page. I want to make a dev team here
Sent from my GT540 using Tapatalk
deleted
10 character
This numbers working with this java code together:
]
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Read current values
final int xoffset = (readValue("xoffset")*240+480)/960;
final int yoffset = (readValue("yoffset")*320+460)/920;
final int xscale = readValue("xscale");
final int yscale = readValue("yscale");
view = new View(this) {
private int step = 1;
private int rawx1;
private int rawy1;
private int rawx2;
private int rawy2;
private void writeValue(String parameter, int value) {
try {
FileOutputStream fos = new FileOutputStream(new File("/sys/module/msm_touch/parameters/tscal_" + parameter));
fos.write(String.valueOf(value).getBytes());
fos.flush();
fos.getFD().sync();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_UP)
return true;
if(step==1) {
rawx1 = ((int)ev.getRawX()*65536-xoffset+32768)/xscale;
rawy1 = ((int)ev.getRawY()*65536-yoffset+32768)/yscale;
if(rawx1<100 && rawy1<100)
step = 2;
} else if(step==2) {
rawx2 = ((int)ev.getRawX()*65536-xoffset+32768)/xscale;
rawy2 = ((int)ev.getRawY()*65536-yoffset+32768)/yscale;
if(rawx2>140 && rawy2>220)
step = 3;
} else {
int distx = rawx2 - rawx1;
int new_xscale = (140*65536 + distx/2)/distx;
int disty = rawy2 - rawy1;
int new_yscale = (220*65536 + disty/2)/disty;
int new_xoffset = 1;
new_xoffset += 50*65536-rawx1*new_xscale;
new_xoffset += 190*65536-rawx2*new_xscale;
new_xoffset /= 2;
new_xoffset = (new_xoffset*960+120)/240;
int new_yoffset = 1;
new_yoffset += 50*65536-rawy1*new_yscale;
new_yoffset += 270*65536-rawy2*new_yscale;
new_yoffset /= 2;
new_yoffset = (new_yoffset*920+160)/320;
// Pass new calibration to kernel
writeValue("xoffset", new_xoffset);
writeValue("yoffset", new_yoffset);
writeValue("xscale", new_xscale);
writeValue("yscale", new_yscale);
// Save calibraiton data to /data/system/pointercal
StringBuilder sb = new StringBuilder();
sb.append(new_xscale);
sb.append(" ");
sb.append(0);
sb.append(" ");
sb.append(new_xoffset);
sb.append(" ");
sb.append(0);
sb.append(" ");
sb.append(new_yscale);
sb.append(" ");
sb.append(new_yoffset);
sb.append(" ");
sb.append(65536);
App + ui input framework + kernel working together.
App - creation poinercal
ui input framework - reading pointercal send correct info to kernel
kernel touch driver - doing move.
Öhm, the touchscreen driver use a virtual square (320*320) to detect touch, stretched to a rectangle(320*480)?
mod: about calibration, http://code.google.com/p/openeve/issues/detail?id=91
jasper580 said:
Please discuss development on your page. I want to make a dev team here
Click to expand...
Click to collapse
I cant understand you! What do you mean? Do you wanna make new dev team? Working on my sources but without me?
I exactly want to ask that. Maybe he start from scratch, his github is near empty.

[Q] XSharedPreferences - never loaded

Hi guys,
I'm currently a little bit confused because i try to create my first XPosed module for Xposed 2.6.1 on a Android 4.0.3 unit but i have trouble with my preferences. I tried multiple things but it was never working.
Here is the preferences code of my Settings activity. That one works and it creates a the preference file with rw-rw-r permissions and the preferences are correctly saved.
Code:
getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE | MODE_MULTI_PROCESS);
getPreferenceManager().setSharedPreferencesName(Const.PACKAGE + "_preferences");
addPreferencesFromResource(R.xml.preferences);
That one is the xposed side snippet:
Code:
preferences = new XSharedPreferences(Const.PACKAGE, Const.PACKAGE+"_preferences");
if (preferences.getAll().size()==0)
{
debug("Preferences seems not to be initialized!");
}
It never loads any of my preferences. I tried the constructor XSharedPreferences(Const.PACKAGE) instead, but without any luck...
I checked the directory permissions of the settings directory, and that one seems to be correct (rwxrwxr-x).
Thanks for every help!
Bye
Have you checked what Const.PACKAGE actually is set to?
It is set to the hardcoded package Name. No class.getPackage... I added a file.isreadable and it returns false. I dont know, im just out oft any ideas.
TheLexus said:
It is set to the hardcoded package Name. No class.getPackage... I added a file.isreadable and it returns false. I dont know, im just out oft any ideas.
Click to expand...
Click to collapse
Is there any reason why you set MODE_MULTI_PROCESS? Can you please try removing it, delete your preference file and try again?
In my UI I open SharedPreferences from <packagename>_preferences.xml
getSharedPreferences(Common.PREFERENCES_NAME, Context.MODE_WORLD_READABLE)
Click to expand...
Click to collapse
and in the module I open the settings via
new XSharedPreferences(Common.PACKAGE_NAME);
Click to expand...
Click to collapse
Please remove your current preferences file and the MODE_MULTI_PROCESS and try the code from above.
So you found any way to make it work??
I ran into the same problem, I set the preferences by the code:
SharedPreferences.Editor editor = LogExtras.getAppContext().getSharedPreferences(Commons.PACKAGE_NAME, Context.MODE_WORLD_READABLE).edit();
editor.putString("package_to_look", _packageToLook);
And when I try to get it from the module it always returns size 0
private static final XSharedPreferences preferences = new XSharedPreferences(Commons.PACKAGE_NAME, Commons.PACKAGE_NAME+"_preferences");
public static void refreshPreferences() {
Log.d("Utils", "reading prefs");
preferences.reload();
Log.d("Utils", Integer.toString(preferences.getAll().size()));
Commons.PACKAGE_TO_LOOK = preferences.getString("package_to_look", Commons.PACKAGE_TO_LOOK);
log("Package to Look: " + Commons.PACKAGE_TO_LOOK);
}
---------- Post added at 04:30 PM ---------- Previous post was at 03:34 PM ----------
I tested the prefs in the context, and it works, only in xposed it dont load.
So I got the app saving the pref and reading the pref working, but when I try to read the pref with XSharedPreference, the size is always 0.
Already tried everything, but nothing works.
caioketo said:
So you found any way to make it work??
I ran into the same problem, I set the preferences by the code:
SharedPreferences.Editor editor = LogExtras.getAppContext().getSharedPreferences(Commons.PACKAGE_NAME, Context.MODE_WORLD_READABLE).edit();
editor.putString("package_to_look", _packageToLook);
And when I try to get it from the module it always returns size 0
private static final XSharedPreferences preferences = new XSharedPreferences(Commons.PACKAGE_NAME, Commons.PACKAGE_NAME+"_preferences");
public static void refreshPreferences() {
Log.d("Utils", "reading prefs");
preferences.reload();
Log.d("Utils", Integer.toString(preferences.getAll().size()));
Commons.PACKAGE_TO_LOOK = preferences.getString("package_to_look", Commons.PACKAGE_TO_LOOK);
log("Package to Look: " + Commons.PACKAGE_TO_LOOK);
}
---------- Post added at 04:30 PM ---------- Previous post was at 03:34 PM ----------
I tested the prefs in the context, and it works, only in xposed it dont load.
So I got the app saving the pref and reading the pref working, but when I try to read the pref with XSharedPreference, the size is always 0.
Already tried everything, but nothing works.
Click to expand...
Click to collapse
I have a similar problem, but only for one preference:
Code:
public class Main implements IXposedHookZygoteInit, IXposedHookLoadPackage {
public static final String MY_PACKAGE_NAME = Main.class.getPackage().getName();
private static XSharedPreferences pref, packagePref;
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
pref = new XSharedPreferences(MY_PACKAGE_NAME, Common.PREF);
packagePref = new XSharedPreferences(MY_PACKAGE_NAME, Common.PREF_PACKAGE);
}
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
pref.reload();
packagePref.reload();
final String packageName = lpparam.packageName;
boolean masterSwitchOn = pref.getBoolean(Common.MASTER_SWITCH, true);
XposedBridge.log("Master Switch " + (masterSwitchOn ? "on" : "off"));
if (!masterSwitchOn) {
return;
}
if (!packagePref.getBoolean(packageName, false)) {
return;
}
Long timestamp = System.currentTimeMillis();
Long permitTimestamp = packagePref.getLong(packageName + "_tmp", 0);
if (permitTimestamp != 0 && timestamp - permitTimestamp <= 4000) {
return;
}
.
.
.
}
So, the package boolean works, the master switch doesn't…
It only seems to work after opening and closing the app multiple times.
caioketo said:
So you found any way to make it work??
I ran into the same problem, I set the preferences by the code:
Click to expand...
Click to collapse
Are you sure that your app saves the file to shared_prefs/<packagename>_preferences.xml? Better verify it using a file explorer. It's the default for preference activities, but it might not be for the methods you use.
Maxr1998 said:
I have a similar problem, but only for one preference:
Click to expand...
Click to collapse
Similar stuff here. Does your application really save the preferences in two different files, named shared_prefs/<Value of Common.PREF>.xml and shared_prefs/<Value of Common.PREF_PACKAGE>.xml? If yes, are both of these files world-readable?
You just saved my day. Making the preference files world readable solves it , preferences.makeWorldReadable() is the way to go. And yes, I'm using two preference files.
Thank you thank you thank you

[Q] hooking RecentLocationApps.getAppList()

I am trying to hook this method, I want to filter out the "Google Play services" from there...(is under settings app)
Code:
/**
* Fills a list of applications which queried location recently within
* specified time.
*/
public List<Preference> getAppList() {
// Retrieve a location usage list from AppOps
AppOpsManager aoManager =
(AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(
new int[] {
AppOpsManager.OP_MONITOR_LOCATION,
AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION,
});
// Process the AppOps list and generate a preference list.
ArrayList<Preference> prefs = new ArrayList<Preference>();
long now = System.currentTimeMillis();
for (AppOpsManager.PackageOps ops : appOps) {
// Don't show the Android System in the list - it's not actionable for the user.
// Also don't show apps belonging to background users.
int uid = ops.getUid();
boolean isAndroidOs = (uid == Process.SYSTEM_UID)
&& ANDROID_SYSTEM_PACKAGE_NAME.equals(ops.getPackageName());
if (!isAndroidOs && ActivityManager.getCurrentUser() == UserHandle.getUserId(uid)) {
Preference pref = getPreferenceFromOps(now, ops);
if (pref != null) {
prefs.add(pref);
}
}
}
return prefs;
}
I can't hook this method, I'v tried something like :
Code:
if (lpparam.packageName.equals("com.android.settings")) {
findAndHookMethod("com.android.settings.location.LocationSettings", lpparam.classLoader, "getAppList", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("Called");
}
what is the best approach to achieve this?
devtrop said:
I can't hook this method
Click to expand...
Click to collapse
Why not? Are there any errors in the Xposed log?
If not, I'd make sure the package name is correct and that the method is actually called when you expect it to be.
Code:
09-29 11:06:53.600 5277 5277 I Xposed : java.lang.NoSuchMethodError: com.android.settings.location.RecentLocationApps#getAppList(java.util.List)#exact
running on Samsumg Note 3.
devtrop said:
Code:
09-29 11:06:53.600 5277 5277 I Xposed : java.lang.NoSuchMethodError: com.android.settings.location.RecentLocationApps#getAppList(java.util.List)#exact
running on Samsumg Note 3.
Click to expand...
Click to collapse
That error doesn't correspond to the code you've posted in the first post. Post the modified code and the error.
Purely guessing, though: Samsung modified the code you're trying to hook. You're hooking the methods you're seeing in the AOSP code, but that's not the case on your device.
You are correct, sorry. I'm trying a lot of different stuff.
this is the code:
Code:
try
{
findAndHookMethod("com.android.settings.location.RecentLocationApps", lpparam.classLoader,
"getAppList", List.class, new XC_MethodHook() {
@SuppressWarnings("unchecked")
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
{
XposedBridge.log("RecentLocationApps.getAppList()");
}
});
}
catch(Throwable t)
{
XposedBridge.log(t);
}
the throwable is :
Code:
09-29 11:56:08.559 5282 5282 I Xposed : java.lang.NoSuchMethodError: com.android.settings.location.RecentLocationApps#getAppList(java.util.List)#exact
if tried to do that for every package, not just com.android.settings or com.android.settings.location and it doesn't seem to work.
do you know what's the correct package? do I have to start dedexing Samsung's packages to get the answer?
devtrop said:
do you know what's the correct package?
Click to expand...
Click to collapse
com.android.settings should be the correct package, if I'm not mistaken.
devtrop said:
do I have to start dedexing Samsung's packages to get the answer?
Click to expand...
Click to collapse
That'd be the best thing to do as it looks like Samsung has changed some things.

[Q] Change layout from VolumePanel

Hey there,
at the moment I'm trying to create my first Xposed Module. My wish to give the VolumePanel a new look. I found the layout and the code for the VolumePanel in AOSP here:
Code
Layout
Now I want to modify this layout but I can't get it work. I'm not sure in which package the VolumePanel is after the compilation of Android. I tried wit this code here:
Code:
resparam.res.hookLayout("android", "layout", "volume_adjust", new XC_LayoutInflated()
{
@Override
public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable
{
Log.d("ME", "Layout infaleted");
LinearLayout ll = new LinearLayout(liparam.view.getContext());
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(liparam.view);
liparam.view = ll;
}
});
If I try it with this code the function is never called. As you can see here I'm trying to wrap the whole layout with a LinearLayout (for the beginning).
I'm also not realy sure if I can call the last line of code and overwrite the variable view. Is that okay or do I have to do it in another way? (but I know that the xml is in the framework-res.apk)
Would be great if you can help me with this: Can I overwrite the view in the way I do and where can I get the packageName of the volumeView?
Kind regards
Cilenco

[DexKit] Xposed Module Jni Lib | An easy-to-use, high-performance dex deobfuscation library

Library: DexKit
Project Link: https://github.com/LuckyPray/DexKit
About: An easy-to-use, high-performance dex deobfuscation library. Easy to use your CMAKE/Android projects.
Highlight:
JNI multi-threaded processing Dex bytecode, more efficient than JVM implementation.
It single search is ms level, You can even inject the host application at runtime without causing an ANR, to the extent permitted.
You can use it to handle reinforced apps(use ClassLoader cookies).
API introduction​There are two APIs can meet most of your usage scenarios:
DexKit::BatchFindClassesUsingStrings
DexKit::BatchFindMethodsUsingStrings
Note: In all cases you should avoid searching for keywords that contain duplicate content, eg: {"key_word", "word"}, as this will cause tags to be overwritten, resulting in inaccurate search results. If there is such a need, open the advanced search mode as much as possible, and use the string to match the content exactly, for example, modify it to this: {"^key_word$", "^word$"}
Click to expand...
Click to collapse
And there are many other APIs:
DexKit::FindMethodCaller: find caller for specified method.
DexKit::FindMethodInvoking: find the called method
DexKit::FindMethodUsingField: Find method to get/set specified field
DexKit::FindMethodUsingString: find method used utf8 string
DexKit::FindMethod: find method by multiple conditions
DexKit::FindSubClasses: find all direct subclasses of the specified class
DexKit::FindMethodUsingOpPrefixSeq: find all method using opcode prefix sequence(op range: 0x00-0xFF)
DexKit::FindMethodUsingOpCodeSeq: find all method using opcode sequence(op range: 0x00-0xFF)
DexKit::GetMethodOpCodeSeq: get method opcode sequence(op range: 0x00-0xFF)
Note: At present, all instructions are only for standard dex instructions and do not include odex optimization instructions.
Click to expand...
Click to collapse
For more detailed instructions, please refer to dex_kit.h.
Quick start​However, this approach will import an extra so file. If you don't want to import an extra so file, please use the second/third method.
build.gradle:
Code:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
app/build.gradle:
Code:
dependencies {
implementation 'com.github.LuckyPray:DexKit:<version>'
}
​JAVA Example​DexKitBridge provides 2 factory methods to create Dexkit instances:
DexKitBridge.create(apkPath): normally, please use it.
DexKitBridge.create(classLoader, true): for reinforced apps, used classLoader and set option useCookieDexFile to true.
PS: DexKitBridge.create(classLoader, useCookieDexFile = false) ≈ DexKitBridge.create(apkPath), but the former may contain part of the system dex.
Java:
import io.luckypry.dexkit.DexKitBridge;
// ...
public class DexUtil {
static {
System.loadLibrary("dexkit");
}
public static void findMethod() {
// for no-reinforced apps please use apkpath to load, because of the exist of dex2oat and CompactDex(cdex),
// dexkit currently only handles StandardDex.
String apkPath = application.applicationInfo.sourceDir
// try-with-resources, auto close DexKitBridge, no need to call DexKitBridge.close()
// if you don't use try-with-resources, be sure to manually call DexKitBridge.close() to release the jni memory
try (DexKitBridge dexKitBridge = DexKitBridge.create(apkPath)) {
if (dexKitBridge == null) {
Log.e("DexUtil", "DexKitBridge create failed");
return;
}
List<DexClassDescriptor> classes = dexKitBridge.findSubClasses("android.app.Activity", null);
for (DexClassDescriptor clazz : classes) {
String name = clazz.getName();
String simpleName = clazz.getSimpleName();
Class<?> clz = clazz.getClassInstance(hostClassLoader);
Log.i("DexUtil", "findSubClasses: " + clz);
}
} catch (Throwable e) {
Log.e("DexUtil", Log.getStackTraceString(e));
}
}
}
If you have problems using it, please create an issue on the github repo.
Reserved

Categories

Resources