feh-bin 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +10 -0
- data/lib/feh/bin.rb +18 -21
- data/lib/feh/bin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0304cfd58f785acb4908eb96856da9380ae89e6161d7d450ab2e40ea2d465ce0
|
|
4
|
+
data.tar.gz: 671afa221a5a7d418c6baec3d8517a38b1dcd6f0a83da55a712f515ea3db71ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f3585ad8d91ffc43b3af67fd918ffe74435155f33f247d605175352805c7edf709566de3b3e0bc10fa8efbf29fa58f188535e73c3175c6a2a1c5bec545a53aa
|
|
7
|
+
data.tar.gz: 01baff5c76e53a9cdd6b2e6432be210197fec4158292dbc0c26e38015bc24627f15e6fb3de1da3362e0142fdb3569921a36ce4a50cd634107b33b9700f3872df
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -26,6 +26,16 @@ Dir.glob('assets/Common/SRPGMap/*.bin.lz').each do |fname|
|
|
|
26
26
|
end
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## Changelog
|
|
30
|
+
|
|
31
|
+
### V0.1.2
|
|
32
|
+
|
|
33
|
+
- Fixed double encryption issue in `Feh::Bin.compress`
|
|
34
|
+
|
|
35
|
+
### V0.1.0
|
|
36
|
+
|
|
37
|
+
- Initial release
|
|
38
|
+
|
|
29
39
|
## License
|
|
30
40
|
|
|
31
41
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/feh/bin.rb
CHANGED
|
@@ -10,10 +10,9 @@ module Feh
|
|
|
10
10
|
# @return [Symbol] error code if the input is not a valid .bin.lz file
|
|
11
11
|
def self.decompress(buf)
|
|
12
12
|
buf = buf.bytes if buf.is_a?(String)
|
|
13
|
-
read_bin_lz(buf)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# LZ11.new(buf).decompress
|
|
13
|
+
buf2 = read_bin_lz(buf)
|
|
14
|
+
return buf2 if buf2.is_a?(Symbol)
|
|
15
|
+
LZ11.new(buf2).decompress
|
|
17
16
|
end
|
|
18
17
|
|
|
19
18
|
# Compresses data into a .bin.lz file.
|
|
@@ -22,9 +21,9 @@ module Feh
|
|
|
22
21
|
# @return [Symbol] error code if the input is not a valid data buffer
|
|
23
22
|
def self.compress(buf)
|
|
24
23
|
buf = buf.bytes if buf.is_a?(String)
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
write_bin_lz(buf)
|
|
24
|
+
buf2 = LZ11.new(buf).compress
|
|
25
|
+
return buf2 if buf2.is_a?(Symbol)
|
|
26
|
+
write_bin_lz(buf2, buf.size)
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
# Unpacks a Fire Emblem Heroes .bin.lz file.
|
|
@@ -41,29 +40,27 @@ module Feh
|
|
|
41
40
|
4.times {|j| buf[i + j] ^= xorkey[j]}
|
|
42
41
|
4.times {|j| xorkey[j] ^= buf[i + j]}
|
|
43
42
|
end
|
|
44
|
-
LZ11.new(buf).decompress
|
|
45
|
-
elsif header.first == 0x04 && xorseed == buf.size
|
|
46
|
-
xorkey = [0x8083 * xorseed].pack('<I').bytes
|
|
47
|
-
(0...buf.size).step(4).each do |i|
|
|
48
|
-
4.times {|j| buf[i + j] ^= xorkey[j]}
|
|
49
|
-
4.times {|j| xorkey[j] ^= buf[i + j]}
|
|
50
|
-
end
|
|
51
43
|
buf
|
|
44
|
+
# elsif header.first == 0x04 && xorseed == buf.size
|
|
45
|
+
# xorkey = [0x8083 * xorseed].pack('<I').bytes
|
|
46
|
+
# (0...buf.size).step(4).each do |i|
|
|
47
|
+
# 4.times {|j| buf[i + j] ^= xorkey[j]}
|
|
48
|
+
# 4.times {|j| xorkey[j] ^= buf[i + j]}
|
|
49
|
+
# end
|
|
50
|
+
# buf
|
|
52
51
|
else
|
|
53
52
|
:invalid_archive
|
|
54
53
|
end
|
|
55
54
|
end
|
|
56
55
|
|
|
57
56
|
# Packs a Fire Emblem Heroes .bin.lz file.
|
|
58
|
-
# @param
|
|
57
|
+
# @param bytes [Array<Integer>, String] content of an LZ11 archive
|
|
58
|
+
# @param xorseed [Integer, nil] optional XOR encryption value
|
|
59
59
|
# @return [Array<Integer>] content of the packed .bin.lz file
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
buf = buf.bytes if buf.is_a?(String)
|
|
63
|
-
bytes = LZ11.new(buf).compress
|
|
64
|
-
return bytes if bytes.is_a?(Symbol)
|
|
60
|
+
def self.write_bin_lz(bytes, xorseed = nil)
|
|
61
|
+
bytes = bytes.bytes if bytes.is_a?(String)
|
|
65
62
|
bytes += [0] * ((-bytes.size) % 4)
|
|
66
|
-
xorseed =
|
|
63
|
+
xorseed = bytes.size if xorseed.nil?
|
|
67
64
|
header = [xorseed * 0x100 + 0x17].pack('<I').bytes
|
|
68
65
|
xorkey = [0x8083 * xorseed].pack('<I').bytes
|
|
69
66
|
4.times {|j| bytes[4 + j] ^= xorkey[j]}
|
data/lib/feh/bin/version.rb
CHANGED