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

New Feature OBJECT_W_SELF, rewritten 'W' definition #49

Merged
merged 18 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/~feature-hub/dev/impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function makeLib()
'index.d.ts',
'mask.d.ts',
'mask-impl.d.ts',
'mask-impl-64.d.ts',
'mask-impl-52.d.ts',
'mask-index.d.ts',
],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/~feature-hub/src/mask-impl.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { Mask } from './mask';
export * from './mask-impl-64';
export * from './mask-impl-52';
27 changes: 12 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,16 @@ to support.
In order to understand how this works, let's consider the JavaScript functions `atob` and `btoa`.
Not all browsers support these functions: without any further information, JScrewIt will assume that
they are unavailable and will not use them to encode the input.
Anyway, if we know in advance that the browsers we plan to target do support `atob` and `btoa`
indeed, we can let JScrewIt create code that uses those functions whenever that makes the output
shorter.
However, if we know in advance that the browsers we plan to target do support `atob` and `btoa`, we
can let JScrewIt create code that uses those functions whenever that makes the output shorter.

The way to tell JScrewIt to use a particular set of features is by specifying a value for the
`features` option in the second parameter passed to `encode`.

For instance, a generic `alert(1)` example for an unspecified environment is 1905 chracters long.
For instance, a generic `alert(1)` example for an unspecified environment is 1903 chracters long.

```js
const output = JScrewIt.encode("alert(1)"); // output is 1905 characters
const output = JScrewIt.encode("alert(1)"); // output is 1903 characters
```

We can save a few characters by indicating that our code is only supposed to run in a browser.
Expand Down Expand Up @@ -189,37 +188,35 @@ Most typically, it will throw some kind of error at runtime.

