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

BROKEN uc_mem_map on windows #2055

Closed
hxm-cpp opened this issue Nov 27, 2024 · 2 comments
Closed

BROKEN uc_mem_map on windows #2055

hxm-cpp opened this issue Nov 27, 2024 · 2 comments

Comments

@hxm-cpp
Copy link

hxm-cpp commented Nov 27, 2024

problem with the build : d568885

void test_uc_mem_map()
{
    uc_engine *uc;
    uc_err err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc);
    if (err != UC_ERR_OK)
    {
        throw std::runtime_error("Failed to initialize Unicorn engine: " + std::string(uc_strerror(err)));
    }
    constexpr uint64_t start_address = 0x100000; 
    constexpr size_t map_size = 0x1000;          
    uint8_t test_data[map_size] = {0x90};        
        // crash
    	// !tcg_op_supported_x86_64()	C
 	// !tcg_set_frame_x86_64()	C
 	// !tcg_prologue_init_x86_64()	C
 	// !tcg_exec_init_x86_64()	C
 	// !machine_initialize()	C
 	// !uc_hook_del()	C
 	// !uc_mem_map()	C
    err = uc_mem_map(uc, start_address, map_size, UC_PROT_ALL);
    if (err != UC_ERR_OK)
    {
        uc_close(uc);
        throw std::runtime_error("Failed to map memory: " + std::string(uc_strerror(err)));
    }
    std::cout << "Memory mapped successfully at address: 0x" << std::hex << start_address << "\n";
    err = uc_mem_write(uc, start_address, test_data, map_size);
    if (err != UC_ERR_OK)
    {
        uc_close(uc);
        throw std::runtime_error("Failed to write to memory: " + std::string(uc_strerror(err)));
    }
    std::cout << "Memory written successfully.\n";
    uint8_t read_data[map_size] = {0};
    err = uc_mem_read(uc, start_address, read_data, map_size);
    if (err != UC_ERR_OK)
    {
        uc_close(uc);
        throw std::runtime_error("Failed to read memory: " + std::string(uc_strerror(err)));
    }
    for (size_t i = 0; i < map_size; i++)
    {
        if (read_data[i] != test_data[i])
        {
            uc_close(uc);
            throw std::runtime_error("Memory validation failed at offset: " + std::to_string(i));
        }
    }
    std::cout << "Memory validation succeeded.\n";
    uc_close(uc);
    std::cout << "Unicorn engine closed.\n";
}
@wtdcode
Copy link
Member

wtdcode commented Dec 7, 2024

Probably #1841

@wtdcode
Copy link
Member

wtdcode commented Jan 4, 2025

Closing as no activity.

@wtdcode wtdcode closed this as completed Jan 4, 2025
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