kaitai-struct 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kaitai/struct/struct.rb +37 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e1d21f8e7714894c503f0f2c6dade3d0f462c5
|
4
|
+
data.tar.gz: da8b07352f240d0291f148822d7fbeaaf8dbc7b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a01006fb075a575e65af5a21118c5f17758a63dc0313d9c49ab0569ed2d14b93587b1d70be985b23d6795946a11ec6399c293bea800ae1c56e2cb6bf03d299
|
7
|
+
data.tar.gz: 323c1c0d0ff960c519ba089b40841ab3f28c4c53a821425d1402ba0f29ef8d91e9b1af4f019b7fa32d6886b86de6eba9045b968e83dd3cf46c1de99e6f1271c1
|
data/lib/kaitai/struct/struct.rb
CHANGED
@@ -3,7 +3,7 @@ require 'stringio'
|
|
3
3
|
module Kaitai
|
4
4
|
module Struct
|
5
5
|
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.5'
|
7
7
|
|
8
8
|
##
|
9
9
|
# Common base class for all structured generated by Kaitai Struct.
|
@@ -59,7 +59,7 @@ class Struct
|
|
59
59
|
end
|
60
60
|
|
61
61
|
##
|
62
|
-
# Kaitai::Stream is an implementation of
|
62
|
+
# Kaitai::Struct::Stream is an implementation of
|
63
63
|
# {https://github.com/kaitai-io/kaitai_struct/wiki/Kaitai-Struct-stream-API
|
64
64
|
# Kaitai Struct stream API} for Ruby. It's implemented as a wrapper
|
65
65
|
# for generic IO objects.
|
@@ -358,31 +358,46 @@ class Stream
|
|
358
358
|
|
359
359
|
##
|
360
360
|
# Performs a XOR processing with given data, XORing every byte of
|
361
|
-
# input with a single given value.
|
361
|
+
# input with a single given value. Uses pure Ruby implementation suggested
|
362
|
+
# by [Thomas Leitner](https://github.com/gettalong), borrowed from
|
363
|
+
# https://github.com/fny/xorcist/blob/master/bin/benchmark
|
362
364
|
# @param data [String] data to process
|
363
365
|
# @param key [Fixnum] value to XOR with
|
364
366
|
# @return [String] processed data
|
365
|
-
def process_xor_one(data, key)
|
366
|
-
|
367
|
+
def self.process_xor_one(data, key)
|
368
|
+
out = data.dup
|
369
|
+
i = 0
|
370
|
+
max = data.length
|
371
|
+
while i < max
|
372
|
+
out.setbyte(i, data.getbyte(i) ^ key)
|
373
|
+
i += 1
|
374
|
+
end
|
375
|
+
out
|
367
376
|
end
|
368
377
|
|
369
378
|
##
|
370
379
|
# Performs a XOR processing with given data, XORing every byte of
|
371
380
|
# input with a key array, repeating key array many times, if
|
372
381
|
# necessary (i.e. if data array is longer than key array).
|
382
|
+
# Uses pure Ruby implementation suggested by
|
383
|
+
# [Thomas Leitner](https://github.com/gettalong), borrowed from
|
384
|
+
# https://github.com/fny/xorcist/blob/master/bin/benchmark
|
373
385
|
# @param data [String] data to process
|
374
386
|
# @param key [String] array of bytes to XOR with
|
375
387
|
# @return [String] processed data
|
376
|
-
def process_xor_many(data, key)
|
377
|
-
|
378
|
-
kl =
|
388
|
+
def self.process_xor_many(data, key)
|
389
|
+
out = data.dup
|
390
|
+
kl = key.length
|
379
391
|
ki = 0
|
380
|
-
|
381
|
-
|
392
|
+
i = 0
|
393
|
+
max = data.length
|
394
|
+
while i < max
|
395
|
+
out.setbyte(i, data.getbyte(i) ^ key.getbyte(ki))
|
382
396
|
ki += 1
|
383
397
|
ki = 0 if ki >= kl
|
384
|
-
|
385
|
-
|
398
|
+
i += 1
|
399
|
+
end
|
400
|
+
out
|
386
401
|
end
|
387
402
|
|
388
403
|
##
|
@@ -394,7 +409,7 @@ class Stream
|
|
394
409
|
# @param amount [Fixnum] number of bits to shift by
|
395
410
|
# @param group_size [Fixnum] number of bytes per group to shift
|
396
411
|
# @return [String] copy of source array with requested shift applied
|
397
|
-
def process_rotate_left(data, amount, group_size)
|
412
|
+
def self.process_rotate_left(data, amount, group_size)
|
398
413
|
raise NotImplementedError.new("unable to rotate group #{group_size} bytes yet") unless group_size == 1
|
399
414
|
|
400
415
|
mask = group_size * 8 - 1
|
@@ -411,6 +426,15 @@ class Stream
|
|
411
426
|
|
412
427
|
# ========================================================================
|
413
428
|
|
429
|
+
##
|
430
|
+
# Resolves value using enum: if the value is not found in the map,
|
431
|
+
# we'll just use literal value per se.
|
432
|
+
def self.resolve_enum(enum_map, value)
|
433
|
+
enum_map[value] || value
|
434
|
+
end
|
435
|
+
|
436
|
+
# ========================================================================
|
437
|
+
|
414
438
|
private
|
415
439
|
SIGN_MASK_16 = (1 << (16 - 1))
|
416
440
|
SIGN_MASK_32 = (1 << (32 - 1))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaitai-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Yakshin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Kaitai Struct is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
|