c++指针练习
2024-09-07 14:47:22
- Pointers
- 在getchar处断点,断点后,调试->窗口->反汇编 查看数据
main
#include <iostream>
#include <Windows.h>
/*
Player : object
Name : string
Health : integer
Coins : integer
Coordinates : object
X : float
Z : float
Y : float
Inventory : array - Array of item objects, having the item and item count.
*/
uintptr_t _Inventory[3] = { 1,2,3 };
struct _Coordinates
{
float x = 4.0;
float y = 2.0;
float z = 3.0;
} coordinates;
struct Player
{
const char* Name = "ab";
uintptr_t Health = 6;
uintptr_t Coins = 3;
/*
// 这种方法类似把coordinates直接复制到这里来
// Padding1的偏移量将是 playerBaseAddress+4*6
_Coordinates Coordinates = coordinates;
float x = 4.0;
float y = 2.0;
float z = 3.0;
*/
_Coordinates* Coordinates = &coordinates;
// uintptr_t Padding1 = 1;
/*
//类似直接复制到这
//std::cout << "arrar[0]: " << *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 4) << std::endl;
//std::cout << "arrar[1]: " << *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 5) << std::endl;
//std::cout << "arrar[2]: " << *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 6) << std::endl;
const int Inventory[3] = { 1,2,3 };
*/
// 数组直接返回的就是指针,所以不用&
uintptr_t* Inventory = _Inventory;
} player;
int main()
{
std::cout << "playerBaseAddress: " << &player << std::endl;
uintptr_t playerBaseAddress = (uintptr_t)&player;
// name
// lea stringNameAddress, [playerBaseAddress]
uintptr_t* stringNameAddress = (uintptr_t*)(playerBaseAddress);
// 从指针中获取值
// mov eax, dowrd ptr [stringNameAddress]
std::cout << "Name: " << std::hex << *(uintptr_t*)(*stringNameAddress) << std::endl;
// get Health
std::cout << "Health: " << *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t)) << std::endl;
// get Coins
std::cout << "Coins: " << *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 2) << std::endl;
// 获取Coordinates指针
uintptr_t coordinatesAddress = *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 3);
std::cout << "CoordinatesAddress: " << coordinatesAddress << std::endl;
std::cout << "Coordinates->x: " << *(float*)(coordinatesAddress) << std::endl;
std::cout << "Coordinates->y: " << *(float*)(coordinatesAddress + sizeof(float)) << std::endl;
std::cout << "Coordinates->z: " << *(float*)(coordinatesAddress + sizeof(float) * 2) << std::endl;
// 获取Inventory指针
uintptr_t InventoryAddress = *(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t) * 4);
std::cout << "InventoryAddress: " << InventoryAddress << std::endl;
std::cout << "Inventory[0]: " << *(uintptr_t*)(InventoryAddress) << std::endl;
std::cout << "Inventory[1]: " << *(uintptr_t*)(InventoryAddress + sizeof(uintptr_t)) << std::endl;
std::cout << "Inventory[2]: " << *(uintptr_t*)(InventoryAddress + sizeof(uintptr_t) * 2) << std::endl;
// set
*(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t)) = 4;
*(uintptr_t*)(playerBaseAddress + sizeof(uintptr_t)*2) = 5;
getchar();
return 0;
}
x86打印结果:
playerBaseAddress: 0026D05C
Name: 6261
Health: 6
Coins: 3
CoordinatesAddress: 26d050
Coordinates->x: 4
Coordinates->y: 2
Coordinates->z: 3
InventoryAddress: 26d044
Inventory[0]: 1
Inventory[1]: 2
Inventory[2]: 3
x64打印结果:
playerBaseAddress: 00007FF7CC8AD028
Name: 6261
Health: 6
Coins: 3
CoordinatesAddress: 7ff7cc8ad018
Coordinates->x: 4
Coordinates->y: 2
Coordinates->z: 3
InventoryAddress: 7ff7cc8ad000
Inventory[0]: 1
Inventory[1]: 2
Inventory[2]: 3
最新文章
- git bash操作
- js中关于value的一个小知识点(value既是属性也是变量)
- Linux 命令ln
- redis的安装-windows和linux
- 为什么都反对XML而支持使用json呢?
- 监听SWT文本框只能输入数字
- Android中启动页ViewPager和ViewFlipper带指示器
- Jerry 2017年的五一小长假:8种经典排序算法的ABAP实现
- memcached安装与使用详解
- 全面盘点当前Android后台保活方案的真实运行效果(截止2019年前)
- 进程,线程,协程,异步IO知识点
- 为什么Java的main方法必须是public static void?
- Linux 中如何避免 rm -rf /*
- Ionic3的http请求如何实现token验证,并且超时返回登录页
- glyphicons-halflings-regular.woff2:1 Failed to load resource: the server responded with a status of 404 (Not Found)解决Web部署 svg/woff/woff2字体 404错误
- Vlock用于有多个用户访问控制台的共享 Linux 系统
- Java GC 日志解析
- SpringBoot项目结构介绍
- poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)
- JavaScript 与JQuery 常用方法比较
热门文章
- Centos7部署FytSoa项目至Docker——第三步:部署程序
- Web漏洞扫描-AppScan
- linux上 用户间发送消息 通信
- python2.7.5 +eric4.4.2+PyQt4-4.10.3
- 学会lambda表达式,能让你少敲1000行代码!
- dedecms织梦后台栏目显示文档数不为0,但点进去之后什么都没有
- 【洛谷 p3390】模板-矩阵快速幂(数论)
- Codeforces Round #171 (Div. 2) B. Books (模拟队列)
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships
- EF Core数据访问入门