随机键函数

逆向工程 部件 x86
2021-06-26 10:08:33

我目前正在分析 x86 中的反汇编库文件 (.so)。有一个函数被调用get_random_key,我无法理解它。这不仅很奇怪,而且我个人认为由于内存限制,这甚至是不允许的。这是它的代码(用 IDA 反汇编):

sub_685     proc near       ; CODE XREF: get_random_keyp
    mov ecx, [esp+0]
    retn
sub_685     endp

public get_random_key
get_random_key  proc near       ; CODE XREF: get_generated_key+15p
    call    sub_685
    add ecx, 1AFFh
    lea eax, [ecx+3Ch]
    retn
get_random_key  endp

从我在这里看到它加载堆栈顶部的内容,向其添加 0x1AFF(6911!!) 然后将其解释为指针并向其添加 0x3C 并返回。这是一个相当小的库,很可能它最初是用 C 编写的。我想不出任何会产生这样的东西的代码。在我看来,这会导致 9/10 次出现分段错误。这是一个通过 Java 加载到 android 应用程序中的库,大小约为 6kb。

我很高兴对这个功能的每一个提示:)

2个回答

这看起来像是编译器试图生成位置无关代码 (PIC)。sub_685在调用 into 之后,调用to获取指令的地址ecx1AFF可能是从该指令到数据段中的偏移量,并且3C是在所述数据段中的变量的地址。或者,1AFF是结构3C的偏移量,以及结构的成员的偏移量。

0x401000    call    sub_685      call will return 0x401005 the return address 
0x401005    add ecx, 1AFFh       ecx will be  0x401005+0x1aff = 0x402b04
0x401xxx    lea eax, [ecx+3Ch]   lea doesnt deref it will just add 3c 
                                 to ecx so eax will be 402B04 assuming the
                                 call sub_685 was at address 0x401000**