gpt4 book ai didi

c# - 如何检查 exe 是否设置为 LARGEADDRESSAWARE

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

我正在开发一个 C# 程序,它将加载文件并获取加载文件创建日期、修改日期、大小等信息。我需要知道的另一件事是加载的文件 (executable.exe) 与 LARGEADDRESSAWARE 标志链接。 FileInfo 类不提供此信息。

有谁知道如何在 C# 中找出给定的 executable.exe 是否与 LARGEADDRESSAWARE 标志链接(以处理大于 2 GB 的地址)?

最佳答案

这里是一些检查大地址感知标志的代码。您所要做的就是传递一个指向可执行文件开头的流。

IsLargeAware("some.exe");

static bool IsLargeAware(string file)
{
using (var fs = File.OpenRead(file))
{
return IsLargeAware(fs);
}
}
/// <summary>
/// Checks if the stream is a MZ header and if it is large address aware
/// </summary>
/// <param name="stream">Stream to check, make sure its at the start of the MZ header</param>
/// <exception cref=""></exception>
/// <returns></returns>
static bool IsLargeAware(Stream stream)
{
const int IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x20;

var br = new BinaryReader(stream);

if (br.ReadInt16() != 0x5A4D) //No MZ Header
return false;

br.BaseStream.Position = 0x3C;
var peloc = br.ReadInt32(); //Get the PE header location.

br.BaseStream.Position = peloc;
if (br.ReadInt32() != 0x4550) //No PE header
return false;

br.BaseStream.Position += 0x12;
return (br.ReadInt16() & IMAGE_FILE_LARGE_ADDRESS_AWARE) == IMAGE_FILE_LARGE_ADDRESS_AWARE;
}

关于c# - 如何检查 exe 是否设置为 LARGEADDRESSAWARE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9054469/

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