C/C++教程

WiFi固件bin文件转C数组的程序

本文主要是介绍WiFi固件bin文件转C数组的程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

编译环境:Visual Studio 2012

#include <stdio.h>
#include <Windows.h>

#define FOLDER_88W8686 "E:\\Users\\Octopus\\Downloads\\SD-8686-LINUX26-SYSKT-9.70.3.p24-26409.P45-GPL\\SD-8686-FEDORA26FC6-SYSKT-GPL-9.70.3.p24-26409.P45\\FwImage"
#define FOLDER_88W8782 "E:\\Users\\Octopus\\Downloads\\Baidu\\8782模块资料\\SD-UAPSTA-8782-FC13-MMC-14.69.12.p35-M2614336_B0-GPL_new\\SD-UAPSTA-8782-FC13-MMC-14.69.12.p35-M2614336_B0-GPL\\FwImage"
#define FOLDER_88W8801 "E:\\Users\\Octopus\\Downloads\\Baidu\\8782模块资料\\SD-UAPSTA-8801-FC18-MMC-14.76.36.p61-C3X14090_B0-GPL\\SD-UAPSTA-8801-FC18-MMC-14.76.36.p61-C3X14090_B0-GPL\\FwImage"
#define FOLDER_RTL8189 "D:\\Code\\C\\VS2012\\applications\\array_mp_8188e_t_fw_nic\\Debug"
#define LINELEN 24

static void create(char *binfile, char *cfile, char *varname)
{
	char str[100];
	DWORD size = 0;
	FILE *fp, *fp2;
	FILETIME last_write_time;
	HANDLE hFile;
	int linecnt = 0;
	SYSTEMTIME st_local, st_utc;
	unsigned char data;

	hFile = CreateFileA(binfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, (DWORD)NULL, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		size = GetFileSize(hFile, NULL);
		GetFileTime(hFile, NULL, NULL, &last_write_time);
		FileTimeToSystemTime(&last_write_time, &st_utc);
		SystemTimeToTzSpecificLocalTime(NULL, &st_utc, &st_local);
		CloseHandle(hFile);
	}

	fopen_s(&fp, binfile, "rb");
	if (fp == NULL)
	{
		printf("Cannot open %s!\n", binfile);
		return;
	}
	fopen_s(&fp2, cfile, "w");
	if (fp2 == NULL)
	{
		fclose(fp);
		printf("Cannot open %s!\n", cfile);
		return;
	}

	GetDateFormatA(LOCALE_USER_DEFAULT, (DWORD)NULL, &st_local, NULL, str, sizeof(str));
	fprintf(fp2, "// From: %s\n// Last Modified: %s ", binfile, str);
	GetTimeFormatA(LOCALE_USER_DEFAULT, (DWORD)NULL, &st_local, NULL, str, sizeof(str));
	fprintf(fp2, "%s\n", str);

	fprintf(fp2, "const unsigned char %s[%d] = {", varname, size);
	while (data = fgetc(fp), !feof(fp))
	{
		if (linecnt == 0)
			fputs("\n  ", fp2);
		fprintf(fp2, "0x%02x, ", data);
		linecnt = (linecnt + 1) % LINELEN;
	}

	fseek(fp2, -2, SEEK_CUR);
	fputs("\n};\n", fp2);

	fclose(fp);
	fclose(fp2);
}

int main(void)
{
	//SetCurrentDirectoryA(FOLDER_88W8686); // 设置当前目录
	//create("helper_sd.bin", "helper_sd.c", "firmware_helper_sd");
	//create("sd8686.bin", "sd8686.c", "firmware_sd8686");

	//SetCurrentDirectoryA(FOLDER_88W8782);
	//create("sd8782_uapsta.bin", "sd8782_uapsta.c", "firmware_sd8782");

	//SetCurrentDirectoryA(FOLDER_88W8801);
	//create("sd8801_uapsta.bin", "sd8801_uapsta.c", "firmware_sd8801");

	SetCurrentDirectoryA(FOLDER_RTL8189);
	create("mp_8188e_s_fw_ap.bin", "mp_8188e_s_fw_ap.c", "firmware_mp_8188e_s_fw_ap");
	create("mp_8188e_s_fw_nic.bin", "mp_8188e_s_fw_nic.c", "firmware_mp_8188e_s_fw_nic");
	create("mp_8188e_s_fw_wowlan.bin", "mp_8188e_s_fw_wowlan.c", "firmware_mp_8188e_s_fw_wowlan");
	create("mp_8188e_t_fw_ap.bin", "mp_8188e_t_fw_ap.c", "firmware_mp_8188e_t_fw_ap");
	create("mp_8188e_t_fw_nic.bin", "mp_8188e_t_fw_nic.c", "firmware_mp_8188e_t_fw_nic");
	create("mp_8188e_t_fw_nic_89em.bin", "mp_8188e_t_fw_nic_89em.c", "firmware_mp_8188e_t_fw_nic_89em");
	create("mp_8188e_t_fw_wowlan.bin", "mp_8188e_t_fw_wowlan.c", "firmware_mp_8188e_t_fw_wowlan");

	return 0;
}

这篇关于WiFi固件bin文件转C数组的程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!