It's important to keep in mind that each of the target engines needs to support every feature we
specify.
So if we want our JSFuck code to run in Android Browser 4.4, Safari 7.0 and Node.js 13+, we can only
So if we want our JSFuck code to run in Android Browser 4.0, Safari 7.0 and Node.js 13+, we can only
specify features supported by all of these engines.
These features can be retrieved with
[`JScrewIt.Feature.commonOf`](api-doc/interfaces/FeatureConstructor.md#commonof).

```js
{ features: JScrewIt.Feature.commonOf("ANDRO_4_4", "NODE_13", "SAFARI_7_0") }
{ features: JScrewIt.Feature.commonOf("ANDRO_4_0", "NODE_13", "SAFARI_7_0") }
```

The features turn out to be
[`ESC_HTML_QUOT`](api-doc/interfaces/FeatureAll.md#ESC_HTML_QUOT),
[`GENERIC_ARRAY_TO_STRING`](api-doc/interfaces/FeatureAll.md#GENERIC_ARRAY_TO_STRING),
[`GMT`](api-doc/interfaces/FeatureAll.md#GMT),
[`INCR_CHAR`](api-doc/interfaces/FeatureAll.md#INCR_CHAR),
[`NAME`](api-doc/interfaces/FeatureAll.md#NAME),
[`NO_IE_SRC`](api-doc/interfaces/FeatureAll.md#NO_IE_SRC) and
[`OBJECT_UNDEFINED`](api-doc/interfaces/FeatureAll.md#OBJECT_UNDEFINED) (a quick way to see this is
entering `JScrewIt.Feature.commonOf("ANDRO_4_4", "NODE_13", "SAFARI_7_0").toString()` in the
browser's console).
[`NAME`](api-doc/interfaces/FeatureAll.md#NAME) and
[`NO_IE_SRC`](api-doc/interfaces/FeatureAll.md#NO_IE_SRC) (a quick way to see this is entering
`JScrewIt.Feature.commonOf("ANDRO_4_0", "NODE_13", "SAFARI_7_0").toString()` in the browser's
console).
With this knowledge, we could also rewrite the expression above as follows.

```js
{ features: ["ESC_HTML_QUOT", "GMT", "INCR_CHAR", "NAME", "NO_IE_SRC", "OBJECT_UNDEFINED"] }
{ features: ["ESC_HTML_QUOT", "GMT", "INCR_CHAR", "NAME", "NO_IE_SRC"] }
```

Finally, note that simply specifying an array of engine features will not achieve the desired
effect, as it will result in the union of the features available in every engine rather than in
their intersection.

```diff
- { features: ["ANDRO_4_4", "NODE_13", "SAFARI_7_0"] }
- { features: ["ANDRO_4_0", "NODE_13", "SAFARI_7_0"] }
```

### Further Reading
Expand Down
3 changes: 2 additions & 1 deletion src/lib/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ function getFHPaddingEntries(index)
var OBJECT_ARRAY_ENTRIES_CTOR = Feature.OBJECT_ARRAY_ENTRIES_CTOR;
var OBJECT_L_LOCATION_CTOR = Feature.OBJECT_L_LOCATION_CTOR;
var OBJECT_UNDEFINED = Feature.OBJECT_UNDEFINED;
var OBJECT_W_SELF = Feature.OBJECT_W_SELF;
var OLD_SAFARI_LOCATION_CTOR = Feature.OLD_SAFARI_LOCATION_CTOR;
var PLAIN_INTL = Feature.PLAIN_INTL;
var REGEXP_STRING_ITERATOR = Feature.REGEXP_STRING_ITERATOR;
Expand Down Expand Up @@ -1067,7 +1068,7 @@ function getFHPaddingEntries(index)
define('(self + RP_4_A)[SLICE_OR_SUBSTR]("-11")[0]', ANY_WINDOW),
define('btoa(undefined)[1]', ATOB),
define('(RP_0_S + self)[11]', DOMWINDOW),
define('(RP_3_WA + self)[11]', WINDOW),
define('(RP_3_WA + self)[11]', OBJECT_W_SELF),
define('(self + RP_4_A).at("-11")', ANY_WINDOW, AT),
defineCharDefault({ atob: false }),
],
Expand Down
43 changes: 39 additions & 4 deletions src/lib/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,19 @@ var featureInfos =
},
includes: ['UNDEFINED'],
},
OBJECT_W_SELF:
{
description:
'The property that the string representation of the global object self starts ' +
'with "[object W".',
check:
function ()
{
var available = /^\[object W/.test(self);
return available;
},
attributes: { 'web-worker': 'non-ie-restriction' },
},
OLD_SAFARI_LOCATION_CTOR:
{
description:
Expand Down Expand Up @@ -842,6 +855,7 @@ var featureInfos =
'char-increment-restriction': null,
'safari-bug-21820506': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
COMPACT:
Expand Down Expand Up @@ -882,7 +896,12 @@ var featureInfos =
'STATUS',
'WINDOW',
],
attributes: { 'char-increment-restriction': null, 'web-worker-restriction': null },
attributes:
{
'char-increment-restriction': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
ANDRO_4_0:
{
Expand Down Expand Up @@ -927,7 +946,12 @@ var featureInfos =
SHORT_LOCALES: true,
WINDOW: true,
},
attributes: { 'no-console-in-web-worker': null, 'web-worker-restriction': null },
attributes:
{
'no-console-in-web-worker': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
CHROME_PREV:
{
Expand Down Expand Up @@ -977,7 +1001,12 @@ var featureInfos =
'WINDOW',
],
attributes:
{ 'char-increment-restriction': null, 'unstable': null, 'web-worker-restriction': null },
{
'char-increment-restriction': null,
'unstable': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
FF_ESR:
{
Expand Down Expand Up @@ -1033,7 +1062,12 @@ var featureInfos =
'WINDOW',
],
attributes:
{ 'char-increment-restriction': null, 'unstable': null, 'web-worker-restriction': null },
{
'char-increment-restriction': null,
'unstable': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
IE_9:
{
Expand Down Expand Up @@ -1217,6 +1251,7 @@ var featureInfos =
'no-console-in-web-worker': null,
'old-safari-restriction': null,
'web-worker-restriction': null,
'non-ie-restriction': null,
},
},
SAFARI_7_1:
Expand Down
1 change: 1 addition & 0 deletions test/helpers/feature-emulation.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@
if (toString() !== '[object Undefined]')
registerDefaultToStringAdapter(this, undefined, '[object Undefined]');
},
OBJECT_W_SELF: makeEmuFeatureSelf('[object Window]', /^\[object Window]$/),
OLD_SAFARI_LOCATION_CTOR:
function ()
{
Expand Down
Loading