Class: ExtremeUnZip
- Inherits:
-
Object
- Object
- ExtremeUnZip
- Defined in:
- lib/extremeunzip.zzaqsu.rb
Instance Method Summary collapse
- #extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) ⇒ Object
- #exuz(rootPath) ⇒ Object
-
#initialize ⇒ ExtremeUnZip
constructor
A new instance of ExtremeUnZip.
- #readVfsDataList(wholeCbor) ⇒ Object
Constructor Details
#initialize ⇒ ExtremeUnZip
Returns a new instance of ExtremeUnZip.
12 13 14 |
# File 'lib/extremeunzip.zzaqsu.rb', line 12 def initialize # 移除 StreamDecoder 初始化,改为直接调用 LZMA.decompress end |
Instance Method Details
#extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/extremeunzip.zzaqsu.rb', line 43 def extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) dataFileName = 'victoriafreshdata.w' expected_block_length = nil if (fileVersion == 14) compressedVfsData = wholeCbor['vfsData'] victoriaFreshData = LZMA.decompress(compressedVfsData) File.open(dataFileName, 'wb') do |dataFile| dataFile.syswrite(victoriaFreshData) puts "After writing initial block, raw data file size: #{File.size(dataFileName)}" end elsif (fileVersion >= 30) compressedVfsDataList = wholeCbor['vfsDataList'] if (fileVersion >= 251) compressedVfsDataList = readVfsDataList(wholeCbor) end puts("data block amount: #{compressedVfsDataList.length}") dataBlockCounter = 0 previous_block_length = nil File.open(dataFileName, 'wb') do |dataFile| compressedVfsDataList.each_with_index do |currentCompressed, index| puts("data block counter: #{dataBlockCounter}") checkMemoryUsage(34) begin currentRawData = LZMA.decompress(currentCompressed) if previous_block_length.nil? previous_block_length = currentRawData.length expected_block_length ||= previous_block_length elsif currentRawData.length != previous_block_length || currentRawData.length == 0 if currentRawData.length == 0 puts "Warning: decompressed block length is zero at block #{index}. Generating fake data of expected length." # 如果当前解压数据长度为0,则创建一个指定长度的伪造数据块 currentRawData = "\x00" * expected_block_length else puts "Warning: unexpected decompressed block length detected at block #{index}. Previous length: #{previous_block_length}, current length: #{currentRawData.length}" end end dataFile.syswrite(currentRawData) puts "After writing block #{index}, raw data file size: #{File.size(dataFileName)}" rescue RuntimeError => e puts "Warning: the exz file may be incomplete at block #{index}. Error: #{e.}" # 创建一个填充用的假数据块 fake_data_block = "\x00" * expected_block_length dataFile.syswrite(fake_data_block) puts "After writing fake block #{index}, raw data file size: #{File.size(dataFileName)}" next end dataBlockCounter += 1 end end end dataFileName end |
#exuz(rootPath) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/extremeunzip.zzaqsu.rb', line 108 def exuz(rootPath) result = true begin currentBlockFile = File.new(rootPath, 'rb') @wholeFileContent = currentBlockFile.read currentBlockFile.close checkMemoryUsage(60) wholeCborByteArray = @wholeFileContent[4..-1] = {:tolerant => true} wholeCbor = CBOR.decode(wholeCborByteArray, ) fileVersion = wholeCbor['version'] if (fileVersion < 14) checkMemoryUsage(85) puts 'file version too old' else compressedVfsMenu = wholeCbor['vfsMenu'] puts "compressed vfs menu size: #{compressedVfsMenu.size}" checkMemoryUsage(90) replyByteArray = LZMA.decompress(compressedVfsMenu) checkMemoryUsage(95) victoriaFreshDataFile = extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) checkMemoryUsage(100) $clipDownloader = VictoriaFresh.new $clipDownloader.releaseFilesExternalDataFile(replyByteArray, victoriaFreshDataFile) File.delete(victoriaFreshDataFile) end result = true rescue EOFError => e puts "Error: the exz file may be incomplete. Error: #{e.}" result = false rescue => e puts "Unexpected error: #{e.}" result = false end end |
#readVfsDataList(wholeCbor) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/extremeunzip.zzaqsu.rb', line 16 def readVfsDataList(wholeCbor) compressedVfsDataList = [] startIndix = wholeCbor['vfsDataListStart'] puts "whole length: #{@wholeFileContent.length}, list content: #{wholeCbor['vfsDataList']}" # Debug expected_block_length = nil wholeCbor['vfsDataList'].each do |currentBlockInfo| length = currentBlockInfo['length'] if expected_block_length.nil? expected_block_length = length elsif length != expected_block_length puts "Warning: unexpected block length detected. Expected: #{expected_block_length}, got: #{length}" end currentBlock = @wholeFileContent[startIndix, length] compressedVfsDataList << currentBlock startIndix += length end compressedVfsDataList end |