C++逆向之switch-case

来源:互联网 发布:怎么用vs编译c语言 编辑:程序博客网 时间:2024/04/28 13:33

很长时间没有写日志了,前阵子看了下python,发现了python的无边无际,感觉继续学下去就没办法学习逆向相关的内容了。

Switch-Case在编译器编译后主要有三种形式:

1.有序,分支数小于3个

2.有序,但是MaxValue-MinValue小于255的有序

3.无序


1.有序,分支数少于3个

这种方式比较简单,编译器直接使用cmp reg32, mem这种类似于if-else的语句来实现

2.有序,分支数很多,MaxValue-MinValue小于255

        使用索引表,每项占一个字节,一共256项,指向地址表中的项,地址表每项4个字节。地址表项数等于分支数。

3.无序

         下面看一个例子:

// test3.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdio.h>int __cdecl main(int argc, const char **argv, const char **envp){  switch(argc){case 1:return 1;break;case 100:return 100;break;case 222:return 222;break;case 300:return 300;break;case 500:return 500;break;case 700:return 700;break;case 800:return 800;break;}return 0;  }  

        打开IDA,

     

可以发现,这是一个二叉树的结构,首先和300比较,然后。。。

0 0
原创粉丝点击