From 7fe20df34fb6180371e1ef611ed3ba2bb4c05649 Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Tue, 17 Nov 2026 19:59:08 +0100 Subject: [PATCH] Render native PowerShell CP850 output with an explicit decoding choice --- .../powershell-output-encoding-20261117.json | 16 ++++++++ docs/windows-update-dev-window.md | 2 +- web/src/console-output.test.tsx | 29 ++++++++++++++ web/src/console-output.tsx | 40 ++++++++++++++----- 4 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 docs/evidence/powershell-output-encoding-20261117.json diff --git a/docs/evidence/powershell-output-encoding-20261117.json b/docs/evidence/powershell-output-encoding-20261117.json new file mode 100644 index 0000000..2a984b0 --- /dev/null +++ b/docs/evidence/powershell-output-encoding-20261117.json @@ -0,0 +1,16 @@ +{ + "date": "2026-11-17", + "environment": "development", + "job": "6d5f9437-8285-4158-bdb0-7a73493f86d2", + "attempt": "8d653eaf-0be0-4a44-909c-572217d320c7", + "operation": "10380fe3-b9bd-4bad-b5c9-e144448c5f50", + "verified_at": "2026-11-17T18:58:18.398Z", + "displayed_stdout": "{\"id\":\"20a25326-d78f-4a69-bc81-fa8430093374\",\"title\":\"Windows-Tool zum Entfernen bösartiger Software x64 - v5.147 (KB890830)\",\"status\":2,\"hresult\":0,\"reboot_required\":false}\\u000d\n{\"reboot_required\":false,\"found\":1}\\u000d\n", + "cp850_verified": true, + "utf8_switch_verified": true, + "poll_preserves_selection": true, + "raw_download_bytes": 212, + "raw_download_sha256": "3f8fac19ab7631108d738b68a47e2a4f25e7064cd838ec3212524aacb2d3adc5", + "checks": "Six targeted console-output tests and production WebUI build passed; actual stored job result verified over TLS in browser", + "source_encoding": "CP850 is an explicitly labeled display choice for native PowerShell bytes, not a new source encoding assertion." +} diff --git a/docs/windows-update-dev-window.md b/docs/windows-update-dev-window.md index 9690487..f3f1715 100644 --- a/docs/windows-update-dev-window.md +++ b/docs/windows-update-dev-window.md @@ -45,4 +45,4 @@ python3 tests/windows_update_early_abort.py --execute Auch nach einem abgebrochenen Test gibt der Befehl die Fall-ID aus, mit der sich der Rückbau fortsetzen lässt. -Die echte Installation von KB890830 v5.147 und der zugehörige administrative Wartungsneustart sind [nativ belegt](evidence/windows-update-installation-20261117.json). Dabei wurde der zuvor gestoppte Windows-Zeitdienst aktiviert und eine gemessene Zeitabweichung korrigiert. Native CP850-Ausgabebytes bleiben unverändert erhalten. Die UTF-8-Textansicht zeigt bei einem Umlaut weiterhin ein Ersatzzeichen. +Die echte Installation von KB890830 v5.147 und der zugehörige administrative Wartungsneustart sind [nativ belegt](evidence/windows-update-installation-20261117.json). Dabei wurde der zuvor gestoppte Windows-Zeitdienst aktiviert und eine gemessene Zeitabweichung korrigiert. Native CP850-Ausgabebytes bleiben unverändert erhalten. Die WebUI bietet für native PowerShell-Ausgabe eine CP850-Textansicht mit expliziter Dekodierungswahl. Der Umlaut im gespeicherten Updateergebnis und der bytegleiche Download wurden im Browser geprüft. [Darstellungsnachweis](evidence/powershell-output-encoding-20261117.json) diff --git a/web/src/console-output.test.tsx b/web/src/console-output.test.tsx index 6f74ac1..f4288b3 100644 --- a/web/src/console-output.test.tsx +++ b/web/src/console-output.test.tsx @@ -37,3 +37,32 @@ it('shows unknown restart state for an incomplete Windows Update summary', () => expect(rendered(windowsUpdateScriptHash)).toContain('Neustartbedarf: unknown'); expect(rendered('ordinary script')).toContain('Neustartbedarf: false'); }); + + +it('decodes native PowerShell CP850 umlauts while preserving raw bytes and control escapes', () => { + const raw = outputBytes([132, 148, 129, 142, 153, 154, 225, 13, 10, 27]); + const original = Array.from(raw); + expect(outputText(raw, 'powershell').text).toBe('äöüÄÖÜß\\u000d\n\\u001b'); + expect(outputText(raw, 'powershell').encoding).toContain('Quellcodepage nicht separat belegt'); + expect(outputText(raw, 'utf-8').text).toContain('�'); + expect(Array.from(raw)).toEqual(original); + expect(outputText(outputBytes([156, 255]), 'cp850').text).toBe('£ '); +}); + +it('keeps valid UTF-8 PowerShell output and generic invalid UTF-8 on their existing paths', () => { + const raw = new TextEncoder().encode('Grüße äöüÄÖÜß'); + expect(outputText(raw, 'powershell').text).toBe('Grüße äöüÄÖÜß'); + expect(outputText(outputBytes([148])).text).toBe('�'); +}); + +it('selects the native PowerShell text view only from matching result evidence', () => { + const result = { stdout: [98, 148, 115, 97, 114, 116, 105, 103], stderr: [], evidence: {interpreter:'powershell',output_encoding:'raw_native_bytes'} }; + const before = JSON.stringify(result); + const html = renderToStaticMarkup(); + expect(html).toContain('bösartig'); + expect(html).toContain('stdout Textdekodierung'); + expect(html).toContain('Windows OEM 850'); + expect(JSON.stringify(result)).toBe(before); + const other = renderToStaticMarkup(); + expect(other).not.toContain('bösartig'); +}); diff --git a/web/src/console-output.tsx b/web/src/console-output.tsx index 92fd0b2..250bba0 100644 --- a/web/src/console-output.tsx +++ b/web/src/console-output.tsx @@ -1,16 +1,32 @@ +import { useState } from 'react'; import { windowsUpdateScriptHash } from './script-console'; import { record, RecordValue, stringField } from './api'; -/** The wire format carries bytes, not an encoding declaration. Never guess a - * Windows code page or interpret output as HTML, terminal escapes or actions. */ +/** Preserve wire bytes. Text decoding is a labeled display choice, never HTML or terminal interpretation. */ export function outputBytes(value: unknown): Uint8Array { if (!Array.isArray(value) || value.length > 262144 || value.some(byte => !Number.isInteger(byte) || byte < 0 || byte > 255)) throw new Error('Ungültige oder zu große Ausgabebytes'); return new Uint8Array(value); } -export function outputText(raw: Uint8Array): { text: string; encoding: string } { +type OutputEncoding = 'utf-8' | 'cp850' | 'powershell'; +// Unicode mapping of bytes 0x80–0xff in IBM code page 850. ASCII bytes are unchanged. +const cp850 = "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø×ƒáíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´­±‗¾¶§÷¸°¨·¹³²■ "; +function cp850Text(raw: Uint8Array): string { + return Array.from(raw, byte => byte < 128 ? String.fromCharCode(byte) : cp850[byte - 128]).join(''); +} +export function outputText(raw: Uint8Array, selected: OutputEncoding = 'utf-8'): { text: string; encoding: string } { let decoded: string, encoding: string; - try { decoded = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(raw); encoding = 'UTF-8 lesbar; Quellencoding nicht separat belegt'; } - catch { decoded = new TextDecoder('utf-8', { ignoreBOM: true }).decode(raw); encoding = 'Encoding unbekannt / kein gültiges UTF-8: Ersatzzeichen nur in der Textansicht'; } + if (selected === 'cp850') { + decoded = cp850Text(raw); encoding = 'Textdekodierung Windows OEM 850 (CP850)'; + } else { + try { decoded = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(raw); encoding = 'UTF-8 lesbar; Quellencoding nicht separat belegt'; } + catch { + if (selected === 'powershell') { + decoded = cp850Text(raw); encoding = 'Textdekodierung Windows OEM 850 (CP850), automatisch für native PowerShell-Ausgabe gewählt; Quellcodepage nicht separat belegt'; + } else { + decoded = new TextDecoder('utf-8', { ignoreBOM: true }).decode(raw); encoding = 'Encoding unbekannt / kein gültiges UTF-8: Ersatzzeichen nur in der Textansicht'; + } + } + } // Make terminal/control and bidi characters visible. In particular CR cannot // visually overwrite an earlier line; CRLF remains recognizable as such. return { text: decoded.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, @@ -22,10 +38,15 @@ function download(raw: Uint8Array, name: 'stdout' | 'stderr') { link.href = url; link.download = `${name}.bin`; link.click(); setTimeout(() => URL.revokeObjectURL(url), 1000); } -function OutputChannel({ value, name }: { value: unknown; name: 'stdout' | 'stderr' }) { +function OutputChannel({ value, name, nativePowerShell }: { value: unknown; name: 'stdout' | 'stderr'; nativePowerShell: boolean }) { + const [selected, setSelected] = useState<'auto' | 'utf-8' | 'cp850'>('auto'); try { - const raw = outputBytes(value), view = outputText(raw); + const raw = outputBytes(value), view = outputText(raw, selected === 'auto' ? nativePowerShell ? 'powershell' : 'utf-8' : selected); return

{name} · {raw.length} gespeicherte Bytes

{view.encoding}. Steuerzeichen werden sichtbar als \\uXXXX dargestellt; Rohbytes bleiben erhalten.

+
{raw.length ? view.text : '(leere Ausgabe)'}
{name} Originalbytes (dezimal)
{JSON.stringify(Array.from(raw))}
@@ -40,18 +61,19 @@ export function ConsoleOutput({ job }: { job: RecordValue }) { {state === 'unknown' &&

Wirkung oder Ergebnis unklar. Keine automatische Wiederholung; ein neuer Versuch benötigt Abgleich und einen neuen genehmigten Plan.

} {job.cancel_requested === true &&

Abbruch angefordert; dies bestätigt weder Prozessende noch Rollback.

} {job.pending_reason != null &&

Wartegrund: {String(job.pending_reason)}

} - {job.result == null ?

Noch kein gespeichertes Ergebnis. Fehlende Ausgabe ist kein Erfolgsnachweis.

: } + {job.result == null ?

Noch kein gespeichertes Ergebnis. Fehlende Ausgabe ist kein Erfolgsnachweis.

: } ; } function Result({ value }: { value: unknown }) { try { const result = record(value, 'Jobergebnis'); const evidence = result.evidence && typeof result.evidence === 'object' && !Array.isArray(result.evidence) ? record(result.evidence) : {}; + const nativePowerShell = evidence.interpreter === 'powershell' && evidence.output_encoding === 'raw_native_bytes'; const reboot = evidence.script_sha256 === windowsUpdateScriptHash && Object.hasOwn(evidence, 'windows_update_reboot_required') ? evidence.windows_update_reboot_required : result.reboot_required; return <>

Exitcode: {typeof result.exit_code === 'number' && Number.isInteger(result.exit_code) ? result.exit_code : 'unknown / nicht gemeldet'} · Fehlercode: {typeof result.error_code === 'string' && result.error_code ? result.error_code : 'nicht gemeldet'}

Ausgabe begrenzt: {typeof result.output_truncated === 'boolean' ? String(result.output_truncated) : 'unknown'}. {result.output_truncated === true ? 'Die gespeicherten Bytes sind nur ein Ausschnitt.' : result.output_truncated !== false ? 'Vollständigkeit ist nicht bestätigt.' : 'Keine Trunkierung gemeldet.'}

Neustartbedarf: {typeof reboot === 'boolean' ? String(reboot) : 'unknown'}. Ein Exitcode 0 bestätigt Prozessabschluss; fachliche Nachbedingungen stehen im vollständigen Ergebnis.

Ausgabe ist nicht vertrauenswürdiger Text vom Zielgerät. Sie erteilt keine Genehmigung und wird nicht als Anweisung ausgeführt.

- ; + ; } catch { return

Ergebnisformat unbekannt; vollständige Originaldaten stehen darunter.

; } }