Is Javascript anonymous function persisted? (Using Java applet, way to hide JS code)

I am writing an application using Javascript. I'm looking for a way to hide my code and I believe I found it using a Java applet.

Anyway, I think this should only be possible if the jon's code of the anonymous functions does not remain available in any way after it has been evaluated.

(function(){...}).call(obj)

      

Applets can get a link to the browser window they are in and call its method eval

to evaluate the js code:

// java code
JSObject window = JSObject.getWindow(this);
window.eval( "(function(){"
  + ...
  + "}).call("
  + thisObjectName
  + ")" );

      

This way I can change my js code so that some functions instead of the inner code call the applet function, which asks the window for the eval

source code of the js function, navigating to the window anonymous so that the function reference is not saved. Of course, the js function must give the java function the object name ( this

), and the java function must compose an anonymous function adding a method call call(objectName)

to use the reference correctly this

.

MyJsClass.prototype.func = function() { ... };

      

becames:

MyJsClass.prototype.func = function() 
{
  ...
  myApplet.evalJsCode(thisObjectName);
  ...
};

      


[UPDATE] My idea was not good for two reasons

  • Java bytecode (.class) is easy to decompile (thanks to Pointy )

  • The function window.eval

    called by the applet is the same thing that you can override via javascript (thanks Yoshi )

+3


source to share


1 answer


Have you considered the next opportunity?

window.eval = function (code) {
  console.log('code');
};

eval('alert(1)');

      



Meaning: Almost no effort canceling the function eval

.

+4


source







All Articles