-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-bytecode-disassembler.js
More file actions
executable file
·113 lines (103 loc) · 2.65 KB
/
java-bytecode-disassembler.js
File metadata and controls
executable file
·113 lines (103 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use babel';
import DisassembledView from './disassembled-view';
import {CompositeDisposable, Disposable} from 'atom';
import $ from "jquery";
import ChildProcess from "child_process";
import ConfigSchema from "./configuration.js";
import path from "path";
import os from "os";
export default
{
config: ConfigSchema.config,
subscriptions: null,
activate(state)
{
var aThis = this;
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable(
// Add an opener for our view.
atom.workspace.addOpener(
uri =>
{
if(
atom.config.get("Java-Bytecode-Disassembler.openOnClick")
&& uri.endsWith(".class")
){
return aThis.disassemble(uri, true);
}
if(uri.endsWith("?force-disassemble")){
return aThis.disassemble(uri.replace("?force-disassemble", ""), false);
}
}
),
// Register command
atom.commands.add(
'atom-workspace',
{
'java-bytecode-disassembler:disassemble': (e) => {
var dir = $(e.target).hasClass('name') ? $(e.target).data('path') : $(e.target).find('span.name').data('path');
if (!dir.endsWith(".class") && !dir.endsWith(".jar"))
{
atom.notifications.addWarning(
"Invalid file type",
{
detail: "Only files of type .class or .jar can be disassembled by OPAL"
})
return;
}
atom.workspace.open(dir + "?force-disassemble");
}
}
),
// Destroy any OpalViews when the package is deactivated.
new Disposable(() =>
{
atom.workspace.getPaneItems().forEach(
item => {
if (item instanceof DisassembledView)
{
item.destroy();
}
}
);
})
);
},
deactivate()
{
this.subscriptions.dispose();
},
disassemble(dir, calledByLeftClick)
{
var fileName = dir.replace(/^.*[\\\/]/, '').replace('.class', '');
var command =
'java -jar "' + this.escapePath(__dirname+ '/OPALDisassembler.jar') + '"' +
' -source "' + this.escapePath(dir) + '"' +
' -noHeader'
;
var aThis = this;
try{
var result = ChildProcess.execSync(command);
return new DisassembledView(
fileName,
result.toString(),
dir
);
}catch(error){
console.error(error.message);
atom.notifications.addError(
"Error disassembling the file. Check the log for more details",
{
detail: error.message
}
);
return null;
}
},
escapePath(dir){
if(os.platform() !== 'win32'){
dir = dir.replace(/(["\s'$`\\])/g,'\\$1');
}
return path.normalize(dir);
}
};