Hook method in handler - Xposed General

My code
Code:
XposedHelpers.findAndHookMethod("com.android.packageinstaller.InstallAppProgress$mHandler",
lpparam.classLoader, "handleMessage", Message.class, new XC_MethodHook(){
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {...
https://github.com/android/platform...roid/packageinstaller/InstallAppProgress.java
I want hook method "handleMessage". But it doesnt work. Method not found.

pyler said:
My code
Code:
XposedHelpers.findAndHookMethod("com.android.packageinstaller.InstallAppProgress$mHandler",
lpparam.classLoader, "handleMessage", Message.class, new XC_MethodHook(){
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {...
https://github.com/android/platform...roid/packageinstaller/InstallAppProgress.java
I want hook method "handleMessage". But it doesnt work. Method not found.
Click to expand...
Click to collapse
are you sure InstallAppProgress$mHandler was exist? i've try to decompile Packageinstaller.apk of my phone and InstallAppProgress$mHandler doesn't exist, method handleMessage on my phone belong to InstallAppProgress$1.class

riskey95 said:
are you sure InstallAppProgress$mHandler was exist? i've try to decompile Packageinstaller.apk of my phone and InstallAppProgress$mHandler doesn't exist, method handleMessage on my phone belong to InstallAppProgress$1.class
Click to expand...
Click to collapse
I tried to remove $mHandler but still it isnt working.
Maybe @GermainZ can help?

That's an anonymous class, it'll be called InstallAppProgress$number. "number" is a counter (starts at 1, ends at n, where n is the number if anonymous classes in the enclosing class) chosen by the compiler at compile time. It's not guaranteed to stay the same.
You can hook it as riskey95 said, but it might not be InstallAppProgress$1 everywhere (could be e.g. InstallAppProgress$2). TIAS, and maybe blindly try hooking $1 to $3 if necessary (use a try/catch statement).

$1 worked. Now I need to get access to mDoneButton. But I cant since I am in InstallAppDetails$1.
Code:
@Override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {
//prefs.reload();
test = true;
if (test) {
Button mDone = (Button) XposedHelpers.getObjectField(
param.thisObject, "mDoneButton");
// todo
}
}

You can get the outer class using, for example:
Code:
XposedHelpers.getObjectField(param.thisObject, "this$0");
(There might be an Xposed helper or an alternate method to do that, I can't remember and I can't check right now.)

GermainZ said:
You can get the outer class using, for example:
Code:
XposedHelpers.getObjectField(param.thisObject, "this$0");
(There might be an Xposed helper or an alternate method to do that, I can't remember and I can't check right now.)
Click to expand...
Click to collapse
Fanstastic. All work now. I have to put your nick in XInstaller OP
Thank you.
p.s: found. getSurroundingThis

Hi,
can you please share the final code that worked for you in this case:
XposedHelpers.findAndHookMethod("com.android.packageinstaller.InstallAppProgress$mHandler",
lpparam.classLoader, "handleMessage", Message.class, new XC_MethodHook(){
@override
protected void afterHookedMethod(MethodHookParam param)
throws Throwable {...
Thanks!

Related

APK done! thanks again to everyone who helped!!!

edit: not much use in this thread anymore, except maybe a good reference for people making an app
How about rebooting the phone? Will that work?
well yeah, but i don't think people will pay for an app that reboots your phone each time you change the volume settings
I think its, Runtime.getRuntime.exec("your command");
have you seen this?
http://forum.xda-developers.com/showpost.php?p=3434331&postcount=35
hamshu said:
I think its, Runtime.getRuntime.exec("your command");
Click to expand...
Click to collapse
do you think you could elaborate a little more?
i'm still a complete java noob
Process process = Runtime.getRuntime().exec("killall mediaserver");
That line should do it.
hamshu said:
Process process = Runtime.getRuntime().exec("killall mediaserver");
That line should do it.
Click to expand...
Click to collapse
i've got:
try {
Process process = Runtime.getRuntime().exec("killall mediaserver");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
and it doesn't seem to do anything.
any ideas?
try {
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream out = new DataOutputStream(process.getOutputStream());
out.writeBytes("killall mediaserver\n");
out.writeBytes("exit\n");
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
try this, see what it does man
or try this:
Code:
try {
Class<?> execClass = Class.forName("android.os.Exec");
Method createSubprocess = execClass.getMethod("createSubprocess",
String.class, String.class, String.class, int[].class);
Method waitFor = execClass.getMethod("waitFor", int.class);
int[] pid = new int[1];
FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(
null, "/system/xbin/bb/killall", "mediaserver", null, pid);
FileInputStream in = new FileInputStream(fd);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String output = "";
try {
String line;
while ((line = reader.readLine()) != null) {
output += line + "\n";
}
} catch (IOException e) {
}
waitFor.invoke(null, pid[0]);
return output;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
} catch (SecurityException e) {
throw new RuntimeException(e.getMessage());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalArgumentException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage());
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getMessage());
}
the last bit of code i posted dude i know works with an ls command, but with this, we are trying to spawn killall and pass the mediaserver argument, so i dont know if the stack will even handle this.... doesnt hurt to try though
corp769 said:
the last bit of code i posted dude i know works with an ls command, but with this, we are trying to spawn killall and pass the mediaserver argument, so i dont know if the stack will even handle this.... doesnt hurt to try though
Click to expand...
Click to collapse
From the little I know about Android Development, I think that it will work. Then again, I am not a Java coder nor a Android Developer(C# coding ftw). Sorry about getting the Java code wrong, like I stated, I don't code any Java.
It's cool...meltus, how's it going? You have a pm btw...
sorry guys, not had any success yet, but my girlfriends come round so i'll be away for a while
I suppose you need superuser privileges to kill the mediaserver.
This might work :
Process process = Runtime.getRuntime().exec("su -c \"killall mediaserver\"");
Meltus said:
sorry guys, not had any success yet, but my girlfriends come round so i'll be away for a while
Click to expand...
Click to collapse
Pervert lol JK
Zappletoo said:
I suppose you need superuser privileges to kill the mediaserver.
This might work :
Process process = Runtime.getRuntime().exec("su -c \"killall mediaserver\"");
Click to expand...
Click to collapse
this kinda works. i get a SU permission request, but it doesn't reboot the mediaserver. any ideas? ><
alritewhadeva said:
Pervert lol JK
Click to expand...
Click to collapse
lies
goddammit i hate this damn app lol ><
now i've run across another problem, which is, i just realised the system needs to be in read/write mode (im an idiot).
so:
Code:
try {
Process process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
works fine. makes an SU request popup thing appear, but...
Code:
try {
Process process = Runtime.getRuntime().exec("mount -o rw,remount /dev/block/mtdblock3 /system");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
afterwards doesn't do anything. anyone know why this isn't working?
damn, i hate java lol
EDIT: I've also realised that
Code:
(Process process = Runtime.getRuntime().exec("su");
works fine but replacing it with
Code:
(Process process = Runtime.getRuntime().exec("reboot");
does nothing?!? wtf's going on!! lol
ONLY su works. no other commands seem to do anything
I'm not a coder by any means (more like a beta tester, but I can go through a code and 'see' it pretty easily) and I've often refered to this specific code for sms backup for root user app to do basic things..it basically uses two buttons and sends commands to the system. Check out the source code to see if it helps any: http://code.google.com/p/sms-backup-root/
Specifically the event when a button is pressed (notice it gets 'su' the same way you currently do, but does the actual commands differently):
Code:
backup.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
[B]os.writeBytes("cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard \n");[/B]
[B]os.writeBytes("exit\n");[/B]
os.flush();
process.waitFor();
builder.setMessage("Backup done.. Found it in /sdcard/mmssms.db");
builder.show();
} catch (Exception e) {
return;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// Be Happy :)
}
}
return;
} });
It uses writebytes to send the code to the os. Try your code around that template and it may give you what you want.
Again im no coder, but there are a lot of open source apps that can give you a start towards what you want to do. Hope that helps!
p.s. love the audio mods, keep up the great work! Let me know if you want graphic work :]
Here you go.
Runtime rt = Runtime.getRuntime();
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("reboot");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
I just ran this on my phone and it rebooted.... Once you start the process, you use .writeBytes to "type to it". As if you were at the terminal and just typed "su"...
Instead of "reboot", you could do "killall mediaserver" or anything else you want to type to the console...

findAndHookMethod help!

Hi all,
I need to set an hook to a method whose signature is
public ArrayList<Object> populateList(Map<String, Object> paramMap, boolean paramBoolean1, boolean paramBoolean2)
I do not seem able to retrieve the class for the first parameter (ie: Map<String, Object>). What sintax am I supposed to use when invoking the hook method?
findAndHookMethod(classString, lpparam.classloader, "populateList", ?????, boolean.class, boolean.class, new XC_MethodHook() {...}
Thanks in advance
Silver.
slvrbllt said:
Hi all,
I need to set an hook to a method whose signature is
public ArrayList<Object> populateList(Map<String, Object> paramMap, boolean paramBoolean1, boolean paramBoolean2)
I do not seem able to retrieve the class for the first parameter (ie: Map<String, Object>). What sintax am I supposed to use when invoking the hook method?
findAndHookMethod(classString, lpparam.classloader, "populateList", ?????, boolean.class, boolean.class, new XC_MethodHook() {...}
Thanks in advance
Silver.
Click to expand...
Click to collapse
Try "Map.class".
Off the top of my head, I think generics are not part of the method signatures with regards to uniqueness; they only serve to aid the compiler in checking types during compilation.
Tungstwenty said:
Try "Map.class".
Click to expand...
Click to collapse
Duh!! It worked...
Thanks mate!

Help FindHookMethod

to the point How to findAndHookMethod this method:
Code:
public static ujiCoba(String[] string) {
}
i've tried with code bellow, but didnt work
Code:
findAndHookMethod(findClass, classLoader, String.class, hook);
You're not passing the method's name to findAndHookMethod. Also, the argument's class should be String[].class.
GermainZ said:
You're not passing the method's name to findAndHookMethod. Also, the argument's class should be String[].class.
Click to expand...
Click to collapse
i'm typo.
its work
hi @GermainZ. last qustion..
Code:
private static void getDetail(Context context, long l1, Info info, int i, long l2) {
Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), Uri.parser(Prefs.PARSER), new String[] {"status","sent","date"}, "group_id=", l1, null, null);
}
method like that make me confuse. i want change sent to received, how can i do this?
riskey95 said:
hi @GermainZ. last qustion..
Code:
private static void getDetail(Context context, long l1, Info info, int i, long l2) {
Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), Uri.parser(Prefs.PARSER), new String[] {"status","sent","date"}, "group_id=", l1, null, null);
}
method like that make me confuse. i want change sent to received, how can i do this?
Click to expand...
Click to collapse
You can replace the method and replicate these two lines, doing whatever modifications you want.
See:
XC_MethodReplacement to replace the method,
findClass to get the SqliteWrapper class,
callStaticMethod to call SqliteWrapper.query.
The rest should be covered in the development tutorial/wiki.
GermainZ said:
You can replace the method and replicate these two lines, doing whatever modifications you want.
See:
XC_MethodReplacement to replace the method,
findClass to get the SqliteWrapper class,
callStaticMethod to call SqliteWrapper.query.
The rest should be covered in the development tutorial/wiki.
Click to expand...
Click to collapse
that method very long and i dont have full of source code. so i can't replace method.
riskey95 said:
that method very long and i dont have full of source code. so i can't replace method.
Click to expand...
Click to collapse
Next best thing I can think of:
in beforeHookedMethod for getDetail, hook SqliteWrapper.query.
In that hook, check if the third argument is equal to the string array you want. If so, change it.
In afterHookedMethod for getDetail, unhook SqliteWrapper.query.

Why use onClickListener for button function?

I am new in android development. In the first tutorial I saw that they use code like below for button function. (They were showing to make calculator and this is not that code) and was just adding this in the attribute menu with onclick.
Code:
public void onpressButton(View v)
{
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
However, from the next tutorial while they were using Toast they always started using onClickListener for which I need to write a lot of code than before .
Code:
public void addListnerToCheckBox() {
check1 = (CheckBox)findViewById(R.id.checkBox_dog);
check1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
}
}
);
}
But the same thing can be done by the first code I have written. Then why are they using onClickListener?
tanvir108115 said:
I am new in android development. In the first tutorial I saw that they use code like below for button function. (They were showing to make calculator and this is not that code) and was just adding this in the attribute menu with onclick.
Code:
public void onpressButton(View v)
{
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
However, from the next tutorial while they were using Toast they always started using onClickListener for which I need to write a lot of code than before .
Code:
public void addListnerToCheckBox() {
check1 = (CheckBox)findViewById(R.id.checkBox_dog);
check1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
}
}
);
}
But the same thing can be done by the first code I have written. Then why are they using onClickListener?
Click to expand...
Click to collapse
Because the setOnClickListener is a method which is listening for onClick events on a particular object in your case the Button, so when you press that button it will do the things you listed in the onClick method
But even with the first code it executes the commands written in the function.

[Newbie] Correct way to start some App when Android started

I finding a correct way to start some app when started Android or restared
I have something like
Code:
public void startSomeApp() {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("xxx.xxx.xxx");
if (launchIntent != null) {
context.startActivity(launchIntent);
}
}
But was wonder a correct way where should I put?
I try to push to
Code:
public void initZygote(StartupParam startupParam) throws Throwable {
startSomeApp();
}
But problem with context, any trick please?
1001z said:
I finding a correct way to start some app when started Android or restared
I have something like
But was wonder a correct way where should I put?
I try to push to
But problem with context, any trick please?
Click to expand...
Click to collapse
The correct way is without Xposed! Use the Android BOOT_COMPLETED broadcast.

Categories

Resources