簡體   English   中英

如何檢測和分離連接的文件?

[英]How to detect and separate concatenated files?

我試圖找到一種方法來分離使用copy /b file1+file2 file3連接在一起的兩個文件。

我知道至少兩個文件之一的 MIME 類型和文件類型。

使用以下 csharp 代碼,您可以根據 zip 文件具有 指示本地文件頭4 字節簽名這一事實進行拆分。 如果 EXE 在某些地方具有相同的 4 個字節,則此代碼將中斷。 如果你想克服這個問題,你必須挖掘PE/COFF 頭來加起來所有的部分大小

不, 逐字節復制流不是很有效......

using(var fs = new FileStream(@"exeandzip.screwed", FileMode.Open))
{
    var lfh = new byte[] { 0x50, 0x4b, 0x03, 0x04 }; /* zip local file header signature */
    var match = 0;
    var splitAt = 0;
    var keep = new Queue<int>();
    var b = fs.ReadByte();  
    using(var exe = new FileStream(
                         @"exeandzip.screwed.exe", 
                         FileMode.Create))
    {
        while((b != -1) && (match<lfh.Length))
        {   splitAt++;

            if (b==lfh[match]) 
            {
                match++; 
                keep.Enqueue(b);
            }
            else 
            {
                while(keep.Count>0)
                {
                    exe.WriteByte((byte) keep.Dequeue());
                }
                exe.WriteByte((byte)b);
                match=0;
            }
            b = fs.ReadByte();
        }
    }

    if (match==lfh.Length && b!=-1)
    {
        keep.Enqueue(b);
        splitAt = splitAt-lfh.Length;
        Console.WriteLine(splitAt);
        using(var zip = new FileStream(
                                   @"exeandzip.screwed.zip", 
                                   FileMode.Create))
        { 
            while(keep.Count>0)
            {
                zip.WriteByte((byte) keep.Dequeue());
            }
            b = fs.ReadByte();  
            while(b != -1)
            {  
                zip.WriteByte((byte)b);
                b = fs.ReadByte();
            }
        }
    }   
}

或者你可以使用foremost -i <input file> -o <output directory>

我什至用這種方式分割了蘋果的 webarchive 格式文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM