修改.smali文件 [英] modifying .smali files

查看:233
本文介绍了修改.smali文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我反向工程了一些安卓的apk添加一些仪器进行功能测试。 我想知道给予smali如下如何添加像

  Log.e(TAG,有些descritpion,E);
 

在.smali文件中的每个方法。

 的.class公共LD;
。超Landroid /视图/视图;
.source的SourceFile


#实例字段
技术领域一个:Z

点域B:LCOM / Rovio公司/ ka3d /应用程序;


#直接的方法
。方法公共构造< INIT>(LCOM / Rovio公司/ ka3d /应用程序;)V
    .locals 2
    。参数

    。序幕
    常量/ 4 V1,为0x1

    .line区段317
    调用直接{P0,P1},Landroid /视图/视图;  - >< INIT>(Landroid /内容/语境;)V

    .line区段313
    常量/ 4 V0,为0x0

    iput布尔V0,P0,LD;  - >一种:Z

    .line区段314
    常量/ 4 V0,为0x0

    iput对象V0,P0,LD;  - > B:LCOM / Rovio公司/ ka3d /应用程序;

    .line区段318
    iput对象P1,P0,LD;  - > B:LCOM / Rovio公司/ ka3d /应用程序;

    .line区段319
    调用虚拟{P0,V1},LD;  - > setFocusable(Z)V

    .line区段320
    调用虚拟{P0,V1},LD;  - > setFocusableInTouchMode(Z)V

    .line区段321
    返回孔隙
.END方法


#虚拟方法
公众。方法一(Z)V
    .locals 4
    。参数

    。序幕
    常量/ 4 V3,为0x0

    .line区段325
    调用虚拟{P0},LD;  - >的getContext()Landroid /内容/语境;

    布展结果对象V0

    常量字符串V1,input_method

    调用虚拟{V0,V1},Landroid /内容/语境;  - > getSystemService(Ljava /朗/字符串;)Ljava /郎/对象;

    布展结果对象V0

    检查铸V0,Landroid /查看/ inputmethod / InputMethodManager;

    .line区段326
    调用虚拟{P0},LD;  - > getWindowToken()Landroid / OS /的IBinder;

    布展结果对象V1

    调用虚拟{V0,V1,V3},Landroid /查看/ inputmethod / InputMethodManager;  - > hideSoftInputFromWindow(Landroid / OS /的IBinder;我)z

    .line区段327
    如果-eqz P1,:cond_0

    .line区段329
    调用虚拟{P0},LD;  - > getWindowToken()Landroid / OS /的IBinder;

    布展结果对象V1

    常量/ 4 V2,0X2

    调用虚拟{V0,V1,V2,V3},Landroid /查看/ inputmethod / InputMethodManager;  - > toggleSoftInputFromWindow(Landroid / OS /的IBinder; II)V

    .line区段330
    调用虚拟{P0},LD;  - >不是requestFocus()z

    .line区段333
    :cond_0
    iput布尔P1,P0,LD;  - >一种:Z

    .line区段334
    返回孔隙
.END方法

