Skip to content

Commit

Permalink
Fix issues with disassembly
Browse files Browse the repository at this point in the history
Tidy message

Bump version
  • Loading branch information
Your Name committed Oct 1, 2024
1 parent b870996 commit 408a81c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frida-cshell",
"version": "1.6.0",
"version": "1.6.1",
"description": "Frida's CShell",
"scripts": {
"prepare": "npm run build && npm run version && npm run package && npm run copy",
Expand Down
26 changes: 24 additions & 2 deletions src/cmdlets/data/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Format } from '../../misc/format.js';
import { Token } from '../../io/token.js';
import { Var } from '../../vars/var.js';
import { Mem } from '../../memory/mem.js';
import { Overlay } from '../../memory/overlay.js';

export class AssemblyCmdLet extends CmdLet {
name = 'l';
Expand Down Expand Up @@ -47,6 +48,7 @@ l address <bytes> - show disassembly listing
try {
const minLength = this.maxInstructionLen();
const copy = Memory.alloc(Process.pageSize);
let hasOverlaps = false;

for (let i = 1; i <= length; i++) {
if (buffer.byteLength < minLength) {
Expand All @@ -58,7 +60,15 @@ l address <bytes> - show disassembly listing
}

Mem.writeBytes(copy, buffer);
const insn = Instruction.parse(copy.add(isThumb ? 1 : 0));

let insn = Instruction.parse(cursor.add(isThumb ? 1 : 0));
const overlaps = Overlay.overlaps(cursor, insn.size);

if (overlaps) {
hasOverlaps = true;
insn = Instruction.parse(copy.add(isThumb ? 1 : 0));
}

if (insn.size > buffer.length)
throw new Error(
`failed to parse instruction at ${cursor}, not enough bytes: ${buffer.length}`,
Expand All @@ -71,14 +81,26 @@ l address <bytes> - show disassembly listing
.join(' ');

Output.writeln(
`${Output.bold(idx)}: ${Output.green(Format.toHexString(cursor))}: ${Output.yellow(insn.toString().padEnd(40))} ${Output.blue(bytesStr)}`,
[
`${Output.bold(idx)}:`,
`${Output.green(Format.toHexString(cursor))}:`,
`${Output.yellow(insn.toString().padEnd(40))}`,
`${Output.blue(bytesStr)}`,
overlaps ? `${Output.red('*')}` : '',
].join(' '),
true,
);

cursor = cursor.add(insn.size);
buffer = buffer.slice(insn.size);
}

if (hasOverlaps) {
Output.writeln(
`${Output.red('*')} offset in RIP relative instruction may be incorrect due to conflicting breakpoint`,
);
}

return new Var(uint64(cursor.toString()));
} catch (error) {
throw new Error(
Expand Down

0 comments on commit 408a81c

Please sign in to comment.