Android的smali问题问题、Android、smali

2023-09-06 00:38:18 作者:瘋瘋癫癫!

我目前做的smali /code混淆了一些研究,我试图让familar与反编译源$ C ​​$ CS的时刻。为此,我创建了一个简单的应用程序,并通过smali反编译它。

我想现在了解反编译源$ C ​​$ C,以改善和以后使用code混淆器后,比较安全(反编译)。虽然大多数的smali源$ C ​​$ c不是那么困难,我仍然有问题,有时用格式的数字转换。

愿你向我解释,例如下面一行。我想它应该有五个价值,但我不知道,哪一种二进制格式,这是。如何计算它0x4014 = 5 ???

 常量宽/ high16 V0,0x4014 // 100000000010100(5 = 101)
 

附上完整的Java和本次测试功能smali code来源:

Java源代码:

 布尔测试(智力一,双D){
        如果(一个小于5&安培;和D小于5)
            返回true;
        其他
            返回false;
    }
 

Smali来源:

 。方法测试(ID)z
    .locals 2
    。参数a的
    。参数D

    。序幕
    .line区段28
    常量/ 4 V0,0x5的

    如果阁P1,V0,:cond_0

    常量宽/ high16 V0,0x4014

    cmpg双V0,P2,V0

    如果-GEZ V0,:cond_0

    .line区段29
    常量/ 4 V0,为0x1

    .line区段31
    :goto_0
    回报V0

    :cond_0
    常量/ 4 V0,为0x0

    转到:goto_0
.END方法
 
解决新版Android Studio 4.0 无法断点调试smali问题

解决方案

不幸的是,Dalvik的字节code使得积分类型(短/整数/长/等),以及浮点类型(浮点/双之间没有区别)。所以baksmali无法知道是否显示像,作为一个浮点或整型常量,所以它只是默认为整数。

这是进一步复杂化的这样一个你所提到的指令是否存在等。从的Dalvik字节code从Dalvik的文档页面< /一>:

将赋予文字值(右零扩展到64位)到指定的寄存器对。

这样的指令将实际加载值0x4014000000000000到V0和V1寄存器。这是一个标准的64位的IEEE-754浮点数重新presentation。第一(最显著)位是符号位,接下来的11位是指数(基数为2),最后52位是尾数。在这种情况下,我们有一个二进制重新presentation

  0100000000010100000000000000000000000000000000000000000000000000
SEEEEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 

有关的符号位,0是正的,1是负

有关的指数,则采取的11位整数值(在此情况下,1025),并减去1023,用于对2的幂

和尾数,有一个隐含的1,在前面,在2 ^ 0的地方,用下面的数字是通常的2 ^ -1,2 ^ -2,等,所以在这种情况下,我们有二进制数1.01,或1 * 2 ^ 0 + 1 * 2 ^ -2,或1.25

用于数值计算的一般形式是

-1 ^(2 + S)* M * 2 ^ E

其中S,M和E标志,尾数和指数。

在这种情况下,我们有 -1 ^(2 + 0)* 1.25 * 2 ^ 2 = 1 * 1.25 * 4 = 5

如果您不希望每次都手动进行这样的计算,有各种各样的在线计算器,可以为你做它。 http://babbage.cs.qc.edu/IEEE-754/64bit.html 似乎是一个更好的。

I'm currently doing some research on smali/"code obfuscator" and I'm trying to get familar with the decompiled source codes at the moment. For this I created a simple app and decompiled it by smali.

I'm trying to understand the decompiled source code now to improve and compare the security (against decompiling) after using a code obfuscator later. While most of the smali source code is not that difficult, I'm still having sometimes problems with the format conversion of figures.

May you explain to me e.g. the following line. I guess it should have a value of five, but I'm not sure, which kind of binary format this is. How to calculate it 0x4014 = 5 ???

const-wide/high16 v0, 0x4014       // 100000000010100        (5 = 101)

Attached are the full java and smali code sources of this test function :

Java source:

 boolean test(int a, double d) {
        if (a < 5 && d < 5)
            return true;
        else 
            return false;
    }

Smali source:

.method test(ID)Z
    .locals 2
    .parameter "a"
    .parameter "d"

    .prologue
    .line 28
    const/4 v0, 0x5

    if-ge p1, v0, :cond_0

    const-wide/high16 v0, 0x4014

    cmpg-double v0, p2, v0

    if-gez v0, :cond_0

    .line 29
    const/4 v0, 0x1

    .line 31
    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

解决方案

Unfortunately, dalvik bytecode makes no distinction between integral types (short/integer/long/etc.), and floating point types (float/double). So baksmali can't know whether to show a constant like that as a floating point or integer, so it just defaults to integer.

This is further complicated by the existance of instructions like that one that you mentioned. From the dalvik-bytecode page from the dalvik documentation:

"Move the given literal value (right-zero-extended to 64 bits) into the specified register-pair.".

So that instruction will actually load the value 0x4014000000000000 into the v0 and v1 registers. This is a standard 64bit IEEE-754 floating point representation. The first (most significant) bit is the sign bit, the next 11 bits are the exponent (base 2), and the last 52 bits are the mantissa. In this case, we have a binary representation of

0100000000010100000000000000000000000000000000000000000000000000
SEEEEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

For the sign bit, 0 is positive and 1 is negative.

For the exponent, you take the integer value of the 11 bits (in this case, 1025), and subtract 1023, for an exponent of 2.

And for the mantissa, there is an implied "1" at the front, in the 2^0 place, with the following digits being the usual 2^-1, 2^-2, etc. So in this case, we have the binary number 1.01, or 1*2^0 + 1*2^-2, or 1.25.

The general form of the calculation used for the value is

-1^(2+S) * M * 2^E

Where S, M and E are the sign, mantissa and exponent.

In this case, we have -1^(2+0) * 1.25 * 2^2 = 1 * 1.25 * 4 = 5

If you don't want to do this calculation manually every time, there are various online calculators that can do it for you. http://babbage.cs.qc.edu/IEEE-754/64bit.html seems to be one of the better ones.