Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify product id #10

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions generate_and_apply_WinUSB.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
.PARAMETER VenderId
The vender ID provided by the user.

.PARAMETER ProductId
The product ID provided by the user.

.EXAMPLE
.\generate_and_apply_WinUSB.ps1 <vendor id>
Prompts the user for a vender ID and displays the entered vender ID.
Expand All @@ -19,11 +22,13 @@

param (
[Parameter(Mandatory=$true)]
[string]$VenderId
[string]$VenderId,
[string]$ProductId
)

# Vender ID of the target USB device
Write-Host "You entered vender ID: $VenderId"
Write-Host "You entered product ID: $ProductId"

# Working Directory
$installPath = "$env:TEMP"
Expand Down Expand Up @@ -71,7 +76,7 @@ if ($Url.EndsWith("zip")) {
throw "Target archive does not exit."
}

# Generate WinUSB Installer
# Generate and apply WinUSB Installer
if (Test-Path $tempExtractionPath) {

# Run Winusb installer
Expand All @@ -83,7 +88,7 @@ if (Test-Path $tempExtractionPath) {
New-item -Path "$TempDir" -ItemType Directory
$winUSBOptions = @{
FilePath = "${tempExtractionPath}/${installerName}-${version}/winusb_installer.exe"
ArgumentList = "$VenderId"
ArgumentList = "$VenderId $ProductId"
WorkingDirectory = "$TempDir"
Wait = $true
Verb = "RunAs" # This attempts to run the process as an administrator
Expand All @@ -96,31 +101,6 @@ if (Test-Path $tempExtractionPath) {
throw "Failed to execute WinUSB Installer Generator."
}

# Run Driver installer
Write-Verbose "Start Driver installer"

$infPath = "$TempDir/target_device.inf"
if (-not (Test-Path -Path $infPath -PathType Leaf) ){
Write-Error "$infPath does not exist."
}
else{
$pnputilOptions = @{
FilePath = "PNPUtil"
ArgumentList = "-i -a ./target_device.inf"
WorkingDirectory = "$TempDir"
Wait = $true
Verb = "RunAs" # This attempts to run the process as an administrator
}
try {
# Start Pnputil process
Start-Process @pnputilOptions
Write-Host "Sucessfully installed winUSB driver"
}
catch {
Write-Error "An error occurred while running pnputil: $_"
}
}

# delete temp files

Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"Remove-Item -Path '$tempExtractionPath' -Recurse -Force -Confirm:`$false`""
Expand Down
31 changes: 20 additions & 11 deletions src/winusb_installer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdio.h>
#include<stdbool.h>
#include <stdbool.h>
#include <libwdi.h>

#include <stdio.h>
Expand All @@ -17,23 +17,33 @@ int main(int argc, char* argv[]){

bool find_target_device = false;
int vendor_id = 0;
int product_id = 0;

if (argc != 2){
usage("missing argument for parameter");
if (argc != 3){
printf( "missing argument for parameter" );
return 1;
}

vendor_id = (int)strtol(argv[1], NULL, 16);
printf("Targeted vernder id is %s\n", argv[1]);
product_id = (int)strtol(argv[2], NULL, 16);
printf("Targeted vernder id is %s and product id is %s\n", argv[1], argv[2]);

// list all
// https://github.com/pbatard/libwdi/wiki/Usage#struct-wdi_options_create_list
struct wdi_options_create_list option = {TRUE, TRUE, TRUE};

if (wdi_create_list(&list, &option) == WDI_SUCCESS) {
for (device = list; device != NULL; device = device->next) {
printf("Installing driver for USB device: \"%s\" (%04X:%04X)",
device->desc, device->vid, device->pid);
if (device->vid == vendor_id){
printf(" <-- these are the target\n");
if (device->vid == vendor_id && device->pid == product_id){
printf("Installing driver on USB device: \"%s\" (%04X:%04X)",
device->desc, device->vid, device->pid );
if (device->is_composite){
printf("COMPOSITE %u\n", device->mi);
}else{
printf("\n");
}

// if (device->vid == vendor_id && device->pid == product_id){

struct wdi_options_prepare_driver driver_option ={
WDI_WINUSB,
Expand All @@ -46,15 +56,14 @@ int main(int argc, char* argv[]){
printf("********************************************************\n");
wdi_install_driver(device, ".", "target_device.inf", NULL);
}
return 0;
}else{
printf("\n");
// printf("\n");
}
}

wdi_destroy_list(list);
}else{
printf("Faile\n");
printf("Failed\n");
}
return 0;
}
Loading