some fixes

This commit is contained in:
Namhyeon Go 2024-04-16 17:25:50 +09:00
parent ea64977098
commit e391718b52
13 changed files with 173 additions and 121 deletions

View File

@ -93,18 +93,19 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Worker.cs" /> <Compile Include="Model\HashInfo.cs" />
<Compile Include="Form1.cs"> <Compile Include="Worker1.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Form1.Designer.cs"> <Compile Include="Main.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Main.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Form2.cs"> <Compile Include="UserControl2.cs">
<SubType>Form</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Form2.Designer.cs"> <Compile Include="UserControl2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon> <DependentUpon>UserControl2.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Helper\ApkManifestExtractor.cs" /> <Compile Include="Helper\ApkManifestExtractor.cs" />
<Compile Include="Helper\CbpfExtractor.cs" /> <Compile Include="Helper\CbpfExtractor.cs" />
@ -119,7 +120,6 @@
<Compile Include="Helper\Timeline.cs" /> <Compile Include="Helper\Timeline.cs" />
<Compile Include="Model\AndroidPermission.cs" /> <Compile Include="Model\AndroidPermission.cs" />
<Compile Include="Model\ExifTag.cs" /> <Compile Include="Model\ExifTag.cs" />
<Compile Include="Model\FileHash.cs" />
<Compile Include="Model\TimelineMessage.cs" /> <Compile Include="Model\TimelineMessage.cs" />
<Compile Include="Model\OpenXMLMetadata.cs" /> <Compile Include="Model\OpenXMLMetadata.cs" />
<Compile Include="Model\Timestamp.cs" /> <Compile Include="Model\Timestamp.cs" />
@ -131,11 +131,11 @@
<Compile Include="UserControl1.Designer.cs"> <Compile Include="UserControl1.Designer.cs">
<DependentUpon>UserControl1.cs</DependentUpon> <DependentUpon>UserControl1.cs</DependentUpon>
</Compile> </Compile>
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Main.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Form2.resx"> <EmbeddedResource Include="UserControl2.resx">
<DependentUpon>Form2.cs</DependentUpon> <DependentUpon>UserControl2.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>

View File

@ -1,54 +0,0 @@
using Catswords.DataType.Client.Model;
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Windows.Forms;
namespace Catswords.DataType.Client
{
public partial class Form2 : Form
{
private UserControl1 Parent;
private FileHash hashed;
public Form2(UserControl1 parent)
{
InitializeComponent();
Parent = parent;
}
private void Form2_Load(object sender, EventArgs e)
{
hashed = Helper.FileHasher.Compute(Parent.FilePath);
txtExtension.Text = hashed.Extension;
txtHashMd5.Text = hashed.MD5;
txtHashSha1.Text = hashed.SHA1;
txtHashCrc32.Text = hashed.CRC32;
txtHashSha256.Text = hashed.SHA256;
txtMagic.Text = hashed.MAGIC;
txtInfoHash.Text = hashed.InfoHash;
txtSsdeep.Text = hashed.SSDEEP;
}
private void button1_Click(object sender, EventArgs e)
{
ByteViewer bv = new ByteViewer();
bv.SetFile(Parent.FilePath); // or SetBytes
Form newForm = new Form();
newForm.Size = new System.Drawing.Size(650, 600);
newForm.Text = "ByteViewer";
newForm.Icon = Properties.Resources.icon;
newForm.MinimizeBox = false;
newForm.MaximizeBox = false;
newForm.FormBorderStyle = FormBorderStyle.FixedSingle;
newForm.Controls.Add(bv);
newForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("https://www.virustotal.com/gui/file/" + hashed.SHA256);
}
}
}

View File

