変数などを置き換えるランダムな文字列を使用して、元のコードを難読化し、作成したコードを保護します。これにより、他人がコードを直接盗用する コードのコピーを助長することはありません。 コードは次のとおりです: <BR><-- <BR>/**//**//** <BR>** <BR>===================================== == ======================== <BR>===================== === ============= <BR>** クラス名: CLASS_CONFUSION <BR>** 機能: JS 難読化 <BR>** 例: <BR> ------ ---------------------------------------------------- <BR>------------------------------------------ <br><br> var xx = 新しい CLASS_CONFUSION(コード); <br><br> document.getElementById("display").innerHTML = <BR><br> --------- ----------------------------------------------- <br> ----------------------------------------------- <BR>* * 著者: ttyp <BR>** 電子メール: ttyp@21cn.com <BR>** 日付: 2006-3-20 <BR>** バージョン: 0.12 <BR>** <BR>====== ==== ============================================ ==== == <BR>==================================== <BR>**<🎝>* <BR>** <br>=== ================================================= ========= <br>==================================== <BR>** クラス名: CLASS_CONFUSION <BR>** 機能: JS 難読化 <BR>** 例: <BR> ------------------------ -- ---------------------------------- <BR>----------- ----- ---------------------------- <BR><BR> var xx = 新しい CLASS_CONFUSION(コード) <BR><BR> ドキュメント .getElementById("display").innerHTML = <BR>xx.confusion(); <BR><BR> -------------------- ------- -------------------------------- <BR>---------- ---------- ------------------------ <BR>** 作成者: ttyp <BR>** メールアドレス: ttyp@21cn.com <BR> ** 日付: 2006-3-20 <BR>** バージョン: 0.12 <BR>** <BR>================ ========== ===================================== <BR> ========== ========================== <BR>**/ <BR><BR>関数 CLASS_CONFUSION (code){ <BR> //Ha Hashtable class<🎜> function Hashtable(){ <🎜> this._hash = new Object(); <🎜> this.add = function(key,value){ <🎜> if (key)!= "undefined"){<🎜>this._hash [key] = type < >[key];} <🎜> this.count = function(){var i=0;for(var k in <🎜>this._hash){i ;} return i;} <🎜 > this.items = function (key){return this._hash <🎜>[key];} <🎜> this.contains = function(key){return typeof <🎜>(this._hash[key])!= 未定義";}<BR> this.clear = function(){for(var k in <BR>this._hash){delete this._hash[k];}} <br><br> } <br><br> function VariableMap(親){ <BR> this.table = new Hashtable(); <BR> this.level = parent?parent.level 1:0; <BR> this.parent= 親; <BR> this.add = function(key,value){this.table.add <BR>(key,value)}; <BR> this.items = function(key){return this.table.items <BR>(key)}; <BR> this.count = function(){return this.table.count()}; <BR> this.contains = function(key){return <BR>this.table.contains(key);} <BR> this.isParameter = false; <BR> } <br><br> this._caseSensitive = true; <br><br> //文字符串转换は哈希表 <BR> this.str2hashtable = function(key,cs){ <br><br> var _key = key.split(/,/g); <BR> var _hash = new Hashtable(); <BR> var _cs = true; <br><br><BR> if(typeof(cs)=="未定義"||cs==null){ <BR> _cs = this._caseSensitive; <BR> } else { <BR> _cs = cs; <BR> } <br><br> for(var i in _key){ <BR> if(_cs){ <BR> _hash.add(_key[i]); <BR> } else { <BR> _hash.add((_key[i] "").toLowerCase()); <BR> } <br><br> } <BR> return _hash; <BR> } <br><br> //获得必要转换的代码 <BR> this._codetxt = コード; <br><br> if(typeof(syntax)=="未定義"){ <BR> syntax = ""; <BR> } <br><br> this._deleteComment = false; <BR> //否か大小写し敏感 <BR> this._caseSensitive = true; <BR> //得关键字哈希表 <BR> this._keywords = this.str2hashtable <BR>("switch,case,delete,default,typeof,for,in,function,void,this, <BR>boolean ,while,if,return,new,true,false,try,catch,throw,null,el <BR>se,do,var"); <BR> this._function = this.str2hashtable("関数"); <BR> this._var = "var"; <BR> this._beginBlock = "{"; <BR> this._endBlock = "}"; <br><br> this._window = this.str2hashtable <BR>("alert,escape,unescape,document,parseInt,parseFloat"); <BR> //獲得内建对象哈希表 <BR> this._commonObjects = this.str2hashtable <BR>("String,Number,Boolean,RegExp,Error,Math,Date,Object,Array,Gl <BR>obal "); <BR> //得分割文字符 <BR> this._wordDelimiters= " ,.?!;:\/<>(){}[]"'rnt= - <br>|*%@#$^&"; <br> //引用符<br> this._quote = this.str2hashtable("",'"); <br> //行コメント文字 <br> this._lineComment = "//"; <br> //エスケープ文字 <br> this._escape = "\" <br> //複数行の引用符が始まります<br> this._commentOn = "/*"; <br> //複数行の引用の終わり<br> this._commentOff = "*/"; <br> this._execute = "eval" <br> //呼び出し文字<br> this._call = "."; <br> This._varpause = "; <br> This._varContinue = "," <br> // 変数の数 <br> this._varnum = 0; .confusion = function() { <br> var codeArr = new Array(); <br> var word_index = 0; <br> var htmlTxt = new Array() <br><br><br> // を取得します。分割文字配列 (単語分割) <br> for (var i = 0; i <this._codetxt.length i><br> if (this._wordDelimiters.indexOf <br>(this._codetxt. charAt(i)) == -1) { //キーワード <br> が見つかりません if (codeArr[word_index] == null || typeof <br>(codeArr[word_index]) == '未定義') { <br> codearr [word_index] = ""; = 'undefined»&& codearr [word_index] <br> var quote_opned = false; // マークを参照 <br> var Slash_star_comment_opned = false; // 複数行の注記 <br> 🎜 标 <br> var Slash_slash_com replace_opned = false;単一ノート <br>説明マーク<br> var line_num = 1; //行番号<br> var quote_char = "" //引用<br> タグの種類 <br> var call_opened = false; ""; <br> var var_opened = false; <br> var function_opened = false; <br> var var_map = 新しい変数マップ <br>( ); <br> var cur_var_map = var_map; <br> varexecute_opened = false; <br><br> // 分割した単語を押します<br> for (var i=0; i <br> if(this.isVar (codeArr[i])){ <br> ] = "["" <br>this.toHex(call_string) ""] <br> if (codeArr[i]!=this._call){ <br> htmlTxt[htmlTxt.length] = codeArr <br>[i]; <br> call_opened = false;<br> call_string = ""; <br> } <br> } else { <br> if(!this.isVar(codeArr[i]))){ htmlTxt[htmlTxt.length] = "["" <br>this.toHex(call_string) ""]"; <br> if(codeArr[i]!=this._call){ <br> htmlTxt[htmlTxt.length] = codeArr <br>[i]; <br> call_opened = false; <br> } <br> call_string = ""; <br> else{ <br> htmlTxt[htmlTxt.length] = "["" <br>this.toHex(call_string) ""]"; <br> } <br> } <br> 続けます。 <br> } <br><br> //处理空行(转义带来による) <br> if(typeof(codeArr[i])=="未定義"||codeArr <br>[i].length ==0){ <br> 続行; <br> } else if(codeArr[i]==" "){ <br> htmlTxt[htmlTxt.length] = " "; <br> } else if(codeArr[i]=="n"){ <br> //处理换行 <br> } else if (codeArr[i] == "r"){ <br> slash_slash_comment_opened = false; <br> quote_opened = false; <br> var_opened = false; <br> htmlTxt[htmlTxt.length] = "rn"; <br> line_num ; <br> //处理関数里のパラメータ标记 <br> } else if (!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&this.isFunction <br>(codeArr[i])) { <br> htmlTxt[htmlTxt.length ] = codeArr[i]; <br> function_opened = true; <br> } else if (!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i]=="("){ <br> htmlTxt[htmlTxt.length] = codeArr[i] <br> if(function_opened == true){ <br> function_opened =false; <br> var_opened = true; <br> cur_var_map = new VariableMap <br> _map); <br> cur_var_map.isParameter = true; <br> } <br> } else if (!slash_slash_comment_opened&& ! <br>slash_star_comment_opened && !quote_opened &&codeArr[i]==")"){ <br> htmlTxt[htmlTxt.length] = codeArr[i]; <br> //处理var a = new Class(),b=new Date(); 類似の <br>问题 <br> if(cur_var_map.isParameter) <br> { var_opened = false; <br> var_pause = false; <br> <br> } else if (!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i]==";") <br> { htmlTxt[htmlTxt.length] = codeArr[i]; <br> var_opened = false; <br> var_pause = false; <br> if(execute_opened){ <br> execute_opened = false; <br> <br> } else if (!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._var){ htmlTxt[htmlTxt.length] = codeArr[i]; <br> var_opened = true; <br> var_pause = false; <br> } else if(!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._varPause) <br> htmlTxt[htmlTxt.length] ] = codeArr[i]; <br> var_pause = true; <br> } else if(!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._varContinue) <br> htmlTxt[htmlTxt.length] = codeArr[i]; <br> var_pause = false; <br> } else if(!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._beginBlock){ <br> cur_var_map = new VariableMap(cur_var_map); <br> var_opened = false; <br> htmlTxt[htmlTxt.length] = codeArr[i]; <br> } else if(!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._endBlock) <br> cur_var_map = cur_var _map.parent; <br> if(cur_var_map.isParameter){ <br> cur_var_map = cur_var_map.parent; <br> <br> htmlTxt[htmlTxt.length] = codeArr[i]; <br> //处理引用 <br> } else if (!slash_slash_comment_opened&&! <br>slash_star_comment_opened && !quote_opened &&codeArr[i] <br>==this._call){ > //判断引用(.)後面最初の否かは文字母货_$ <br> if(i<word_index-1){ <BR> if(this.isVar(codeArr[i 1]))){ if(call_opened){ <BR> htmlTxt [htmlTxt.length] = <BR>this.toHex(call_string); <BR> <BR> call_opened = true; <BR> else{ <BR> htmlTxt[htmlTxt.length] = this._call; <BR> <BR> }else{ <BR> htmlTxt[htmlTxt.length] = this._call; <BR> <BR> //处理关键字 <BR> } else if (!slash_slash_comment_opened&&! <BR>slash_star_comment_opened && !quote_opened && this.isKeyword <BR>(codeArr[i])){ <BR> htmlTxt[htmlTxt .length] = codeArr[i]; <BR> //处処理eval後の文字列 <BR> } else if (!slash_slash_comment_opened&&! <BR>slash_star_comment_opened && !quote_opened && codeArr[i] <BR>==this._execute){ <BR> htmlTxt[htmlTxt.length] = "window["" <BR>this.to 16進数( codeArr[i]) ""]"; <BR> execute_opened = true; <BR> //window内置对象 <BR> } else if (!slash_slash_comment_opened&&! <BR>slash_star_comment_opened && !quote_opened && this.isWindow <BR>(codeArr[i])){ <BR> htmlTxt[htmlTxt.length] = "window["" <BR>this.toHex(codeArr[i]) ""]"; <BR> //处理普通对象 <BR> } else if (!slash_slash_comment_opened&&! <BR>slash_star_comment_opened && !quote_opened && <BR>this.isCommonObject(codeArr[i])){ <BR> htmlTxt[htmlTxt.length] = "window["" <BR>this.toHex(codeArr[i]) ""]"; <BR> //处理双引号(引号前は转义文字符) <BR> } else if (!slash_star_comment_opened&&! <BR>slash_slash_comment_opened&&this._quotation.contains(codeArr <BR>[i] )){ <BR> 場合(quote_opened){ <BR> // 相应的引号 <BR> if(quote_char==codeArr[i]) <BR> htmlTxt[htmlTxt] .length] = codeArr[i]; <BR> quote_opened = false; <BR> quote_char = ""; <BR> } else { <BR> htmlTxt[htmlTxt.length] = this.toHex <BR>(codeArr[i]); <BR> } <BR> } else { <BR> htmlTxt[htmlTxt.length] = codeArr[i]; <BR> quote_opened = true; <BR> quote_char = codeArr[i]; <BR> } <BR> //处理转义字符 <BR> } else if(codeArr[i] == this._escape){ <BR> htmlTxt[htmlTxt.length] = codeArr[i]; <BR> if(i<word_index-1){ <BR> if(codeArr[i 1].charCodeAt(0) <BR>>=32&&codeArr[i 1].charCodeAt(0)<=127){ <BR> htmlTxt[htmlTxt.length] = codeArr <BR>[i 1].substr(0,1); <BR> htmlTxt[htmlTxt.length] = this.toHex <BR>(codeArr[i 1].substr(1)); <BR> i=i 1; <BR> } <BR> } <BR> //处理多行注释的开始 <BR> } else if (!slash_slash_comment_opened &&! <BR>slash_star_comment_opened&&!quote_opened&&this.isStartWith <BR>(this._commentOn,codeArr,i) ){ <BR> slash_star_comment_opened = true; <BR> htmlTxt[htmlTxt.length] = this._commentOn; <BR> i = i this.getSkipLength(this._commentOn); <BR> //处理单行注释 <BR> } else if (!slash_slash_comment_opened && ! <BR>slash_star_comment_opened&&!quote_opened&&this.isStartWith <BR>(this._lineComment,codeArr) ,i)){ <BR> slash_slash_comment_opened = true; <BR> if(!this._deleteComment){ <BR> htmlTxt[htmlTxt.length] = <BR>this._lineComment; <BR> <BR> i = i this.getSkipLength(this._lineComment); <BR> //处理忽略词 <BR> } else if (!slash_slash_comment_opened && ! <BR>slash_star_comment_opened&&!quote_opened&&this.isStartWith <BR>(this._ignore,codeArr,i )){ <BR> slash_slash_comment_opened = true; <BR> htmlTxt[htmlTxt.length] = this._ignore; <BR> i = i this.getSkipLength(this._ignore); <BR> //处理多行注释结束 <BR> } else if (!quote_opened&&! <BR>slash_slash_comment_opened&&this.isStartWith <BR>(this._commentOff,codeArr,i)){ <BR> if (slash_star_comment_opened) <BR> slash_star_comment_opened = false; <BR> if(!this._deleteComment){ <BR> htmlTxt[htmlTxt.length] = <BR>this._commentOff; <BR> } <BR> i = i this.getSkipLength <BR>(this._commentOff); <BR> <BR> } else { <BR> //不是字串中 <BR> if(!quote_opened){ <BR> //如果不是在注释重 <BR> if(!slash_slash_comment_opened && ! <BR>slash_star_comment_opened){ <BR> //不定义变量時間 <BR> if(!var_opened){ <BR> { if(this.translateVar <BR>(cur_var_map,codeArr[i])==""){ <BR> htmlTxt[htmlTxt.length] = <BR>codeArr[i]; <BR> else{ <BR> htmlTxt[htmlTxt.length] = <BR>this.translateVar(cur_var_map,codeArr[i]); <BR> } <BR> }else{ <BR> //不是在暂变量定义時間 <BR> if(var_pause){ <BR> if(this.translateVar <BR>(cur_var_map,codeArr[i])== ""){ <BR> htmlTxt[htmlTxt.length] = <BR>codeArr[i]; <BR> }else {<suly>}<BR><BR>の前には、スペースまたはタブ文字、またはコンマが付いているため、次のようなものがあります。パラメータ、例: function(a,b,c) <BR> (this.isVar(codeArr[i])&& <BR>(i>0&&codeArr[i-1]==" "||codeArr[i-1]) ]=="t"||codeArr[i-1] <br>==this._varContinue||cur_var_map.isParameter)){ <br> Cur_var_map.add(codeArr <br>[i],name); 🎜 > htmlTxt[htmlTxt.length] = <br>this.translateVar(cur_var_map,codeArr[i]); htmlTxt[htmlTxt.length] = <br>codeArr[i] <br> <br>} } <br> //コメント<br>} else {<br>if(!this._deletecomment){<br>htmltxt [htmltxt.length] = codearr <br> [i];else{ <br> if(execute_opened){ <br> if(this.translateVar <br>(cur_var_map,codeArr[i])=="") <br> { htmlTxt[htmlTxt.length] = codeArr <br>[私]; <br> else{ <br> htmlTxt[htmlTxt.length] = <br>this.translateVar(cur_var_map,codeArr[i]); <br> <br> }else{ <br> htmlTxt[htmlTxt.length] = this.toHex <br>(codeArr[i ]); <br> } <br> <br> } <br><br> <br><br> return htmlTxt.join("") ; <br> } <br>this.isStartWith = function(str,code,index){ <br><br> if(typeof(str)!="unknown"&&str.length>0){ <br> var cc = new Array(); <br> for(var i=index;i<index str.length;i ){ <BR> cc[cc.length] = code[i]; <BR> } <BR> var c = cc.join(""); <BR> if(this._caseSensitive){ <BR> if(str.length>=code[index].length&&c.indexOf <br>(str)==0){ <br> return true; <br> <br> }else{ <br> if(str.length>[index].length&&c.toLowerCase().indexOf(str.toLowerCase()) <br>== 0){ <br> true を返します。 <br> <br> } <br> return false; <br><br> } else { <br> return false; <br> } <br> } <br><br> this.isFunction = function(val){ <br> return this._function.contains(this._caseSensitive? <br>val:val.toLowerCase()); <br> } <br><br> this.isKeyword = function(val) { <br> return this._keywords.contains(this._caseSensitive? <br>val:val.toLowerCase()); <br> } <br><br> this.isWindow = function(val) { <br> return this._window.contains(this._caseSensitive? <br>val:val.toLowerCase()); <br> }<br><br> this.isCommonObject = function(val) { <br> return this._commonObjects.contains <br>(this._caseSensitive?val:val.toLowerCase()); <br> } <br><br> this.getSkipLength = function(val){ <br> var count = 0; <br> for(var i=0;i<val.length> if(this._wordDelimiters.indexOf(val.charAt(i)) <br>>>=0){ <br> count ; <br> } <br> } <br> if(count>0){ <br> count=count-1; <br> } <br> リターン数; <br> } <br><br> //文字串转换は16进形式 <br> this.toHex = function(val){ <br> var str = new Array(); <br> for(var i=0;i<val.length;i ){ <BR> var c = val.charCodeAt(i); <BR> if(c>=0&&c<256){ <br> str[str.length] = "\x" val.charCodeAt <br>(i).toString(16); <br> }else{ <br> str[str.length] = "\u" val.charCodeAt <br>(i).toString(16); <br> } <br> } <br> return str.join(""); <br> } <br><br> //获得变量随机名 <br> this.getRandName = function(){ <br> var style = parseInt(Math.random()*4); <br> var len = parseInt(Math.random()*9) 1; <br> var n = []; <br><br> this._varNum ; <br> var c = <br>"abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"; <br><br> for(var i=0;i<len;i ){ <br> n[n.length] = c.charAt(parseInt(Math.random() <br>*54)); <br> } <br><br> return n.join("") this._varNum; <br><br> } <br><br> //否符合变量命名字首规则 <br> this.isVar = function(val){ <br> return /^[a-zA-Z_$].* $/.test(val); <br> } <br><br> // 翻译变量,如果返空空则不存在此变量 <br> this.translateVar = function(node,key){ <br> if(node.contains(key)) { <br> return node.items(key); <br> } <br><br> var cn = node.parent; <br> while(cn!=null){ <br> if(cn.contains(key)){ <br> return cn.items(key); <br> } <br> cn = cn.parent; <br> } <br> return ""; <br> } <br><br><br>}<br><br>function doConfusion(o){ <br> var htmltxt = ""; <br><br> if (o == null){ <br> alert("domNode is null!"); <br> 戻る; <br> } <br><br> var _codetxt = ""; <br><br> if(typeof(o)=="object"){ <br> switch(o.tagName){ <br> case "TEXTAREA": <br> case <br> _codetxt = o.値; <br> 休憩; <br> case "DIV": <br> case "SPAN": <br> _codetxt = o.innerText; <br> 休憩; <br> デフォルト: <br> _codetxt = o.innerHTML; <br> 休憩; <br> } <br> }else{ <br> _codetxt = o; <br> } <br><br> var _syn = 新しい CLASS_CONFUSION(_codetxt); <br> htmltxt = _syn.confusion(); <br> 戻り htmltxt; <br>} <br><br><br>function go() <br>{ <br> var code = document.getElementById("code").value; <br> var xx = 新しい CLASS_CONFUSION(コード); <br> var a = 新しい Date(); <br> document.getElementById("display").value = xx.confusion(); <br> alert("共花:" (new Date().getTime()-a.getTime()) <br>"ms"); <br>} <br>//--> <br>