« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
|
公告 |
本站技术贴除标明为“原创”的之外,其余均为网上转载,文中我会尽量保留原作者姓名,若有侵权请与我联系,我将第一时间做出修改。谢谢!
——既瑜 |
统计 |
blog名称:★既瑜★ 日志总数:183 评论数量:636 留言数量:-25 访问次数:1405963 建立时间:2005年3月12日 |
OICQ:215768265
njucs2001@hotmail.com
erichoo1982@gmail.com |
|
W3CHINA Blog首页 管理页面 写新日志 退出
[【技术文档】]指针引用非法地址,理解指针含义 |
程序很短,方法和思想值得一看!
程序1:
#include <iostream>using namespace std;void main(){
int b = 2100;//跟踪得到变量b的地址为0x0012ff7c int *a; a = (int *)0x0012ffff;//赋值为b变量地址附近的某个地址(经测试前四位和其相同一般都可以) //,增加地址允许访问的概率性。 cout<<*a;}
可以看出通过此等转换,指针可以访问任何此进程有访问权限的地址。利用此种方法就可以神不只鬼不觉地修改某些变量的值如下程序:
程序2:
#include <iostream>using namespace std;void main(){
int b = 2100;//跟踪得到变量b的地址为0x0012ff7c int *a; a = (int *)0x0012ff7c;
*a = 2200; cout<<b;}
程序结果输出为2200,b值通过a指针给偷偷的修改了!
基本上可以看出,指针就是一个long型变量,只不过其具有特殊功能,可以通过*一起联合使用作为一个表示地址为此指针值的变量。
因此我们可以将程序1改的更隐藏,代码如下:
程序3:
#include <iostream>using namespace std;void main(){
int b = 2100;//跟踪得到变量b的地址为0x0012ff7c cout<<*(int *)0x0012ffff;}
程序2也可改为:
#include <iostream>using namespace std;void main(){
int b = 2100;//跟踪得到变量b的地址为0x0012ff7c *(int *)0x0012ff7c = 2200; cout<<(int *)0x0012ff7c;}
作者:胡一刀 2005.7.13 email:hlq83@126.com本文引用通告地址: http://blog.csdn.net/hlq83/services/trackbacks/423014.aspx
|
阅读全文(3165) | 回复(0) | 编辑 | 精华 |
|