linux - python的汇编函数

标签 linux recursion

我在 ASM 中有以下功能:

//edx=0xe,esi=0,edi=user input
push   %rbx
mov    %edx,%eax
sub    %esi,%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %ebx,%eax
sar    %eax
lea    (%rax,%rsi,1),%ebx
cmp    %edi,%ebx
jle    401013 <func4+0x21>
lea    -0x1(%rbx),%edx
callq  400ff2 <func4>
add    %ebx,%eax
jmp    401023 <func4+0x31>
mov    %ebx,%eax
cmp    %edi,%ebx
jge    401023 <func4+0x31>
lea    0x1(%rbx),%esi
callq  400ff2 <func4>
add    %ebx,%eax
pop    %rbx
retq

我试着把它转换成 Python:

def L1(eax,ebx):
    eax = eax+ebx
    return (eax+ebx)

def L2(eax,ebx,edi,esi,edx):
    eax = ebx
    if (ebx >= edi):
        L1(eax,ebx)
    else:
        esi = esi+1
        eax = func(edi,esi,edx,eax,ebx)
        L1(eax,ebx)

def func(edi,esi,edx,eax,ebx):
    eax = edx
    eax = eax - esi
    ebx = eax
    ebx = ebx >> 31
    eax = eax + ebx
    eax = eax >> 1
    ebx = eax + esi*1
    if (ebx <= edi):
        eax = ebx
        L1(eax,ebx)
    else:
        edx = ebx-1
        eax = func(edi,esi,edx,eax,ebx)
        L1(eax,ebx)

if __name__ == "__main__":
    for n in range (2,99):
        result=func(n, 0 , 14,0,0)
        if (result==11):
            print (result)

我真的很想知道我哪里错了(我假设有很多错误,因为它有递归和很多跳转)。非常感谢!

最佳答案

我同意这里的共识。您必须记住逆向工程,特别是在汇编级别,Python 是一种解释型语言,因此如果您要在 Linux 中使用 GDB 之类的东西,则必须加载整个解释器。

你可以在Windows中创建一个py2exe,然后使用IDA反汇编它。我认为这可能是您最好的选择!

关于linux - python的汇编函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38423589/

相关文章:

c - SO_KEEPALIVE 和轮询

Linux mint17 : error with apt-get

linux - 循环遍历多个文件夹以执行命令,然后写入另一个目录中的文件

java - 打印二叉树中所有大于或等于传入方法的值的方法

function - Fortran函数返回意外的类型和值

linux - 如何使用imp命令覆盖现有数据

Linux内核模块编译失败

c - 操作给定路径的递归函数

c++ - 求数次幂的递归函数

java - 我的 Java 递归函数出了什么问题?