惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - lixiong

关于调试,有一个真实的故事我要讲一讲 疑似CPU或者内存故障导致进程崩溃 Web服务的性能,和BCrypt性能问题的解决方法 md5/sha1+salt和Bcrypt 从Win8回顾微软平台的各种技术 其实.NET的确慢, 微软推的这一套的确不适合很多地方 微软平台UI自动化(UIA)经验集 今天在InfoQ看到一个google关于test的演讲, 非常精彩 来来来, 我也来发发我大二时候的作品 Windows用户态程序高效排错 全文PDF 回顾下COM+提供的服务,就明白啥是中间层了, 我把绝招贡献给你们吧 招聘职位:赴微软软件测试开发工程师(产品: Windows 7) 《Windows 高效排错》 可以在CSDN读书频道预览了 三个关键命令找出ASP.NET程序内存分片的原因 handle leak ts steps in chinese 除了memory leak和handle leak外的其它资源泄露 一些重要的计数器 IE的leak useful log options in .Net
为什么EXE不能超过4GB
lixiong · 2010-07-13 · via 博客园 - lixiong

2010-07-13 10:32  lixiong  阅读(10355)  评论()    收藏  举报

为什么EXE不能超过4GB

前几天看到大家在讨论EXE装载的问题,很新奇。有的说PE装载受到进程空间的限制,有的说PE一定是整体装入,有的用ZIP自解压包来举例子。

我当时大概想了一下,觉得PE不一定是要整体装入的。PE文件包含一个PE header,里面定义了各个段,比如代码,资源等等的偏移地址,装载的时候应该不会超出这个PE header的定义。也就是说,如果PE header里面定义了最远的段是10M,但是PE文件有100M的话,应该最多只有10M装载。

于是我写了一个程序来测试下。首先写一个简单的C++的helloworld。然后随便在硬盘上找了个700M左右的A片,然后执行下面的命令把这两个文件拼合起来成为一个新的EXE:

copy /B helloworld.exe /B + 常盘みちる.avi /B largepe.exe /B

然后运行这个largepe.exe, 一切正常。在debugger中加载这个largepe.exe后发现,这个module占据的内存空间和helloworld一样,并没有包avi那部分。

所以我在想,既然是这样的话,我可以把很大的数据放到exe文件后面,然后在exe的实现里面来分段读取这些数据,实现自我播放自我解压之类的。为了再次证明这一点,我用dxshow写了一个简单的播放程序,然后用同样的办法拼接了一个4G多的高清版本。运行,发现:

不能运行。说这个是invalid win32 application。

好吧,由此看来,自解压文件不超过4G的确还是有原因的。但是原因到底是什么呢,难道真的和4GB内存空间相关么?于是我换了个64位的机器,运行,发现:

不能运行。说这个是invalid win32 application。

哦,原来64位的机器也不能运行超过4GB的EXE啊,那看来和什么进程内存空间没太大关系了吧。但是原因到底是什么呢,我拿debugger跟到失败前的最后一个API,发现是ZwCreateSection,这个API调用失败并且返回STATUS_INVALID_FILE_FOR_SECTION。额,这里已经超出我的知识范围了,于是就去讨论组问专家,专家Pavel说:

"
SECTION_IMAGE_INFORMATION structure contains a ULONG ImageFileSize field. If we allow files larger than 4 GB, programs that use this structure may break, and that can potentially affect 3rd party apps because all this information is on the web, even though the structure and the APIs using it are not officially documented.

(Note that this is separate from the image size in the PE headers, which is also a ULONG and is currently limited to slightly less than 2 GB.)

--by Pavel
"

原来是这样啊~~~

PS, 附上文SECTION_IMAGE_INFORMATION的结构定义:

http://www.nirsoft.net/kernel_struct/vista/SECTION_IMAGE_INFORMATION.html

typedef struct _SECTION_IMAGE_INFORMATION
{
     PVOID TransferAddress;
     ULONG ZeroBits;
     ULONG MaximumStackSize;
     ULONG CommittedStackSize;
     ULONG SubSystemType;
     union
     {
          struct
          {
               WORD SubSystemMinorVersion;
               WORD SubSystemMajorVersion;
          };
          ULONG SubSystemVersion;
     };
     ULONG GpValue;
     WORD ImageCharacteristics;
     WORD DllCharacteristics;
     WORD Machine;
     UCHAR ImageContainsCode;
     UCHAR ImageFlags;
     ULONG ComPlusNativeReady: 1;
     ULONG ComPlusILOnly: 1;
     ULONG ImageDynamicallyRelocated: 1;
     ULONG Reserved: 5;
     ULONG LoaderFlags;
     ULONG ImageFileSize;
     ULONG CheckSum;
} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;