Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: couple of helper functions for win32 PE modules
  4. //
  5. //=============================================================================//
  6. #pragma once
  7. enum EOpCodeOffsetType
  8. {
  9. k_ENoRelativeOffsets,
  10. k_EDWORDOffsetAtByteTwo,
  11. k_EDWORDOffsetAtByteThree,
  12. k_EDWORDOffsetAtByteFour,
  13. k_EBYTEOffsetAtByteTwo,
  14. };
  15. bool ParseOpcode( unsigned char *pOpcode, int &nLength, EOpCodeOffsetType &eOffsetType );
  16. #define CALCULATE_ADDRESS(base, offset) (((DWORD)(base)) + (offset))
  17. #define GET_HEADER_DICTIONARY(module, idx) &(module)->pNtHeaders->OptionalHeader.DataDirectory[idx]
  18. // This structure describes an opcode parsed by our disassembler
  19. typedef unsigned __int32 uint32;
  20. typedef unsigned char uint8;
  21. typedef struct
  22. {
  23. int bOpcode;
  24. int cubOpcode;
  25. int cubImmed;
  26. uint32 uJump;
  27. uint32 uImmed; // not filled in
  28. bool bModRM;
  29. bool bRelative;
  30. bool bCantContinue;
  31. bool bJumpOrCall;
  32. bool bURJ;
  33. } OPCODE_t;
  34. bool ParseCode( uint8 *pubCode, OPCODE_t *pOpcode, int cubLeft );
  35. uint32 ComputeJumpAddress( OPCODE_t *pOpcode, uint32 uVACurrent );
  36. bool OpcodeText( OPCODE_t *pOpcode, char *rgchText );
  37. bool LikelyValid( OPCODE_t *pOpcode );
  38. bool LikelyNewValid( OPCODE_t *pOpcode );
  39. int DisassembleSingleFunction( unsigned char *pubStart, int cub );