-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Stack seems to be corrupted when running on Windows #1316
Comments
A piece of minimum reproduction code: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include "unicorn.h"
// addr:
// INT 21h;
// jmp addr;
const char* cmd = "\xcd\x21\xeb\xfc";
int count = 1;
void cb(uc_engine *uc, uint32_t intno, void *user_data) {
printf("Callback count: %d\n", count);
count += 1;
}
int main() {
uc_engine* uc;
uc_err err;
printf("Start\n");
err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc);
if (err != UC_ERR_OK) {
printf("Failed to open uc\n");
return -1;
}
err = uc_mem_map(uc, 0x7000, 4 * 1024, UC_PROT_ALL);
if (err != UC_ERR_OK) {
printf("Failed to allocate memory with %d\n", err);
return -1;
}
int ip = 0x100;
int cs = 0x75a;
int address_to_load = cs * 16 + ip;
err = uc_mem_write(uc, address_to_load, cmd, 4);
if (err != UC_ERR_OK) {
printf("Failed to write memory with %d\n", err);
return -1;
}
err = uc_reg_write(uc, UC_X86_REG_IP, &ip);
if (err != UC_ERR_OK) {
printf("Failed to write register with %d\n", err);
return -1;
}
err = uc_reg_write(uc, UC_X86_REG_CS, &cs);
if (err != UC_ERR_OK) {
printf("Failed to write register with %d\n", err);
return -1;
}
uc_hook hook;
err = uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)cb, nullptr, 0, -1);
if (err != UC_ERR_OK) {
printf("Hook failed with %d\n", err);
return -1;
}
printf("Before emulation.\n");
err = uc_emu_start(uc, address_to_load, address_to_load + 4, 0, 0);
if (err != UC_ERR_OK) {
printf("Emulation error %d\n", err);
return -1;
}
printf("After emulation.\n");
uc_close(uc);
return 0;
} Update: This code works with C++ exception disabled, but it seems that we can't disable C++ exceptions for ctypes. |
wtdcode
changed the title
Unicorn crashes in uc_version
Stack seems to be corrupted when running on Windows
Sep 14, 2020
aquynh
added a commit
that referenced
this issue
Sep 15, 2020
Corresponding python script. from unicorn import *
from unicorn.x86_const import *
def test16():
count = 0
def cb(a, b, c):
nonlocal count
count += 1
print(f"Count: {count}")
if count >= 100:
mu.emu_stop()
try:
mu = Uc(UC_ARCH_X86, UC_MODE_16)
mu.mem_map(0x7000, 4 * 1024, UC_PROT_ALL)
cs = 0x75a
ip = 0x100
mu.reg_write(UC_X86_REG_IP, 0x100)
mu.reg_write(UC_X86_REG_CS, 0x75a)
address_to_load = cs * 16 + ip
mu.mem_write(address_to_load, b"\xcd\x21\xeb\xfc")
mu.hook_add(UC_HOOK_INTR, cb)
mu.emu_start(address_to_load, address_to_load + 4)
except UcError as e:
print("ERROR: %s" % e)
if __name__ == '__main__':
test16() |
Fixed in #1331 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I run Qiling tests on Windows (native, not wsl), the Unicorn crashes and causes the whole python process to die siliently. To locate the exception, I attach Windbg to python process and below is the stacktrace.
The text was updated successfully, but these errors were encountered: