-1

Help me out!

I would like to ask how to implement my Obfuscated code?

heres my sample code

var accessToken = $('#access_token').val();
var myapp = angular.module("loginApp", []);


myapp.controller("loginCtrl", function ($scope, $http) {
    $scope.log_username = '';
    $scope.log_password = '';
    $scope.loginfirst = $("#reqerr").val();

sample code obfuscated code

eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('3 4=$(\'#8\').2();3 1=7.6("5",[]);1.g("9",e($0,$f){$0.d=\'\';$0.c=\'\';$0.a=$("#b").2();',17,17,'scope|myapp|val|var|accessToken|loginApp|module|angular|access_token|loginCtrl|loginfirst|reqerr|log_password|log_username|function|http|controller'.split('|'),0,{}))

my problem is how do i implement it? i tried to replace my sample code with obfuscated code, i got an error, and i have no idea on how should i implement it?

PS dont mind the code above , its just a sample..

1 Answers1

-2

You need a special tool like google's closure compiler, but before that you need to properly inline annotate your services like so...

myapp.controller("loginCtrl", ["$scope", "$http", function ($scope, $http) {
    ....
}])

This statement clarifies why, and is correct.

"When minifying, variable names are changed to save space. That means the $scope variable could be renamed to 'a', which interferes with AngularJS' dependency injection. Annotating the services allows AngularJS to keep the relationship between minified variables and the service they represent" - bob esponja

Then follow the steps below:

Step 1) Download http://dl.google.com/closure-compiler/compiler-latest.zip

Step 2) run (you need to install java's JRE or JDK)

java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js
sss
  • 1,259
  • 9
  • 23
  • Don't mind the code above it just a sample.. i just want to know how should i implement my obfuscated code to my project/javasacript.. – Enzo DooDz Armero Oct 01 '14 at 09:06
  • 3
    This really should just be a comment, not an answer. – Cerbrus Oct 01 '14 at 09:11
  • happy to have helped... you're welcome... =) – sss Oct 01 '14 at 09:14
  • 2
    Link-only answers aren't considered "Okay" on SO. – Cerbrus Oct 01 '14 at 09:15
  • and is more easily readable on answer space -- – sss Oct 01 '14 at 09:15
  • Cerbrus already mentioned that link-only answers aren't considered good answers on SO. The link may stop working in the future, it can be hard to identify the relevant content, etc. From http://stackoverflow.com/help/how-to-answer "Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline." – bob esponja Oct 01 '14 at 09:23
  • ok... you should have told me earlier... – sss Oct 01 '14 at 09:23
  • Your short code snippet doesn't answer the question. It may or may not be the solution, but you haven't explained why it works. Then, to answer how to obfuscate JS code, you just added a link. – Cerbrus Oct 01 '14 at 09:26
  • right, have edited my updates. – sss Oct 01 '14 at 09:26
  • It still doesn't explain why that code snippet helps. – Cerbrus Oct 01 '14 at 09:28
  • anyways sorry... i should be going on my own business now, thanks for allowing me to improve my writing. – sss Oct 01 '14 at 09:32
  • When explaining why it works, in my opinion saying "You need to properly inline annotate your services" still doesn't explain the reason behind the code. So that readers can understand _why_ annotating the services is needed, you could say something along the lines of "When minifying, variable names are changed to save space. That means the `$scope` variable could be renamed to `a`, which interferes with AngularJS' dependency injection. Annotating the services allows AngularJS to keep the relationship between minified variables and the service they represent". – bob esponja Oct 01 '14 at 09:45
  • It was meant as a starting point, but I guess quoting it is fine :) – bob esponja Oct 01 '14 at 10:49