| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package org.tukaani.xz.simple; |
| 7 |
|
| 8 |
import org.tukaani.xz.common.ByteArrayView; |
| 9 |
|
| 10 |
|
| 11 |
public final class PowerPC implements SimpleFilter { |
| 12 |
private final boolean isEncoder; |
| 13 |
private int pos; |
| 14 |
|
| 15 |
public PowerPC(boolean isEncoder, int startPos) { |
| 16 |
this.isEncoder = isEncoder; |
| 17 |
pos = startPos; |
| 18 |
} |
| 19 |
|
| 20 |
@Override |
| 21 |
public int code(byte[] buf, int off, int len) { |
| 22 |
int end = off + len - 4; |
| 23 |
int i; |
| 24 |
|
| 25 |
for (i = off; i <= end; i += 4) { |
| 26 |
if ((buf[i] & 0xFC) == 0x48 && (buf[i + 3] & 0x03) == 0x01) { |
| 27 |
int instr = ByteArrayView.getIntBE(buf, i); |
| 28 |
|
| 29 |
int pc = pos + i - off; |
| 30 |
if (!isEncoder) |
| 31 |
pc = -pc; |
| 32 |
|
| 33 |
instr = 0x48000001 | ((instr + pc) & 0x03FFFFFC); |
| 34 |
ByteArrayView.setIntBE(buf, i, instr); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
i -= off; |
| 39 |
pos += i; |
| 40 |
return i; |
| 41 |
} |
| 42 |
} |