Skip to content

[Feature Request] Option to save Checksums to Alternate Data Stream #266

@planetrocky

Description

@planetrocky

Feature Request: Option to save Checksums to Alternate Data Stream

  1. Option to write the computer checksum to ADS streams
    • example of ADS names that I've been using: hash.sha256, hash.crc32, hash.sha512
  2. Option to verify checksum from ADS (if it exists)

I have this is my PowerShell profile, and have been using on the command-line - but a GUI version would be great (It's on my TODO list as a project, but it's a long TODO list)

I actually use a longer script

function add_checksums_to_ads {

    param (
        [Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
        [string[]]$FilePaths
    )

    $files = Get-ChildItem -File -Recurse -Attributes !System # !System+!ReadOnly

    foreach ($file in $files) {
        $ads = "$($file.FullName):hash.sha256"

        if (Test-Path -LiteralPath $ads) {
            $current_checksum = Get-Content -Path "$($file.FullName)" -Stream "hash.sha256"
            $checksum = Get-FileHash -Path "$($file.FullName)" -Algorithm SHA256 | Select-Object -ExpandProperty Hash
            Write-Host -NoNewline "$($file.Name) already has a 'hash.sha256'"
            if ($checksum -eq $current_checksum) {
                Write-Host " ✅�[32;1mChecksums match�[0m"
                
            } else {
                Write-Host " ❌�[31;1mCurrent checksum and computer don't match!!!�[0m"
            }

        } else {
            Write-Host -NoNewline "$($file.Name) generating 'hash.sha256'"
            $lastWriteTime = $file.LastWriteTime
            # SHA256, SHA384, SHA512
            $checksum = Get-FileHash -Path "$($file.FullName)" -Algorithm SHA256 | Select-Object -ExpandProperty Hash
            try {
                #Write-Host "$checksum"
                Set-Content -Force -Path "$($file.FullName)" -Stream "hash.sha256" -Value $checksum
                Write-Host " $checksum"
            } catch {
                Write-Host " Failed to write ADS 'hash.sha256' to $file [$_]"
            }
            try {
                #Write-Host "Reseting LastWriteTime"
                $file.LastWriteTime = $lastWriteTime
            } catch {
                Write_host "Failed to reset LastWriteTime on $file"
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions