XClasses - A Xposed Library - Xposed Framework Development

Hello guys,
I want to share my library XClasses.
My idea was to see every XClass as an extension of the original class.
My aim was to improve the user experience during the development.
Also I wanted to increase the readability of xposed code.
So it's nothing special.
It's just my personal opinion how readable code should look like.
A small example:
Code:
public class XposedMain implements IXposedHookLoadPackage
{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
if(lpparam.packageName.equals("com.android.systemui"))
{
XposedHelpers.findAndHookMethod(TextView.class, "setText", CharSequence.class, TextView.BufferType.class, boolean.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param)
throws Throwable {
TextView tv = (TextView)param.thisObject;
CharSequence text = (CharSequence)param.args[0];
TextView.BufferType type = (TextView.BufferType)param.args[1];
boolean notifyBefore = (Boolean)param.args[2];
int oldlen = (Integer)param.args[3];
XposedBridge.log("setText "+text+" with size "+tv.getTextSize());
}
});
}
}
}
The same code with XClasses:
Code:
// class 1
public class XposedMain implements IXposedHookLoadPackage
{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
if(lpparam.packageName.equals("com.android.systemui"))
{
setup(lpparam.classLoader);
hook(XTextView.class);
}
}
}
// class 2
public class XTextView
extends AbstractXClass<TextView>
{
public static String getOriginalClassName() { return TextView.class.getCanonicalName(); }
public XTextView(TextView objectThis) { super(objectThis); }
@BeforeOriginalMethod
private void setText_Before(CharSequence text, TextView.BufferType type,
boolean notifyBefore, int oldlen) throws Throwable {
XposedBridge.log("setText "+text+" with size "+getThis().getTextSize());
}
}
If you would like to know more you should visit the following site: https://github.com/seebye/XClasses
Regards,
Seebye

Related

[App] QuickSnap - Makes up for no hardware camera button

