Bug in obfuscate js code.

未關閉
#24 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
javascript

研究方向

未指定任何儲存庫檔案、測試、版本或設定。首先透過 gulp 混淆管線重現所提供的 Painter 範例,並比較為 this.prePaint、this.paint 和 this.postPaint 產生的參照。完成的標準是,混淆後的程式碼保留可呼叫的屬性參照,而不需要插入換行符號。

由索引模型根據 Issue 內容生成。

描述

bug cannot reproduce

First at all, sorry for my english, i will try to explain it as better as possible.

I have the following js code:

    export const Painter = function (elements, data) {
        let title = elements.title;
        let container = elements.container;
        this.prePaint = () => { };
        this.paint = () => { };
        this.postPaint = () => { };
        let finalPaint = () => {
            this.prePaint = () => { };
            this.paint = () => { };
            this.postPaint = () => { };
            createPromise();
        };

        let createPromise = () => {
            return new Promise((resolve, reject) => {
                this.paint = () => { resolve() }
            }).then(() => {
                this.prePaint(elements, data);
                title.innerHTML = data.title;
                container.innerHTML = data.html;
                this.postPaint(elements, data);
                finalPaint();
            });
        }

        createPromise();
    };

When i obfuscate this code, it seems like this (it was minimized and formatted by the browser):

5: [function(a, b, c) {
        "use strict";
        Object[_0x56ae("0x6")](c, _0x56ae("0x6e"), {
            value: !0
        });
        c[_0x56ae("0xb5")] = function(a, b) {
            var c = this
              , d = a[_0x56ae("0xb6")]
              , e = a[_0x56ae("0xb7")];
            this.prePaint = function() {}      //// THIS LINE
            ,
            this[_0x56ae("0xb8")] = function() {}
            ,
            this[_0x56ae("0xb9")] = function() {}
            ;
            var f = function() {
                c[_0x56ae("0xba")] = function() {}
                ,
                c.paint = function() {}         ///// THIS LINE TOO
                ,
                c.postPaint = function() {}       ///// AND THIS LINE TOO
                ,
                g()
            }
              , g = function() {
                return new Promise(function(a) {
                    c.paint = function() {
                        a()
                    }
                }
                )[_0x56ae("0x24")](function() {
                    c[_0x56ae("0xba")](a, b),
                    d.innerHTML = b[_0x56ae("0xb6")],
                    e.innerHTML = b[_0x56ae("0x34")],
                    c.postPaint(a, b),
                    f()
                })
            };
            g()
        }
    }
    , {}]

You can see, how the fisrt this.prePaint has not transformed to this[_0x56ae("0xba")] and when this is called, it said undefined function.
But if i insert breaklines between all this "problematic" lines, it work. Like this:


export const Painter = function (elements, data) {
    let title = elements.title;
    let container = elements.container;

    this.prePaint = () => { };

    this.paint = () => { };

    this.postPaint = () => { };

    let finalPaint = () => {

        this.prePaint = () => { };

        this.paint = () => { };

        this.postPaint = () => { };

        createPromise();
    };

    let createPromise = () => {
        return new Promise((resolve, reject) => {

            this.paint = () => { resolve() }

        }).then(() => {
            this.prePaint(elements, data);

            title.innerHTML = data.title;
            container.innerHTML = data.html;

            this.postPaint(elements, data);

            finalPaint();

        });
    }

    createPromise();
};

I did fix this issue with this partial solution, but i don't know where more places of my code, will appear the same issue.

Thank you

主要語言
JavaScript
星號
103
分支
37
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

javascript-obfuscator/gulp-javascript-obfuscator 的其他 Issue

查看 javascript-obfuscator/gulp-javascript-obfuscator 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。