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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12f43b8f3478cbe44da84b86aedbbba2777cc505095841d3b81862c53df40d32
4
- data.tar.gz: e06d68f95ad4bdc8675fc2dc9a4b46349c556a01fd0119907954c351a3b451a3
3
+ metadata.gz: edd6d24993fac460bb3802e6e0b5bbf89eba157f95578fcddefc1978c10252de
4
+ data.tar.gz: 6533e94d5ccac6f450d9d30af5030e176db4b0e07469b08f7b46461d687afbab
5
5
  SHA512:
6
- metadata.gz: 5933e1059ebe9af2e92b33d6102af96ceb45b6b8fb639b041d8a7f38c7017057a278ae9164e04729c7c0866fdc8b575709980c8b5b13b21acaacd94f10003195
7
- data.tar.gz: 95a60737d73dd0e0c26ef99a03310e436a656045b1da27f6148102db6d570f17a4c8f0b8f6ae1bda2c525b677a543f2dfa1e074be8e0ec0ff08c5ce7b7d037ca
6
+ metadata.gz: 559d591883a1f7eff863a5f1a0e156486c6003a341b9394d0763068f4a03486cac4fba1ed095615dad4acda308231fa66bbc503185c4599c04ecf4efd91db220
7
+ data.tar.gz: 403236754926a1ff5addb2bcf06f67f00da021d7101dba6e3da0b1db135cbc49d0dc961f0807a0280d4fc2282da51f642bc375b6abfd800467d34ee563ec5033
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- feh-bin (0.1.2)
4
+ feh-bin (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -19,4 +19,4 @@ DEPENDENCIES
19
19
  rake (~> 10.0)
20
20
 
21
21
  BUNDLED WITH
22
- 1.16.5
22
+ 1.16.6
@@ -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
@@ -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
- buf2 = LZ11.new(buf).compress
25
- return buf2 if buf2.is_a?(Symbol)
26
- write_bin_lz(buf2, buf.size)
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('<I').bytes
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('<I').bytes
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('<I').bytes
79
- xorkey = [0x8083 * xorseed].pack('<I').bytes
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
@@ -5,7 +5,6 @@ require 'forwardable'
5
5
  module Feh module Bin
6
6
  # Single-pass output array stream that writes little-endian integers.
7
7
  class ArrayOStream
8
-
9
8
  # @return [Array<Integer>] the stream content
10
9
  def buf
11
10
  @buf.dup
@@ -1,6 +1,6 @@
1
1
  module Feh
2
2
  module Bin
3
3
  # Version number.
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  end
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.3
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-09 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler