我们什么时候说java中加载了类?(When do we say class is loaded in java?)
当我们说一个
class
被“加载”时,它意味着什么?例如,据说
Static init
块在类加载时执行。 什么时候加载了class
?请参阅Kathy Sierra的书中的代码:
class Bird { { System.out.print("b1 "); } public Bird() { System.out.print("b2 "); } } class Raptor extends Bird { static { System.out.print("r1 "); } public Raptor() { System.out.print("r2 "); } { System.out.print("r3 "); } static { System.out.print("r4 "); } } class Hawk extends Raptor { public static void main(String[] args) { System.out.print("pre "); //1 new Hawk();//2 System.out.println("hawk "); } }
上面代码的输出是: r1 r4 pre b1 b2 r3 r2 hawk
我不能理解在r1之后打印prefor的结果。 哪部分代码加载了Raptor类?
其中一个答案是:
“该类在最后一刻被初始化,但在访问其任何成员之前”。
但按照这个逻辑,不应该在r1之前预先打印? 由于第2行在执行line1后访问类Raptor的构造函数。
What does it mean when we say a
class
is "loaded"?For example it is said that
Static init
blocks are executed at the time of class loading. When exactlyclass
is loaded?Please see this code from Kathy Sierra's book:
class Bird { { System.out.print("b1 "); } public Bird() { System.out.print("b2 "); } } class Raptor extends Bird { static { System.out.print("r1 "); } public Raptor() { System.out.print("r2 "); } { System.out.print("r3 "); } static { System.out.print("r4 "); } } class Hawk extends Raptor { public static void main(String[] args) { System.out.print("pre "); //1 new Hawk();//2 System.out.println("hawk "); } }
The output of above code is: r1 r4 pre b1 b2 r3 r2 hawk
I cant not understand howcome pre is printed after r1. Which part of the code loaded Raptor class?
One of the answer says :
"the class is initialized at the last possible moment, but before any of its members is accessed".
But by that logic, shouldn't pre be printed BEFORE r1? Since line 2 accesses constructor of class Raptor AFTER execution of line1.
原文:https://stackoverflow.com/questions/39412177
最满意答案
Hex-Rays反编译器是一个很好的工具,但代码很难读取,你将不得不花费大量的时间对整个DLL进行反向工程。
Hex-Rays decompiler is a great tool, but the code will be quite hard to read and you will have to spend a lot of time to reverse engineer the whole DLL.
相关问答
更多-
不要反套。 只需逐渐用C替换组件即可。以下是一系列可能的转换。 .LFBO pushq %rbp movq %rsp,%rbp movl %edi,-4(%rbp) movl %esi,-8(%rbp) movl -4(%rbp),%eax compl -8(%rbp),%eax jg .L2 movl -8(%rbp),%eax jmp .L3 .L2: movl ...
-
反向工程C ++ DLL(Reverse engineer C++ DLL)[2023-10-31]
Hex-Rays反编译器是一个很好的工具,但代码很难读取,你将不得不花费大量的时间对整个DLL进行反向工程。 Hex-Rays decompiler is a great tool, but the code will be quite hard to read and you will have to spend a lot of time to reverse engineer the whole DLL. -
如何从DLL(构造函数在DLL中)创建一些类?(с++)(How to create some class from dll(constructor in dll) in C++?)[2023-05-10]
严格回答你的问题,你需要添加一个返回构造函数结果的extern“C”函数: extern "C" foo* __declspec(dllexport) new_foo(int x) { return new foo(x); } 然后在源文件中,您可以使用“new_foo”上的GetProcAddr来调用该函数。 Answering your question strictly, you need to add an extern "C" function that returns the resu ... -
首先,你的代码中混合了各种值。 %esi以值b开始, %edi以值a开始。 您可以从testl %edx, %edx行推断%edx用作以.L7开头的循环的条件变量(如果%edx不.L7 0,则控制权将转移到.L9块中,然后返回.L7 )。 我们将在我们的反向工程代码中将%edx称为remainder 。 我们开始逆向设计主循环: movl %edi, %edx 由于%edi存储a ,所以相当于用remainder初始化remainder数值: int remainder = a; 。 movl ...
-
您可以直接使用PInvoke和DllImport属性来调用它。 当然,假设它有标准的C入口点,而不是编译器特定的C ++入口点。 除非你在谈论C ++ / CLI,在这种情况下,你会引用.NET DLL,就像你引用任何其他.NET DLL一样。 You can call it directly with PInvoke and the DllImport attribute. Assuming, of course, that it has standard C entry points, not comp ...
-
检查汇编代码。 把它变回C ++。 利润。 不可否认,你可以在第1步和第2步中添加一些细节,但这是基本的想法,我的答案中的详细程度超过了你问题中的详细程度:-) Examine the assembler code. Turn it back into C++. Profit. Admittedly, there a fair bit of detail you could add to steps 1 and 2 but that's the basic idea, and the level of de ...
-
查看C ++ DLL的成员(View the members of a C++ DLL)[2023-12-06]
获取: http : //www.dependencywalker.com/ ,使用depends.exe打开DLL,然后在“视图”菜单中激活“Undecorate C ++ Functions”。 我主要使用它来查找依赖项,但它也暴露了DLL的入口点。 这不是万无一失的,因为暴露类的DLL不必导出其方法。 例如,纯虚方法布局足够统一,您可以将实例公开为可能是工厂函数的接口指针。 但它可能会解决您的问题。 无论如何,您需要一个依赖性walker的副本。 :) Get this: http://www.dep ... -
你几乎做对了。 只需将数字2和3放在同一个C ++ / CLI DLL中。 您既可以使用.NET类,也可以从C ++ / CLI项目中导出C函数。 extern "C" __declspec( dllexport ) void __stdcall PureExportC( const wchar_t* param ) { CSharpAssemblyNamespace::CSharpWorker ...
-
如果将宏定义转储到文本文件会有所帮助,请尝试以下方法: application.saveastext acMacro, "Macro1", "Macro1.txt" 然后,您可以打开文本文件并阅读Action和Argument语句。 If it would be helpful to dump the macro definitions to text files, try something like this: application.saveastext acMacro, "Macro1", "Ma ...
-
Can Reflector可以对C ++ / CLI应用程序进行反向工程(Can Reflector reverse engineer a C++/CLI application)[2021-04-08]
答案是两者。 使用CLR的方法将编译为il,而不使用clr的方法将编译为本机代码。 但最好的答案是编写一些示例函数,编译dll并在Refelctor中打开它。 The answer is both. Methods that use CLR will be compiled as il, while methods that do not use clr will be compiled to native code. But the best answer for you will be to write ...