Skip to content

Commit

Permalink
Fix Registry access of large unsigned values
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleex255 committed Jun 13, 2021
1 parent 531746a commit e961160
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Docs/Components.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This list shows which code files are responsible for which parts of Policy Plus'
* `AdmxBundle.vb`: Defines the `AdmxBundle` class, which represents a policy workspace. Information is taken out of multiple `AdmxFile` and `AdmlFile` instances and processed to discover properties of and relationships between policy objects. Bundle objects serve as links between ADMX data and ADML data, providing methods to resolve text from a language-neutral identifier. Also defines the `AdmxLoadFailType` enumeration and `AdmxLoadFailure` class, which represent problems encountered while trying to add ADMX files to the bundle.
* `AdmxFile.vb`: Defines the `AdmxFile` class, which represents an administrative template's policy objects: categories, policies, products, and support definitions. That information is loaded from ADMX files parsed as XML. All text in these files is language-neutral; the ADML files provide the human-readable strings.
* `AdmxStructures.vb`: Defines several classes used to hold information extracted from ADMX files. Since ADMX files rarely make sense on their own, these classes have minimal interconnectedness. Rather, string fields hold the IDs of referenced policy objects.
* `BitReinterpretation.vb`: Defines explicit-layout structures used to reinterpret signed integers/longs as unsigned or vice versa so that large unsigned values can be read or written from the Registry using the standard `RegistryKey` class.
* `CmtxFile.vb`: Defines the `CmtxFile` class, which represents a comments file, which holds the user's annotations on policy settings. Information can be loaded from and saved to a CMTX file (XML format). For ease of use, the class also provides methods for translating policy-ID-to-comment mappings to `CmtxFile` instances and back.
* `CompiledStructures.vb`: Defines several interconnected classes used to hold information about policy objects. `AdmxBundle` creates these by weaving together information from several ADMX and ADML files. These instances are the object-oriented equivalents of their `AdmxStructures.vb` counterparts.
* `ConfigurationStorage.vb`: Helps load and store program configuration that resides in the Registry.
Expand Down
13 changes: 13 additions & 0 deletions PolicyPlus/BitReinterpretation.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Explicit)>
Public Structure ReinterpretableDword
<FieldOffset(0)> Public Signed As Integer
<FieldOffset(0)> Public Unsigned As UInteger
End Structure

<StructLayout(LayoutKind.Explicit)>
Public Structure ReinterpretableQword
<FieldOffset(0)> Public Signed As Long
<FieldOffset(0)> Public Unsigned As ULong
End Structure
1 change: 1 addition & 0 deletions PolicyPlus/PolicyPlus.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="AdmxBundle.vb" />
<Compile Include="AdmxFile.vb" />
<Compile Include="AdmxStructures.vb" />
<Compile Include="BitReinterpretation.vb" />
<Compile Include="CmtxFile.vb" />
<Compile Include="CompiledStructures.vb" />
<Compile Include="ConfigurationStorage.vb" />
Expand Down
14 changes: 13 additions & 1 deletion PolicyPlus/PolicySource.vb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ Public Class RegistryPolicyProxy ' Pass operations through to the real Registry
DeleteValue(Key, Value) ' The Registry has no concept of "will delete this when I see it"
End Sub
Public Sub SetValue(Key As String, Value As String, Data As Object, DataType As RegistryValueKind) Implements IPolicySource.SetValue
If TypeOf Data Is UInteger Then
Data = (New ReinterpretableDword With {.Unsigned = Data}).Signed
ElseIf TypeOf Data Is ULong Then
Data = (New ReinterpretableQword With {.Unsigned = Data}).Signed
End If
Using regKey = RootKey.CreateSubKey(Key)
regKey.SetValue(Value, Data, DataType)
End Using
Expand All @@ -386,7 +391,14 @@ Public Class RegistryPolicyProxy ' Pass operations through to the real Registry
Public Function GetValue(Key As String, Value As String) As Object Implements IPolicySource.GetValue
Using regKey = RootKey.OpenSubKey(Key, False)
If regKey Is Nothing Then Return Nothing
Return regKey.GetValue(Value, Nothing, RegistryValueOptions.DoNotExpandEnvironmentNames)
Dim data = regKey.GetValue(Value, Nothing, RegistryValueOptions.DoNotExpandEnvironmentNames)
If TypeOf data Is Integer Then
Return (New ReinterpretableDword With {.Signed = data}).Unsigned
ElseIf TypeOf data Is Long Then
Return (New ReinterpretableQword With {.Signed = data}).Unsigned
Else
Return data
End If
End Using
End Function
Public Function GetValueNames(Key As String) As List(Of String) Implements IPolicySource.GetValueNames
Expand Down

0 comments on commit e961160

Please sign in to comment.