1
0

disasm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.c
  9. Abstract:
  10. This module contains routines for disassembling x86 binary code.
  11. Author:
  12. Evan Green 21-Jun-2012
  13. Environment:
  14. Debugging client
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <minoca/lib/types.h>
  20. #include "disasm.h"
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. //
  25. // ---------------------------------------------------------------- Definitions
  26. //
  27. //
  28. // ----------------------------------------------- Internal Function Prototypes
  29. //
  30. //
  31. // ------------------------------------------------------ Data Type Definitions
  32. //
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. BOOL
  37. DbgDisassemble (
  38. ULONGLONG InstructionPointer,
  39. PBYTE InstructionStream,
  40. PSTR Buffer,
  41. ULONG BufferLength,
  42. PDISASSEMBLED_INSTRUCTION Disassembly,
  43. MACHINE_LANGUAGE Language
  44. )
  45. /*++
  46. Routine Description:
  47. This routine decodes one instruction from a binary instruction stream into
  48. a human readable form.
  49. Arguments:
  50. InstructionPointer - Supplies the instruction pointer for the start of the
  51. instruction stream.
  52. InstructionStream - Supplies a pointer to the binary instruction stream.
  53. Buffer - Supplies a pointer to the buffer where the human
  54. readable strings will be printed. This buffer must be allocated by the
  55. caller.
  56. BufferLength - Supplies the length of the supplied buffer.
  57. Disassembly - Supplies a pointer to the structure that will receive
  58. information about the instruction.
  59. Language - Supplies the machine language to interpret this stream as.
  60. Return Value:
  61. TRUE on success.
  62. FALSE if the instruction was unknown.
  63. --*/
  64. {
  65. BOOL Result;
  66. switch (Language) {
  67. case MachineLanguageX86:
  68. case MachineLanguageX64:
  69. Result = DbgpX86Disassemble(InstructionPointer,
  70. InstructionStream,
  71. Buffer,
  72. BufferLength,
  73. Disassembly,
  74. Language);
  75. break;
  76. case MachineLanguageArm:
  77. case MachineLanguageThumb2:
  78. Result = DbgpArmDisassemble(InstructionPointer,
  79. InstructionStream,
  80. Buffer,
  81. BufferLength,
  82. Disassembly,
  83. Language);
  84. break;
  85. default:
  86. Result = FALSE;
  87. goto DisassembleEnd;
  88. }
  89. DisassembleEnd:
  90. return Result;
  91. }
  92. //
  93. // --------------------------------------------------------- Internal Functions
  94. //