Calling another method from another class - Xposed General

I have hooked a function from a class (w.class) and I want to call another function from another class (x.class). However, this x.class does not have any context or instance.
I tried searching XDA, Google and Github, but couldn't solve my problem. The closest thing I found was https://forum.xda-developers.com/xposed/findclass-returning-java-lang-class-t2853108 but as I stated, I do not have a context or instance.
My w.class is:
PHP:
final class w
extends Thread
{
private Handler b = new Handler();
w(SplashActivity paramSplashActivity) {}
public final void run()
{
this.b.postDelayed(new x(this), 2000L);
super.run();
}
}
and the x.class is
PHP:
final class x
implements Runnable
{
x(w paramw) {}
public final void run()
{
w.a(this.a).startActivity(new Intent(w.a(this.a).getApplicationContext(), pack.class));
}
}
I have hooked the run() function from w.class, but I don't know how to call the run() method from x.class.
My Xposed module looks like this:
PHP:
XposedHelpers.findAndHookMethod("com.pack.w", lpparam.classLoader, "run", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) {
XposedBridge.log(TAG + " we are replacing... " );
Class<?> classstart = XposedHelpers.findClass("com.pack.x", lpparam.classLoader);
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
XposedHelpers.callMethod(class2Instance, "run");
XposedBridge.log(TAG + " replacing should be done " );
return null;
}
});
but since there is no "context" in x.class, it does not get the object and I cannot use callMethod()
any ideas, please? I am bit stucked
P.S.: Btw, the main goal is to remove the 2000ms wait from "postDelayed()". I did it through .smali already, but wanted to learn how to do it in Xposed.

still nothing?

I feel like this is more complicated than necessary. If Xposed weren't in the picture, and you were writing code that would end up in w.class, what statement would you put there to do what you want?

josephcsible said:
I feel like this is more complicated than necessary. If Xposed weren't in the picture, and you were writing code that would end up in w.class, what statement would you put there to do what you want?
Click to expand...
Click to collapse
Hi and thanks for answering!
I would just write a call to the e.class.

rauleeros said:
Hi and thanks for answering!
I would just write a call to the e.class.
Click to expand...
Click to collapse
I meant can you post the exact line of Java that you'd add, and which method you'd put it in?

josephcsible said:
I meant can you post the exact line of Java that you'd add, and which method you'd put it in?
Click to expand...
Click to collapse
Well, I would simply replace it with this:
PHP:
public final void run()
{
this.b.postDelayed(new x(this), 10L); // run for 10ms instead of 2 seconds
super.run();
}

rauleeros said:
Well, I would simply replace it with this:
PHP:
public final void run()
{
this.b.postDelayed(new x(this), 10L); // run for 10ms instead of 2 seconds
super.run();
}
Click to expand...
Click to collapse
Why are you involving a Context at all? Try this:
Code:
// Replace this:
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
// With this:
Object class2Instance = XposedHelpers.newInstance(classstart, param.thisObject);

josephcsible said:
Why are you involving a Context at all? Try this:
Code:
// Replace this:
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "context");
Object class2Instance = XposedHelpers.newInstance(classstart, context);
// With this:
Object class2Instance = XposedHelpers.newInstance(classstart, param.thisObject);
Click to expand...
Click to collapse
Didn't even realize I could do it as simple as that! Thanks a lot for the help, I really appreciate it man

Related

How to use hidden class in hook?

I have something like this..
Code:
XposedHelpers.findAndHookMethod(packageManagerService,
"installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class, new XC_MethodHook()
bla bla...
But IPackageInstallObserver.class is not resolved (hidden, not in SDK). So, devs, how can I use it? Any workaround? I just need it to make hook working. For info, I am going to hook flags, not observer.
pyler said:
I have something like this..
Code:
XposedHelpers.findAndHookMethod(packageManagerService,
"installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class, new XC_MethodHook()
bla bla...
But IPackageInstallObserver.class is not resolved (hidden, not in SDK). So, devs, how can I use it? Any workaround? I just need it to make hook working. For info, I am going to hook flags, not observer.
Click to expand...
Click to collapse
Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)
rovo89 said:
Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)
Click to expand...
Click to collapse
This is awesome. Thank you!
rovo89 said:
Simply use the string "android.content.pm.IPackageInstallObserver" instead of IPackageInstallObserver.class. You can do the same for the first class name:
Code:
XposedHelpers.findAndHookMethod("com.android.server.pm.PackageManagerService", null,
"installPackage", Uri.class, "android.content.pm.IPackageInstallObserver", int.class, String.class, new XC_MethodHook()
bla bla...
(classloader is null here because the class is part of the BootClassLoader, usually you would use lpparam.classLoader instead)
Click to expand...
Click to collapse
hello @rovo89
I know that I can use the string ... instead of .....class to use "findAndHookMethod",
but if I want to get the parameter in "beforeHookedMethod", like this:
Code:
XposedHelpers.findAndHookMethod("com.example.main", null,
"a", "com.example.Details", int.class, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
int i = (Integer)param.args[1];
String s = (String)param.args[2];
.........
}
});
I can get the parameters like this: int i = (Integer)param.args[1]; String s = (String)param.args[2];
but what about the first one?
how to define "(Details)param.args[0]"?
thanks.
aoei said:
I can get the parameters like this: int i = (Integer)param.args[1]; String s = (String)param.args[2];
but what about the first one?
how to define "(Details)param.args[0]"?
Click to expand...
Click to collapse
That's not possible. You have to assign it to an Object variable and then keep using reflection to get/set its fields and call methods. The methods in XposedHelpers make this very easy.
rovo89 said:
That's not possible. You have to assign it to an Object variable and then keep using reflection to get/set its fields and call methods. The methods in XposedHelpers make this very easy.
Click to expand...
Click to collapse
Got it! Thank you very much!
rovo89 said:
That's not possible. You have to assign it to an Object variable and then keep using reflection to get/set its fields and call methods. The methods in XposedHelpers make this very easy.
Click to expand...
Click to collapse
what we don't know the parameter type ?
for example parameter type keep changing per class in update ,do we have something like keeping Object.class or unknown.class in paramtere type