@ -1,6 +1,5 @@
using BencodeNET.Parsing; using BencodeNET.Parsing;
using BencodeNET.Torrents; using BencodeNET.Torrents;
using Catswords.DataType.Client.Model;
using Force.Crc32; using Force.Crc32;
using SsdeepNET; using SsdeepNET;
using System; using System;
@ -12,29 +11,20 @@ namespace Catswords.DataType.Client.Helper
{ {
public class FileHasher public class FileHasher
{ {
public static FileHash Compute(string filename) private string FilePath;
public FileHasher(string filePath)
{ {
string extension = GetExtension(filename); FilePath = filePath;
return new FileHash
{
Extension = extension,
MD5 = GetMD5(filename),
SHA1 = GetSHA1(filename),
MAGIC = GetMAGIC(filename),
CRC32 = GetCRC32(filename),
SHA256 = GetSHA256(filename),
InfoHash = GetInfoHash(filename, extension),
SSDEEP = GetSSDEEP(filename)
};
} }
private static string GetExtension(string filename) public string GetExtension()
{ {
try try
{ {
if (Path.GetExtension(filename).Length > 0) if (Path.GetExtension(FilePath).Length > 0)
{ {
return Path.GetExtension(filename).Substring(1).ToUpper(); return Path.GetExtension(FilePath).Substring(1).ToUpper();
} }
else else
{ {
@ -47,13 +37,13 @@ namespace Catswords.DataType.Client.Helper
} }
} }
private static string GetMD5(string filename) public string GetMD5()
{ {
string checksum = ""; string checksum = "";
using (MD5 hasher = MD5.Create()) using (MD5 hasher = MD5.Create())
{ {
using (FileStream stream = File.OpenRead(filename)) using (FileStream stream = File.OpenRead(FilePath))
{ {
byte[] hash = hasher.ComputeHash(stream); byte[] hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
@ -63,13 +53,13 @@ namespace Catswords.DataType.Client.Helper
return checksum; return checksum;
} }
private static string GetSHA1(string filename) public string GetSHA1()
{ {
string checksum = ""; string checksum = "";
using (SHA1 hasher = SHA1.Create()) using (SHA1 hasher = SHA1.Create())
{ {
using (FileStream stream = File.OpenRead(filename)) using (FileStream stream = File.OpenRead(FilePath))
{ {
byte[] hash = hasher.ComputeHash(stream); byte[] hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
@ -79,11 +69,11 @@ namespace Catswords.DataType.Client.Helper
return checksum; return checksum;
} }
private static string GetCRC32(string filename) public string GetCRC32()
{ {
string checksum = ""; string checksum = "";
using (FileStream stream = File.OpenRead(filename)) using (FileStream stream = File.OpenRead(FilePath))
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
stream.CopyTo(ms); stream.CopyTo(ms);
@ -93,13 +83,13 @@ namespace Catswords.DataType.Client.Helper
return checksum; return checksum;
} }
private static string GetSHA256(string filename) public string GetSHA256()
{ {
string checksum = ""; string checksum = "";
using (SHA256 hasher = SHA256.Create()) using (SHA256 hasher = SHA256.Create())
{ {
using (FileStream stream = File.OpenRead(filename)) using (FileStream stream = File.OpenRead(FilePath))
{ {
var hash = hasher.ComputeHash(stream); var hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
@ -109,11 +99,11 @@ namespace Catswords.DataType.Client.Helper
return checksum; return checksum;
} }
public static byte[] GetFileBytes(string filename, int count = 32) public byte[] GetFileBytes(int count = 32)
{ {
byte[] buffer = new byte[count]; byte[] buffer = new byte[count];
using (var stream = File.OpenRead(filename)) using (var stream = File.OpenRead(FilePath))
{ {
int offset = 0; int offset = 0;
while (offset < count) while (offset < count)
@ -122,7 +112,7 @@ namespace Catswords.DataType.Client.Helper
{ {
int read = stream.Read(buffer, offset, count - offset); int read = stream.Read(buffer, offset, count - offset);
if (read == 0) if (read == 0)
throw new System.IO.EndOfStreamException(); throw new EndOfStreamException();
offset += read; offset += read;
} }
catch (EndOfStreamException) catch (EndOfStreamException)
@ -137,30 +127,31 @@ namespace Catswords.DataType.Client.Helper
return buffer; return buffer;
} }
private static string GetMAGIC(string filename) public string GetMagic()
{ {
return new FileMagicExtractor(filename).GetString(); return new FileMagicExtractor(FilePath).GetString();
} }
private static string GetInfoHash(string filename, string extension) public string GetInfoHash()
{ {
string checksum = ""; string checksum = "";
string extension = GetExtension().ToLower();
if (extension.ToUpper() == "TORRENT") if (extension == "torrent")
{ {
BencodeParser parser = new BencodeParser(); BencodeParser parser = new BencodeParser();
Torrent torrent = parser.Parse<Torrent>(filename); Torrent torrent = parser.Parse<Torrent>(FilePath);
checksum = BitConverter.ToString(torrent.GetInfoHashBytes()).Replace("-", "").ToLowerInvariant(); checksum = BitConverter.ToString(torrent.GetInfoHashBytes()).Replace("-", "").ToLowerInvariant();
} }
return checksum; return checksum;
} }
private static string GetSSDEEP(string filename) public string GetSSDEEP()
{ {
string checksum = ""; string checksum = "";
using (FileStream stream = File.OpenRead(filename)) using (FileStream stream = File.OpenRead(FilePath))
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
stream.CopyTo(ms); stream.CopyTo(ms);
@ -172,7 +163,7 @@ namespace Catswords.DataType.Client.Helper
return checksum; return checksum;
} }
public static string GetHexView(byte[] Data) public string GetHexView(byte[] Data)
{ {
string output = ""; string output = "";

View File

@ -1,6 +1,6 @@
namespace Catswords.DataType.Client namespace Catswords.DataType.Client
{ {
partial class Form1 partial class Main
{ {
/// <summary> /// <summary>
/// 필수 디자이너 변수입니다. /// 필수 디자이너 변수입니다.

View File

@ -2,9 +2,9 @@
namespace Catswords.DataType.Client namespace Catswords.DataType.Client
{ {
public partial class Form1 : Form public partial class Main : Form
{ {
public Form1() public Main()
{ {
InitializeComponent(); InitializeComponent();

View File

@ -1,6 +1,6 @@
namespace Catswords.DataType.Client.Model namespace Catswords.DataType.Client.Model
{ {
public class FileHash: Timestamp class HashInfo: Timestamp
{ {
public string Path { get; set; } public string Path { get; set; }
public string Extension { get; set; } public string Extension { get; set; }
@ -12,4 +12,4 @@
public string InfoHash { get; set; } public string InfoHash { get; set; }
public string SSDEEP { get; set; } public string SSDEEP { get; set; }
} }
} }

View File

@ -16,7 +16,7 @@ namespace Catswords.DataType.Client
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Main());
} }
} }
} }

View File

@ -67,7 +67,7 @@ namespace Catswords.DataType.Client
} }
// Run the worker // Run the worker
(new Worker(this)).Run(); (new Worker1(this)).Run();
} }
public string OpenFileDialog() public string OpenFileDialog()
@ -123,8 +123,19 @@ namespace Catswords.DataType.Client
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
Form newForm = new Form2(this); Form form = new Form
newForm.Show(); {
Text = "Expert",
FormBorderStyle = FormBorderStyle.FixedSingle,
Icon = Properties.Resources.icon,
MaximizeBox = false,
MinimizeBox = false,
Width = 450,
Height = 560,
BackColor = System.Drawing.SystemColors.Window
};
form.Controls.Add(new UserControl2(this));
form.Show();
} }
} }
} }

View File

@ -1,6 +1,6 @@
namespace Catswords.DataType.Client namespace Catswords.DataType.Client
{ {
partial class Form2 partial class UserControl2
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -76,6 +76,7 @@
this.txtExtension.Name = "txtExtension"; this.txtExtension.Name = "txtExtension";
this.txtExtension.Size = new System.Drawing.Size(284, 20); this.txtExtension.Size = new System.Drawing.Size(284, 20);
this.txtExtension.TabIndex = 1; this.txtExtension.TabIndex = 1;
this.txtExtension.Text = "Calculating...";
// //
// txtHashSha256 // txtHashSha256
// //
@ -83,6 +84,7 @@
this.txtHashSha256.Name = "txtHashSha256"; this.txtHashSha256.Name = "txtHashSha256";
this.txtHashSha256.Size = new System.Drawing.Size(284, 20); this.txtHashSha256.Size = new System.Drawing.Size(284, 20);
this.txtHashSha256.TabIndex = 1; this.txtHashSha256.TabIndex = 1;
this.txtHashSha256.Text = "Calculating...";
// //
// txtMagic // txtMagic
// //
@ -90,6 +92,7 @@
this.txtMagic.Name = "txtMagic"; this.txtMagic.Name = "txtMagic";
this.txtMagic.Size = new System.Drawing.Size(284, 20); this.txtMagic.Size = new System.Drawing.Size(284, 20);
this.txtMagic.TabIndex = 1; this.txtMagic.TabIndex = 1;
this.txtMagic.Text = "Calculating...";
// //
// txtHashCrc32 // txtHashCrc32
// //
@ -97,6 +100,7 @@
this.txtHashCrc32.Name = "txtHashCrc32"; this.txtHashCrc32.Name = "txtHashCrc32";
this.txtHashCrc32.Size = new System.Drawing.Size(284, 20); this.txtHashCrc32.Size = new System.Drawing.Size(284, 20);
this.txtHashCrc32.TabIndex = 1; this.txtHashCrc32.TabIndex = 1;
this.txtHashCrc32.Text = "Calculating...";
// //
// txtHashSha1 // txtHashSha1
// //
@ -104,6 +108,7 @@
this.txtHashSha1.Name = "txtHashSha1"; this.txtHashSha1.Name = "txtHashSha1";
this.txtHashSha1.Size = new System.Drawing.Size(284, 20); this.txtHashSha1.Size = new System.Drawing.Size(284, 20);
this.txtHashSha1.TabIndex = 1; this.txtHashSha1.TabIndex = 1;
this.txtHashSha1.Text = "Calculating...";
// //
// txtHashMd5 // txtHashMd5
// //
@ -111,6 +116,7 @@
this.txtHashMd5.Name = "txtHashMd5"; this.txtHashMd5.Name = "txtHashMd5";
this.txtHashMd5.Size = new System.Drawing.Size(284, 20); this.txtHashMd5.Size = new System.Drawing.Size(284, 20);
this.txtHashMd5.TabIndex = 1; this.txtHashMd5.TabIndex = 1;
this.txtHashMd5.Text = "Calculating...";
// //
// labelLocale // labelLocale
// //
@ -190,6 +196,7 @@
this.txtInfoHash.Name = "txtInfoHash"; this.txtInfoHash.Name = "txtInfoHash";
this.txtInfoHash.Size = new System.Drawing.Size(284, 20); this.txtInfoHash.Size = new System.Drawing.Size(284, 20);
this.txtInfoHash.TabIndex = 1; this.txtInfoHash.TabIndex = 1;
this.txtInfoHash.Text = "Calculating...";
// //
// labelTools // labelTools
// //
@ -229,6 +236,7 @@
this.txtSsdeep.Name = "txtSsdeep"; this.txtSsdeep.Name = "txtSsdeep";
this.txtSsdeep.Size = new System.Drawing.Size(284, 20); this.txtSsdeep.Size = new System.Drawing.Size(284, 20);
this.txtSsdeep.TabIndex = 9; this.txtSsdeep.TabIndex = 9;
this.txtSsdeep.Text = "Calculating...";
// //
// labelSsdeep // labelSsdeep
// //
@ -269,14 +277,8 @@
this.Controls.Add(this.labelInfoHash); this.Controls.Add(this.labelInfoHash);
this.Controls.Add(this.labelLocale); this.Controls.Add(this.labelLocale);
this.Controls.Add(this.labelExtension); this.Controls.Add(this.labelExtension);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = global::Catswords.DataType.Client.Properties.Resources.icon;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form2"; this.Name = "Form2";
this.Text = "Expert"; this.Text = "Expert";
this.TopMost = true;
this.Load += new System.EventHandler(this.Form2_Load); this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@ -0,0 +1,102 @@
using Catswords.DataType.Client.Helper;
using Catswords.DataType.Client.Model;
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Catswords.DataType.Client
{
public partial class UserControl2 : UserControl
{
private UserControl1 Parent;
private HashInfo CalculatedHashInfo = new HashInfo();
public UserControl2(UserControl1 parent)
{
InitializeComponent();
Parent = parent;
}
private void Form2_Load(object sender, EventArgs e)
{
new Task(() =>
{
var hasher = new FileHasher(Parent.FilePath);
txtExtension.Invoke(new MethodInvoker(delegate
{
txtExtension.Text = hasher.GetExtension();
CalculatedHashInfo.Extension = txtExtension.Text;
}));
txtMagic.Invoke(new MethodInvoker(delegate
{
txtMagic.Text = hasher.GetMagic();
CalculatedHashInfo.Extension = txtMagic.Text;
}));
txtHashMd5.Invoke(new MethodInvoker(delegate
{
txtHashMd5.Text = hasher.GetMD5();
CalculatedHashInfo.MD5 = txtHashMd5.Text;
}));
txtHashSha1.Invoke(new MethodInvoker(delegate
{
txtHashSha1.Text = hasher.GetSHA1();
CalculatedHashInfo.SHA1 = txtHashSha1.Text;
}));
txtHashCrc32.Invoke(new MethodInvoker(delegate
{
txtHashCrc32.Text = hasher.GetCRC32();
CalculatedHashInfo.CRC32 = txtHashCrc32.Text;
}));
txtHashSha256.Invoke(new MethodInvoker(delegate
{
txtHashSha256.Text = hasher.GetSHA256();
CalculatedHashInfo.SHA256 = txtHashSha256.Text;
}));
txtInfoHash.Invoke(new MethodInvoker(delegate
{
txtInfoHash.Text = hasher.GetInfoHash();
CalculatedHashInfo.InfoHash = txtInfoHash.Text;
}));
txtSsdeep.Invoke(new MethodInvoker(delegate
{
txtSsdeep.Text = hasher.GetSSDEEP();
CalculatedHashInfo.SSDEEP = txtSsdeep.Text;
}));
CalculatedHashInfo.CreatedAt = DateTime.Now;
CalculatedHashInfo.UpdatedAt = CalculatedHashInfo.CreatedAt;
}).Start();
}
private void button1_Click(object sender, EventArgs e)
{
ByteViewer bv = new ByteViewer();
bv.SetFile(Parent.FilePath); // or SetBytes
Form newForm = new Form();
newForm.Size = new System.Drawing.Size(650, 600);
newForm.Text = "ByteViewer";
newForm.Icon = Properties.Resources.icon;
newForm.MinimizeBox = false;
newForm.MaximizeBox = false;
newForm.FormBorderStyle = FormBorderStyle.FixedSingle;
newForm.Controls.Add(bv);
newForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("https://www.virustotal.com/gui/file/" + CalculatedHashInfo.SHA256);
}
}
}

View File

@ -5,11 +5,11 @@ using System.Threading.Tasks;
namespace Catswords.DataType.Client namespace Catswords.DataType.Client
{ {
public class Worker public class Worker1
{ {
private UserControl1 Parent; private UserControl1 Parent;
public Worker(UserControl1 parent) public Worker1(UserControl1 parent)
{ {
Parent = parent; Parent = parent;
} }