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

Bump System.Management from 8.0.0 to 9.0.0-rc.2.24473.5 #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Defrag/Rebound.Defrag.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Diagnostics.EventLog" Version="9.0.0-preview.6.24327.7" />
<PackageReference Include="System.Management" Version="8.0.0" />
<PackageReference Include="System.Management" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="TaskScheduler" Version="2.11.0" />
<PackageReference Include="WinUIEx" Version="2.3.4" />
<Manifest Include="$(ApplicationManifest)" />
Expand Down
2 changes: 1 addition & 1 deletion TrustedPlatform/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
FontWeight="Normal"
Foreground="{Binding Foreground, ElementName=WindowTitle}"
Opacity="0.5"
Text=" v0.0.3"
Text=" v0.0.4"
TextTrimming="CharacterEllipsis" />
</StackPanel>
<StackPanel
Expand Down
109 changes: 69 additions & 40 deletions TrustedPlatform/Models/TpmManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Management;
using System.Text;
using Tpm2Lib;
using Windows.Devices.Spi;

public class TpmManager : INotifyPropertyChanged
{
private string _manufacturerName;
private string _manufacturerVersion;
private string _specificationVersion;
private string _status;
private string _tpmSubVersion;
private string _pcClientSpecVersion;
private string _pcrValues;
public string _manufacturerName;
public string _manufacturerVersion;
public string _specificationVersion;
public string _status;
public string _tpmSubVersion;
public string _pcClientSpecVersion;
public string _pcrValues;

public string ManufacturerName
{
Expand Down Expand Up @@ -85,40 +90,33 @@ private set

public TpmManager()
{
GetTpmInfo();
tpmDevice = new TbsDevice(); // or whichever device you are using
tpmDevice.Connect(); // No assignment, just calling the method
tpm = new Tpm2(tpmDevice);
GetTpmInfo(); // No assignment, just calling the method
}

public void RefreshTpmInfo()
{
GetTpmInfo();
GetTpmInfo(); // No assignment, just calling the method
}

public List<string> GetTpmInfo()
private void GetTpmInfo()
{
try
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2\Security\MicrosoftTpm", "SELECT * FROM Win32_Tpm"))
{
foreach (ManagementObject queryObj in searcher.Get())
{
return new List<string>
{
queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown",
queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown",
queryObj["SpecVersion"]?.ToString() ?? "Unknown",
queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown",
queryObj["SpecVersion"]?.ToString() ?? "Unknown",
GetPcrValues(),
queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready"
};
/*ManufacturerName = queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown";
ManufacturerName = queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown";
ManufacturerVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown";
SpecificationVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown";
TpmSubVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown";
PcClientSpecVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown";
PcrValues = GetPcrValues();

Status = queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready";*/
Status = queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready";
}
}
}
Expand All @@ -133,21 +131,9 @@ public List<string> GetTpmInfo()
Status = "Error communicating with TPM";
Console.WriteLine($"An error occurred while getting TPM information: {ex.Message}");
}

return new List<string>()
{
ManufacturerName,
ManufacturerVersion,
SpecificationVersion,
TpmSubVersion,
PcClientSpecVersion,
PcrValues,

Status,
};
}

private string ConvertManufacturerIdToName(uint manufacturerId)
public string ConvertManufacturerIdToName(uint manufacturerId)
{
var manufacturerStr = string.Empty;
manufacturerStr += (char)((manufacturerId >> 24) & 0xFF);
Expand All @@ -157,11 +143,54 @@ private string ConvertManufacturerIdToName(uint manufacturerId)
return manufacturerStr;
}