Replace method. Need help. PLease

Hi everyone. I ask for help. I literally beg for it..
com.android.dialer.dialpad.LatinSmartDialMap
You can see it here http://grepcode.com/file/repository...id/dialer/dialpad/LatinSmartDialMap.java?av=f
I only want to replace method . Any of them.
For example I want this method returns FALSE every time it's called.
Code:
@Override
public boolean isValidDialpadAlphabeticChar(char ch) {
return (ch >= 'a' && ch <= 'z');
}
Here is my code
Code:
public class Fm implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam loadpkg) throws Throwable {
if (loadpkg.packageName.equals("com.android.dialer")) {
ClassLoader classLoader = loadpkg.classLoader;
XC_MethodReplacement methodreplacer = new XC_MethodReplacement() {
protected Object replaceHookedMethod(
XC_MethodHook.MethodHookParam paramAnonymousMethodHookParam)
throws Throwable {
XposedBridge.log("ALLLLL RIGHTTTT . NOW We ARE IN. AND MADE IT FALSe");
return false;
}
};
XposedHelpers.findAndHookMethod("com.android.dialer.dialpad.LatinSmartDialMap", loadpkg.classLoader,
"[COLOR="Red"]isValidDialpadAlphabeticChar[/COLOR]", Character.class, methodreplacer);
}
}
}
But this doesn't work
Here what I see in xposed log file:
java.lang.NoSuchMethodError: com.android.dialer.dialpad.LatinSmartDialMap#isValidDialpadAlphabeticChar(java.lang.Character)#exact
at de.robv.android.xposed.XposedHelpers.findMethodExact(XposedHelpers.java:179)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:129)
at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
at com.s0bes.fmspeaker.Fm.handleLoadPackage(Fm.java:30)
at de.robv.android.xposed.IXposedHookLoadPackage
BUUUT. If I will try to replace other method. For example
matchesCombination in com.android.dialer.dialpad.SmartDialNameMatcher (http://grepcode.com/file/repository...dialer/dialpad/SmartDialNameMatcher.java?av=f)
Here the part of code which was changed:
Code:
XposedHelpers.findAndHookMethod("com.android.dialer.dialpad.SmartDialNameMatcher", loadpkg.classLoader,
"matchesCombination", String.class, String.class, ArrayList.class, methodreplacer);
Now everything work...
So, it works with one thing and doesnt work with method I need
If you want to replace a method to return a consatnt, you can use the XC_MethodReplacement.returnConstant(…) shortcut. For example:
Java:
XposedHelpers.findAndHookMethod("com.android.dialer.dialpad.SmartDialNameMatcher", loadpkg.classLoader,
"matchesCombination", String.class, String.class, ArrayList.class, XC_MethodReplacement.returnConstant(false));
As for your problem, you're trying to hook isValidDialpadAlphabeticChar(Character.class), but you should be hooking isValidDialpadAlphabeticChar(char.class). Just replace "Character.class" by "char.class" in your findAndHookMethod call.

How to make an activity to open a url

Hello! I dont know much about coding so i decided to buy an app about quotes. The thing is i have opened it in android studio and want to make some changes. Specifically i want i want to change the button ''authors'' and instead of opening an activity i want to open a web link. How i am supposed to do that?
I hope this bit of code helps :
I think the button i want to change is this in the android manifest
<activity
android:name="com.axdev.quotes.AuteursActivity"
android:label="@string/title_activity_auteurs"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- Points to searchable activity -->
<meta-data android:name="android.app.default_searchable"
android:value=".AuteursActivity" />
<!-- Points to searchable meta data -->
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
Hi!
Code:
author_button.setOnClickListener(buttonClick);
private View.OnClickListener buttonClick = new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("your link"));
startActivity(intent);
}
};
Where to put code
Ducktamine said:
Hi!
Code:
author_button.setOnClickListener(buttonClick);
private View.OnClickListener buttonClick = new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("your link"));
startActivity(intent);
}
};
Click to expand...
Click to collapse
Thank you very much for your reply! Where do i have to put this code? In the android manifest? Also do i have to replace something first?
Looks like it should be in com.axdev.quotes.AuteursActivity, just find the place where click listener for button ''authors'' is setted. And replace code of listener.
Button
I cant find it. Here is th code
public class AuteursActivity extends ActionBarActivity {
private ArrayList<Quote> imageArry = new ArrayList<Quote>();
private AuthorsListAdapter adapter;
private DataBaseHandler db;
private ListView dataList;
SearchView searchView;
private AdView adView;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auteurs);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
db = new DataBaseHandler(this);
List<Quote> authors = db.getAllAuthors("");
for (Quote cn : authors) {
imageArry.add(cn);
}
adapter = new AuthorsListAdapter(this, R.layout.author_items, imageArry);
dataList = (ListView) findViewById(R.id.listView1);
dataList.setAdapter(adapter);
dataList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
Quote srr = imageArry.get(position);
Intent i = new Intent(getApplicationContext(),
QuotesActivity.class);
i.putExtra("name", srr.getName());
i.putExtra("mode", "isAuthor");
startActivity(i);
}
});
Here it is:
Code:
@override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
Quote srr = imageArry.get(position);
Intent i = new Intent(getApplicationContext(),
QuotesActivity.class);
i.putExtra("name", srr.getName());
i.putExtra("mode", "isAuthor");
startActivity(i);
}
});
cant build apk
Thank you! I made the changes but when i go to build the apk it gives the following errors
error: <identifier> expected
error: <identifier> expected
error: <;> expected
error: <identifier> expected
error: <identifier> expected
nickblu said:
Thank you! I made the changes but when i go to build the apk it gives the following errors
error: <identifier> expected
error: <identifier> expected
error: <;> expected
error: <identifier> expected
error: <identifier> expected
Click to expand...
Click to collapse
looks like errors in your syntax.
I strongly recommend to pick some basics skills in programming, study java and android development, if you really want to make good app by yourself.

