Add CompanyInfo
This commit is contained in:
parent
280f304ede
commit
48a9f5f4e2
101
SocialOnTheFile/Helper/FileCompany.cs
Normal file
101
SocialOnTheFile/Helper/FileCompany.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace SocialOnTheFile.Helper
|
||||
{
|
||||
public static class FileCompany
|
||||
{
|
||||
static public string Read(string filePath)
|
||||
{
|
||||
// 회사 정보 추출
|
||||
string[] companies = new string[] {
|
||||
GetCompanyInfo(filePath),
|
||||
GetProductName(filePath),
|
||||
GetCopyrightInfo(filePath),
|
||||
GetOrganization(filePath)
|
||||
};
|
||||
foreach (string company in companies)
|
||||
{
|
||||
if (company != null && !company.Equals(string.Empty))
|
||||
{
|
||||
return company;
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
public static string GetOrganization(string filePath)
|
||||
{
|
||||
string organization = string.Empty;
|
||||
|
||||
// 서명된 파일인 경우 인증서 정보 추출
|
||||
X509Certificate2 certificate = GetCertificateInfo(filePath);
|
||||
if (certificate != null)
|
||||
{
|
||||
// Subject 필드에서 O (Organization) 값을 찾아 회사 정보 추출
|
||||
string[] fields = certificate.Subject.Split(',');
|
||||
|
||||
foreach (string field in fields)
|
||||
{
|
||||
string[] keyValue = field.Trim().Split('=');
|
||||
|
||||
if (keyValue.Length == 2 && keyValue[0].Trim().Equals("O", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
organization = keyValue[1].Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return organization;
|
||||
}
|
||||
|
||||
public static string GetCompanyInfo(string filePath)
|
||||
{
|
||||
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(filePath);
|
||||
return versionInfo.CompanyName;
|
||||
}
|
||||
|
||||
public static string GetProductName(string filePath)
|
||||
{
|
||||
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(filePath);
|
||||
return versionInfo.ProductName;
|
||||
}
|
||||
|
||||
public static string GetCopyrightInfo(string filePath)
|
||||
{
|
||||
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(filePath);
|
||||
return versionInfo.LegalCopyright;
|
||||
}
|
||||
|
||||
static X509Certificate2 GetCertificateInfo(string filePath)
|
||||
{
|
||||
// GetCertificateInfo 구현
|
||||
try
|
||||
{
|
||||
// 파일에 디지털 서명이 있는지 확인
|
||||
Assembly assembly = Assembly.LoadFile(filePath);
|
||||
X509Certificate2 certificate = new X509Certificate2(assembly.Location);
|
||||
|
||||
// 서명이 유효한지 확인 (옵션)
|
||||
X509Chain chain = new X509Chain();
|
||||
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; // 여러 인증서를 사용하는 경우 인증서 연쇄를 무시할 수 있습니다.
|
||||
|
||||
if (chain.Build(certificate))
|
||||
{
|
||||
return certificate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,6 +94,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Helper\FileCompany.cs" />
|
||||
<Compile Include="Helper\ImpHash.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using SharpShell.Attributes;
|
||||
using SharpShell.ServerRegistration;
|
||||
using SharpShell.SharpPropertySheet;
|
||||
using SocialOnTheFile.Model;
|
||||
using System;
|
||||
|
@ -7,9 +6,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace SocialOnTheFile
|
||||
{
|
||||
|
@ -84,7 +81,11 @@ namespace SocialOnTheFile
|
|||
{
|
||||
string imphash = Helper.ImpHash.Calculate(filePath);
|
||||
search.Fetch(imphash);
|
||||
textBox1.Text = imphash;
|
||||
|
||||
string companyInfo = Helper.FileCompany.Read(filePath);
|
||||
search.Fetch(companyInfo);
|
||||
|
||||
textBox1.Text = "ImpHash=" + imphash + "; CompanyInfo=" + companyInfo;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user