打印一首唐诗的N种实现之六:内存修改
2007-01-02 13:07
369 查看
通过调用VirtualProtectEx来修改,通过修改main()函数的入口地址来达到修改打印内容的目的。
完整的代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main(int argc, char* argv[]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int mine()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout << "白日依山尽, 黄河入海流, 欲穷千里目, 更上一层楼. ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int SetHook()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD flag = PAGE_EXECUTE_READWRITE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD mineAddr = (DWORD)mine;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD mainAddr = (DWORD)main;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mineAddr -= (mainAddr + 5);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
VirtualProtectEx(GetCurrentProcess(), (BYTE*)mainAddr, 200, flag, &flag);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[0] = 0xe9;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[1] = (BYTE)(mineAddr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[2] = (BYTE)(mineAddr>>8);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[3] = (BYTE)(mineAddr>>16);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[4] = (BYTE)(mineAddr>>24);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
VirtualProtectEx(GetCurrentProcess(), (BYTE*)mainAddr, 200, flag, &flag);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int s = SetHook();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main(int argc, char* argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout << "白日依山尽, ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
完整的代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main(int argc, char* argv[]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int mine()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout << "白日依山尽, 黄河入海流, 欲穷千里目, 更上一层楼. ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int SetHook()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD flag = PAGE_EXECUTE_READWRITE;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD mineAddr = (DWORD)mine;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DWORD mainAddr = (DWORD)main;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mineAddr -= (mainAddr + 5);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
VirtualProtectEx(GetCurrentProcess(), (BYTE*)mainAddr, 200, flag, &flag);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[0] = 0xe9;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[1] = (BYTE)(mineAddr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[2] = (BYTE)(mineAddr>>8);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[3] = (BYTE)(mineAddr>>16);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
((BYTE*)mainAddr)[4] = (BYTE)(mineAddr>>24);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
VirtualProtectEx(GetCurrentProcess(), (BYTE*)mainAddr, 200, flag, &flag);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int s = SetHook();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main(int argc, char* argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout << "白日依山尽, ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- 打印一首唐诗的N种实现之二:程序退出点修改
- 打印一首唐诗的N种实现之一:问题的提出
- 打印一首唐诗的N种实现之三:宏替换
- 打印一首唐诗的N种实现之四:原代码失效
- 打印一首唐诗的N种实现之五:操作符重载
- 写了一个将VxWorks的shell打印输出到指定内存中的接口,可广泛用于CLI下的调试函数显示以及故障自动捕获等功能,稍作修改可以适合其它嵌入式OS
- 修改fastreport实现页尾补空白行或打印固定行数
- 实现一个"可变二维数组",这个二维数组的行数要求用户从键盘输入,每行的元素个数仍由用户从键盘输入. //数组元素值用户可以自定义.最后把二维数组打印出来.不要忘记释放数组内存. /*void main
- 不修改源代码实现Libjpeg内存编解码jpeg
- C#编码中,打印预览DataGridView的一段代码,稍作了修改,可以实现。
- logback动态修改配置文件实现打印不同级别日志
- C++黑客编程揭秘与防范之利用修改内存的方式实现进程注入
- 字符数组封装实现添加,删除,插入,修改,搜索,打印
- DELPHI 实现内存修改的方法
- golang基础-数组、切片创建_内存_底层实现_修改值_拷贝_循环、string与切片
- jmeter3.x源码修改实现jtl文件只打印失败请求
- 不修改libjpeg库同样实现内存内位图的压缩及解压缩
- 简易printf打印实现,占用内存非常小------<嵌入式开发自学笔记>
- 不修改libjpeg库同样实现内存内位图的压缩及解压缩
- DELPHI实现游戏内存的修改