Methods 分析压缩文件或任何存档文件
我想知道是否有人可以推荐一个工具来分析压缩文件或任何存档文件。我的意思不是检查归档文件中的内容,而是更多地了解它是如何被压缩的,使用什么压缩方法,等等Methods 分析压缩文件或任何存档文件,methods,compression,zip,Methods,Compression,Zip,我想知道是否有人可以推荐一个工具来分析压缩文件或任何存档文件。我的意思不是检查归档文件中的内容,而是更多地了解它是如何被压缩的,使用什么压缩方法,等等 谢谢 对于压缩到ZIP文件中的数据,命令行工具zipinfo非常有用,尤其是在使用“-v”参数(用于详细模式)时。我从中了解到zipinfo,最近我遇到了一个问题,一个工具创建的zip只能用某些程序打开,而不能用其他程序打开。问题是,目录在zip文件中没有条目,它们只是由其中存在的文件暗示的。此外,所有目录分隔符都是反斜杠,而不是正斜杠 zipi
谢谢 对于压缩到ZIP文件中的数据,命令行工具zipinfo非常有用,尤其是在使用“-v”参数(用于详细模式)时。我从中了解到zipinfo,最近我遇到了一个问题,一个工具创建的zip只能用某些程序打开,而不能用其他程序打开。问题是,目录在zip文件中没有条目,它们只是由其中存在的文件暗示的。此外,所有目录分隔符都是反斜杠,而不是正斜杠 zipinfo并没有真的帮上忙。我需要查看zip条目,所以我最终写了以下内容,这使我能够将目录条目与已知的良好版本进行区分
using System;
using System.IO;
using System.Text;
namespace ZipAnalysis
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("No filename specified");
Console.WriteLine("Press any key to exit");
Console.ReadKey(true);
return;
}
string fileName = args[0];
if (!File.Exists(fileName))
{
Console.WriteLine($"File not found: {fileName}");
Console.WriteLine("Press any key to exit");
Console.ReadKey(true);
return;
}
using (var file = File.OpenRead(fileName))
{
//First, find the End of central directory record
BinaryReader reader = new BinaryReader(file);
int entryCount = ReadEndOfCentralDirectory(reader);
if (entryCount > 0)
{
ReadCentralDirectory(reader, entryCount);
}
}
Console.WriteLine("Press any key to exit");
Console.ReadKey(true);
}
private static int ReadEndOfCentralDirectory(BinaryReader reader)
{
var b = reader.ReadByte();
int result = 0;
long fileSize = reader.BaseStream.Length;
while (result == 0 && reader.BaseStream.Position < fileSize)
{
while (b != 0x50)
{
if (reader.BaseStream.Position < fileSize)
b = reader.ReadByte();
else
break;
}
if (reader.BaseStream.Position >= fileSize)
{
break;
}
if (reader.ReadByte() == 0x4b && reader.ReadByte() == 0x05 && reader.ReadByte() == 0x06)
{
int diskNumber = reader.ReadInt16();
int centralDirectoryStartDiskNumber = reader.ReadInt16();
int centralDirectoryCount = reader.ReadInt16();
int centralDirectoryTotal = reader.ReadInt16();
result = centralDirectoryTotal;
int centralDirectorySize = reader.ReadInt32();
int centralDirectoryOffset = reader.ReadInt32();
int commentLength = reader.ReadInt16();
string comment = Encoding.ASCII.GetString(reader.ReadBytes(commentLength));
Console.WriteLine("EOCD Found");
Console.WriteLine($"Disk Number: {diskNumber}");
Console.WriteLine($"Central Directory Disk Number: {centralDirectoryStartDiskNumber}");
Console.WriteLine($"Central Directory Count: {centralDirectoryCount}");
Console.WriteLine($"Central Directory Total: {centralDirectoryTotal}");
Console.WriteLine($"Central Directory Size: {centralDirectorySize}");
Console.WriteLine($"Central Directory Offset: {centralDirectoryOffset}");
Console.WriteLine($"Comment: {comment}");
reader.BaseStream.Seek(centralDirectoryOffset, SeekOrigin.Begin);
}
b=0;
}
return result;
}
private static void ReadCentralDirectory(BinaryReader reader, int count)
{
for (int i = 0; i < count; i++)
{
var signature = reader.ReadInt32();
if (signature == 0x02014b50)
{
Console.WriteLine($"Version Made By: {reader.ReadInt16()}");
Console.WriteLine($"Minimum version to extract: {reader.ReadInt16()}");
Console.WriteLine($"Bit Flag: {reader.ReadInt16()}");
Console.WriteLine($"Compression Method: {reader.ReadInt16()}");
Console.WriteLine($"File Last Modification Time: {reader.ReadInt16()}");
Console.WriteLine($"File Last Modification Date: {reader.ReadInt16()}");
Console.WriteLine($"CRC: {reader.ReadInt32()}");
Console.WriteLine($"CompressedSize: {reader.ReadInt32()}");
Console.WriteLine($"UncompressedSize: {reader.ReadInt32()}");
var fileNameLength = reader.ReadInt16();
var extraFieldLength = reader.ReadInt16();
var fileCommentLength = reader.ReadInt16();
Console.WriteLine($"Disk number where file starts: {reader.ReadInt16()}");
Console.WriteLine($"Internal file attributes: {reader.ReadInt16()}");
Console.WriteLine($"External file attributes: {reader.ReadInt32()}");
Console.WriteLine($"Relative offset of local file header: {reader.ReadInt32()}");
string filename = Encoding.ASCII.GetString(reader.ReadBytes(fileNameLength));
string extraField = Encoding.ASCII.GetString(reader.ReadBytes(extraFieldLength));
string fileComment = Encoding.ASCII.GetString(reader.ReadBytes(fileCommentLength));
Console.WriteLine($"Filename: {filename}");
Console.WriteLine($"Extra Field: {extraField}");
Console.WriteLine($"File Comment: {fileComment}");
}
}
}
}
}
使用系统;
使用System.IO;
使用系统文本;
名称空间分析
{
班级计划
{
静态void Main(字符串[]参数)
{
如果(参数长度<1)
{
Console.WriteLine(“未指定文件名”);
Console.WriteLine(“按任意键退出”);
Console.ReadKey(true);
返回;
}
字符串文件名=args[0];
如果(!File.Exists(fileName))
{
WriteLine($“未找到文件:{fileName}”);
Console.WriteLine(“按任意键退出”);
Console.ReadKey(true);
返回;
}
使用(var file=file.OpenRead(文件名))
{
//首先,找到中央目录记录的结尾
BinaryReader=新的BinaryReader(文件);
int entryCount=ReadEndOfCentralDirectory(reader);
如果(入口计数>0)
{
ReadCentralDirectory(reader,entryCount);
}
}
Console.WriteLine(“按任意键退出”);
Console.ReadKey(true);
}
私有静态int ReadEndOfCentralDirectory(BinaryReader)
{
var b=reader.ReadByte();
int结果=0;
long fileSize=reader.BaseStream.Length;
while(result==0&&reader.BaseStream.Position=文件大小)
{
打破
}
if(reader.ReadByte()==0x4b&&reader.ReadByte()==0x05&&reader.ReadByte()==0x06)
{
int diskNumber=reader.ReadInt16();
int centralDirectoryStartDiskNumber=reader.ReadInt16();
int centralDirectoryCount=reader.ReadInt16();
int centralDirectoryTotal=reader.ReadInt16();
结果=中心目录剂;
int centralDirectorySize=reader.ReadInt32();
int centralDirectoryOffset=reader.ReadInt32();
int commentLength=reader.ReadInt16();
字符串注释=Encoding.ASCII.GetString(reader.ReadBytes(commentLength));
Console.WriteLine(“找到EOCD”);
WriteLine($“磁盘号:{diskNumber}”);
WriteLine($“中央目录磁盘号:{centralDirectoryStartDiskNumber}”);
WriteLine($“中心目录计数:{centralDirectoryCount}”);
WriteLine($“中心目录总数:{centralDirectoryTotal}”);
WriteLine($“中心目录大小:{centralDirectorySize}”);
WriteLine($“中心目录偏移量:{centralDirectoryOffset}”);
WriteLine($“Comment:{Comment}”);
reader.BaseStream.Seek(centralDirectoryOffset,SeekOrigin.Begin);
}
b=0;
}
返回结果;
}
私有静态void ReadCentralDirectory(二进制读取器,int计数)
{
for(int i=0;i