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