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
Related
I'm completely noob.
Here are the sources
http://grepcode.com/file/repository...cFeedback.java#HapticFeedback.0mHapticPattern
Code:
public void init(Context context, boolean enabled) {
mEnabled = enabled;
if (enabled)
{
mVibrator = new SystemVibrator(context);
mHapticPattern = new long[] {0, DURATION, 2 * DURATION, 3 * DURATION};
mSystemSettings = new Settings.System();
mContentResolver = context.getContentResolver();
}
}
I need to change mHapticPattern array to adjust vibration duration on dialpad.
So, I can use that
Code:
findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "init", new XC_MethodHook()
{
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// BUT I don't know what I have to write here to get it working :(
// I know that this method will be called after init method and I don't know how I can change mHapticPattern array :(
}
});
Or I think I can also change value of Duration
private static final long DURATION = 10;
Click to expand...
Click to collapse
But anyway I do not know how...
I will be glad if anyone will try to help me...
Changing DURATION directly will have no effect. This is because the compiler replaces final static variables with their values (so "10" will be directly used instead of "DURATION").
What you could do is replace the init(Context context, boolean enabled) method entirely. Check out the development tutorial (and other wiki pages) for some hints on where to get started.
GermainZ said:
Changing DURATION directly will have no effect. This is because the compiler replaces final static variables with their values (so "10" will be directly used instead of "DURATION").
What you could do is replace the init(Context context, boolean enabled) method entirely. Check out the development tutorial (and other wiki pages) for some hints on where to get started.
Click to expand...
Click to collapse
Thank you for your answer. But I did not see it till now. That's why my respond is so late.
I had one experience with replacing entire method. But it was just a boolean method. I used this example http://forum.xda-developers.com/showpost.php?p=34609860&postcount=4
And also I've tried to replace whole init method but I have a problem with that string:
Code:
mVibrator = new SystemVibrator(context);
I did
import android.os.SystemVibrator;
but this "android.os.SystemVibrator;" is highlighted with red in eclipse
It says "The import android.os.SystemVibrator cannot be resolved" but the file exists...
I have a code but because of that error I can't test it
S0bes said:
It says "The import android.os.SystemVibrator cannot be resolved" but the file exists...
Click to expand...
Click to collapse
It's possible it's not in the SDK. Use XposedHelpers.findClass(...) to get the SystemVibrator class, then XposedHelpers.newInstance(...) to create a new instance.
@GermainZ please help me. This is the last thing I want to implement. Dialpad vibration is heavy and I think it's not good for vibro inside my phone.
This is what I try but Vibration is gone after that:
PHP:
package com.s0bes.fmspeaker;
import android.content.Context;
import android.os.Vibrator;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.newInstance;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import android.content.ContentResolver;
import android.provider.Settings;
//import android.os.SystemVibrator;
public class bool1 {
static Context context;
private static Vibrator mVibrator ;
private static Settings.System mSystemSettings;
private static ContentResolver mContentResolver;
private static long[] mHapticPattern;
public static void InitResources(final LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("com.android.dialer")) {
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader,
"init", Context.class, boolean.class, new XC_MethodHook() {
@Override protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
XposedBridge.log("HOOOKED init" );
//context=(Context) param.args[0];
}
});
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "init", Context.class, boolean.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
context=(Context) param.args[0];
XposedBridge.log("REPLACED init. Enabled="+param.args[1] );
Class Myclass = findClass("android.os.SystemVibrator", lpparam.classLoader);
Object mVibrator = newInstance(Myclass, context);
mHapticPattern = new long[] {0, 10, 2 * 10, 8 * 10};
mSystemSettings = new Settings.System();
mContentResolver = context.getContentResolver();
return true;
}
});
}
}
}
EDIT:
Yeehoooo. I got this working
Your post http://forum.xda-developers.com/showpost.php?p=54951841&postcount=8 very helped me.
Instead replace init method I replaced vibrate();
PHP:
XposedHelpers.findAndHookMethod("com.android.phone.common.HapticFeedback", lpparam.classLoader, "vibrate", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
Class Myclass = findClass("android.os.SystemVibrator", lpparam.classLoader);
Object mVibrator = newInstance(Myclass, context);
mHapticPattern = new long[] {0, 10, 1 * 10, 1 * 10};
((Vibrator) mVibrator).vibrate(mHapticPattern, -1);
return true;
}
});
}
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 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() {
....
}
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");
}
});