<commit_before>﻿#  Copyright 2021 Google Inc. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

function Format-ObjectTable {
    Param(
        [parameter(Mandatory, Position = 0)]
        $InputObject,
        [switch]$HideTableHeaders,
        [switch]$NoTrailingLine
    )

    $output = $InputObject | Format-Table -HideTableHeaders:$HideTableHeaders | Out-String
    $output -Split "`r`n" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Write-Output
    if (!$NoTrailingLine) {
        Write-Output ""
    }
}

<#
.SYNOPSIS
Get API set entries
.DESCRIPTION
This cmdlet gets API set entries for the current system.
.PARAMETER Name
Specify an API set name to lookup.
.INPUTS
None
.OUTPUTS
NtApiDotNet.ApiSet.ApiSetEntry[]
.EXAMPLE
Get-NtApiSet
Get all API set entries.
.EXAMPLE
Get-NtApiSet -Name "api-ms-win-base-util-l1-1-0"
Get an API set by name.
#>
function Get-NtApiSet {
    [CmdletBinding(DefaultParameterSetName="All")]
    param (
        [parameter(Mandatory, Position = 0, ParameterSetName="FromName")]
        [string]$Name
    )

    if ($PSCmdlet.ParameterSetName -eq "FromName") {
        [NtApiDotNet.ApiSet.ApiSetNamespace]::Current.GetApiSet($Name)
    } else {
        [NtApiDotNet.ApiSet.ApiSetNamespace]::Current.Entries | Write-Output
    }
}

<#
.SYNOPSIS
Get the SDK name for an enumerated type or other type.
.DESCRIPTION
This cmdlet removes a package SID from the list of granted loopback exceptions.
.PARAMETER InputObject
The package SID to remove.
.INPUTS
object
.OUTPUTS
string
.EXAMPLE
Get-NtAccessMask 0x1 -AsSpecificAccess File | Get-NtSDKName
Get the SDK names for an access mask.
#>
function Get-NtSDKName { 
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        $InputObject
    )
    PROCESS {
        [NtApiDotNet.Utilities.Reflection.ReflectionUtils]::GetSDKName($InputObject)
    }
}

<#
.SYNOPSIS
Converts a text hexdump into bytes.
.DESCRIPTION
This cmdlet tries to convert a hexdump into the original bytes.
.PARAMETER Hex
The hex dump.
.INPUTS
string
.OUTPUTS
byte[]
.EXAMPLE
1, 2, 3, 4 | Format-HexDump | ConvertFrom-HexDump
Convert some bytes to a hex dump and back again.
#>
function ConvertFrom-HexDump { 
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [string]$Hex
    )

    PROCESS {
        [NtApiDotNet.Utilities.Text.HexDumpBuilder]::ParseHexDump($Hex)
    }
}

<#
.SYNOPSIS
Gets a certificate object.
.DESCRIPTION
This cmdlet gets a certificate object from a file.
.PARAMETER Path
Specify the path to the certificate or file.
.INPUTS
None
.OUTPUTS
System.Security.Cryptography.X509Certificates.X509Certificate2
#>
function Get-X509Certificate {
    param(
        [Parameter(Position = 0, Mandatory, ParameterSetName="FromPath")]
        [string]$Path
    )

    $Path = Resolve-Path -Path $Path
    if ($null -ne $Path) {
        [Security.Cryptography.X509Certificates.X509Certificate2]::new($Path)
    }
}<commit_msg>Added options to Get-X509Certificate.<commit_after>﻿#  Copyright 2021 Google Inc. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

function Format-ObjectTable {
    Param(
        [parameter(Mandatory, Position = 0)]
        $InputObject,
        [switch]$HideTableHeaders,
        [switch]$NoTrailingLine
    )

    $output = $InputObject | Format-Table -HideTableHeaders:$HideTableHeaders | Out-String
    $output -Split "`r`n" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Write-Output
    if (!$NoTrailingLine) {
        Write-Output ""
    }
}

