Bra.h 1.8 KB

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