简体   繁体   English

这些类如何访问默认程序包(后编译)?

[英]How are these classes able to access the default package (post-compile)?

This is taken from the bytecode of Minecraft. 这取自Minecraft的字节码 Most of the jar's classes are found in the default package, however there is another package, "net.minecraft.client", which has the main class (Minecraft.class) that runs the game loop, sets up OpenGL, etc. I don't have the source, but if I open up Minecraft.class in JD-Gui, it has the following import setup: jar的大多数类都在默认包中找到,但是还有另一个包“ net.minecraft.client”,它具有运行游戏循环,设置OpenGL等的主类(Minecraft.class)。没有源代码,但是如果我在JD-Gui中打开Minecraft.class,它将具有以下导入设置:

package net.minecraft.client;

import aaa;
import aai;
import ajq;
import ajv;
import akf;
import aki;
import aqx;
import aqz;
import ara;
import arb;
... (many more classes from the default package)

public abstract class Minecraft implements Runnable, mc {
...
}

How does this work? 这是如何运作的? Let's say I have a folder with a similar setup (default classes that need to be accessed by other packages) and want to compile it with a batch file. 假设我有一个具有类似设置的文件夹(默认类需要其他软件包访问),并希望使用批处理文件进行编译。 What method of compiling could replicate this result? 哪种编译方法可以复制此结果?

This is taken from the source of Minecraft. 这是从《我的世界》中获取的。

I don't think so. 我不这么认为。 (EDIT: The question was edited to make this "bytecode" - which doesn't make much sense, as bytecode isn't Java source code. Anyway...) (编辑:对该问题进行了编辑,以使其成为“字节码”-这没有多大意义,因为字节码不是Java源代码。无论如何...)

How does this work? 这是如何运作的?

It doesn't, fundamentally. 从根本上讲,它不是。 The code you're looking at in JD-Gui isn't the original source code - it's code which represents the bytecode as accurately as JD-Gui is able to manage. 您在JD-Gui中查看的代码不是原始源代码-它是代表JD-Gui能够准确管理的字节码的代码。

I strongly suspect the original source code does use packages, but then uses an obfuscator of some kind to rename the classes and put them in the default package. 我强烈怀疑原始源代码确实使用了程序包,但是随后使用某种混淆器来重命名这些类并将它们放在默认程序包中。 I strongly suspect this isn't the only kind of change which leaves valid bytecode which couldn't actually be directly compiled from valid source code. 我强烈怀疑这不是留下有效字节码的唯一更改,而该字节码实际上不能直接从有效源代码进行编译。 (For example, I strongly suspect there are method names which are valid in bytecode but not in source code.) (例如,我强烈怀疑有些方法名称在字节码中有效,但在源代码中无效。)

Let's say I have a folder with a similar setup (default classes that need to be accessed by other packages) and want to compile it with a batch file. 假设我有一个具有类似设置的文件夹(默认类需要其他软件包访问),并希望使用批处理文件进行编译。 What method of compiling could replicate this result? 哪种编译方法可以复制此结果?

You wouldn't. 你不会的 You'd have source code set up using packages (as all sane, non-trivial Java code does), compile it and then post-process the bytecode. 您将使用软件包设置源代码(就像所有理智的,平凡的Java代码一样),对其进行编译,然后对字节码进行后处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM