English 中文(简体)
禁用仪器仪表图书馆
原标题:Disable Instrumentation Library

是否可以在 Java 应用程序中禁用仪表库, 或者检查是否正在运行?

我的目标是防止用户出于安全原因在我的应用程序上运行仪器安装。

经过一些实验后,我独自想出了一种理论解决方案。在实验中,我发现 java.class.path 系统属性以 -javagent VM 参数工具罐文件的路径结束,但以路径分隔符字符结束。从此属性中,我可以检查一个类路径属性是否是程序本身没有指定的外部罐,然后如果检测到一个外来罐,则终止我的应用程序。

然而,我认为上述办法似乎有些古怪,但我一直未能找到办法直接阻止javaagent(javaagent)的争论,也未能找到一种简单的办法检测仪器代理图书馆。 这些更清洁的替代品中是否有一种可能?

最佳回答

在做了更多的研究之后,我发现一个坚实的解决方案 几天前,我写了一个临时的分类物产分析器。

我用 RuntimeMCUSIAN 来获取 VM 参数, 然后我检查一个 -javaagent: 参数 。

RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
List<String> args = RuntimemxBean.getInputArguments();
for (String arg : args) {
    if (arg.contains("-javaagent:")) {
        // block application from running
    }
}
问题回答

Java 介质也可以在运行时装入 :

vm = com.sun.tools.attach.VirtualMachine.attach(pid);
agent = new File("agent.jar");
vm.loadAgent(agent.toString());
vm.detach();

I don t think your code will work in this case.
One can check if attach allowed like so:

SecurityManager sm = System.getSecurityManager();
if (sm != null)
    sm.checkPermission(new AttachPermission("attachVirtualMachine"));




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签