Skip to content

Commit d060e9a

Browse files
fix for "iphone 5" type 5 issue (#52)
* fix for "iphone 5" type 5 issue "type 5" error when running iphone 5, Added handling for "type 5" * add testcase for "type 5"
1 parent c4570b6 commit d060e9a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

screencapture/common/nsnumber.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func NewNSNumber(bytes []byte) (NSNumber, error) {
4545
}
4646
value := math.Float64frombits(binary.LittleEndian.Uint64(bytes[1:]))
4747
return NSNumber{typeSpecifier: typeSpecifier, FloatValue: value}, nil
48+
case 5:
49+
if len(bytes) != 5 {
50+
return NSNumber{}, fmt.Errorf("the NSNumber, type 5 should contain 4 bytes: %s", hex.Dump(bytes))
51+
}
52+
value := binary.LittleEndian.Uint32(bytes[1:])
53+
return NSNumber{typeSpecifier: typeSpecifier, IntValue: value}, nil
4854
case 4:
4955
if len(bytes) != 9 {
5056
return NSNumber{}, fmt.Errorf("the NSNumber, type 4 should contain 8 bytes: %s", hex.Dump(bytes))

screencapture/common/nsnumber_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88

99
//I took these from hexdumps
1010
var typeSix = []byte{0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x40}
11+
var typeFive = []byte{0x05, 0x2E, 00, 00, 00}
1112
var typeFour = []byte{0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
1213
var typeThree = []byte{0x03, 0x1E, 00, 00, 00}
1314

1415
const typeSixDecoded float64 = 1920
15-
const typeThreeDecoded uint32 = 30
16+
const typeFiveDecoded uint32 = 46
1617
const typeFourDecoded uint64 = 5
18+
const typeThreeDecoded uint32 = 30
1719

1820
func TestErrors(t *testing.T) {
1921
var broken []byte
@@ -36,6 +38,12 @@ func TestErrors(t *testing.T) {
3638
broken[0] = 56
3739
_, err = common.NewNSNumber(broken)
3840
assert.Error(t, err)
41+
42+
broken = make([]byte, len(typeFive))
43+
copy(broken, typeFive)
44+
broken[0] = 134
45+
_, err = common.NewNSNumber(broken)
46+
assert.Error(t, err)
3947
}
4048

4149
func TestNumberValue(t *testing.T) {
@@ -45,12 +53,17 @@ func TestNumberValue(t *testing.T) {
4553
assert.Equal(t, typeSixDecoded, float64Num.FloatValue)
4654
}
4755

56+
uint32Num, err := common.NewNSNumber(typeFive)
57+
if assert.NoError(t, err) {
58+
assert.Equal(t, typeFiveDecoded, uint32Num.IntValue)
59+
}
60+
4861
uint64Num, err := common.NewNSNumber(typeFour)
4962
if assert.NoError(t, err) {
5063
assert.Equal(t, typeFourDecoded, uint64Num.LongValue)
5164
}
5265

53-
uint32Num, err := common.NewNSNumber(typeThree)
66+
uint32Num, err = common.NewNSNumber(typeThree)
5467
if assert.NoError(t, err) {
5568
assert.Equal(t, typeThreeDecoded, uint32Num.IntValue)
5669
}

0 commit comments

Comments
 (0)