disasm.c 2.7 KB

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