In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail about jd-gui decompilation access$ analysis and function explanation, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1) static Type access$iii (Outer); is a very important method automatically generated by the JAVA compiler (the number of this method is related to the number of variables of the external class to be accessed by your inner class). The purpose is to be used when the inner class accesses the data members of the external class.
2) therefore: the JAVA compiler automatically generates code to call this method when it generates a data member of an inner class that accesses an external class.
Take your code as an example: methods in the inner class Inner
Public int getDate () {
Return xx
}
The generated code is as follows: (after javap processing)
Java code
?
12 3 4 5 6 7 8 9 10 11 12public int getDate (); LineNumberTable: line 12: 0 Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield # 1; / / Field this$0:LOuter; 4: invokestatic # 3; / / Method Outer.access$000: (LOuter;) I 7: ireturn
Look at line 4 of the code: get the private data members in the external class object o through Outer.access$000 (Outer o) (note: this is accessing private data members of other classes from another class-not through reflection technology)
3) further:
If the external class defines two private data members as follows:
Private int xx=12
Private float yy=12.4f
If both data members are accessed in the inner class, the compiler automatically generates two access methods:
Static int access$000 (Outer); used for inner classes to access private int xx
Static float access$100 (Outer); used for inner classes to access private float yy
4) this technique for internal classes to access private data members in external classes (not through reflection!) It leaves a possible small risk to security (because some private data members do not provide outside access to its so-called getter ()). For this reason, the compiler checks these access$000 () methods generated automatically at compile time and does not allow programmers to call them directly.
However, we can bypass this check by using the class compilation feature of the JAVA compiler: the goal is to call these access$000 () methods directly in our other classes.
In this way, we can use this technique (that is, in our own class-- note that this access$000 (Outer) is called directly from the external class instead of the inner class;) to access the data members of the private of other classes.
The specific technical demonstration is as follows:
Step 1: define the following classes:
Class Outer {
Private final int xx = 123
/ / because it is final, access$000 (Outer) is no longer automatically generated
Public Inner getInner () {
Return new Inner ()
}
Public class Inner {
Public int getDate () {
Return xx
}
} / / class Inner
Static int access$000 (Outer) / / this is self-defined!
{
Return 1
}
Step 2: define your other classes to call the access$000 () method directly
Public class Test1
{
Public static void main (String [] args)
{
System.out.println (Outer.access$000 (new Outer (); / / there is no problem with this call, because it is self-defined!
}
}
Compile the above two JAVA files into class, which is the second step of Test1.class.
Step 3: this is a step of magic:
Change the class Outer in the first step to the following:
Class Outer {
Private int xx = 123
/ / since it is not final, access$000 (Outer) is generated automatically
Public Inner getInner () {
Return new Inner ()
}
Public class Inner {
Public int getDate () {
Return xx
}
} / / class Inner
/ * remove the self-defined access$000 in this first step, because the compiler will generate it automatically!
Static int access$000 (Outer {
Return 1
} * /
Recompile the class in step 3, while the class Test.class in step 2 does not move it. At this point, we have achieved the purpose of calling the access$000 (...) automatically generated by the compiler in the Outer class in the class Test1. Yes.
-the first article draws lessons from others.
Remove comments /\ * after decompilation using jd-gui
*\ d * * /
A slight modification is made here:\ / *\ d*\ * /
Remove the comment automatically generated on the last line /\ * Location: [\ s\ s] +? (? =\ * /)\ * / $
.access $Decoding the problem of calling external class members from my inner class
A very simple test class source code:
Public class testOuter {
Private int a
Private int b
Private void fun () {
A + = 1
}
Class testInner {
Int x = 0
TestInner () {
B = 1
A = 0
Fun ()
}
}
Compile the resulting Class file:
Class testOuter$testInner {
Int x = 0
TestOuter$testInner (testOuter paramtestOuter) {
TestOuter.access$002 (paramtestOuter, 1)
TestOuter.access$102 (paramtestOuter, 0)
TestOuter.access$200 (paramtestOuter)
}
}
As you can see, in order for the inner class to access the private members of the external class, the compiler generates a function similar to the "external class .access $XYZ". XYZ is a number. X is incremented in the order in which private members appear in the inner class. 8 is service, if YZ is 02, it is marked as a member of the basic variable; if YZ is 00, it is marked as an object member or function; if YZ is 08, it is marked as an object member or function.
These parameters can produce a corresponding table, waiting to be sorted out.
.sionManager.access $102 (.. nManager.this, null)
Jd-gui decompilation on the emergence of access$ analysis and function description to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.