Skip to content

Commit

Permalink
⚒️ Driver implementation & Bug fixes
Browse files Browse the repository at this point in the history
fixes issue #11
  • Loading branch information
valnoxy committed Mar 12, 2023
1 parent 9a81b51 commit 419c352
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 84 deletions.
48 changes: 41 additions & 7 deletions deploya/deployaCore/Action/Apply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.ComponentModel;
using System.IO;
using System.Linq;
using deployaCore.Common;
using static System.Collections.Specialized.BitVector32;

namespace deployaCore.Action
{
Expand All @@ -30,23 +32,55 @@ internal static void WriteToDisk(string imagePath, int index, string drive, Back
}
}

internal static void AddDriverToDisk(string windowsPath, List<string> driverPath, BackgroundWorker worker = null)
internal static void AddDriverToDisk(string windowsDrive, List<string> driverPath, BackgroundWorker worker = null)
{
Bw = worker;

foreach (var driver in driverPath.Where(File.Exists))
try
{
using var session = DismApi.OpenOfflineSession(windowsPath);
Output.WriteLine("[Driver] Entering Injection process ...");
Output.WriteLine("[Driver] Initialize Dism API ...");
DismApi.Initialize(DismLogLevel.LogErrors);
Output.WriteLine("[Driver] Open offline session ...");

DismSession session = null;
try
{
DismApi.AddDriver(session, driver, true);
if (Bw != null) Bw.ReportProgress(202, ""); // Update progress text
if (Bw != null) Bw.ReportProgress(207, "Initialize"); // Update progress text
session = DismApi.OpenOfflineSession(windowsDrive);
Output.WriteLine("[Driver] Session opened. ");
}
catch
catch (Exception ex)
{
Output.WriteLine("[Driver] Failed to open offline session: " + ex.Message);
Output.WriteLine("[Driver] Shutdown Dism API ...");
DismApi.Shutdown();
return;
}

var currentDriverCount = 0;
foreach (var driver in driverPath.Where(File.Exists))
{
try
{
currentDriverCount++;
Output.WriteLine($"[Driver] Current Driver ({currentDriverCount}): {driver}");
if (Bw != null) Bw.ReportProgress(207, currentDriverCount); // Update progress text
DismApi.AddDriver(session, driver, true);
}
catch (Exception ex)
{
Output.WriteLine("[Driver] Failed to inject driver: " + ex.Message);
if (Bw != null) Bw?.ReportProgress(308, "");
}
}

session.Close();
DismApi.Shutdown();
}
catch (Exception ex)
{
Output.WriteLine("[Driver] Unknown error: " + ex.Message);
DismApi.Shutdown();
}
}

