bigsinger / AndroidIdChanger

Xposed Module for Changing Android Device Info
http://repo.xposed.info/module/com.bigsing.changer
548 stars 152 forks source link

Core: Nougat problem with preferences #26

Closed lars18th closed 5 years ago

lars18th commented 7 years ago

Hi,

In the lasted version (v1.12) all the functionality is working... except that in some devicies the preferences aren't avaliable. The observable behaviour is this: the user selects some hook values but the module reads "" (aka empty) values, and then none of the values are hooked.

After reading a lot of documents, the problems seems to be related with the SECURITY context. As the module is running inside the Xposed Framework Context, it can't read/write the preferences. Using "root" privileges for this task is a very dirty hack. So a different solution is required.

Here you can found a detailed description of the the problem by the reputated developer C3C0 (with responses from robo89, the main developer of Xposed): https://github.com/rovo89/XposedBridge/issues/74

I'll check in my device if changing file permissions (with 'chmod') is sufficient for fix the "read" issue.

lars18th commented 7 years ago

Gi @bigsinger ,

I found a solution! :smiley:

This is the regular content of the "/data/data/com.bigsing.changer/shared_prefs" directory:

-rw-rw-r-- 1 u0_a259 u0_a259  288 2017-10-23 09:16 CHANGER.xml
-rw-rw---- 1 u0_a259 u0_a259  153 2017-10-16 13:37 ThemeColor.xml
-rw-rw---- 1 u0_a259 u0_a259  116 2017-10-20 08:52 com.bigsing.changer.BETA_VALUES.xml
-rw-rw---- 1 u0_a259 u0_a259  192 2017-10-16 09:36 crashrecord.xml
-rw-rw---- 1 u0_a259 u0_a259 2100 2017-10-20 08:52 phone.xml
-rw-rw---- 1 u0_a259 u0_a259 1858 2017-10-23 09:06 phoneinfo.xml

But if I change the access mode of the file "phoneinfo.xml" with "chmod a+r phoneinfo.xml" in this sense:

-rw-rw-r-- 1 u0_a259 u0_a259 1858 2017-10-23 09:06 phoneinfo.xml

Then the values can be readed and the hook works!

Please, can you add the code for set this file with "MODE_WORLD_READABLE" (aka 664 flag)? https://github.com/rovo89/XposedBridge/issues/74#issuecomment-172860273

Regards!

bigsinger commented 7 years ago

i know , but can't find getPreferenceManager in xposed82.jar. should i use the xposed88.jar for N?

lars18th commented 7 years ago

should i use the xposed88.jar for N?

No. This XposedBridge version is not released. You're using the correct version. In fact, as I commented the current version (v1.12) it's working now in Nougat. The only problem is the reading of the preferencies. And setting "664" for "phoneinfo.xml" it's sufficient to run it and fix the problem.

