为了便于测试透明解密的效果,写了一个文件拷贝工具,把文件从a拷贝到b位置。
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
#define TMP_BLOCK_SIZE 1024
int main(int argc, char **argv)
{
FILE * fp_input = NULL;
FILE * fp_output = NULL;
char * inputname = argv[1];
char * outputname = argv[2];
char * tmp_buff = NULL;
int input_file_size = 0;
int curr_offset = 0;
size_t i = 0;
int ret = 0;
tmp_buff = (char*)malloc(sizeof(char)*TMP_BLOCK_SIZE);
ret = fopen_s(&fp_input,inputname, "rb");
if (NULL == fp_input)
{
return -1;
}
ret = fopen_s(&fp_output,outputname, "wb");
if (NULL == fp_output)
{
return -1;
}
_fseeki64(fp_input, 0, SEEK_END);
input_file_size = _ftelli64(fp_input);
if (0 == input_file_size)
{
// 文件大小为0
return -1;
}
do
{
fseek(fp_input, curr_offset, SEEK_SET);
if (input_file_size - curr_offset < TMP_BLOCK_SIZE)
{
fread(tmp_buff, 1, input_file_size - curr_offset ,fp_input);
fwrite(tmp_buff, 1, input_file_size - curr_offset, fp_output);
}
else
{
fread(tmp_buff, 1, TMP_BLOCK_SIZE, fp_input);
fwrite(tmp_buff, 1, TMP_BLOCK_SIZE, fp_output);
}
curr_offset += TMP_BLOCK_SIZE;
} while (curr_offset <= input_file_size);
fclose(fp_input);
fclose(fp_output);
if (tmp_buff != NULL)
{
free(tmp_buff);
tmp_buff = NULL;
}
return 0;
}
|