Bug in obfuscate js code.

Aberta
#24 3 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
javascript
Domínio
build-system, tooling

Direção de pesquisa

Nenhum arquivo do repositório, teste, versão ou configuração é especificado. Comece reproduzindo o exemplo Painter fornecido por meio do pipeline de ofuscação do gulp e compare as referências geradas para this.prePaint, this.paint e this.postPaint. Está concluído quando o código ofuscado preserva referências de propriedades chamáveis sem exigir quebras de linha inseridas.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
JavaScript
Estrelas
103
Forks
37
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de javascript-obfuscator/gulp-javascript-obfuscator

Todas as issues de javascript-obfuscator/gulp-javascript-obfuscator

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.