PE在代码中验证?
我正在使用 Reflection.Emit
等动态生成程序集。
对于单元测试,我想 PEVerify 我的 IL。
我可以从命令行执行此操作,但我宁愿用代码执行此操作。
有没有比调用 PEVerify.exe 更方便的方法?理想情况下,我想直接将动态程序集交给它,而不必先将该程序集保存到磁盘。
理想情况下,我正在寻找类似的东西(伪代码:
Assert.IsFalse(new PEVerifier(myAssembly).Verify().Errors.Any());
Possible Duplicate:
Is there an API for verifying the MSIL of a dynamic assembly at runtime?
I'm dynamically generating an assembly using Reflection.Emit
and the like.
For a unit test, I'd like to PEVerify my IL.
I can do it from the command line, but I'd rather do this in code.
Is there a way to do this which is more convenient than calling PEVerify.exe? Ideally, I'd like to directly hand it the dynamic assembly without having to save that assembly to disk first.
Ideally I'm looking for something along the lines of (psuedocode:
Assert.IsFalse(new PEVerifier(myAssembly).Verify().Errors.Any());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如“重复”问题的答案所暗示的那样,您可以弄清楚如何挂钩 PEVerify.exe 使用的本机 DLL(我猜测这会导致问题,因为它没有记录并且可能会发生变化)。
另一种选择是使用
AssemblyBuilder
类将您要创建的动态程序集写入磁盘的临时位置,然后通过 System.Diagnostics.Process 类调用 PEVerify.exe(非常类似于此 PEVerifier 类示例确实如此)。You could, as the 'duplicate' question's answer suggests, figure out how to hook into the native DLL used by PEVerify.exe (which I'm guessing would cause issues since it is not documented and probably is subject to change).
The other option would be to use the
AssemblyBuilder
class to write the dynamic assembly that you're creating to the disk at a temporary location and then call PEVerify.exe via theSystem.Diagnostics.Process
class (much like this PEVerifier class example does).