This commit is contained in:
Gustave Monce
2024-11-17 20:45:46 +01:00
parent db91b1df5e
commit 62c9b11a27
16 changed files with 1207 additions and 24 deletions
+65
View File
@@ -0,0 +1,65 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
target: [win-x86,win-x64,win-arm64]
include:
- target: win-x86
platform: win
architecture: x86
- target: win-x64
platform: win
architecture: x64
- target: win-arm64
platform: win
architecture: arm64
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Build Utilities
shell: pwsh
run: |
msbuild /m:1 /t:restore,ufptool:publish /p:Platform=${{ matrix.architecture }} /p:RuntimeIdentifier=${{ matrix.platform }}-${{ matrix.architecture }} /p:PublishDir=${{ github.workspace }}/artifacts/${{ matrix.platform }}-${{ matrix.architecture }} /p:PublishSingleFile=true /p:PublishTrimmed=false /p:Configuration=Release /p:IncludeNativeLibrariesForSelfExtract=true UnifiedFlashingPlatform.sln
- name: Create PDB Output Directory
shell: pwsh
run: |
mkdir ${{ github.workspace }}\artifacts\${{ matrix.platform }}-${{ matrix.architecture }}-symbols
- name: Move PDBs
shell: pwsh
run: |
move ${{ github.workspace }}\artifacts\${{ matrix.platform }}-${{ matrix.architecture }}\*.pdb ${{ github.workspace }}\artifacts\${{ matrix.platform }}-${{ matrix.architecture }}-symbols
- name: Upload artifact (Binaries)
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.architecture }}-binaries
path: ${{ github.workspace }}/artifacts/${{ matrix.platform }}-${{ matrix.architecture }}
- name: Upload artifact (Symbols)
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.architecture }}-symbols
path: ${{ github.workspace }}/artifacts/${{ matrix.platform }}-${{ matrix.architecture }}-symbols
+217
View File
@@ -0,0 +1,217 @@
using Img2Ffu.Reader.Data;
using MadWizard.WinUSBNet;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class FlashDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
PrintFlashDeviceHelp();
Environment.Exit(0);
}
if (!args.ToList().Any(x => x.Equals("-Path", StringComparison.InvariantCultureIgnoreCase)))
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
PrintFlashDeviceHelp();
Environment.Exit(1);
}
string FFUPath = "";
bool Reboot = false;
string DevicePath = "";
bool VerifyWrite = false;
bool ForceSynchronousWrite = false;
bool SkipPlatformIDCheck = false;
bool SkipSignatureCheck = false;
bool SkipHash = false;
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-Path", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
PrintFlashDeviceHelp();
Environment.Exit(1);
}
i++;
FFUPath = args[i];
}
else if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
PrintFlashDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else if (arg.Equals("-Reboot", StringComparison.InvariantCultureIgnoreCase))
{
Reboot = true;
}
else if (arg.Equals("-VerifyWrite", StringComparison.InvariantCultureIgnoreCase))
{
VerifyWrite = true;
}
else if (arg.Equals("-ForceSynchronousWrite", StringComparison.InvariantCultureIgnoreCase))
{
ForceSynchronousWrite = true;
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
PrintFlashDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($" {i + 1}. {details[i].DevicePath} {details[i].DeviceDescription} ({details[i].Manufacturer})");
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
FlashFlags flashFlags = FlashFlags.Normal;
if (VerifyWrite)
{
flashFlags |= FlashFlags.VerifyWrite;
}
if (ForceSynchronousWrite)
{
flashFlags |= FlashFlags.ForceSynchronousWrite;
}
if (SkipPlatformIDCheck)
{
flashFlags |= FlashFlags.SkipPlatformIDCheck;
}
if (SkipSignatureCheck)
{
flashFlags |= FlashFlags.SkipSignatureCheck;
}
if (SkipHash)
{
flashFlags |= FlashFlags.SkipHash;
}
using FileStream FFUStream = new(FFUPath, FileMode.Open, FileAccess.Read, FileShare.Read);
SignedImage signedImage = new(FFUStream);
int chunkSize = signedImage.ChunkSize;
ulong totalChunkCount = (ulong)FFUStream.Length / (ulong)chunkSize;
FFUStream.Seek(0, SeekOrigin.Begin);
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
int previousPercentage = -1;
long length = FFUStream.Length;
Stopwatch stopwatch = new();
stopwatch.Start();
Console.WriteLine($"Flashing {DevicePath}");
ufp.FlashFFU(FFUStream, new ProgressUpdater(totalChunkCount, (int percentage, TimeSpan? eta) =>
{
string NewText = null;
if (percentage != null)
{
NewText = $"\rFlash: {percentage:d}% completed...";
}
if (eta != null)
{
if (NewText == null)
{
NewText = "";
}
else
{
NewText += " - ";
}
NewText += $"Estimated time remaining: {eta:h\\:mm\\:ss}";
}
if (NewText != null && previousPercentage != percentage)
{
previousPercentage = percentage;
Console.Write(NewText);
}
}), ResetAfterwards: Reboot, Options: (byte)flashFlags);
stopwatch.Stop();
TimeSpan elapsed = stopwatch.Elapsed;
double num = length / 1048576L / elapsed.TotalSeconds;
Console.WriteLine();
Console.WriteLine($"Device flashed successfully at {num:F3} MB/s in {elapsed.TotalSeconds:F3} seconds");
}
static void PrintFlashDeviceHelp()
{
Console.WriteLine("Flash a FFU to a device via USB or network");
Console.WriteLine();
Console.WriteLine(" UFPTool.exe FlashDevice [-Property] <[Value]> <[-Property] <[Value]>...>");
Console.WriteLine();
Console.WriteLine("Supported properties and their possible values:");
Console.WriteLine();
Console.WriteLine(" Path - Path to the FFU");
Console.WriteLine(" DevicePath - [Optional] Device path");
Console.WriteLine(" Reboot - [Optional] Reboot the device after it is flashed successfully");
Console.WriteLine(" VerifyWrite - [Optional] Verify FFU is written successfully");
Console.WriteLine(" ForceSynchronousWrite - [Optional] Force synchronous write to storage");
Console.WriteLine(" SkipPlatformIDCheck - [Optional] Skip platform ID check between device and FFU file");
Console.WriteLine(" SkipSignatureCheck - [Optional] Skip signature check between device and FFU file");
Console.WriteLine(" SkipHash - [Optional] Skip hash check of FFU file chunks");
Console.WriteLine();
Console.WriteLine("Examples:");
Console.WriteLine();
Console.WriteLine(" UFPTool.exe FlashDevice -Path d:\\flash.ffu");
}
}
}
+17
View File
@@ -0,0 +1,17 @@
using System;
namespace UFPTool
{
[Flags]
public enum FlashFlags : uint
{
Normal = 0U,
SkipPlatformIDCheck = 1U,
SkipSignatureCheck = 2U,
SkipHash = 4U,
VerifyWrite = 8U,
SkipWrite = 16U,
ForceSynchronousWrite = 32U,
FlashToRAM = 64U
}
}
+82
View File
@@ -0,0 +1,82 @@
using MadWizard.WinUSBNet;
using System;
using System.IO;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class GetDeviceLog
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintGetDeviceLogHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintGetDeviceLogHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintGetDeviceLogHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
string logContent = ufp.ReadLog()!;
// Example FileName: FlashLog_5_19_2023_12_33_20_PM.log
string fileName = $"FlashLog_{DateTime.Now.Month}_{DateTime.Now.Day}_{DateTime.Now.Year}_{DateTime.Now.Hour}_{DateTime.Now.Minute}_{DateTime.Now.Second}_{DateTime.Now.ToString("tt", System.Globalization.CultureInfo.InvariantCulture)}.log";
File.WriteAllText(fileName, logContent);
}
}
}
+78
View File
@@ -0,0 +1,78 @@
using MadWizard.WinUSBNet;
using System;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class GetUnlockId
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintGetUnlockIdHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintGetUnlockIdHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintGetUnlockIdHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
byte[] UnlockID = ufp.ReadUnlockID();
Console.WriteLine($"Unlock id: {BitConverter.ToString(UnlockID).Replace("-", string.Empty).ToUpper()}");
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using MadWizard.WinUSBNet;
using System;
namespace UFPTool
{
internal static class ListDevice
{
internal static void Execute(string[] args)
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Console.WriteLine($"Found {details.Length:d} device(s) in total.");
}
}
}
+76
View File
@@ -0,0 +1,76 @@
using MadWizard.WinUSBNet;
using System;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class MassStorageDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintMassStorageDeviceHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintMassStorageDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintMassStorageDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
ufp.MassStorage();
}
}
}
+111
View File
@@ -0,0 +1,111 @@
using System;
namespace UFPTool
{
internal class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Console tool for UFP devices");
Console.WriteLine("Copyright (c) The DuoWoA authors. All rights reserved");
Console.WriteLine();
ParseArgs(args);
PrintHelp();
}
static void ParseArgs(string[] args)
{
if (args.Length > 0)
{
switch (args[0].ToLower())
{
case "deleteuefivariable":
Console.WriteLine("Not yet implemented.");
Environment.Exit(1);
break;
case "flashdevice":
FlashDevice.Execute(args);
Environment.Exit(0);
break;
case "getdevicelog":
GetDeviceLog.Execute(args);
Environment.Exit(0);
break;
case "getuefivariable":
Console.WriteLine("Not yet implemented.");
Environment.Exit(1);
break;
case "getunlockid":
GetUnlockId.Execute(args);
Environment.Exit(0);
break;
case "listdevice":
ListDevice.Execute(args);
Environment.Exit(0);
break;
case "massstoragedevice":
MassStorageDevice.Execute(args);
Environment.Exit(0);
break;
case "queryunlocktokenfiles":
Console.WriteLine("Not yet implemented.");
Environment.Exit(1);
break;
case "rambootdevice":
RambootDevice.Execute(args);
Environment.Exit(0);
break;
case "rebootdevice":
RebootDevice.Execute(args);
Environment.Exit(0);
break;
case "relockdevice":
RelockDevice.Execute(args);
Environment.Exit(0);
break;
case "setuefivariable":
Console.WriteLine("Not yet implemented.");
Environment.Exit(1);
break;
case "shutdowndevice":
ShutdownDevice.Execute(args);
Environment.Exit(0);
break;
case "skipdevice":
SkipDevice.Execute(args);
Environment.Exit(0);
break;
case "unlockdevice":
Console.WriteLine("Not yet implemented.");
Environment.Exit(1);
break;
}
}
}
static void PrintHelp()
{
Console.WriteLine("Supported commands");
Console.WriteLine();
Console.WriteLine(" DeleteUefiVariable - Deletes UEFI variable on device");
Console.WriteLine(" FlashDevice - Flash a FFU to a device via USB or network");
Console.WriteLine(" GetDeviceLog - Get device flashing log");
Console.WriteLine(" GetUefiVariable - Get UEFI variable from device");
Console.WriteLine(" GetUnlockId - Gets unlock id from device");
Console.WriteLine(" ListDevice - List all flashable USB devices");
Console.WriteLine(" MassStorageDevice - Boot device into mass storage mode");
Console.WriteLine(" QueryUnlockTokenFiles - Queries unlock token files from device. Returns a bitmask of populate slots.");
Console.WriteLine(" RambootDevice - Flash a FFU onto device RAM, and subsequently boot it");
Console.WriteLine(" RebootDevice - Reboot device");
Console.WriteLine(" RelockDevice - Retail relocks the device");
Console.WriteLine(" SetUefiVariable - Sets UEFI variable on device");
Console.WriteLine(" ShutdownDevice - Shut down device connected via USB or network");
Console.WriteLine(" SkipDevice - Exit UFP app and return control to the caller");
Console.WriteLine(" UnlockDevice - Retail unlocks device");
Console.WriteLine();
Console.WriteLine(" ufptool.exe [Command] -?, for help on a specific command");
}
}
}
+184
View File
@@ -0,0 +1,184 @@
using Img2Ffu.Reader.Data;
using MadWizard.WinUSBNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class RambootDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintRambootDeviceHelp();
Environment.Exit(0);
}
if (!args.ToList().Any(x => x.Equals("-Path", StringComparison.InvariantCultureIgnoreCase)))
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintRambootDeviceHelp();
Environment.Exit(1);
}
string FFUPath = "";
string DevicePath = "";
bool VerifyWrite = false;
bool SkipPlatformIDCheck = false;
bool SkipSignatureCheck = false;
bool SkipHash = false;
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-Path", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintRambootDeviceHelp();
Environment.Exit(1);
}
i++;
FFUPath = args[i];
}
else if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintRambootDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else if (arg.Equals("-VerifyWrite", StringComparison.InvariantCultureIgnoreCase))
{
VerifyWrite = true;
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintRambootDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($" {i + 1}. {details[i].DevicePath} {details[i].DeviceDescription} ({details[i].Manufacturer})");
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
FlashFlags flashFlags = FlashFlags.FlashToRAM;
if (VerifyWrite)
{
flashFlags |= FlashFlags.VerifyWrite;
}
if (SkipPlatformIDCheck)
{
flashFlags |= FlashFlags.SkipPlatformIDCheck;
}
if (SkipSignatureCheck)
{
flashFlags |= FlashFlags.SkipSignatureCheck;
}
if (SkipHash)
{
flashFlags |= FlashFlags.SkipHash;
}
using FileStream FFUStream = new(FFUPath, FileMode.Open, FileAccess.Read, FileShare.Read);
SignedImage signedImage = new(FFUStream);
int chunkSize = signedImage.ChunkSize;
ulong totalChunkCount = (ulong)FFUStream.Length / (ulong)chunkSize;
FFUStream.Seek(0, SeekOrigin.Begin);
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
int previousPercentage = -1;
long length = FFUStream.Length;
Stopwatch stopwatch = new();
stopwatch.Start();
Console.WriteLine($"Flashing {DevicePath}");
ufp.FlashFFU(FFUStream, new ProgressUpdater(totalChunkCount, (int percentage, TimeSpan? eta) =>
{
string NewText = null;
if (percentage != null)
{
NewText = $"\rFlash: {percentage:d}% completed...";
}
if (eta != null)
{
if (NewText == null)
{
NewText = "";
}
else
{
NewText += " - ";
}
NewText += $"Estimated time remaining: {eta:h\\:mm\\:ss}";
}
if (NewText != null && previousPercentage != percentage)
{
previousPercentage = percentage;
Console.Write(NewText);
}
}), ResetAfterwards: false, Options: (byte)flashFlags);
stopwatch.Stop();
TimeSpan elapsed = stopwatch.Elapsed;
double num = length / 1048576L / elapsed.TotalSeconds;
Console.WriteLine();
Console.WriteLine($"Device flashed successfully at {num:F3} MB/s in {elapsed.TotalSeconds:F3} seconds");
Console.WriteLine("Device is RAM booting");
}
}
}
+76
View File
@@ -0,0 +1,76 @@
using MadWizard.WinUSBNet;
using System;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class RebootDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintRebootDeviceHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintRebootDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintRebootDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
ufp.RebootPhone();
}
}
}
+81
View File
@@ -0,0 +1,81 @@
using MadWizard.WinUSBNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class RelockDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintRelockDeviceHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintRelockDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintRelockDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
ufp.Relock();
Console.WriteLine("Device relocked successfully");
}
}
}
+76
View File
@@ -0,0 +1,76 @@
using MadWizard.WinUSBNet;
using System;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class ShutdownDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintShutdownDeviceHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintShutdownDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintShutdownDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
ufp.Shutdown();
}
}
}
+76
View File
@@ -0,0 +1,76 @@
using MadWizard.WinUSBNet;
using System;
using System.Linq;
using UnifiedFlashingPlatform;
namespace UFPTool
{
internal static class SkipDevice
{
internal static void Execute(string[] args)
{
if (args.Contains("-?"))
{
//PrintSkipDeviceHelp();
Environment.Exit(0);
}
string DevicePath = "";
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg.Equals("-DevicePath", StringComparison.InvariantCultureIgnoreCase))
{
if (i + 1 >= args.Length)
{
Console.WriteLine("Insufficient number of arguments");
Console.WriteLine();
//PrintSkipDeviceHelp();
Environment.Exit(1);
}
i++;
DevicePath = args[i];
}
else
{
Console.WriteLine($"Unknown argument: {arg}");
Console.WriteLine();
//PrintSkipDeviceHelp();
Environment.Exit(1);
}
}
if (string.IsNullOrEmpty(DevicePath))
{
USBDeviceInfo[] details = USBDevice.GetDevices("{9E3BD5F7-9690-4FCC-8810-3E2650CD6ECC}");
if (details.Length == 0)
{
Console.WriteLine("No UFP devices found");
Environment.Exit(1);
}
if (details.Length > 1)
{
Console.WriteLine("Multiple UFP devices found. Please specify the device path");
Console.WriteLine();
Console.WriteLine("Available devices:");
for (int i = 0; i < details.Length; i++)
{
Console.WriteLine($"[Device {i}]");
Console.WriteLine($"Device Path: {details[i].DevicePath}");
Console.WriteLine($"Can Flash: True");
Console.WriteLine();
}
Environment.Exit(1);
}
DevicePath = details[0].DevicePath;
}
using UnifiedFlashingPlatformTransport ufp = new(DevicePath);
ufp.ContinueBoot();
}
}
}
+17
View File
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Platforms>ARM32;ARM64;x86;x64</Platforms>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WinUSBNet" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UnifiedFlashingPlatform\UnifiedFlashingPlatform.csproj" />
</ItemGroup>
</Project>
+26 -22
View File
@@ -9,42 +9,36 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Img2Ffu.Library", "img2ffu\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Img2Ffu.Library.Compression.Windows", "img2ffu\Img2Ffu.Library.Compression.Windows\Img2Ffu.Library.Compression.Windows.csproj", "{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UFPTool", "UFPTool\UFPTool.csproj", "{30E9547D-D2C5-49C3-8D78-997305EAFA13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM32 = Debug|ARM32
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM32 = Release|ARM32
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM32.ActiveCfg = Debug|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM32.Build.0 = Debug|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM64.ActiveCfg = Debug|arm64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM64.Build.0 = Debug|arm64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM32.ActiveCfg = Debug|ARM32
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM32.Build.0 = Debug|ARM32
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM64.ActiveCfg = Debug|ARM64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|ARM64.Build.0 = Debug|ARM64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|x64.ActiveCfg = Debug|x64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|x64.Build.0 = Debug|x64
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|x86.ActiveCfg = Debug|x86
{E1F73032-3193-434B-806D-636D136B8B35}.Debug|x86.Build.0 = Debug|x86
{E1F73032-3193-434B-806D-636D136B8B35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Release|Any CPU.Build.0 = Release|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM32.ActiveCfg = Release|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM32.Build.0 = Release|Any CPU
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM64.ActiveCfg = Release|arm64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM64.Build.0 = Release|arm64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM32.ActiveCfg = Release|ARM32
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM32.Build.0 = Release|ARM32
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM64.ActiveCfg = Release|ARM64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|ARM64.Build.0 = Release|ARM64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|x64.ActiveCfg = Release|x64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|x64.Build.0 = Release|x64
{E1F73032-3193-434B-806D-636D136B8B35}.Release|x86.ActiveCfg = Release|x86
{E1F73032-3193-434B-806D-636D136B8B35}.Release|x86.Build.0 = Release|x86
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|Any CPU.ActiveCfg = Debug|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|Any CPU.Build.0 = Debug|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|ARM32.ActiveCfg = Debug|ARM32
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|ARM32.Build.0 = Debug|ARM32
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -53,8 +47,6 @@ Global
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|x64.Build.0 = Debug|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|x86.ActiveCfg = Debug|x86
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Debug|x86.Build.0 = Debug|x86
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|Any CPU.ActiveCfg = Release|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|Any CPU.Build.0 = Release|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|ARM32.ActiveCfg = Release|ARM32
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|ARM32.Build.0 = Release|ARM32
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -63,8 +55,6 @@ Global
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|x64.Build.0 = Release|x64
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|x86.ActiveCfg = Release|x86
{65F75BC0-735F-4CA1-8B33-C03FEECFA322}.Release|x86.Build.0 = Release|x86
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|Any CPU.ActiveCfg = Debug|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|Any CPU.Build.0 = Debug|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|ARM32.ActiveCfg = Debug|ARM32
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|ARM32.Build.0 = Debug|ARM32
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -73,8 +63,6 @@ Global
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|x64.Build.0 = Debug|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|x86.ActiveCfg = Debug|x86
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Debug|x86.Build.0 = Debug|x86
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|Any CPU.ActiveCfg = Release|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|Any CPU.Build.0 = Release|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|ARM32.ActiveCfg = Release|ARM32
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|ARM32.Build.0 = Release|ARM32
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|ARM64.ActiveCfg = Release|ARM64
@@ -83,6 +71,22 @@ Global
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|x64.Build.0 = Release|x64
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|x86.ActiveCfg = Release|x86
{AB5868C5-4BAC-4CE8-A927-7385D9D8776D}.Release|x86.Build.0 = Release|x86
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|ARM32.ActiveCfg = Debug|ARM32
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|ARM32.Build.0 = Debug|ARM32
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|ARM64.ActiveCfg = Debug|ARM64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|ARM64.Build.0 = Debug|ARM64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|x64.ActiveCfg = Debug|x64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|x64.Build.0 = Debug|x64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|x86.ActiveCfg = Debug|x86
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Debug|x86.Build.0 = Debug|x86
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|ARM32.ActiveCfg = Release|ARM32
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|ARM32.Build.0 = Release|ARM32
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|ARM64.ActiveCfg = Release|ARM64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|ARM64.Build.0 = Release|ARM64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|x64.ActiveCfg = Release|x64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|x64.Build.0 = Release|x64
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|x86.ActiveCfg = Release|x86
{30E9547D-D2C5-49C3-8D78-997305EAFA13}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -473,9 +473,9 @@ namespace UnifiedFlashingPlatform
// Reads the device properties from the UEFI Variable "UnlockID"
// in the g_guidOfflineDUIdEfiNamespace namespace and returns it as a string.
//
public string? ReadUnlockID()
public byte[] ReadUnlockID()
{
return ReadStringParam("UKID");
return ReadParam("UKID");
}
public string? ReadUnlockTokenFiles()