#pragma once
#include "types.hpp"
#include "loader/binary.hpp"
#include <capstone/capstone.h>

class Disassembler
{
    public:
        Disassembler();
        ~Disassembler();

        bool init(Arch arch);
        vector<Instruction> disassemble(const vector<uint8_t>& bytes, addr_t base, size_t count = 0);
        bool isProlog(const vector<Instruction>& insts) const;
        bool isEpilog(const Instruction& inst) const;
        bool isReturn(const Instruction& inst) const;
        bool isTrap(const Instruction& inst) const;
        bool isCall(const Instruction& inst) const;
        bool isUnconditionalBranch(const Instruction& inst) const;
        bool isConditionalBranch(const Instruction& inst) const;
        bool isIndirectBranch(const Instruction& inst) const;
        addr_t getBranchTarget(const Instruction& inst) const;
        int64_t getRIPDisp(const Instruction& inst) const;

    private:
        csh m_handle;
        bool m_initialized;
};
