OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function Unzip(file, path, verbose) { | |
6 if (verbose) { | |
7 WScript.StdOut.Write(" * UNZIP " + file); | |
8 } | |
9 var shell_app; | |
10 var fso; | |
11 try { | |
12 shell_app = new ActiveXObject("Shell.Application"); | |
13 fso = new ActiveXObject("Scripting.FileSystemObject"); | |
14 } catch (e) { | |
15 WScript.StdOut.WriteLine("[-] OBJECTS " + new Number(e.number).toHex() + | |
16 ": Cannot create Active-X object (" + e.description) + ")."; | |
17 WScript.Quit(1); | |
18 } | |
19 // shell_app.Namespace() doesn't work with relative paths. | |
20 //current_dir = fso.GetFolder('.').Path + '\\' | |
21 //path = current_dir + path | |
22 //file = current_dir + file | |
23 var out; | |
24 var zip; | |
25 try { | |
26 if (!fso.FolderExists(path)) { | |
27 fso.CreateFolder(path); | |
28 } | |
29 out = shell_app.Namespace(path); | |
30 } catch (e) { | |
31 WScript.StdOut.WriteLine("[-] SHELL.APPLICATION " + | |
32 new Number(e.number).toHex() + | |
33 ": Failed to open output directory."); | |
34 WScript.Quit(1); | |
35 } | |
36 if (!out) { | |
37 WScript.StdOut.WriteLine("[-] SHELL.APPLICATION : Failed to open output dire
ctory."); | |
38 WScript.Quit(1); | |
39 } | |
40 | |
41 try { | |
42 zip = shell_app.Namespace(file); | |
43 } catch (e) { | |
44 WScript.StdOut.WriteLine("[-] SHELL.APPLICATION " + | |
45 new Number(e.number).toHex() + | |
46 ": Failed to open zip file."); | |
47 WScript.Quit(1); | |
48 } | |
49 if (!zip) { | |
50 WScript.StdOut.WriteLine("[-] SHELL.APPLICATION " + | |
51 ": Failed to open zip file."); | |
52 WScript.Quit(1); | |
53 } | |
54 | |
55 try { | |
56 out.CopyHere(zip.Items()); | |
57 } catch (e) { | |
58 WScript.StdOut.WriteLine("[-] SHELL.APPLICATION " + | |
59 new Number(e.number).toHex() + | |
60 ": Failed to extract."); | |
61 WScript.Quit(1); | |
62 } | |
63 if (verbose) { | |
64 WScript.StdOut.WriteLine("ok."); | |
65 } | |
66 } | |
67 | |
68 // Utilities | |
69 Number.prototype.isInt = function NumberIsInt() { | |
70 return this % 1 == 0; | |
71 }; | |
72 Number.prototype.toHex = function NumberToHex(length) { | |
73 if (arguments.length == 0) length = 1; | |
74 if (typeof(length) != "number" && !(length instanceof Number)) { | |
75 throw Exception("Length must be a positive integer larger than 0.", | |
76 TypeError, 0); | |
77 } | |
78 if (length < 1 || !length.isInt()) { | |
79 throw Exception("Length must be a positive integer larger than 0.", | |
80 "RangeError", 0); | |
81 } | |
82 var result = (this + (this < 0 ? 0x100000000 : 0)).toString(16); | |
83 while (result.length < length) result = "0" + result; | |
84 return result; | |
85 }; | |
86 | |
87 if (WScript.Arguments.length != 2) { | |
88 WScript.StdOut.Write("Incorrect arguments to unzip.js") | |
89 } else { | |
90 Unzip(WScript.Arguments(0), WScript.Arguments(1), false); | |
91 } | |
OLD | NEW |