baikal 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPL-3 +674 -0
- data/History.txt +10 -0
- data/Makefile +7 -0
- data/Manifest.txt +11 -0
- data/README.txt +34 -0
- data/baikal.gemspec +20 -0
- data/lib/baikal.rb +459 -0
- data/lib/baikal/cursor.rb +297 -0
- data/lib/baikal/hexdump.rb +257 -0
- data/lib/baikal/tweak.rb +103 -0
- data/test/test_baikal.rb +61 -0
- metadata +65 -0
data/lib/baikal/tweak.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# $Id: tweak.rb 93 2009-10-19 15:05:26Z dig $
|
2
|
+
|
3
|
+
require_relative '../baikal'
|
4
|
+
|
5
|
+
module Baikal
|
6
|
+
class Pool
|
7
|
+
#
|
8
|
+
# Fetches an unsigned byte from +offset+ in this byte pool, calls
|
9
|
+
# +thunk+ with the byte as its argument, and stores the result of
|
10
|
+
# calling +thunk+ as a byte at the same +offset+.
|
11
|
+
#
|
12
|
+
# Error if the byte lies outside this byte pool.
|
13
|
+
#
|
14
|
+
def tweak_unsigned_byte offset, &thunk
|
15
|
+
set_byte offset, yield(get_unsigned_byte(offset))
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Fetches a signed byte from +offset+ in this byte pool, calls +thunk+
|
21
|
+
# with the byte as its argument, and stores the result of calling
|
22
|
+
# +thunk+ as a byte at the same +offset+.
|
23
|
+
#
|
24
|
+
# Error if the byte lies outside this byte pool.
|
25
|
+
#
|
26
|
+
def tweak_signed_byte offset, &thunk
|
27
|
+
set_byte offset, yield(get_signed_byte(offset))
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Fetches an unsigned wyde from +offset+ in this byte pool, calls
|
33
|
+
# +thunk+ with the wyde as its argument, and stores the result of
|
34
|
+
# calling +thunk+ as a wyde at the same +offset+.
|
35
|
+
#
|
36
|
+
# Error if the wyde lies outside this byte pool, even partially.
|
37
|
+
#
|
38
|
+
def tweak_unsigned_wyde offset, &thunk
|
39
|
+
set_wyde offset, yield(get_unsigned_wyde(offset))
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Fetches a signed wyde from +offset+ in this byte pool, calls +thunk+
|
45
|
+
# with the wyde as its argument, and stores the result of calling
|
46
|
+
# +thunk+ as a wyde at the same +offset+.
|
47
|
+
#
|
48
|
+
# Error if the wyde lies outside this byte pool, even partially.
|
49
|
+
#
|
50
|
+
def tweak_signed_wyde offset, &thunk
|
51
|
+
set_wyde offset, yield(get_signed_wyde(offset))
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Fetches an unsigned tetra from +offset+ in this byte pool, calls
|
57
|
+
# +thunk+ with the tetra as its argument, and stores the result of
|
58
|
+
# calling +thunk+ as a tetra at the same +offset+.
|
59
|
+
#
|
60
|
+
# Error if the tetra lies outside this byte pool, even partially.
|
61
|
+
#
|
62
|
+
def tweak_unsigned_tetra offset, &thunk
|
63
|
+
set_tetra offset, yield(get_unsigned_tetra(offset))
|
64
|
+
return
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Fetches a signed tetra from +offset+ in this byte pool, calls +thunk+
|
69
|
+
# with the tetra as its argument, and stores the result of calling
|
70
|
+
# +thunk+ as a tetra at the same +offset+.
|
71
|
+
#
|
72
|
+
# Error if the tetra lies outside this byte pool, even partially.
|
73
|
+
#
|
74
|
+
def tweak_signed_tetra offset, &thunk
|
75
|
+
set_tetra offset, yield(get_signed_tetra(offset))
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Fetches an unsigned octa from +offset+ in this byte pool, calls
|
81
|
+
# +thunk+ with the octa as its argument, and stores the result of
|
82
|
+
# calling +thunk+ as a octa at the same +offset+.
|
83
|
+
#
|
84
|
+
# Error if the octa lies outside this byte pool, even partially.
|
85
|
+
#
|
86
|
+
def tweak_unsigned_octa offset, &thunk
|
87
|
+
set_octa offset, yield(get_unsigned_octa(offset))
|
88
|
+
return
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Fetches a signed octa from +offset+ in this byte pool, calls +thunk+
|
93
|
+
# with the octa as its argument, and stores the result of calling
|
94
|
+
# +thunk+ as a octa at the same +offset+.
|
95
|
+
#
|
96
|
+
# Error if the octa lies outside this byte pool, even partially.
|
97
|
+
#
|
98
|
+
def tweak_signed_octa offset, &thunk
|
99
|
+
set_octa offset, yield(get_signed_octa(offset))
|
100
|
+
return
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/test/test_baikal.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
require_relative '../lib/baikal'
|
7
|
+
require_relative '../lib/baikal/tweak'
|
8
|
+
require_relative '../lib/baikal/hexdump'
|
9
|
+
|
10
|
+
class Test_Baikal < Test::Unit::TestCase
|
11
|
+
def test_sanity
|
12
|
+
pool = Baikal::Pool.new
|
13
|
+
pool.emit_byte(42)
|
14
|
+
assert_equal pool.bytes, '*'
|
15
|
+
pool.go_network_byte_order
|
16
|
+
pool.emit_tetra(0x41424344)
|
17
|
+
assert_equal pool.bytes,'*ABCD'
|
18
|
+
pool.truncate 1
|
19
|
+
assert_equal pool.size, 1
|
20
|
+
pool.go_reverse_network_byte_order
|
21
|
+
pool.emit_wyde(0x3132)
|
22
|
+
assert_equal pool.bytes, '*21'
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_tweak
|
27
|
+
pool = Baikal::Pool.new 'XYZ'
|
28
|
+
pool.tweak_unsigned_byte 2 do |c| c = 0x20 end
|
29
|
+
assert_equal pool.bytes, 'XY '
|
30
|
+
pool.tweak_signed_byte 1 do |c| c -= 2 end
|
31
|
+
assert_equal pool.bytes, 'XW '
|
32
|
+
pool.go_network_byte_order
|
33
|
+
pool.tweak_unsigned_wyde 1 do |c| c += 0xFF03 end
|
34
|
+
assert_equal pool.bytes, 'XV#'
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_hexdump
|
39
|
+
sport = StringIO.new
|
40
|
+
s = "Mary had a little lamb,\n" +
|
41
|
+
"His fleece was white as snow,\n" +
|
42
|
+
"And everywhere that Mary went,\n" +
|
43
|
+
"The lamb was sure to go.\n"
|
44
|
+
Baikal.hexdump s, sport
|
45
|
+
assert_equal sport.string,
|
46
|
+
"00000: 4D 61 72 79 20 68 61 64 20 61 20 6C 69 74 74 6C " +
|
47
|
+
"Mary had a littl\n" +
|
48
|
+
"00010: 65 20 6C 61 6D 62 2C 0A 48 69 73 20 66 6C 65 65 " +
|
49
|
+
"e lamb,.His flee\n" +
|
50
|
+
"00020: 63 65 20 77 61 73 20 77 68 69 74 65 20 61 73 20 " +
|
51
|
+
"ce was white as \n" +
|
52
|
+
"00030: 73 6E 6F 77 2C 0A 41 6E 64 20 65 76 65 72 79 77 " +
|
53
|
+
"snow,.And everyw\n" +
|
54
|
+
"00040: 68 65 72 65 20 74 68 61 74 20 4D 61 72 79 20 77 " +
|
55
|
+
"here that Mary w\n" +
|
56
|
+
"00050: 65 6E 74 2C 0A 54 68 65 20 6C 61 6D 62 20 77 61 " +
|
57
|
+
"ent,.The lamb wa\n" +
|
58
|
+
"00060: 73 20 73 75 72 65 20 74 6F 20 67 6F 2E 0A " +
|
59
|
+
"s sure to go.. \n"
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baikal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andres Soolo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'Baikal is a Ruby library for constructing, parsing and modifying binary
|
15
|
+
objects
|
16
|
+
|
17
|
+
(''blobs'') in a linear manner. Its primary use is facilitating custom bytecode
|
18
|
+
|
19
|
+
engines.
|
20
|
+
|
21
|
+
'
|
22
|
+
email: dig@mirky.net
|
23
|
+
executables: []
|
24
|
+
extensions: []
|
25
|
+
extra_rdoc_files:
|
26
|
+
- README.txt
|
27
|
+
files:
|
28
|
+
- GPL-3
|
29
|
+
- History.txt
|
30
|
+
- Makefile
|
31
|
+
- Manifest.txt
|
32
|
+
- README.txt
|
33
|
+
- baikal.gemspec
|
34
|
+
- lib/baikal.rb
|
35
|
+
- lib/baikal/cursor.rb
|
36
|
+
- lib/baikal/hexdump.rb
|
37
|
+
- lib/baikal/tweak.rb
|
38
|
+
- test/test_baikal.rb
|
39
|
+
homepage: https://github.com/digwuren/baikal
|
40
|
+
licenses:
|
41
|
+
- GPL-3
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.23
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A blob handling toolkit
|
64
|
+
test_files:
|
65
|
+
- test/test_baikal.rb
|