1

I'm working on a project, written in C++, that involves the injection of source code into an already compiled (and running) process, and so in a few cases I'm required to write inline assembly. This short introduction is to avoid any comment telling me inline assembly probably shouldn't be used.

So, as for my actual question, I've found out C++ had alternative operators, and a few of them, notably and and or reminded me a lot of Python, a programming language I find very pleasant in terms of syntax.

I know using these alternative operators certainly isn't in the best practices and should be avoided, but this is a personal project so code readability for others doesn't bother me too much.

My project is compiled with a MSVC compiler, and my first observation was that these alternative operators do not seem to be defined by default. After a bit of research, I found out one way to enable them was to include <ciso646>. So mission accomplished, I thought.

But on compiling I found out my inline assembly snippets are now causing compile errors, because they contains asm instructions such as or and and. Yes, the inline assembly is written in lower case. So, the possible workaround would be to uppercase all of my inline assembly snippets, but since I don't like the ALL CAPS RAGE STYLE too much, I'm asking here if there's any other workaround to this problem.

Here's an example of inline assembly causing problems

__declspec (naked) Unit* __fastcall D2CLIENT_GetClientUnit(int nGUID, DWORD dwType)
{
    /*
        push dwType
        mov eax, nGUID & 0x7F
        mov edx, ((dwType << 9) + D2CLIENT_6FBBA608)
        call D2CLIENT_6FB54E20
    */

    __asm
    {
        push edx
        mov eax, ecx
        shl edx, 0x09
        and eax, 0x7F
        add edx, [D2CLIENT_6FBBA608]
        call D2CLIENT_6FB54E20
        retn
    }
}

Thanks

Verv
  • 2,385
  • 2
  • 23
  • 37
  • Sounds like a compiler error? They are around since the last century, but not many serious developer use them. – Aganju May 14 '18 at 04:04
  • Have you looked at the `/Za` (disable language extensions) compiler flag? It'll make `and` and `or` keywords, but may break other things. – 1201ProgramAlarm May 14 '18 at 04:53
  • Put your inline asm in its own C file which does not include ciso646? Or maybe instead of using "inline" asm, use actual asm (in an .asm file)? You'll have to do that anyway if you want to support x64 (which doesn't support inline). And just to add: while this may make your code easier (for you) to write, it's likely to be unpleasant for others to maintain. – David Wohlferd May 14 '18 at 05:12
  • @1201ProgramAlarm I did but as you said, it "may break other things", so that's kind of a deal breaker – Verv May 14 '18 at 17:45
  • @DavidWohlferd I did think about this, but the way my include pattern is right now, that would be kind of complicated to achieve. As for x64 support, my project is strictly aimed at x86 architecture, since I'm injecting into a 32 bits executable, and as for code maintainability, I mentioned in my post this was a personal project which only I will read, so I'm not worried about this. – Verv May 14 '18 at 17:46

0 Answers0