20.将Dll文件转为二进制代码运行时解压出来
[toc]
使用C语言读取与写入文件
1. c语言读取文件
新建一个文本文件,命名为first.txt。
在first.txt中编辑文本。
编写C语言代码在程序中读取文本内容。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
FILE* fp = NULL;
char buff[255];
fp = fopen("D:\\Users\\3\\Desktop\\first.txt", "r");
fgets(buff, 255, (FILE*)fp);
printf("1: %s\n", buff);
fgets(buff, 255, (FILE*)fp);
printf("2: %s\n", buff);
fgets(buff, 255, (FILE*)fp);
printf("3: %s\n", buff);
fclose(fp);
return 0;
}编译运行
2.C语言写入给文本文件中写入字符串
- 编写代码
1 |
|
- 打开first.txt查看文件发现文本内容更改
1 | This is testing for fprintf... |
3.C语言以二进制的方式读取文本
编写C语言代码,以二进制的方式读取文本。
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
int main() {
FILE* file;
unsigned char buffer[100]; // 用于存储读取的数据
size_t bytesRead;
// 以二进制模式打开文件
file = fopen("D:\\Users\\3\\Desktop\\first.txt", "rb");
if (file == NULL) {
perror("无法打开文件");
return 1;
}
// 读取文件内容
bytesRead = fread(buffer, sizeof(unsigned char), sizeof(buffer), file);
if (bytesRead > 0) {
// 处理读取的数据
printf("读取了 %zu 字节\n", bytesRead);
}
// 关闭文件
fclose(file);
return 0;
}
4.C语言以二进制的方式读取文本并打印字符串
1 |
|
5.C语言以二进制的方式读取文本并打印16进制数据
1 |
|
6. C语言以二进制的方式写入文件
1 |
|
使用C语言在windows读取与写入文件
1. windows读取文件
新建一个文本文件,命名为first.txt。
在first.txt中编辑文本。
1
2
31.windows read file
2. cotine
3. 6666666666666C语言使用win32api在程序中读取文本内容。
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
int main()
{
HANDLE hFile;
DWORD bytesRead;
char buffer[100];
// 打开文件
hFile = CreateFileA("D:\\Users\\3\\Desktop\\first.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("无法打开文件,错误代码: %lu\n", GetLastError());
return 1;
}
// 读取文件内容
if (ReadFile(hFile, buffer, sizeof(buffer) - 1, &bytesRead, NULL)) {
buffer[bytesRead] = '\0'; // 添加字符串结束符
printf("读取的内容:\n%s", buffer);
}
else {
printf("读取文件时出错,错误代码: %lu\n", GetLastError());
}
// 关闭文件
CloseHandle(hFile);
return 0;
}编译运行
2.windows给文本文件中写入字符串
- 编写代码
1 |
|
- 打开first.txt查看文件发现文本内容更改
1 | Hello, World! |
3. windows以二进制的方式读取文本并打印字符串
1 |
|
4. windows以二进制的方式读取文本并打印16进制数据
1 |
|
6. windows以二进制的方式写入文件
1 |
|
使用C语言在windows系统中将Dll文件打包到exe程序中
1.使用WinHex将二进制文件复制
在WinHex选中编辑->复制选块->c源码
2.将二进制代码粘贴到c语言源码中
3.编写c语言代码写入文件
源码
1 | //main.c |
二进制文件内容概括
1 | //DllBuffer.h |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
