BranchARMThumb.c 817 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* BranchARMThumb.c */
  2. #include "BranchARMThumb.h"
  3. UInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
  4. {
  5. UInt32 i;
  6. for (i = 0; i + 4 <= size; i += 2)
  7. {
  8. if ((data[i + 1] & 0xF8) == 0xF0 &&
  9. (data[i + 3] & 0xF8) == 0xF8)
  10. {
  11. UInt32 dest;
  12. UInt32 src =
  13. ((data[i + 1] & 0x7) << 19) |
  14. (data[i + 0] << 11) |
  15. ((data[i + 3] & 0x7) << 8) |
  16. (data[i + 2]);
  17. src <<= 1;
  18. if (encoding)
  19. dest = nowPos + i + 4 + src;
  20. else
  21. dest = src - (nowPos + i + 4);
  22. dest >>= 1;
  23. data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
  24. data[i + 0] = (Byte)(dest >> 11);
  25. data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
  26. data[i + 2] = (Byte)dest;
  27. i += 2;
  28. }
  29. }
  30. return i;
  31. }