• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[APP][XPOSED][6.0+] Use Xposed without developing a module

Status
Not open for further replies.
Search This thread

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
ic_launcher.png

XPrivacyLua custom hook definitions

By using XPrivacyLua you can define Xposed hooks and apply them to any app at run time (so, rebooting your device is not necessary). You can write hook code on your device in Lua, which is quite easy to learn.

See the documentation about how to define hooks.

Although XPrivacyLua has 'privacy' in its name, new hooks don't need to be privacy related at all. Disabling the built in privacy related hooks is a matter of selecting another collection of hooks.

This XDA thread is meant to discuss defining hooks, with the restriction that hook definitions must serve a legally allowed purpose. This XDA thread is not meant to make you a developer, so at least some development experience is expected, which means that you'll need to be able to figure out where to hook yourself and that you'll need to be able to write Lua scripts yourself.


XDA:DevDB Information
XPrivacyLua hook definitions, Xposed for all devices (see above for details)

Contributors
M66B
Xposed Package Name:

Version Information
Status: Beta

Created 2018-01-28
Last Updated 2018-04-01
 

jawz101

Senior Member
Could there be a generic "always return true" lua script?

And when building a definition, what does it mean to be in a group and collection? Do I just put anything there or do I have to call them something particular?


Well, I'm trying but I'm lost. Just trying to setAnalyticsCollectionEnabled

https://firebase.google.com/support/guides/disable-analytics

Code:
 public void setAnalyticsCollectionEnabled (boolean enabled) = false
supposedly disables Firebase Analytics (which apparently 67% of the top 200 apps use).


My definition looks like
Collection: privacy
Group: firebase
Name: firebase.analytics
author: whatever
class: com.google.firebase.analytics
method:setAnalyticsCollectionEnabled
parameter type: void
return type: boolean
min/max sdk: 1/999
lua script: @generic_false_value I suppose I can use this?

Even if this looks valid, it feels like maybe this wouldn't fire unless certain other things happen first? Looking at your hooks.json for google analytics it looks like you had to maybe set a chain of events to occur to get to the point of controlling the method you intend to make changes?
 
Last edited:

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
Could there be a generic "always return true" lua script?

And when building a definition, what does it mean to be in a group and collection? Do I just put anything there or do I have to call them something particular?


Well, I'm trying but I'm lost. Just trying to setAnalyticsCollectionEnabled

https://firebase.google.com/support/guides/disable-analytics

Code:
 public void setAnalyticsCollectionEnabled (boolean enabled) = false
supposedly disables Firebase Analytics (which apparently 67% of the top 200 apps use).


My definition looks like
Collection: privacy
Group: firebase
Name: firebase.analytics
author: whatever
class: com.google.firebase.analytics
method:setAnalyticsCollectionEnabled
parameter type: void
return type: boolean
min/max sdk: 1/999
lua script: @generic_false_value I suppose I can use this?

Even if this looks valid, it feels like maybe this wouldn't fire unless certain other things happen first? Looking at your hooks.json for google analytics it looks like you had to maybe set a chain of events to occur to get to the point of controlling the method you intend to make changes?
The built-in scripts are not meant for general use because they might change over time breaking stuff that depends on them. Therefore imported definitions are not linked against the built-in scripts. If needed, you can simply copy and paste the Lua script from another (built in) definition. Copying guarantees your definition will keep working, even when the built-in scripts are changed or even removed.

Calling setAnalyticsCollectionEnabled requires access to an instance of FirebaseAnalytics, which apps needs to get by calling getInstance. So, hook getInstance to call setAnalyticsCollectionEnabled(false) and hook setAnalyticsCollectionEnabled to prevent an app from turning analytics on again.

Restricting Google Analytics (available in the next release of XPrivacyLua) works similar:
https://github.com/M66B/XPrivacyLua/blob/master/app/src/main/assets/ga_getinstance.lua
https://github.com/M66B/XPrivacyLua/blob/master/app/src/main/assets/ga_setdryrun.lua

