package com.interview.classLoader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
/**
* 加密class文件
* @author dhh
*
*/
public class MyClassLoader{
public static void main(String[] args) throws Exception{
String srcPath = args[0];
String destDir = args[1];//参数,在运行时配置参数
InputStream input = new FileInputStream(srcPath);
String destPath= destDir + "\\" + srcPath.substring(srcPath.lastIndexOf("\\"));
OutputStream output = new FileOutputStream(destPath);
enCode(input,output);
input.close();
output.close();
}
/**
* 简单加密解密算法
* @param input
* @param output
*/
public static void enCode(InputStream input,OutputStream output) throws Exception{
int len = 0 ;
while((len=input.read())!=-1){
output.write(len^ 0xff);
}
}
}
听课笔记:
给main函数传递参数:
在运行前,给main函数传递参数,从项目目录中找到编译器已经编译好的enPackage.class,
利用IO流方式加密后写入到myclass文件夹中。
本文介绍了一个简单的Class文件加密工具MyClassLoader的实现原理及使用方法。该工具通过读取指定路径下的Class文件,并采用简单的XOR操作进行加密处理,最终将加密后的文件输出到指定目录。演示了如何通过命令行参数传递源文件路径和目标目录。
933

被折叠的 条评论
为什么被折叠?



