Last active
October 8, 2024 03:07
-
-
Save EggToaster/4a38402217dc19a1e5ac305d2e61b130 to your computer and use it in GitHub Desktop.
Convert CPU-Z output to actual .rom file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--!/usr/bin/env lua | |
---@diagnostic disable: need-check-nil | |
-- frickoffcpuz.lua | |
-- | |
-- Converts BIOS file generated from CPU-Z to actual BIOS file so you | |
-- can use it with many programs. | |
-- CPU-Z will generate txt file with both binary data and ASCII data, | |
-- but doesn't work with many programs as they except binary data. | |
-- | |
-- Created by github.com/EggToaster | |
-- Please credit me if you are going to use this code in paid software. | |
-- Not a requirement, but will be cool. | |
-- Not compiling and not obfusacting this .lua file and keeping | |
-- all comments including this one counts as credited for this file. | |
-- https://stackoverflow.com/questions/9137415/lua-writing-hexadecimal-values-as-a-binary-file | |
-- Answer provided by jpjacobs. | |
-- Originally named writeHex. Modified part of it. | |
local function tobinary(str) | |
local r = "" | |
for byte in str:gmatch'%x%x' do | |
r = r .. string.char(tonumber(byte,16)) | |
end | |
return r | |
end | |
local o = io.open(arg[1],"r") | |
-- Assuming that file contains 10 lines of information at first, and | |
-- 11th line is start for actual data. | |
---@diagnostic disable-next-line: discard-returns | |
for i = 1, 11 do o:read("l") end | |
local s = o:read("a") | |
o:close() | |
s = s:gsub("\r","") | |
local sss = "" | |
for ss in string.gmatch(s,"([^\n]+)") do | |
ss = ss:sub(6,ss:len()-18) | |
sss = sss..ss | |
end | |
sss = sss:gsub(" ","") | |
local f = io.open(arg[2],"wb") | |
f:write(tobinary(sss)) | |
f:close() | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment