Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uc_mem_protect can't set readonly page to be writable #1468

Closed
bet4it opened this issue Oct 20, 2021 · 3 comments
Closed

uc_mem_protect can't set readonly page to be writable #1468

bet4it opened this issue Oct 20, 2021 · 3 comments

Comments

@bet4it
Copy link
Contributor

bet4it commented Oct 20, 2021

#include <unicorn/unicorn.h>

const unsigned char CODE[64] =  {0x01, 0x70, 0x04}; // add [eax+4], esi
unsigned char MEM[5] =  {0x00, 0x00, 0x00, 0x00};

int main()
{
    uc_engine *uc;
    int r_eax = 0x2000;
    int r_esi = 0xdeadbeef;
    uc_open(UC_ARCH_X86, UC_MODE_32, &uc);
    uc_reg_write(uc, UC_X86_REG_EAX, &r_eax);
    uc_reg_write(uc, UC_X86_REG_ESI, &r_esi);
    uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_READ | UC_PROT_EXEC);
    uc_mem_write(uc, 0x1000, CODE, sizeof(CODE));
    uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_READ);
    uc_mem_protect(uc, 0x2000, 0x1000, UC_PROT_READ | UC_PROT_WRITE);
    uc_emu_start(uc, 0x1000, 0x2000, 0, 1);
    uc_mem_read(uc, 0x2004, MEM, sizeof(MEM));
    printf("%02x %02x %02x %02x\n", MEM[0], MEM[1], MEM[2], MEM[3]);
    return 0;
}
@wtdcode
Copy link
Member

wtdcode commented Oct 20, 2021

Any exception?

@bet4it
Copy link
Contributor Author

bet4it commented Oct 20, 2021

The MEM be read should be 0xdeadbeef, but now we get 0.
The right value can be get by using uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_READ | UC_PROT_WRITE) and removing the uc_mem_protect.

@wtdcode
Copy link
Member

wtdcode commented Nov 7, 2021

Fixed in 2f61592

@wtdcode wtdcode closed this as completed Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants