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 2f964b5 commit 544fbd1
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 34 deletions.
51 changes: 38 additions & 13 deletions Catswords.DataType.Client/Catswords.DataType.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>게시\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -42,9 +57,6 @@
<AssemblyOriginatorKeyFile>socialonthefile.snk</AssemblyOriginatorKeyFile>
</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>
</Reference>
<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>
Expand Down Expand Up @@ -103,6 +115,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Helper\InfoHashExtractor.cs" />
<Compile Include="Model\CfbfPartInfo.cs" />
<Compile Include="Model\HashInfo.cs" />
<Compile Include="Worker1.cs" />
Expand Down Expand Up @@ -192,16 +205,6 @@
<ItemGroup>
<None Include="Resources\document_paperclip_list_paper_icon_219544.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\OneDrive\문서\GitHub\androidxmldotnet\AndroidXml\AndroidXml.csproj">
<Project>{607eeb2c-6b7c-409e-959e-3b458a109426}</Project>
<Name>AndroidXml</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\OneDrive\문서\GitHub\SsdeepNET\Source\SsdeepNET\SsdeepNET.csproj">
<Project>{b1244c5a-cdeb-4d1d-8807-bf40251abcab}</Project>
<Name>SsdeepNET</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\2333410-android-os-smartphone_85588.png" />
</ItemGroup>
Expand All @@ -214,5 +217,27 @@
<ItemGroup>
<None Include="Resources\tags_icon-icons.com_73382.png" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8%28x86 및 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\androidxmldotnet\AndroidXml\AndroidXml.csproj">
<Project>{e55ce5e9-aeec-4625-82ff-9c73dad2ba84}</Project>
<Name>AndroidXml</Name>
</ProjectReference>
<ProjectReference Include="..\SsdeepNET\Source\SsdeepNET\SsdeepNET.csproj">
<Project>{1fc34ef4-5137-4069-a18a-d35afec5181f}</Project>
<Name>SsdeepNET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
37 changes: 17 additions & 20 deletions Catswords.DataType.Client/Helper/FileHasher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BencodeNET.Parsing;
using BencodeNET.Torrents;
using Force.Crc32;
using Force.Crc32;
using SsdeepNET;
using System;
using System.IO;
Expand All @@ -20,26 +18,26 @@ public FileHasher(string filePath)

public string GetExtension()
{
string extension = string.Empty;

try
{
if (Path.GetExtension(FilePath).Length > 0)
{
return Path.GetExtension(FilePath).Substring(1).ToUpper();
}
else
{
return "";
extension = Path.GetExtension(FilePath).Substring(1).ToLower();
}
}
catch (Exception)
catch
{
return "";
// nothing
}

return extension;
}

public string GetMD5()
{
string checksum = "";
string checksum = string.Empty;

using (MD5 hasher = MD5.Create())
{
Expand All @@ -55,7 +53,7 @@ public string GetMD5()

public string GetSHA1()
{
string checksum = "";
string checksum = string.Empty;

using (SHA1 hasher = SHA1.Create())
{
Expand All @@ -71,7 +69,7 @@ public string GetSHA1()

public string GetCRC32()
{
string checksum = "";
string checksum = string.Empty;

using (FileStream stream = File.OpenRead(FilePath))
{
Expand All @@ -85,7 +83,7 @@ public string GetCRC32()

public string GetSHA256()
{
string checksum = "";
string checksum = string.Empty;

using (SHA256 hasher = SHA256.Create())
{
Expand Down Expand Up @@ -134,22 +132,21 @@ public string GetMagic()

public string GetInfoHash()
{
string checksum = "";
string checksum = string.Empty;
string extension = GetExtension().ToLower();

if (extension == "torrent")
{
BencodeParser parser = new BencodeParser();
Torrent torrent = parser.Parse<Torrent>(FilePath);
checksum = BitConverter.ToString(torrent.GetInfoHashBytes()).Replace("-", "").ToLowerInvariant();
var extractor = new InfoHashExtractor(FilePath);
checksum = extractor.GetString();
}

return checksum;
}

public string GetSSDEEP()
{
string checksum = "";
string checksum = string.Empty;

using (FileStream stream = File.OpenRead(FilePath))
{
Expand All @@ -165,7 +162,7 @@ public string GetSSDEEP()

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

StringBuilder strb = new StringBuilder();
StringBuilder text = new StringBuilder();
Expand Down
51 changes: 51 additions & 0 deletions Catswords.DataType.Client/Helper/InfoHashExtractor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.IO;

namespace Catswords.DataType.Client.Helper
{
public class InfoHashExtractor
{
private string FilePath;

public InfoHashExtractor(string filePath)
{
FilePath = filePath;
}

public string GetString()
{
string infoHashString = "";

try
{
// 토렌트 파일을 바이트 배열로 읽어옴
byte[] torrentData = File.ReadAllBytes(FilePath);

// 토렌트 파일에서 InfoHash 추출
byte[] infoHash = ExtractInfoHash(torrentData);

// InfoHash를 문자열로 변환하여 출력
infoHashString = BitConverter.ToString(infoHash).Replace("-", "").ToLower();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}

return infoHashString;
}

private byte[] ExtractInfoHash(byte[] torrentData)
{
// 토렌트 파일의 구조에 따라 InfoHash 위치 파악
int start = Array.IndexOf(torrentData, (byte)'4', 0);
int end = Array.IndexOf(torrentData, (byte)'e', start);

// InfoHash 추출
byte[] infoHash = new byte[20];
Array.Copy(torrentData, start + 1, infoHash, 0, 20);

return infoHash;
}
}
}
1 change: 0 additions & 1 deletion Catswords.DataType.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
Expand Down

0 comments on commit 544fbd1

Please sign in to comment.