Skip to content

Commit

Permalink
Type-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Sep 22, 2022
1 parent c84bffb commit 935e441
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ struct Instruction : ZydisDecodedInstruction {
ZyanU64 address;
};

template <typename T>
concept DecoderCallback = std::invocable<T, Instruction &> &&
std::convertible_to<std::invoke_result_t<T, Instruction &>, DecoderStatus>;

struct Decoder : ZydisDecoder {
Decoder() {
detail::enforce_status(ZydisDecoderInit(this, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64));
}

template <typename T = void>
void disassemble(ZyanU64 address, std::invocable<Instruction &> auto &&callback) {
void disassemble(ZyanU64 address, DecoderCallback auto &&callback) {
Instruction instrn{};
instrn.address = address;

Expand Down Expand Up @@ -222,7 +225,7 @@ std::optional<std::ptrdiff_t> locate_udwm_desktop_manager() {

Formatter formatter{};
Decoder decoder{};
decoder.disassemble(dwm_client_startup, [&formatter, &dyn_data](Instruction &instrn) {
decoder.disassemble(dwm_client_startup, [&formatter, &dyn_data](Instruction &instrn) -> DecoderStatus {
if (instrn.mnemonic == ZYDIS_MNEMONIC_RET)
throw std::out_of_range("Failed to disasm: Reached end of function");

Expand Down

0 comments on commit 935e441

Please sign in to comment.