首页 > 解决方案 > 如何将模块化代码更改为 OOP 设计?

问题描述

我正在尝试将这个 c 的自突变示例移植到 c++,但是我遇到了指针问题,以使其适用于 c++ OOP 的这个示例。我已经更改了显示数据的部分,但是如何更改其余的指针?

啊啊啊

void aa::display(std::string data){
    const char* str;
    str = data.data();
    std::cout << str << std::endl;

}

void aa::printfFunctionStub() {}

void aa::enc(DWORD dwAddress, DWORD dwSize) {
    __asm {
        mov ecx, dwAddress
        add ecx, dwSize
        mov eax, dwAddress
        C_loop :
        xor byte ptr ds : [eax], 0x5A
            inc eax
            cmp eax, ecx
            jl C_loop;
    }
}

aa.cpp

class aa{
public:
    void debugger();
    bool IsVmRunning();
    void sandbox();
    void foo(void);
    void display(std::string data);
    void printfFunctionStub();
    void enc(DWORD dwAddress, DWORD dwSize);
};

主文件

int main(){

DWORD dwPrintFunctionSize = 0, dwOldProtect; 双字 *fA = NULL,*fB = NULL;

    // Obtain the addresses for the functions so we can calculate size.
    fA = (DWORD *)&printfFunction;
    fB = (DWORD *)&printfFunctionStub;
    // Get total function size
    dwPrintFunctionSize = (fB - fA);

    // Test the function
     aa.display("Hello A!\n");

    // We need to give ourselves access to modifify data at the given address
    VirtualProtect(fA, dwPrintFunctionSize, PAGE_READWRITE, &dwOldProtect);
    enc((DWORD)fA, dwPrintFunctionSize); // XOR encrypt the function
    enc((DWORD)fA, dwPrintFunctionSize); // XOR decrypt the function

    // Restore the old protection
    VirtualProtect(fA, dwPrintFunctionSize, dwOldProtect, NULL);

    // Test the function
    aa.display("Hello B!\n");

    _getch();
    return 0;
}

标签: c++oopself-modifying

解决方案


推荐阅读