2 Star 11 Fork 10

RustSBI/010 Editor 模板

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
D1Image.bt 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
//------------------------------------------------
//--- 010 Editor v13.0.1 Binary Template
//
// File: d1-flash
// Authors: Mingrui Ma
// Version: 0.0.0
// Purpose:
// Category:
// File Mask:
// ID Bytes:
// History:
//------------------------------------------------
RequiresVersion( 12 );
/**** STRUCTURES ****/
struct EgonHead;
typedef struct {
uint32 jump_instruction <format=hex, comment="address of jump_instruction">;
uint64 magic <format=hex>;
uint32 checksum <format=hex, comment="checksum">;
uint32 total_length <format=hex>;
uint32 _head_size;
uint32 fel_script_address;
uint32 fel_uenv_length;
uint32 dt_name_offset;
uint32 dram_size;
uint32 boot_media;
uint32 string_pool[13];
} EgonHead;
/**** PARSING CODE ****/
LittleEndian();
EgonHead head <bgcolor=cLtPurple>;
local uint64 correct_magic = 0x3054422E4E4F4765;
if (correct_magic != head.magic) {
Warning("wrong magic!");
}
local uint32 tmp_check_num = 0;
local uint64 i;
for(i = 10h; i<FileSize(); i+=4){
tmp_check_num += ReadUInt(i);
}
tmp_check_num += ReadUInt(0);
tmp_check_num += ReadUInt(4);
tmp_check_num += ReadUInt(8);
tmp_check_num += 0x5F0A6C39; // stamp number
if (tmp_check_num != ReadUInt(0xC)) {
Warning("Wrong check_num!");
}
local uint32 opcode = head.jump_instruction & 0x7f;
// 0x6f JAL opcode
if (opcode == 0x6f)
{
local uint32 imm1912 = (head.jump_instruction >> 12) & 0xff;
local uint32 imm11 = (head.jump_instruction >> 20) & 0x01;
local uint32 imm101 = (head.jump_instruction >> 21) & 0x3ff;
local uint32 imm20 = (head.jump_instruction >> 31) & 0x01;
local uint32 offset = (imm20 << 20) + (imm1912 << 12) + (imm11 << 11) + (imm101 << 1);
local quad off = FTell();
if(offset < FileSize() && head.total_length <= FileSize()) {
FSeek(offset);
ubyte code[head.total_length - offset] <comment="code",bgcolor=cLtGreen>;
} else {
Warning("code appears to either overlap with header, exist after the end of the file or overlap with the end of the file!");
}
FSeek(off);
}
local uint16 c_ins = head.jump_instruction & 0xffff;
local uint16 c_op = c_ins & 0x3;
local uint16 c_funct3 = c_ins >> 13;
if (c_op == 0x1 && c_funct3 == 0x5) {
local uint16 imm11 = (c_ins >> 12) & 0x1;
local uint16 imm4 = (c_ins >> 11) & 0x1;
local uint16 imm98 = (c_ins >> 9) & 0x3;
local uint16 imm10 = (c_ins >> 8) & 0x1;
local uint16 imm6 = (c_ins >> 7) & 0x1;
local uint16 imm7 = (c_ins >> 6) & 0x1;
local uint16 imm31 = (c_ins >> 3) & 0x7;
local uint16 imm5 = (c_ins >> 2) & 0x1;
local uint16 offset = (imm11 << 11) | (imm4 << 4) | (imm98 << 8) | (imm10 << 10) | (imm6 << 6)| (imm7 << 7)| (imm31 << 1) | (imm5 << 5);
local quad off = FTell();
if(offset < FileSize() && head.total_length <= FileSize()) {
FSeek(offset);
ubyte code[head.total_length - offset] <comment="code",bgcolor=cLtGreen>;
} else {
Warning("code appears to either overlap with header, exist after the end of the file or overlap with the end of the file!");
}
FSeek(off);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rustsbi/010-editor-scripts.git
git@gitee.com:rustsbi/010-editor-scripts.git
rustsbi
010-editor-scripts
010 Editor 模板
main

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385