Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp.$1 not get the right value #829

Closed
Fndroid opened this issue Dec 3, 2020 · 3 comments · Fixed by #854
Closed

RegExp.$1 not get the right value #829

Fndroid opened this issue Dec 3, 2020 · 3 comments · Fixed by #854

Comments

@Fndroid
Copy link

Fndroid commented Dec 3, 2020

When I tried to use RegExp by calling .test(), I got different results when the code was obfuscatied.

Here is the sample code to reproduce the issue: gist

Expected Behavior

The code above should log the host(127.0.0.1:54637) of the url to the console

Current Behavior

By running multiple times of npm run test, I got different results.
image

Steps to Reproduce

  1. clone the code from gist
  2. install deps npm install
  3. run npm run test

Your Environment

  • Obfuscator version used: 2.9.4
  • Node version used: v12.16.3

Stack trace

no error throw in this case.

Minimal working example that will help to reproduce issue

gist

@da411d
Copy link
Contributor

da411d commented Dec 4, 2020

I did some test and there is what i get:

// Test 1
/(.+)/.test("12345");
console.log(RegExp.$1); //> 12345

// Test 2
/(.+)/.test("12345");
"a".replace(/=+$/, "");
console.log(RegExp.$1); //> 12345

// Test 3
/(.+)/.test("12345");
"a==".replace(/=+$/, "");
console.log(RegExp.$1); //> 

image
image

Looks like RegExp.$1 resets after other regex. Such used in rc4 or base64 decode helper.
I think problem is in AtobTemplate.ts. Replacing with regex should be replaced with something else. Maybe substring? Or just putting all base64 strings to code without "=" in the end.

@sanex3339 sanex3339 added the bug label Dec 4, 2020
@sanex3339
Copy link
Member

sanex3339 commented Jan 1, 2021

I'll try to remove padding characters from the base64 encoded strings, and as result - remove this regexp that just trims these padding characters during decoding. Also this slightly decreases obfuscated code size with base64 and rc4 encodings.

sanex3339 added a commit that referenced this issue Jan 1, 2021
Removed RegExp that trims padding characters from `base64` encoded strings from `atob` code helper to prevent mutation of `RegExp.$1` value during calls to the `stringArray`. Fixed #829
@sanex3339
Copy link
Member

Released as 2.10.1

@sanex3339 sanex3339 added the fixed label Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants