java中操作系统的名称(不是“os.name”)

编程入门 行业动态 更新时间:2024-10-28 18:30:17
本文介绍了java中操作系统的名称(不是“os.name”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道如何掌握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”)

本文发布于:2023-11-27 05:53:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作系统   名称   java   os

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!