[Q] Access variables in an outer class - Xposed General

Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.
Any suggestions? Cheers

perseus0807 said:
Hullo, you lot. I was working on my own xposed module - and I had a bit of a question. Assuming I'm hooking into a function that's a member of a nested class, how do I refer to objects in the outer class? Here's what I'm trying to hook into - initContentView is a member function of the class ActionPopupWindow, which is inside the outer class Editor. I'm trying to access mTextView - a TextView defined within Editor, not ActionPopupWindow.
Any suggestions? Cheers
Click to expand...
Click to collapse
Use XposedHelpers.getSurroundingThis(...), something like:
Code:
Object outerObject = XposedHelpers.getSurroundingThis(param.thisObject);
Object fieldValue = XposedHelpers.getObjectField(outerObject, "mTextView");
...
However, for the specific case you mention I don't think this is what you need. mTextView isn't defined on the Editor class but rather on PinnedPopupWindow, which is also an inner class and a superclass of ActionPopupWindow.
getObjectField() is aware of fields on superclasses and will fetch it for you just by using:
Code:
XposedHelpers.getObjectField(param.thisObject, "mTextView");

This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.
I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/
Thanks again!

perseus0807 said:
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.
I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/
Thanks again!
Click to expand...
Click to collapse
You can check the helper classes (e.g. XposedHelpers) and read the Java docs.

perseus0807 said:
This is exactly what I was looking for, thank you! Although you were wrong about the inherited part; mTextView is a member of Editor.
I'm curious - where did you read all this? There doesn't seem to be very cohesive documentation on the wiki :/
Thanks again!
Click to expand...
Click to collapse
There is a wiki page about the helpers, but it doesn't cover them all. The best thing is to check the existing methods and read the javadocs, as mentioned by GermainZ.

Related

[Q] Creating a class which extends an abstract class defined in the target apk

I used dex2jar on the apk I am hooking and made it an external jar in eclipse and all my references to classes in it get resolved in eclipse and it doesn't complain. But the code in my module is failing. Specifically, I'm trying to create a class which extends an abstract class in the original apk. When I try to do new MyClass(); the logcat shows:
Unable to resolve superclass
Is there any way to make it work the way I have it, or is there some other way that I need to instantiate my own instance of an abstract class?
If you just instantiate a class, I think Java tries to resolve it using the calling class's classloader. That classloader only knows the classes in your APK, and otherwise falls back to the boot classloader.
The only chance I see is to put your subclass into a separate JAR, then during handleLoadPackage() create a new PathClassLoader and use lpparam.classLoader as parent. Then I think you should be able to find and instantiate your class via reflection.
rovo89 said:
If you just instantiate a class, I think Java tries to resolve it using the calling class's classloader. That classloader only knows the classes in your APK, and otherwise falls back to the boot classloader.
The only chance I see is to put your subclass into a separate JAR, then during handleLoadPackage() create a new PathClassLoader and use lpparam.classLoader as parent. Then I think you should be able to find and instantiate your class via reflection.
Click to expand...
Click to collapse
Thanks for the tip on using the class loader. I managed to get it working without a jar:
Code:
String dexPath = (String)XposedHelpers.getObjectField(getClass().getClassLoader(), "originalPath");
PathClassLoader combinedClassLoader = new PathClassLoader(dexPath, lpparam.classLoader);
Class<?> c = combinedClassLoader.loadClass("MY.CLASS");
EDIT: So it seems I'm able to do c.newInstance() directly in handleLoadPackage, but if I am inside of a replaceHookedMethod I still get the unable to resolve. It's good enough for what I need, because I can create the class in handleLoadPackage just fine.
EDIt2: Well nevermind, it works in both places. It seems I was trying to cast it, and that is what was causing the error. So when doing this, you have to use generic objects, which I suppose makes sense, since the class loader in that context isn't the combined one.
Thanks for posting the solution! Be careful with getClass(), as it depends on where you use it. You might want to grab your APK's path in initZygote instead.
rbox said:
It seems I was trying to cast it, and that is what was causing the error. So when doing this, you have to use generic objects, which I suppose makes sense, since the class loader in that context isn't the combined one.
Click to expand...
Click to collapse
Yes, you can't cast between objects/classes loaded from different class loaders, even when they are the same class from the same APK. Also, it would probably not work in your situation because the class can't be resolved with your class loader.

[Q] [Problem] How to list parameters in

