Files
desktop-edge-win/ZitiUpdateService/checkers/PeFile/StructHelper.cs
T
2021-06-03 10:06:25 -04:00

16 lines
526 B
C#

using System.Runtime.InteropServices;
namespace ZitiUpdateService.Checkers.PeFile {
public static class StructHelper {
public static T FromBytes<T>(byte[] bytes) {
// Pin the managed memory while, copy it out the data, then unpin it
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return theStructure;
}
}
}