hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
can you tell me what this script is doing
- Assistant
Of course! Please provide the script you would like me to analyze, and I'll help explain what it does.
- User
param( [switch]$verbose )
The variables starting with $GLOBAL store values that should be applied to all XHCI controllers by default.
To override this default value on a per-controller basis, specify the DEV_XXXX hardware ID value for the XHCI controller along with its data
See the example below.
$globalInterval = 0x0
$globalHCSPARAMSOffset = 0x4
$globalRTSOFF = 0x18
$userDefinedData = @{
"DEV_8A4D" = @{
"INTERVAL" = 0xFFFF
"HCSPARAPS_OFFSET" = 0x8
"RTSOFF" = 0x12
}
"DEV_4AC6" = @{
"INTERVAL" = 0xFA00
}
}
In this example, the IMOD interval, HCSPARAMS and RTSOFF offsets for all controllers will be treated as 0x0, 0x4 and 0x18 respectively.
However, the IMOD interval, HCSPARAMS and RTSOFF offsets for the DEV_8A4D XHCI controller will override the global values and will be treated
as 0xFFFF, 0x8, 0x12 respectively. similarly with the DEV_4AC6 XHCI controller, only the IMOD interval will be overridden (0xFA00). The global
values will be used for each field that is not specified they are optional.
https://github.com/valleyofdoom/PC-Tuning/blob/main/bin/XHCI-IMOD-Interval.ps1
$globalInterval = 0x0
common offsets across XHCI vendors that will work with most XHCI controllers
globalRTSOFF = 0x18
$userDefinedData = @{}
specify the path to Rw.exe
$rwePath = "C:\Program Files\RW-Everything\Rw.exe"
function Dec-To-Hex(decimal) { hexValue = ($hexValue)" }
function Get-Value-From-Address(address) { # convert the hex value to string for RWE address = Dec-To-Hex -decimal ([uint64]$address)
$stdout = & $rwePath /Min /NoLogo /Stdout /Command="R32 $($address)" | Out-String $splitString = $stdout -split " " return [uint64]$splitString[-1]}
function Get-Device-Addresses() { resources = Get-WmiObject -Class Win32_PNPAllocatedResource -ComputerName LocalHost -Namespace root\CIMV2
foreach ($resource in $resources) { $deviceId = $resource.Dependent.Split("=")[1].Replace('"', '').Replace("\\", "\") $physicalAddress = $resource.Antecedent.Split("=")[1].Replace('"', '') if (-not $data.ContainsKey($deviceId) -and $deviceId -and $physicalAddress) { $data[$deviceId] = [uint64]$physicalAddress } } return $data}
function Is-Admin() { currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) }
function main() { if (-not (Is-Admin)) { Write-Host "error: administrator privileges required" return 1 }
if (-not (Test-Path $rwePath -PathType Leaf)) { Write-Host "error: $($rwePath) not exists, edit the script to change the path to Rw.exe" Write-Host "http://rweverything.com/download" return 1 } # CLI will not work if Rw is already open Stop-Process -Name "Rw" -ErrorAction SilentlyContinue # get physical address of each device present in the system $deviceMap = Get-Device-Addresses foreach ($xhciController in Get-WmiObject Win32_USBController) { $isDisabled = $xhciController.ConfigManagerErrorCode -eq 22 if ($isDisabled) { continue } $deviceId = $xhciController.DeviceID Write-Host "$($xhciController.Caption) - $($deviceId)" # skip if entry is null if (-not $deviceMap.Contains($deviceId)) { Write-Host "error: could not obtain base address`n" continue } $desiredInterval = $globalInterval $hcsparamsOffset = $globalHCSPARAMSOffset $rtsoff = $globalRTSOFF foreach ($hwid in $userDefinedData.Keys) { if ($deviceId -match $hwid) { $userDefinedController = $userDefinedData[$hwid] if ($userDefinedController.ContainsKey("INTERVAL")) { $desiredInterval = $userDefinedController["INTERVAL"] } if ($userDefinedController.ContainsKey("HCSPARAPS_OFFSET")) { $hcsparamsOffset = $userDefinedController["HCSPARAPS_OFFSET"] } if ($userDefinedController.ContainsKey("RTSOFF")) { $rtsoff = $userDefinedController["RTSOFF"] } } } $capabilityAddress = $deviceMap[$deviceId] $HCSPARAMSValue = Get-Value-From-Address -address ($capabilityAddress + $hcsparamsOffset) $HCSPARAMSBitmask = [Convert]::ToString($HCSPARAMSValue, 2) $maxIntrs = [Convert]::ToInt32($HCSPARAMSBitmask.Substring($HCSPARAMSBitmask.Length - 16, 8), 2) $RTSOFFValue = Get-Value-From-Address -address ($capabilityAddress + $rtsoff) $runtimeAddress = $capabilityAddress + $RTSOFFValue if ($verbose) { $formattedCapabilityAddress = Dec-To-Hex -decimal $capabilityAddress $formattedRTSOFFValue = Dec-To-Hex -decimal $RTSOFFValue Write-Host "capability_address = $($formattedCapabilityAddress)" Write-Host "HCSPARAMS_value = capability_address + hcsparams_offset = $($formattedCapabilityAddress) + $(Dec-To-Hex -decimal $hcsparamsOffset) = $(Dec-To-Hex -decimal $HCSPARAMSValue)" Write-Host "HCSPARAMS_bitmask = $($HCSPARAMSBitmask)" Write-Host "max_intrs = $($maxIntrs)" Write-Host "RTSOFF_value = capability_address + rtsoff = $($formattedCapabilityAddress) + $(Dec-To-Hex -decimal $rtsoff) = $($formattedRTSOFFValue)" Write-Host "runtime_address = capability_address + RTSOFF_value = $($formattedCapabilityAddress) + $($formattedRTSOFFValue) = $(Dec-To-Hex -decimal $runtimeAddress)" } for ($i = 0; $i -lt $maxIntrs; $i++) { # calculate address and convert address to hex string $interrupterAddress = Dec-To-Hex -decimal ([uint64]($runtimeAddress + 0x24 + (0x20 * $i))) if ($verbose) { Write-Host "`ninterrupter_address = runtime_address + 0x24 + (0x20 * index) = $(Dec-To-Hex -decimal $runtimeAddress) + 0x24 + (0x20 * $($i)) = $($interrupterAddress)" Write-Host "Write DWORD = $(Dec-To-Hex -decimal $desiredInterval)" } & $rwePath /Min /NoLogo /Stdout /Command="W32 $($interrupterAddress) $($desiredInterval)" | Write-Host } Write-Host # new line } return 0}
_exitCode = main Write-Host # new line exit _exitCode
- Assistant
This PowerShell script is designed to modify the IMOD interval and parameters of xHCI (Extensible Host Controller Interface) USB controllers on a Windows machine. Let's break down its components and functionality:
Parameters
param([switch]$verbose): Defines a parameter to run the script in verbose mode, which provides additional output for debugging or information purposes.
Global Variables
$globalInterval,$globalHCSPARAMSOffset, and$globalRTSOFF: These are default values for settings applied to all xHCI controllers unless overridden by specific hardware ID configurations.$userDefinedData: A hash table where users can specify custom settings for individual xHCI controllers identified by their hardware IDs.$rwePath: Specifies the path toRw.exe, a tool used to read/write hardware registers.
Functions
Dec-To-Hex($decimal): Converts a decimal value to a hexadecimal string.Get-Value-From-Address($address): Reads a DWORD value from a given hardware address usingRw.exe.Get-Device-Addresses(): Retrieves the physical memory addresses of devices from the WMI (Windows Management Instrumentation) service.Is-Admin(): Checks if the script is running with administrator privileges.
Main Functionality
- Administrator Check: Verifies that the script is running with the necessary privileges.
- Rw.exe Check: Ensures that
Rw.exeis available at the specified path. - Device Scanning: Obtains a list of xHCI USB controllers on the system.
- Default and User-Specific Settings: Applies global settings or overrides them with user-specified configurations if available.
- Register Reading/Writing: Calculates specific addresses where USB controller parameters are stored and writes new values to these addresses using
Rw.exe.
Process Flow
- Check for Admin Privileges: Exits if the script is not run as an administrator.
- Ensure Rw.exe is Available: Halts execution if
Rw.exeis not found. - Get Device Addresses: Collects the base addresses for the devices using WMI.
- Iterate Over xHCI Controllers: For each controller:
- Skips disabled controllers.
- Retrieves or calculates relevant properties like
HCSPARAMS,RTSOFF, andruntime_address. - Uses
Rw.exeto write the desired IMOD interval to each interrupter's address.
- Verbose Mode: If enabled, detailed computational steps and address values are printed to the console for each controller.
This script is used for tuning hardware parameters of xHCI controllers and is meant for users who understand the implications of directly manipulating hardware registers. It's essential to use such scripts carefully to avoid system instability.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →