したがって、この質問を見つけた他の人のために、ここに話があります:
はい、ファイルで 7-Zip が失敗する理由について、Andy は文字通り正しいですが、人々に MY バージョンの 7-Zip を正確に使用してもらうことができないため、問題の解決にはなりません。
しかし、ティラニッドは私に解決策をもたらしました。
- まず、彼が提案するように JPG に小さなバイト文字列を追加すると、7-Zip で開くことができます。ただし、有効な JPG フラグメントからわずかにずれています。FFEF00 07 504B030400 である必要があります。長さは 2 バイトずれています。
- これにより、7-Zip で開くことができますが、ファイルを抽出することはできず、黙って失敗します。これは、中央ディレクトリのエントリに、ファイルのエントリを指す内部ポインタ/オフセットがあるためです。その前にたくさんのものを置いたので、それらすべてのポインタを修正する必要があります!
- Windowsに組み込まれたzipサポートでzipを開くには、tyranidが言うように、「開始ディスク番号に対する中央ディレクトリの開始のオフセット」を修正する必要があります。最後の 2 つを実行する Python スクリプトを次に示しますが、これはフラグメントであり、copypasta ですぐに使用できるものではありません。
#Now we need to read the file and rewrite all the zip headers. Fun!
torewrite = open(magicfilename, 'rb')
magicdata = torewrite.read()
torewrite.close()
#Change the Central Repository's Offset
offsetOfCentralRepro = magicdata.find('\x50\x4B\x01\x02') #this is the beginning of the central repo
start = len(magicdata) - 6 #it so happens, that on my files, the point is stored 2 bytes from the end. so datadatadatdaata OF FS ET !! 00 00 EOF where OFFSET!! is the 4 bytes 00 00 are the last two bytes, then EOF
magicdata = magicdata[:start] + pack('I', offsetOfCentralRepro) + magicdata[start+4:]
#Now change the individual offsets in the central directory files
startOfCentralDirectoryEntry = magicdata.find('\x50\x4B\x01\x02', 0) #find the first central directory entry
startOfFileDirectoryEntry = magicdata.find('\x50\x4B\x03\x04', 10) #find the first file entry (we start at 10 because we have to skip past the first fake entry in the jpg)
while startOfCentralDirectoryEntry > 0:
#Now I move a magic number of bytes past the entry (really! It's 42!)
startOfCentralDirectoryEntry = startOfCentralDirectoryEntry + 42
#get the current offset just to output something to the terminal
(oldoffset,) = unpack('I', magicdata[startOfCentralDirectoryEntry : startOfCentralDirectoryEntry+4])
print "Old Offset: ", oldoffset, " New Offset: ", startOfFileDirectoryEntry , " at ", startOfCentralDirectoryEntry
#now replace it
magicdata = magicdata[:startOfCentralDirectoryEntry] + pack('I', startOfFileDirectoryEntry) + magicdata[startOfCentralDirectoryEntry+4:]
#now I move to the next central directory entry, and the next file entry
startOfCentralDirectoryEntry = magicdata.find('\x50\x4B\x01\x02', startOfCentralDirectoryEntry)
startOfFileDirectoryEntry = magicdata.find('\x50\x4B\x03\x04', startOfFileDirectoryEntry+1)
#Finally write the rewritten headers' data
towrite = open(magicfilename, 'wb')
towrite.write(magicdata)
towrite.close()