How to get c code to execute hex machine code?

前端 未结 6 1709
南旧
南旧 2020-12-01 05:36

I want a simple C method to be able to run hex bytecode on a Linux 64 bit machine. Here\'s the C program that I have:

char code[] = \"\\x48\\x31\\xc0\";
#in         


        
6条回答
  •  -上瘾入骨i
    2020-12-01 06:35

    Your machine code may be all right, but your CPU objects.

    Modern CPUs manage memory in segments. In normal operation, the operating system loads a new program into a program-text segment and sets up a stack in a data segment. The operating system tells the CPU never to run code in a data segment. Your code is in code[], in a data segment. Thus the segfault.

提交回复
热议问题