[Q] How to modify memory capacity?

Hello guys,
Here is the script to get RAM capacity of a device. It's really different to other device specs that I read.
I have no idea how to hook to change it (memInfo.totalMem) .
PHP:
ActivityManager actManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;
The system file "/proc/meminfo" also holds RAM memory info, I tried to modify this file but didn't affect.
Is there anyway to solve this problem??
Have a nice day.
kidsphy said:
Hello guys,
Here is the script to get RAM capacity of a device. It's really different to other device specs that I read.
I have no idea how to hook to change it (memInfo.totalMem) .
PHP:
ActivityManager actManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;
The system file "/proc/meminfo" also holds RAM memory info, I tried to modify this file but didn't affect.
Is there anyway to solve this problem??
Have a nice day.
Click to expand...
Click to collapse
You can try:
Code:
ActivityManager.MemoryInfo memInfo = (ActivityManager.MemoryInfo) XposedHelpers.newInstance(ActivityManager.MemoryInfo.class);
XposedHelpers.setObjectField(memInfo, "totalMem", 141211211L);
OR:
Code:
Constructor<?> constructLayoutParams = XposedHelpers.findConstructorExact(android.app.ActivityManager.MemoryInfo.class, Parcel.class);
constructLayoutParams.setAccessible(true);
XposedBridge.hookMethod(constructLayoutParams, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.args[0] != null) {
param.args[0] = new CustomMemoryInfo();
}
}});
CustomMemoryInfo extends MemoryInfo class, you can override super method to change "totalMem" attribute
hahalulu said:
You can try:
Code:
ActivityManager.MemoryInfo memInfo = (ActivityManager.MemoryInfo) XposedHelpers.newInstance(ActivityManager.MemoryInfo.class);
XposedHelpers.setObjectField(memInfo, "totalMem", 141211211L);
OR:
Code:
Constructor<?> constructLayoutParams = XposedHelpers.findConstructorExact(android.app.ActivityManager.MemoryInfo.class, Parcel.class);
constructLayoutParams.setAccessible(true);
XposedBridge.hookMethod(constructLayoutParams, new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.args[0] != null) {
param.args[0] = new CustomMemoryInfo();
}
}});
CustomMemoryInfo extends MemoryInfo class, you can override super method to change "totalMem" attribute
Click to expand...
Click to collapse
Thank for your reply, but it doesn't work. Have you ever tried running this piece or it's just your thinking?
Here's a commented example of doing this (at least for the method that you posted):
Java:
// Hook the method getMemoryInfo from the ActivityManager class
XposedHelpers.findAndHookMethod(ActivityManager.class, "getMemoryInfo", ActivityManager.MemoryInfo.class, new XC_MethodHook() {
// We use afterHooked here because you have to modify the values *after* the method already setup the object,
// as this method take the object passed as argument and parcel the data (it's always good to check the source)
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ActivityManager.java#2358 > which calls
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ActivityManagerNative.java#4918
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Method contructor -> public void getMemoryInfo(MemoryInfo outInfo)
// As you can see, the getMemoryInfo take a MemoryInfo object as argument
// you just have to get the object from the arguments array, and then cast
// to MemoryInfo to set the desired field
((ActivityManager.MemoryInfo) param.args[0]).totalMem = 12345678L;
((ActivityManager.MemoryInfo) param.args[0]).availMem = 87654321L;
}
});
mauricio_C said:
Here's a commented example of doing this (at least for the method that you posted):
Click to expand...
Click to collapse
Thank you so much :good:

