1

I am trying to porting this sample of self-mutation of c to c++, but i am having problems with pointers to make it work this example for c++ OOP. I have changed this the part of displaying the data , but how can I change the rest of pointers?

aa.h

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);
};

main.cpp

int main(){

DWORD dwPrintFunctionSize = 0, dwOldProtect; DWORD *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;
}
cyb3rpunk
  • 61
  • 7

0 Answers0