equal
deleted
inserted
replaced
1 /* BranchPPC.c */ |
|
2 |
|
3 #include "BranchPPC.h" |
|
4 |
|
5 UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) |
|
6 { |
|
7 UInt32 i; |
|
8 for (i = 0; i + 4 <= size; i += 4) |
|
9 { |
|
10 /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */ |
|
11 if ((data[i] >> 2) == 0x12 && |
|
12 ( |
|
13 (data[i + 3] & 3) == 1 |
|
14 /* || (data[i+3] & 3) == 3 */ |
|
15 ) |
|
16 ) |
|
17 { |
|
18 UInt32 src = ((data[i + 0] & 3) << 24) | |
|
19 (data[i + 1] << 16) | |
|
20 (data[i + 2] << 8) | |
|
21 (data[i + 3] & (~3)); |
|
22 |
|
23 UInt32 dest; |
|
24 if (encoding) |
|
25 dest = nowPos + i + src; |
|
26 else |
|
27 dest = src - (nowPos + i); |
|
28 data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); |
|
29 data[i + 1] = (Byte)(dest >> 16); |
|
30 data[i + 2] = (Byte)(dest >> 8); |
|
31 data[i + 3] &= 0x3; |
|
32 data[i + 3] |= dest; |
|
33 } |
|
34 } |
|
35 return i; |
|
36 } |
|