The Pedigree Project  0.1
x86_common/Disassembler.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Disassembler.h"
21 #include "pedigree/kernel/debugger/libudis86/udis86.h"
22 #include "pedigree/kernel/processor/types.h"
23 #include "pedigree/kernel/utilities/StaticString.h"
24 
25 X86Disassembler::X86Disassembler() : m_Location(0), m_Mode(32), m_Obj()
26 {
27  ud_init(&m_Obj);
28  ud_set_mode(&m_Obj, m_Mode);
29  ud_set_syntax(&m_Obj, UD_SYN_INTEL);
30  ud_set_pc(&m_Obj, m_Location);
31  ud_set_input_buffer(&m_Obj, reinterpret_cast<uint8_t *>(m_Location), 4096);
32 }
33 
34 X86Disassembler::~X86Disassembler()
35 {
36 }
37 
38 void X86Disassembler::setLocation(uintptr_t nLocation)
39 {
40  m_Location = nLocation;
41  ud_set_mode(&m_Obj, m_Mode);
42  ud_set_pc(&m_Obj, m_Location);
43  ud_set_input_buffer(&m_Obj, reinterpret_cast<uint8_t *>(m_Location), 4096);
44  ud_disassemble(&m_Obj);
45 }
46 
48 {
49  return m_Location;
50 }
51 
52 void X86Disassembler::setMode(size_t nMode)
53 {
54  if (nMode == 32 || nMode == 64)
55  m_Mode = nMode;
56  ud_set_mode(&m_Obj, m_Mode);
57 }
58 
60 {
61  text += ud_insn_asm(&m_Obj);
62 
63  ud_disassemble(&m_Obj);
64  m_Location = ud_insn_off(&m_Obj);
65 }
void disassemble(LargeStaticString &text)
void setLocation(uintptr_t location)
void setMode(size_t mode)