Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for unpacking

  • Loading branch information...
commit f271b865b91ffda0d2c07e6af2e9d3b75cd3f8f2 1 parent 7a48b95
Chris O'Hara authored December 19, 2010
15  README.md
Source Rendered
@@ -28,13 +28,10 @@ hello1.js
28 28
 
29 29
 hello2.js
30 30
 
31  
-	packed =  "5b3be6d94448754b6d8484a78b5f30d7a2c2598105d0e225166a0132bef8b1cb30e252c835e25d40";
32  
-	packed += "e1a5542b809641159ab7c7dbfff1b2ba5177c6e291b3d9b5";
33  
-	exports.unpack = function (password) {
34  
-		var decipher = require("crypto").createDecipher("aes256", password);
35  
-		eval(decipher.update(packed, "hex", "utf8") + decipher.final("utf8"));
36  
-		return exports;
37  
-	};
  31
+	e="5b3be6d94448754b6d8484a78b5f30d7a2c2598105d0e225166a0132bef8b1cb30e252c835e25d40";
  32
+	e+="e1a5542b809641159ab7c7dbfff1b2ba5177c6e291b3d9b5";
  33
+	exports.unpack=function(p){var d=require("crypto").createDecipher("aes256",p);
  34
+	eval(d.update(e,"hex","utf8")+d.final("utf8"));return exports;}
38 35
 
39 36
 Running both modules
40 37
 
@@ -51,6 +48,10 @@ To specify a custom encryption algorithm or output encoding, use `-a` and `-e`
51 48
 
52 49
     $ packnode -a aes256 -e hex < myscript.js > packed.js
53 50
     
  51
+To unpack a packed node, use the `-u` switch
  52
+
  53
+    $ packnode -u pass123 < packed.js > unpacked.js
  54
+	
54 55
 [node.io](http://node.io) has built-in support for unpacking private modules.
55 56
 
56 57
 To run a packed job, use the `-u` switch to specify the password
2  package.json
... ...
@@ -1,6 +1,6 @@
1 1
 { "name"          : "pack",
2 2
   "description"   : "Create private node modules",
3  
-  "version"       : "0.1.2",
  3
+  "version"       : "0.1.3",
4 4
   "homepage"      : "http://github.com/chriso/packnode",
5 5
   "keywords"      : ["pack","packnode","encrypt","compress","unpack"],
6 6
   "author"        : "Chris O'Hara <cohara87@gmail.com>",
36  packnode
@@ -7,11 +7,12 @@ var fs = require('fs'),
7 7
 
8 8
 var stdin = process.openStdin(), input = '';
9 9
 
10  
-var cipher, data = '', encrypted, packed, chunk = [],
  10
+var cipher, data = '', encrypted, out, chunk = [],
  11
+    packed, decipher,
11 12
     encoding = 'hex', 
12 13
     algorithm = 'aes256',
13 14
     chunk_length = 80,
14  
-    password;
  15
+    password, unpack;
15 16
 
16 17
 var exit = function (msg, is_error) {
17 18
     console.log(msg);
@@ -27,6 +28,7 @@ var usage = ''
27 28
   + '\x1b[1mOptions\x1b[0m:\n'
28 29
   + '  -a, --algorithm <..>   Use the specified algorithm. Default is "aes256"\n'
29 30
   + '  -e, --encoding <..>    Encode with base64|hex|binary. Default is "hex"\n'
  31
+  + '  -u, --unpack           Unpack the module using the specified password\n'
30 32
   + '  -h, --help             Display help information\n'
31 33
   ;
32 34
 
@@ -45,6 +47,10 @@ while (args.length) {
45 47
     case '--encoding':
46 48
         encoding = args.shift();
47 49
         break;
  50
+    case '-u':
  51
+    case '--unpack':
  52
+        unpack = true;
  53
+        break;
48 54
     case '-h':
49 55
     case '--help':
50 56
         exit(usage);
@@ -60,6 +66,8 @@ stdin.setEncoding('utf8');
60 66
 stdin.on('data', function (input) { data += input; });
61 67
 stdin.on('end', function () { 
62 68
 
  69
+    if (!unpack) {
  70
+
63 71
     // Minify the file
64 72
     data = jsmin(data);
65 73
     
@@ -71,14 +79,24 @@ stdin.on('end', function () {
71 79
     }
72 80
 
73 81
     // Prepare the output
74  
-    packed  = 'packed =  "' + chunk.join('";\npacked += "') + '";\n';
75  
-    packed += 'exports.unpack = function (password) {\n';
76  
-    packed += '    var decipher = require("crypto").createDecipher("' + algorithm + '", password);\n';
77  
-    packed += '    eval(decipher.update(packed, "' + encoding + '", "utf8") + decipher.final("utf8"));\n';
78  
-    packed += '    return exports;\n';
79  
-    packed += '};';
  82
+    out  = 'e="' + chunk.join('";\ne+="') + '";\n';
  83
+    out += 'exports.unpack=function(p){var d=require("crypto").createDecipher("' + algorithm + '",p);\n';
  84
+    out += 'eval(d.update(e,"' + encoding + '","utf8")+d.final("utf8"));return exports;}';
80 85
 
  86
+    } else {
  87
+        
  88
+        packed = (function () {
  89
+            eval(data);
  90
+            return e;
  91
+        }());
  92
+        
  93
+        decipher = crypto.createDecipher(algorithm, password);
  94
+        
  95
+        out = decipher.update(packed, encoding, 'utf8') + decipher.final('utf8');
  96
+        
  97
+    }
  98
+    
81 99
     // ..and write to stdout
82  
-    process.stdout.write(packed);
  100
+    process.stdout.write(out);
83 101
     
84 102
 });

0 notes on commit f271b86

Please sign in to comment.
Something went wrong with that request. Please try again.