How to hide library source code in Google way?

前端 未结 2 719
失恋的感觉
失恋的感觉 2021-01-07 01:33

For instance, I have a library and I would like to protect the source code to being viewed. The first method that comes to mind is to create public wrappers for private func

2条回答
  •  遥遥无期
    2021-01-07 02:07

    Edit: changed my answer to reflect the fact that an exception's stacktrace will contain the library project key.

    In this example, MyLibraryB is a library included by MyLibraryA. Both are shared publicly to view (access controls) but only MyLibraryA's project key is made known. It appears it would be very difficult for an attacker to see the code in MyLibraryB:

    //this function is in your MyLibraryA, and you share its project key
    function executeMyCoolFunction(param1, param2, param3) {
      for (var i = 0; i < 1000000; i++) {
        debugger; //forces a breakpoint that the IDE cannot? step over
      }
      //... your code goes here
      //don't share MyLibraryB project key
      MyLibraryB.doSomething(args...); 
    }
    

    but as per the @megabyte1024's comments, if you were to cause an exception in MyLibraryB.doSomething(), the stacktrace would contain the project key to MyLibraryB.

提交回复
热议问题