arm.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(void *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 src = ((uint32_t)(buffer[i + 2]) << 16)
  23. | ((uint32_t)(buffer[i + 1]) << 8)
  24. | (uint32_t)(buffer[i + 0]);
  25. src <<= 2;
  26. uint32_t dest;
  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, const 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. #ifdef HAVE_ENCODER_ARM
  47. extern lzma_ret
  48. lzma_simple_arm_encoder_init(lzma_next_coder *next,
  49. const lzma_allocator *allocator,
  50. const lzma_filter_info *filters)
  51. {
  52. return arm_coder_init(next, allocator, filters, true);
  53. }
  54. #endif
  55. #ifdef HAVE_DECODER_ARM
  56. extern lzma_ret
  57. lzma_simple_arm_decoder_init(lzma_next_coder *next,
  58. const lzma_allocator *allocator,
  59. const lzma_filter_info *filters)
  60. {
  61. return arm_coder_init(next, allocator, filters, false);
  62. }
  63. #endif