我在Visual Studio 2008上测试了一些代码并注意到了security_cookie.我能理解它的重点,但我不明白这条指令的目的是什么.
rep ret /* REP to avoid AMD branch prediction penalty */
Run Code Online (Sandbox Code Playgroud)
当然我可以理解评论:)但是这个前缀exaclty在上下文中做了ret什么,如果ecx是!= 0 会发生什么?显然,ecx当我调试它时,忽略循环计数,这是预期的.
我发现这里的代码在这里(由编译器注入安全性):
void __declspec(naked) __fastcall __security_check_cookie(UINT_PTR cookie)
{
/* x86 version written in asm to preserve all regs */
__asm {
cmp ecx, __security_cookie
jne failure
rep ret /* REP to avoid AMD branch prediction penalty */
failure:
jmp __report_gsfailure
}
}
Run Code Online (Sandbox Code Playgroud) 我试图了解地址计算指令的工作原理,尤其是leaq命令.然后当我看到leaq用于进行算术运算的例子时,我感到困惑.例如,以下C代码,
long m12(long x) {
return x*12;
}
Run Code Online (Sandbox Code Playgroud)
在组装中
leaq (%rdi, %rdi, 2), %rax
salq $2, $rax
Run Code Online (Sandbox Code Playgroud)
如果我的理解是正确的,那么leaq应该移动任何(%rdi, %rdi, 2)应该2*%rdi+%rdi评估的地址%rax.我感到困惑的是,因为值x存储%rdi在内,这只是内存地址,为什么%rdi乘以3然后左移这个内存地址 2等于x乘以12?是不是当我们%rdi用3时,我们跳到另一个没有值x的内存地址?
我正试图逆向设计这个神秘功能.此函数返回一个整数,并将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)是什么以及函数最终返回的是什么因为它应该返回和整数.