BraIA64.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* BraIA64.c -- Converter for IA-64 code
  2. 2017-01-26 : Igor Pavlov : Public domain */
  3. #include "Precomp.h"
  4. #include "CpuArch.h"
  5. #include "Bra.h"
  6. SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
  7. {
  8. SizeT i;
  9. if (size < 16)
  10. return 0;
  11. size -= 16;
  12. i = 0;
  13. do
  14. {
  15. unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3;
  16. if (m)
  17. {
  18. m++;
  19. do
  20. {
  21. Byte *p = data + (i + (size_t)m * 5 - 8);
  22. if (((p[3] >> m) & 15) == 5
  23. && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0)
  24. {
  25. unsigned raw = GetUi32(p);
  26. unsigned v = raw >> m;
  27. v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3);
  28. v <<= 4;
  29. if (encoding)
  30. v += ip + (UInt32)i;
  31. else
  32. v -= ip + (UInt32)i;
  33. v >>= 4;
  34. v &= 0x1FFFFF;
  35. v += 0x700000;
  36. v &= 0x8FFFFF;
  37. raw &= ~((UInt32)0x8FFFFF << m);
  38. raw |= (v << m);
  39. SetUi32(p, raw);
  40. }
  41. }
  42. while (++m <= 4);
  43. }
  44. i += 16;
  45. }
  46. while (i <= size);
  47. return i;
  48. }