JGraph 中的 eval 隐藏代码与混淆\打包

发布于 2024-11-06 09:15:42 字数 285 浏览 1 评论 0 原文

几乎每次出现关于 eval 的问题时,答案都是一样的——不要使用 eval。我认为 eval 存在是有原因的。但还有很多差距需要下降。

那么关于 jgraph - 为什么他们使用 eval(在此 示例 中);当有 JavaScript 的混淆和打包工具时,使用 eval 来隐藏代码是否实用?这是唯一的“实际”用途吗?

那里涉及很多钱,所以我认为他们知道自己在做什么。

Almost every time when there is a question about eval, the answer is the same - do not use eval. I think that there is a reason eval to exist. But there are manny gaps to fall.

So about jgraph - why they use eval(in this example); is it practical to use eval to hide code, when there is obfuscation and packing tools for javascript? Is this the only "practical" use?

There are a lot of money involved there, so I think they know what they are doing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南笙 2024-11-13 09:15:42

那里涉及很多钱,所以我认为他们知道自己在做什么。

并不真地。这是一项毫无意义的措施,旨在减缓 JS 开发人员的任何潜在抄袭行为,但实际上,它最多会比获得去混淆代码所需的步骤增加 30 秒。例如,考虑一下如果我打开 http://jsFiddle.nethttp://jsbin.com 并在 JavaScript 框中输入以下内容:

var txt = "textContent" in document.body ? "textContent" : "innerText",
    eval = function (s) { document.body[txt] = s; }

然后,我将该网站的代码复制并粘贴到小提琴中的正下方,然后单击运行。结果是,所有代码都转储到页面上,以便我可以将其复制并粘贴到 http://jsbeautifier.org。这并不是转储代码的唯一方法。人们只需将字符串复制并粘贴到任何开发人员工具控制台窗口中即可获得结果。

混淆是一回事,但在我看来,使用 eval 添加额外的层是业余的,抓住救命稻草并表现出绝望地隐藏其宝贵的源代码。这根本不表明他们知道自己在做什么。

There are a lot of money involved there, so I think they know what they are doing.

Not really. It's a pointless measure designed to slow down any potential plagiarism from JS developers but in reality it adds, at most, 30 seconds to the steps necessary to attain the de-obfuscated code. For instance, consider what happens if I open http://jsFiddle.net or http://jsbin.com and type the following into the JavaScript box:

var txt = "textContent" in document.body ? "textContent" : "innerText",
    eval = function (s) { document.body[txt] = s; }

Then, I copy and paste the code from that site directly below this in the fiddle and hit run. The result is, all the code is dumped onto the page so that I can copy and paste it into http://jsbeautifier.org. And that isn't the only way to dump the code. One could just copy and paste the string into any developer tools console window and get the result.

Obfuscation is one thing, but adding an extra layer using eval is, in my opinion, amateurish, clutching at straws and showing desperation to hide their precious source code. It doesn't at all show that they know what they're doing.

甜嗑 2024-11-13 09:15:42

你可以使用 eval!它给你更多的可能性!
有时没有其他方法可以做某事。

但是:

  • 通过 eval 执行的代码可能是
    较慢
  • 评估代码中的错误速度确实
    很难找到(你不会排队
    没有
  • 如果经常使用 eval 可能会使您的代码变得不可读

eval 就不可能实现的示例:

var varname = "X";
var varvalue = 5;
eval("var "+varname+" = "+varvalue+";");
console.log(X);

You CAN use eval! It gives you much more possibilities!
Sometimes there is no other way to do something.

But:

  • code executed through eval is maybe
    slower
  • errors in evaled codes are really
    hard to find (you don´t get line
    numbers or something)
  • eval could make your code unreadable if used to often

Example that would be impossible without eval:

var varname = "X";
var varvalue = 5;
eval("var "+varname+" = "+varvalue+";");
console.log(X);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文