@@ -157,6 +157,10 @@ public function readUInt8() {
157157 return ord ($ this ->read (1 ));
158158 }
159159
160+ public function readUInt8Many ($ count ) {
161+ return array_values (unpack ("C* " , $ this ->read ($ count )));
162+ }
163+
160164 public function writeUInt8 ($ data ) {
161165 return $ this ->write (chr ($ data ), 1 );
162166 }
@@ -171,6 +175,10 @@ public function readInt8() {
171175 return $ v ;
172176 }
173177
178+ public function readInt8Many ($ count ) {
179+ return array_values (unpack ("c* " , $ this ->read ($ count )));
180+ }
181+
174182 public function writeInt8 ($ data ) {
175183 if ($ data < 0 ) {
176184 $ data += 0x100 ;
@@ -185,6 +193,10 @@ public function readUInt16() {
185193 return $ a ["n " ];
186194 }
187195
196+ public function readUInt16Many ($ count ) {
197+ return array_values (unpack ("n* " , $ this ->read ($ count * 2 )));
198+ }
199+
188200 public function readUFWord () {
189201 return $ this ->readUInt16 ();
190202 }
@@ -198,7 +210,8 @@ public function writeUFWord($data) {
198210 }
199211
200212 public function readInt16 () {
201- $ v = $ this ->readUInt16 ();
213+ $ a = unpack ("nn " , $ this ->read (2 ));
214+ $ v = $ a ["n " ];
202215
203216 if ($ v >= 0x8000 ) {
204217 $ v -= 0x10000 ;
@@ -207,6 +220,17 @@ public function readInt16() {
207220 return $ v ;
208221 }
209222
223+ public function readInt16Many ($ count ) {
224+ $ vals = array_values (unpack ("n* " , $ this ->read ($ count * 2 )));
225+ foreach ($ vals as &$ v ) {
226+ if ($ v >= 0x8000 ) {
227+ $ v -= 0x10000 ;
228+ }
229+ }
230+
231+ return $ vals ;
232+ }
233+
210234 public function readFWord () {
211235 return $ this ->readInt16 ();
212236 }
@@ -251,6 +275,12 @@ public function readLongDateTime() {
251275 $ this ->readUInt32 (); // ignored
252276 $ date = $ this ->readUInt32 () - 2082844800 ;
253277
278+ if ($ date > PHP_INT_MAX ) {
279+ $ date = PHP_INT_MAX ;
280+ } elseif ($ date < PHP_INT_MIN ) {
281+ $ date = PHP_INT_MIN ;
282+ }
283+
254284 return strftime ("%Y-%m-%d %H:%M:%S " , $ date );
255285 }
256286
@@ -319,6 +349,18 @@ public function r($type) {
319349 if ($ type [0 ] == self ::char) {
320350 return $ this ->read ($ type [1 ]);
321351 }
352+ if ($ type [0 ] == self ::uint16) {
353+ return $ this ->readUInt16Many ($ type [1 ]);
354+ }
355+ if ($ type [0 ] == self ::int16) {
356+ return $ this ->readInt16Many ($ type [1 ]);
357+ }
358+ if ($ type [0 ] == self ::uint8) {
359+ return $ this ->readUInt8Many ($ type [1 ]);
360+ }
361+ if ($ type [0 ] == self ::int8) {
362+ return $ this ->readInt8Many ($ type [1 ]);
363+ }
322364
323365 $ ret = array ();
324366 for ($ i = 0 ; $ i < $ type [1 ]; $ i ++) {
0 commit comments