gpt4 book ai didi

linux - python的汇编函数

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:06 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com