小编min*_*tle的帖子

从给定的x86程序集编写C函数

我正试图逆向设计这个神秘功能.此函数返回一个整数,并将struct节点作为参数

#include "mystery.h"
int mystery(struct e4_struct *s){}
Run Code Online (Sandbox Code Playgroud)

头文件是一个简单的结构声明

struct my_struct {
    int a;
    int b; 
};
Run Code Online (Sandbox Code Playgroud)

我试图逆向工程的组件是

400596:    8b 07                    mov    (%rdi),%eax
400598:    8d 04 40                 lea    (%rax,%rax,2),%eax
40059b:    89 07                    mov    %eax,(%rdi)
40059d:    83 47 04 07              addl   $0x7,0x4(%rdi)
4005a1:    c3                       retq  
Run Code Online (Sandbox Code Playgroud)

到目前为止,我认为功能如下:

int mystery(struct m_struct *s){
    int i = s->a;
    i = 3*i;
    int j = s->b;
    j += 7;
    return i;
}
Run Code Online (Sandbox Code Playgroud)

但这不正确.我不明白究竟mov %eax,(%rdi)是什么以及函数最终返回的是什么因为它应该返回和整数.

c assembly gcc reverse-engineering x86-64

4
推荐指数
1
解决办法
123
查看次数

标签 统计

assembly ×1

c ×1

gcc ×1

reverse-engineering ×1

x86-64 ×1