It's quite a simple one I hope. Also, apologies for adding noise to the forum, but I couldn't find any detailed documentation or many tutorials.
I'm making use of findAndHookMethod for a little test project of mine. The problem is, the method which I am hooking has custom classes in its parameters.
Obviously I don't have access to these classes in terms of having the source code imported, so my first thought was just to list the paramaters as Object.class, but this didn't work.
What (if any) are the solutions? Thanks!
P.S.
In case I worded it badly. Say I have method to be hooked...
public void methodThatDoesSomething(ThisCustomClass nameOfParameter)
How do I use findAndHookMethod when listing parameters, as ThisCustomClass.class is not within the scope of my project
Use a string with the class' full name, e.g. "com.hooked.package.ThisCustomClass".

[Q] Overriding non-overrode method of a class

I am hooking a class that extends FrameLayout. The FrameLayout has an override method of "onInterceptTouchEvent" that I would like to hook, however, the custom class that I am hooking never overrides this method. So doing the usual, XposedHelpers.findAndHookMethod() causes "method not found exception". I feel like I have done this before, but can't recall exactly what I did to make it work.
Any help is appreciated!
@GermainZ
You have any idea how to do this?
Tip from MohammadAG: you can override the superclass' method (FrameLayout.onInterceptTouchEvent) and check for the class name of the current instance (to see if it matches the class you want to hook or not).
GermainZ said:
Tip from MohammadAG: you can override the superclass' method (FrameLayout.onInterceptTouchEvent) and check for the class name of the current instance (to see if it matches the class you want to hook or not).
Click to expand...
Click to collapse
Thanks man. I wasn't sure if that would work since the custom class doesn't call super.onInterceptTouchEvent() but I will try it. Thanks again boss!

[Q] Idea about how to get values from a table

Hello!
As some could see in my other topic, I'm learning about android studio to make an app with some maths to help me with my job.
Well, in one specific case, I need to search and get values in a table, based in a reference. Its basically like the VLOOKUP/HLOOKUP function in Excel.
My doubt is the ideal way of doing that, is there any kind of table inside the android studio, like a container or something ? Or I should use a data base ?
Below is the same math, on excel, that is the base that I'm creating the app for android, in this case is a simple table, but in some cases are many values:
The attachment 001.png is the list where I select the materials Standard, and then I get the 2 values σt and σe from the table.
The attachment 002.png is the table I am looking for the values:
Sorry about this kind of question, but I'm just reading a lot, looking for tips leading me to an ideal way of doing it, but its a little hard in the beginning.
Thanks in advanced.
Barata
Conversion
Hey from your question , I undestood that you are looking for ready table to give values.
As i see you are getting values in excel.
1) There is no direct conversion table available into android studio.
2) You can use library project import if you require familiar conversion tables.
3) If in excel you make your own conversion method . apply same into Anddroid studio.
What more , share your method or query breif.
Hello,
Thanks for replying satyampv,
Actually my doubt isnt about conversion, I said about excel because I'm used to work with it. And its so easy to use vlookup there that I was wondering if would have something like it on android studio .
If I have to put some huge table in a database here on android, it's ok, I accepted that I would have to do it. But the doubt is if I really have to use a database, or if exists other way to look up for values in a table. Like you said "2) You can use library project import if you require familiar conversion tables.", is that an alternative for a database ?
Or should I just forget those "normal tables" from my mind and use SQL lite ? Because is just to look for values, just read, I don't need to write neither do any changes in the table after it's created.
Thanks in advanced, again.
barata

How to find which imports classes are defined in

LayoutInflater inflater, ViewGroup container
I am trying to google these classes so I know what imports to add to my list.
But it is a hit and miss affair - sometimes I find suitable examples showing the correct import files, often I don't.
It is probably going to be import XXX.XXX.LayoutInflater, but I have little idea what the XXX.XXX.part of it is going to be.
Is there a website where all this is adequately documented and quick and simple to determine?
gregaryb said:
LayoutInflater inflater, ViewGroup container
I am trying to google these classes so I know what imports to add to my list.
But it is a hit and miss affair - sometimes I find suitable examples showing the correct import files, often I don't.
It is probably going to be import XXX.XXX.LayoutInflater, but I have little idea what the XXX.XXX.part of it is going to be.
Is there a website where all this is adequately documented and quick and simple to determine?
Click to expand...
Click to collapse
If you are using Android Studio, If when you declare an element, say LayouInflater layout, it gives you an error, double click and select "LayoutInflater" word and it should show you the missing import. This should happen as well when trying to compile with this kind of errors.
Ciuffy's SM-G900F CM 12.1 spirit hath marked this way. Thank if helped your soul.

Categories

Resources