1

In Borland, there is a macro __emit__, "a pseudo-function that injects literal values directly into the object code" (James Holderness).

Is there an equivalent for gcc / g++? (I can't seem to find one in the documentation)

If not, how could I implement it in my C++ source code?


Usage can be found at Metamorphic Code Examples

Community
  • 1
  • 1
J C
  • 123
  • 2
  • 11

1 Answers1

4

You can take a look at .byte assembler directive:

asm __volatile__ (".byte 0xEA, 0x00, 0x00, 0xFF, 0xFF");

GCC's optimizers sometimes discard asm statements if they determine there is no need for the output variables. Also, the optimizers may move code out of loops if they believe that the code will always return the same result (i.e. none of its input values change between calls). Using the volatile qualifier disables these optimizations.

Anyway you should pay attention to many corner cases (e.g. gcc skips asm code after goto...)

Community
  • 1
  • 1
manlio
  • 18,345
  • 14
  • 76
  • 126