mirror of
https://github.com/openziti/desktop-edge-win.git
synced 2026-10-15 17:11:19 +00:00
16 lines
526 B
C#
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;
|
|
}
|
|
}
|
|
}
|