js代碼混淆工具(js混淆破解)

本文目錄一覽:

UglifyJS怎麼混淆js

如果你是全局安裝的,可以直接在需要混淆文件的目錄下,

按住shift鍵右擊滑鼠選擇在此處打開命令窗口如圖

2.打開窗口後直接在窗口執行

uglifyjs main.js demo.js -o foo.min.js –source-map foo.min.js.map –source-map-root  -p 5 -c -m –wrap –export-all

混淆文件main.js和demo.js生成foo.min.js和foo.min.js.map並指定map的來源網站

3.另一種使用方式是,把UglifyJS2包放到程序中,通過API對JS文件或JS代碼進行壓縮。首先,新建一個NPM項目文件package.json,然後在是下載UglifyJS2依賴包。

新建文件package.json

{

  “name”: “nodejs-uglifyjs2”,

  “version”: “0.0.1”,

  “description”: “uglifyjs2”,

  “author”: “Conan Zhang “,

  “dependencies”: {

  }

}

4.執行npm install uglify-js –save下載UglifyJS2依賴包

5.安裝完成後

新建test.js開始測試

var UglifyJS = require(‘uglify-js’);

 

//代碼壓縮

var result = UglifyJS.minify(“var b = function () {};”, {fromString: true});

console.log(“\n===========================”);

console.log(result);

 

//文件壓縮

result = UglifyJS.minify([“demo.js”]);

console.log(“\n===========================”);

console.log(result.code);

//多文件壓縮,指定source map和網站來源

result = UglifyJS.minify([“main.js”,”demo.js”],{

    outSourceMap: “out.js.map”,

    sourceRoot: “”,

    mangle:true

});

console.log(“\n===========================”);

console.log(result.code);

console.log(result.map);

有沒有比np好用的混淆工具

YUICompressor。YUICompressor是市場最通用的js混淆工具,其操作簡單,混淆程度高,相比於操作難度高np好用多了。

JS代碼混淆了,怎麼反混淆回去?

這不是混淆,只是使用16進位表示的ASCII碼~

單獨提取出字元串,在後面加上.toString()進行調試即可看到原本字元串。

你的這句轉碼後如下:

window[“document”][“write”](‘sc’)

相當於:window.document.write(‘sc’)

很有可能是輸出一個script標籤的代碼段的開始。

npm安裝完uglifyjs怎麼對js代碼進行混淆

如果你是全局安裝的,可以直接在需要混淆文件的目錄下,

按住shift鍵右擊滑鼠選擇在此處打開命令窗口如圖

2.打開窗口後直接在窗口執行

uglifyjs main.js demo.js -o foo.min.js –source-map foo.min.js.map –source-map-root  -p 5 -c -m –wrap –export-all

混淆文件main.js和demo.js生成foo.min.js和foo.min.js.map並指定map的來源網站

3.另一種使用方式是,把UglifyJS2包放到程序中,通過API對JS文件或JS代碼進行壓縮。首先,新建一個NPM項目文件package.json,然後在是下載UglifyJS2依賴包。

新建文件package.json

{

  “name”: “nodejs-uglifyjs2”,

  “version”: “0.0.1”,

  “description”: “uglifyjs2”,

  “author”: “Conan Zhang “,

  “dependencies”: {

  }

}

4.執行npm install uglify-js –save下載UglifyJS2依賴包

5.安裝完成後

新建test.js開始測試

var UglifyJS = require(‘uglify-js’);

//代碼壓縮

var result = UglifyJS.minify(“var b = function () {};”, {fromString: true});

console.log(“\n===========================”);

console.log(result);

//文件壓縮

result = UglifyJS.minify([“demo.js”]);

console.log(“\n===========================”);

console.log(result.code);

//多文件壓縮,指定source map和網站來源

result = UglifyJS.minify([“main.js”,”demo.js”],{

    outSourceMap: “out.js.map”,

    sourceRoot: “”,

    mangle:true

});

console.log(“\n===========================”);

console.log(result.code);

console.log(result.map);

js代碼混淆 以及 混淆後如何使用

js反混淆需要藉助第三方工具:

