Bra.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Bra.h -- Branch converters for executables
  2. 2008-10-04 : Igor Pavlov : Public domain */
  3. #ifndef __BRA_H
  4. #define __BRA_H
  5. #include "Types.h"
  6. /*
  7. These functions convert relative addresses to absolute addresses
  8. in CALL instructions to increase the compression ratio.
  9. In:
  10. data - data buffer
  11. size - size of data
  12. ip - current virtual Instruction Pinter (IP) value
  13. state - state variable for x86 converter
  14. encoding - 0 (for decoding), 1 (for encoding)
  15. Out:
  16. state - state variable for x86 converter
  17. Returns:
  18. The number of processed bytes. If you call these functions with multiple calls,
  19. you must start next call with first byte after block of processed bytes.
  20. Type Endian Alignment LookAhead
  21. x86 little 1 4
  22. ARMT little 2 2
  23. ARM little 4 0
  24. PPC big 4 0
  25. SPARC big 4 0
  26. IA64 little 16 0
  27. size must be >= Alignment + LookAhead, if it's not last block.
  28. If (size < Alignment + LookAhead), converter returns 0.
  29. Example:
  30. UInt32 ip = 0;
  31. for ()
  32. {
  33. ; size must be >= Alignment + LookAhead, if it's not last block
  34. SizeT processed = Convert(data, size, ip, 1);
  35. data += processed;
  36. size -= processed;
  37. ip += processed;
  38. }
  39. */
  40. #define x86_Convert_Init(state) { state = 0; }
  41. SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
  42. SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  43. SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  44. SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  45. SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  46. SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
  47. #endif