。方法公开onCreateInputConnection(Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;
    .locals 3
    。参数

    。序幕
    .line区段343
    新的实例V0,香格里拉;

    的iget对象V1,P0,LD;  - > B:LCOM / Rovio公司/ ka3d /应用程序;

    常量/ 4 V2,为0x0

    调用直接{V0,V1,P0,V2},香格里拉;  - >< INIT>(LCOM / Rovio公司/ ka3d /应用程序; Landroid /视图/视图; Z)V

    .line区段345
    常量/ 4 V1,为0x0

    iput对象V1,P1,Landroid /查看/ inputmethod / EditorInfo;  - > actionLabel:Ljava /朗/ CharSequence的;

    .line区段350
    常量V1,0x80090

    iput V1,P1,Landroid /查看/ inputmethod / EditorInfo;  - > inputType:我

    .line区段351
    常量/ high16 V1,为0x1000

    iput V1,P1,Landroid /查看/ inputmethod / EditorInfo;  - > imeOptions:我

    .line区段352
    返回对象V0
.END方法
 

解决方案

实际的code调用Log.e()是相当简单的。这将涉及这样的:

 常量字符串V0,MyTag的
常量字符串V1,有些事情要打印
#假设你已经在V2异常...
调用静态{V0,V1,V2},Landroid / UTIL /日志;  - > E(Ljava /朗/字符串; Ljava /朗/字符串; Ljava /朗/可抛出;)我
 

不过,你要小心什么您注册使用。你不想揍具有稍后将使用的值的寄存器。

所以,你有2个选择:

  1. 找到安全未使用的寄存器,并使用这些(可能会非常棘手)
  2. 增加了该方法的寄存器数量,并使用新创建的寄存器

有关2号,唯一的疑难杂症是,新的寄存器不在登记范围的结束 - 他们其实只是在参数寄存器之前

例如,让我们有5个寄存器总的方法( .registers 5 ),其中3个是参数寄存器。所以,你必须V0和V1其是非参数寄存器和P0-P2这是第3个参数的寄存器,并且别名V2-V4。

如果您需要添加额外的2个寄存器,你会碰到它设置为 .registers 7 。参数登记入住登记范围的末端,因此P0-P2现在化名为V4,V6和v2和v3是新的寄存器,可以安全使用。

I reverse engineered some android apks to add some instrumentation for functional testing. I want to know given an smali as following how can I add something like

Log.e(TAG, "some descritpion", e);

to each method in the .smali files.

.class public Ld;
.super Landroid/view/View;
.source "SourceFile"


# instance fields
.field a:Z

.field b:Lcom/rovio/ka3d/App;


# direct methods
.method public constructor <init>(Lcom/rovio/ka3d/App;)V
    .locals 2
    .parameter

    .prologue
    const/4 v1, 0x1

    .line 317
    invoke-direct {p0, p1}, Landroid/view/View;-><init>(Landroid/content/Context;)V

    .line 313
    const/4 v0, 0x0

    iput-boolean v0, p0, Ld;->a:Z

    .line 314
    const/4 v0, 0x0

    iput-object v0, p0, Ld;->b:Lcom/rovio/ka3d/App;

    .line 318
    iput-object p1, p0, Ld;->b:Lcom/rovio/ka3d/App;

    .line 319
    invoke-virtual {p0, v1}, Ld;->setFocusable(Z)V

    .line 320
    invoke-virtual {p0, v1}, Ld;->setFocusableInTouchMode(Z)V

    .line 321
    return-void
.end method


# virtual methods
.method public a(Z)V
    .locals 4
    .parameter

    .prologue
    const/4 v3, 0x0

    .line 325
    invoke-virtual {p0}, Ld;->getContext()Landroid/content/Context;

    move-result-object v0

    const-string v1, "input_method"

    invoke-virtual {v0, v1}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/view/inputmethod/InputMethodManager;

    .line 326
    invoke-virtual {p0}, Ld;->getWindowToken()Landroid/os/IBinder;

    move-result-object v1

    invoke-virtual {v0, v1, v3}, Landroid/view/inputmethod/InputMethodManager;->hideSoftInputFromWindow(Landroid/os/IBinder;I)Z

    .line 327
    if-eqz p1, :cond_0

    .line 329
    invoke-virtual {p0}, Ld;->getWindowToken()Landroid/os/IBinder;

    move-result-object v1

    const/4 v2, 0x2

    invoke-virtual {v0, v1, v2, v3}, Landroid/view/inputmethod/InputMethodManager;->toggleSoftInputFromWindow(Landroid/os/IBinder;II)V

    .line 330
    invoke-virtual {p0}, Ld;->requestFocus()Z

    .line 333
    :cond_0
    iput-boolean p1, p0, Ld;->a:Z

    .line 334
    return-void
.end method

.method public onCreateInputConnection(Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;
    .locals 3
    .parameter

    .prologue
    .line 343
    new-instance v0, La;

    iget-object v1, p0, Ld;->b:Lcom/rovio/ka3d/App;

    const/4 v2, 0x0

    invoke-direct {v0, v1, p0, v2}, La;-><init>(Lcom/rovio/ka3d/App;Landroid/view/View;Z)V

    .line 345
    const/4 v1, 0x0

    iput-object v1, p1, Landroid/view/inputmethod/EditorInfo;->actionLabel:Ljava/lang/CharSequence;

    .line 350
    const v1, 0x80090

    iput v1, p1, Landroid/view/inputmethod/EditorInfo;->inputType:I

    .line 351
    const/high16 v1, 0x1000

    iput v1, p1, Landroid/view/inputmethod/EditorInfo;->imeOptions:I

    .line 352
    return-object v0
.end method

解决方案

The actual code to call Log.e() is fairly simple. It would involve something like:

const-string v0, "MyTag"
const-string v1, "Something to print"
# assuming you have an exception in v2...
invoke-static {v0, v1, v2}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

However, You have to be careful with what registers you use. You don't want to clobber a register that has a value that will be used later.

So you have 2 options:

  1. Find "safe" unused registers, and use those (can be tricky)
  2. Increase the register count of the method, and use the newly created registers

For number 2, the only gotcha is that the new registers aren't at the end of the register range - they're actually just before the parameter registers.

For example, let's take a method that has 5 registers total (.registers 5), 3 of which are parameter registers. So you have v0 and v1 which are non-param registers, and p0-p2 which are the 3 parameter registers, and are aliases for v2-v4.

If you need to add an additional 2 registers, you would bump it up to .registers 7. The parameter registers stay at the end of the register range, so p0-p2 are now aliased to v4-v6, and v2 and v3 are the new registers that are safe to use.

这篇关于修改.smali文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