Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit fcdd3ad

Browse files
author
Matt Graeber
committed
Explicitly casting types as [Type]
The latest version of .NET added generics to many of the InteropService methods. Therefore, all of my uses of types need to be explicitly cast with [Type].
1 parent 7f0be86 commit fcdd3ad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ReverseEngineering/Get-NtSystemInformation.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@
633633

634634
foreach ($i in 0..($Count-1))
635635
{
636-
[Runtime.InteropServices.Marshal]::PtrToStructure($StructAddress, $StructType)
636+
[Runtime.InteropServices.Marshal]::PtrToStructure($StructAddress, [Type] $StructType)
637637
$StructAddress = ([IntPtr]($StructAddress.ToInt64() + $StructSize))
638638
}
639639

@@ -958,7 +958,7 @@
958958
# Base address of the _SYSTEM_OBJECTTYPE_INFORMATION struct
959959
$ObjectTypeAbsoluteAddress = [IntPtr]($PtrData.ToInt64() + $NextTypeOffset)
960960

961-
$Result = [Runtime.InteropServices.Marshal]::PtrToStructure($ObjectTypeAbsoluteAddress, $ObjectTypeClass)
961+
$Result = [Runtime.InteropServices.Marshal]::PtrToStructure($ObjectTypeAbsoluteAddress, [Type] $ObjectTypeClass)
962962

963963
if ($Result.NumberOfObjects -gt 0)
964964
{
@@ -970,7 +970,7 @@
970970

971971
do
972972
{
973-
$ObjectResult = [Runtime.InteropServices.Marshal]::PtrToStructure(( [IntPtr]($ObjectBaseAddr.ToInt64() + $NextObjectOffset) ), $ObjectClass)
973+
$ObjectResult = [Runtime.InteropServices.Marshal]::PtrToStructure(( [IntPtr]($ObjectBaseAddr.ToInt64() + $NextObjectOffset) ), [Type] $ObjectClass)
974974

975975
$ResultHashTable2 = @{
976976
Object = $ObjectResult.Object

ReverseEngineering/Get-StructFromMemory.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ http://www.exploit-monday.com
131131
$MemoryBasicInformation = [Activator]::CreateInstance($MEMORY_BASIC_INFORMATION)
132132

133133
# Confirm you can actually read the address you're interested in
134-
$NativeUtils::VirtualQueryEx($Handle, $MemoryAddress, [Ref] $MemoryBasicInformation, [Runtime.InteropServices.Marshal]::SizeOf($MEMORY_BASIC_INFORMATION)) | Out-Null
134+
$NativeUtils::VirtualQueryEx($Handle, $MemoryAddress, [Ref] $MemoryBasicInformation, [Runtime.InteropServices.Marshal]::SizeOf([Type] $MEMORY_BASIC_INFORMATION)) | Out-Null
135135

136136
$PAGE_EXECUTE_READ = 0x20
137137
$PAGE_EXECUTE_READWRITE = 0x40
@@ -154,7 +154,7 @@ http://www.exploit-monday.com
154154
throw 'The address specified does not have read access.'
155155
}
156156

157-
$StructSize = [Runtime.InteropServices.Marshal]::SizeOf($StructType)
157+
$StructSize = [Runtime.InteropServices.Marshal]::SizeOf([Type] $StructType)
158158
$EndOfAllocation = $AllocationBase + $RegionSize
159159
$EndOfStruct = $MemoryAddress.ToInt64() + $StructSize
160160

@@ -194,7 +194,7 @@ http://www.exploit-monday.com
194194
Write-Verbose "Struct Size: $StructSize"
195195
Write-Verbose "Bytes read: $BytesRead"
196196

197-
$ParsedStruct = [Runtime.InteropServices.Marshal]::PtrToStructure($LocalStructPtr, $StructType)
197+
$ParsedStruct = [Runtime.InteropServices.Marshal]::PtrToStructure($LocalStructPtr, [Type] $StructType)
198198

199199
[Runtime.InteropServices.Marshal]::FreeHGlobal($LocalStructPtr)
200200
$SafeHandle.Close()

0 commit comments

Comments
 (0)