1、在百度搜索js混淆還原

2、把要還原的代碼放在第一個文本框,點擊js解混淆就可以了。

結果在下面顯示

怎麼使用yuicompressor2.4.2.jar進行js,CSS進行代碼混淆

目前開發Web應用Javascript發揮的作用越來越大,相關的Javascript框架也比較多。但是有一個問題,我們開發過程中,所有的JS代碼都添加了注釋,如使用JsDoc,代碼的可讀性比較強,同時這樣的代碼也便於調試。但是在產品環境中,我們希望這些JS代碼是壓縮和混淆過的,這主要是讓 JS代碼載入的更快,這也是Google AJAX Libraries API出現的原因。YUI Compressor 是一款由 Yahoo 公司開發的、功能非常強大的 JS、CSS 代碼混淆和壓縮工具,採用Java開發,目前很多Javascript Framework都使用YUI Compressor進行代碼分發。

二、使用簡介:

在命令行下執行 Java 程序,運行 yuicompressor jar 軟體包,來完成任務:

//壓縮JS

    java -jar yuicompressor-2.4.2.jar –type js –charset utf-8 -v src.js packed.js

//壓縮CSS

    java -jar yuicompressor-2.4.2.jar –type css –charset utf-8 -v src.css packed.css

三、參考官方英文注釋:

3.1 How does the YUI Compressor work?

The YUI Compressor is written in Java (requires Java = 1.4) and relies on Rhino to tokenize the source JavaScript file. It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, omitting as many white space characters as possible, and replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate (in the face of evil features such as eval or with, the YUI Compressor takes a defensive approach by not obfuscating any of the scopes containing the evil statement) The CSS compression algorithm uses a set of finely tuned regular expressions to compress the source CSS file. The YUI Compressor is open-source, so don’t hesitate to look at the code to understand exactly how it works.

3.2 Using the YUI Compressor from the command line

java -jar yuicompressor-x.y.z.jar

Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]

Global Options

      -h, –help                Displays this information

      –type js|css           Specifies the type of the input file

      –charset charset       Read the input file using charset

      –line-break column     Insert a line break after the specified column number

      -v, –verbose             Display informational messages and warnings

      -o file                 Place the output into file. Defaults to stdout.

JavaScript Options

      –nomunge                 Minify only, do not obfuscate

      –preserve-semi           Preserve all semicolons

      –disable-optimizations   Disable all micro optimizations

GLOBAL OPTIONS

-h, –help

        Prints help on how to use the YUI Compressor

–line-break

        Some source control tools don’t like files containing lines longer than,

        say 8000 characters. The linebreak option is used in that case to split

        long lines after a specific column. It can also be used to make the code

        more readable, easier to debug (especially with the MS Script Debugger)

        Specify 0 to get a line break after each semi-colon in JavaScript, and

        after each rule in CSS.

–type js|css

        The type of compressor (JavaScript or CSS) is chosen based on the

        extension of the input file name (.js or .css) This option is required

        if no input file has been specified. Otherwise, this option is only

        required if the input file extension is neither ‘js’ nor ‘css’.

–charset character-set

        If a supported character set is specified, the YUI Compressor will use it

        to read the input file. Otherwise, it will assume that the platform’s

        default character set is being used. The output file is encoded using

        the same character set.  IMPORTANT: if you do not supply this argument

        and the file encoding is not compatible with the system’s default

        encoding, the compressor will throw an error.  In particular, if your

        file is encoded in utf-8, you should include this parameter.

-o outfile

        Place output in file outfile. If not specified, the YUI Compressor will

        default to the standard output, which you can redirect to a file.

-v, –verbose

        Display informational messages and warnings.

JAVASCRIPT ONLY OPTIONS

–nomunge

      Minify only. Do not obfuscate local symbols.

–preserve-semi

      Preserve unnecessary semicolons (such as right before a ‘}’) This option

      is useful when compressed code has to be run through JSLint (which is the

      case of YUI for example)

–disable-optimizations

      Disable all the built-in micro optimizations.Note: If no input file is specified, it defaults to stdin.

The following command line (x.y.z represents the version number):

