diff --git a/D1Image.bt b/D1Image.bt index fd1a74cb86af5f6714bce32510f4a8c0c0d3462e..b0cabaf7093b8e629c3c2dd01039974d0cc98e9f 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); +}