#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
struct node{ //换了一种方式,使用链表存储更加灵活
char data;
struct node *next;
};
int main(){
FILE *pFile = fopen("D://1.exe", "rb");
FILE *wFile = fopen("D://2.exe", "ab+");
char buf[5];
int ret = 0;
node *p = (node *)malloc(sizeof(node));
node *head = p;
while((ret = fread(buf, sizeof(char), 1, pFile))){
node *x = (node *)malloc(sizeof(node));
x->data = *buf;
p->next = x;
p = x;
}
p->next = NULL;
head = head->next;
while(head->next != NULL){
fwrite(&(head->data), sizeof(char), 1, wFile);
head = head->next;
}
return 0;
}
1、打开文件
2、申请内存
3、把exe可执行文件链式存取到内存中
4、再读取出来
5、有些大佬会觉得有点扯淡,瞎写练手而已