Skip to content

Commit

Permalink
v2.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
msasanmh committed Jan 3, 2024
1 parent 191db2f commit bdf3737
Show file tree
Hide file tree
Showing 193 changed files with 12,567 additions and 9,539 deletions.
11 changes: 6 additions & 5 deletions MsmhToolsClass/MsmhToolsClass.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.5" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="7.0.1" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.7" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="8.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private int LPHostIpPort(int position, byte[] stampBinary, int defaultPort, out
Buffer.BlockCopy(stampBinary, position, bHostPort, 0, hostPortLength);

string hostPort = Encoding.UTF8.GetString(bHostPort);
NetworkTool.GetHostDetails(hostPort, defaultPort, out host, out _, out port, out _, out bool _);
NetworkTool.GetHostDetails(hostPort, defaultPort, out host, out _, out _, out port, out _, out bool _);
position += hostPortLength; // Skip Host:Port

return position;
Expand Down
4 changes: 2 additions & 2 deletions MsmhToolsClass/MsmhToolsClass/DnsTool/DnsDeDup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private async Task<bool> IsTheSame(string dns1, string dns2)
{
string ip1 = string.Empty;
DnsReader dr1 = new(dns1, null);
NetworkTool.GetUrlDetails(dns1, dr1.Port, out string scheme1, out string host1, out _, out int port1, out string path1, out _);
NetworkTool.GetUrlDetails(dns1, dr1.Port, out string scheme1, out string host1, out _, out _, out int port1, out string path1, out _);
if (dr1.IsDnsCryptStamp)
{
host1 = dr1.Host;
Expand All @@ -73,7 +73,7 @@ private async Task<bool> IsTheSame(string dns1, string dns2)

string ip2 = string.Empty;
DnsReader dr2 = new(dns2, null);
NetworkTool.GetUrlDetails(dns2, dr2.Port, out string scheme2, out string host2, out _, out int port2, out string path2, out _);
NetworkTool.GetUrlDetails(dns2, dr2.Port, out string scheme2, out string host2, out _, out _, out int port2, out string path2, out _);
if (dr2.IsDnsCryptStamp)
{
if (!dr1.IsDnsCryptStamp)
Expand Down
4 changes: 2 additions & 2 deletions MsmhToolsClass/MsmhToolsClass/DnsTool/DnsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public DnsReader(string dns, string? companyNameDataFileContent)

private void SetIpPortHostPath(string dns, int defaultPort)
{
NetworkTool.GetUrlDetails(dns, defaultPort, out _, out string host, out _, out int port, out string path, out bool isIPv6);
NetworkTool.GetUrlDetails(dns, defaultPort, out _, out string host, out _, out _, out int port, out string path, out bool isIPv6);
Port = port;
Path = path;
bool isIPv4 = NetworkTool.IsIPv4Valid(host, out IPAddress? _);
Expand All @@ -135,7 +135,7 @@ private void SetIpPortHostPath(string dns, int defaultPort)

private void SetIpPortHost(string hostIpPort, int defaultPort)
{
NetworkTool.GetHostDetails(hostIpPort, defaultPort, out string host, out _, out int port, out string _, out bool isIPv6);
NetworkTool.GetHostDetails(hostIpPort, defaultPort, out string host, out _, out _, out int port, out string _, out bool isIPv6);
Port = port;
bool isIPv4 = NetworkTool.IsIPv4Valid(host, out IPAddress? _);
if (isIPv6 || isIPv4)
Expand Down
2 changes: 1 addition & 1 deletion MsmhToolsClass/MsmhToolsClass/DnsTool/GetCompanyName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static string HostToCompanyOffline(string host, string fileContent)

public static string UrlToCompanyOffline(string url, string fileContent)
{
NetworkTool.GetUrlDetails(url, 53, out _, out string host, out _, out int _, out string _, out bool _);
NetworkTool.GetUrlDetails(url, 53, out _, out string host, out _, out _, out int _, out string _, out bool _);
return HostToCompanyOffline(host, fileContent);
}

Expand Down
135 changes: 99 additions & 36 deletions MsmhToolsClass/MsmhToolsClass/EncodingTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;

Expand All @@ -8,77 +8,140 @@ public class EncodingTool
{
public static string GetSHA1(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA1 hash = SHA1.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
try
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA1 hash = SHA1.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
}
catch (Exception)
{
return string.Empty;
}
}

public static string GetSHA256(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA256 hash = SHA256.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
try
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA256 hash = SHA256.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
}
catch (Exception)
{
return string.Empty;
}
}

public static string GetSHA384(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA384 hash = SHA384.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
try
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA384 hash = SHA384.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
}
catch (Exception)
{
return string.Empty;
}
}

public static string GetSHA512(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA512 hash = SHA512.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
try
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
using SHA512 hash = SHA512.Create();
byte[] hashedInputBytes = hash.ComputeHash(bytes);
return Convert.ToHexString(hashedInputBytes);
}
catch (Exception)
{
return string.Empty;
}
}

public static string Base64Encode(string plainText)
{
byte[] data = Encoding.UTF8.GetBytes(plainText);
string encodedString = Convert.ToBase64String(data);
return encodedString;
try
{
byte[] data = Encoding.UTF8.GetBytes(plainText);
return Convert.ToBase64String(data);
}
catch (Exception)
{
return string.Empty;
}
}

public static string Base64Decode(string encodedString)
{
byte[] data = Convert.FromBase64String(encodedString);
string decodedString = Encoding.UTF8.GetString(data);
return decodedString;
try
{
byte[] data = Convert.FromBase64String(encodedString);
return Encoding.UTF8.GetString(data);
}
catch (Exception)
{
return string.Empty;
}
}

public static string UrlEncode(byte[] arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));

var s = Convert.ToBase64String(arg);
return s.Replace("=", "").Replace("/", "_").Replace("+", "-");
try
{
string s = Convert.ToBase64String(arg);
return s.Replace("=", "").Replace("/", "_").Replace("+", "-");
}
catch (Exception)
{
return string.Empty;
}
}

