mirror of https://github.com/raandree/NTFSSecurity
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
684 B
26 lines
684 B
|
10 years ago
|
using System;
|
||
|
|
using System.Runtime.InteropServices;
|
||
|
|
|
||
|
|
namespace Security2
|
||
|
|
{
|
||
|
|
internal static class IntPtrExtensions
|
||
|
|
{
|
||
|
|
public static IntPtr Increment(this IntPtr ptr, int cbSize)
|
||
|
|
{
|
||
|
|
return new IntPtr(ptr.ToInt64() + cbSize);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static IntPtr Increment<T>(this IntPtr ptr)
|
||
|
|
{
|
||
|
|
return ptr.Increment(Marshal.SizeOf(typeof(T)));
|
||
|
|
}
|
||
|
|
|
||
|
|
public static T ElementAt<T>(this IntPtr ptr, int index)
|
||
|
|
{
|
||
|
|
var offset = Marshal.SizeOf(typeof(T)) * index;
|
||
|
|
var offsetPtr = ptr.Increment(offset);
|
||
|
|
return (T)Marshal.PtrToStructure(offsetPtr, typeof(T));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|