forked from bodgit/sevenzip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm.go
55 lines (40 loc) · 827 Bytes
/
arm.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
49
50
51
52
53
54
55
package bra
import (
"encoding/binary"
"io"
)
const armAlignment = 4
type arm struct {
ip uint32
}
func (c *arm) Size() int { return armAlignment }
func (c *arm) Convert(b []byte, encoding bool) int {
if len(b) < c.Size() {
return 0
}
if c.ip == 0 {
c.ip += armAlignment
}
var i int
for i = 0; i < len(b) & ^(armAlignment-1); i += armAlignment {
v := binary.LittleEndian.Uint32(b[i:])
c.ip += uint32(armAlignment)
if b[i+3] == 0xeb {
v <<= 2
if encoding {
v += c.ip
} else {
v -= c.ip
}
v >>= 2
v &= 0x00ffffff
v |= 0xeb000000
}
binary.LittleEndian.PutUint32(b[i:], v)
}
return i
}
// NewARMReader returns a new ARM io.ReadCloser.
func NewARMReader(_ []byte, _ uint64, readers []io.ReadCloser) (io.ReadCloser, error) {
return newReader(readers, new(arm))
}