Add CFBF extractor

This commit is contained in:
Namhyeon Go 2024-04-16 17:49:11 +09:00
parent e391718b52
commit 52c31028c5
6 changed files with 100 additions and 16 deletions

View File

@ -61,6 +61,9 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Packaging, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Packaging.8.0.0\lib\net462\System.IO.Packaging.dll</HintPath>
</Reference>
<Reference Include="System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Pipelines.8.0.0\lib\net462\System.IO.Pipelines.dll</HintPath>
</Reference>
@ -87,12 +90,14 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="XmpCore, Version=6.1.10.1, Culture=neutral, PublicKeyToken=961f4f366277b80e, processorArchitecture=MSIL">
<HintPath>..\packages\XmpCore.6.1.10.1\lib\net35\XmpCore.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Model\CfbfPartInfo.cs" />
<Compile Include="Model\HashInfo.cs" />
<Compile Include="Worker1.cs" />
<Compile Include="Main.cs">
@ -108,7 +113,7 @@
<DependentUpon>UserControl2.cs</DependentUpon>
</Compile>
<Compile Include="Helper\ApkManifestExtractor.cs" />
<Compile Include="Helper\CbpfExtractor.cs" />
<Compile Include="Helper\CfbfExtractor.cs" />
<Compile Include="Helper\FileHasher.cs" />
<Compile Include="Helper\FileExtensionDatabase.cs" />
<Compile Include="Helper\PeOrganizationExtractor.cs" />

View File

@ -1,14 +0,0 @@
namespace Catswords.DataType.Client.Helper
{
public class CbpfExtractor
{
private string FilePath;
public CbpfExtractor(string filePath)
{
FilePath = filePath;
}
}
}

View File

@ -0,0 +1,71 @@
using Catswords.DataType.Client.Model;
using System.Collections.Generic;
using System.IO.Packaging;
using System.IO;
namespace Catswords.DataType.Client.Helper
{
public class CfbfExtractor
{
private string FilePath;
public CfbfExtractor(string filePath)
{
FilePath = filePath;
}
public List<CfbfPartInfo> GetParts()
{
List<CfbfPartInfo> partInfoList = new List<CfbfPartInfo>();
if (!IsValidFormat())
{
return partInfoList;
}
using (Package package = Package.Open(FilePath, FileMode.Open, FileAccess.Read))
{
foreach (PackagePart part in package.GetParts())
{
CfbfPartInfo partInfo = new CfbfPartInfo();
partInfo.URI = part.Uri.ToString();
partInfo.ContentType = part.ContentType;
using (Stream stream = part.GetStream(FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(stream))
{
partInfo.Content = reader.ReadToEnd();
}
}
partInfoList.Add(partInfo);
}
}
return partInfoList;
}
public bool IsValidFormat()
{
// CFBF 파일 시그니처 확인
byte[] signatureBytes = { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 };
byte[] fileBytes = new byte[signatureBytes.Length];
using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
{
fileStream.Read(fileBytes, 0, signatureBytes.Length);
}
for (int i = 0; i < signatureBytes.Length; i++)
{
if (fileBytes[i] != signatureBytes[i])
{
return false;
}
}
return true;
}
}
}

View File

@ -0,0 +1,9 @@
namespace Catswords.DataType.Client.Model
{
public class CfbfPartInfo: Timestamp
{
public string URI { get; set; }
public string ContentType { get; set; }
public string Content { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using Catswords.DataType.Client.Helper;
using Catswords.DataType.Client.Model;
using MetadataExtractor;
using System;
using System.Threading.Tasks;
@ -140,6 +141,16 @@ namespace Catswords.DataType.Client
}
}
public void FormCfbf()
{
var extractor = new CfbfExtractor(Parent.FilePath);
var parts = extractor.GetParts();
foreach (CfbfPartInfo part in parts)
{
Parent.AddIndicator(DateTime.Now, $"CFBF: {part.Content} ({part.ContentType}, {part.URI})", 5);
}
}
public void Run()
{
new Task(() =>
@ -148,7 +159,8 @@ namespace Catswords.DataType.Client
FromAndroidManifest(); // Get data from Android manifest
FromTimeline(); // Get data from timeline
FromLinks(); // Get links from file
FromExif(); // Get EXIF tags from file
FromExif(); // Get EXIF tags from file
FormCfbf(); // Get CFBF (aka. OLE) parts from file
}).Start();
}
}

View File

@ -6,6 +6,7 @@
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net48" />
<package id="System.IO.Packaging" version="8.0.0" targetFramework="net48" />
<package id="System.IO.Pipelines" version="8.0.0" targetFramework="net48" />
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />