diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ae18b90..f96dcfa 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1 +1,4 @@ FROM cshell AS frida-cshell +RUN apt-get update && \ + apt-get install -y \ + nano diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b699650..72a2795 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -131,7 +131,7 @@ }, { "type": "shell", - "command": "frida-inject-32 -s frida-cshell.js -P '{\"verbose\": true}' --interactive -f /usr/bin/target32", + "command": "frida-inject-32 -s frida-cshell.js -P '{\"debug\": true}' --interactive -f /usr/bin/target32", "problemMatcher": [], "label": "Debug32", "group": { @@ -153,7 +153,7 @@ } { "type": "shell", - "command": "frida-inject-64 -s frida-cshell.js -P '{\"verbose\": true}' --interactive -f /usr/bin/target64", + "command": "frida-inject-64 -s frida-cshell.js -P '{\"debug\": true}' --interactive -f /usr/bin/target64", "problemMatcher": [], "label": "Debug64", "group": { @@ -282,4 +282,4 @@ } } ] -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 18f18fc..9de5b7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "frida-cshell", - "version": "1.4.3", + "version": "1.4.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "frida-cshell", - "version": "1.4.3", + "version": "1.4.4", "devDependencies": { "@eslint/js": "^9.10.0", "@types/frida-gum": "^18.7", diff --git a/package.json b/package.json index 800ab32..23bbaae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frida-cshell", - "version": "1.4.3", + "version": "1.4.4", "description": "Frida's CShell", "scripts": { "prepare": "npm run build && npm run version && npm run package && npm run copy", diff --git a/src/breakpoints/bp.ts b/src/breakpoints/bp.ts index 33f13ac..9820a42 100644 --- a/src/breakpoints/bp.ts +++ b/src/breakpoints/bp.ts @@ -283,7 +283,7 @@ export class Bp { } catch (error) { if (error instanceof Error) { Output.writeln(`ERROR: ${error.message}`); - Output.verboseWriteln(`${error.stack}`); + Output.debug(`${error.stack}`); } else { Output.writeln(`ERROR: Unknown error`); } diff --git a/src/cmdlets/bp.ts b/src/cmdlets/breakpoints/bp.ts similarity index 97% rename from src/cmdlets/bp.ts rename to src/cmdlets/breakpoints/bp.ts index b6b282e..92d049c 100644 --- a/src/cmdlets/bp.ts +++ b/src/cmdlets/breakpoints/bp.ts @@ -1,10 +1,10 @@ -import { BP_LENGTH, BpType } from '../breakpoints/bp.js'; -import { Bps } from '../breakpoints/bps.js'; -import { CmdLet } from '../commands/cmdlet.js'; -import { Input, InputInterceptLine } from '../io/input.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { BP_LENGTH, BpType } from '../../breakpoints/bp.js'; +import { Bps } from '../../breakpoints/bps.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Input, InputInterceptLine } from '../../io/input.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const NUM_CHAR: string = '#'; const UNLIMITED_CHAR: string = '*'; diff --git a/src/cmdlets/reg.ts b/src/cmdlets/breakpoints/reg.ts similarity index 86% rename from src/cmdlets/reg.ts rename to src/cmdlets/breakpoints/reg.ts index 03f7027..bcec824 100644 --- a/src/cmdlets/reg.ts +++ b/src/cmdlets/breakpoints/reg.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Vars } from '../vars/vars.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; -import { Regs } from '../breakpoints/regs.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Vars } from '../../vars/vars.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Regs } from '../../breakpoints/regs.js'; const USAGE: string = `Usage: R R - show the values of all registers diff --git a/src/cmdlets/assembly.ts b/src/cmdlets/data/assembly.ts similarity index 93% rename from src/cmdlets/assembly.ts rename to src/cmdlets/data/assembly.ts index 588688c..e57a644 100644 --- a/src/cmdlets/assembly.ts +++ b/src/cmdlets/data/assembly.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; const DEFAULT_LENGTH: number = 10; const USAGE: string = `Usage: l diff --git a/src/cmdlets/copy.ts b/src/cmdlets/data/copy.ts similarity index 78% rename from src/cmdlets/copy.ts rename to src/cmdlets/data/copy.ts index e84abf5..38dbe26 100644 --- a/src/cmdlets/copy.ts +++ b/src/cmdlets/data/copy.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; const USAGE: string = `Usage: cp diff --git a/src/cmdlets/dump.ts b/src/cmdlets/data/dump.ts similarity index 94% rename from src/cmdlets/dump.ts rename to src/cmdlets/data/dump.ts index c497ff0..ea0cd95 100644 --- a/src/cmdlets/dump.ts +++ b/src/cmdlets/data/dump.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; const ROW_WIDTH: number = 16; const DEFAULT_COUNT: number = 32; diff --git a/src/cmdlets/read.ts b/src/cmdlets/data/read.ts similarity index 86% rename from src/cmdlets/read.ts rename to src/cmdlets/data/read.ts index 5ea923f..d957ce4 100644 --- a/src/cmdlets/read.ts +++ b/src/cmdlets/data/read.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; export class ReadCmdLet extends CmdLet { name = 'r'; diff --git a/src/cmdlets/string.ts b/src/cmdlets/data/string.ts similarity index 86% rename from src/cmdlets/string.ts rename to src/cmdlets/data/string.ts index f951550..d87f478 100644 --- a/src/cmdlets/string.ts +++ b/src/cmdlets/data/string.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; const MAX_STRING_LENGTH: number = 1024; const USAGE: string = `Usage: ds diff --git a/src/cmdlets/write.ts b/src/cmdlets/data/write.ts similarity index 91% rename from src/cmdlets/write.ts rename to src/cmdlets/data/write.ts index c9094ff..75e3b18 100644 --- a/src/cmdlets/write.ts +++ b/src/cmdlets/data/write.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -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 { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Mem } from '../../memory/mem.js'; export class WriteCmdLet extends CmdLet { name = 'w'; diff --git a/src/cmdlets/development/debug.ts b/src/cmdlets/development/debug.ts new file mode 100644 index 0000000..2964a96 --- /dev/null +++ b/src/cmdlets/development/debug.ts @@ -0,0 +1,30 @@ +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; + +const USAGE: string = `Usage: debug +debug - toggle debug mode`; + +export class DebugCmdLet extends CmdLet { + name = 'debug'; + category = 'development'; + help = 'toggle debug mode'; + + public runSync(_tokens: Token[]): Var { + const debug = !Output.getDebugging(); + if (debug) { + Output.writeln(`debug mode ${Output.green('enabled')}`); + } else { + Output.writeln(`debug mode ${Output.red('disabled')}`); + } + Output.setDebugging(debug); + + return Var.ZERO; + } + + public usage(): Var { + Output.writeln(USAGE); + return Var.ZERO; + } +} diff --git a/src/cmdlets/js.ts b/src/cmdlets/development/js.ts similarity index 54% rename from src/cmdlets/js.ts rename to src/cmdlets/development/js.ts index 6e82df8..d50392b 100644 --- a/src/cmdlets/js.ts +++ b/src/cmdlets/development/js.ts @@ -1,40 +1,40 @@ -import { Bp } from '../breakpoints/bp.js'; -import { Bps } from '../breakpoints/bps.js'; -import { MemoryBps } from '../breakpoints/memory.js'; -import { Regs } from '../breakpoints/regs.js'; -import { CmdLet } from '../commands/cmdlet.js'; -import { CmdLets } from '../commands/cmdlets.js'; -import { Command } from '../commands/command.js'; -import { CharCode, Vt } from '../io/char.js'; -import { Input } from '../io/input.js'; -import { Output } from '../io/output.js'; -import { Parser } from '../io/parser.js'; -import { Token } from '../io/token.js'; -import { Mem } from '../memory/mem.js'; -import { Overlay } from '../memory/overlay.js'; -import { Base64 } from '../misc/base64.js'; -import { Format } from '../misc/format.js'; -import { Numeric } from '../misc/numeric.js'; -import { History } from '../terminal/history.js'; -import { Line } from '../terminal/line.js'; -import { Var } from '../vars/var.js'; -import { Vars } from '../vars/vars.js'; -import { AssemblyCmdLet } from './assembly.js'; +import { Bp } from '../../breakpoints/bp.js'; +import { Bps } from '../../breakpoints/bps.js'; +import { MemoryBps } from '../../breakpoints/memory.js'; +import { Regs } from '../../breakpoints/regs.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { CmdLets } from '../../commands/cmdlets.js'; +import { Command } from '../../commands/command.js'; +import { CharCode, Vt } from '../../io/char.js'; +import { Input } from '../../io/input.js'; +import { Output } from '../../io/output.js'; +import { Parser } from '../../io/parser.js'; +import { Token } from '../../io/token.js'; +import { Mem } from '../../memory/mem.js'; +import { Overlay } from '../../memory/overlay.js'; +import { Base64 } from '../../misc/base64.js'; +import { Format } from '../../misc/format.js'; +import { Numeric } from '../../misc/numeric.js'; +import { History } from '../../terminal/history.js'; +import { Line } from '../../terminal/line.js'; +import { Var } from '../../vars/var.js'; +import { Vars } from '../../vars/vars.js'; +import { AssemblyCmdLet } from '../data/assembly.js'; import { FunctionEntryBpCmdLet, FunctionExitBpCmdLet, InsnBpCmdLet, ReadBpCmdLet, WriteBpCmdLet, -} from './bp.js'; -import { BtCmdLet } from './bt.js'; -import { CopyCmdLet } from './copy.js'; -import { DumpCmdLet } from './dump.js'; -import { ExitCmdLet } from './exit.js'; -import { FdCmdLet } from './fd.js'; -import { HelpCmdLet } from './help.js'; -import { HistoryCmdLet } from './history.js'; -import { LdCmdLet } from './ld.js'; +} from '../breakpoints/bp.js'; +import { BtCmdLet } from '../thread/bt.js'; +import { CopyCmdLet } from '../data/copy.js'; +import { DumpCmdLet } from '../data/dump.js'; +import { ExitCmdLet } from '../misc/exit.js'; +import { FdCmdLet } from '../files/fd.js'; +import { HelpCmdLet } from '../misc/help.js'; +import { HistoryCmdLet } from '../misc/history.js'; +import { LdCmdLet } from '../modules/ld.js'; import { AddCmdLet, AndCmdLet, @@ -46,27 +46,27 @@ import { ShrCmdLet, SubCmdLet, XorCmdLet, -} from './math.js'; -import { ModCmdLet } from './mod.js'; -import { ReadCmdLet } from './read.js'; -import { RegCmdLet } from './reg.js'; -import { SymCmdLet } from './sym.js'; -import { ThreadCmdLet } from './thread.js'; -import { VarCmdLet } from './var.js'; -import { VmCmdLet } from './vm.js'; -import { WriteCmdLet } from './write.js'; -import { GrepCmdLet } from './grep.js'; -import { CatCmdLet } from './cat.js'; -import { LogCmdLet } from './log.js'; +} from '../math/math.js'; +import { ModCmdLet } from '../modules/mod.js'; +import { ReadCmdLet } from '../data/read.js'; +import { RegCmdLet } from '../breakpoints/reg.js'; +import { SymCmdLet } from '../memory/sym.js'; +import { ThreadCmdLet } from '../thread/thread.js'; +import { VarCmdLet } from '../misc/var.js'; +import { VmCmdLet } from '../memory/vm.js'; +import { WriteCmdLet } from '../data/write.js'; +import { GrepCmdLet } from '../misc/grep.js'; +import { CatCmdLet } from '../files/cat.js'; +import { LogCmdLet } from '../misc/log.js'; const USAGE: string = `Usage: js -js path - load JS script - path the absolute path of the script to load (note that paths with spaces must be quoted)`; +js path - load commandlet JS script + path the absolute path of the commandlet script to load (note that paths with spaces must be quoted)`; export class JsCmdLet extends CmdLet { name = 'js'; - category = 'misc'; + category = 'development'; help = 'load script'; public runSync(tokens: Token[]): Var { diff --git a/src/cmdlets/cat.ts b/src/cmdlets/files/cat.ts similarity index 79% rename from src/cmdlets/cat.ts rename to src/cmdlets/files/cat.ts index 391e18e..721d05f 100644 --- a/src/cmdlets/cat.ts +++ b/src/cmdlets/files/cat.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: cat @@ -10,7 +10,7 @@ cat file - dump file export class CatCmdLet extends CmdLet { name = 'cat'; - category = 'misc'; + category = 'files'; help = 'dump a file'; public runSync(tokens: Token[]): Var { diff --git a/src/cmdlets/fd.ts b/src/cmdlets/files/fd.ts similarity index 97% rename from src/cmdlets/fd.ts rename to src/cmdlets/files/fd.ts index 3a71849..87504fa 100644 --- a/src/cmdlets/fd.ts +++ b/src/cmdlets/files/fd.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; enum DtType { DT_UNKNOWN = 0 /* The file type is unknown. */, @@ -27,7 +27,7 @@ type Fds = { export class FdCmdLet extends CmdLet { name = 'fd'; - category = 'misc'; + category = 'files'; help = 'display file descriptors'; private static readonly PATH_MAX: number = 4096; diff --git a/src/cmdlets/src.ts b/src/cmdlets/files/src.ts similarity index 76% rename from src/cmdlets/src.ts rename to src/cmdlets/files/src.ts index 4918f7f..a7cdd23 100644 --- a/src/cmdlets/src.ts +++ b/src/cmdlets/files/src.ts @@ -1,21 +1,21 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Command } from '../commands/command.js'; -import { Input } from '../io/input.js'; -import { Output } from '../io/output.js'; -import { Parser } from '../io/parser.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; -import { Vars } from '../vars/vars.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Command } from '../../commands/command.js'; +import { Input } from '../../io/input.js'; +import { Output } from '../../io/output.js'; +import { Parser } from '../../io/parser.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Vars } from '../../vars/vars.js'; const USAGE: string = `Usage: src -src path - load script - path the absolute path of the script to load (note that paths with spaces must be quoted)`; +src path - run commands from file + path the absolute path of the file to load (note that paths with spaces must be quoted)`; export class SrcCmdLet extends CmdLet { name = 'src'; - category = 'misc'; - help = 'load script'; + category = 'files'; + help = 'run commands from file'; private static lastPath: string | null = null; diff --git a/src/cmdlets/math.ts b/src/cmdlets/math/math.ts similarity index 98% rename from src/cmdlets/math.ts rename to src/cmdlets/math/math.ts index 0267eb9..b51a074 100644 --- a/src/cmdlets/math.ts +++ b/src/cmdlets/math/math.ts @@ -1,8 +1,8 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Format } from '../misc/format.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const HEX_LABEL: string = 'HEXADECIMAL'; const DEC_LABEL: string = 'DECIMAL'; diff --git a/src/cmdlets/sym.ts b/src/cmdlets/memory/sym.ts similarity index 95% rename from src/cmdlets/sym.ts rename to src/cmdlets/memory/sym.ts index 6824f13..7ed4ee0 100644 --- a/src/cmdlets/sym.ts +++ b/src/cmdlets/memory/sym.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Format } from '../misc/format.js'; -import { Var } from '../vars/var.js'; -import { Regex } from '../misc/regex.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Format } from '../../misc/format.js'; +import { Var } from '../../vars/var.js'; +import { Regex } from '../../misc/regex.js'; const USAGE: string = `Usage: sym diff --git a/src/cmdlets/vm.ts b/src/cmdlets/memory/vm.ts similarity index 93% rename from src/cmdlets/vm.ts rename to src/cmdlets/memory/vm.ts index 9e9bc8c..c70b16f 100644 --- a/src/cmdlets/vm.ts +++ b/src/cmdlets/memory/vm.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Format } from '../misc/format.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; -import { Regex } from '../misc/regex.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Regex } from '../../misc/regex.js'; const USAGE: string = `Usage: vm diff --git a/src/cmdlets/exit.ts b/src/cmdlets/misc/exit.ts similarity index 62% rename from src/cmdlets/exit.ts rename to src/cmdlets/misc/exit.ts index e70122b..fe6d932 100644 --- a/src/cmdlets/exit.ts +++ b/src/cmdlets/misc/exit.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; export class ExitCmdLet extends CmdLet { name = 'exit'; diff --git a/src/cmdlets/grep.ts b/src/cmdlets/misc/grep.ts similarity index 69% rename from src/cmdlets/grep.ts rename to src/cmdlets/misc/grep.ts index 2e9e32d..3b74cd8 100644 --- a/src/cmdlets/grep.ts +++ b/src/cmdlets/misc/grep.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: grep @@ -18,12 +18,19 @@ export class GrepCmdLet extends CmdLet { public runSync(tokens: Token[]): Var { const vars = this.transformOptional(tokens, [], [this.parseLiteral]); if (vars === null) return this.usage(); - const [_, [filter]] = vars as [[], [string | null]]; + let [_, [filter]] = vars as [[], [string | null]]; if (filter === null) { Output.clearFilter(); Output.writeln('output filter cleared'); } else { try { + if ( + filter.length > 1 && + filter.startsWith('"') && + filter.endsWith('"') + ) { + filter = filter.slice(1, filter.length - 1); + } Output.setFilter(filter); Output.writeln( [ diff --git a/src/cmdlets/help.ts b/src/cmdlets/misc/help.ts similarity index 70% rename from src/cmdlets/help.ts rename to src/cmdlets/misc/help.ts index 17b2765..ee64f15 100644 --- a/src/cmdlets/help.ts +++ b/src/cmdlets/misc/help.ts @@ -1,8 +1,8 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { CmdLets } from '../commands/cmdlets.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { CmdLets } from '../../commands/cmdlets.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; export class HelpCmdLet extends CmdLet { name = 'help'; @@ -34,17 +34,19 @@ export class HelpCmdLet extends CmdLet { Array.from(groups.entries()) .sort(([k1, _v1], [k2, _v2]) => k1.localeCompare(k2)) .forEach(([k, v]) => { - Output.writeln(`${Output.bold(k)}:`); + Output.writeln(`${Output.bold(Output.blue(k))}:`); Array.from(v) .sort((c1, c2) => c1.name.localeCompare(c2.name)) .forEach(c => { - Output.writeln(`\t${c.name.padEnd(10, ' ')}: ${c.help}`); + Output.writeln( + `\t${Output.green(c.name.padEnd(10, ' '))}: ${Output.yellow(c.help)}`, + ); }); }); Output.writeln(); Output.writeln('For more information about a command use:'); - Output.writeln('\thelp '); + Output.writeln(`\t${Output.green('help')} ${Output.yellow('')}`); return Var.ZERO; } } diff --git a/src/cmdlets/history.ts b/src/cmdlets/misc/history.ts similarity index 80% rename from src/cmdlets/history.ts rename to src/cmdlets/misc/history.ts index ef67684..3354315 100644 --- a/src/cmdlets/history.ts +++ b/src/cmdlets/misc/history.ts @@ -1,8 +1,8 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { History } from '../terminal/history.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { History } from '../../terminal/history.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: h diff --git a/src/cmdlets/log.ts b/src/cmdlets/misc/log.ts similarity index 84% rename from src/cmdlets/log.ts rename to src/cmdlets/misc/log.ts index b604935..9464395 100644 --- a/src/cmdlets/log.ts +++ b/src/cmdlets/misc/log.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: log diff --git a/src/cmdlets/print.ts b/src/cmdlets/misc/print.ts similarity index 78% rename from src/cmdlets/print.ts rename to src/cmdlets/misc/print.ts index 42be11e..2231da4 100644 --- a/src/cmdlets/print.ts +++ b/src/cmdlets/misc/print.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: p p - print an expression diff --git a/src/cmdlets/sh.ts b/src/cmdlets/misc/sh.ts similarity index 95% rename from src/cmdlets/sh.ts rename to src/cmdlets/misc/sh.ts index d3f6b1b..24095a5 100644 --- a/src/cmdlets/sh.ts +++ b/src/cmdlets/misc/sh.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Input, InputInterceptRaw } from '../io/input.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Format } from '../misc/format.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Input, InputInterceptRaw } from '../../io/input.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Format } from '../../misc/format.js'; +import { Var } from '../../vars/var.js'; const INT_SIZE: number = 4; const PIPE_READ_OFFSET: number = 0; @@ -87,7 +87,7 @@ export class ShCmdLet extends CmdLet { throw new Error(`failed to getenv("SHELL"), errno: ${getenvErrno}`); const shellPath = shellVar.readUtf8String(); - Output.verboseWriteln(`SHELL: ${shellPath}`); + Output.debug(`SHELL: ${shellPath}`); if (shellPath === null) throw new Error('failed to read SHELL'); @@ -205,7 +205,7 @@ export class ShCmdLet extends CmdLet { if (this.fnClose === null || this.fnWaitPid === null) throw new Error('failed to find necessary native functions'); - Output.verboseWriteln(`child pid: ${childPid}`); + Output.debug(`child pid: ${childPid}`); const { value: closeChildRet, errno: closeChildErrno } = this.fnClose( toChildReadFd, ) as UnixSystemFunctionResult; @@ -233,7 +233,7 @@ export class ShCmdLet extends CmdLet { Input.setInterceptRaw(onRaw); - Output.verboseWriteln(`reading pid: ${childPid}`); + Output.debug(`reading pid: ${childPid}`); for ( let buf = await input.read(READ_SIZE); @@ -244,7 +244,7 @@ export class ShCmdLet extends CmdLet { Output.write(str); } - Output.verboseWriteln(`waiting pid: ${childPid}`); + Output.debug(`waiting pid: ${childPid}`); const pStatus = Memory.alloc(INT_SIZE); diff --git a/src/cmdlets/var.ts b/src/cmdlets/misc/var.ts similarity index 92% rename from src/cmdlets/var.ts rename to src/cmdlets/misc/var.ts index e3c6e72..fa79c5f 100644 --- a/src/cmdlets/var.ts +++ b/src/cmdlets/misc/var.ts @@ -1,8 +1,8 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Vars } from '../vars/vars.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Vars } from '../../vars/vars.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const DELETE_CHAR: string = '#'; diff --git a/src/cmdlets/ld.ts b/src/cmdlets/modules/ld.ts similarity index 82% rename from src/cmdlets/ld.ts rename to src/cmdlets/modules/ld.ts index 4a4b5f6..c92c049 100644 --- a/src/cmdlets/ld.ts +++ b/src/cmdlets/modules/ld.ts @@ -1,7 +1,7 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: ld diff --git a/src/cmdlets/mod.ts b/src/cmdlets/modules/mod.ts similarity index 92% rename from src/cmdlets/mod.ts rename to src/cmdlets/modules/mod.ts index 36938f9..b765fb7 100644 --- a/src/cmdlets/mod.ts +++ b/src/cmdlets/modules/mod.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Format } from '../misc/format.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; -import { Regex } from '../misc/regex.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Format } from '../../misc/format.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Regex } from '../../misc/regex.js'; const USAGE: string = `Usage: mod diff --git a/src/cmdlets/bt.ts b/src/cmdlets/thread/bt.ts similarity index 91% rename from src/cmdlets/bt.ts rename to src/cmdlets/thread/bt.ts index 69e10e3..0f94111 100644 --- a/src/cmdlets/bt.ts +++ b/src/cmdlets/thread/bt.ts @@ -1,9 +1,9 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Regs } from '../breakpoints/regs.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; -import { Format } from '../misc/format.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Regs } from '../../breakpoints/regs.js'; +import { Token } from '../../io/token.js'; +import { Var } from '../../vars/var.js'; +import { Format } from '../../misc/format.js'; const USAGE: string = `Usage: bt bt - show the backtrace for the current thread in a breakpoint diff --git a/src/cmdlets/thread.ts b/src/cmdlets/thread/thread.ts similarity index 92% rename from src/cmdlets/thread.ts rename to src/cmdlets/thread/thread.ts index 5d6c45a..a18d981 100644 --- a/src/cmdlets/thread.ts +++ b/src/cmdlets/thread/thread.ts @@ -1,8 +1,8 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Format } from '../misc/format.js'; -import { Var } from '../vars/var.js'; +import { CmdLet } from '../../commands/cmdlet.js'; +import { Output } from '../../io/output.js'; +import { Token } from '../../io/token.js'; +import { Format } from '../../misc/format.js'; +import { Var } from '../../vars/var.js'; const USAGE: string = `Usage: t diff --git a/src/cmdlets/verbose.ts b/src/cmdlets/verbose.ts deleted file mode 100644 index 1ad6110..0000000 --- a/src/cmdlets/verbose.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { CmdLet } from '../commands/cmdlet.js'; -import { Output } from '../io/output.js'; -import { Token } from '../io/token.js'; -import { Var } from '../vars/var.js'; - -const USAGE: string = `Usage: verbose -verbose - toggle verbose mode`; - -export class VerboseCmdLet extends CmdLet { - name = 'verbose'; - category = 'misc'; - help = 'toggle verbose mode'; - - public runSync(_tokens: Token[]): Var { - const verbose = !Output.getVerbose(); - if (verbose) { - Output.writeln(`verbose mode ${Output.green('enabled')}`); - } else { - Output.writeln(`verbose mode ${Output.red('disabled')}`); - } - Output.setVerbose(verbose); - - return Var.ZERO; - } - - public usage(): Var { - Output.writeln(USAGE); - return Var.ZERO; - } -} diff --git a/src/commands/cmdlets.ts b/src/commands/cmdlets.ts index 6548c1b..faa4915 100644 --- a/src/commands/cmdlets.ts +++ b/src/commands/cmdlets.ts @@ -1,16 +1,16 @@ import { CmdLet } from './cmdlet.js'; -import { DumpCmdLet } from '../cmdlets/dump.js'; -import { DumpStringCmdLet } from '../cmdlets/string.js'; -import { ExitCmdLet } from '../cmdlets/exit.js'; -import { SymCmdLet } from '../cmdlets/sym.js'; -import { ReadCmdLet } from '../cmdlets/read.js'; -import { WriteCmdLet } from '../cmdlets/write.js'; -import { AssemblyCmdLet } from '../cmdlets/assembly.js'; -import { VarCmdLet } from '../cmdlets/var.js'; -import { VmCmdLet } from '../cmdlets/vm.js'; -import { ModCmdLet } from '../cmdlets/mod.js'; -import { ThreadCmdLet } from '../cmdlets/thread.js'; -import { BtCmdLet } from '../cmdlets/bt.js'; +import { DumpCmdLet } from '../cmdlets/data/dump.js'; +import { DumpStringCmdLet } from '../cmdlets/data/string.js'; +import { ExitCmdLet } from '../cmdlets/misc/exit.js'; +import { SymCmdLet } from '../cmdlets/memory/sym.js'; +import { ReadCmdLet } from '../cmdlets/data/read.js'; +import { WriteCmdLet } from '../cmdlets/data/write.js'; +import { AssemblyCmdLet } from '../cmdlets/data/assembly.js'; +import { VarCmdLet } from '../cmdlets/misc/var.js'; +import { VmCmdLet } from '../cmdlets/memory/vm.js'; +import { ModCmdLet } from '../cmdlets/modules/mod.js'; +import { ThreadCmdLet } from '../cmdlets/thread/thread.js'; +import { BtCmdLet } from '../cmdlets/thread/bt.js'; import { AddCmdLet, SubCmdLet, @@ -23,10 +23,10 @@ import { ShrCmdLet, NotCmdLet, EndianCmdLet, -} from '../cmdlets/math.js'; -import { HistoryCmdLet } from '../cmdlets/history.js'; -import { HelpCmdLet } from '../cmdlets/help.js'; -import { CopyCmdLet } from '../cmdlets/copy.js'; +} from '../cmdlets/math/math.js'; +import { HistoryCmdLet } from '../cmdlets/misc/history.js'; +import { HelpCmdLet } from '../cmdlets/misc/help.js'; +import { CopyCmdLet } from '../cmdlets/data/copy.js'; import { FunctionEntryBpCmdLet, FunctionExitBpCmdLet, @@ -37,18 +37,18 @@ import { InsnBpCmdLet, ReadBpCmdLet, WriteBpCmdLet, -} from '../cmdlets/bp.js'; -import { RegCmdLet } from '../cmdlets/reg.js'; -import { LdCmdLet } from '../cmdlets/ld.js'; -import { FdCmdLet } from '../cmdlets/fd.js'; -import { JsCmdLet } from '../cmdlets/js.js'; -import { PrintCmdLet } from '../cmdlets/print.js'; -import { ShCmdLet } from '../cmdlets/sh.js'; -import { SrcCmdLet } from '../cmdlets/src.js'; -import { VerboseCmdLet } from '../cmdlets/verbose.js'; -import { GrepCmdLet } from '../cmdlets/grep.js'; -import { CatCmdLet } from '../cmdlets/cat.js'; -import { LogCmdLet } from '../cmdlets/log.js'; +} from '../cmdlets/breakpoints/bp.js'; +import { RegCmdLet } from '../cmdlets/breakpoints/reg.js'; +import { LdCmdLet } from '../cmdlets/modules/ld.js'; +import { FdCmdLet } from '../cmdlets/files/fd.js'; +import { JsCmdLet } from '../cmdlets/development/js.js'; +import { PrintCmdLet } from '../cmdlets/misc/print.js'; +import { ShCmdLet } from '../cmdlets/misc/sh.js'; +import { SrcCmdLet } from '../cmdlets/files/src.js'; +import { DebugCmdLet } from '../cmdlets/development/debug.js'; +import { GrepCmdLet } from '../cmdlets/misc/grep.js'; +import { CatCmdLet } from '../cmdlets/files/cat.js'; +import { LogCmdLet } from '../cmdlets/misc/log.js'; export class CmdLets { private static byName: Map = new Map(); @@ -95,7 +95,7 @@ export class CmdLets { this.registerCmdletType(ThreadCmdLet); this.registerCmdletType(UniqueBlockTraceBpCmdLet); this.registerCmdletType(VarCmdLet); - this.registerCmdletType(VerboseCmdLet); + this.registerCmdletType(DebugCmdLet); this.registerCmdletType(VmCmdLet); this.registerCmdletType(WriteCmdLet); this.registerCmdletType(WriteBpCmdLet); diff --git a/src/commands/command.ts b/src/commands/command.ts index b04c5a8..64f8923 100644 --- a/src/commands/command.ts +++ b/src/commands/command.ts @@ -57,7 +57,7 @@ export class Command { } args.forEach((param, index) => { - Output.verboseWriteln( + Output.debug( [ `\t${index}:`, Format.toHexString(param), diff --git a/src/entrypoint.ts b/src/entrypoint.ts index 019abe6..ba765de 100644 --- a/src/entrypoint.ts +++ b/src/entrypoint.ts @@ -12,20 +12,20 @@ import { Output } from './io/output.js'; import { MemoryBps } from './breakpoints/memory.js'; import { Regs } from './breakpoints/regs.js'; import { Format } from './misc/format.js'; -import { SrcCmdLet } from './cmdlets/src.js'; -import { BtCmdLet } from './cmdlets/bt.js'; +import { SrcCmdLet } from './cmdlets/files/src.js'; +import { BtCmdLet } from './cmdlets/thread/bt.js'; export const DEFAULT_SRC_PATH: string = `${Process.getHomeDir()}/.cshellrc`; type InitParams = { - verbose: boolean; + debug: boolean; }; rpc.exports = { init(stage: string, params: InitParams | null = null) { - const verbose = params?.verbose ?? false; - Output.setVerbose(verbose); - Output.verboseWriteln(`init - stage: ${stage}, verbose: ${verbose}`); + const debug = params?.debug ?? false; + Output.setDebugging(debug); + Output.debug(`init - stage: ${stage}, debug: ${debug}`); Output.banner(); Process.setExceptionHandler(exceptionHandler); SrcCmdLet.loadInitScript(DEFAULT_SRC_PATH); diff --git a/src/io/input.ts b/src/io/input.ts index 726d757..a3ad5a3 100644 --- a/src/io/input.ts +++ b/src/io/input.ts @@ -109,7 +109,7 @@ export class Input { } catch (error) { if (error instanceof Error) { Output.writeln(`ERROR: ${error.message}`); - Output.verboseWriteln(`${error.stack}`); + Output.debug(`${error.stack}`); } else { Output.writeln(`ERROR: Unknown error`); } diff --git a/src/io/output.ts b/src/io/output.ts index 104da83..f91a881 100644 --- a/src/io/output.ts +++ b/src/io/output.ts @@ -23,7 +23,7 @@ export class Output { '\\____|___/_| |_|\\___|_|_| ', ]; - private static verbose: boolean = false; + private static debugging: boolean = false; private static indent: boolean = false; private static filter: RegExp | null = null; private static log: File | null = null; @@ -55,7 +55,7 @@ export class Output { this.writeln(`\tName: ${this.green(first.name)}`); } - public static verboseWriteln(buffer: string | null) { + public static debug(buffer: string | null) { this.dowrite(`${buffer ?? ''}\n`, true, false); } @@ -72,7 +72,7 @@ export class Output { verbose: boolean, filter: boolean, ) { - if (verbose && !this.verbose) return; + if (verbose && !this.debugging) return; if (buffer === null) return; const filterExpression = (l: string) => @@ -117,12 +117,12 @@ export class Output { Output.writeln(`ret: ${Output.bold(Vars.getRet().toString())}`); } - public static getVerbose(): boolean { - return this.verbose; + public static getDebugging(): boolean { + return this.debugging; } - public static setVerbose(verbose: boolean) { - this.verbose = verbose; + public static setDebugging(debugging: boolean) { + this.debugging = debugging; } public static setIndent(indent: boolean) {