public static string UrlToBase64(string arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));

var s = arg.PadRight(arg.Length + (4 - arg.Length % 4) % 4, '=').Replace("_", "/").Replace("-", "+");
return s;
try
{
return arg.PadRight(arg.Length + (4 - arg.Length % 4) % 4, '=').Replace("_", "/").Replace("-", "+");
}
catch (Exception)
{
return string.Empty;
}
}

public static byte[] UrlDecode(string arg)
{
var decrypted = UrlToBase64(arg);
return Convert.FromBase64String(decrypted);
try
{
string decrypted = UrlToBase64(arg);
return Convert.FromBase64String(decrypted);
}
catch (Exception ex)
{
Debug.WriteLine("UrlDecode: " + ex.Message);
return Array.Empty<byte>();
}
}

public static T[] SubArray<T>(T[] arr, int start, int length)
{
var result = new T[length];
Buffer.BlockCopy(arr, start, result, 0, length);

T[] result = new T[length];
try
{
Buffer.BlockCopy(arr, start, result, 0, length);
}
catch (Exception ex)
{
Debug.WriteLine("SubArray: " + ex.Message);
}
return result;
}

Expand Down
18 changes: 6 additions & 12 deletions MsmhToolsClass/MsmhToolsClass/ExtensionsMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,28 @@ public static string GetInnerExceptions(this Exception ex)
public static string TrimStart(this string source, string value)
{
string result = source;
if (result.StartsWith(value))
try
{
try
if (result.StartsWith(value))
{
result = result[value.Length..];
}
catch (Exception)
{
// do nothing
}
}
catch (Exception) { }
return result;
}
//-----------------------------------------------------------------------------------
public static string TrimEnd(this string source, string value)
{
string result = source;
if (result.EndsWith(value))
try
{
try
if (result.EndsWith(value))
{
result = result.Remove(source.LastIndexOf(value, StringComparison.Ordinal));
}
catch (Exception)
{
// do nothing
}
}
catch (Exception) { }
return result;
}
//-----------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit bdf3737

Please sign in to comment.