You can also wait until I have added this ... ;)
 
  • Like
Reactions: AndroTech

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
And when building a definition, what does it mean to be in a group and collection? Do I just put anything there or do I have to call them something particular?
With the latest version of XPrivacyLua / companion app you can change the collection of hooks to use in XPrivacyLua. The default is to use the collection 'Privacy'. You can define your own collection by definition hooks with a new collection name. There can only be one collection active at one time, so if you want to add your own definitions to the built-in privacy collection you'll have to use the collection 'Privacy'. Basically collections exists to allow using XPrivacyLua for things other than privacy.

Groups are listed in the XPrivacyLua app and make it easy to apply a group of hooks to one or more apps. XPrivacyLua cannot and will not handle applying individual hooks to keep things simple, but I might add this to the pro companion app in the near feature. For now you can rename a group of an existing hook definition to be able to apply it separately in XPrivacyLua.

Edit: this has been clarified in the documentation too now: https://github.com/M66B/XPrivacyLua/blob/master/DEFINE.md
 
Last edited:

mnjm9b

Senior Member
Apr 26, 2008
1,046
227
I still have some questions on when,where,how etc.... but I will wait until I can dedicate more time to playing with this.

I do have a feature request.

could there be a sort of drop down box that queries all valid entries for each item when creating a custom definition.

for example...
when creating a custom definition, when taping on the line for group, you would just type a new group (as it is now) but if there was a drop down arrow at the end of the line that could give a list of currently used groups and then the user could just click the listed group instead of typing and it would auto-fill that field.

maybe even more useful would be for the other items like Name,Class, Method etc...
where it could show possible entries. That would help a lot.
 

jawz101

Senior Member
... I turned on notifications for your new Firebase rules. I would think a bunch of apps I have use Firebase Analytics. @M66B Have you seen any apps trigger it yet?
Even if the app imported Firebase Analytics library and gathers Firebase Analytics but never uses the setAnalyticsCollectionEnabled() method in its own code would it mean this hook will never trigger?
With the latest version of XPrivacyLua / companion app you can change the collection of hooks to use in XPrivacyLua. The default is to use the collection 'Privacy'. You can define your own collection by definition hooks with a new collection name. There can only be one collection active at one time, so if you want to add your own definitions to the built-in privacy collection you'll have to use the collection 'Privacy'. Basically collections exists to allow using XPrivacyLua for things other than privacy.
Thanks:highfive:.
This is just a suggestion but if this was my app I would break these 2 elements out to separate screens from the definition builder. You would define collections and groups in a separate spot, and then when building rules the collections and groups would pull in as a selectable dropdown. Avoids typos and helps to explain how there can be only one active collection for XPrivacyLua.
 

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
I still have some questions on when,where,how etc.... but I will wait until I can dedicate more time to playing with this.

I do have a feature request.

could there be a sort of drop down box that queries all valid entries for each item when creating a custom definition.

for example...
when creating a custom definition, when taping on the line for group, you would just type a new group (as it is now) but if there was a drop down arrow at the end of the line that could give a list of currently used groups and then the user could just click the listed group instead of typing and it would auto-fill that field.

maybe even more useful would be for the other items like Name,Class, Method etc...
where it could show possible entries. That would help a lot.
I will see what I can do for collection and group, but all the other fields are flexible and depend on the hook.
 

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
... I turned on notifications for your new Firebase rules. I would think a bunch of apps I have use Firebase Analytics. @M66B Have you seen any apps trigger it yet?
Even if the app imported Firebase Analytics library and gathers Firebase Analytics but never uses the setAnalyticsCollectionEnabled() method in its own code would it mean this hook will never trigger?
An app will normally not disable/enable analytics given the default is enabled and the user has mostly no choice in this. So see this hook as a safeguard to prevent an app enabling analytics again after we disabled it in another hook ;)
 

jawz101

