Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Husak committed Nov 22, 2022
0 parents commit 4d25e9c
Show file tree
Hide file tree
Showing 23 changed files with 895 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
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/
25 changes: 25 additions & 0 deletions SCCDownloader.sln
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
205 changes: 205 additions & 0 deletions SCCDownloader/MD5Crypt.cs
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();
}

}
}
11 changes: 11 additions & 0 deletions SCCDownloader/Models/HitsTotal.cs
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; }
}
}
10 changes: 10 additions & 0 deletions SCCDownloader/Models/MediaInfoLabel.cs
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; }
}
}
10 changes: 10 additions & 0 deletions SCCDownloader/Models/MediaSource.cs
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; }
}
}
13 changes: 13 additions & 0 deletions SCCDownloader/Models/RootHits.cs
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; }
}
}
14 changes: 14 additions & 0 deletions SCCDownloader/Models/SearchHits.cs
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; }
}
}
16 changes: 16 additions & 0 deletions SCCDownloader/Models/SearchResponse.cs
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; }
}
}
14 changes: 14 additions & 0 deletions SCCDownloader/Models/StreamAudioInfo.cs
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;
}
}
13 changes: 13 additions & 0 deletions SCCDownloader/Models/StreamSubtitleInfo.cs
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;
}
}
16 changes: 16 additions & 0 deletions SCCDownloader/Models/StreamVideoInfo.cs
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;
}
}
Loading

0 comments on commit 4d25e9c

Please sign in to comment.