├── src ├── main │ └── java │ │ └── org │ │ └── hot2hot │ │ ├── Hot.java │ │ ├── utils │ │ ├── ClassDumper.java │ │ ├── Clazzs.java │ │ ├── PackageFromBytes.java │ │ ├── PackageFromClassFile.java │ │ ├── ASMClassLoader.java │ │ ├── PackageFromClassFast.java │ │ └── Hex.java │ │ ├── ClassRedefiner.java │ │ ├── AgentMain.java │ │ ├── task │ │ └── FileScanTask.java │ │ └── jdk │ │ └── ClassLoaderAdapter.java └── test │ └── java │ └── org │ └── hot2hot │ ├── test │ ├── A_enum.java │ ├── A_interface.java │ ├── TestAgent.java │ └── A.java │ ├── forname │ └── ClazzForName.java │ ├── houseMD │ ├── Test.java │ └── T.java │ └── classfile │ └── ReadClassFile.java ├── README.md ├── .gitignore ├── pom.xml └── LICENSE /src/main/java/org/hot2hot/Hot.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot; 2 | 3 | public class Hot { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hot2hot 2 | class热替换项目 3 | 4 | 5 | 当A.run()在执行时,替换A。当然run中的参数不受影响,下次执行使用的就是新的class 6 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/test/A_enum.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.test; 2 | 3 | public enum A_enum { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/test/A_interface.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.test; 2 | 3 | public interface A_interface { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/forname/ClazzForName.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.forname; 2 | 3 | public class ClazzForName { 4 | 5 | public static void main(String[] args) throws ClassNotFoundException { 6 | Class.forName("org.hot2hot.test.A"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Eclipse 15 | .classpath 16 | .project 17 | .settings/ 18 | target/ 19 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/ClassDumper.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | 8 | public class ClassDumper { 9 | 10 | public static void dump(String className, byte[] classfile) { 11 | 12 | try { 13 | FileUtils.writeByteArrayToFile(new File("/tmp/" + className + ".class"), classfile); 14 | } catch (IOException e) { 15 | e.printStackTrace(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/Clazzs.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | public class Clazzs { 7 | private final static Map> clazz_map = new ConcurrentHashMap>(); 8 | 9 | private Clazzs() {} 10 | 11 | public static Class getClazz(String key) { 12 | return clazz_map.get(key); 13 | } 14 | 15 | public static void setClazz(String key, Class clazz) { 16 | clazz_map.put(key, clazz); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/test/TestAgent.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.test; 2 | 3 | /** 4 | * 启动参数配置 javaagent 5 | * -javaagent:hot2hot.jar 6 | * 7 | * @author jiaojianfeng 8 | * 9 | */ 10 | public class TestAgent { 11 | 12 | public static void main(String[] args) throws InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException { 13 | //Clazzs.setClazz(A.class.getName(), A.class); 14 | A a = new A(); 15 | a.run(); 16 | 17 | while(true) { 18 | Thread.sleep(20000); 19 | a.run(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/test/A.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.test; 2 | 3 | public class A { 4 | 5 | private int age; 6 | private String name; 7 | 8 | public A() { 9 | 10 | } 11 | 12 | public A(int age, String name) { 13 | this.age = age; 14 | this.name = name; 15 | } 16 | 17 | public void run() throws InterruptedException { 18 | this.age = 100; 19 | this.name = "ton1"; 20 | 21 | for(int i=0; i<10; i++) { 22 | System.out.println(this.age + ":" + this.name); 23 | Thread.sleep(1000); 24 | } 25 | System.out.println("--------------------"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/houseMD/Test.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.houseMD; 2 | 3 | import java.io.IOException; 4 | 5 | public class Test { 6 | 7 | public static void main(String[] args) throws IOException, InterruptedException { 8 | int count = 0; 9 | while(true) { 10 | T t = new T(); 11 | t.getStr("name", count++); 12 | 13 | /*InputStream in = Test.class.getClassLoader().getResourceAsStream(Type.getInternalName(T.class) + ".class"); 14 | FileUtils.writeByteArrayToFile(new File("/tmp/jjf/T" + count + ".class"), IOUtils.toByteArray(new BufferedInputStream(in))); 15 | in.close();*/ 16 | 17 | Thread.sleep(3000); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/ClassRedefiner.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot; 2 | 3 | import java.lang.instrument.ClassDefinition; 4 | import java.lang.instrument.Instrumentation; 5 | import java.lang.instrument.UnmodifiableClassException; 6 | 7 | public class ClassRedefiner { 8 | 9 | private static Instrumentation inst; 10 | 11 | public static void setInstrumentation(Instrumentation inst) { 12 | ClassRedefiner.inst = inst; 13 | } 14 | 15 | public static void redefine(Class klass, byte[] classFile) { 16 | try { 17 | inst.redefineClasses(new ClassDefinition(klass, classFile)); 18 | } catch (ClassNotFoundException | UnmodifiableClassException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/houseMD/T.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.houseMD; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | import org.apache.commons.io.FileUtils; 9 | import org.apache.commons.io.IOUtils; 10 | import org.objectweb.asm.Type; 11 | 12 | public class T { 13 | public String getStr(String name, int count) throws IOException { 14 | System.out.println(name); 15 | 16 | InputStream in = Test.class.getClassLoader().getResourceAsStream(Type.getInternalName(T.class) + ".class"); 17 | FileUtils.writeByteArrayToFile(new File("/tmp/jjf/T" + count + ".class"), IOUtils.toByteArray(new BufferedInputStream(in))); 18 | in.close(); 19 | 20 | return name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/hot2hot/classfile/ReadClassFile.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.classfile; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.nio.ByteBuffer; 7 | import java.nio.channels.FileChannel; 8 | 9 | import org.hot2hot.utils.PackageFromBytes; 10 | 11 | public class ReadClassFile { 12 | 13 | public static void main(String[] args) throws IOException { 14 | FileInputStream fs = null; 15 | FileChannel channel = null; 16 | File file = new File("/Users/jiaojianfeng/Documents/sourceCode/openSource/hot2hot/target/classes/org/hot2hot/AgentMain.class"); 17 | try { 18 | fs = new FileInputStream(file); 19 | channel = fs.getChannel(); 20 | ByteBuffer byteBuffer = ByteBuffer.allocate((int)channel.size()); 21 | while(channel.read(byteBuffer) > 0) {} 22 | 23 | byte[] b = byteBuffer.array(); 24 | System.out.println(PackageFromBytes.getPackage(b)); 25 | 26 | //System.out.println(Hex.encodeHex(b, false)); 27 | 28 | } catch(Exception e) { 29 | 30 | } finally { 31 | if(null != fs) { 32 | channel.close(); 33 | } 34 | if(null != channel) { 35 | fs.close(); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/PackageFromBytes.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | @Deprecated 6 | public class PackageFromBytes { 7 | 8 | private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 9 | 10 | public static String getPackage(byte[] clazz) { 11 | StringBuilder pack = new StringBuilder(); 12 | //300 是根据包名的一般长度设置的。 13 | char[] cs = encodeHex(clazz, 300); 14 | 15 | int i = 32; 16 | while(true) { 17 | String hexStr = new String(cs, i, 2); 18 | int c = Integer.parseInt(hexStr, 16); 19 | pack.append((char)c); 20 | 21 | i += 2; 22 | if(!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c == 47 || c>= 48 && c <=57 || c == 36)) { 23 | break; 24 | } 25 | } 26 | return StringUtils.replace(pack.toString(), "/", "."); 27 | } 28 | 29 | private static char[] encodeHex(byte[] data, int think) { 30 | int l = data.length; 31 | l = think < l ? think : l; 32 | char[] out = new char[l << 1]; 33 | for (int i = 0, j = 0; i < l; i++) { 34 | out[j++] = DIGITS_UPPER[(0xF0 & data[i]) >>> 4]; 35 | out[j++] = DIGITS_UPPER[0x0F & data[i]]; 36 | } 37 | return out; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/PackageFromClassFile.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.lang.StringUtils; 7 | 8 | import com.sun.tools.classfile.ClassFile; 9 | import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; 10 | import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; 11 | import com.sun.tools.classfile.ConstantPool.CPInfo; 12 | import com.sun.tools.classfile.ConstantPoolException; 13 | 14 | public class PackageFromClassFile { 15 | 16 | public static String getPackage(File paramFile) { 17 | try { 18 | ClassFile classFile = ClassFile.read(paramFile); 19 | CPInfo classInfo = classFile.constant_pool.get(classFile.this_class); 20 | if(classInfo instanceof CONSTANT_Class_info) { 21 | CPInfo cp = classFile.constant_pool.get(((CONSTANT_Class_info) classInfo).name_index); 22 | if(cp instanceof CONSTANT_Utf8_info) { 23 | return StringUtils.replace(((CONSTANT_Utf8_info)cp).value, "/", "."); 24 | } 25 | } 26 | 27 | } catch (IOException e) { 28 | e.printStackTrace(); 29 | } catch (ConstantPoolException e) { 30 | e.printStackTrace(); 31 | } 32 | 33 | return null; 34 | } 35 | 36 | public static void main(String[] args) { 37 | File file = new File("/Users/jiaojianfeng/Documents/empleyment/clazz/A.class"); 38 | System.out.println(getPackage(file)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/ASMClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import java.security.PrivilegedAction; 4 | 5 | import org.hot2hot.Hot; 6 | 7 | public class ASMClassLoader extends ClassLoader { 8 | 9 | private static java.security.ProtectionDomain DOMAIN; 10 | 11 | private final static ASMClassLoader classLoader = new ASMClassLoader(); 12 | 13 | public static ASMClassLoader getClassLoader() { 14 | return classLoader; 15 | } 16 | 17 | static { 18 | DOMAIN = (java.security.ProtectionDomain) java.security.AccessController.doPrivileged(new PrivilegedAction() { 19 | 20 | public Object run() { 21 | return ASMClassLoader.class.getProtectionDomain(); 22 | } 23 | }); 24 | } 25 | 26 | public ASMClassLoader(){ 27 | super(getParentClassLoader()); 28 | } 29 | 30 | public ASMClassLoader(ClassLoader parent){ 31 | super (parent); 32 | } 33 | 34 | static ClassLoader getParentClassLoader() { 35 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 36 | if (contextClassLoader != null) { 37 | try { 38 | contextClassLoader.loadClass(Hot.class.getName()); 39 | return contextClassLoader; 40 | } catch (ClassNotFoundException e) { 41 | // skip 42 | } 43 | } 44 | return Hot.class.getClassLoader(); 45 | } 46 | 47 | public Class defineClassPublic(String name, byte[] b, int off, int len) throws ClassFormatError { 48 | Class clazz = defineClass(name, b, off, len, DOMAIN); 49 | 50 | return clazz; 51 | } 52 | 53 | public boolean isExternalClass(Class clazz) { 54 | ClassLoader classLoader = clazz.getClassLoader(); 55 | 56 | if (classLoader == null) { 57 | return false; 58 | } 59 | 60 | ClassLoader current = this; 61 | while (current != null) { 62 | if (current == classLoader) { 63 | return false; 64 | } 65 | 66 | current = current.getParent(); 67 | } 68 | 69 | return true; 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/AgentMain.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.lang.instrument.ClassDefinition; 7 | import java.lang.instrument.Instrumentation; 8 | import java.lang.instrument.UnmodifiableClassException; 9 | import java.util.concurrent.ScheduledExecutorService; 10 | import java.util.concurrent.ScheduledThreadPoolExecutor; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | import org.apache.commons.io.IOUtils; 14 | import org.hot2hot.jdk.ClassLoaderAdapter; 15 | import org.hot2hot.task.FileScanTask; 16 | import org.objectweb.asm.ClassReader; 17 | import org.objectweb.asm.ClassVisitor; 18 | import org.objectweb.asm.ClassWriter; 19 | import org.objectweb.asm.Type; 20 | 21 | 22 | public class AgentMain { 23 | 24 | public static void premain(String agentArgs, Instrumentation inst) { 25 | if(null == agentArgs || agentArgs.trim().length() == 0) { 26 | throw new RuntimeException("启动参数需要加上扫描文件路径!-javaagent:jarpath[=options]"); 27 | } 28 | ClassRedefiner.setInstrumentation(inst); 29 | System.out.println("扫描文件夹路径:" + agentArgs); 30 | 31 | //替换classloader 32 | InputStream is = ClassLoader.getSystemResourceAsStream(Type.getInternalName(ClassLoader.class) + ".class"); 33 | 34 | try { 35 | ClassReader cr = new ClassReader(IOUtils.toByteArray(new BufferedInputStream(is))); 36 | ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); 37 | ClassVisitor cv = new ClassLoaderAdapter(cw); 38 | cr.accept(cv, 0); 39 | byte[] transformedByte = cw.toByteArray(); 40 | //ClassDumper.dump(Type.getInternalName(ClassLoader.class), transformedByte); 41 | ClassDefinition classDefinition = new ClassDefinition(ClassLoader.class, transformedByte); 42 | 43 | try { 44 | inst.redefineClasses(classDefinition); 45 | } catch (ClassNotFoundException | UnmodifiableClassException e) { 46 | e.printStackTrace(); 47 | } 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | 52 | //定时任务,扫描文件,替换 53 | ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1); 54 | FileScanTask task = new FileScanTask(agentArgs); 55 | 56 | executorService.scheduleWithFixedDelay(task, 1000, 2000, TimeUnit.MILLISECONDS); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/task/FileScanTask.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.task; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FilenameFilter; 6 | import java.io.IOException; 7 | import java.nio.ByteBuffer; 8 | import java.nio.channels.FileChannel; 9 | 10 | import org.hot2hot.ClassRedefiner; 11 | import org.hot2hot.utils.Clazzs; 12 | import org.hot2hot.utils.PackageFromClassFast; 13 | 14 | /** 15 | * 文件扫描 16 | * @author jiaojianfeng 17 | * 18 | */ 19 | public class FileScanTask implements Runnable { 20 | private String filePath; 21 | 22 | public FileScanTask(final String filePath) { 23 | this.setFilePath(filePath); 24 | } 25 | 26 | @Override 27 | public void run() { 28 | try { 29 | //System.out.println(filePath); 30 | //System.out.println(Thread.currentThread().getContextClassLoader()); 31 | File file = new File(filePath); 32 | if(!file.exists() || !file.isDirectory()) { 33 | return; 34 | } 35 | 36 | File[] classFiles = file.listFiles(new FilenameFilter() { 37 | 38 | @Override 39 | public boolean accept(File dir, String name) { 40 | if(!name.endsWith(".class")) { 41 | return false; 42 | } 43 | return true; 44 | } 45 | }); 46 | 47 | for(File classFile : classFiles) { 48 | FileInputStream fs = null; 49 | FileChannel channel = null; 50 | try { 51 | fs = new FileInputStream(classFile); 52 | channel = fs.getChannel(); 53 | ByteBuffer byteBuffer = ByteBuffer.allocate((int)channel.size()); 54 | while(channel.read(byteBuffer) > 0) {} 55 | 56 | byte[] b = byteBuffer.array(); 57 | 58 | String clazzName = PackageFromClassFast.getPackage(classFile.getAbsolutePath()); 59 | System.out.println("替换:" + clazzName); 60 | 61 | Class clazz = Clazzs.getClazz(clazzName); 62 | System.out.println(clazz.getClassLoader()); 63 | ClassRedefiner.redefine(clazz, b); 64 | 65 | } catch (IOException e) { 66 | e.printStackTrace(); 67 | } finally { 68 | if(channel != null) { 69 | try { 70 | channel.close(); 71 | } catch (IOException e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | if(fs != null) { 76 | try { 77 | fs.close(); 78 | } catch (IOException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | } 83 | classFile.delete(); 84 | } 85 | } catch (Exception e) { 86 | e.printStackTrace(); 87 | //ScheduledExecutorService bug 88 | } 89 | 90 | } 91 | 92 | public String getFilePath() { 93 | return filePath; 94 | } 95 | 96 | public void setFilePath(String filePath) { 97 | this.filePath = filePath; 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/PackageFromClassFast.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.utils; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.DataInputStream; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import org.apache.commons.lang.StringUtils; 11 | 12 | /** 13 | * fast 14 | * @author jiaojianfeng 15 | * 16 | */ 17 | public class PackageFromClassFast { 18 | private final static int MAGIC = 0xCAFEBABE; 19 | 20 | public static String getPackage(String fileName) { 21 | DataInputStream in = null; 22 | 23 | try { 24 | in = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName))); 25 | if (in.readInt() != MAGIC) { 26 | throw new IOException(fileName + "非Java class文件!"); 27 | } 28 | 29 | in.readUnsignedShort();// 次版本号 30 | in.readUnsignedShort();// 主版本号 31 | int i = in.readUnsignedShort();// 常量池长度 32 | Map classInfoMap = new HashMap(); 33 | Map classNameMap = new HashMap(); 34 | 35 | //常量池 36 | for (int j = 1; j < i; ++j) { 37 | int k = in.readUnsignedByte(); 38 | switch (k) { 39 | case 7: 40 | classInfoMap.put(j, in.readUnsignedShort()); 41 | break; 42 | case 6: 43 | in.readDouble(); 44 | ++j; 45 | break; 46 | case 9: 47 | in.readUnsignedShort(); 48 | in.readUnsignedShort(); 49 | break; 50 | case 4: 51 | in.readFloat(); 52 | break; 53 | case 3: 54 | in.readInt(); 55 | break; 56 | case 11: 57 | in.readUnsignedShort(); 58 | in.readUnsignedShort(); 59 | break; 60 | case 18: 61 | in.readUnsignedShort(); 62 | in.readUnsignedShort(); 63 | break; 64 | case 5: 65 | in.readLong(); 66 | ++j; 67 | break; 68 | case 15: 69 | in.readUnsignedByte(); 70 | in.readUnsignedShort(); 71 | break; 72 | case 16: 73 | in.readUnsignedShort(); 74 | break; 75 | case 10: 76 | in.readUnsignedShort(); 77 | in.readUnsignedShort(); 78 | break; 79 | case 12: 80 | in.readUnsignedShort(); 81 | in.readUnsignedShort(); 82 | break; 83 | case 8: 84 | in.readUnsignedShort(); 85 | break; 86 | case 1: 87 | classNameMap.put(j, in.readUTF()); 88 | break; 89 | case 2: 90 | case 13: 91 | case 14: 92 | case 17: 93 | default: 94 | throw new RuntimeException("class文件错误!"); 95 | } 96 | } 97 | 98 | //access flag 99 | in.readUnsignedShort(); 100 | 101 | //this class 102 | int thisClazz = in.readUnsignedShort(); 103 | 104 | return StringUtils.replace(classNameMap.get(classInfoMap.get(thisClazz)), "/", "."); 105 | 106 | } catch (IOException ioe) { 107 | ioe.printStackTrace(); 108 | } finally { 109 | try { 110 | in.close(); 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } 114 | } 115 | return null; 116 | } 117 | 118 | public static void main(String[] args) { 119 | System.out.println(getPackage("/Users/jiaojianfeng/Documents/empleyment/clazz/A.class")); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/utils/Hex.java: -------------------------------------------------------------------------------- 1 | 2 | package org.hot2hot.utils; 3 | 4 | /** 5 | * 6 | * 来自Internet 7 | * 8 | */ 9 | public class Hex { 10 | private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 11 | /** 用于建立十六进制字符的输出的大写字符数组 */ 12 | private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 13 | 14 | /** 将字节数组转换为十六进制字符数组 15 | * 16 | * @param data byte[] 17 | * @return 十六进制char[] */ 18 | public static char[] encodeHex (byte[] data) { 19 | return encodeHex(data, true); 20 | } 21 | 22 | /** 将字节数组转换为十六进制字符数组 23 | * 24 | * @param data byte[] 25 | * @param toLowerCase true 传换成小写格式 , false 传换成大写格式 26 | * @return 十六进制char[] */ 27 | public static char[] encodeHex (byte[] data, boolean toLowerCase) { 28 | return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); 29 | } 30 | 31 | /** 将字节数组转换为十六进制字符数组 32 | * 33 | * @param data byte[] 34 | * @param toDigits 用于控制输出的char[] 35 | * @return 十六进制char[] */ 36 | protected static char[] encodeHex (byte[] data, char[] toDigits) { 37 | int l = data.length; 38 | char[] out = new char[l << 1]; 39 | // two characters form the hex value. 40 | for (int i = 0, j = 0; i < l; i++) { 41 | out[j++] = toDigits[(0xF0 & data[i]) >>> 4]; 42 | out[j++] = toDigits[0x0F & data[i]]; 43 | } 44 | return out; 45 | } 46 | 47 | /** 将字节数组转换为十六进制字符串 48 | * 49 | * @param data byte[] 50 | * @return 十六进制String */ 51 | public static String encodeHexStr (byte[] data) { 52 | return encodeHexStr(data, true); 53 | } 54 | 55 | /** 将字节数组转换为十六进制字符串 56 | * 57 | * @param data byte[] 58 | * @param toLowerCase true 传换成小写格式 , false 传换成大写格式 59 | * @return 十六进制String */ 60 | public static String encodeHexStr (byte[] data, boolean toLowerCase) { 61 | return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); 62 | } 63 | 64 | /** 将字节数组转换为十六进制字符串 65 | * 66 | * @param data byte[] 67 | * @param toDigits 用于控制输出的char[] 68 | * @return 十六进制String */ 69 | protected static String encodeHexStr (byte[] data, char[] toDigits) { 70 | return new String(encodeHex(data, toDigits)); 71 | } 72 | 73 | /** 将十六进制字符数组转换为字节数组 74 | * 75 | * @param data 十六进制char[] 76 | * @return byte[] 77 | * @throws RuntimeException 如果源十六进制字符数组是一个奇怪的长度,将抛出运行时异常 */ 78 | public static byte[] decodeHex (char[] data) { 79 | int len = data.length; 80 | if ((len & 0x01) != 0) { 81 | throw new RuntimeException("Odd number of characters."); 82 | } 83 | byte[] out = new byte[len >> 1]; 84 | // two characters form the hex value. 85 | for (int i = 0, j = 0; j < len; i++) { 86 | int f = toDigit(data[j], j) << 4; 87 | j++; 88 | f = f | toDigit(data[j], j); 89 | j++; 90 | out[i] = (byte)(f & 0xFF); 91 | } 92 | return out; 93 | } 94 | 95 | /** 将十六进制字符转换成一个整数 96 | * 97 | * @param ch 十六进制char 98 | * @param index 十六进制字符在字符数组中的位置 99 | * @return 一个整数 100 | * @throws RuntimeException 当ch不是一个合法的十六进制字符时,抛出运行时异常 */ 101 | protected static int toDigit (char ch, int index) { 102 | int digit = Character.digit(ch, 16); 103 | if (digit == -1) { 104 | throw new RuntimeException("Illegal hexadecimal character " + ch + " at index " + index); 105 | } 106 | return digit; 107 | } 108 | 109 | public static void main (String[] args) { 110 | String srcStr = "待转换字符串"; 111 | String encodeStr = encodeHexStr(srcStr.getBytes()); 112 | String decodeStr = new String(decodeHex(encodeStr.toCharArray())); 113 | System.out.println("转换前:" + srcStr); 114 | System.out.println("转换后:" + encodeStr); 115 | System.out.println("还原后:" + decodeStr); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hot2hot 6 | hot2hot 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | hot2hot 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.ow2.asm 20 | asm-all 21 | 4.1 22 | 23 | 24 | commons-io 25 | commons-io 26 | 2.4 27 | 28 | 29 | commons-lang 30 | commons-lang 31 | 2.6 32 | 33 | 34 | com.google.guava 35 | guava 36 | 14.0.1 37 | 38 | 39 | com.sun 40 | tools 41 | 1.7 42 | 43 | 44 | 45 | 124 | 125 | 126 | 127 | 128 | org.apache.maven.plugins 129 | maven-compiler-plugin 130 | 3.1 131 | 132 | 1.7 133 | 1.7 134 | 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-jar-plugin 139 | 2.4 140 | 141 | hot2hot 142 | 143 | 144 | true 145 | lib/ 146 | 147 | 148 | org.hot2hot.AgentMain 149 | true 150 | hot2hot.jar 151 | 152 | 153 | 154 | 155 | 156 | org.apache.maven.plugins 157 | maven-shade-plugin 158 | 1.6 159 | 160 | 161 | package 162 | 163 | shade 164 | 165 | 166 | 167 | 168 | org.objectweb 169 | com.khotyn.hotcode.third-party-lib.org.objectweb 170 | 171 | 172 | org.apache.commons 173 | com.khotyn.hotcode.third-party-lib.org.apache.commons 174 | 175 | 176 | com.google 177 | com.khotyn.hotcode.third-party-lib.com.google 178 | 179 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /src/main/java/org/hot2hot/jdk/ClassLoaderAdapter.java: -------------------------------------------------------------------------------- 1 | package org.hot2hot.jdk; 2 | 3 | import java.security.ProtectionDomain; 4 | 5 | import org.hot2hot.utils.Clazzs; 6 | import org.objectweb.asm.ClassVisitor; 7 | import org.objectweb.asm.Label; 8 | import org.objectweb.asm.MethodVisitor; 9 | import org.objectweb.asm.Opcodes; 10 | import org.objectweb.asm.Type; 11 | 12 | /** 13 | * 修改ClassLoader的defineClass 14 | * @author jiaojianfeng 15 | * 16 | */ 17 | public class ClassLoaderAdapter extends ClassVisitor { 18 | 19 | public ClassLoaderAdapter(ClassVisitor cv){ 20 | super(Opcodes.ASM4, cv); 21 | } 22 | 23 | @Override 24 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 25 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 26 | 27 | if (name.equals("defineClass") 28 | && desc.equals(Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class), 29 | Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE, 30 | Type.getType(ProtectionDomain.class)))) { 31 | return new MethodVisitor(Opcodes.ASM4, mv) { 32 | 33 | @Override 34 | public void visitCode() { 35 | super.visitCode(); 36 | //if 判断 37 | Label jump = new Label(); 38 | Label tryLabel = new Label(); 39 | 40 | mv.visitVarInsn(Opcodes.ALOAD, 1); 41 | mv.visitLdcInsn("com.sun."); 42 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 43 | "startsWith", "(Ljava/lang/String;)Z"); 44 | mv.visitJumpInsn(Opcodes.IFNE, jump); 45 | 46 | mv.visitVarInsn(Opcodes.ALOAD, 1); 47 | mv.visitLdcInsn("java."); 48 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 49 | "startsWith", "(Ljava/lang/String;)Z"); 50 | mv.visitJumpInsn(Opcodes.IFNE, jump); 51 | 52 | mv.visitVarInsn(Opcodes.ALOAD, 1); 53 | mv.visitLdcInsn("javax."); 54 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 55 | "startsWith", "(Ljava/lang/String;)Z"); 56 | mv.visitJumpInsn(Opcodes.IFNE, jump); 57 | 58 | mv.visitVarInsn(Opcodes.ALOAD, 1); 59 | mv.visitLdcInsn("org.omg."); 60 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 61 | "startsWith", "(Ljava/lang/String;)Z"); 62 | mv.visitJumpInsn(Opcodes.IFNE, jump); 63 | 64 | mv.visitVarInsn(Opcodes.ALOAD, 1); 65 | mv.visitLdcInsn("org.w3c."); 66 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 67 | "startsWith", "(Ljava/lang/String;)Z"); 68 | mv.visitJumpInsn(Opcodes.IFNE, jump); 69 | 70 | mv.visitVarInsn(Opcodes.ALOAD, 1); 71 | mv.visitLdcInsn("org.xml."); 72 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 73 | "startsWith", "(Ljava/lang/String;)Z"); 74 | mv.visitJumpInsn(Opcodes.IFNE, jump); 75 | 76 | mv.visitVarInsn(Opcodes.ALOAD, 1); 77 | mv.visitLdcInsn("sun."); 78 | mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), 79 | "startsWith", "(Ljava/lang/String;)Z"); 80 | mv.visitJumpInsn(Opcodes.IFNE, jump); 81 | 82 | //if 83 | 84 | mv.visitVarInsn(Opcodes.ALOAD, 0); 85 | mv.visitVarInsn(Opcodes.ALOAD, 1); 86 | mv.visitVarInsn(Opcodes.ALOAD, 5); 87 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ClassLoader.class), 88 | "preDefineClass", "(Ljava/lang/String;Ljava/security/ProtectionDomain;)Ljava/security/ProtectionDomain;"); 89 | mv.visitVarInsn(Opcodes.ASTORE, 5); 90 | mv.visitInsn(Opcodes.ACONST_NULL); 91 | 92 | mv.visitVarInsn(Opcodes.ASTORE, 6); 93 | mv.visitVarInsn(Opcodes.ALOAD, 0); 94 | mv.visitVarInsn(Opcodes.ALOAD, 5); 95 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ClassLoader.class), 96 | "defineClassSourceLocation", "(Ljava/security/ProtectionDomain;)Ljava/lang/String;"); 97 | 98 | mv.visitVarInsn(Opcodes.ASTORE, 7); 99 | mv.visitVarInsn(Opcodes.ALOAD, 0); 100 | mv.visitVarInsn(Opcodes.ALOAD, 1); 101 | mv.visitVarInsn(Opcodes.ALOAD, 2); 102 | mv.visitVarInsn(Opcodes.ILOAD, 3); 103 | mv.visitVarInsn(Opcodes.ILOAD, 4); 104 | mv.visitVarInsn(Opcodes.ALOAD, 5); 105 | mv.visitVarInsn(Opcodes.ALOAD, 7); 106 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ClassLoader.class), 107 | "defineClass1", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;Ljava/lang/String;)Ljava/lang/Class;"); 108 | mv.visitVarInsn(Opcodes.ASTORE, 6); 109 | mv.visitJumpInsn(Opcodes.GOTO, tryLabel); 110 | mv.visitVarInsn(Opcodes.ASTORE, 8); 111 | 112 | mv.visitVarInsn(Opcodes.ALOAD, 0); 113 | mv.visitVarInsn(Opcodes.ALOAD, 1); 114 | mv.visitVarInsn(Opcodes.ALOAD, 2); 115 | mv.visitVarInsn(Opcodes.ILOAD, 3); 116 | mv.visitVarInsn(Opcodes.ILOAD, 4); 117 | mv.visitVarInsn(Opcodes.ALOAD, 5); 118 | mv.visitVarInsn(Opcodes.ALOAD, 8); 119 | mv.visitVarInsn(Opcodes.ALOAD, 7); 120 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ClassLoader.class), 121 | "defineTransformedClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;Ljava/lang/ClassFormatError;Ljava/lang/String;)Ljava/lang/Class;"); 122 | mv.visitVarInsn(Opcodes.ASTORE, 6); 123 | mv.visitLabel(tryLabel); 124 | 125 | mv.visitVarInsn(Opcodes.ALOAD, 0); 126 | mv.visitVarInsn(Opcodes.ALOAD, 6); 127 | mv.visitVarInsn(Opcodes.ALOAD, 5); 128 | mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ClassLoader.class), 129 | "postDefineClass", "(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V"); 130 | 131 | 132 | mv.visitVarInsn(Opcodes.ALOAD, 1); 133 | mv.visitVarInsn(Opcodes.ALOAD, 6); 134 | mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Clazzs.class), 135 | "setClazz", "(Ljava/lang/String;Ljava/lang/Class;)V"); 136 | 137 | mv.visitVarInsn(Opcodes.ALOAD, 6); 138 | mv.visitInsn(Opcodes.ARETURN); 139 | 140 | mv.visitLabel(jump); 141 | } 142 | 143 | }; 144 | } 145 | 146 | return mv; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------