Very simple application that makes up (slightly) for not having a dedicated camera button.
Install the app, put a shortcut to it on your homepage. Shortcut will open (as quickly as possible) a preview window. Tapping anywhere on the screen will take a photo. Back button to exit.
QuickSnapNoAutofocus.apk - Takes pictures instantly, but you need a steady hand or your picture will be blurred!
QuickSnapAutoFocus.apk - Takes pictures using autofocus, so there is a delay while it focuses, but the pictures can't be blurred.
Saves the images to internal sd card as $DT.jpg on a seperate thread. Multiple taps on the screen to take lots of pictures quickly. (Supports multitouch! )
Source is in the next post - if anybody knows how to override the home or power button, give a shout!
Code:
package com.rc.QuickSnap;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class QuickSnap extends Activity {
Camera cam;
ExecutorService executorService;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onPause() {
super.onPause();
try {
cam.stopPreview();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
cam.release();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
executorService.shutdown();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
executorService = Executors.newSingleThreadExecutor();
try {
SurfaceView surface = (SurfaceView) findViewById(R.id.surface);
SurfaceHolder sh = surface.getHolder();
sh.setKeepScreenOn(true);
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
sh.addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("QuickSnap", "surfaceDestroyed");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.i("QuickSnap", "surfaceCreated");
try {
cam = Camera.open();
cam.setPreviewDisplay(holder);
cam.startPreview();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.i("QuickSnap", "surfaceChanged");
try {
cam.setPreviewDisplay(holder);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.i("QuickSnap", "TouchEvent");
cam.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
cam.takePicture(new ShutterCallback() {
@Override
public void onShutter() {
Log.i("QuickSnap", "Shutter");
}
}, null, new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.i("QuickSnap", "JPEG");
final byte[] finaldata = data;
executorService.submit(new Runnable() {
@Override
public void run() {
try {
FileOutputStream fileOutputStream = new FileOutputStream("/sdcard/" + sdf.format(new Date()) + ".jpg");
fileOutputStream.write(finaldata);
fileOutputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
camera.startPreview();
}
});
}
});
}
return true;
}
}
thx a lot !!
Looks great, gotta try. Thanks!
Has anyone got a mod that takes control of the Vol+ key for use with a camera?

[Q] Extract live wallpaper

Does anyone know where I can find code handling the current live wallpaper engine / view? I am trying to extract the live wallpaper for further processing (e.g. blurring).
I already found an entrance point: If the LWP used the standard com.android.internal.view.BaseSurfaceHolder supplied by the base class android.service.wallpaper.WallpaperService.Engine i can hook into lockCanvas and unlockCanvas to grab the image. But most LWPs do not use this, so I need another (more general) solution.
I thought about hooking all subclasses of android.service.wallpaper.WallpaperService, but AFAIK that's not possible without loading every single class and check if it's a subclass.
Any ideas?
Implementation for reference:
Code:
public class Hook implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
final Class<?> engingeClass = findClass("android.service.wallpaper.WallpaperService.Engine", loadPackageParam.classLoader);
final String packageName = loadPackageParam.packageName;
final Class<?> surfaceHolderClass = findClass("com.android.internal.view.BaseSurfaceHolder",loadPackageParam.classLoader);
findAndHookMethod(engingeClass, "getSurfaceHolder", new XC_MethodHook() {
private boolean isFirstCall = true;
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Field field = findField(param.thisObject.getClass(), "this$0");
WallpaperService service = (WallpaperService) field.get(param.thisObject);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(service);
if (isFirstCall && wallpaperManager.getWallpaperInfo().getPackageName().equals(packageName)) {
isFirstCall = false;
XposedBridge.log("Got context. Set up hooks...");
hook(surfaceHolderClass,service);
}
}
});
}
Bitmap bitmap;
Canvas internalCanvas;
Canvas originalCanvas;
private void hook(Class<?> clazz, final Context context) {
hookAllMethods(clazz, "lockCanvas", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
originalCanvas = (Canvas) param.getResult();
bitmap = Bitmap.createBitmap(originalCanvas.getWidth(),originalCanvas.getHeight(), Bitmap.Config.ARGB_8888);
internalCanvas = new Canvas(bitmap);
param.setResult(internalCanvas);
XposedBridge.log("Locked Canvas");
}
});
findAndHookMethod(clazz, "unlockCanvasAndPost", Canvas.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
originalCanvas.drawBitmap(bitmap,0,0,null);
param.args[0] = originalCanvas;
Intent intent = new Intent("com.faendir.lwpextractor.WALLPAPER_CHANGE");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100,bs);
intent.putExtra("bmp",bs.toByteArray());
context.sendBroadcast(intent, "com.faendir.lwpextractor.RECEIVE_WALLPAPER_CHANGE");
XposedBridge.log("Unlocked Canvas");
}
});
}
}
[this post is a copy of http://forum.xda-developers.com/xposed/modules/extract-live-wallpaper-t3260128, now posted here, because @Spott07 pointed out it would fit better]

Xposed module not working.

Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Wassupdog said:
Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Click to expand...
Click to collapse
I think that your code isn't doing anything. I'm not surprised it isn't working
What is
Wassupdog said:
Hello guys!
I'm learning to create Xposed modules and have a nice idea .
I'm just in the begining and I face a problem.
I'm trying to move the Google search bar in the Recent's window, this is my code:
Code:
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(final LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.android.systemui"))//check if the package being loaded is systemUI
return;
findAndHookMethod("com.android.systemui.recents.RecentsActivity", loadPackageParam.classLoader, "addSearchBarAppWidgetView", new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
AppWidgetHostView newSearchBar = (AppWidgetHostView) param.thisObject;
newSearchBar.setPadding(0,0,0,100);
}
});
}
}
but it ain't working for some reason.
Help?
Also, I don't really know how to control the views already exists in the code of Google.
I guess the problem is that I don't takeover Google's search bar but create one of my own, that does not show.
Click to expand...
Click to collapse
After a }, is ).
Please Check your Code.

