运行时可执行代码的CRC计算 [英] CRC calculation of executable code in runtime

查看:107
本文介绍了运行时可执行代码的CRC计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中使用了一些代码完整性检查过程。我在构建应用程序之后计算代码片段的CRC,然后在运行时检入。

一切都适用于32位平台,但在64位平台上有很多麻烦。



我尝试过:



完整性检查如下:



I have an application in which some code integrity check procedure is used. I calculate CRC of the code fragment after applicaztion is built and then check in in runtime.
All works well om 32bit platform, but there are lot of troubles on 64-bit platform.

What I have tried:

Integrity check looks like the following:

codemark1_start:

   <Some code>

    codemark1_end:
    AsmCrcCodeMrk((MyTinyBuff), codemark1_start, codemark1_end, 1,Procedure);





AsmCrcCodeMrk宏看起来像





AsmCrcCodeMrk macro looks like


AsmCrcCodeMrk(DescriptorAddr,StartAddr,EndAddr,Id,BPA)\

AsmCrcCodeSig \

__asm mov EAX,offset DescriptorAddr \

__asm mov EAX,StartAddr \

__asm mov EAX,EndAddr \

__asm mov EAX,Id \

__asm mov EAX,BPA \



编译完成后,程序已由另一个应用程序处理,该应用程序拉出标签之间的片段并计算其CRC。在Win32下,所有内容都可编译并运行。



但是,对于X64,有一些困难:



1) Visual Studio 2015中的X64不支持内联汇编程序。但我可以将宏作为函数放在单独的文件中,我可以使函数__forceinline。



2)有必要在编译时获取标签的地址。这是一个问题。



有人能告诉我如何在X64平台的编译时获取标签地址吗?

AsmCrcCodeMrk(DescriptorAddr, StartAddr, EndAddr, Id, BPA) \
AsmCrcCodeSig \
__asm mov EAX, offset DescriptorAddr \
__asm mov EAX, StartAddr \
__asm mov EAX, EndAddr \
__asm mov EAX, Id\
__asm mov EAX, BPA\

After compilation, the program has been processed by an additional application that "pulls out" the fragments between labels and calculates theirs CRC. Under Win32, everything compiles and works.

However, for X64 there are difficulties:

1) X64 in Visual Studio 2015 does not support inline assembler. But I can make macro as function in separate file and I can make the function __forceinline.

2) It is necessary to get addresses of labels at the compilation time. And this is a problem.

Can anyone tell me how to get addresses of labels at the compilation time for X64 platform?

推荐答案

C / C ++标准中没有方法来获取标签的地址。这可能是使用内联汇编的原因。


除了在64位汇编或使用GNU编写整个代码之外,我没有看到解决方案编译器编译特定的代码部分,因为它有使用GNU编译器集合(GCC):标签为值 [ ^ ] C扩展名。但是,这需要使创建的目标文件与VS可链接。另请参见SO线程标签地址(MSVC)
There is no method in the C/C++ standard to get the address of a label. That is probably the reason why inline assembly has been used.

So I don't see a solution besides writing the whole code in 64-bit assembly or using the GNU compiler to compile the specific code portion because that has a Using the GNU Compiler Collection (GCC): Labels as Values[^] C extension. However, this requires to make the created object file linkable with VS. See also the SO thread Address of labels (MSVC).


这篇关于运行时可执行代码的CRC计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