Skip to content

Commit

Permalink
[fix/ISSUE-75] Fix bug when deciphering N param with $ in challenge name
Browse files Browse the repository at this point in the history
  • Loading branch information
azihassan committed May 14, 2024
1 parent a528ddc commit 8c006d9
Show file tree
Hide file tree
Showing 3 changed files with 13,499 additions and 9 deletions.
8 changes: 4 additions & 4 deletions source/helpers.d
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ string matchOrFail(string pattern, bool escape = false)(string source)
{
trace("Matching ", pattern);
auto regex = ctRegex!(escape ? pattern.escaper.to!string : pattern);
return source.matchFirst(regex).matchOrFail();
return source.matchFirst(regex).matchOrFail(pattern);
}

string matchOrFail(string source, string pattern)
{
trace("Matching ", pattern);
auto regex = regex(pattern);
return source.matchFirst(regex).matchOrFail();
return source.matchFirst(regex).matchOrFail(pattern);
}

string matchOrFail(Captures!string match)
string matchOrFail(Captures!string match, string pattern = "")
{
if(match.empty)
{
throw new Exception("Failed to match regular expression");
throw new Exception("Failed to match regular expression " ~ pattern);
}
return match[1];
}
Expand Down
23 changes: 18 additions & 5 deletions source/parsers.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import std.conv : to;
import std.array : replace;
import std.file : readText;
import std.string : indexOf, format, lastIndexOf, split, strip, toStringz, startsWith;
import std.regex : ctRegex, matchFirst;
import std.regex : ctRegex, matchFirst, escaper;
import std.algorithm : canFind, filter, reverse, map;
import std.format : formattedRead;

Expand Down Expand Up @@ -556,12 +556,12 @@ struct ThrottlingAlgorithm

string findChallengeName()
{
return javascript.matchOrFail!(`\|\|([a-zA-Z]{3})\(""\)`, false);
return javascript.matchOrFail!(`\|\|(.{3})\(""\)`, false);
}

string findChallengeImplementation()
{
string challengeName = findChallengeName();
string challengeName = findChallengeName().escaper().to!string;
logger.displayVerbose("challenge name : ", challengeName);
return javascript.matchOrFail(challengeName ~ `=function\(a\)\{((.|\s)+?)return b\.join\(""\)\};`).strip();
}
Expand Down Expand Up @@ -597,8 +597,9 @@ struct ThrottlingAlgorithm
}
catch(Exception e)
{
logger.display(e.message.idup.formatError());
logger.display("Failed to solve N parameter, downloads might be rate limited".formatError());
logger.display(e.message.idup.formatWarning());
logger.display("Failed to solve N parameter, downloads might be rate limited".formatWarning());
logger.displayVerbose(e.info.to!string.formatWarning());
return n;
}
}
Expand Down Expand Up @@ -627,3 +628,15 @@ unittest

assert(expected == actual, expected ~ " != " ~ actual);
}

unittest
{
writeln("Should solve challenge with unusual characters in it");
auto algorithm = ThrottlingAlgorithm("tests/a960a0cb.js".readText(), new StdoutLogger());
assert(algorithm.findChallengeName() == "$la", algorithm.findChallengeName() ~ " != $la");

string expected = "CJ6mFweU_U3YMQ";
string actual = algorithm.solve("lTCmja7irJFW2HwaD");

assert(expected == actual, expected ~ " != " ~ actual);
}
Loading

0 comments on commit 8c006d9

Please sign in to comment.