Click here to Skip to main content
13,770,697 members
Rate this:
 
Please Sign up or sign in to vote.
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 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\

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?
Posted 21-May-18 21:00pm
Updated 21-May-18 22:18pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.181119.1 | Last Updated 22 May 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100