<#
.SYNOPSIS
Get API set entries
.DESCRIPTION
This cmdlet gets API set entries for the current system.
.PARAMETER Name
Specify an API set name to lookup.
.INPUTS
None
.OUTPUTS
NtApiDotNet.ApiSet.ApiSetEntry[]
.EXAMPLE
Get-NtApiSet
Get all API set entries.
.EXAMPLE
Get-NtApiSet -Name "api-ms-win-base-util-l1-1-0"
Get an API set by name.
#>
function Get-NtApiSet {
    [CmdletBinding(DefaultParameterSetName="All")]
    param (
        [parameter(Mandatory, Position = 0, ParameterSetName="FromName")]
        [string]$Name
    )

    if ($PSCmdlet.ParameterSetName -eq "FromName") {
        [NtApiDotNet.ApiSet.ApiSetNamespace]::Current.GetApiSet($Name)
    } else {
        [NtApiDotNet.ApiSet.ApiSetNamespace]::Current.Entries | Write-Output
    }
}

<#
.SYNOPSIS
Get the SDK name for an enumerated type or other type.
.DESCRIPTION
This cmdlet removes a package SID from the list of granted loopback exceptions.
.PARAMETER InputObject
The package SID to remove.
.INPUTS
object
.OUTPUTS
string
.EXAMPLE
Get-NtAccessMask 0x1 -AsSpecificAccess File | Get-NtSDKName
Get the SDK names for an access mask.
#>
function Get-NtSDKName { 
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        $InputObject
    )
    PROCESS {
        [NtApiDotNet.Utilities.Reflection.ReflectionUtils]::GetSDKName($InputObject)
    }
}

<#
.SYNOPSIS
Converts a text hexdump into bytes.
.DESCRIPTION
This cmdlet tries to convert a hexdump into the original bytes.
.PARAMETER Hex
The hex dump.
.INPUTS
string
.OUTPUTS
byte[]
.EXAMPLE
1, 2, 3, 4 | Format-HexDump | ConvertFrom-HexDump
Convert some bytes to a hex dump and back again.
#>
function ConvertFrom-HexDump { 
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [string]$Hex
    )

    PROCESS {
        [NtApiDotNet.Utilities.Text.HexDumpBuilder]::ParseHexDump($Hex)
    }
}

<#
.SYNOPSIS
Gets a certificate object.
.DESCRIPTION
This cmdlet gets a certificate object from a path.
.PARAMETER Path
Specify the path to the certificate or file. Can only be a cert:\ drive path.
.PARAMETER Pin
Specify the PIN for the certificate's private key if needed.
.PARAMETER Byte
Specify the certificate as bytes.
.INPUTS
None
.OUTPUTS
System.Security.Cryptography.X509Certificates.X509Certificate2
#>
function Get-X509Certificate {
    [CmdletBinding(DefaultParameterSetName="FromPath")]
    param(
        [Parameter(Position = 0, Mandatory, ParameterSetName="FromPath")]
        [string]$Path,
        [Parameter(Position = 0, Mandatory, ParameterSetName="FromByte")]
        [byte[]]$Byte,
        [NtObjectManager.Utils.PasswordHolder]$Pin
    )

    switch($PSCmdlet.ParameterSetName) {
        "FromPath" {
            $Path = Resolve-Path -Path $Path
            if ($null -ne $Path) {
                $cert = Get-Item $Path
                if ($cert -is [Security.Cryptography.X509Certificates.X509Certificate]) {
                    [Security.Cryptography.X509Certificates.X509Certificate2]::new($cert)
                } elseif ($Pin -eq $null) {
                    [Security.Cryptography.X509Certificates.X509Certificate2]::new($Path)
                } else {
                    [Security.Cryptography.X509Certificates.X509Certificate2]::new($Path, $Pin.Password)
                }
            }
        }
        "FromByte" {
            if ($Pin -eq $null) {
                [Security.Cryptography.X509Certificates.X509Certificate2]::new($Byte)
            } else {
                [Security.Cryptography.X509Certificates.X509Certificate2]::new($Byte, $Pin.Password)
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09968469560999273, 'fraction_numerical': 0.014067426631093864, 'mean_word_length': 3.1841704718417048, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '111381', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2537, 'n_words': 736}