很多时候,Insyde BIOS 是以 EXE 的形式给出来的,直接在 Windows下运行即可烧写当前设备。但是很多时候我们期望使用烧录器来烧写,这种情况,我们需要提取 EXE 中的BIOS ROM 文件。
本文根据【参考1】编写,主要步骤是:
- 使用 7z 解压 EXE 文件(选中EXE后解压即可)
- 之后使用十六进制工具打开解压出来的 winflash.fd 文件
- 在winflash.fd 中搜索 “$_IFLASH_BIOSIMG”,这个字符串起始位置+ 这个字符串长度+8字节就是 BIOS Rom 的起始位置
- 在winflash.fd 中搜索 “$_IFLASH_INI_IMG”,这个字符串起始位置-8字节就是 BIOS Rom 的结束位置
- 将中间内容粘贴为一个单独的文件就是这个 EXE 对应的 BIOS Rom了。
编写一个批处理和VC 来实现自动化。
对应的 Bat代码:
if "%1"=="" (
echo Please give the filename
exit /b 1
)
if NOT exist "%1" (
echo %1 not exist!
exit /b 1
)
mkdir tempdir
7z x %1 -otempdir -y
Ins2ROM
对应的 VC 代码:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
bool readFileToMemory(const std::string& filePath, std::vector<char>& buffer) {
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
if (!file) {
std::cerr << "Failed to open file: " << filePath << std::endl;
return false;
}
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
buffer.resize(size);
if (!file.read(buffer.data(), size)) {
std::cerr << "Failed to read file: " << filePath << std::endl;
return false;
}
return true;
}
bool saveMemoryToFile(const std::string& filePath, const std::vector<char>& buffer, size_t start, size_t end) {
if (start >= end || end > buffer.size()) {
std::cerr << "Invalid start or end position." << std::endl;
return false;
}
std::ofstream outFile(filePath, std::ios::binary);
if (!outFile) {
std::cerr << "Failed to open output file: " << filePath << std::endl;
return false;
}
outFile.write(buffer.data() + start, end - start);
if (!outFile) {
std::cerr << "Failed to write to output file: " << filePath << std::endl;
return false;
}
return true;
}
int main() {
const std::string inputFilePath = ".\\tempdir\\winflash.fd";
const std::string outputFilePath = "BIOSRom.bin";
const std::string startPattern = "$_IFLASH_BIOSIMG";
const std::string endPattern = "$_IFLASH_INI_IMG";
std::cout << "Insyde EXE to BIOS ROM" << std::endl;
std::cout << " www.lab-z.com" << std::endl;
std::cout << " 2025 02" << std::endl;
std::vector<char> buffer;
if (!readFileToMemory(inputFilePath, buffer)) {
std::cerr << "Can't find" << inputFilePath << std::endl;
return 1;
}
auto startIt = std::search(buffer.begin(), buffer.end(), startPattern.begin(), startPattern.end());
auto endIt = std::search(buffer.begin(), buffer.end(), endPattern.begin(), endPattern.end());
if (startIt == buffer.end() || endIt == buffer.end() || startIt >= endIt) {
std::cerr << "Patterns not found or in wrong order." << std::endl;
return 1;
}
size_t startPos = std::distance(buffer.begin(), startIt) + startPattern.size()+ 8;
size_t endPos = std::distance(buffer.begin(), endIt)-8;
if (!saveMemoryToFile(outputFilePath, buffer, startPos, endPos)) {
return 1;
}
std::cout << "BIOSRom.bin successfully created." << std::endl;
return 0;
}
完整的编译后的工具打包在一起:
参考:
1. https://zhuanlan.zhihu.com/p/21169375283