Senior Member
An app will normally not disable/enable analytics given the default is enabled and the user has mostly no choice in this. So see this hook as a safeguard to prevent an app enabling analytics again after we disabled it in another hook ;)

Would there be a way to introduce the app to calling it? Or maybe that's what you're implying. Also, have you noticed that system and google apps seem to gray out the read identifiers permission? Ex: set read identifiers as restricted on Android Webview or Google Photos/Maps/Google TTS. Turns pink Get out of XPrivacyLua and open it again. Read Identifiers is gray. (I'm on LineageOS if that matters)
 
Last edited:

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
Would there be a way to introduce the app to calling it? Or maybe that's what you're implying. Also, have you noticed that system and google apps seem to gray out the read identifiers permission? Ex: set read identifiers as restricted on Android Webview or Google Photos/Maps/Google TTS. Turns pink Get out of XPrivacyLua and open it again. Read Identifiers is gray. (I'm on LineageOS if that matters)
Normally an apps doesn't call the function. Maybe if the user can choose to opt in or opt out, but this is rarely the case.

The other thing should go into the XPrivacyLua XDA thread, but I will look into it anyway.
 

mnjm9b

Senior Member
Apr 26, 2008
1,046
227
I will see what I can do for collection and group, but all the other fields are flexible and depend on the hook.

Thanks, That's a good start.
Maybe if the "PRO" app takes off enough for you to bother you could charge extra for the expanded feature of having the drop lists change depending on the choices made?

I did have a moment to look over a definition I was playing with for "TIME"

it serves no real purpose so I gave up early but if I could get a better understanding on why it doesn't work it could help with actual ones.

using the FINGERPRINT example I made several other entries that all worked fine but this one caused issue.
I assumed it was because according to https://developer.android.com/reference/android/os/Build.html the type for TIME wasn't "String" but "Long"

this is the last one I tried...
Code:
{
  "collection": "Privacy",
  "group": "Read.Device",
  "name": "Build.TIME",
  "author": "M66B",
  "className": "android.os.Build",
  "methodName": "#TIME",
  "parameterTypes": [],
  "returnType": "long",
  "minSdk": 1,
  "maxSdk": 999,
  "enabled": true,
  "optional": false,
  "usage": true,
  "notify": false,
  "luaScript": "function after(hook, param)\n  param:setResult("unknown")\n  return true\nend\n"
}


I was also playing with "SUPPORTED_ABIS" which also didn't work and the type was "Sting []" instead of just "String" so I was thinking that was the problem also.

:confused:
 

Namnodorel

Senior Member
Oct 26, 2015
379
286
@mnjm9b You are returning a string (series of characters) as a long (number). Try returning just a number (without the quotes).
String[] is an array (mulitple strings), so you need to return an array as well. But I don't know how to do that in Lua right now
 

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
@mnjm9b You are returning a string (series of characters) as a long (number). Try returning just a number (without the quotes).
String[] is an array (mulitple strings), so you need to return an array as well. But I don't know how to do that in Lua right now
You are 100% right.

Returning a string array is not trivial. Look at 'generic_empty_string_array.lua' about how to do this.
 

mnjm9b

Senior Member
Apr 26, 2008
1,046
227
@mnjm9b You are returning a string (series of characters) as a long (number). Try returning just a number (without the quotes).
String[] is an array (mulitple strings), so you need to return an array as well. But I don't know how to do that in Lua right now
so in my example the returnType instead of "long" should be a number like 0 without quotes?

I tried that and it still doesn't work.

---------- Post added at 08:55 PM ---------- Previous post was at 08:54 PM ----------

You are 100% right.

Returning a string array is not trivial. Look at 'generic_empty_string_array.lua' about how to do this.
thanks for this, I guess I am in WAY over my head.
 

Namnodorel

Senior Member
Oct 26, 2015
379
286
so in my example the returnType instead of "long" should be a number like 0 without quotes?

I tried that and it still doesn't work.
No. the return type was correct. That specifies what type of object you are expected to return. What you need to change is what you then actually return, which is

Code:
param:setResult("unknown")

to
Code:
param:setResult(12345678)
 

Rom

Senior Member
Jul 1, 2013
2,534
1,046
Lyon
@M66B

Thank you for your work, if i understand right, you provide us an programmable interface that will execute command lines written in Lua language without having to create a complete module in JAVA for XPosed?

From what i understood in your initial post, you indicate that we must install your module "XPrivacyLua", then that one disposes there after of the possibility to apply for the applications which one wishes, lines of codes written in Lua language and which do not necessarily have to relate to the logic of rights of access concerning privacy?

If yes then we must necessarily install XPrivacyLua even if in view of all your work provided on it the basic functions do not interest me forcibly?

All this seems to be promising however :good:
 

M66B

Recognized Developer
Aug 1, 2010
24,677
50,968
@M66B

Thank you for your work, if i understand right, you provide us an programmable interface that will execute command lines written in Lua language without having to create a complete module in JAVA for XPosed?
Yes.

From what i understood in your initial post, you indicate that we must install your module "XPrivacyLua", then that one disposes there after of the possibility to apply for the applications which one wishes, lines of codes written in Lua language and which do not necessarily have to relate to the logic of rights of access concerning privacy?
Yes.

If yes then we must necessarily install XPrivacyLua even if in view of all your work provided on it the basic functions do not interest me forcibly?

All this seems to be promising however :good:
You'll need XPrivacyLua to install and run defined Xposed hooks written in Lua, but you don't need to use the built in privacy related hooks.

The companion app allows you to switch to another collection of hooks you've written, in effect disabling the built-in privacy related hooks.

Try it and I will help you when needed and in the process I will update the documentation where needed.
 
Last edited:
Status
Not open for further replies.

Top Liked Posts

  • There are no posts matching your filters.
  • 31
    ic_launcher.png

    XPrivacyLua custom hook definitions

    By using XPrivacyLua you can define Xposed hooks and apply them to any app at run time (so, rebooting your device is not necessary). You can write hook code on your device in Lua, which is quite easy to learn.

    See the documentation about how to define hooks.

    Although XPrivacyLua has 'privacy' in its name, new hooks don't need to be privacy related at all. Disabling the built in privacy related hooks is a matter of selecting another collection of hooks.

    This XDA thread is meant to discuss defining hooks, with the restriction that hook definitions must serve a legally allowed purpose. This XDA thread is not meant to make you a developer, so at least some development experience is expected, which means that you'll need to be able to figure out where to hook yourself and that you'll need to be able to write Lua scripts yourself.


    XDA:DevDB Information
    XPrivacyLua hook definitions, Xposed for all devices (see above for details)

    Contributors
    M66B
    Xposed Package Name:

    Version Information
    Status: Beta

    Created 2018-01-28
    Last Updated 2018-04-01
    14
    The latest version of the companion app supports uploading to and downloading from a hook definitions repository, so if you created a hook definition which might be useful to others, consider to upload it.
    9
    @jawz101 because of this shocking article I looked into the Mixpanel API. Since apps using Mixpanel can send data without using a library, it is better to block Mixpanel using a firewall app. The default block list of NetGuard contains the Mixpanel domain name.
    8
    It is really simple to define new hooks. As another example I have added hooks to prevent tracking by the Mixpanel library:
    https://github.com/M66B/XPrivacyLua/commit/3aadf9a3521f44dd84e43c45711fba5c368960de

    This will be in the next release of XPrivacyLua, but you can import the definitions right now if you want, see attachment.

    View attachment Mixpanel.json.txt
    8
    Version 1.13 of XPrivacyLua and version 0.29 of the companion app support defining hooks for constructors and dynamic hooking in Lua scripts.

    See here for an example of dynamic hooking:
    https://github.com/M66B/XPrivacyLua/blob/master/app/src/main/assets/webview_constructor.lua