PoshCode Archive  Artifact [201bf6f15c]

Artifact 201bf6f15c624da221d5ace705165b6780db107d5f0380f959a943382073d143:

  • File get-windows-product-key.ps1 — part of check-in [2859899687] at 2018-06-10 14:25:33 on branch trunk — in progress -buggy (user: karl prosser size: 1462)

# encoding: ascii
# api: powershell
# title: get windows product key
# description: in progress -buggy
# version: 0.1
# type: class
# author: karl prosser
# license: CC0
# x-poshcode-id: 867
# x-archived: 2016-08-26T03:12:37
# x-published: 2009-02-12T18:21:00
#
#
$Reg = [WMIClass]"root\default:StdRegProv"
$values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId").uvalue)
$lookup = [char[]]("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")

$keyStartIndex = [int]52;
$keyEndIndex = [int]($keyStartIndex + 15);
$decodeLength = [int]29
$decodeStringLength = [int]15
$decodedChars = new-object char[] $decodeLength 
$hexPid = new-object System.Collections.ArrayList
for ($i = $keyStartIndex; $i -le $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
for ( $i = $decodeLength - 1; $i -ge 0; $i--)
    {                
     if (($i + 1) % 6 -eq 0){$decodedChars[$i] = '-'}
     else
       {
        $digitMapIndex = [int]0
        for ($j = $decodeStringLength - 1; $j -ge 0; $j--)
        {
            $byteValue = [int](($digitMapIndex * [int]256) -bor [byte]$hexPid[$j]);
            $hexPid[$j] = [byte]($byteValue / [int]24);
            $digitMapIndex = $byteValue % 24;
            $decodedChars[$i] = $lookup[$digitMapIndex];
         }
        }
     }
 
$str = "";
$decodedChars | % { $str+=$_}
$str