我想知道如何掌握jvm运行的那种操作系统。它也必须是安全的,所以 System.getProperty(os.name)实际上不是一个选项,因为它可以通过-D指令轻易绕过它。
I'd like to know how to get hold of the kind of Operating System the jvm is running on. It has to be "secure" as well, so System.getProperty("os.name") is not really an option because it can be trivially circumvented with the -D directive.
通过安全,我的意思是不值得规避。它适用于桌面应用程序。用户总是可以对代码进行反混淆,反编译,编辑和重新编译,但这比将-D传递给jvm要困难得多。我们想要修补不平凡,而不是不可能(因为这不可能)。
By "secure" I mean nontrivial to circumvent. It's for a desktop application. The user could always deobfuscate, decompile, edit and recompile the code, but that is significantly harder than passing -D to the jvm. We want to make tinkering nontrivial, not impossible (since that can't be done).
推荐答案首先,它是不可能保护的代码来自其运行时环境的任意操作。但是为了使它至少难以欺骗你的支票,最好的选择可能是某种基于文件系统操作系统指纹识别。
First, it's impossible to protect code from being manipulated arbitrarily by its runtime environment. But in order to make it at least hard to fool your check, the best bet is probably some sort of file system based OS fingerprinting.
File.listRoots()是你的出发点;在类Unix系统上,它将返回一个包含/ etc,/ usr等特征目录的根。在Windows上,它将返回多个结果,但AFAIK OS安装驱动器不一定是C:并且特征目录不同Windows版本和区域设置 - 小心不要假设每个人都运行英文版的Vista。
File.listRoots() is your starting point; on a Unix-like system it will return a single root containing characteristic directories like /etc, /usr, etc. On Windows, it will return multiple results, but AFAIK the OS installation drive is not necessarily C: and the characteristic directories differ across Windows versions and locales - be careful not to assume that everyone runs an English version of Vista.
您可以投入大量精力来识别不同版本的Windows和Linux,以及BSD或MacOS - 从编译后的代码中删除支票可能会花费很少的工作。
You could invest a lot of work into recognizing different versions of Windows and Linux, as well as BSD or MacOS - and it would probably take a lot less work to remove the check from the compiled code once it's out there.
更多推荐
java中操作系统的名称(不是“os.name”)
发布评论