编译环境: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; }