From fd470c97f7c6a456c4dc87595c70f4fe44a341f5 Mon Sep 17 00:00:00 2001 From: Ishotihadus Date: Sun, 5 Aug 2018 18:15:33 +0900 Subject: [PATCH] add support for a header of AssetBundle on the last in the file --- lib/mikunyan/asset_bundle.rb | 2 +- lib/mikunyan/binary_reader.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/mikunyan/asset_bundle.rb b/lib/mikunyan/asset_bundle.rb index 60b54fc..314c167 100644 --- a/lib/mikunyan/asset_bundle.rb +++ b/lib/mikunyan/asset_bundle.rb @@ -73,7 +73,7 @@ module Mikunyan ui_block_size = br.i32u flags = br.i32u - head = BinaryReader.new(uncompress(br.read(ci_block_size), ui_block_size, flags)) + head = BinaryReader.new(uncompress(flags & 0x80 == 0 ? br.read(ci_block_size) : br.read_abs(ci_block_size, file_size - ci_block_size), ui_block_size, flags)) guid = head.read(16) blocks = [] diff --git a/lib/mikunyan/binary_reader.rb b/lib/mikunyan/binary_reader.rb index 1e8beeb..19da576 100644 --- a/lib/mikunyan/binary_reader.rb +++ b/lib/mikunyan/binary_reader.rb @@ -51,6 +51,14 @@ module Mikunyan data end + # Read given size of binary string from specified position. This method does not seek. + # @param [Integer] size size + # @param [Integer] pos position + # @return [String] data + def read_abs(size, pos) + @data.byteslice(pos, size) + end + # Read string until null character # @return [String] string def cstr