基本操作
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int add(int a,int b)
{
return a+b;
}
void main()
{
int num=100;
int *p=#//p 是一个指针变量,存储的是num地址
int (*pp)(int a,int b);//定义函数指针
// *p=19;//通过地址修改变量 *p 是一个int 类型数据。*p 根据地址取出内容赋值
*(&num)=19;
printf("%d",num);
//printf("\n%d",add(1,1));
//函数名就是一个地址
pp=add;
printf("\n%d",pp(1,2));//通过指针调用函数;
system("pause");
}
dll 注入
_declspec(dllexport) void go()
{
/* int *p=(int *)0x1cf794;
*p=-108;*/
void(*p1)()=(void(*)())0xbb113b;
p1();
}
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void msg()
{
while(1)
{
MessageBoxA(0,"你好","108...",0);
Sleep(2000);
}
}
void main()
{
int num=100;
printf("%x,%x",&num,msg);
while(1)
{
Sleep(2000);
printf("你好%d",num);
}
//msg();
}
#include <stdio.h>
#include <stdlib.h>
void chage(int a)
{
a=8;
}
void chageA(int *p)//创建一个指针接收&a,地址
{
*p=8;
}
void main()
{
int a=10;
chageA(&a);
printf("%d",a);
system("pause");
}
void main4()
{
int num=100;
int *p=#//(int *) 指针,包含一个地址
//*p 就是int 数据
//p 的值是一个地址,存放的num 的值,
printf("%x,%x",&num,&p);
// 根据*p=10,根据一个地址获取内容
*p=10;
printf("%d",num);
system("pause");
}
void main3()
{
int num=100;
printf("%x,%d",&num,num);
printf("\n%d",*(&num));
system("pause");
//* 根据地址取出内容
//& 取出地址
}
void main2()
{
int a[1000]={0};
printf("%x",a);
}
二级指针
#include <stdio.h>
#include <stdlib.h>
void main23()
{
int a=5;
int b=8;
int *p=&a;//&a 是一个地址,p存放地址是一个指针变量
int **pp=&p;//**pp 对称int,可以当作int处理
*pp=&b;//int * 是指针
**pp=1;
printf("%d,%d\n",a,b);
printf("%d",**pp);
system("pause");
}
//void main12()
//{
// int a=1;
// int b=2;
// int* p=&a;
// printf("*p=%d,a=%d",*p,a);
// printf("p=%x,&a=%x",p,&a);
// system("pause");
//}
函数改变外部指针
#include <stdio.h>
#include <stdlib.h>
char a='A';
char b='B';
char c='C';
void changep(char *p)
{
p=&c;
}
//改变一个变量,需要这个变量的地址
//如果变量是数据,就需要指针 保存变量的地址
//如果是指针,就需要二级指针保存指针变量的地址
void changepp(char **p)
{
*p=&c;
}
void main()
{
char *p=&a;
p=&b;
printf("我的级别%c",*p);
changepp(&p);
printf("\n我的级别%c\n",*p);
system("pause");
}
二级指针外挂
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
char a='A';
char b='B';
char c='C';
char d='D';
void main()
{
char *p=&a;
printf("&a=%x\n",p);
printf("&p=%x,&a=%x,&b=%x,&c=%x,&d=%x",&p,&a,&b,&c,&d);
while(1)
{
printf("我的游戏级别是%c\n",*p);
_sleep(2000);//跨平台的。
}
}
//动态库 脱离平台运行的
_declspec(dllexport) void go()
{
//改变一个数据用指针,改变一个指针用二级指针
int **p=(int**)0x1ffb1c;
*p=(int *)0x348002;
}
单向双向 指针
#include <stdio.h>
#include <stdlib.h>
void changetest(int test)//单向传递,赋值,只能接收,不能改变
{
test=100;
}
void changetestA(int * p)//新建一个变量,复制了地址的值,根据地址改变原来的值 双向赋值
{
*p=1000;
}
void main()
{
int test=10;
changetestA(&test);
printf("%d",test);
getchar();
}