1.需要获取运行程序要修改的地址,写个成为动态链接库的函数,打包成dll文件,dll注入工具注入到运行的程序中。
__declspec(dllexport) void go(){
//方法内容
}
2.指针的属性
1.指针有类型地址没类型的原因:获取数据值时获取存储数据的地址范围,指针只是数据的开始地址数据类型告诉这个数据占了多大的范围。
2.多级指针(二级指针以上):指针保存的是变量的地址,这个地址保存的是其他数据的地址
3.指针占内存的大小:
4.指针的运输,一般在数组遍历时才有意义。*p++ *p--。移动的大小为sizeof(datatype)
5.JNIEnv是一个二级指针
6函数指针 包括:函数返回值 函数指针名称 函数的参数
void msg(char* msg, char* title) {
showMsg(title, msg);
}
void main() {
void (*fun_p)(char* msg, char* title) = msg;
fun_p("消息","标题");
}
7.函数指针的使用:复用性多态。
int add(int a, int b) {
return a + b;
}
int minus(int a, int b) {
return a - b;
}
void msg(int(*func_p)(int a, int b), int n, int m) {
int t = func_p(m, n);
}
三.内存
1.动态的内存分配
内存区域:堆区,栈区(自动分配回收,执行代码),方法区,常量区,字符串区,全局区静态区
动态内存使用的demo:
// 动态分配内存
int* p = malloc(len*sizeof(int));
// 赋值
int i = 0;
// 随机数设置种子
srand(1000);
for (; i < len; i++) {
p[i] = rand() % 100;
printf("%d, %#x\n", p[i], &p[i]);
}
//回收
free(p)
申请内存扩充,当当前的地址连续上不能满足扩充时,去内存中中可以满足的内存块并且释放当前使用的内存块.
int p2 = realloc(p, sizeof(int) * (len + addLen));
calloc的使用
int* p = calloc(len, sizeof(int));
四.字符串
1.定义char[] 数组
char str[] = {'c', 'h', 'i', 'n', 'a', '\0'};
char str[6] = {'c', 'h', 'I', 'n', 'a'};
char str[10] = "china";
2.通过字符指针
char *str = "china is a great country"
3.字符串相关函数的使用。需要注意有些使用和方法需要声明一段内存:strcpy(),strcat()...
五.结构体枚举
1.结构体定义和使用
struct Person {
char name[20];
int age;
int (*func)();
}
1.
struct Person p1 = {"Bruce", 28};
2.
struct Person p1
p1.age = 28;
strcpy(p1.name, "Jack");
2 .匿名结构体
3.结构体和指针
4.联合体
union MyValue {
int x;
int y;
double z;
}
void mian() {
union MyValue d1;
d1.x = 80;
d1.y = 110;
d1.z = 23.5;
printf("%d, %d, %lf\n", d1.x, d1.y, d1.z);
}
5.枚举类型 ,enumeration 对数据范围进行限定范围可以列举的情况下
enum WeekDay {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
void main() {
enum WeekDay weekDay = Monday;
printf("%#x, %d\n", &d, d);
getchars();
}
六.File操作
1.file文件描述符
2.文件路径
3.打开文件的方式 wb,rb,
4.文件读写的方法
#define _CRT_SECURE_NO_WARNINGS
#include "stdlib.h"
#include "stdio.h"
// 读取文本文件
void main() {
// 路径
char *path = "绝对路径";
// 打开 + 打开方式
FILE *fp = fopen(path, "r");
if (fp == null) {
printf("文件打开失败...");
return;
}
// 读取
char buffer[50]; // 缓存
while (gets(buff, 50, fp)) {
printf("%s", buffer);
}
fclose(fp);
getchars();
}
1.字符流字节流的区别
2.换行符的区别
写文本时,每遇到一个'\n',会将其转换成'\r\n'(回车换行)
读文本时,每遇到一个'\r\n',会将其转化成'\n'
3.demo
void main() {
char *read_path = "";
char *write_path = "";
// 读的文件 b字符表示操作二进制文件binary
FILE *read_fp = fopen(read_path, "rb");
FILE *write_fp = fopen(write_path, "wb");
//复制
int buffer[50]; // 缓存区域
int len = 0; // 每次读到的数据长度
while ((len = read(buff, sizeof(int), 50, read_fp)) != 0) {
write(buffer, sizeof(int), len, write_fp);
}
close(read_fp);
close(write_fp);
getchar();
}
4.文件大小获取 fseek
// 获取文件大小
void main() {
char *read_path = "";
FILE *fp = fopen(read_path, "r");
// 重新定位文件指针
// SEEK_END 文件
fseek(fp, 0, SEEK_END);
getchar();
}
5.文件加密示例代码:
void encrypt(char* normal_path, char* crypt_path) {
// 打开文件
FILE *normal_fp = fopen(normal_path, "r");
FILE *crypt_fp = fopen(crypt_path, "w");
// 一次读取一个字符
int ch;
while ((ch = fgetc(normal_fp) != EOF)) { // end of file
// 加密 (异或加密 1^1=0, 0^0=0,1^0=1, 0^1=1)
// 写入
fputc(ch ^ 9, crypt_fp);
}
}
void main() {
char *normal_path = "";
char *crypt_path = "";
encrypt(normal_path, crypt_path);
getchar();
}
6.文件分割和合并
7.C++宏定义
1.定义宏常量
2.定义宏函数
引入printf
#define LOG(LEVEL, FORMAT, ...) printf(##LEVEL); printf(##FORMAT, __VA_ARGS__);
#define LOG_I(FORMAT, ...); LOG("INFO:", ##FORMAT, __VA_ARGS__);
#define LOG_D(FORMAT, ...); LOG("INFO:", ##FORMAT, __VA_ARGS__);
#define LOG_W(FORMAT, ...); LOG("INFO:", ##FORMAT, __VA_ARGS__);
#define LOG_E(FORMAT, ...); LOG("INFO:", ##FORMAT, __VA_ARGS__);
使用:
LOG("%s%d", "大小:", 89);