Run Java Class With Root Permissions (Not running)

SU Version 2.82 and using BlueStacks 3
I've made a post on StackExchange but w/o any responses - inside are links I'll reference below but unfortunately can't directly post here due to being a new user of these forums. Googling the following should turn up the result: SU Command to start java class for input automation not working
Since then I've learned a bit more about what I'm trying to do (which is surprising considering I've been attempting this since the 30th of January) and implemented a singleton so that I can toast from within the class I'm attempting to start. Regardless of whether this allows me to inject inputs to other apps, my current problem is simply that I'm unable to use a SU command to open up my Main.Java class as described in the following links:
The code describing what I'm trying to do: OmerJerk Execute Java Class as Root User
The code w/ a full implementation: Remotedroid on GitHub
^ ServerService runs MainStarter which runs Main.Java as SU so that Main.Java can run EventInput to inject motion events
The super basic implementation I've got is below, but I've tried a bunch of things. I can't seem to figure out what's going wrong.
A snippet from ActivityMain wherein I'm running the Main.Java (attempting at least):
Code:
new Main().main(COMMAND3); //COMMAND3 is just a String[] because if it's not provided this won't execute. This isn't what I'm trying to do, though. Just a test to see if my Main.Java was broke.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids){
try {
//BlueStacks is 32 bit so it only has app_process - it doesn't have app_process32 and I believe if you try to target it it simply fails (the symbolic link is inconsistent iirc) vv
String[] COMMAND4 = {"su", "-c", "\"CLASSPATH=" + MainActivity.this.getPackageCodePath(), "/system/bin/app_process", "/system/bin", MainActivity.this.getPackageName() + ".Main"};
java.lang.Process console = Runtime.getRuntime().exec(COMMAND4);
BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(console.getOutputStream()));
String outputStr = new String();
BufferedReader reader = new BufferedReader(new InputStreamReader(console.getInputStream()));
while (reader.ready()) {
outputStr += reader.readLine();
}
PropertyReader.getInstance().setText(outputStr);
} catch (IOException e) {
e.printStackTrace();
PropertyReader.getInstance().showToast("IOException" + e.getMessage());
}
// final List<String> SUOutput = Shell.SU.run(String.format(COMMAND,
// new String[] {
// getApplicationContext()
// }));
// final String joined = TextUtils.join(", ", SUOutput);
//
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (SUOutput != null) {
// Toast.makeText(MainActivity.this, "Output isn't null" + joined, Toast.LENGTH_LONG).show();
// Toast.makeText(MainActivity.this, joined, Toast.LENGTH_LONG).show();
// Toast.makeText(MainActivity.this, SUOutput.toString(), Toast.LENGTH_LONG).show();
//
// } else {
// Toast.makeText(MainActivity.this, "Output is null o-o", Toast.LENGTH_LONG).show();
// }
// }
// });
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "It finished.. ?", Toast.LENGTH_LONG).show();
PropertyReader.getInstance().ToastString();
}
});
return null;
}
}.execute();
}
And my Main.Java is reaaaally simple and very stripped down at this point:
Code:
package intsumniac.overbitegames.com.intsumniac;
import android.os.Process;
public class Main {
public static void main(String[] args) {
PropertyReader.getInstance().showToast("Main Is working!!! SUCCESS" + "current process id = " + Process.myPid() + "current process uid = " + Process.myUid()); //Should be 0, preferably
}
}
It is certainly possible to run Java stuff as root, however you are lacking many contexts/instances/etc. There is some trickery to be able to get around some of that. Some of my apps' root parts are mostly Java, in fact.
Rule of thumb is that most Android API calls are not available, just standard Java things. Toasting for example is most certainly not available.

Categories

Resources