Skip to content

Commit 287c150

Browse files
committed
Implementing detection of a jump in the middle of instruction
1 parent 34fffa7 commit 287c150

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/app/shared/disassembler.shared.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ export class Disassembler {
145145
Disassembler.JLT, Disassembler.JLE, Disassembler.JGT, Disassembler.JGE,
146146
Disassembler.CALL, Disassembler.RETURN, Disassembler.ENTER, Disassembler.EXIT,
147147
Disassembler.READ, Disassembler.PRINT, Disassembler.BREAD, Disassembler.BPRINT,
148-
Disassembler.TRAP, Disassembler.INVOKEVIRTUAL, Disassembler.DUP_X1, Disassembler.DUP_X2];
148+
Disassembler.TRAP, Disassembler.INVOKEVIRTUAL, Disassembler.DUP_X1, Disassembler.DUP_X2
149+
];
150+
151+
private startAddresses: number[];
149152

150153
constructor(uint8Array: Uint8Array) {
151154
this.uint8Array = uint8Array;
@@ -191,10 +194,13 @@ export class Disassembler {
191194

192195
this.headerSize = this.current;
193196
this.address = this.current - this.headerSize;
197+
198+
this.startAddresses = [];
194199

195200
while (this.current < this.uint8Array.length) {
196201
this.warning = null;
197202
this.jumpDestination = null;
203+
this.startAddresses.push(this.address);
198204
switch(this.opcode = this.get()) {
199205
case Disassembler.LOAD.opcode: {
200206
this.operand1 = this.get();
@@ -486,6 +492,12 @@ export class Disassembler {
486492
}
487493
}
488494
}
495+
496+
this.disassembledInstructions.forEach(disassembledInstruction => {
497+
if (disassembledInstruction.referencedAddress && !this.startAddresses.includes(disassembledInstruction.referencedAddress)) {
498+
disassembledInstruction.warning = "This instruction is problematic! It jumps in the middle of another instruction."
499+
}
500+
});
489501
}
490502

491503
getCodeSize() {

0 commit comments

Comments
 (0)