Hacker News new | ask | show | jobs
by billforsternz 4710 days ago
Damn, was hoping this was an article about how to encode Windows executables into text.
1 comments

Ask and ye shall receive (in powershell form):

    $fName = "last.exe"

    $fContent = get-content $fName

    $fContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fContent)

    $fContentEncoded = [System.Convert]::ToBase64String($fContentBytes)

    $fContentEncoded set-content ($fName + ".text")
Now you can at least say that all your .exes live in base64-encoded .texts.
I guess that should rather be

    Get-PSDrive -PSProvider Filesystem |
      Get-ChildItem -Recurse -Path { $_.Root } -Filter *.exe |
      ForEach-Object {
        $bytes = Get-Content $_ -Encoding Byte -ReadCount 0
        $text = [Convert]::ToBase64String($bytes)
        $text | Set-Content ($_.FullName + '.text')
      }
Reading the files as UTF-8 and converting them back into a byte array isn't such a great idea, I think ;-)
Thanks, upvoted. (But, also, note that I wasn't really hoping this was an article about how to store my Windows .exes as text :-)