简体   繁体   English

如何使 .NET 应用程序“识别大地址”?

[英]How to make a .NET application “large address aware”?

假设我已经使用 /3GB 开关启动了一个 32 位 Windows 服务器,我怎样才能让 .NET 应用程序使用额外的地址空间?

The flag is part of the image header, so you need to modify that using editbin.该标志是图像标题的一部分,因此您需要使用 editbin 对其进行修改。

editbin /LARGEADDRESSAWARE <your exe>

Use dumpbin /headers and look for the presence of Application can handle large (>2GB) addresses to see if the flag is set or not.使用dumpbin /headers并查找Application can handle large (>2GB) addresses以查看是否设置了标志。

From what I can tell you have to use the editbin utility shown in the existing answer.据我所知,您必须使用现有答案中显示的 editbin 实用程序。 There does not appear to be any way to set the flag using Visual Studio .NET, it looks like they encourage people to compile for 64 bit if possible instead of using the flag似乎没有任何方法可以使用 Visual Studio .NET 设置标志,看起来他们鼓励人们尽可能编译 64 位而不是使用标志

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=93771 http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=93771

要从 Visual Studio 自动执行此操作,请参阅此问题:来自 Visual Studio 的标志

Add those lines to Post build:将这些行添加到 Post build:

call "$(DevEnvDir)..\tools\vsdevcmd.bat"
editbin /largeaddressaware "$(TargetPath)"

From: vsvars32.bat in Visual Studio 2017来自: Visual Studio 2017 中的 vsvars32.bat

Thus far there haven't been an answer giving a cross-platform and open-source way to set LAA bit on a PE executable, so I decided to fill the gap.到目前为止,还没有给出跨平台和开源方式在 PE 可执行文件上设置 LAA 位的答案,所以我决定填补空白。

Note: make sure you have a backup!注意:确保您有备份!

You can that with reverse-engineering framework radare2.您可以使用逆向工程框架radare2 做到这一点。 In case you use a Linux distro, radare2 is typically in the repository.如果您使用 Linux 发行版,radare2 通常位于存储库中。 Unfortunately, the capability to set the bit isn't built-in, nonetheless it is quite easy with the following script:不幸的是,设置位的功能不是内置的,但是使用以下脚本很容易:

e cfg.newshell=true      # allows nested $(…) commands
s/ PE\0\0                # search PE file signature
s +4                     # skip the signature
echo "Original content:"
pf.pe_image_file_header.characteristics
echo "Patching the file…"
s+ 0x12                  # go to the characteristics field
wv2 $(?v $(pv2) \| 0x20) # 0x20 is the LAA bit, binary-OR it in the address
s-
echo "The new content:"
pf.pe_image_file_header.characteristics

Here's a demo how you use it (the script is in script.r2 file) with a notepad.exe file:这是一个演示如何使用它(脚本在script.r2文件中)notepad.exe文件:

 λ r2 -qi script.r2 -nnw notepad.exe
Searching 4 bytes in [0x1-0x620ca]
0x00000080 hit0_0 .mode.$PE\u0000\u0000Ld`J.
Original content:
      characteristics : 0x00000096 = characteristics (bitfield) = 0x00000107 : IMAGE_FILE_RELOCS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_32BIT_MACHINE
Patching the file…
The new content:
      characteristics : 0x00000096 = characteristics (bitfield) = 0x00000127 : IMAGE_FILE_RELOCS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_LARGE_ADDRESS_AWARE | IMAGE_FILE_32BIT_MACHINE

To double check it worked you can also use use objdump -p notepad.exe | grep "large address aware"要仔细检查它是否有效,您还可以使用 use objdump -p notepad.exe | grep "large address aware" objdump -p notepad.exe | grep "large address aware" command and see that it has output. objdump -p notepad.exe | grep "large address aware"命令并查看它有输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM