asm source code note 1.7_switch case分支的实现
发布日期:2021-06-30 22:06:02 浏览次数:2 分类:技术文章

本文共 4149 字,大约阅读时间需要 13 分钟。

源代码

// test1020.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
#include
#include
enum eNumberRange{ eNumberRange_0_100 = 1, eNumberRange_100_200, eNumberRange_200_300, eNumberRange_Unknown};/// 判断一个输入数的范围eNumberRange NumJudge(int iNumber);int _tmain(int argc, _TCHAR* argv[]){ int iDigIn = 0; srand( (unsigned)time( NULL ) ); iDigIn = rand(); _tprintf(L"NumJudge(%d) = %d\r\n", iDigIn, NumJudge(iDigIn)); getwchar(); return 0;}/// 如果iNumber在源代码中给定值, Release版编译后, 会优化掉eNumberRange NumJudge(int iNumber){ eNumberRange eType = eNumberRange_Unknown; int iRange = (iNumber - iNumber % 100) / 100 + eNumberRange_0_100; switch (iRange) { case eNumberRange_0_100: eType = eNumberRange_0_100; break; case eNumberRange_100_200: eType = eNumberRange_100_200; break; case eNumberRange_200_300: eType = eNumberRange_200_300; break; default: eType = eNumberRange_Unknown; break; } return eType;}

OD反汇编代码

002E1000 >/$  56            push    esi002E1001  |.  6A 00         push    0002E1003  |.  FF15 B0202E00 call    dword ptr [<&MSVCR90._time64>]   ;  MSVCR90._time64002E1009  |.  50            push    eax                              ; /seed002E100A  |.  FF15 AC202E00 call    dword ptr [<&MSVCR90.srand>]     ; \srand002E1010  |.  83C4 08       add     esp, 8002E1013  |.  FF15 A8202E00 call    dword ptr [<&MSVCR90.rand>]      ; [rand002E1019  |.  8BF0          mov     esi, eax                         ;  通过修改eax, 判断常量除法的除数 eax = 0x1234(4660)002E101B  |.  B8 1F85EB51   mov     eax, 51EB851F                    ;  >> 除法1002E1020  |.  F7EE          imul    esi002E1022  |.  C1FA 05       sar     edx, 5002E1025  |.  8BC2          mov     eax, edx002E1027  |.  C1E8 1F       shr     eax, 1F002E102A  |.  03C2          add     eax, edx002E102C  |.  8BC8          mov     ecx, eax                         ;  eax = 0x2e(46), 貌似被除数的百位数, (4660 - 60) % 100002E102E  |.  6BC9 64       imul    ecx, ecx, 64                     ;  执行后: ecx = 0x11f8(4600), 貌似 (4660 - (4660 % 100))002E1031  |.  B8 1F85EB51   mov     eax, 51EB851F                    ;  >> 除法2002E1036  |.  F7E9          imul    ecx002E1038  |.  C1FA 05       sar     edx, 5002E103B  |.  8BCA          mov     ecx, edx002E103D  |.  C1E9 1F       shr     ecx, 1F002E1040  |.  8D440A 01     lea     eax, dword ptr [edx+ecx+1]       ;  ///< eax = 0x2f(47), 貌似入参的百位数 + 1002E1044  |.  83E8 01       sub     eax, 1                           ;  ///< 看来0~400是有效输入; Switch (cases 1..3)002E1047  |.  74 1F         je      short 002E1068                   ;  ///< 百位数减到第几次为0了, 就match了002E1049  |.  83E8 01       sub     eax, 1002E104C  |.  74 13         je      short 002E1061002E104E  |.  83E8 01       sub     eax, 1002E1051  |.  74 07         je      short 002E105A002E1053  |.  B8 04000000   mov     eax, 4                           ;  Default case of switch 002E1044002E1058  |.  EB 13         jmp     short 002E106D002E105A  |>  B8 03000000   mov     eax, 3                           ;  Case 3 of switch 002E1044002E105F  |.  EB 0C         jmp     short 002E106D002E1061  |>  B8 02000000   mov     eax, 2                           ;  Case 2 of switch 002E1044002E1066  |.  EB 05         jmp     short 002E106D002E1068  |>  B8 01000000   mov     eax, 1                           ;  Case 1 of switch 002E1044002E106D  |>  50            push    eax                              ; |<%d>002E106E  |.  56            push    esi                              ; |
002E106F |. 68 04212E00 push 002E2104 ; |format = "NumJudge(%d) = %d.."002E1074 |. FF15 A4202E00 call dword ptr [<&MSVCR90.wprintf>] ; \wprintf002E107A |. 83C4 0C add esp, 0C002E107D |. FF15 A0202E00 call dword ptr [<&MSVCR90.getwchar>] ; [getwchar002E1083 |. 33C0 xor eax, eax002E1085 |. 5E pop esi002E1086 \. C3 retn
常量除数的除法, 比较难判断被除数是多少。 暂时只能猜~, 如果靠常用除数常量表判断, 也不通用。

通过修改常量除数除法的入参, 从除法结果来判断除法到底除的是常量几, 还算好使。

转载地址:https://lostspeed.blog.csdn.net/article/details/4632151 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:asm source code note 1.8_没有原文的asm to c
下一篇:asm source code note 1.6_if else分支的实现

发表评论

最新留言

很好
[***.229.124.182]2024年04月17日 06时27分50秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

Image Pyramid(图像金字塔) 2019-04-30
Oracle 作业记录 2019-04-30
putty连接AWS配置(multimedia project) 2019-04-30
Hourglass Network 沙漏网络 (pose estimation姿态估计) 2019-04-30
OpenCV实战(二)——答题卡识别判卷 2019-04-30
目标检测神经网络的发展历程(52 个目标检测模型) 2019-04-30
Boundary loss 损失函数 2019-04-30
神经网络调参实战(一)—— 训练更多次数 & tensorboard & finetune 2019-04-30
tensorflow使用tensorboard进行可视化 2019-04-30
神经网络调参实战(二)—— activation & initializer & optimizer 2019-04-30
凸优化 convex optimization 2019-04-30
数据库索引 & 为什么要对数据库建立索引 / 数据库建立索引为什么会加快查询速度 2019-04-30
IEEE与APA引用格式 2019-04-30
research gap 2019-04-30
pytorch训练cifar10数据集查看各个种类图片的准确率 2019-04-30
Python鼠标点击图片,获取点击点的像素坐标 2019-04-30
路径规划(一) —— 环境描述(Grid Map & Feature Map) & 全局路径规划(最优路径规划(Dijkstra&A*star) & 概率路径规划(PRM&RRT)) 2019-04-30
神经网络调参实战(四)—— 加深网络层次 & 批归一化 batch normalization 2019-04-30
数据挖掘与数据分析(三)—— 探索性数据分析EDA(多因子与复合分析) & 可视化(1)—— 假设检验(μ&卡方检验&方差检验(F检验))&相关系数(皮尔逊&斯皮尔曼) 2019-04-30
RRT算法(快速拓展随机树)的Python实现 2019-04-30