github.com/bodgit/sevenzip@v1.5.1/internal/bra/arm.go (about)

     1  package bra
     2  
     3  import (
     4  	"encoding/binary"
     5  	"io"
     6  )
     7  
     8  const armAlignment = 4
     9  
    10  type arm struct {
    11  	ip uint32
    12  }
    13  
    14  func (c *arm) Size() int { return armAlignment }
    15  
    16  func (c *arm) Convert(b []byte, encoding bool) int {
    17  	if len(b) < c.Size() {
    18  		return 0
    19  	}
    20  
    21  	if c.ip == 0 {
    22  		c.ip += armAlignment
    23  	}
    24  
    25  	var i int
    26  
    27  	for i = 0; i < len(b) & ^(armAlignment-1); i += armAlignment {
    28  		v := binary.LittleEndian.Uint32(b[i:])
    29  
    30  		c.ip += uint32(armAlignment)
    31  
    32  		if b[i+3] == 0xeb {
    33  			v <<= 2
    34  
    35  			if encoding {
    36  				v += c.ip
    37  			} else {
    38  				v -= c.ip
    39  			}
    40  
    41  			v >>= 2
    42  			v &= 0x00ffffff
    43  			v |= 0xeb000000
    44  		}
    45  
    46  		binary.LittleEndian.PutUint32(b[i:], v)
    47  	}
    48  
    49  	return i
    50  }
    51  
    52  // NewARMReader returns a new ARM io.ReadCloser.
    53  func NewARMReader(_ []byte, _ uint64, readers []io.ReadCloser) (io.ReadCloser, error) {
    54  	return newReader(readers, new(arm))
    55  }