So, I suggest to do: first release the version 1.3 with lasted suggestions (#25, #24, #16, #12) and advise for this version: "For Nougat support you need to execute "sudo chmod a+x /data/data/com.bigsing.changer/shared_prefs.xml" And after release this version (that improves a lot the DEBUG and UI) we can explore the best solution for setting the correct access of this file.

You agree?

lars18th commented 7 years ago

hi @bigsinger ,

Sorry! v88.1 of XposedBridge is released: https://github.com/rovo89/XposedBridge/releases/tag/v88.1 Please, use it!

bigsinger commented 7 years ago

v88.1 support 4.X~7.X?

lars18th commented 7 years ago

v88.1 support 4.X~7.X?

Yes, v88 & v88.1 supports Android KK,L,MM,N.

bigsinger commented 7 years ago
compile 'de.robv.android.xposed:api:82:sources'

changed as:

compile 'de.robv.android.xposed:api:88:sources'???
lars18th commented 7 years ago

Hi @bigsinger ,

I'm not sure! I'll search for it. I recommend to implement the pending functions (enable/disable logs, log the hooked value, support null values in phoneinfo.xml) until an upgraded documentation is published regarding the v88.x of Xposed.

For the Nougar support, at time it's sufficient to advertise the '664' of the "phoneinfo.xml" file!

You agree?

bigsinger commented 7 years ago

how to change file attr with 664?

lars18th commented 7 years ago

how to change file attr with 664?

Now, I do manually with "chmod 664 /data/data/com.bigsing.changer/shared_prefs/phoneinfo.xml", after the file is created and calling to "su".

You can advertise this, and/or incorporate an event in the UI for launching this command with root. If you like this (as a temporal workaround), please, only call to "su" one time and only for this command. And suggest to select in the SU Tool "accept only now".

However, as I'm reading the solution is create the file for the first time with the "MODE_WORLD_READABLE" flag.

lars18th commented 7 years ago

Hi @bigsinger ,

how to change file attr with 664?

Try this code:

File file = new File("path_to_your_file");
file.setReadable(true, false);

First parameter of "setReadable(bool,bool)" is for setting "MODE_WORLD_READABLE" (equal to "chmod a+r"), and the second parameter is for setting ""MODE_WORLD_WRITABLE" (equal to "chmod a+w").

Try to execute this after you create the file... or when you write to it (please, not use "setReadable(true,true)" so then any other App can write to this file and it can generate a security hole).

lars18th commented 7 years ago

Hi @bigsinger ,

The module SudoHide is now Nougat compatible: https://forum.xda-developers.com/xposed/modules/mod-sudohide-prevent-apps-detected-apps-t3384559/ https://github.com/SudoCode755/SudoHide/

See the solution for the preference trouble:

    @Override
    public void initZygote(StartupParam startupParam) throws Throwable {
        pref = new XSharedPreferences(BuildConfig.APPLICATION_ID);
        pref.makeWorldReadable();
        isInitialized = false;
    }

https://github.com/SudoCode755/SudoHide/blob/master/app/src/main/java/com/sudocode/sudoHideModule/XposedMain.java#L40

I feel you can use the same code for resolve the problem.

bigsinger commented 7 years ago

SudoHide not Support N. r u kidding me?

i tested XposedInstaller_3.1.2.apk

SudoHide 's gradle: dependencies { provided 'de.robv.android.xposed:api:82' provided 'de.robv.android.xposed:api:82:sources' compile 'com.android.support:appcompat-v7:25.4.0' }

the same as me.

lars18th commented 7 years ago

Hi @bigsinger ,

SudoHide not Support N. r u kidding me?

I not use this module. I'm using it only as an example. I'm reading a lot for fixing this problem. The author of this module indicates that it should be compatible with Nougat... se this post: https://forum.xda-developers.com/showpost.php?p=74255694&postcount=142

SudoHide 's gradle: dependencies { 'de.robv.android.xposed:api:82' } the same as me.

As I commented I feel there is not need for a v88.x XposedBridge. However, please check the code:

 @Override
    public void initZygote(StartupParam startupParam) throws Throwable {
        pref = new XSharedPreferences(BuildConfig.APPLICATION_ID);
        pref.makeWorldReadable();
        isInitialized = false;
    }

This module doesn't have problems for reading the configuration. The trick is quite simple: mark the preference file with "MODE_WORLD_READABLE". And as the class is XSharedPreferences, you don't need to worry about it, as the method makeWorldReadable() is already declaret on it.

Try it!

bigsinger commented 7 years ago

i sovled makeWorldReadable by view the xposed source: @SuppressLint("SetWorldReadable") public boolean makeWorldReadable() { if (!SELinuxHelper.getAppDataFileService().hasDirectFileAccess()) return false; // It doesn't make much sense to make the file readable if we wouldn't be able to access it anyway.

    if (!mFile.exists()) // Just in case - the file should never be created if it doesn't exist.
        return false;

    return mFile.setReadable(true, false);
}

and i use this as: File file = new File(Environment.getDataDirectory(), "data/" + Constant.PACKAGE_THIS + "/shared_prefs/" + Constant.FILENAME_FAKEINFO + ".xml"); file.setReadable(true, false);

lars18th commented 7 years ago

Ah, OK!

I'm only searching for "examples" that have resolved the problem. As you see the problem is now identified: the trouble is created when the Xposed Framework reads the file "phoneinfo.xml", as the SE Context is different to the App. So the solution is make the file world readable. This can be done "at low level" with access attributes "664".

So the problem is how to set the "664" attribute from Android without special privileges. I'll continue searching...

lars18th commented 7 years ago

Hii @bigsinger ,

Some user suggests this workaround. As the SDK 24 & 25 have an empty implementation for the function "pref.makeWorldReadable()" he suggests to compile the module with SDK 23. The idea is quite simple: even if the App targets Nougat, if you compile it with SDK 23 then the implementation will work.

Please, can you try it? You don't need to change nothing more, only the target SDK of your APP. However, you need to use the code:

pref = new XSharedPreferences(BuildConfig.APPLICATION_ID);
pref.makeWorldReadable();

I hope we can found soon a definitive solution (until Oreo support for Xposed is added).

bigsinger commented 7 years ago

ok

lars18th commented 6 years ago

Hi @bigsinger ,

ok

You used this workaround with v1.14?

lars18th commented 6 years ago

Hi @bigsinger ,

No news about this issue. Have you implemented something about it in last releases? Then please, explain the solution that you implemented.

In any case, please upload the last release to the official Xposed repo. I found it sufficient robust for general use.

You agree?

bigsinger commented 6 years ago

i can not test it , cause xposed not work on my Android N device。

lars18th commented 6 years ago

i can not test it

So, no changes in the code?

In this case, we need to advertize it in the README and Xposed Repo Info. Like this:

"For use it in Nougat you need to execute "chmod a+r /data/data/com.bigsing.changer/shared_prefs/phoneinfo.xml" after first run."

I'll try to check it with another Nougat device, for check if this is set automatically anyway.

bigsinger commented 6 years ago

nonono, i use this code, u can check it :

File file = new File(Environment.getDataDirectory(), "data/" + Constant.PACKAGE_THIS + "/shared_prefs/" + Constant.FILENAME_FAKEINFO + ".xml"); file.setReadable(true, false);

i can not test it , but you can, tell me if that can work

lars18th commented 6 years ago

u can check it :

So, I'll check it (in some days) with another device. Thank you!

lars18th commented 6 years ago

Hi @bigsinger ,

Checked with a full reinstall. After the first edit of parameters, the file is set with "global read". So, this problem is fixed now! :smile:

bigsinger commented 6 years ago

:100:

lars18th commented 6 years ago

Hi,

Anyway I don't close this issue now. As you see in #25, some trouble reading the preferences exists in Nougat. I'm not sure about the cause, as the hook is done only in my list of selected packages (and with correct values), but the logs prints "all packages" and "debug is off".

We continue exploring! :smile:

Android1500 commented 3 years ago

I am making a xposed module which change device parameters like imei, device id, etc but for access desirable parameters read parameters from sharedpreference but as we knw MODE WORLD READABLE not works anymore so i can"t access preference file by calling Xsharedpreference so any idea how to deal in this issue