如何最轻松地访问 .NET PE 文件中的特定字段?
我正在制作一个程序,该程序应该比较可移植可执行格式的两个文件,以查看它们是否是从相同的代码编译的。即使代码没有更改,有些字段也总是会有所不同。我的解决方案基本上是将文件加载到我的程序中并将所有时间戳和校验和设置为零,然后比较它们。这对于 exe 文件效果很好,但 .NET DLL 在 #~ 流中也有一个修订字段,该字段更难访问。我必须解析所有标头,这看起来相当乏味,如果我能避免这样做,我会很高兴。
现在我正在考虑忽略整个 #~ 流。我可以这样做并仍然确保文件是等效的吗?当我只需要一个字段的地址时,读取所有标头感觉像是浪费时间。如果我不能做到这一点,您能否建议其他耗时较少的解决方案?
可以补充一点,我正在用 C# 编程。
I'm making a program that should compare two files of the Portable Executable format, to see if they were compiled from the same code. There are fields that always will differ, even when the code wasn't changed. My solution is basically to load the files into my program and set all timestamps and checksums to zero and then compare them. This works fine for exe-files, but .NET DLL's also have a revision field in the #~ stream which is much harder to access. I'd have to parse all headers which seems quite tedious and I'd be happy if I could avoid doing that.
Now I'm thinking about just ignoring the whole #~ stream. Can I do this and still be sure the files are equivalent? It feels like a waste of time to read in all headers when I just need the address of one field. If i cannot do this, could you suggest other less time-consuming solutions?
Could add that I'm programming in C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过莫诺塞西尔吗?它是一个用于读取和修改 .NET 程序集的出色 API。
请参阅http://www.mono-project.com/Cecil
Did you try Mono Cecil? It's a great API for reading and modifing .NET assemblies.
see http://www.mono-project.com/Cecil