-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Husak
committed
Nov 22, 2022
0 parents
commit 4d25e9c
Showing
23 changed files
with
895 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
#Ignore thumbnails created by Windows | ||
Thumbs.db | ||
#Ignore files built by Visual Studio | ||
*.obj | ||
*.exe | ||
*.pdb | ||
*.user | ||
*.aps | ||
*.pch | ||
*.vspscc | ||
*_i.c | ||
*_p.c | ||
*.ncb | ||
*.suo | ||
*.tlb | ||
*.tlh | ||
*.bak | ||
*.cache | ||
*.ilk | ||
*.log | ||
[Bb]in | ||
[Dd]ebug*/ | ||
*.lib | ||
*.sbr | ||
obj/ | ||
[Rr]elease*/ | ||
_ReSharper*/ | ||
[Tt]est[Rr]esult* | ||
.vs/ | ||
#Nuget packages folder | ||
packages/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32922.545 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCCDownloader", "SCCDownloader\SCCDownloader.csproj", "{6AF96A91-4ADF-46BF-9F46-E404A4B702A8}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6AF96A91-4ADF-46BF-9F46-E404A4B702A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6AF96A91-4ADF-46BF-9F46-E404A4B702A8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6AF96A91-4ADF-46BF-9F46-E404A4B702A8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6AF96A91-4ADF-46BF-9F46-E404A4B702A8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8238873A-8861-4869-A98A-3A2F375807DF} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace SCCDownloader | ||
{ | ||
public class MD5Crypt | ||
{ | ||
/** Password hash magic */ | ||
private static String magic = "$1$"; | ||
|
||
/** Characters for base64 encoding */ | ||
private static String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
|
||
/// <summary> | ||
/// A function to concatenate bytes[] | ||
/// </summary> | ||
/// <param name="array1"></param> | ||
/// <param name="array2"></param> | ||
/// <returns>New adition array</returns> | ||
private static byte[] Concat(byte[] array1, byte[] array2) | ||
{ | ||
byte[] concat = new byte[array1.Length + array2.Length]; | ||
System.Buffer.BlockCopy(array1, 0, concat, 0, array1.Length); | ||
System.Buffer.BlockCopy(array2, 0, concat, array1.Length, array2.Length); | ||
return concat; | ||
} | ||
/// <summary> | ||
/// Another function to concatenate bytes[] | ||
/// </summary> | ||
/// <param name="array1"></param> | ||
/// <param name="array2"></param> | ||
/// <returns>New adition array</returns> | ||
private static byte[] PartialConcat(byte[] array1, byte[] array2, int max) | ||
{ | ||
byte[] concat = new byte[array1.Length + max]; | ||
System.Buffer.BlockCopy(array1, 0, concat, 0, array1.Length); | ||
System.Buffer.BlockCopy(array2, 0, concat, array1.Length, max); | ||
return concat; | ||
} | ||
|
||
/// <summary> | ||
/// Base64-Encode integer value | ||
/// </summary> | ||
/// <param name="value"> The value to encode</param> | ||
/// <param name="length"> Desired length of the result</param> | ||
/// <returns>@return Base64 encoded value</returns> | ||
private static String to64(int value, int length) | ||
{ | ||
StringBuilder result; | ||
|
||
result = new StringBuilder(); | ||
while (--length >= 0) | ||
{ | ||
result.Append(itoa64.Substring(value & 0x3f, 1)); | ||
value >>= 6; | ||
} | ||
return (result.ToString()); | ||
} | ||
/// <summary> | ||
/// Unix-like Crypt-MD5 function | ||
/// </summary> | ||
/// <param name="password">The user password</param> | ||
/// <param name="salt">The salt or the pepper of the password</param> | ||
/// <returns>a human readable string</returns> | ||
public static String crypt(String password, String salt) | ||
{ | ||
int saltEnd; | ||
int len; | ||
int value; | ||
int i; | ||
/* | ||
MessageDigest ctx; | ||
MessageDigest ctx1; | ||
*/ | ||
|
||
// sResult = BitConverter.ToString(hashvalue1); | ||
byte[] final; | ||
byte[] passwordBytes; | ||
byte[] saltBytes; | ||
byte[] ctx; | ||
|
||
StringBuilder result; | ||
HashAlgorithm x_hash_alg = HashAlgorithm.Create("MD5"); | ||
|
||
|
||
|
||
// Skip magic if it exists | ||
if (salt.StartsWith(magic)) | ||
{ | ||
salt = salt.Substring(magic.Length); | ||
} | ||
|
||
// Remove password hash if present | ||
if ((saltEnd = salt.LastIndexOf('$')) != -1) | ||
{ | ||
salt = salt.Substring(0, saltEnd); | ||
} | ||
|
||
// Shorten salt to 8 characters if it is longer | ||
if (salt.Length > 8) | ||
{ | ||
salt = salt.Substring(0, 8); | ||
} | ||
|
||
ctx = Encoding.ASCII.GetBytes((password + magic + salt)); | ||
final = x_hash_alg.ComputeHash(Encoding.ASCII.GetBytes((password + salt + password))); | ||
|
||
|
||
// Add as many characters of ctx1 to ctx | ||
byte[] hashM;// = new byte[15]; | ||
for (len = password.Length; len > 0; len -= 16) | ||
{ | ||
if (len > 16) | ||
{ | ||
ctx = Concat(ctx, final); | ||
} | ||
else | ||
{ | ||
ctx = PartialConcat(ctx, final, len); | ||
|
||
} | ||
|
||
//System.Buffer.BlockCopy(final, 0, hash16, ctx.Length, len); | ||
//System.Buffer.BlockCopy(ctx, 0, hash16, 0, ctx.Length); | ||
|
||
} | ||
//ctx = hashM; | ||
|
||
// Then something really weird... | ||
passwordBytes = Encoding.ASCII.GetBytes(password); | ||
|
||
for (i = password.Length; i > 0; i >>= 1) | ||
{ | ||
if ((i & 1) == 1) | ||
{ | ||
ctx = Concat(ctx, new byte[] { 0 }); | ||
} | ||
else | ||
{ | ||
ctx = Concat(ctx, new byte[] { passwordBytes[0] }); | ||
} | ||
} | ||
|
||
final = x_hash_alg.ComputeHash(ctx); | ||
|
||
byte[] ctx1; | ||
|
||
// Do additional mutations | ||
saltBytes = Encoding.ASCII.GetBytes(salt);//.getBytes(); | ||
for (i = 0; i < 1000; i++) | ||
{ | ||
ctx1 = new byte[] { }; | ||
if ((i & 1) == 1) | ||
{ | ||
ctx1 = Concat(ctx1, passwordBytes); | ||
} | ||
else | ||
{ | ||
ctx1 = Concat(ctx1, final); | ||
} | ||
if (i % 3 != 0) | ||
{ | ||
ctx1 = Concat(ctx1, saltBytes); | ||
} | ||
if (i % 7 != 0) | ||
{ | ||
ctx1 = Concat(ctx1, passwordBytes); | ||
} | ||
if ((i & 1) != 0) | ||
{ | ||
ctx1 = Concat(ctx1, final); | ||
} | ||
else | ||
{ | ||
ctx1 = Concat(ctx1, passwordBytes); | ||
} | ||
final = x_hash_alg.ComputeHash(ctx1); | ||
|
||
} | ||
result = new StringBuilder(); | ||
// Add the password hash to the result string | ||
value = ((final[0] & 0xff) << 16) | ((final[6] & 0xff) << 8) | ||
| (final[12] & 0xff); | ||
result.Append(to64(value, 4)); | ||
value = ((final[1] & 0xff) << 16) | ((final[7] & 0xff) << 8) | ||
| (final[13] & 0xff); | ||
result.Append(to64(value, 4)); | ||
value = ((final[2] & 0xff) << 16) | ((final[8] & 0xff) << 8) | ||
| (final[14] & 0xff); | ||
result.Append(to64(value, 4)); | ||
value = ((final[3] & 0xff) << 16) | ((final[9] & 0xff) << 8) | ||
| (final[15] & 0xff); | ||
result.Append(to64(value, 4)); | ||
value = ((final[4] & 0xff) << 16) | ((final[10] & 0xff) << 8) | ||
| (final[5] & 0xff); | ||
result.Append(to64(value, 4)); | ||
value = final[11] & 0xff; | ||
result.Append(to64(value, 2)); | ||
|
||
// Return result string | ||
return magic + salt + "$" + result.ToString(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class HitsTotal | ||
{ | ||
|
||
[JsonPropertyName("value")] | ||
public int Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class MediaInfoLabel | ||
{ | ||
[JsonPropertyName("originaltitle")] | ||
public String OriginalTitle { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class MediaSource | ||
{ | ||
[JsonPropertyName("info_labels")] | ||
public MediaInfoLabel InfoLabel { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class RootHits | ||
{ | ||
[JsonPropertyName("total")] | ||
public HitsTotal Total { get; set; } | ||
|
||
[JsonPropertyName("hits")] | ||
public SearchHits[] Hits { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class SearchHits | ||
{ | ||
|
||
[JsonPropertyName("_id")] | ||
public String Id { get; set; } | ||
|
||
[JsonPropertyName("_source")] | ||
public MediaSource Source { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class SearchResponse | ||
{ | ||
[JsonPropertyName("took")] | ||
public int Took { get; set; } | ||
|
||
[JsonPropertyName("timed_out")] | ||
public bool TimeOut { get; set; } | ||
|
||
[JsonPropertyName("hits")] | ||
public RootHits Hits { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class StreamAudioInfo | ||
{ | ||
[JsonPropertyName("language")] | ||
public String Language; | ||
[JsonPropertyName("codec")] | ||
public String Codec; | ||
[JsonPropertyName("channels")] | ||
public int Channels; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class StreamSubtitleInfo | ||
{ | ||
[JsonPropertyName("language")] | ||
public String Language; | ||
|
||
[JsonPropertyName("forced")] | ||
public Boolean Forced; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SCCDownloader.Models | ||
{ | ||
public class StreamVideoInfo | ||
{ | ||
[JsonPropertyName("width")] | ||
public int Width; | ||
|
||
[JsonPropertyName("height")] | ||
public int Height; | ||
|
||
[JsonPropertyName("codec")] | ||
public String Codec; | ||
} | ||
} |
Oops, something went wrong.