19#include <radio_tool/fw/ailunce_fw.hpp>
20#include <radio_tool/util.hpp>
28 auto i = std::ifstream(file, std::ios_base::binary);
31 i.seekg(0, std::ios_base::end);
32 auto binarySize = i.tellg();
33 memory_ranges.push_back(std::make_pair(0, binarySize));
34 i.seekg(std::ios_base::beg);
35 data.resize(binarySize);
36 i.read((
char *)data.data(), data.size());
43 std::ofstream fout(file, std::ios_base::binary);
46 fout.write((
char *)data.data(), data.size());
53 std::stringstream out;
54 out <<
"== Ailunce Firmware == " << std::endl;
58 out <<
" " << n++ <<
": Start=0x" << std::setfill(
'0') << std::setw(8) << std::hex << m.first
59 <<
", Length=0x" << std::setfill(
'0') << std::setw(8) << std::hex << m.second
68 i.open(file, i.binary);
76 throw std::runtime_error(
"Can't open firmware file");
83 return model ==
"HD1";
105auto AilunceFW::ApplyXOR() ->
void
107 for (uint32_t i = 0; i < (data.size() /
sizeof(uint32_t)); i++)
109 uint32_t *word =
reinterpret_cast<uint32_t *
>(data.data()) + i;
110 if (*word == 0x0 || *word == 0xffffffff)
112 else if (*word & (1 << 28))
118 for (
auto z = data.size() - (data.size() %
sizeof(uint32_t));
119 z < data.size(); z++)
121 if (data[z] == 0x00 || data[z] == 0xff)
123 else if (data[z] & 1)
132 if (
typeid(Other) !=
typeid(
this)) {
136 auto afw =
dynamic_cast<const AilunceFW*
>(Other);
137 return afw->radio_model == radio_model;