Rename e to uce

This commit is contained in:
momo5502
2024-08-20 12:42:25 +02:00
parent fe145a0bae
commit a0b453deb8
5 changed files with 24 additions and 24 deletions

View File

@@ -20,10 +20,10 @@ namespace
{
void setup_stack(const unicorn& uc, uint64_t stack_base, size_t stack_size)
{
e(uc_mem_map(uc, stack_base, stack_size, UC_PROT_READ | UC_PROT_WRITE));
uce(uc_mem_map(uc, stack_base, stack_size, UC_PROT_READ | UC_PROT_WRITE));
const uint64_t stack_end = stack_base + stack_size;
e(uc_reg_write(uc, UC_X86_REG_RSP, &stack_end));
uce(uc_reg_write(uc, UC_X86_REG_RSP, &stack_end));
}
unicorn_allocator setup_gs_segment(const unicorn& uc, const uint64_t segment_base, const uint64_t size)
@@ -33,15 +33,15 @@ namespace
segment_base
};
e(uc_reg_write(uc, UC_X86_REG_MSR, value.data()));
e(uc_mem_map(uc, segment_base, size, UC_PROT_READ | UC_PROT_WRITE));
uce(uc_reg_write(uc, UC_X86_REG_MSR, value.data()));
uce(uc_mem_map(uc, segment_base, size, UC_PROT_READ | UC_PROT_WRITE));
return {uc, segment_base, size};
}
void setup_kusd(const unicorn& uc)
{
e(uc_mem_map(uc, KUSD_ADDRESS, page_align_up(sizeof(KUSER_SHARED_DATA)), UC_PROT_READ));
uce(uc_mem_map(uc, KUSD_ADDRESS, page_align_up(sizeof(KUSER_SHARED_DATA)), UC_PROT_READ));
const unicorn_object<KUSER_SHARED_DATA> kusd_object{uc, KUSD_ADDRESS};
kusd_object.access([](KUSER_SHARED_DATA& kusd)
@@ -92,7 +92,7 @@ namespace
printf("Mapping %s at %llX\n", name.c_str(), binary.image_base);
e(uc_mem_write(uc, binary.image_base, ptr, optional_header.SizeOfHeaders));
uce(uc_mem_write(uc, binary.image_base, ptr, optional_header.SizeOfHeaders));
const std::span sections(IMAGE_FIRST_SECTION(nt_headers), nt_headers->FileHeader.NumberOfSections);
@@ -105,7 +105,7 @@ namespace
const void* source_ptr = ptr + section.PointerToRawData;
const auto size_of_data = std::min(section.SizeOfRawData, section.Misc.VirtualSize);
e(uc_mem_write(uc, target_ptr, source_ptr, size_of_data));
uce(uc_mem_write(uc, target_ptr, source_ptr, size_of_data));
}
uint32_t permissions = UC_PROT_NONE;
@@ -126,7 +126,7 @@ namespace
const auto size_of_section = page_align_up(std::max(section.SizeOfRawData, section.Misc.VirtualSize));
e(uc_mem_protect(uc, target_ptr, size_of_section, permissions));
uce(uc_mem_protect(uc, target_ptr, size_of_section, permissions));
}
auto& export_directory_entry = optional_header.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
@@ -320,13 +320,13 @@ namespace
uint64_t rip{};
uc_reg_read(uc, UC_X86_REG_RIP, &rip);
printf("Emulation failed at: %llX\n", rip);
e(err);
uce(err);
}
printf("Emulation done. Below is the CPU context\n");
uint64_t rax{};
e(uc_reg_read(uc, UC_X86_REG_RAX, &rax));
uce(uc_reg_read(uc, UC_X86_REG_RAX, &rax));
printf(">>> RAX = 0x%llX\n", rax);
}
@@ -339,9 +339,9 @@ int main(int /*argc*/, char** /*argv*/)
run();
return 0;
}
catch (std::exception& e)
catch (std::exception& uce)
{
puts(e.what());
puts(uce.what());
#ifdef _WIN32
//MessageBoxA(nullptr, e.what(), "ERROR", MB_ICONERROR);

View File

@@ -38,7 +38,7 @@ T access_memory_regions(const unicorn& uc, const F& accessor)
uint32_t count{};
uc_mem_region* regions{};
e(uc_mem_regions(uc, &regions, &count));
uce(uc_mem_regions(uc, &regions, &count));
const auto _ = utils::finally([&]
{
uc_free(regions);

View File

@@ -297,7 +297,7 @@ namespace
old_protection.write(current_protection);
const auto requested_protection = map_nt_to_unicorn_protection(protection);
e(uc_mem_protect(uc, address, size, requested_protection));
uce(uc_mem_protect(uc, address, size, requested_protection));
uc.reg<uint64_t>(UC_X86_REG_RAX, STATUS_SUCCESS);
}

View File

@@ -19,7 +19,7 @@ inline void ThrowIfUnicornError(const uc_err error_code)
}
}
#define e ThrowIfUnicornError
#define uce ThrowIfUnicornError
class unicorn
{
@@ -46,7 +46,7 @@ public:
T reg(const int regid) const
{
T value{};
e(uc_reg_read(this->uc_, regid, &value));
uce(uc_reg_read(this->uc_, regid, &value));
return value;
}
@@ -54,12 +54,12 @@ public:
void reg(const int regid, const S& maybe_value) const
{
T value = static_cast<T>(maybe_value);
e(uc_reg_write(this->uc_, regid, &value));
uce(uc_reg_write(this->uc_, regid, &value));
}
void stop() const
{
e(uc_emu_stop(this->uc_));
uce(uc_emu_stop(this->uc_));
}
uint64_t read_stack(const size_t index) const
@@ -67,7 +67,7 @@ public:
uint64_t result{};
const auto rsp = this->reg(UC_X86_REG_RSP);
e(uc_mem_read(this->uc_, rsp + (index * sizeof(result)), &result, sizeof(result)));
uce(uc_mem_read(this->uc_, rsp + (index * sizeof(result)), &result, sizeof(result)));
return result;
}

View File

@@ -43,21 +43,21 @@ public:
{
T obj{};
e(uc_mem_read(*this->uc_, this->address_, &obj, sizeof(obj)));
uce(uc_mem_read(*this->uc_, this->address_, &obj, sizeof(obj)));
return obj;
}
void write(const T& value) const
{
e(uc_mem_write(*this->uc_, this->address_, &value, sizeof(value)));
uce(uc_mem_write(*this->uc_, this->address_, &value, sizeof(value)));
}
template <typename F>
void access(const F& accessor) const
{
T obj{};
e(uc_mem_read(*this->uc_, this->address_, &obj, sizeof(obj)));
uce(uc_mem_read(*this->uc_, this->address_, &obj, sizeof(obj)));
accessor(obj);
@@ -113,7 +113,7 @@ public:
const auto string_buffer = this->reserve(total_length, required_alignment);
e(uc_mem_write(*this->uc_, string_buffer, str.data(), total_length));
uce(uc_mem_write(*this->uc_, string_buffer, str.data(), total_length));
result.Buffer = reinterpret_cast<PWCH>(string_buffer);
result.Length = static_cast<USHORT>(total_length);
@@ -179,7 +179,7 @@ public:
(*static_cast<internal_function*>(user_data))(address, size);
};
}
e(uc_hook_add(*this->uc_, &this->hook_, type, handler, this->function_.get(), begin, end, args...));
uce(uc_hook_add(*this->uc_, &this->hook_, type, handler, this->function_.get(), begin, end, args...));
}
unicorn_hook(const unicorn_hook&) = delete;