原理
- 去除无效字符"0x"、"\n"、空格等,从第一个有效字符(即0~F)开始,每2个有效字符满足转换条件,输出一个格式化HEX字节。
- 将字符串输入后,每两个字符转换成一个byte(Hex),如:9F01以ASCII码保存的四个字节,输出为十六进制文件的两个字节:9F01
使用方式
设定输入/输出的绝对路径(路径+文件名),如:
日志| please set source file path:
输入| D:/test/input.txt
日志| please set output file path:
输入| D:/test/output.txt
程序
代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _CRT_SECURE_NO_WARNINGS
#define PAYLOAD_OFFSET 0
#define INVALID_CHARACTOR 0x10 //valid:0x0~0xF
unsigned char HexChar(unsigned char c);
char* getFilePath(void);
int find_next_number(unsigned char* pbData, int size);
int main(void)
{
size_t result = -1;
FILE* pFile = NULL;
unsigned char* pbFileData = NULL;
unsigned char* pbHexData = NULL;
int dFileSize = 0;
char* pbSourcePath = NULL;
char* pbOutput = NULL;
printf("please set source file path: \n");
pbSourcePath = getFilePath();
printf("please set output file path: \n");
pbOutput = getFilePath(