当前位置:网站首页>Custom classloader that breaks parental delegation
Custom classloader that breaks parental delegation
2022-07-02 03:20:00 【Tianlong supreme】
Steps to break parental delegation :
1、 Inherit ClassLoader
2、 rewrite loadClass、findClass
Code implementation :
package ljxwtl;
import org.apache.commons.io.IOUtils;
import java.io.*;
/**
* @author: wtl
* @License: (C) Copyright 2022, wtl Corporation Limited.
* @Contact: [email protected]
* @Date: 2022/2/15 9:58 AM
* @Version: 1.0
* @Description:
*/
public class CustomClassLoader extends ClassLoader{
@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {
if (!name.startsWith("ljxwtl")){
c = super.loadClass(name,resolve);
}
else{
// If still not found, then invoke findClass in order
// to find the class.
c = findClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
String classPath = name.replaceAll("\\.","/");
InputStream inputStream = CustomClassLoader.class.getResourceAsStream("/" + classPath + ".class");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
IOUtils.copy(inputStream,byteArrayOutputStream);
} catch (IOException e) {
e.printStackTrace();
}
byte[] classBytes = byteArrayOutputStream.toByteArray();
return defineClass(name,classBytes,0,classBytes.length);
}
}
边栏推荐
- How to establish its own NFT market platform in 2022
- MySQL advanced (Advanced) SQL statement (II)
- Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
- SAML2.0 notes (I)
- Learn PWN from CTF wiki - ret2shellcode
- Gradle 笔记
- Xiaomi, a young engineer, was just going to make soy sauce
- 2022-2028 global human internal visualization system industry research and trend analysis report
- V-model of custom component
- Verilog state machine
猜你喜欢
Verilog parallel block implementation
On redis (II) -- cluster version
【JVM】创建对象的流程详解
[HCIA continuous update] working principle of OSPF Protocol
Retrofit's callback hell is really vulnerable in kotlin synergy mode
Baohong industry | four basic knowledge necessary for personal finance
Generate random numbers that obey normal distribution
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
高并发场景下缓存处理方案
Verilog 状态机
随机推荐
2022-2028 global encryption software industry research and trend analysis report
Baohong industry | what misunderstandings should we pay attention to when diversifying investment
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
Gradle 笔记
3048. Number of words
只需简单几步 - 开始玩耍微信小程序
Aaaaaaaaaaaa
On redis (II) -- cluster version
Just a few simple steps - start playing wechat applet
流线线使用阻塞还是非阻塞
Use usedeferredvalue for asynchronous rendering
Render header usage of El table
汇率的查询接口
JS <2>
KL divergence is a valuable article
终日乾乾,夕惕若厉
Spark Tuning
MySQL connection query and subquery
< job search> process and signal
Download and use of the super perfect screenshot tool snipaste