当前位置:  开发笔记 > 编程语言 > 正文

什么是最好的JavaScript混淆器?

如何解决《什么是最好的JavaScript混淆器?》经验,为你挑选了3个好方法。

我希望使用javascript混淆器.什么是最流行的,它们对性能有什么影响?



1> Jeremy DeGro..:

雅虎有一个非常好的.它在技术上是一个缩小器,但它在这个过程中做了很好的混淆.

YUI压缩机


链接不再有效

2> AareP..:

测试了8个不同的混淆器(www.javascriptobfuscator.com除外),并且惊讶于他们都吮吸了多少.结束使用正则表达式编写自己的混淆器.请享用:

static Dictionary names = new Dictionary();
static bool testing = false;
static string[] files1 = 
    @"a.js,b.js,c.js"
    .Split(new string[] { Environment.NewLine, " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries);
static string[] ignore_names = 
    @"sin,cos,order,min,max,join,round,pow,abs,PI,floor,random,index,http,
    __defineGetter__,__defineSetter__,indexOf,isPrototypeOf,length,clone,toString,split,clear,erase
    RECT,SIZE,Vect,VectInt,vectint,vect,int,double,canvasElement,text1,text2,text3,textSizeTester,target,Number
    number,TimeStep,images,solid,white,default,cursive,fantasy,".
  Split(new string[] { Environment.NewLine, " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries);
string[] extra_names = @"a,b,c".Split(new string[] { Environment.NewLine, " ", "\t", "," }, StringSplitOptions.RemoveEmptyEntries);
string src = @"C:\temp";
string dest1 = src + "\\all1.js";
string dest2 = src + "\\all2.js";

static void Main()
{
  File.Delete(dest1);
  File.Delete(dest2);
  foreach (string s in files1)
    File.AppendAllText(dest1, File.ReadAllText(src + "\\" + s) + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine, Encoding.UTF8);

  string all = File.ReadAllText(dest1);
  int free_index = 0;

  foreach (string s in extra_names)
  {
    free_index++;
    string free_name = "" + (char)('A' + (free_index % 25)) + (char)('A' + ((free_index / 25) % 25));
    Debug.Assert(free_name != "AA");
    names.Add(s, free_name);
  }

  Regex reg1 = new Regex("(var |function |\\.prototype\\.)([a-zA-Z0-9_]+)");

  int startat = 0;
  while (startat < all.Length)
  {
    Match match = reg1.Match(all, startat);
    if (!match.Success)
      break;

    string key = all.Substring(match.Groups[2].Index, match.Groups[2].Length);
    if (!ignore_names.Contains(key))
    {
      free_index++;
      string free_name = "" + (char)('A' + (free_index % 25)) + (char)('A' + ((free_index / 25) % 25));
      Debug.Assert(free_name != "AA");
      if (!names.ContainsKey(key))
        names.Add(key, testing ? key + free_name : free_name);
    }
    startat = match.Groups[0].Index + match.Groups[0].Length;
  }

  Regex reg2 = new Regex(@"/\*.*\*/", RegexOptions.Multiline);
  Regex reg3 = new Regex("([^:\\\\])//.*\r\n");
  Regex reg4 = new Regex("([a-zA-Z0-9_]+)");
  Regex reg5 = new Regex("(\r\n)*[ \t]+");
  Regex reg6 = new Regex("(\r\n)+");
  all = reg2.Replace(all, eval2);
  all = reg3.Replace(all, eval3);
  all = reg4.Replace(all, eval4);
  all = reg5.Replace(all, eval5);
  all = reg6.Replace(all, eval6);
  File.WriteAllText(dest2, all);
}

public static string eval4(Match match)
{
  return names.ContainsKey(match.Groups[1].Value) ? names[match.Groups[1].Value] : match.Groups[0].Value;
}
public static string eval5(Match match)
{
  return string.IsNullOrEmpty(match.Groups[1].Value) ? " " : Environment.NewLine;
}
public static string eval6(Match match)
{
  return Environment.NewLine;
}
public static string eval2(Match match)
{
  return " ";
}
public static string eval3(Match match)
{
  return match.Groups[1].Value + Environment.NewLine;
}


为什么"他们都吮吸"?您的代码解决了什么问题?
@frenchie好吧,首先,将那些"sucky"混淆器生成的混淆javascript粘贴到http://jsbeautifier.org/上的JavaScript美化器中,并观察它是否立即被混淆.

3> Randolpho..:

好吧,谷歌提出了这作为第一个链接:

http://www.javascriptobfuscator.com

但是我不知道对JavaScript有什么好的混淆。无论您在javascript中需要进行混淆处理的是什么,都应该在服务器端完成,对吗?

推荐阅读
云聪京初瑞子_617
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有