javaw.py
1.44 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
#appModules/javaw.py
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2014 NV Access Limited
"""Support for app specific modules for Java apps hosted by javaw.exe.
"""
import os
import shlex
import appModuleHandler
from appModuleHandler import AppModule
def _getEntryPoint(cmd):
cmd = iter(shlex.split(cmd))
# First argument is the executable.
next(cmd)
for arg in cmd:
if arg in ("-cp", "-classpath"):
# This option consuems the next argument.
next(cmd)
continue
if arg.startswith("-jar"):
# Next argument is the jar. Remove the extension.
return os.path.splitext(next(cmd))[0]
if arg.startswith("-"):
continue
if not arg:
continue
# Class.
return arg
raise LookupError
def getAppNameFromHost(processId):
# Some apps have launcher executables which launch javaw.exe to run the app.
# In this case, the parent process will usually be the launcher.
proc = appModuleHandler.getWmiProcessInfo(processId)
parent = proc.parentProcessId
if parent:
name = appModuleHandler.getAppNameFromProcessID(parent)
if name and name not in ("explorer", "cmd"):
# The parent isn't a shell, so it's probably a launcher.
return name
# Try getting the class/jar from the command line.
cmd = proc.CommandLine
if not cmd:
raise LookupError
try:
return "javaw_" + _getEntryPoint(cmd).replace(".", "_")
except:
raise LookupError