[Q] How to use a variable from one hook in another? (Why is this an NPE?)

Hello, I have made this code
Link : http://hastebin.com/hiyupafibi.java
Duplicated here :
Code:
//In my module, I have this activity MainActivity, which has a function to generate random number
private int randomNumber() {
return (new Random()).nextInt(3);
}
//Toast this random number somewhere in the main activity
Toast.makeText(MainActivity.this, " " + randomNumber(), Toast.LENGTH_LONG).show();
//In XposedMod, make a hook
public class XposedMod implements IXposedHookLoadPackage {
private TextView tv;
public static final String PACKAGE_NAME = ".......";
@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals(PACKAGE_NAME)) {
Class<?> MainActivityClass = XposedHelpers.findClass(PACKAGE_NAME + ".MainActivity", lpparam.classLoader);
XposedHelpers.findAndHookMethod(MainActivityClass, "randomNumber", new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
try {
tv.setText("No NPE");
return 45;
} catch (NullPointerException e) {
return 44;
}
}
});
} else if (lpparam.packageName.equals("com.android.systemui")) {
Class<?> someClass = XposedHelpers.findClass("com.android.systemui.SomeClass", lpparam.classLoader);
XposedHelpers.findAndHookMethod(someClass, "someMethod", Context.class, new XC_MethodHook() {
@Override
protected Object beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
tv = new TextView((Context) param.args[0]);
if (tv==null)
XposedBridge.log("tv is null, apologies!");
}
});
}
}
}
Everytime that toast is supposed to be shown, I get the answer to be 44 (that is, tv is null), but that should not be the case, because the log statement when tv is null is not shown. What am I doing wrong?
Thanks for the help, I appreciate it.
Cheers!

Casting and reflection issues in a method argument. okhttp3.OkHttpClient$Builder;->addInterceptor(···)

Hi guys, I'm trying to hook the constructor of
Java:
okhttp3.OkHttpClient$Builder
in order to add an interceptor that converts any OkHttp call into a curl call and log it (see https://github.com/mrmike/Ok2Curl by MrMike). But I'm having problems with reflection, say I must haven't understood it pretty well...
The idea is to call
Java:
.addInterceptor(okhttp3.Interceptor)
method JUST after the
Java:
OkHttpClient$Builder
instance has been constructed, but it's more painful than expected. (See code and code comments for further details)
Java:
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
Class builderClass = XposedHelpers.findClassIfExists("okhttp3.OkHttpClient$Builder", lpparam.classLoader);
if(builderClass != null){
XposedBridge.hookAllConstructors(builderClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
CurlInterceptor interceptor = new CurlInterceptor(new Loggable() {
@Override
public void log(String message) {
Log.v("Ok2Curl", message);
}
});
/*
Attempt nº1:
Cannot do it this way, it throws an exception because there's not (and there's actually not) a method
'okhttp3.OkHttpClient$Builder#addInterceptor(CurlInterceptor)' since CurlInterceptor is from the Ok2Curl library.
Maybe the '.callMethod()' cannot make implicit casting?
*/
Object attempt1 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", interceptor);
/*
Attempt nº2:
Declaring explicitly the argument classes that addInterceptor(···) has, does not help.
I get an exception: it could not find an ".addInterceptor(java.lang.Class, ...CurlInterceptor)" method, so
this means Interceptor.class was taken as one of the method arguments and not as an argument type.
Anyways, given the results from attempt 1, it seems that .callMethod() will not do implicit casting whatsoever...
*/
Object attempt2 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", Interceptor.class, interceptor);
/*
Attempt nº3:
Explicit casting from CurlInterceptor to okhttp3.Interceptor did not help...
java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder#addInterceptor(com.moczul.ok2curl.CurlInterceptor)#bestmatch
*/
Object attempt3 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", (okhttp3.Interceptor) interceptor);
}
});
}
}
Thanks in advance!

Categories

Resources