From ea00e67e80129a64691864497f08b52016080689 Mon Sep 17 00:00:00 2001 From: Jakob Friedl <71284620+jakobfriedl@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:46:53 +0200 Subject: [PATCH] Updated ps command output. --- src/modules/environment.nim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/environment.nim b/src/modules/environment.nim index 5420578..e22d7e4 100644 --- a/src/modules/environment.nim +++ b/src/modules/environment.nim @@ -58,7 +58,6 @@ when defined(agent): echo fmt" [>] Listing running processes." try: - var processes: seq[DWORD] = @[] var procMap = initTable[DWORD, ProcessInfo]() var output: string = "" @@ -98,6 +97,11 @@ when defined(agent): else: processes.add(pid) + # Add header row + let headers = @["PID", "PPID", "Process"] + output &= fmt"{headers[0]:<10}{headers[1]:<10}{headers[2]:<25}" & "\n" + output &= "-".repeat(len(headers[0])).alignLeft(10) & "-".repeat(len(headers[1])).alignLeft(10) & "-".repeat(len(headers[2])).alignLeft(25) & "\n" + # Format and print process proc printProcess(pid: DWORD, indentSpaces: int = 0) = if not procMap.contains(pid): @@ -106,9 +110,7 @@ when defined(agent): var process = procMap[pid] let indent = " ".repeat(indentSpaces) - let tree = (indent & fmt"[{process.pid}]").alignLeft(30) - - output &= fmt"{tree}{process.name:<25}" & "\n" + output &= fmt"{process.pid:<10}{process.ppid:<10}{indent}{process.name:<25}" & "\n" # Recursively print child processes with indentation process.children.sort() @@ -125,6 +127,7 @@ when defined(agent): except CatchableError as err: return createTaskResult(task, STATUS_FAILED, RESULT_STRING, err.msg.toBytes()) + import sugar proc executeEnv(config: AgentConfig, task: Task): TaskResult = echo fmt" [>] Displaying environment variables." @@ -132,7 +135,8 @@ when defined(agent): try: var envVars: string = "" for key, value in envPairs(): - envVars &= fmt"{key}: {value}" & '\n' + envVars &= fmt"{key}: {value}" & '\n' + return createTaskResult(task, STATUS_COMPLETED, RESULT_STRING, envVars.toBytes()) except CatchableError as err: @@ -143,8 +147,9 @@ when defined(agent): echo fmt" [>] Getting user information." try: - echo "whoami" + let message = "Not implemented" + return createTaskResult(task, STATUS_FAILED, RESULT_STRING, message.toBytes()) except CatchableError as err: return createTaskResult(task, STATUS_FAILED, RESULT_STRING, err.msg.toBytes()) \ No newline at end of file