Skip to content

Commit

Permalink
[fix/ISSUE-51] Fix N parameter implementation parsing for player 717a…
Browse files Browse the repository at this point in the history
…6f94
  • Loading branch information
azihassan committed Jan 24, 2024
1 parent 539f204 commit f3ecaa7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions source/parsers.d
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,15 @@ struct ThrottlingAlgorithm
{
string challengeName = findChallengeName();
logger.displayVerbose("challenge name : ", challengeName);
return javascript.matchOrFail(challengeName ~ `=function\(a\)\{((.|\s)+?)\};`).strip();
return javascript.matchOrFail(challengeName ~ `=function\(a\)\{((.|\s)+?)return b\.join\(""\)\};`).strip();
}

string solve(string n)
{
duk_context *context = duk_create_heap_default();
if(!context)
{
logger.display("Failed to create a Duktape heap.");
logger.display("Failed to create a Duktape heap.".formatError());
return n;
}

Expand All @@ -517,7 +517,9 @@ struct ThrottlingAlgorithm

try
{
string implementation = format!`var descramble = function(a) { %s }`(findChallengeImplementation());
string implementation = format!`var descramble = function(a) { %s return b.join("")};`(findChallengeImplementation());
logger.displayVerbose("Challenge implementation :");
logger.displayVerbose(implementation);
duk_peval_string(context, implementation.toStringz());
duk_get_global_string(context, "descramble");
duk_push_string(context, n.toStringz());
Expand Down Expand Up @@ -550,3 +552,15 @@ unittest

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

unittest
{
writeln("Should parse new challenge");
auto algorithm = ThrottlingAlgorithm("717a6f94.js".readText(), new StdoutLogger());
assert(algorithm.findChallengeName() == "bma", algorithm.findChallengeName() ~ " != bma");

string expected = "vDwB7sNN_ZK_8w";
string actual = algorithm.solve("kVFjC9ssz1cOv88r");

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

0 comments on commit f3ecaa7

Please sign in to comment.