将指针地址复制到程序集中

问题描述 投票:0回答:1

我正在研究一些从数组运行程序集的代码(它是在现场生成的,但是我将简化问题)。想象一下,我有以下内容:

#include <iostream>

uint8_t Assembly[]={ 0xB0, 0x61, 0xA2, 0xBB, 0xAA, 0xFF, 0xEE, 0x00, 0xFF, 0xDD, 0xDA, 
0xC3 };
//x86_64
//0: mov al,'a'
//2: movabs [0xDADDFF00EEFFAABB], al
//11: ret

typedef void (*AsmPointer)(void);

int main(int argc, char* argv[])
{
    uint8_t SomeValue=0;
    //I need to copy this value's address into the address of the assembly instructuon
    //but this does not work
    *((uint8_t**)(Assembly+3)) = &SomeValue;
    //Code to set up Assembly as executable ommited but confirmed to function
    AsmPointer Func=(AsmPointer)Assembly;
    Func();
    std::cout << SomeValue;
    return 0;
}

[我正在尝试找到一种方法来复制SomeValue的地址以替换0xDADDFF00EEFFAABB(备用地址)。

有人知道这样做的好方法吗?

c++ assembly x86-64
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.