Add IP and URL extractor

This commit is contained in:
Namhyeon Go 2024-04-15 17:21:31 +09:00
parent 325c9ab13e
commit 05b6541e2a
18 changed files with 192 additions and 54 deletions

View File

@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="BencodeNET, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BencodeNET.4.0.0\lib\netstandard2.0\BencodeNET.dll</HintPath>
@ -39,6 +42,9 @@
<Reference Include="Crc32.NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dc0b95cf99bf4e99, processorArchitecture=MSIL">
<HintPath>..\packages\Crc32.NET.1.2.0\lib\net20\Crc32.NET.dll</HintPath>
</Reference>
<Reference Include="MetadataExtractor, Version=2.8.1.0, Culture=neutral, PublicKeyToken=b66b5ccaf776c301, processorArchitecture=MSIL">
<HintPath>..\packages\MetadataExtractor.2.8.1\lib\net45\MetadataExtractor.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
@ -81,6 +87,9 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<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" />
@ -101,6 +110,7 @@
<Compile Include="Helper\FileExtensionDB.cs" />
<Compile Include="Helper\FileCompany.cs" />
<Compile Include="Helper\FileMagic.cs" />
<Compile Include="Helper\LinkExtractor.cs" />
<Compile Include="Helper\ImpHash.cs" />
<Compile Include="Helper\OpenXMLExtractor.cs" />
<Compile Include="Helper\Timeline.cs" />
@ -156,39 +166,12 @@
<ItemGroup>
<None Include="Resources\icon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\fediverse.1024x1020.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\fediverse.256x255.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon_32.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\officedatabase_103574.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\database_theapplication_3365.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\chat_bubble_talk_conversation_talking_snapchat_icon-icons.com_59964.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\message_bubble_conversation_speech_communication_talk_chat_icon_219299.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\data_96285.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\data_database_icon_177024.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ok_done_yes_accept_checklist_checkmark_icon_232033.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\checkmark_checklist_agenda_schedule_budget_wedding_cost_list_planner_icon_255066.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\document_paperclip_list_paper_icon_219544.png" />
</ItemGroup>
@ -208,5 +191,8 @@
<ItemGroup>
<None Include="Resources\office_18907.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\link-symbol_icon-icons.com_56927.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -35,12 +35,13 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(384, 469);
this.ClientSize = new System.Drawing.Size(384, 517);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = global::Catswords.DataType.Client.Properties.Resources.icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Catswords.DataType.Client";
this.Icon = Properties.Resources.icon;
this.ResumeLayout(false);
}

View File

@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Catswords.DataType.Client.Helper
{
class LinkExtractor
{
private string FilePath;
public LinkExtractor(string filePath)
{
FilePath = filePath;
}
private void ProcessFile(string srcfile, List<string> results)
{
// Read the binary file
byte[] data = File.ReadAllBytes(srcfile);
// Convert binary data to string
string binaryString = Encoding.ASCII.GetString(data);
// Regular expression to match IP address pattern
string ipPattern = @"(?<!\d)(?:\d{1,3}\.){3}\d{1,3}(?!\d)";
// Regular expression to match URL pattern
string urlPattern = @"(?:http|https):\/\/[\w\-_]+(?:\.[\w\-_]+)+[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#]";
// Match IP addresses
MatchCollection ipMatches = Regex.Matches(binaryString, ipPattern);
foreach (Match match in ipMatches)
{
results.Add(match.Value);
}
// Match URLs
MatchCollection urlMatches = Regex.Matches(binaryString, urlPattern);
foreach (Match match in urlMatches)
{
results.Add(match.Value);
}
}
private bool IsZipFile()
{
try
{
using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[4];
int bytesRead = fs.Read(buffer, 0, 4);
if (bytesRead >= 4)
{
string fileSignature = BitConverter.ToString(buffer);
return fileSignature == "50-4B-03-04"; // "PK" signature for zip files
}
else
{
// File is too small to read signature
return false;
}
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}");
return false;
}
}
public string[] GetStrings()
{
List<string> results = new List<string>();
try
{
// Check if the file is a zip file
bool isZip = IsZipFile();
if (isZip)
{
// Extract files from zip archive
string tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempDir);
using (ZipArchive apkArchive = ZipFile.OpenRead(FilePath))
{
foreach (ZipArchiveEntry entry in apkArchive.Entries)
{
string extractedFile = Path.Combine(tempDir, Guid.NewGuid().ToString());
entry.ExtractToFile(extractedFile);
ProcessFile(extractedFile, results);
}
}
// Clean up temp directory
Directory.Delete(tempDir, true);
}
else
{
// Process the file directly
ProcessFile(FilePath, results);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}");
}
return results.ToArray();
}
}
}

View File

