Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #73 from Cyano/master
Browse files Browse the repository at this point in the history
Trial fix for latest 403 Errors
  • Loading branch information
flagbug committed Aug 7, 2014
2 parents c3055f8 + 8b59d54 commit e2fc777
Showing 1 changed file with 64 additions and 11 deletions.
75 changes: 64 additions & 11 deletions YoutubeExtractor/YoutubeExtractor/Decipherer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,74 @@ public static string DecipherWithVersion(string cipher, string cipherVersion)
//Match the function function_name (that has one argument)
string funcPattern = string.Format(@"{0}\(\w+\){1}", funcName, funcBodyPattern);
var funcBody = Regex.Match(js, funcPattern).Groups["brace"].Value;

var lines = funcBody.Split(';');

string operations = "";


//CYNAO - 07/08/2014, Test Fix
/* The previous algoritms used a.splice(), where the decipher used the method (.splice()), however it seems the new algoritm
* renames the method to random but unique characters (example ab.dc() = splice). This code determines what each method code is,
* as it is defined once using the original name.
*/
string id_Reverse = "" , id_Slice = "" , id_CharSwap = ""; //Holds the new method name for each.
string functionIdentifier = "";

string functIDPattern = @"\w+:\bfunction\b"; //Define as "NB:function(a,b)" where nb can be the three ciphers
var funcID = Regex.Match(js, functIDPattern).Groups[1].Value;

///CODE ADDITION: Get the three ciphers by finding the definition
foreach (var line in lines.Skip(1).Take(lines.Length - 2))
{
string newVarName; //Previous algoritms used to be just "a." - now stores temp var name as its uneccessary
int locOfDot, locOfBracket, functionIDLength;
locOfDot = line.IndexOf("."); // NB.AC( - gets location of the dot.
locOfBracket = line.IndexOf("("); //NB.AC( - gets location of the bracet
functionIDLength = locOfBracket - (locOfDot + 1);
newVarName = line.Substring(0, locOfDot);
functionIdentifier = line.Substring(locOfDot + 1, functionIDLength); //leaving us with the function AC

//This is what the definitions currently look like, could be changed so the regex needs improving. Messy fix.
string tempReverse = string.Format(@"{0}:\bfunction\b\(\w+\)", functionIdentifier); //Reverse only one that doesnt have two parameters
string tempSlice = string.Format(@"{0}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\.", functionIdentifier); //Regex for slice (return or not)
string tempCharSwap = string.Format(@"{0}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b", functionIdentifier); //Regex for the char swap.

Match me;
if ((me = Regex.Match(js, tempReverse)).Success)
{ id_Reverse = functionIdentifier; } //If def matched the regex for reverse then the current function is a defined as the reverse cipher

if ((me = Regex.Match(js, tempSlice)).Success)
{ id_Slice = functionIdentifier; } //If def matched the regex for slice then the current function is defined as the slice cipher.

if ((me = Regex.Match(js, tempCharSwap)).Success)
{ id_CharSwap = functionIdentifier; } //If def matched the regex for charSwap then the current function is defined as swap cipher.

}


foreach (var line in lines.Skip(1).Take(lines.Length - 2))
{
Match m;
if ((m = Regex.Match(line, @"\(\w+,(?<index>\d+)\)")).Success)
//calling a two argument function (swap)
operations += "w" + m.Groups["index"].Value + " ";
else if ((m = Regex.Match(line, @"slice\((?<index>\d+)\)")).Success)
//calling slice
operations += "s" + m.Groups["index"].Value + " ";
else if ((m = Regex.Match(line, @"reverse\(\)")).Success)
//calling reverse
operations += "r ";
///DUPLICATE CODE! Improve.
int locOfDot; int locOfBracket; int functionIDLength;
locOfDot = line.IndexOf(".");
locOfBracket = line.IndexOf("(");
functionIDLength = locOfBracket - (locOfDot + 1);
functionIdentifier = line.Substring(locOfDot + 1, functionIDLength); //Just needed this (define it as a member?)

string newSliceIDRegex = string.Format(@"(?<index>\d+)\)+", functionIdentifier);

if ((m = Regex.Match(line, @"\(\w+,(?<index>\d+)\)")).Success && functionIdentifier == id_CharSwap)
{ operations += "w" + m.Groups["index"].Value + " "; } //Character swap regex appears to be the same as before


if ((m = Regex.Match(line, @"\(\w+,(?<index>\d+)\)")).Success && functionIdentifier == id_Slice)
{ operations += "s" + m.Groups["index"].Value + " "; } //Slice appears to have changed the index location???
//Could be wrong and the regex needs improving, seems to work on the latest algorithm though.

if (functionIdentifier == id_Reverse)
{ operations += "r "; } //Reverse operation, no regex required

}
operations = operations.Trim();

Expand All @@ -51,7 +104,7 @@ private static string ApplyOperation(string cipher, string op)
{
case 'r':
return new string(cipher.ToCharArray().Reverse().ToArray());

case 'w':
{
int index = GetOpIndex(op);
Expand Down

0 comments on commit e2fc777

Please sign in to comment.