1
0

disasm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*++
  2. Copyright (c) 2012 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. disasm.h
  9. Abstract:
  10. This header contains definitions for the disassembler.
  11. Author:
  12. Evan Green 21-Jun-2012
  13. --*/
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // ------------------------------------------------------ Data Type Definitions
  19. //
  20. typedef enum _MACHINE_LANGUAGE {
  21. MachineLanguageInvalid,
  22. MachineLanguageX86,
  23. MachineLanguageArm,
  24. MachineLanguageThumb2,
  25. MachineLanguageX64,
  26. MachineLanguageCount
  27. } MACHINE_LANGUAGE, *PMACHINE_LANGUAGE;
  28. /*++
  29. Structure Description:
  30. This structure stores a disassembled instruction for use by external
  31. consumers of this module.
  32. Members:
  33. Mnemonic - Stores a pointer to the string containing the human readable
  34. assembly mnemonic associated with this instruction.
  35. DestinationOperand - Stores a pointer to the string containing the
  36. destination operand. If the instruction has only one operand, it will
  37. be this one. This can be NULL if the instruction has 0 operands.
  38. SourceOperand - Stores a pointer to the string containing the source
  39. operand. If the instruction has 2 operands, this will be the second one.
  40. This can be NULL if the instruction has 0 or 1 operands.
  41. ThirdOperand - Stores a pointer to the string containing the third operand.
  42. This will be NULL for most x86 instructions, which have no third
  43. parameter.
  44. FourthOperand - Stores a pointer to the string containing the fourth
  45. operand. This is only used on ARM.
  46. OperandAddress - Stores the numeric address if one of the operands contains
  47. an address.
  48. AddressIsValid - Stores a boolean indicating whether the address in
  49. OperandAddress is valid.
  50. AddressIsDestionation - Stores a flag indicating whether the address in
  51. OperandAddress refers to the source operand or the destination operand.
  52. BinaryLength - Stores the size of the instruction, in bytes. This can be
  53. useful for advancing the instruction stream by the number of bytes just
  54. disassembled in this instruction.
  55. --*/
  56. typedef struct _DISASSEMBLED_INSTRUCTION {
  57. PSTR Mnemonic;
  58. PSTR DestinationOperand;
  59. PSTR SourceOperand;
  60. PSTR ThirdOperand;
  61. PSTR FourthOperand;
  62. ULONGLONG OperandAddress;
  63. BOOL AddressIsValid;
  64. BOOL AddressIsDestination;
  65. ULONG BinaryLength;
  66. } DISASSEMBLED_INSTRUCTION, *PDISASSEMBLED_INSTRUCTION;
  67. //
  68. // -------------------------------------------------------- Function Prototypes
  69. //
  70. BOOL
  71. DbgDisassemble (
  72. ULONGLONG InstructionPointer,
  73. PBYTE InstructionStream,
  74. PSTR Buffer,
  75. ULONG BufferLength,
  76. PDISASSEMBLED_INSTRUCTION Disassembly,
  77. MACHINE_LANGUAGE Language
  78. );
  79. /*++
  80. Routine Description:
  81. This routine decodes one instruction from a binary instruction stream into
  82. a human readable form.
  83. Arguments:
  84. InstructionPointer - Supplies the instruction pointer for the start of the
  85. instruction stream.
  86. InstructionStream - Supplies a pointer to the binary instruction stream.
  87. Buffer - Supplies a pointer to the buffer where the human
  88. readable strings will be printed. This buffer must be allocated by the
  89. caller.
  90. BufferLength - Supplies the length of the supplied buffer.
  91. Disassembly - Supplies a pointer to the structure that will receive
  92. information about the instruction.
  93. Language - Supplies the machine language to interpret this stream as.
  94. Return Value:
  95. TRUE on success.
  96. FALSE if the instruction was unknown.
  97. --*/
  98. BOOL
  99. DbgpX86Disassemble (
  100. ULONGLONG InstructionPointer,
  101. PBYTE InstructionStream,
  102. PSTR Buffer,
  103. ULONG BufferLength,
  104. PDISASSEMBLED_INSTRUCTION Disassembly,
  105. MACHINE_LANGUAGE Language
  106. );
  107. /*++
  108. Routine Description:
  109. This routine decodes one instruction from an IA-32 binary instruction
  110. stream into a human readable form.
  111. Arguments:
  112. InstructionPointer - Supplies the instruction pointer for the start of the
  113. instruction stream.
  114. InstructionStream - Supplies a pointer to the binary instruction stream.
  115. Buffer - Supplies a pointer to the buffer where the human
  116. readable strings will be printed. This buffer must be allocated by the
  117. caller.
  118. BufferLength - Supplies the length of the supplied buffer.
  119. Disassembly - Supplies a pointer to the structure that will receive
  120. information about the instruction.
  121. Language - Supplies the type of machine langage being decoded.
  122. Return Value:
  123. TRUE on success.
  124. FALSE if the instruction was unknown.
  125. --*/
  126. BOOL
  127. DbgpArmDisassemble (
  128. ULONGLONG InsructionPointer,
  129. PBYTE InstructionStream,
  130. PSTR Buffer,
  131. ULONG BufferLength,
  132. PDISASSEMBLED_INSTRUCTION Disassembly,
  133. MACHINE_LANGUAGE Language
  134. );
  135. /*++
  136. Routine Description:
  137. This routine decodes one instruction from an ARM binary instruction
  138. stream into a human readable form.
  139. Arguments:
  140. InstructionPointer - Supplies the instruction pointer for the start of the
  141. instruction stream.
  142. InstructionStream - Supplies a pointer to the binary instruction stream.
  143. Buffer - Supplies a pointer to the buffer where the human
  144. readable strings will be printed. This buffer must be allocated by the
  145. caller.
  146. BufferLength - Supplies the length of the supplied buffer.
  147. Disassembly - Supplies a pointer to the structure that will receive
  148. information about the instruction.
  149. Language - Supplies the machine language to interpret this stream as.
  150. Return Value:
  151. TRUE on success.
  152. FALSE if the instruction was unknown.
  153. --*/