Expand Down
16 changes: 8 additions & 8 deletions deploya/deployaCore/Actions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* deploya - Fast and Easy way to deploy Windows
* Dive - Deployment is very easy.
* Copyright (c) 2018 - 2023 Exploitox.
*
* deploya is licensed under MIT License (https://github.com/valnoxy/deploya/blob/main/LICENSE).
* Dive (formally deploya) is licensed under MIT License (https://github.com/valnoxy/dive/blob/main/LICENSE).
* So you are allowed to use freely and modify the application.
* I will not be responsible for any outcome.
* Proceed with any action at your own risk.
*
* Source code: https://github.com/valnoxy/deploya
* Source code: https://github.com/valnoxy/dive
*/

using deployaCore.Action;
Expand Down Expand Up @@ -534,7 +534,7 @@ public static void InstallUnattend(Entities.UI ui, string windowsPath, string co
}

// Copy OEM logo to Windows\System32 directory
if (string.IsNullOrEmpty(oemLogoPath))
if (!string.IsNullOrEmpty(oemLogoPath))
{
try
{
Expand All @@ -559,7 +559,7 @@ public static void InstallUnattend(Entities.UI ui, string windowsPath, string co
{
try
{
Output.Write("Applying DISM Unattend ... ");
Output.Write("Registering unattend file with DISM ...");
var f = new FileInfo(windowsPath);
var drive = Path.GetPathRoot(f.FullName);

Expand Down Expand Up @@ -601,16 +601,16 @@ public static void InstallUnattend(Entities.UI ui, string windowsPath, string co
/// Installs the specific driver to the Windows Installation (only Vista and higher).
/// </summary>
/// <param name="ui">User Interface type</param>
/// <param name="windowsPath">Path to the Windows directory</param>
/// <param name="windowsDrive">Drive letter to the Windows disk</param>
/// <param name="driverPath">List of driver paths</param>
/// <param name="worker">Background worker for Graphical user interface</param>
public static void InstallDriver(Entities.UI ui, string windowsPath, List<string> driverPath, BackgroundWorker worker = null)
public static void InstallDriver(Entities.UI ui, string windowsDrive, List<string> driverPath, BackgroundWorker worker = null)
{
Output.Write("Installing drivers ... ");
ConsoleUtility.WriteProgressBar(0);
if (ui == Entities.UI.Graphical) { worker.ReportProgress(102, ""); worker.ReportProgress(0, ""); }

Apply.AddDriverToDisk(windowsPath, driverPath, worker);
Apply.AddDriverToDisk(windowsDrive, driverPath, worker);

ConsoleUtility.WriteProgressBar(100, true);
Console.WriteLine();
Expand Down
2 changes: 1 addition & 1 deletion deploya/deployaCore/deployaCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugType>embedded</DebugType>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<PackageId>deploya</PackageId>
<Version>12.0.0.435</Version>
<Version>12.0.0.448</Version>
<Authors>valnoxy</Authors>
<Company>Exploitox</Company>
<Product>deploya</Product>
Expand Down
77 changes: 52 additions & 25 deletions deploya/deployaUI/Common/UnattendBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,36 +685,41 @@ public class UnattendBuilder
{
public static string Build(Common.UnattendMode? mode)
{
var uc = new UnattendXmlClass.unattend();
uc.settings = new UnattendXmlClass.unattendSettings[3];
uc.settings[0] = new UnattendXmlClass.unattendSettings();
uc.settings[0].pass = "oobeSystem";

uc.settings[0].component = new UnattendXmlClass.unattendSettingsComponent
{
name = "Microsoft-Windows-Shell-Setup",
processorArchitecture = "amd64",
publicKeyToken = "31bf3856ad364e35",
language = "neutral",
versionScope = "nonSxS"
Common.Debug.WriteLine($"[UnattendBuilder] Entering Build process with mode {mode.Value} ...");
var uc = new UnattendXmlClass.unattend
{
settings = new UnattendXmlClass.unattendSettings[3]
};
uc.settings[0] = new UnattendXmlClass.unattendSettings
{
pass = "oobeSystem",
component = new UnattendXmlClass.unattendSettingsComponent
{
name = "Microsoft-Windows-Shell-Setup",
processorArchitecture = "amd64",
publicKeyToken = "31bf3856ad364e35",
language = "neutral",
versionScope = "nonSxS"
}
};

// Auto Logon for Administrator account
if (mode == Common.UnattendMode.Admin ||
mode == Common.UnattendMode.AdminWithoutOem ||
mode == Common.UnattendMode.AdminWithoutPassword ||
mode == Common.UnattendMode.AdminWithoutPasswordAndOem)
if (mode is Common.UnattendMode.Admin
or Common.UnattendMode.AdminWithoutOem
or Common.UnattendMode.AdminWithoutPassword
or Common.UnattendMode.AdminWithoutPasswordAndOem)
{
Common.Debug.WriteLine("[UnattendBuilder] AutoLogon for Admin account");
uc.settings[0].component.AutoLogon = new UnattendXmlClass.unattendSettingsComponentAutoLogon
{
Enabled = true,
LogonCount = 1,
Username = "Administrator"
};

if (mode != Common.UnattendMode.AdminWithoutPassword ||
mode != Common.UnattendMode.AdminWithoutPasswordAndOem)
if (mode is not (Common.UnattendMode.AdminWithoutPassword and Common.UnattendMode.AdminWithoutPasswordAndOem))
{
Common.Debug.WriteLine("[UnattendBuilder] Define Admin password");
uc.settings[0].component.AutoLogon.Password = new UnattendXmlClass.unattendSettingsComponentAutoLogonPassword
{
Value = Common.DeploymentInfo.Password,
Expand All @@ -727,13 +732,15 @@ public static string Build(Common.UnattendMode? mode)
// User Account
if (mode != Common.UnattendMode.OnlyOem)
{
Common.Debug.WriteLine("[UnattendBuilder] User Account creation");
uc.settings[0].component.UserAccounts = new UnattendXmlClass.unattendSettingsComponentUserAccounts();

switch (mode)
{
// Administrator Password
case Common.UnattendMode.Admin:
case Common.UnattendMode.AdminWithoutOem:
Common.Debug.WriteLine("[UnattendBuilder] Administrator Password");
uc.settings[0].component.UserAccounts.AdministratorPassword =
new UnattendXmlClass.unattendSettingsComponentUserAccountsAdministratorPassword
{
Expand All @@ -748,6 +755,7 @@ public static string Build(Common.UnattendMode? mode)
case Common.UnattendMode.UserWithoutPassword:
case Common.UnattendMode.UserWithoutPasswordAndOem:
{
Common.Debug.WriteLine("[UnattendBuilder] Local account");
uc.settings[0].component.UserAccounts.LocalAccounts =
new UnattendXmlClass.unattendSettingsComponentUserAccountsLocalAccounts
{
Expand All @@ -758,9 +766,9 @@ public static string Build(Common.UnattendMode? mode)
};

// Password
if (mode != Common.UnattendMode.UserWithoutPassword ||
mode != Common.UnattendMode.UserWithoutPasswordAndOem)
if (mode is not (Common.UnattendMode.UserWithoutPassword and Common.UnattendMode.UserWithoutPasswordAndOem))
{
Common.Debug.WriteLine("[UnattendBuilder] Local Account Password");
uc.settings[0].component.UserAccounts.LocalAccounts.LocalAccount.Password =
new UnattendXmlClass.unattendSettingsComponentUserAccountsLocalAccountsLocalAccountPassword
{
Expand All @@ -778,15 +786,29 @@ public static string Build(Common.UnattendMode? mode)

var oemLogo = "";
if (!string.IsNullOrEmpty(Common.OemInfo.LogoPath))
{
Common.Debug.WriteLine("[UnattendBuilder] OEM Logo is not Null or Empty: " + Common.OemInfo.LogoPath);
oemLogo = "%WINDIR%\\System32\\logo.bmp";
}

// OEM Information
if (mode != Common.UnattendMode.AdminWithoutOem ||
mode != Common.UnattendMode.AdminWithoutPasswordAndOem ||
mode != Common.UnattendMode.UserWithoutOem ||
mode != Common.UnattendMode.UserWithoutPasswordAndOem)
if (mode is UnattendMode.Admin or UnattendMode.AdminWithoutPassword or UnattendMode.User or UnattendMode.UserWithoutPassword)
{
uc.settings[0].component.OEMInformation = new UnattendXmlClass.unattendSettingsComponentOEMInformation
Common.Debug.WriteLine("[UnattendBuilder] OEM Information");
if (string.IsNullOrEmpty(Common.OemInfo.LogoPath))
{
uc.settings[0].component.OEMInformation = new UnattendXmlClass.unattendSettingsComponentOEMInformation
{
Manufacturer = Common.OemInfo.Manufacturer,
Model = Common.OemInfo.Model,
SupportHours = Common.OemInfo.SupportHours,
SupportPhone = Common.OemInfo.SupportPhone,
SupportURL = Common.OemInfo.SupportURL
};
}
else
{
uc.settings[0].component.OEMInformation = new UnattendXmlClass.unattendSettingsComponentOEMInformation
{
Logo = oemLogo,
Manufacturer = Common.OemInfo.Manufacturer,
Expand All @@ -795,11 +817,13 @@ public static string Build(Common.UnattendMode? mode)
SupportPhone = Common.OemInfo.SupportPhone,
SupportURL = Common.OemInfo.SupportURL
};
}
}

// S-Mode (Windows 10 1709 and up)
if (Common.DeploymentOption.UseSMode)
{
Common.Debug.WriteLine("[UnattendBuilder] Using S Mode");
uc.settings[1] = new UnattendXmlClass.unattendSettings
{
pass = "offlineServicing",
Expand All @@ -819,6 +843,7 @@ public static string Build(Common.UnattendMode? mode)
// Copy Profile (only for syspreped user profiles)
if (Common.DeploymentOption.UseCopyProfile)
{
Common.Debug.WriteLine("[UnattendBuilder] Using CopyProfile");
var nextIndex = Common.DeploymentOption.UseSMode ? 2 : 1;
uc.settings[nextIndex] = new UnattendXmlClass.unattendSettings
{
Expand All @@ -844,6 +869,8 @@ public static string Build(Common.UnattendMode? mode)

using StringWriter textWriter = new Utf8StringWriter();
slz.Serialize(textWriter, uc, ns);

Common.Debug.WriteLine("[UnattendBuilder] Building completed.");
return textWriter.ToString();
}

Expand Down
Loading

0 comments on commit 419c352

Please sign in to comment.