Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnh1201 committed Apr 16, 2024
1 parent ea64977 commit e391718
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 121 deletions.
26 changes: 13 additions & 13 deletions Catswords.DataType.Client/Catswords.DataType.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Worker.cs" />
<Compile Include="Form1.cs">
<Compile Include="Model\HashInfo.cs" />
<Compile Include="Worker1.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
</Compile>
<Compile Include="Form2.cs">
<SubType>Form</SubType>
<Compile Include="UserControl2.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
<Compile Include="UserControl2.Designer.cs">
<DependentUpon>UserControl2.cs</DependentUpon>
</Compile>
<Compile Include="Helper\ApkManifestExtractor.cs" />
<Compile Include="Helper\CbpfExtractor.cs" />
Expand All @@ -119,7 +120,6 @@
<Compile Include="Helper\Timeline.cs" />
<Compile Include="Model\AndroidPermission.cs" />
<Compile Include="Model\ExifTag.cs" />
<Compile Include="Model\FileHash.cs" />
<Compile Include="Model\TimelineMessage.cs" />
<Compile Include="Model\OpenXMLMetadata.cs" />
<Compile Include="Model\Timestamp.cs" />
Expand All @@ -131,11 +131,11 @@
<Compile Include="UserControl1.Designer.cs">
<DependentUpon>UserControl1.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form2.resx">
<DependentUpon>Form2.cs</DependentUpon>
<EmbeddedResource Include="UserControl2.resx">
<DependentUpon>UserControl2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
54 changes: 0 additions & 54 deletions Catswords.DataType.Client/Form2.cs

This file was deleted.

63 changes: 27 additions & 36 deletions Catswords.DataType.Client/Helper/FileHasher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BencodeNET.Parsing;
using BencodeNET.Torrents;
using Catswords.DataType.Client.Model;
using Force.Crc32;
using SsdeepNET;
using System;
Expand All @@ -12,29 +11,20 @@ namespace Catswords.DataType.Client.Helper
{
public class FileHasher
{
public static FileHash Compute(string filename)
private string FilePath;

public FileHasher(string filePath)
{
string extension = GetExtension(filename);
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)
};
FilePath = filePath;
}

private static string GetExtension(string filename)
public string GetExtension()
{
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
{
Expand All @@ -47,13 +37,13 @@ private static string GetExtension(string filename)
}
}

private static string GetMD5(string filename)
public string GetMD5()
{
string checksum = "";

using (MD5 hasher = MD5.Create())
{
using (FileStream stream = File.OpenRead(filename))
using (FileStream stream = File.OpenRead(FilePath))
{
byte[] hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
Expand All @@ -63,13 +53,13 @@ private static string GetMD5(string filename)
return checksum;
}

private static string GetSHA1(string filename)
public string GetSHA1()
{
string checksum = "";

using (SHA1 hasher = SHA1.Create())
{
using (FileStream stream = File.OpenRead(filename))
using (FileStream stream = File.OpenRead(FilePath))
{
byte[] hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
Expand All @@ -79,11 +69,11 @@ private static string GetSHA1(string filename)
return checksum;
}

private static string GetCRC32(string filename)
public string GetCRC32()
{
string checksum = "";

using (FileStream stream = File.OpenRead(filename))
using (FileStream stream = File.OpenRead(FilePath))
{
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
Expand All @@ -93,13 +83,13 @@ private static string GetCRC32(string filename)
return checksum;
}

private static string GetSHA256(string filename)
public string GetSHA256()
{
string checksum = "";

using (SHA256 hasher = SHA256.Create())
{
using (FileStream stream = File.OpenRead(filename))
using (FileStream stream = File.OpenRead(FilePath))
{
var hash = hasher.ComputeHash(stream);
checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
Expand All @@ -109,11 +99,11 @@ private static string GetSHA256(string filename)
return checksum;
}

public static byte[] GetFileBytes(string filename, int count = 32)
public byte[] GetFileBytes(int count = 32)
{
byte[] buffer = new byte[count];

using (var stream = File.OpenRead(filename))
using (var stream = File.OpenRead(FilePath))
{
int offset = 0;
while (offset < count)
Expand All @@ -122,7 +112,7 @@ public static byte[] GetFileBytes(string filename, int count = 32)
{
int read = stream.Read(buffer, offset, count - offset);
if (read == 0)
throw new System.IO.EndOfStreamException();
throw new EndOfStreamException();
offset += read;
}
catch (EndOfStreamException)
Expand All @@ -137,30 +127,31 @@ public static byte[] GetFileBytes(string filename, int count = 32)
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 extension = GetExtension().ToLower();

if (extension.ToUpper() == "TORRENT")
if (extension == "torrent")
{
BencodeParser parser = new BencodeParser();
Torrent torrent = parser.Parse<Torrent>(filename);
Torrent torrent = parser.Parse<Torrent>(FilePath);
checksum = BitConverter.ToString(torrent.GetInfoHashBytes()).Replace("-", "").ToLowerInvariant();
}

return checksum;
}

private static string GetSSDEEP(string filename)
public string GetSSDEEP()
{
string checksum = "";

using (FileStream stream = File.OpenRead(filename))
using (FileStream stream = File.OpenRead(FilePath))
{
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
Expand All @@ -172,7 +163,7 @@ private static string GetSSDEEP(string filename)
return checksum;
}

public static string GetHexView(byte[] Data)
public string GetHexView(byte[] Data)
{
string output = "";

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Catswords.DataType.Client
{
public partial class Form1 : Form
public partial class Main : Form
{
public Form1()
public Main()
{
InitializeComponent();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Catswords.DataType.Client.Model
{
public class FileHash: Timestamp
class HashInfo: Timestamp
{
public string Path { get; set; }
public string Extension { get; set; }
Expand All @@ -12,4 +12,4 @@ public class FileHash: Timestamp
public string InfoHash { get; set; }
public string SSDEEP { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Catswords.DataType.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Main());
}
}
}
17 changes: 14 additions & 3 deletions Catswords.DataType.Client/UserControl1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public UserControl1(Form parent)
}

// Run the worker
(new Worker(this)).Run();
(new Worker1(this)).Run();
}

public string OpenFileDialog()
Expand Down Expand Up @@ -123,8 +123,19 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs

private void button1_Click(object sender, EventArgs e)
{
Form newForm = new Form2(this);
newForm.Show();
Form form = new Form
{
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();
}
}
}
Loading

0 comments on commit e391718

Please sign in to comment.