📄 memory.cs
字号:
using System;
using System.Runtime.InteropServices;
namespace SmartAnswerCall.处理类
{
public class Memory
{
public const uint LMEM_FIXED = 0;
public const uint LMEM_MODIFY = 0x80;
public const uint LMEM_MOVEABLE = 2;
public const uint LMEM_ZEROINIT = 0x40;
[DllImport("coredll.dll")]
public static extern IntPtr LocalAlloc(uint uFlags, uint uBytes);
[DllImport("coredll.dll")]
public static extern IntPtr LocalFree(IntPtr hMem);
[DllImport("coredll.dll")]
public static extern IntPtr LocalReAlloc(IntPtr hMem, uint uBytes, uint fuFlags);
public static void TestProc(MainTest.DisplayLineDelegate showLine)
{
IntPtr zero = IntPtr.Zero;
showLine("Allocating 1KB...");
zero = LocalAlloc(0, 0x400);
if (!(zero != IntPtr.Zero))
{
showLine("FAILURE: Allocation of 1KB failed");
}
else
{
showLine("Marshalling bytes to pointer...");
for (int i = 0; i < 0x400; i++)
{
Marshal.WriteByte(zero, i, 240);
}
showLine("Testing marshalled bytes...");
for (int j = 0; j < 0x400; j++)
{
if (Marshal.ReadByte(zero, j) != 240)
{
showLine("FAILURE: Data not marshalled properly");
break;
}
}
showLine("Freeing allocated pointer...");
if (LocalFree(zero) == IntPtr.Zero)
{
showLine("Freed successfully");
}
else
{
showLine("FAILURE: Failed to free memory");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -