Giter Club home page Giter Club logo

Comments (6)

 avatar commented on May 31, 2024 2

Thank to all which reply me. I found a solution.
newApplication is invoked before a new Activity is created and should invoked also when there is no activity but only a service.

Class<?> clsInstrumentation = findClass("android.app.Instrumentation", classLoader);
XposedBridge.hookAllMethods(instrumentation, "newApplication", new XC_MethodHook() {
    @Override
    protected void afterHookedMethod(MethodHookParam param)
    {
        SharedPreferences spXMain = new RemotePreferences((Context)param.getResult(), Utils.PREFS, Utils.XMAIN);
        // processHook((Context)param.getResult(), sPackageName, classLoader);
    }
});

I do think we should have an official guide on "where do I get a Context instance from"

@apsun would be great

A quick question, did you look around if you could disable this check?

@MPeti1 I tried to analyze, but it wasn't easy for me

from remotepreferences.

aviraxp avatar aviraxp commented on May 31, 2024 1

Is the app you are hooking (and the class) having context as a parameter somewhere? If so, you can hook it to get context.

See https://github.com/apsun/NekoSMS/blob/82205ebed9cd57fd59a59457d2a65b10a5e17751/app/src/main/java/com/crossbowffs/nekosms/xposed/SmsHandlerHook.java#L182

from remotepreferences.

MPeti1 avatar MPeti1 commented on May 31, 2024

It should have an Application Context in Application.onCreate(), if I remember it correctly, but in cases it's not practical to wait until that. I'm not entirely sure why, but I remember thinking about this and not taking this path.
Edit: yeah, I'm starting #3 with why it's not a good idea. Basically it's because I need the preferences while handleLoadPackage() is running, so I can read my settings so I can decide early if I want to hook something.

But now that I'm thinking about this, is it really needed? I could just hook everything where a that early hook is crucial, and when I receive some kind of context (from a hook made to do just that) in my settings class, I could unload hooks that are not actually needed.
Or an other solution would probably be making my own IPC capable services with Binder, but that's not done as easily as said, and even more I know of apps where it's been found that my phone (and apparently there are more) fails in the middle of transferring arrays, except when not but that's rare and still don't know what does it depend on.

from remotepreferences.

MPeti1 avatar MPeti1 commented on May 31, 2024

So I think this project is useless with *Posed and new Android if this check can't be disabled.

A quick question, did you look around if you could disable this check (possibly only for once every time you request it, so other apps couldn't abuse it)?

from remotepreferences.

apsun avatar apsun commented on May 31, 2024

From @MPeti1:

I could just hook everything where a that early hook is crucial, and when I receive some kind of context (from a hook made to do just that) in my settings class, I could unload hooks that are not actually needed.

This is the approach I would recommend. Hook everything, and decide what to do within the callback based on the preferences. I am not a fan of grabbing random context objects out of internal APIs exactly for this reason: they can and will break with system updates.

RemotePreferences isn't magic, it's just SharedPreferences implemented on top of ContentResolver. If Android says you can't use the "system context" with ContentResolver, there isn't really much choice other than to either: a) change where you obtain the Context, or b) use a different preference sharing solution that doesn't rely on Context.

from remotepreferences.

apsun avatar apsun commented on May 31, 2024

I do think we should have an official guide on "where do I get a Context instance from", since this is probably the most frequently asked question on this project. Obviously a "one-size-fits-all" approach would be ideal, like hooking Application.onCreate and deferring all the initialization logic to there, although it's been so long since I've touched Xposed that I'm not even sure if that works.

from remotepreferences.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.