From 09c3f64d518224f8069c93cae89634e42a081694 Mon Sep 17 00:00:00 2001 From: unzner Date: Fri, 22 Jun 2012 08:56:22 +0000 Subject: [PATCH] Bugfixing in L4-Sys git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1379 8c4709b5-6ec9-48aa-a5cd-a96041d1645a --- src/experiments/l4-sys/CMakeLists.txt | 2 + src/experiments/l4-sys/UDIS86.cc | 60 +++++++++++++++++++++++++++ src/experiments/l4-sys/UDIS86.hpp | 41 ++++++++++++++++++ src/experiments/l4-sys/experiment.cc | 1 + src/experiments/l4-sys/experiment.hpp | 3 +- 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/experiments/l4-sys/UDIS86.cc create mode 100644 src/experiments/l4-sys/UDIS86.hpp diff --git a/src/experiments/l4-sys/CMakeLists.txt b/src/experiments/l4-sys/CMakeLists.txt index 98af5259..e74625fb 100644 --- a/src/experiments/l4-sys/CMakeLists.txt +++ b/src/experiments/l4-sys/CMakeLists.txt @@ -14,6 +14,8 @@ set(MY_CAMPAIGN_SRCS experiment.cc campaign.hpp campaign.cc + UDIS86.hpp + UDIS86.cc ) #### PROTOBUFS #### diff --git a/src/experiments/l4-sys/UDIS86.cc b/src/experiments/l4-sys/UDIS86.cc new file mode 100644 index 00000000..f11220bd --- /dev/null +++ b/src/experiments/l4-sys/UDIS86.cc @@ -0,0 +1,60 @@ +#include "sal/bochs/BochsController.hpp" +#include "UDIS86.hpp" + +using namespace fail; + +Udis86::Udis86(const unsigned char *instr, size_t size) { + // initialise the buffer + unsigned char *udis_instr = static_cast(malloc(size)); + memcpy(udis_instr, instr, size); + + // initialise the internal data structure + memset(&ud_obj, 0, sizeof(ud_t)); + ud_init(&ud_obj); + + // assign the buffer to the data structure + ud_set_input_buffer(&ud_obj, udis_instr, size); + + // free the buffer + free(udis_instr); +} + +bool Udis86::fetchNextInstruction() { + return (ud_disassemble(&ud_obj) > 0); +} + +GPRegisterId Udis86::udisGPRToFailBochsGPR(ud_type_t udisReg) { +#define REG_CASE(REG) case UD_R_##REG: return RID_##REG + switch (udisReg) { +#if BX_SUPPORT_X86_64 // 64 bit register id's: + REG_CASE(RAX); + REG_CASE(RCX); + REG_CASE(RDX); + REG_CASE(RBX); + REG_CASE(RSP); + REG_CASE(RBP); + REG_CASE(RSI); + REG_CASE(RDI); + REG_CASE(R8); + REG_CASE(R9); + REG_CASE(R10); + REG_CASE(R11); + REG_CASE(R12); + REG_CASE(R13); + REG_CASE(R14); + REG_CASE(R15); +#else + REG_CASE(EAX); + REG_CASE(ECX); + REG_CASE(EDX); + REG_CASE(EBX); + REG_CASE(ESP); + REG_CASE(EBP); + REG_CASE(ESI); + REG_CASE(EDI); +#endif + default: + return RID_LAST_GP_ID; + } +#undef REG_CASE +} diff --git a/src/experiments/l4-sys/UDIS86.hpp b/src/experiments/l4-sys/UDIS86.hpp new file mode 100644 index 00000000..9946961a --- /dev/null +++ b/src/experiments/l4-sys/UDIS86.hpp @@ -0,0 +1,41 @@ +#ifndef __UDIS86_HPP__ + #define __UDIS86_HPP__ + +#include +#include "sal/bochs/BochsRegister.hpp" + +/** + * \class Udis86 + * + * \brief Class to disassemble instructions + * + * This class disassembles a stream of machine code instruction + * by instruction. + * It provides a (thin) wrapper around the C API of UDIS86. + */ +class Udis86 +{ +private: + ud_t ud_obj; //