@ -110,6 +110,16 @@ namespace Catswords.DataType.Client.Properties {
}
}
/// <summary>
/// System.Drawing.Bitmap 형식의 지역화된 리소스를 찾습니다.
/// </summary>
internal static System.Drawing.Bitmap link_symbol_icon_icons_com_56927 {
get {
object obj = ResourceManager.GetObject("link_symbol_icon_icons_com_56927", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// System.Drawing.Bitmap 형식의 지역화된 리소스를 찾습니다.
/// </summary>

View File

@ -130,6 +130,9 @@
<data name="image1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\image1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="link_symbol_icon_icons_com_56927" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\link-symbol_icon-icons.com_56927.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="message_bubble_conversation_speech_communication_talk_chat_icon_219299" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\message_bubble_conversation_speech_communication_talk_chat_icon_219299.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -46,7 +46,7 @@
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(18, 125);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(347, 277);
this.listView1.Size = new System.Drawing.Size(347, 339);
this.listView1.TabIndex = 8;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
@ -75,7 +75,7 @@
//
this.textBox1.BackColor = System.Drawing.Color.White;
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox1.Location = new System.Drawing.Point(16, 445);
this.textBox1.Location = new System.Drawing.Point(16, 496);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(349, 13);
@ -94,7 +94,7 @@
// linkLabel1
//
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(15, 416);
this.linkLabel1.Location = new System.Drawing.Point(13, 475);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(122, 13);
this.linkLabel1.TabIndex = 9;
@ -104,7 +104,7 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 411);
this.button1.Location = new System.Drawing.Point(280, 470);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(85, 23);
this.button1.TabIndex = 12;
@ -126,7 +126,7 @@
this.Controls.Add(this.label2);
this.Controls.Add(this.linkLabel1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(433, 457);
this.Size = new System.Drawing.Size(388, 517);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -28,6 +28,7 @@ namespace Catswords.DataType.Client
imageList.Images.Add(Properties.Resources.message_bubble_conversation_speech_communication_talk_chat_icon_219299);
imageList.Images.Add(Properties.Resources._2333410_android_os_smartphone_85588);
imageList.Images.Add(Properties.Resources.office_18907);
imageList.Images.Add(Properties.Resources.link_symbol_icon_icons_com_56927);
// set image list
listView1.SmallImageList = imageList;
@ -71,15 +72,18 @@ namespace Catswords.DataType.Client
FetchFromFileExtensionDB();
// Get data from Android manifest
FetchFromAndroidManifest();
ExtractAndroidManifest();
// Get data from timeline
FetchFromTimeline();
// Get links from file binary
ExtractLink();
}
private void FetchFromFileExtensionDB()
{
var search = new Helper.FileExtensionDB();
var search = new FileExtensionDB();
search.Fetch(fileExtension);
foreach (Indicator ind in search.Indicators)
{
@ -90,7 +94,7 @@ namespace Catswords.DataType.Client
private void FetchFromTimeline()
{
// Request a timeline
var search = new Helper.Timeline(Config.MASTODON_HOST, Config.MASTODON_ACCESS_TOKEN);
var search = new Timeline(Config.MASTODON_HOST, Config.MASTODON_ACCESS_TOKEN);
// fetch data by file magic
search.Fetch("0x" + fileMagic);
@ -100,10 +104,10 @@ namespace Catswords.DataType.Client
{
try
{
string imphash = Helper.ImpHash.Calculate(filePath);
string imphash = ImpHash.Calculate(filePath);
search.Fetch(imphash);
string companyInfo = Helper.FileCompany.Read(filePath);
string companyInfo = FileCompany.Read(filePath);
search.Fetch(companyInfo);
textBox1.Text = "ImpHash=" + imphash + "; CompanyInfo=" + companyInfo;
@ -124,20 +128,7 @@ namespace Catswords.DataType.Client
{
if (fileExtension == "xlsx" || fileExtension == "pptx" || fileExtension == "docx")
{
var extractor = new OpenXMLExtractor(filePath);
extractor.Open();
var metadata = extractor.GetMetadata();
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Author: " + metadata.Author }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Title: " + metadata.Title }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Subject: " + metadata.Subject }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Category: " + metadata.Category }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Description: " + metadata.Description }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Created: " + metadata.CreatedAt.ToString() }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last updated: " + metadata.UpdatedAt.ToString() }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last updated by: " + metadata.LastUpdatedBy }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last printed: " + metadata.LastPrintedAt }, 3));
extractor.Close();
ExtractOpenXML();
}
search.Fetch("msoffice");
@ -164,7 +155,7 @@ namespace Catswords.DataType.Client
}
}
private void FetchFromAndroidManifest()
private void ExtractAndroidManifest()
{
if (fileExtension == "apk")
{
@ -178,6 +169,34 @@ namespace Catswords.DataType.Client
}
}
private void ExtractOpenXML()
{
var extractor = new OpenXMLExtractor(filePath);
extractor.Open();
var metadata = extractor.GetMetadata();
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Author: " + metadata.Author }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Title: " + metadata.Title }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Subject: " + metadata.Subject }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Category: " + metadata.Category }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Description: " + metadata.Description }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Created: " + metadata.CreatedAt.ToString() }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last updated: " + metadata.UpdatedAt.ToString() }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last updated by: " + metadata.LastUpdatedBy }, 3));
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), "Last printed: " + metadata.LastPrintedAt }, 3));
extractor.Close();
}
private void ExtractLink()
{
var extractor = new LinkExtractor(filePath);
string[] links = extractor.GetStrings();
foreach (string link in links)
{
listView1.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), link }, 4));
}
}
public string OpenFileDialog()
{
string filePath = null;

View File

@ -2,6 +2,7 @@
<packages>
<package id="BencodeNET" version="4.0.0" targetFramework="net48" />
<package id="Crc32.NET" version="1.2.0" targetFramework="net48" />
<package id="MetadataExtractor" version="2.8.1" targetFramework="net48" />
<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" />
@ -10,4 +11,5 @@
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="XmpCore" version="6.1.10.1" targetFramework="net48" />
</packages>