Sorry, I know this is in the wrong section, but my post count would not let me post this anywhere else.
edit: I guess the title is slightly misleading, when the method LH64SpKkS1auK7N8sA is called, it now acts like there is no data left in ByteBuffer Ebn0ng1tXXh6Wa0h4V5Z
Anyways, I'm trying to capture packets with XPosed, however when I do this the app hangs for about 2 minutes(however captured packets are being logged) then force quits. I believe getStaticObjectField(docs claim it sets it to accessible, this is a private ByteBuffer) is possibly causing conflicts with other classes using the same field name. I have tried using field.setAccessible(false) after the getStaticObjectField call to no avail.
Code:
findAndHookMethod("com.AmZcqxXhvYDc8ktpbnHM", lpparam.classLoader, "LH64SpKkS1auK7N8sA", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Class<?> clazz = XposedHelpers.findClass("com.AmZcqxXhvYDc8ktpbnHM",lpparam.classLoader);
Field f = XposedHelpers.findField(clazz,"wQgxcxe7fAn3LzYJ8Jj");
//f.setAccessible(true);
if(XposedHelpers.getStaticBooleanField(clazz,f.getName())) {
XposedBridge.log("wQ true");
f = XposedHelpers.findField(clazz, "Ebn0ng1tXXh6Wa0h4V5Z");
//f.setAccessible(true);
ByteBuffer b = (ByteBuffer)XposedHelpers.getStaticObjectField(clazz,"Ebn0ng1tXXh6Wa0h4V5Z");
//f.setAccessible(false);
XposedBridge.log(b.toString());
//b.flip();
byte[] bytes = new byte[b.remaining()];
b.get(bytes);
String packet = new String(bytes);
XposedBridge.log("packet: " + packet);
}
else
XposedBridge.log("wQ false");
}
});
Related
Is there a way to use System context from non system app?
I try to create xposed module that enable double-tap to sleep in my specific app (the app is for G3 smart case only, so I try to mimic LG's stock Quick Circle apps).
I tried to override PowerManager.gotoSleep that will do
[CODEjava] mService.gotoSleep(time, GO_TO_SLEEP_REASON_DEVICE_ADMIN)[/CODE]
but it seem that the GO_TO_SLEEP_REASON_USER isn't the problem.
can I save the context of a system app for later use? using this code, context somewhy is null...
Java:
public class XposedModule implements IXposedHookLoadPackage {
static Context context;
[user=439709]@override[/user]
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.yoavst.quickapps")) {
findAndHookMethod("com.yoavst.quickapps.DoubleTapper", lpparam.classLoader, "onDoubleTap", Context.class, MotionEvent.class, new XC_MethodHook() {
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("onDoubleTap After; context: " + (context == null ? "null" : "notNull"));
if (context != null) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
powerManager.goToSleep(((MotionEvent) param.args[1]).getEventTime());
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
findAndHookMethod("com.android.systemui.SystemUIService", lpparam.classLoader, "onCreate", new XC_MethodHook() {
[user=439709]@override[/user]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// this will be called before the clock was updated by the original method
}
[user=439709]@override[/user]
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hooking onCreate: " + (param.thisObject == null ? "null" :"not Null"));
context = (Service) param.thisObject;
XposedBridge.log("context: " + (context == null ? "null" :"not Null"));
}
});
}
}
}
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
GermainZ said:
You could call AndroidAppHelper.currentApplication() if you need any context — it doesn't look you need the system's context anyway..
Click to expand...
Click to collapse
I need the context of an app with DEVICE_POWER permission (level 2 permission).
Oh, wait — your code won't work at all the way you expect it to work. Keep in mind the hooked code is running in the hooked app's process, so even though you set "context" in com.android.systemui, the "context" variable is still null in the "com.yoavst.quickapps" process (and will *always* be null).
You probably want to send a broadcast from your app instead, and register a BroadcastReceiver somewhere in SystemUI to handle it.
@yoavst you need to use a Device Policy Manager that will allow you to turn off the display. Doesn't even require root or xposed.
Hello,
i try to cast
Object test = param.args[1]; to
TestClass new = (TestClass) test;
But I get an error that the Class is not created?
What am i missing here?
Code:
Class<?> TestClass = Class.forName("com.android.internal.x");
Class<?> HookClass = Class.forName("com.android.systemui.z", false, lpparam.classLoader);
XposedHelpers.findAndHookMethod(HookClass, "someMethod", IBinder.class, TestClass, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
{
Object test = param.args[1];
TestClass testConverted = (TestClass) test;
}
});
Why are you trying to cast it? You probably don't need to and can keep it as an Object.
(Can't say much more without an exact error.)
GermainZ said:
Why are you trying to cast it? You probably don't need to and can keep it as an Object.
(Can't say much more without an exact error.)
Click to expand...
Click to collapse
Solved, i used XposedHelpers.getObjectField
to get the field i needed.
Xposed is awesoeme
Danke!
I'm trying to change the color of text from black to white. Modding the app with smali, I have narrowed it down to this portion of code. Where this.b(-16777216); would be the color black.
Code:
@Override
public void t() {
super.t();
this.p.setVisibility(8);
this.q.setVisibility(8);
this.n.setVisibility(8);
this.o.setVisibility(8);
this.u.setVisibility(8);
this.t.setVisibility(8);
this.r.setVisibility(8);
this.w.setVisibility(8);
this.x.setVisibility(8);
this.z.setVisibility(8);
this.C.setVisibility(8);
this.B.setVisibility(8);
this.D.setVisibility(8);
this.i.setVisibility(8);
this.k.setVisibility(8);
this.b(-16777216);
this.B.setOnClickListener(null);
this.D.setOnClickListener(null);
this.I = false;
}
So far this is where I am at. Logs not throwing any errors.
Edit.. I've also placed param.thisObject in place of null with no luck as well.
Code:
public class ClassName implements IXposedHookLoadPackage {
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.app.package"))
return;
findAndHookMethod("com.app.package.blah.blah.Class", lpparam.classLoader, "t", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.setIntField(null, "b", Color.WHITE);
}
});
}
}
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
C3C076 said:
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
Click to expand...
Click to collapse
OMG THANK YOU! It worked perfectly. I've been trying everything since Monday. Since I know what works and re-reading the section on the wiki about the callMethod helper, it makes a lot more sense now. Thanks again .
C3C076 said:
Try using Xposedhelpers.callMethod(param.thisObject, "b", Color.WHITE) instead of setIntField.
set***Field methods are for the purpose of setting values of field members of object.
"b" is not a field member. It's a method (function).
Click to expand...
Click to collapse
One last thing.. before I spend days trying to figure it out again lol. I'm getting a cannot cast to android....TextView with the following:
Edit: I think it is because I forgot to add the following:
Code:
String text = tv.getText().toString();
tv.setText(text);
I'll test when I get home.
Code:
XposedHelpers.findAndHookMethod("com.app.package.blah.blah.Class", lpparam.classLoader, "a", "com.app.package.blah.blah.AnotherClass", TextView.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
TextView tv = (TextView) param.thisObject;
tv.setTextColor(Color.WHITE);
}
});
This is what the portion of code looks like for the text color I am trying to change: textView.setTextColor(-16777216);
Code:
@Trace
private void a(FeedItem feedItem, TextView textView) {
this.b(chatFeedItem, textView);
if (feedItem instanceof StatefulChatFeedItem && (feedItem.Y() || feedItem.Z())) {
textView.setTextColor(this.b.getResources().getColor(2131230734));
return;
}
textView.setTextColor(-16777216);
}
Nevermind.. didn't work
93Akkord said:
Nevermind.. didn't work
Click to expand...
Click to collapse
Arguments of a function you are hooking are accessed using param.args array, not param.thisObject.
param.thisObject refers to the instance of an object you are working with. In your case,
it's an instance of "com.app.package.blah.blah.Class" class.
So proper way of getting that TextView which is a second argument of a function you are hooking is:
TextView tv = (TextView) param.args[1];
C3C076 said:
Arguments of a function you are hooking are accessed using param.args array, not param.thisObject.
param.thisObject refers to the instance of an object you are working with. In your case,
it's an instance of "com.app.package.blah.blah.Class" class.
So proper way of getting that TextView which is a second argument of a function you are hooking is:
TextView tv = (TextView) param.args[1];
Click to expand...
Click to collapse
Oh wow.. thanks. That worked. I actually tried TextView tv = (TextView) param.args[0];, among numerous other combinations, and never thought to try [1]. It makes me feel happy and sad at the same time lol. I appreciate the help :highfive:
dupe
param.args array is zero based and TextView is a second argument of a function. so:
- param.args[0] is FeedItem argument
- param.args[1] is TextView argument
I have a textview that shows your amount of money and i would like the ui to update every second to visually show how much money you have in real time. Would i be able to accomplish this with a timer?, and if so what would it look like.
Hello,
You should do inside your class, outside of any method:
Code:
TextView tv;
String calculatedString;
MyAsyncTask mAsync = null;
Timer timer = null;
TimerTask task = null;
private class MyAsyncTask extends AsyncTask<String, Void, String> {
public MyAsyncTask(){
}
@Override
protected String doInBackground(String... params) {
//Background operation in a separate thread
//Write here your code to run in the background thread
//calculate here whatever you like
calculatedString = ....;
return null;
}
@Override
protected void onPostExecute(String result) {
//Called on Main UI Thread. Executed after the Background operation, allows you to have access to the UI
tv.setText(calculatedString);
}
@Override
protected void onPreExecute() {
//Called on Main UI Thread. Executed before the Background operation, allows you to have access to the UI
}
}
inside the onCreate after super and setContentView:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
final Handler handler = new Handler();
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
MyAsyncTask mAsync = new MyAsyncTask();
mAsync.execute();
}
});
}
};
timer.schedule(task, 0, 1000); //Every 1 second
If you still need help, feel free to ask
I have attached 2 screenshots showing the errors i was given after inputting. Any idea how to fix this?
mmdeveloper10 said:
Hello,
You should do inside your class, outside of any method:
Code:
TextView tv;
String calculatedString;
MyAsyncTask mAsync = null;
Timer timer = null;
TimerTask task = null;
private class MyAsyncTask extends AsyncTask<String, Void, String> {
public MyAsyncTask(){
}
@Override
protected String doInBackground(String... params) {
//Background operation in a separate thread
//Write here your code to run in the background thread
//calculate here whatever you like
calculatedString = ....;
return null;
}
@Override
protected void onPostExecute(String result) {
//Called on Main UI Thread. Executed after the Background operation, allows you to have access to the UI
tv.setText(calculatedString);
}
@Override
protected void onPreExecute() {
//Called on Main UI Thread. Executed before the Background operation, allows you to have access to the UI
}
}
inside the onCreate after super and setContentView:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
final Handler handler = new Handler();
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
MyAsyncTask mAsync = new MyAsyncTask();
mAsync.execute();
}
});
}
};
timer.schedule(task, 0, 1000); //Every 1 second
If you still need help, feel free to ask
Click to expand...
Click to collapse
Hello,
For the first image:
You have to import the AsyncTask.
add this
Code:
import android.os.AsyncTask;
with the other imports in your java file.
For your second image:
You haven't wrote the line
Code:
setContentView(R.layout.activity_main);
under your super.onCreate(savedInstanceState); and then the code I said above (I said that on my post )
inside onCreate, where activity_main is your xml layout. And you should have inside that layout, a TextView with an id "tv" (or whatever you like)
and then:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
R.id.tv must much the id you have in your layout. Replace it with the actual id of your TextView. If your id is "tv", write R.id.tv, if it is "mytv" write R.id.mytv. ( I said that on my post also)
Can you show your layout file? (XML - your activity_main.xml). You said that you have a TextView Where is your TextView?
Ok I fixed the problems stated and now only have these two errors remaining
mmdeveloper10 said:
Hello,
For the first image:
You have to import the AsyncTask.
add this
Code:
import android.os.AsyncTask;
with the other imports in your java file.
For your second image:
You haven't wrote the line
Code:
setContentView(R.layout.activity_main);
under your super.onCreate(savedInstanceState); and then the code I said above (I said that on my post )
inside onCreate, where activity_main is your xml layout. And you should have inside that layout, a TextView with an id "tv" (or whatever you like)
and then:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
R.id.tv must much the id you have in your layout. Replace it with the actual id of your TextView. If your id is "tv", write R.id.tv, if it is "mytv" write R.id.mytv. ( I said that on my post also)
Can you show your layout file? (XML - your activity_main.xml). You said that you have a TextView Where is your TextView?
Click to expand...
Click to collapse
Have you imported this?
Code:
import java.util.logging.Handler;
If so, change it to
Code:
import android.os.Handler;
Im not at the computer but I think that should solve my issue I will keep you updated
Sent from my HTC6525LVW using XDA Free mobile app
Hey thanks so much its working perfectly now :good:
Hi,
I'm trying to hook some of the Android APIs in my module. I have a simple app consists of two activities (MyActivity, DisplayMessageActivity) and one service (LocationService). "MyActivity" starts "LocationService" using the following code:
Intent intent = new Intent(getApplicationContext(), LocationService.class);
startService(intent);
"MyActivity" can also start "DisplayMessageActivity" by pressing a button using the following code:
Intent intent = new Intent(this, DisplayMessageActivity.class);
startActivity(intent);
In the "LocationService", I register a GPS location listener at the start of service, which will update the "DisplayMessageActivity" upon change in the location or provider status as follows:
public int onStartCommand(Intent intent, int flags, int startId) {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onStatusChanged(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onProviderEnabled(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}
public void onProviderDisabled(Location location) {
Intent intent1 = new Intent(getApplicationContext(), DisplayMessageActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, locationListener);
return Service.START_NOT_STICKY;
}
I hooked the method "startActivity" in my module as follows:
XposedHelpers.findAndHookMethod("android.app.Activity", lpparam.classLoader, "startActivity", android.content.Intent.class, new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Intent intent = (Intent) param.args[0];
String destination = intent.getComponent().getClassName().split(lpparam.packageName+".")[1];
XposedBridge.log("(Intent,"+destination+")");
}
});
The module successfully logs the invocation of "startActivity" when I press the button (starting "DisplayMessageActivity" from "MyActivity"). But when "startActivity" is invoked from the service, the module does not log the invocation. I'm new to Xposed and I'm not sure why this is happening. Is this because the "startActivity" is called from a background service? What can I do to resolve the issue?
I really appreciate your help
You can go to rovo89's Github for help, he is keen at helping other's development.
You are hooking on startActivity method of android.app.Activity class.
This method is specific for Activity class only as it overrides startActivity from super class (ContextWrapper and Context which is abstract). Calling startActivity within Service class is like calling completely different method that's why your hook won't work here.
To be able to cover both cases, you will have to hook on lower level in class hierarchy.
Probably the best would be to hook onto startActivity(Intent intent, Bundle bundle) of ContextWrapper class as it is sure all calls made from either Activity or Service will go this path.
So
Code:
XposedHelpers.findAndHookMethod("android.content.ContextWrapper", lpparam.classLoader, "startActivity", Intent.class, Bundle.class, new XC_MethodHook() {
....
}