先上代码:
****************************************************************************
#define SIZE 100
const int g_nCount = 1000;
enum eData { enum_TYPE_1 = 1,
enum_TYPE_2 = 2,
enum_TYPE_3 = 3
};
struct sData { int n;
float fNum;
char chA; };
int main() {
bool bRet = true; // 布尔常量
const int nCount = SIZE; // 宏常量
const char* szHello = "aaaaHHH"; // 字符串常量
const eData data = enum_TYPE_1; // 枚举常量
const float fNum = 1.5; // 浮点常量
const sData stc = { 1,2.0,'1' }; // 结构体常量
return 0;
}
****************************************************************************
上面这段代码在vc中实现,静态编译成exe后拖进IDA中查看指令
下面是在IDA中找到main函数之后,开辟栈帧以及一系列相关的字符串操作:
图片对上面代码有了清晰的解释,字有点乱,再理一下:
xmm?(寄存器):浮点数,并没有嵌入到opcode中
edit-operand type-number-floating point 设置为浮点数
浮点数位于rdata段里面,在一个内存区域里
c++中的常量:const 宏 enum struct
编译完成后,所有常量都会变成数字
常量:嵌入opcode
浮点数怎么变成小数查看呢:
在系统函数security cookie里面查看:
cookie是一个随机值,每次程序运行都不一样,因此每次都要异或一下eax与ebp,ebp的值是不确定的,然后将eax压入栈中,如果程序发生了溢出,就会将这个压入的地方覆盖掉,此时取出来的值就发生了错误,取出来的值与原来的值不想等了就发生了溢出,就报错
下面这个是为了对比,另外写的代码:
#define SIZE 200
const int g = 100;
enum data {
enum1 = 1,
enum2 = 2,
enum3 = 3
};
struct s {
int n;
float f;
char c;
};
int main() {
bool bRet = false;
const int nCount = SIZE;
const char* sz = "hello";
const data da = enum3;
const s stc = { 1,2.0,'1' };
return 0;
}
****************************************************************
浪费了不少时间之后发现,并没有什么不同,只是数据上的差异而已,因为代码里只改了数据,emmm纯属浪费时间
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有