java執行在運行時的exe包裝器在一個字節數組中

[英]java execution at runtime of exe wrapper in a byte array


I have this code which copy the executable file into byte array.

我有這個代碼將可執行文件復制到字節數組。

    //winmine.exe
    Path path = Paths.get("winmine.exe");
    byte[] bin = Files.readAllBytes(path);

I want execute dinamically the array without use the file. By example I need something like this:

我想在不使用文件的情況下執行數組。通過示例,我需要這樣的事情:

    Runtime app = Runtime.getRuntime();
    String currentDir = new File(".").getAbsolutePath();
    Process p = app.exec_WRAP_BINARY(bin);   //Not exixts

The purpose of that is prevent the user from accessing the file winmine.exe

其目的是阻止用戶訪問文件winmine.exe

Update: I'm sure this must be possible somehow. If we consider that is an execution: First, it read a file and then it load to memory it completely... I don't see because it can't do this separately.

更新:我確信這必須以某種方式實現。如果我們認為這是一個執行:首先,它讀取一個文件,然后它完全加載到內存...我沒有看到,因為它不能單獨執行此操作。

2 个解决方案

#1


What you want is not really possible, in general. The system linker will need to link the binary and load it before it executes, and on most (almost every one I know and cetainly Windows/Linux) this means you will need a file on the filesystem.

一般來說,你想要的是不可能的。系統鏈接器需要鏈接二進制文件並在其執行之前加載它,並且在大多數(幾乎每一個我知道並且確定為Windows / Linux)上,這意味着您將需要文件系統上的文件。

Of course - you can always write it there, perhaps to a temp directory, execute it as a file, and then delete it later.

當然 - 您可以隨時將其寫入臨時目錄,將其作為文件執行,然后再將其刪除。

Even if you were writing in pure C, you could not easily do this.

即使你是用純C寫作,你也不能輕易做到這一點。

(Caveat - On Windows, you /can/ in theory do it with a .com format executable. But severe limitations on that format make it obsolete.)

(警告 - 在Windows上,您/可以/理論上使用.com格式的可執行文件。但是對該格式的嚴格限制使其過時。)

On Linux, you might also try locating the system loader binary, and execute that, passing the entire binary into it through a pipe. This works because it functions a sort of "binary interpreter". But I would not recommend that approach.

在Linux上,您也可以嘗試查找系統加載器二進制文件,並執行該操作,通過管道將整個二進制文件傳遞給它。這是有效的,因為它起到了一種“二進制解釋器”的作用。但我不建議采用這種方法。

#2


Maybe I am understanding what you are asking in a totally wrong way, but if what you are trying to achieve is to have a "private '.exe' file" maybe you should put that as a resource inside the '.jar' that I suppose you want to generate and then extract it to a temp folder "hidden" for the user and call it from there using a simple process call, then when you finish, delete that file without never releasing the lock on it so that the user cannot access it, but all of that is for a "lazy" user, you have to understand that if someone really wants to have access to that exe, THEY WILL, that is the reason Window is still being pirated so easily and all of that is to create a java application that only works on windows, therefore you will need to add another "library/application" to do that for you in *NIX (in case you want to add support for multiple systems)

也許我正在以完全錯誤的方式理解你的要求,但如果你想要實現的是擁有一個“私有'.exe'文件”,也許你應該將它作為資源放在'.jar'中我假設您想要生成然后將其提取到用戶的“隱藏”臨時文件夾,並使用簡單的進程調用從那里調用它,然后當您完成時,刪除該文件而不釋放鎖定,以便用戶不能訪問它,但所有這一切都是為了一個“懶惰”的用戶,你必須明白,如果有人真的想要訪問該exe,他們會,這就是Window仍然被盜版的原因,所有這一切都是要創建一個僅適用於Windows的Java應用程序,因此您需要在* NIX中添加另一個“庫/應用程序”來為您執行此操作(如果您要添加對多個系統的支持)


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/04/729eae80986fd8327627502d96ce1156.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com