如果把的class文件加密
Class文件能被很輕松的重構生成JAVA源文件與最初JAVA字節碼的設計目的和商業交易有緊密地聯系
如果不能阻止被反編譯的話
不幸的是
加密而不打亂
或許上述可能會使你問
下面是一個簡單的類編碼器
public class Main
{
public static void main (final String [] args)
{
System
MySecretClass
}
} // End of class
package de;
import java
public class MySecretClass
{
/**
* Guess what
* a random number generator
*/
public static int mySecretAlgorithm ()
{
return (int) s_random
}
private static final Random s_random = new Random
(System
} // End of class
我想通過加密相關的class文件並在運行期解密來隱藏de
public class EncryptedClassLoader extends URLClassLoader
{
public static void main (final String [] args)
throws Exception
{
if (
{
// Create a custom loader that will use the current
//loader as delegation parent:
final ClassLoader appLoader =
new EncryptedClassLoader (EncryptedClassLoader
class
new File (args [
// Thread context loader must be adjusted as well:
Thread
(appLoader);
final Class app = appLoader
final Method appmain = app
new Class [] {String []
final String [] appargs = new String[args
System
appmain
}
else if (
{
}
else
throw new IllegalArgumentException (USAGE);
}
/**
* Overrides java
* the usual parent
* be able to
* system classloader
*/
public Class loadClass (final String name
final boolean resolve)
throws ClassNotFoundException
{
if (TRACE) System
Class c = null;
// First
// by this classloader instance:
c = findLoadedClass (name);
if (c == null)
{
Class parentsVersion = null;
try
{
// This is slightly unorthodox: do a trial load via the
// parent loader and note whether the parent delegated or not;
// what this accomplishes is proper delegation for all core
// and extension classes without my having to filter
// on class name:
parentsVersion = getParent ()
if(parentsVersion
c = parentsVersion;
}
catch (ClassNotFoundException ignore) {}
catch (ClassFormatError ignore) {}
if (c == null)
{
try
{
// OK
// or extension) loader (in which case I want to ignore that
// definition) or the parent failed altogether; either way I
// attempt to define my own version:
c = findClass (name);
}
catch (ClassNotFoundException ignore)
{
// If that failed
// [which could be null at this point]:
c = parentsVersion;
}
}
}
if (c == null)
throw new ClassNotFoundException (name);
if (resolve)
resolveClass (c);
return c;
}
/**
* Overrides java
* be able to call crypt() before defining a class
*/
protected Class findClass (final String name)
throws ClassNotFoundException
{
if(TRACE) System
//
// but if Sun
final String classResource = name
(
final URL classURL = getResource (classResource);
if (classURL == null)
throw new ClassNotFoundException (name);
else
{
InputStream in = null;
try
{
in = classURL
final byte [] classBytes = readFully (in);
//
crypt (classBytes);
if (TRACE) System
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27348.html