Fix confirmed PowerShell history alias collision with a verified create-only console patch
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 15:00:03 +01:00
parent 900e19d471
commit e7dcad9c10
2 changed files with 106 additions and 4 deletions
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""Local CreateNew correction of the public recovery hash function alias clash.
The User's H/Get-History error occurred in the old pre-effect case/config guard.
Keep the same console case and untouched original files. No target/server call,
alias mutation or retry of an effect; the same case-absence guard still applies.
"""
import argparse
import os
from pathlib import Path
import re
import console_access_precision as previous
require, sha, save = previous.require, previous.sha, previous.save
CASE = '5c96d3d8-1657-40c8-a6ec-c00b63a98210'
OLD_SHA = '4977665fb092723998473f1c4be6685b1d93975176f8957bc3287d7e2f61cb69'
OLD_NAME = 'Recover-ExistingDevAccess.ps1'
NEW_NAME = 'Recover-ExistingDevAccess-HashFix.ps1'
NAME = 'Get-RmmRecoveryFileSha256'
STATE = previous.original.cb.EVIDENCE / 'dev-access-console-hash-correction'
def corrected(raw):
require(previous.original.pair.raw_sha(raw) == OLD_SHA, 'exact original reviewed 5c96 public script')
source = raw.decode('utf-8')
require(source.count('function H(') == 1 and NAME not in source, 'one original hash function and fresh unique name')
calls = re.findall(r'\(H\s', source)
require(len(calls) == source.count('(H ') and calls, 'all original H calls have the reviewed spelling')
result = source.replace('function H(', 'function ' + NAME + '(').replace('(H ', '(' + NAME + ' ')
require('function H(' not in result and not re.search(r'\(H\s', result), 'no alias-sensitive hash call remains')
require(result.replace('function ' + NAME + '(', 'function H(').replace('(' + NAME + ' ', '(H ') == source, 'only function/command spelling changed; all effects/pins/case bytes preserved')
return result.encode(), len(calls)
def build():
folder = previous.STATE / CASE
raw = (folder / OLD_NAME).read_bytes()
new, calls = corrected(raw)
STATE.mkdir(mode=0o700, parents=True, exist_ok=False)
previous.original.pair.write_bytes(STATE / NEW_NAME, new)
digest = previous.original.pair.raw_sha(new)
# Literal replacement, UTF8 without BOM, CreateNew, both independent hashes.
# No free script content, Remove-Alias, persistent policy or registry change.
patch = r'''$ErrorActionPreference='Stop'
$oldPath=Join-Path (Get-Location) 'Recover-ExistingDevAccess.ps1'
$newPath=Join-Path (Get-Location) 'Recover-ExistingDevAccess-HashFix.ps1'
if((Get-FileHash -LiteralPath $oldPath -Algorithm SHA256).Hash.ToLowerInvariant()-cne'@@OLD@@'){throw 'Falsche Originaldatei; nichts ausfuehren'}
if(Test-Path -LiteralPath $newPath){throw 'Korrekturdatei existiert bereits; nur lesend pruefen'}
$text=[Text.Encoding]::UTF8.GetString([IO.File]::ReadAllBytes($oldPath))
$text=$text.Replace('function H(','function Get-RmmRecoveryFileSha256(').Replace('(H ','(Get-RmmRecoveryFileSha256 ')
$bytes=(New-Object Text.UTF8Encoding($false)).GetBytes($text)
$out=[IO.File]::Open($newPath,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write,[IO.FileShare]::Read)
try{$out.Write($bytes,0,$bytes.Length);$out.Flush($true)}finally{$out.Dispose()}
if((Get-FileHash -LiteralPath $newPath -Algorithm SHA256).Hash.ToLowerInvariant()-cne'@@NEW@@'){throw 'Korrekturhash stimmt nicht; nichts ausfuehren'}
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File $newPath
'''.replace('@@OLD@@', OLD_SHA).replace('@@NEW@@', digest)
previous.original.pair.write_bytes(STATE / 'Create-VerifiedHashFix.ps1', patch.encode())
save(STATE / 'qualification.json', dict(source_sha256=sha(__file__), source_only=True, same_console_case=CASE, original_script_sha256=OLD_SHA, corrected_script_sha256=digest, renamed_call_count=calls, exact_inverse_spelling_transform=True, all_other_bytes_unchanged=True, original_script_and_zip_unchanged=True, case_absence_guard_retained=True, no_alias_mutation=True, no_server_or_vm_call=True, original_failure='Get-History/IdCannotConvert before New-Item/case or any effect'))
print('corrected_script_sha256=' + digest)
print('patch_sha256=' + sha(STATE / 'Create-VerifiedHashFix.ps1'))
print('renamed_hash_calls=' + str(calls))
print('patch=' + str((STATE / 'Create-VerifiedHashFix.ps1').resolve()))
def main():
os.umask(0o077)
parser = argparse.ArgumentParser(description=__doc__); parser.add_argument('phase', choices=('build',)); parser.parse_args(); build()
if __name__ == '__main__':
main()