forked from bodgit/sevenzip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppc.go
48 lines (35 loc) · 777 Bytes
/
ppc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package bra
import (
"encoding/binary"
"io"
)
const ppcAlignment = 4
type ppc struct {
ip uint32
}
func (c *ppc) Size() int { return ppcAlignment }
func (c *ppc) Convert(b []byte, encoding bool) int {
if len(b) < c.Size() {
return 0
}
var i int
for i = 0; i < len(b) & ^(ppcAlignment-1); i += ppcAlignment {
v := binary.BigEndian.Uint32(b[i:])
if b[i+0]&0xfc == 0x48 && b[i+3]&3 == 1 {
if encoding {
v += c.ip
} else {
v -= c.ip
}
v &= 0x03ffffff
v |= 0x48000000
}
c.ip += uint32(ppcAlignment)
binary.BigEndian.PutUint32(b[i:], v)
}
return i
}
// NewPPCReader returns a new PPC io.ReadCloser.
func NewPPCReader(_ []byte, _ uint64, readers []io.ReadCloser) (io.ReadCloser, error) {
return newReader(readers, new(ppc))
}