gpt4 book ai didi

C# 字节数组到结构

转载 作者:IT王子 更新时间:2023-10-28 23:37:49 29 4
gpt4 key购买 nike

我想使用 ReadProcessMemory 函数来填充这个结构。

    [StructLayout(LayoutKind.Explicit)]
public struct WinMineGameStruct
{
[FieldOffset(0x118)]
public Int32 xPressed;
[FieldOffset(0x118)]
public Int32 yPressed;
[FieldOffset(0x140)]
public Int32 MouseDown;
[FieldOffset(0x160)]
public Int32 GameStatus;
[FieldOffset(0x164)]
public Int32 IsInGame;
[FieldOffset(0x194)]
public Int32 MinesLeft;
[FieldOffset(0x330)]
public Int32 LevelMines;
[FieldOffset(0x334)]
public Int32 Colls;
[FieldOffset(0x338)]
public Int32 Rows;
[FieldOffset(0x6a0)]
public Int32 GameType;
[FieldOffset(0x6cc)]
public Int32 EasyBestScore;
[FieldOffset(0x6d0)]
public Int32 MediumBestScore;
[FieldOffset(0x6d4)]
public Int32 HardBestScore;
[FieldOffset(0x6d8)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public Char[] PlayerEasyName;
[FieldOffset(0x718)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public Char[] PlayerMediumName;
[FieldOffset(0x758)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public Char[] PlayerHardName;
[FieldOffset(0x798)]
public Int32 NumLastHitDiscovered;
[FieldOffset(0x79c)]
public Int32 TimePlayed;
[FieldOffset(0x7a4)]
public Int32 DiscoveredFields;
}

我知道如何读取字节数组、int、string、short 等。我想知道如何将字节数组转换为这个结构。

最佳答案

哇...有趣的问题。

你可以看看 binaryformatter... http://msdn.microsoft.com/en-us/library/b85344hz.aspx

话虽如此,看起来您有一些与您的对象定义不完全匹配的二进制数组。在这种情况下,我认为您必须阅读您感兴趣的数组的每一部分并将该 block 反序列化为您想要的类型,即 int32 等......

请参阅此页面,了解如何将 byte[] 中的单个字段输入.. enter link description here

关于C# 字节数组到结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5052881/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com