java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.jswill minify the file myfile.js and output the file myfile-min.js. For more information on how to use the YUI Compressor, please refer to the documentation included in the archive.

The charset parameter isn’t always required, but the compressor may throw an error if the file’s encoding is incompatible with the system’s default encoding. In particular, if your file is encoded in utf-8, you should supply the parameter.

java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js –charset utf-8

四、YUI Compressor 壓縮 JavaScript 的原理

YUI Compressor 壓縮 JavaScript 的內容包括:

1.移除注釋

    2.移除額外的空格

    3.細微優化

    4.標識符替換(Identifier Replacement)

YUI Compressor 包括哪些細微優化呢?

• object[“property”],如果屬性名是合法的 JavaScript 標識符(註:合法的 JavaScript 標識符——由一個字母開頭,其後選擇性地加上一個或者多個字母、數字或下劃線)且不是保留字,將優化為: object.property

    • {“property”:123},如果屬性名是合法的 JavaScript 標識符且不是保留字,將優化為 {property:123} (註:在對象字面量中,如果屬性名是一個合法的 JavaScript 標識符且不是保留字,並不強制要求用引號引住屬性名)。

    • ‘abcd/’efgh’,將優化為 “abcd’efgh”。

    • “abcd” + “efgh”,如果是字元串相連接,將優化成 “abcdefgh”(註:所有在使用 YUI Compressor 的前提下,對於腳本中的字元串連接,使用連接符 「+」 的效率和可維護性最高)。

    對於 JavaScript 最有效的壓縮優化,當屬標識符替換。

比如:

(function(){function add(num1, num2) {return num1 + num2;}})();

進行屬標識符替換後:

(function(){function A(C, B) {return C+ B;}})();

再移除額外的空格,最終成了:

(function(){function A(C,B){return C+B;}})();

YUI Compressor 標識符替換僅替換函數名和變數名,那哪些不能被替代呢?

1.原始值:字元串、布爾值、數字、null 和 undefined。一般來說字元串占的空間最多,而非數字字面量其次(true、false,null,underfinded)。

    2.全局變數:window、document、XMLHttpRequest等等。使用最多的就是 document、window。

    3.屬性名,比如:foo.bar。佔據的空間僅次於字元串,」.」 操作符無法被代替,且 a.b.c 更加費空間。

    4.關鍵字。經常被過度使用的關鍵字有:var、return。最好的優化方法:一個函數僅出現一次 var 和 return 關鍵字。

    對於原始值、全局變數、屬性名的優化處理方式大致相同:任何字面量值、全局變數或者屬性名被使用超過 2 次(包括2次),都應該用局部變數存儲代替。

但有部分情況下是禁止使用標識符替換的:

1.使用 eval() 函數。解決方法:不使用或者創建一個全局函數封裝 eval()。

    2.使用 with 語句。解決方法:方法同上。

    3.JScript 的條件注釋。唯一解決的方法:不使用。

    由於 YUI Compressor 是建立在 rhino interpreter 基礎上的,所以上述所有的優化都是安全的。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/201242.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-06 11:31
下一篇 2024-12-06 11:31

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • JS Proxy(array)用法介紹

    JS Proxy(array)可以說是ES6中非常重要的一個特性,它可以代理一個數組,監聽數據變化並進行攔截、處理。在實際開發中,使用Proxy(array)可以方便地實現數據的監…

    編程 2025-04-29
  • Python字典去重複工具

    使用Python語言編寫字典去重複工具,可幫助用戶快速去重複。 一、字典去重複工具的需求 在使用Python編寫程序時,我們經常需要處理數據文件,其中包含了大量的重複數據。為了方便…

    編程 2025-04-29
  • Python字元串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字元串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字元串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變數和數…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在著手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29
  • 怎麼寫不影響Python運行的長段代碼

    在Python編程的過程中,我們不可避免地需要編寫一些長段代碼,包括函數、類、複雜的控制語句等等。在編寫這些代碼時,我們需要考慮代碼可讀性、易用性以及對Python運行性能的影響。…

    編程 2025-04-29

發表回復

登錄後才能評論