feh-bin 0.1.3 → 0.1.4
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/bin/feh_bin_lz +17 -3
- data/lib/feh/bin.rb +31 -8
- data/lib/feh/bin/array_ostream.rb +0 -1
- data/lib/feh/bin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: edd6d24993fac460bb3802e6e0b5bbf89eba157f95578fcddefc1978c10252de
|
|
4
|
+
data.tar.gz: 6533e94d5ccac6f450d9d30af5030e176db4b0e07469b08f7b46461d687afbab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 559d591883a1f7eff863a5f1a0e156486c6003a341b9394d0763068f4a03486cac4fba1ed095615dad4acda308231fa66bbc503185c4599c04ecf4efd91db220
|
|
7
|
+
data.tar.gz: 403236754926a1ff5addb2bcf06f67f00da021d7101dba6e3da0b1db135cbc49d0dc961f0807a0280d4fc2282da51f642bc375b6abfd800467d34ee563ec5033
|
data/Gemfile.lock
CHANGED
data/bin/feh_bin_lz
CHANGED
|
@@ -3,13 +3,27 @@
|
|
|
3
3
|
require 'feh/bin'
|
|
4
4
|
|
|
5
5
|
DESC = "Fire Emblem Heroes assets converter
|
|
6
|
-
Usage: #{File.basename(__FILE__)} <files>...
|
|
6
|
+
Usage: #{File.basename(__FILE__)} [OPTION] <files>...
|
|
7
7
|
|
|
8
8
|
Files ending in .bin.lz are converted to .bin; all other files are converted
|
|
9
|
-
into .bin.lz.
|
|
9
|
+
into .bin.lz.
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
-s Only encrypt files, do not compress using LZ11"
|
|
10
13
|
|
|
11
14
|
abort DESC if ARGV.empty? || ARGV.include?('-?') || ARGV.include?('--help')
|
|
12
15
|
|
|
16
|
+
$no_compress = false
|
|
17
|
+
|
|
18
|
+
ARGV.select {|opt| opt.start_with? '-'}.each do |opt|
|
|
19
|
+
case opt
|
|
20
|
+
when '-s'
|
|
21
|
+
$no_compress = true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
ARGV.reject! {|opt| opt.start_with? '-'}
|
|
26
|
+
|
|
13
27
|
ARGV.each do |fname|
|
|
14
28
|
begin
|
|
15
29
|
buf = IO.binread(fname)
|
|
@@ -24,7 +38,7 @@ ARGV.each do |fname|
|
|
|
24
38
|
outname = File.expand_path(
|
|
25
39
|
File.basename(fname, '.*') + '.bin.lz', File.dirname(fname))
|
|
26
40
|
puts "Compressing #{fname} -> #{outname}..."
|
|
27
|
-
res = Feh::Bin.compress(buf)
|
|
41
|
+
res = Feh::Bin.compress(buf, $no_compress)
|
|
28
42
|
raise RuntimeError, res.to_s if res.is_a?(Symbol)
|
|
29
43
|
IO.binwrite(outname, res.pack('c*'))
|
|
30
44
|
end
|
data/lib/feh/bin.rb
CHANGED
|
@@ -17,13 +17,18 @@ module Feh
|
|
|
17
17
|
|
|
18
18
|
# Compresses data into a .bin.lz file.
|
|
19
19
|
# @param buf [Array<Integer>, String] content of the data to compress
|
|
20
|
+
# @param no_compress [Boolean] true if LZ11 is not used to compress the data
|
|
20
21
|
# @return [Array<Integer>] content of the .bin.lz file
|
|
21
22
|
# @return [Symbol] error code if the input is not a valid data buffer
|
|
22
|
-
def self.compress(buf)
|
|
23
|
+
def self.compress(buf, no_compress = false)
|
|
23
24
|
buf = buf.bytes if buf.is_a?(String)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if no_compress
|
|
26
|
+
write_bin_lz04(buf, buf.size)
|
|
27
|
+
else
|
|
28
|
+
buf2 = LZ11.new(buf).compress
|
|
29
|
+
return buf2 if buf2.is_a?(Symbol)
|
|
30
|
+
write_bin_lz(buf2, buf.size)
|
|
31
|
+
end
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
# Unpacks a Fire Emblem Heroes .bin.lz file.
|
|
@@ -35,7 +40,7 @@ module Feh
|
|
|
35
40
|
header = buf.shift(4)
|
|
36
41
|
xorseed = header[1] | (header[2] << 8) | (header[3] << 16)
|
|
37
42
|
if (header.first & 0xFF) == 0x17 && (buf.first & 0xFF) == 0x11
|
|
38
|
-
xorkey = [0x8083 * xorseed].pack('<
|
|
43
|
+
xorkey = [0x8083 * xorseed].pack('<l').bytes
|
|
39
44
|
(4...buf.size).step(4).each do |i|
|
|
40
45
|
4.times {|j| buf[i + j] ^= xorkey[j]}
|
|
41
46
|
4.times {|j| xorkey[j] ^= buf[i + j]}
|
|
@@ -56,7 +61,7 @@ module Feh
|
|
|
56
61
|
header = buf.shift(4)
|
|
57
62
|
xorseed = header[1] | (header[2] << 8) | (header[3] << 16)
|
|
58
63
|
if header.first == 0x04 && xorseed == buf.size
|
|
59
|
-
xorkey = [0x8083 * xorseed].pack('<
|
|
64
|
+
xorkey = [0x8083 * xorseed].pack('<l').bytes
|
|
60
65
|
(0...buf.size).step(4).each do |i|
|
|
61
66
|
4.times {|j| buf[i + j] ^= xorkey[j]}
|
|
62
67
|
4.times {|j| xorkey[j] ^= buf[i + j]}
|
|
@@ -75,13 +80,31 @@ module Feh
|
|
|
75
80
|
bytes = bytes.bytes if bytes.is_a?(String)
|
|
76
81
|
bytes += [0] * ((-bytes.size) % 4)
|
|
77
82
|
xorseed = bytes.size if xorseed.nil?
|
|
78
|
-
header = [xorseed * 0x100 + 0x17].pack('<
|
|
79
|
-
xorkey = [0x8083 * xorseed].pack('<
|
|
83
|
+
header = [xorseed * 0x100 + 0x17].pack('<l').bytes
|
|
84
|
+
xorkey = [0x8083 * xorseed].pack('<l').bytes
|
|
80
85
|
4.times {|j| bytes[4 + j] ^= xorkey[j]}
|
|
81
86
|
(8...bytes.size).step(4).each do |i|
|
|
82
87
|
4.times {|j| bytes[i + j] ^= bytes[i - 4 + j]}
|
|
83
88
|
end
|
|
84
89
|
header + bytes
|
|
85
90
|
end
|
|
91
|
+
|
|
92
|
+
# Packs a Fire Emblem Heroes .bin.lz file.
|
|
93
|
+
# Used for files that are XOR-encrypted for FEH but not LZ11-compressed.
|
|
94
|
+
# @param bytes [Array<Integer>, String] content of an archive
|
|
95
|
+
# @param xorseed [Integer, nil] optional XOR encryption value
|
|
96
|
+
# @return [Array<Integer>] content of the packed .bin.lz file
|
|
97
|
+
def self.write_bin_lz04(bytes, xorseed = nil)
|
|
98
|
+
bytes = bytes.bytes if bytes.is_a?(String)
|
|
99
|
+
bytes += [0] * ((-bytes.size) % 4)
|
|
100
|
+
xorseed = bytes.size if xorseed.nil?
|
|
101
|
+
header = [xorseed * 0x100 + 0x04].pack('<l').bytes
|
|
102
|
+
xorkey = [0x8083 * xorseed].pack('<l').bytes
|
|
103
|
+
4.times {|j| bytes[j] ^= xorkey[j]}
|
|
104
|
+
(4...bytes.size).step(4).each do |i|
|
|
105
|
+
4.times {|j| bytes[i + j] ^= bytes[i - 4 + j]}
|
|
106
|
+
end
|
|
107
|
+
header + bytes
|
|
108
|
+
end
|
|
86
109
|
end
|
|
87
110
|
end
|
data/lib/feh/bin/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: feh-bin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Quinton Miller
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-10-
|
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|