arm.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file arm.c
  4. /// \brief Filter for ARM binaries
  5. ///
  6. // Authors: Igor Pavlov
  7. // Lasse Collin
  8. //
  9. // This file has been put into the public domain.
  10. // You can do whatever you want with this file.
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #include "simple_private.h"
  14. static size_t
  15. arm_code(lzma_simple *simple lzma_attribute((__unused__)),
  16. uint32_t now_pos, bool is_encoder,
  17. uint8_t *buffer, size_t size)
  18. {
  19. size_t i;
  20. for (i = 0; i + 4 <= size; i += 4) {
  21. if (buffer[i + 3] == 0xEB) {
  22. uint32_t dest;
  23. uint32_t src = (buffer[i + 2] << 16)
  24. | (buffer[i + 1] << 8)
  25. | (buffer[i + 0]);
  26. src <<= 2;
  27. if (is_encoder)
  28. dest = now_pos + (uint32_t)(i) + 8 + src;
  29. else
  30. dest = src - (now_pos + (uint32_t)(i) + 8);
  31. dest >>= 2;
  32. buffer[i + 2] = (dest >> 16);
  33. buffer[i + 1] = (dest >> 8);
  34. buffer[i + 0] = dest;
  35. }
  36. }
  37. return i;
  38. }
  39. static lzma_ret
  40. arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
  41. const lzma_filter_info *filters, bool is_encoder)
  42. {
  43. return lzma_simple_coder_init(next, allocator, filters,
  44. &arm_code, 0, 4, 4, is_encoder);
  45. }
  46. extern lzma_ret
  47. lzma_simple_arm_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
  48. const lzma_filter_info *filters)
  49. {
  50. return arm_coder_init(next, allocator, filters, true);
  51. }
  52. extern lzma_ret
  53. lzma_simple_arm_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
  54. const lzma_filter_info *filters)
  55. {
  56. return arm_coder_init(next, allocator, filters, false);
  57. }