some fixes

This commit is contained in:
Namhyeon Go 2024-04-16 18:15:40 +09:00
parent 2f964b5b93
commit 544fbd19f4
4 changed files with 106 additions and 34 deletions

View File

@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <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>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -42,9 +57,6 @@
<AssemblyOriginatorKeyFile>socialonthefile.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>socialonthefile.snk</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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"> <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> <HintPath>..\packages\Crc32.NET.1.2.0\lib\net20\Crc32.NET.dll</HintPath>
</Reference> </Reference>
@ -103,6 +115,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Helper\InfoHashExtractor.cs" />
<Compile Include="Model\CfbfPartInfo.cs" /> <Compile Include="Model\CfbfPartInfo.cs" />
<Compile Include="Model\HashInfo.cs" /> <Compile Include="Model\HashInfo.cs" />
<Compile Include="Worker1.cs" /> <Compile Include="Worker1.cs" />
@ -192,16 +205,6 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\document_paperclip_list_paper_icon_219544.png" /> <None Include="Resources\document_paperclip_list_paper_icon_219544.png" />
</ItemGroup> </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> <ItemGroup>
<None Include="Resources\2333410-android-os-smartphone_85588.png" /> <None Include="Resources\2333410-android-os-smartphone_85588.png" />
</ItemGroup> </ItemGroup>
@ -214,5 +217,27 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\tags_icon-icons.com_73382.png" /> <None Include="Resources\tags_icon-icons.com_73382.png" />
</ItemGroup> </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" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -1,6 +1,4 @@
using BencodeNET.Parsing; using Force.Crc32;
using BencodeNET.Torrents;
using Force.Crc32;
using SsdeepNET; using SsdeepNET;
using System; using System;
using System.IO; using System.IO;
@ -20,26 +18,26 @@ namespace Catswords.DataType.Client.Helper
public string GetExtension() public string GetExtension()
{ {
string extension = string.Empty;
try try
{ {
if (Path.GetExtension(FilePath).Length > 0) if (Path.GetExtension(FilePath).Length > 0)
{ {
return Path.GetExtension(FilePath).Substring(1).ToUpper(); extension = Path.GetExtension(FilePath).Substring(1).ToLower();
}
else
{
return "";
} }
} }
catch (Exception) catch
{ {
return ""; // nothing
} }
return extension;
} }
public string GetMD5() public string GetMD5()
{ {
string checksum = ""; string checksum = string.Empty;
using (MD5 hasher = MD5.Create()) using (MD5 hasher = MD5.Create())
{ {
@ -55,7 +53,7 @@ namespace Catswords.DataType.Client.Helper
public string GetSHA1() public string GetSHA1()
{ {
string checksum = ""; string checksum = string.Empty;
using (SHA1 hasher = SHA1.Create()) using (SHA1 hasher = SHA1.Create())
{ {
@ -71,7 +69,7 @@ namespace Catswords.DataType.Client.Helper
public string GetCRC32() public string GetCRC32()
{ {
string checksum = ""; string checksum = string.Empty;
using (FileStream stream = File.OpenRead(FilePath)) using (FileStream stream = File.OpenRead(FilePath))
{ {
@ -85,7 +83,7 @@ namespace Catswords.DataType.Client.Helper
public string GetSHA256() public string GetSHA256()
{ {
string checksum = ""; string checksum = string.Empty;
using (SHA256 hasher = SHA256.Create()) using (SHA256 hasher = SHA256.Create())
{ {
@ -134,14 +132,13 @@ namespace Catswords.DataType.Client.Helper
public string GetInfoHash() public string GetInfoHash()
{ {
string checksum = ""; string checksum = string.Empty;
string extension = GetExtension().ToLower(); string extension = GetExtension().ToLower();
if (extension == "torrent") if (extension == "torrent")
{ {
BencodeParser parser = new BencodeParser(); var extractor = new InfoHashExtractor(FilePath);
Torrent torrent = parser.Parse<Torrent>(FilePath); checksum = extractor.GetString();
checksum = BitConverter.ToString(torrent.GetInfoHashBytes()).Replace("-", "").ToLowerInvariant();
} }
return checksum; return checksum;
@ -149,7 +146,7 @@ namespace Catswords.DataType.Client.Helper
public string GetSSDEEP() public string GetSSDEEP()
{ {
string checksum = ""; string checksum = string.Empty;
using (FileStream stream = File.OpenRead(FilePath)) using (FileStream stream = File.OpenRead(FilePath))
{ {
@ -165,7 +162,7 @@ namespace Catswords.DataType.Client.Helper
public string GetHexView(byte[] Data) public string GetHexView(byte[] Data)
{ {
string output = ""; string output = string.Empty;
StringBuilder strb = new StringBuilder(); StringBuilder strb = new StringBuilder();
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();

View File

@ -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;
}
}
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="BencodeNET" version="4.0.0" targetFramework="net48" />
<package id="Crc32.NET" version="1.2.0" targetFramework="net48" /> <package id="Crc32.NET" version="1.2.0" targetFramework="net48" />
<package id="MetadataExtractor" version="2.8.1" targetFramework="net48" /> <package id="MetadataExtractor" version="2.8.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" /> <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />