Let's say I have a normal function:
function coolsecretalgo() {
return 42;
}
I tought of hiding it's code by using this function:
function hide(fname) {
var fn=self[fname]
Object.defineProperty(fn,"toString",{"value": ()=>fname+"() { [native code] }"})
Object.defineProperty(fn.toString,"toString",{"value": ()=>"toString() { [native code] }"})
Object.defineProperty(fn.toString.toString,"toString",{"value": fn.toString.toString})
}
Is there any way to unhide such hidden function?
hide("coolsecretalgo")
undefined
coolsecretalgo
ƒ coolsecretalgo() { [native code] }
coolsecretalgo.toString
ƒ toString() { [native code] }
coolsecretalgo.toString.toString
ƒ toString() { [native code] }
coolsecretalgo.toString.toString.toString
ƒ toString() { [native code] }
Are there better ways to do it?
I mean: is it possible to write a function like:
function unhide(funcname) {
...some code..
}
and then
unhide("coolsecretalgo")
and get back the original code?