From 2a37f7dae6022e164163e6d9ea4a4bba8a369fe6 Mon Sep 17 00:00:00 2001 From: mashitianxia Date: Mon, 17 Apr 2023 22:43:00 +0800 Subject: [PATCH] =?UTF-8?q?d1:=20=E9=AA=8C=E8=AF=81magic=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=EF=BC=8C=E8=A7=A3=E6=9E=90c.j=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mashitianxia --- D1Image.bt | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/D1Image.bt b/D1Image.bt index fd1a74c..b0cabaf 100644 --- a/D1Image.bt +++ b/D1Image.bt @@ -17,7 +17,7 @@ struct EgonHead; typedef struct { uint32 jump_instruction ; - ubyte magic[8]; + uint64 magic ; uint32 checksum ; uint32 total_length ; uint32 _head_size; @@ -31,9 +31,13 @@ typedef struct { /**** PARSING CODE ****/ LittleEndian(); - EgonHead head ; +local uint64 correct_magic = 0x3054422E4E4F4765; +if (correct_magic != head.magic) { + Warning("wrong magic!"); +} + local uint32 opcode = head.jump_instruction & 0x7f; // 0x6f JAL opcode if (opcode == 0x6f) @@ -53,3 +57,26 @@ if (opcode == 0x6f) } 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] ; + } 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); +} -- Gitee