private string GetPcrValues()
public Tpm2Device tpmDevice;
public Tpm2 tpm;
public string GetPcrValues()
{
// Placeholder for PCR retrieval logic. This should query TPM for PCR values.
// Requires advanced access via TBS API or TPM library.
return "PCR values are not directly accessible via WMI. Requires advanced TPM API.";
try
{
// Specify PCR selection for reading (e.g., PCR 0, 1, 2)
PcrSelection[] pcrSelectionIn = { new PcrSelection(TpmAlgId.Sha256, new uint[] { 0, 1, 2 }) };
PcrSelection[] pcrSelectionOut;
Tpm2bDigest[] pcrValues;

// Read PCR values
tpm.PcrRead(pcrSelectionIn, out pcrSelectionOut, out pcrValues);

// Build a string to display PCR values
StringBuilder pcrStringBuilder = new StringBuilder();

// Check if pcrValues has entries
if (pcrValues.Length == 0)
{
return "No PCR values available.";
}

for (int i = 0; i < pcrSelectionOut.Length; i++)
{
pcrStringBuilder.AppendLine($"PCR {i}: {BitConverter.ToString(pcrValues[i].buffer)}");
}

return pcrStringBuilder.ToString();
}
catch (TpmException tpmEx)
{
// Log specific TPM-related errors
Debug.WriteLine($"TPM Error retrieving PCR values: {tpmEx.Message} (Error Code:)");
return $"TPM Error: {tpmEx.Message} (Error Code:)";
}
catch (Exception ex)
{
// Log general errors with stack trace
Debug.WriteLine($"General Error retrieving PCR values: {ex.Message}\n{ex.StackTrace}");
return $"Error retrieving PCR values: {ex.Message}";
}
finally
{
// Ensure resources are cleaned up
tpm?.Dispose();
tpmDevice?.Dispose();
}
}

protected virtual void OnPropertyChanged(string propertyName)
Expand Down
117 changes: 117 additions & 0 deletions TrustedPlatform/Rebound - Backup.TrustedPlatform.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.22621.35-preview</WindowsSdkPackageVersion>
<RootNamespace>Rebound.TrustedPlatform</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64;x86</Platforms>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<Version>0.0.3</Version>
<ImplicitUsings>true</ImplicitUsings>
<LangVersion>Latest</LangVersion>
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<WindowsPackageType>MSIX</WindowsPackageType>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<PackageCertificateKeyFile>Rebound.TrustedPlatform_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>

<ItemGroup>
<None Include="Assets\**\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Content Remove="Assets\Store\icon.ico" />
<Content Remove="Assets\Store\icon.png" />
</ItemGroup>

<ItemGroup>
<None Remove="Assets\icon.ico" />
<None Remove="MainWindow.xaml" />
</ItemGroup>

<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.1.240821" />
<PackageReference Include="CommunityToolkit.WinUI.Helpers" Version="8.0.240109" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.2.1-experimental2" />
<PackageReference Include="Microsoft.TSS" Version="2.1.1" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="System.Management" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="WinUIEx" Version="2.3.4" />
</ItemGroup>
<ItemGroup>
<Page Update="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>

<ItemGroup>
<None Include="..\Rebound\Assets\AppIcons\Rebound11Icon.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\.github\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Helpers\Rebound.Helpers.csproj" />
</ItemGroup>

<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Riverside, ErrorTek,TheDevil, Lamparter</Authors>
<PackageProjectUrl>https://ivirius.vercel.app</PackageProjectUrl>
<Title>TPM Management</Title>
<PackageId>Riverside.Rebound.TrustedPlatform</PackageId>
<Copyright>Copyright (c) 2024-present Ivirius Community</Copyright>
<Description>Windows 11 done right.</Description>
<PackageIcon>Rebound11Icon.png</PackageIcon>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<AssemblyName>Rebound TPM Management</AssemblyName>
</PropertyGroup>
</Project>
8 changes: 6 additions & 2 deletions TrustedPlatform/Rebound.TrustedPlatform.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<ImplicitUsings>true</ImplicitUsings>
<LangVersion>Latest</LangVersion>
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
Expand Down Expand Up @@ -98,10 +98,14 @@
<ItemGroup>
<ProjectReference Include="..\Helpers\Rebound.Helpers.csproj" />
</ItemGroup>

<PropertyGroup>
<WindowsSdkPackageVersion>10.0.22621.38</WindowsSdkPackageVersion>
</PropertyGroup>

<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Riverside, ErrorTek, Lamparter</Authors>
<Authors>Riverside, ErrorTek,TheDevil, Lamparter</Authors>
<PackageProjectUrl>https://ivirius.vercel.app</PackageProjectUrl>
<Title>TPM Management</Title>
<PackageId>Riverside.Rebound.TrustedPlatform</PackageId>
Expand Down
3 changes: 2 additions & 1 deletion TrustedPlatform/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@
<TextBlock
Grid.Row="5"
Grid.Column="0"
Margin="0,10,20,0"
Margin="0,10,20,15"
VerticalAlignment="Center"
FontSize="12"
TextWrapping="Wrap"
FontWeight="SemiBold"
Text="PCR Values:" />
<TextBlock
Expand Down
Loading