├── README.md ├── pom.xml └── src └── main ├── java └── me │ └── javapacker │ ├── Main.java │ ├── app │ ├── api │ │ └── PackerApplication.java │ └── impl │ │ └── JavaPacker.java │ ├── config │ └── PackerConfiguration.java │ ├── file │ ├── api │ │ ├── Encryptable.java │ │ ├── PackerFile.java │ │ └── PackerFilesManager.java │ └── impl │ │ ├── EncryptableImpl.java │ │ ├── FactoryPackerFiles.java │ │ ├── PackerFileImpl.java │ │ └── PackerFilesManagerImpl.java │ ├── steps │ ├── api │ │ ├── PackerRepository.java │ │ └── PackerStep.java │ └── impl │ │ ├── PackerRepositoryImpl.java │ │ ├── S01ReadingJar.java │ │ ├── S02EncryptClasses.java │ │ ├── S03TrashingResource.java │ │ ├── S04SavingKey.java │ │ ├── S05JoinLoader.java │ │ └── S06AttachManifest.java │ └── utils │ ├── JarUtil.java │ ├── RandomUtil.java │ └── StringUtil.java └── resources └── MANIFEST.MF /README.md: -------------------------------------------------------------------------------- 1 | # JavaPacker 2 | 3 | Semester project for studies using GoF design patterns - sometimes they are used by force :D 4 | 5 | 6 | ## Getting Started 7 | 8 | The goal of the project is to encrypt another JAR executable based on the key provided by the user, save it to a file and create a decryptor and put it into the loader (I used ow2 asm to generate bytecode). 9 | After launching the program and going through all the steps, you will get the default - output.jar in jar file location (configurable) file which is ready to run. Nothing hard! :) 10 | 11 | ## Configuration 12 | 13 | ``` 14 | #Mon Jan 11 10:08:37 CET 2021 15 | useNullByteName=true 16 | outputPath=output.jar 17 | fakeDirectory=true 18 | inputPath=input.jar 19 | encryptionKey=ABCDEFGHIJKLMNPA 20 | ``` 21 | 22 | Property name | expected value | Description 23 | ------------- | ------------- | ------------- 24 | inputPath | Path to input jar file | Define input jar location 25 | outputPath | Path to output jar file | Define output jar location 26 | encryptionKey | 16 bytes(length) key | Key used to AES encryption 27 | useNullByteName | true/false | Method add \u0000 to the beginning of the class name. This method allows you to hide class names and prevent them from unpacking by popular archivers like WinRar 28 | fakeDirectory | true/false | https://github.com/x4e/fakedirectory - completely unavailable to anyone using WinRAR, Luyten and every other zip viewer. 29 | 30 | ## My comment 31 | 32 | Such a packer is not a protection you can rely on. It can only come in handy against total noobs. If you already want to use it somewhere to add extra protection to your application - Please obfuscate the loader. 33 | Remember that there are tons of ways to get around this - memory dump, defineClass hook, javaagent ... etc 34 | 35 | 36 | ## Screenshots 37 | 38 | ![alt text](https://i.imgur.com/jUrEsd8.png) 39 | ![alt text](https://i.imgur.com/967U67f.png) 40 | 41 | ## Credits 42 | x4e - https://github.com/x4e/fakedirectory 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | JavaPacker 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | maven-assembly-plugin 22 | 23 | 24 | package 25 | 26 | single 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | me.javapacker.Main 35 | 36 | 37 | 38 | jar-with-dependencies 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | commons-io 50 | commons-io 51 | 2.8.0 52 | 53 | 54 | 55 | org.ow2.asm 56 | asm 57 | 9.0 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/Main.java: -------------------------------------------------------------------------------- 1 | package me.javapacker; 2 | 3 | import me.javapacker.app.api.PackerApplication; 4 | import me.javapacker.app.impl.JavaPacker; 5 | 6 | public class Main { 7 | 8 | 9 | public static void main(String[] args) 10 | { 11 | new JavaPacker().enableApp(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/app/api/PackerApplication.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.app.api; 2 | 3 | public abstract class PackerApplication { 4 | 5 | public abstract void enableApp(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/app/impl/JavaPacker.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.app.impl; 2 | 3 | import me.javapacker.app.api.PackerApplication; 4 | import me.javapacker.config.PackerConfiguration; 5 | import me.javapacker.file.api.PackerFilesManager; 6 | import me.javapacker.file.impl.FactoryPackerFiles; 7 | import me.javapacker.steps.api.PackerRepository; 8 | import me.javapacker.steps.api.PackerStep; 9 | import me.javapacker.steps.impl.*; 10 | 11 | public class JavaPacker extends PackerApplication { 12 | 13 | public static JavaPacker INSTANCE; 14 | private PackerRepository packerRepository; 15 | 16 | @Override 17 | public void enableApp() { 18 | INSTANCE = this; 19 | 20 | try { 21 | PackerConfiguration.INSTANCE.readConfiguration(); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | } 25 | this.packerRepository = new PackerRepositoryImpl(); 26 | final PackerFilesManager packerFilesManager = FactoryPackerFiles.createPackerFilesManager(PackerConfiguration.INSTANCE.getInputPath(), PackerConfiguration.INSTANCE.getOutputPath()); 27 | final PackerStep packerStep = new S01ReadingJar(packerFilesManager); 28 | packerStep.linkWith(new S02EncryptClasses(packerFilesManager)) 29 | .linkWith(new S03TrashingResource(packerFilesManager)) 30 | .linkWith(new S04SavingKey(packerFilesManager)) 31 | .linkWith(new S05JoinLoader(packerFilesManager)) 32 | .linkWith(new S06AttachManifest(packerFilesManager)); 33 | this.packerRepository.setPackerStep(packerStep); 34 | this.packerRepository.packApplication(); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/config/PackerConfiguration.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.config; 2 | 3 | import me.javapacker.steps.api.PackerStep; 4 | 5 | import java.io.*; 6 | import java.util.Properties; 7 | 8 | public class PackerConfiguration { 9 | 10 | public static PackerConfiguration INSTANCE = new PackerConfiguration(); 11 | final Properties properties = new Properties(); 12 | private static String encryptionKey; 13 | private static String inputPath; 14 | private static String outputPath; 15 | private static boolean useNullByteName; 16 | private static boolean fakeDirectory; 17 | 18 | private PackerConfiguration() { } 19 | 20 | public void readConfiguration() throws Exception { 21 | final File f = new File("javapacker.properties"); 22 | if(!f.exists()) 23 | { 24 | properties.setProperty("inputPath", "input.jar"); 25 | properties.setProperty("outputPath", "output.jar"); 26 | properties.setProperty("encryptionKey", "ABCDEFGHIJKLMNPA"); 27 | properties.setProperty("useNullByteName", "true"); 28 | properties.setProperty("fakeDirectory", "true"); 29 | properties.store(new FileOutputStream(f), ""); 30 | } 31 | loadConfiguration(f); 32 | } 33 | 34 | private void loadConfiguration(final File f) throws IOException { 35 | properties.load(new FileInputStream(f)); 36 | inputPath = properties.getProperty("inputPath"); 37 | outputPath = properties.getProperty("outputPath"); 38 | encryptionKey = properties.getProperty("encryptionKey"); 39 | useNullByteName = Boolean.parseBoolean(properties.getProperty("useNullByteName")); 40 | fakeDirectory = Boolean.parseBoolean(properties.getProperty("fakeDirectory")); 41 | if(encryptionKey.length() != 16) 42 | { 43 | throw new RuntimeException("EncryptionKey length must be 16 bytes!"); 44 | } 45 | } 46 | 47 | public String getEncryptionKey() { 48 | return encryptionKey; 49 | } 50 | 51 | public String getInputPath() { 52 | return inputPath; 53 | } 54 | 55 | public String getOutputPath() { 56 | return outputPath; 57 | } 58 | 59 | public boolean isUseNullByteName() { 60 | return useNullByteName; 61 | } 62 | 63 | public boolean isFakeDirectory() { 64 | return fakeDirectory; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/api/Encryptable.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.api; 2 | 3 | public interface Encryptable { 4 | 5 | String getEncryptableConfig(); 6 | 7 | String getEncryptableFile(); 8 | 9 | void setEncryptableConfigName(final String name); 10 | 11 | void setEncryptableFileName(final String name); 12 | 13 | String getEncryptionKey(); 14 | 15 | byte[] getEncryptionIV(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/api/PackerFile.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.api; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.jar.JarFile; 6 | 7 | public interface PackerFile { 8 | 9 | File getFile(); 10 | 11 | default JarFile asJarFile() throws IOException { 12 | return new JarFile(getFile()); 13 | } 14 | 15 | String getMainClassName(); 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/api/PackerFilesManager.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.api; 2 | 3 | import java.util.zip.ZipOutputStream; 4 | 5 | public interface PackerFilesManager { 6 | 7 | PackerFile getInputFile(); 8 | 9 | PackerFile getOutputFile(); 10 | 11 | ZipOutputStream asZipOutputStream(); 12 | 13 | Encryptable getEncryptable(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/impl/EncryptableImpl.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.impl; 2 | 3 | import me.javapacker.file.api.Encryptable; 4 | 5 | import java.util.Random; 6 | 7 | public class EncryptableImpl implements Encryptable { 8 | 9 | private String encryptableConfig; 10 | private String encryptableFileName; 11 | private final String encryptionKey; 12 | private final byte[] encryptionIV; 13 | 14 | public EncryptableImpl(String encryptionKey) { 15 | this.encryptionKey = encryptionKey; 16 | final byte[] iv = new byte[16]; 17 | new Random().nextBytes(iv); 18 | this.encryptionIV = iv; 19 | } 20 | 21 | @Override 22 | public String getEncryptableConfig() { 23 | return this.encryptableConfig; 24 | } 25 | 26 | @Override 27 | public String getEncryptableFile() { 28 | return this.encryptableFileName; 29 | } 30 | 31 | @Override 32 | public void setEncryptableConfigName(String name) { 33 | this.encryptableConfig = name; 34 | } 35 | 36 | @Override 37 | public void setEncryptableFileName(String name) { 38 | this.encryptableFileName = name; 39 | } 40 | 41 | @Override 42 | public String getEncryptionKey() { 43 | return this.encryptionKey; 44 | } 45 | 46 | @Override 47 | public byte[] getEncryptionIV() { 48 | return this.encryptionIV; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/impl/FactoryPackerFiles.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.impl; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | 5 | import java.io.File; 6 | 7 | public class FactoryPackerFiles { 8 | 9 | public static PackerFilesManager createPackerFilesManager(final String inputPath, final String outputPath) 10 | { 11 | return new PackerFilesManagerImpl(new PackerFileImpl(new File(inputPath), true), 12 | new PackerFileImpl(new File(outputPath), false) 13 | ); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/impl/PackerFileImpl.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.impl; 2 | 3 | import me.javapacker.file.api.PackerFile; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.Map; 8 | import java.util.jar.JarFile; 9 | 10 | public class PackerFileImpl implements PackerFile { 11 | 12 | private final File file; 13 | private String mainClassName; 14 | 15 | public PackerFileImpl(File file, boolean readMain) { 16 | this.file = file; 17 | if(!readMain) 18 | { 19 | return; 20 | } 21 | try { 22 | final JarFile jarFile = asJarFile(); 23 | Map map = jarFile.getManifest().getMainAttributes(); 24 | for (Object obj : map.keySet()) { 25 | if (obj.toString().equalsIgnoreCase("main-class")) { 26 | mainClassName = map.get(obj).toString(); 27 | break; 28 | } 29 | } 30 | jarFile.close(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | @Override 37 | public File getFile() { 38 | return this.file; 39 | } 40 | 41 | @Override 42 | public String getMainClassName() { 43 | return this.mainClassName; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/file/impl/PackerFilesManagerImpl.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.file.impl; 2 | 3 | import me.javapacker.config.PackerConfiguration; 4 | import me.javapacker.file.api.Encryptable; 5 | import me.javapacker.file.api.PackerFile; 6 | import me.javapacker.file.api.PackerFilesManager; 7 | 8 | import java.io.FileNotFoundException; 9 | import java.io.FileOutputStream; 10 | import java.util.Random; 11 | import java.util.zip.ZipOutputStream; 12 | 13 | public class PackerFilesManagerImpl implements PackerFilesManager { 14 | 15 | private final PackerFile inputFile; 16 | private final PackerFile outputFile; 17 | private ZipOutputStream zipOutputStream; 18 | private final Encryptable encryptable; 19 | 20 | public PackerFilesManagerImpl(PackerFile inputFile, PackerFile outputFile) { 21 | this.inputFile = inputFile; 22 | this.outputFile = outputFile; 23 | try { 24 | this.zipOutputStream = new ZipOutputStream(new FileOutputStream(outputFile.getFile())); 25 | } catch (FileNotFoundException e) { 26 | e.printStackTrace(); 27 | } 28 | this.encryptable = new EncryptableImpl(PackerConfiguration.INSTANCE.getEncryptionKey()); 29 | } 30 | 31 | @Override 32 | public PackerFile getInputFile() { 33 | return this.inputFile; 34 | } 35 | 36 | @Override 37 | public PackerFile getOutputFile() { 38 | return this.outputFile; 39 | } 40 | 41 | @Override 42 | public ZipOutputStream asZipOutputStream() { 43 | return this.zipOutputStream; 44 | } 45 | 46 | @Override 47 | public Encryptable getEncryptable() { 48 | return this.encryptable; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/api/PackerRepository.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.api; 2 | 3 | public interface PackerRepository { 4 | 5 | void packApplication(); 6 | 7 | void setPackerStep(final PackerStep packerStep); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/api/PackerStep.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.api; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | public abstract class PackerStep { 11 | 12 | private PackerStep nextStep; 13 | private final PackerFilesManager packerFilesManager; 14 | private static Logger LOGGER = Logger.getLogger("PackerStep"); 15 | 16 | public PackerStep(final PackerFilesManager packerFilesManager) { 17 | this.packerFilesManager = packerFilesManager; 18 | } 19 | 20 | public PackerStep linkWith(final PackerStep nextStep) { 21 | this.nextStep = nextStep; 22 | return nextStep; 23 | } 24 | 25 | public abstract boolean completeStep(); 26 | 27 | protected boolean checkNext() 28 | { 29 | if(this.nextStep == null) 30 | { 31 | return true; 32 | } 33 | return this.nextStep.completeStep(); 34 | } 35 | 36 | 37 | protected void logMessage(final Level level, final String message) 38 | { 39 | LOGGER.log(level, message); 40 | } 41 | 42 | public PackerFilesManager getPackerFilesManager() { 43 | return packerFilesManager; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/PackerRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.steps.api.PackerRepository; 4 | import me.javapacker.steps.api.PackerStep; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class PackerRepositoryImpl implements PackerRepository { 10 | 11 | private final List packerSteps = new ArrayList(); 12 | private PackerStep packerStep; 13 | 14 | public void setPackerStep(PackerStep packerStep) { 15 | this.packerStep = packerStep; 16 | } 17 | 18 | public void packApplication() { 19 | if(!this.packerStep.completeStep()) 20 | { 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S01ReadingJar.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.config.PackerConfiguration; 4 | import me.javapacker.file.api.PackerFilesManager; 5 | import me.javapacker.steps.api.PackerStep; 6 | import org.apache.commons.io.IOUtils; 7 | 8 | import java.io.*; 9 | import java.util.Enumeration; 10 | import java.util.logging.Level; 11 | import java.util.zip.ZipEntry; 12 | import java.util.zip.ZipFile; 13 | import java.util.zip.ZipOutputStream; 14 | 15 | public class S01ReadingJar extends PackerStep { 16 | 17 | 18 | public S01ReadingJar(PackerFilesManager packerFilesManager) { 19 | super(packerFilesManager); 20 | } 21 | 22 | public boolean completeStep() 23 | { 24 | final File f = new File(PackerConfiguration.INSTANCE.getInputPath()); 25 | if(!f.exists()) 26 | { 27 | logMessage(Level.WARNING, "File input.jar does not exists!"); 28 | return false; 29 | } 30 | try { 31 | final ZipFile zipFile = new ZipFile(f); 32 | ZipOutputStream out = getPackerFilesManager().asZipOutputStream(); 33 | Enumeration entries = zipFile.entries(); 34 | while (entries.hasMoreElements()) { 35 | final ZipEntry entry = entries.nextElement(); 36 | if (!entry.getName().toLowerCase().contains("meta-inf") && !entry.getName().toLowerCase().endsWith(".class")) { 37 | byte[] b = IOUtils.toByteArray(zipFile.getInputStream(entry)); 38 | out.putNextEntry(entry); 39 | out.write(b); 40 | out.closeEntry(); 41 | } 42 | } 43 | zipFile.close(); 44 | } 45 | catch (Exception e) 46 | { 47 | logMessage(Level.WARNING, "S01ReadingJar failed!"); 48 | e.printStackTrace(); 49 | return false; 50 | } 51 | logMessage(Level.INFO, "S01ReadingJar completed!"); 52 | return checkNext(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S02EncryptClasses.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | import me.javapacker.steps.api.PackerStep; 5 | import me.javapacker.utils.StringUtil; 6 | import org.apache.commons.io.IOUtils; 7 | 8 | import javax.crypto.Cipher; 9 | import javax.crypto.CipherOutputStream; 10 | import javax.crypto.spec.IvParameterSpec; 11 | import javax.crypto.spec.SecretKeySpec; 12 | import java.io.*; 13 | import java.util.logging.Level; 14 | import java.util.zip.ZipEntry; 15 | import java.util.zip.ZipOutputStream; 16 | 17 | public class S02EncryptClasses extends PackerStep { 18 | 19 | 20 | public S02EncryptClasses(PackerFilesManager packerFilesManager) { 21 | super(packerFilesManager); 22 | } 23 | 24 | public boolean completeStep() { 25 | 26 | Cipher cipher = null; 27 | try { 28 | ZipOutputStream out = getPackerFilesManager().asZipOutputStream(); 29 | 30 | cipher = Cipher.getInstance("AES/CBC/NOPADDING"); 31 | 32 | cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(getPackerFilesManager().getEncryptable().getEncryptionKey().getBytes(), "AES"), new IvParameterSpec(getPackerFilesManager().getEncryptable().getEncryptionKey().getBytes())); 33 | 34 | FileInputStream is = new FileInputStream(getPackerFilesManager().getInputFile().getFile()); 35 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 36 | CipherOutputStream cos = new CipherOutputStream(baos, cipher); 37 | 38 | IOUtils.copy(is, cos); 39 | 40 | is.close(); 41 | cos.close(); 42 | 43 | final String jarData = StringUtil.randomPackerName(30); 44 | getPackerFilesManager().getEncryptable().setEncryptableFileName(jarData); 45 | ZipEntry entry = new ZipEntry(jarData); 46 | out.putNextEntry(entry); 47 | out.write(baos.toByteArray()); 48 | out.closeEntry(); 49 | 50 | } 51 | catch (Exception e) 52 | { 53 | logMessage(Level.WARNING, "S02EncryptClasses failed!"); 54 | e.printStackTrace(); 55 | return false; 56 | } 57 | logMessage(Level.INFO, "S02EncryptClasses completed!"); 58 | return checkNext(); 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S03TrashingResource.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | import me.javapacker.steps.api.PackerStep; 5 | import me.javapacker.utils.StringUtil; 6 | 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.security.SecureRandom; 10 | import java.util.logging.Level; 11 | import java.util.zip.CRC32; 12 | import java.util.zip.ZipEntry; 13 | import java.util.zip.ZipOutputStream; 14 | 15 | public class S03TrashingResource extends PackerStep { 16 | 17 | 18 | public S03TrashingResource(PackerFilesManager packerFilesManager) { 19 | super(packerFilesManager); 20 | } 21 | 22 | public boolean completeStep() { 23 | try { 24 | ZipOutputStream zos = getPackerFilesManager().asZipOutputStream(); 25 | for (int i = 0; i < 100; i++) { 26 | final ZipEntry entry = new ZipEntry(StringUtil.randomPackerName(30)); 27 | final byte[] trashByte = new byte[Files.readAllBytes(Paths.get(getPackerFilesManager().getInputFile().getFile().getAbsolutePath())).length - 1]; 28 | zos.putNextEntry(entry); 29 | SecureRandom.getInstanceStrong().nextBytes(trashByte); 30 | zos.write(trashByte); 31 | } 32 | } 33 | catch (Exception e) 34 | { 35 | logMessage(Level.WARNING, "S03TrashingResource failed!"); 36 | e.printStackTrace(); 37 | return false; 38 | } 39 | logMessage(Level.INFO, "S03TrashingResource completed!"); 40 | return checkNext(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S04SavingKey.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.config.PackerConfiguration; 4 | import me.javapacker.file.api.PackerFilesManager; 5 | import me.javapacker.steps.api.PackerStep; 6 | import me.javapacker.utils.StringUtil; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.io.DataOutputStream; 10 | import java.util.logging.Level; 11 | import java.util.zip.ZipEntry; 12 | import java.util.zip.ZipOutputStream; 13 | 14 | public class S04SavingKey extends PackerStep { 15 | 16 | 17 | public S04SavingKey(PackerFilesManager packerFilesManager) { 18 | super(packerFilesManager); 19 | } 20 | 21 | public boolean completeStep() { 22 | final ZipOutputStream zos = getPackerFilesManager().asZipOutputStream(); 23 | try { 24 | final String configName = StringUtil.randomPackerName(30); 25 | getPackerFilesManager().getEncryptable().setEncryptableConfigName(configName); 26 | final ZipEntry entry = new ZipEntry(configName); 27 | zos.putNextEntry(entry); 28 | final ByteArrayOutputStream bos = new ByteArrayOutputStream(); 29 | final DataOutputStream dos = new DataOutputStream(bos); 30 | dos.writeUTF(getPackerFilesManager().getInputFile().getMainClassName()); 31 | dos.writeUTF(PackerConfiguration.INSTANCE.getEncryptionKey()); 32 | zos.write(bos.toByteArray()); 33 | }catch (Exception e) 34 | { 35 | logMessage(Level.WARNING, "S04SavingKey failed!"); 36 | e.printStackTrace(); 37 | return false; 38 | } 39 | logMessage(Level.INFO, "S04SavingKey completed!"); 40 | return checkNext(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S05JoinLoader.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | import me.javapacker.steps.api.PackerStep; 5 | import org.apache.commons.io.IOUtils; 6 | import org.objectweb.asm.*; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.OutputStream; 11 | import java.util.Enumeration; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.logging.Level; 15 | import java.util.zip.ZipEntry; 16 | import java.util.zip.ZipFile; 17 | import java.util.zip.ZipOutputStream; 18 | 19 | public class S05JoinLoader extends PackerStep implements Opcodes { 20 | 21 | private final Map includeClasses = new HashMap<>(); 22 | 23 | public S05JoinLoader(PackerFilesManager packerFilesManager) { 24 | super(packerFilesManager); 25 | } 26 | 27 | @Override 28 | public boolean completeStep() { 29 | includeClasses.putIfAbsent("me/javapacker/Main", mainDump()); 30 | includeClasses.putIfAbsent("me/javapacker/PackerClassLoader", classLoaderDump()); 31 | includeClasses.putIfAbsent("me/javapacker/Util", utilDump()); 32 | //Can not be in 33 | 34 | 35 | try { 36 | final ZipOutputStream out = getPackerFilesManager().asZipOutputStream(); 37 | this.includeClasses.forEach((name, array) -> { 38 | ZipEntry entry = new ZipEntry(name + ".class"); 39 | try { 40 | out.putNextEntry(entry); 41 | out.write(array); 42 | out.closeEntry(); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | }); 47 | } 48 | catch (Exception e) 49 | { 50 | logMessage(Level.WARNING, "S05JoinLoader failed!"); 51 | e.printStackTrace(); 52 | return false; 53 | } 54 | logMessage(Level.INFO, "S05JoinLoader completed!"); 55 | return checkNext(); 56 | } 57 | 58 | public static byte[] utilDump() { 59 | 60 | ClassWriter cw = new ClassWriter(0); 61 | FieldVisitor fv; 62 | MethodVisitor mv; 63 | AnnotationVisitor av0; 64 | 65 | cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "me/javapacker/Util", null, "java/lang/Object", null); 66 | 67 | 68 | { 69 | mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); 70 | mv.visitCode(); 71 | Label l0 = new Label(); 72 | mv.visitLabel(l0); 73 | mv.visitLineNumber(7, l0); 74 | mv.visitVarInsn(ALOAD, 0); 75 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); 76 | mv.visitInsn(RETURN); 77 | Label l1 = new Label(); 78 | mv.visitLabel(l1); 79 | mv.visitLocalVariable("this", "Lme/javapacker/Util;", null, l0, l1, 0); 80 | mv.visitMaxs(1, 1); 81 | mv.visitEnd(); 82 | } 83 | { 84 | mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "readAllBytes", "(Ljava/io/InputStream;)[B", null, new String[] { "java/io/IOException" }); 85 | mv.visitCode(); 86 | Label l0 = new Label(); 87 | Label l1 = new Label(); 88 | Label l2 = new Label(); 89 | mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable"); 90 | Label l3 = new Label(); 91 | Label l4 = new Label(); 92 | Label l5 = new Label(); 93 | mv.visitTryCatchBlock(l3, l4, l5, "java/io/IOException"); 94 | Label l6 = new Label(); 95 | Label l7 = new Label(); 96 | Label l8 = new Label(); 97 | mv.visitTryCatchBlock(l6, l7, l8, "java/lang/Throwable"); 98 | Label l9 = new Label(); 99 | mv.visitTryCatchBlock(l6, l7, l9, null); 100 | Label l10 = new Label(); 101 | Label l11 = new Label(); 102 | Label l12 = new Label(); 103 | mv.visitTryCatchBlock(l10, l11, l12, "java/lang/Throwable"); 104 | Label l13 = new Label(); 105 | mv.visitTryCatchBlock(l8, l13, l9, null); 106 | Label l14 = new Label(); 107 | Label l15 = new Label(); 108 | Label l16 = new Label(); 109 | mv.visitTryCatchBlock(l14, l15, l16, "java/io/IOException"); 110 | mv.visitTryCatchBlock(l8, l16, l16, "java/io/IOException"); 111 | Label l17 = new Label(); 112 | mv.visitTryCatchBlock(l14, l15, l17, null); 113 | Label l18 = new Label(); 114 | Label l19 = new Label(); 115 | Label l20 = new Label(); 116 | mv.visitTryCatchBlock(l18, l19, l20, "java/io/IOException"); 117 | Label l21 = new Label(); 118 | mv.visitTryCatchBlock(l8, l21, l17, null); 119 | Label l22 = new Label(); 120 | mv.visitLabel(l22); 121 | mv.visitLineNumber(10, l22); 122 | mv.visitIntInsn(SIPUSH, 4096); 123 | mv.visitVarInsn(ISTORE, 1); 124 | Label l23 = new Label(); 125 | mv.visitLabel(l23); 126 | mv.visitLineNumber(11, l23); 127 | mv.visitIntInsn(SIPUSH, 4096); 128 | mv.visitIntInsn(NEWARRAY, T_BYTE); 129 | mv.visitVarInsn(ASTORE, 2); 130 | Label l24 = new Label(); 131 | mv.visitLabel(l24); 132 | mv.visitLineNumber(13, l24); 133 | mv.visitInsn(ACONST_NULL); 134 | mv.visitVarInsn(ASTORE, 4); 135 | mv.visitLabel(l14); 136 | mv.visitLineNumber(16, l14); 137 | mv.visitTypeInsn(NEW, "java/io/ByteArrayOutputStream"); 138 | mv.visitInsn(DUP); 139 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/ByteArrayOutputStream", "", "()V", false); 140 | mv.visitVarInsn(ASTORE, 5); 141 | Label l25 = new Label(); 142 | mv.visitLabel(l25); 143 | mv.visitInsn(ACONST_NULL); 144 | mv.visitVarInsn(ASTORE, 6); 145 | mv.visitLabel(l6); 146 | mv.visitLineNumber(17, l6); 147 | mv.visitFrame(Opcodes.F_FULL, 7, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.TOP, "java/io/IOException", "java/io/ByteArrayOutputStream", "java/lang/Throwable"}, 0, new Object[] {}); 148 | mv.visitVarInsn(ALOAD, 0); 149 | mv.visitVarInsn(ALOAD, 2); 150 | mv.visitInsn(ICONST_0); 151 | mv.visitIntInsn(SIPUSH, 4096); 152 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/InputStream", "read", "([BII)I", false); 153 | mv.visitInsn(DUP); 154 | mv.visitVarInsn(ISTORE, 3); 155 | Label l26 = new Label(); 156 | mv.visitLabel(l26); 157 | mv.visitInsn(ICONST_M1); 158 | Label l27 = new Label(); 159 | mv.visitJumpInsn(IF_ICMPEQ, l27); 160 | Label l28 = new Label(); 161 | mv.visitLabel(l28); 162 | mv.visitLineNumber(18, l28); 163 | mv.visitVarInsn(ALOAD, 5); 164 | mv.visitVarInsn(ALOAD, 2); 165 | mv.visitInsn(ICONST_0); 166 | mv.visitVarInsn(ILOAD, 3); 167 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "write", "([BII)V", false); 168 | mv.visitJumpInsn(GOTO, l6); 169 | mv.visitLabel(l27); 170 | mv.visitLineNumber(20, l27); 171 | mv.visitFrame(Opcodes.F_FULL, 7, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.INTEGER, "java/io/IOException", "java/io/ByteArrayOutputStream", "java/lang/Throwable"}, 0, new Object[] {}); 172 | mv.visitVarInsn(ALOAD, 5); 173 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "toByteArray", "()[B", false); 174 | mv.visitVarInsn(ASTORE, 7); 175 | mv.visitLabel(l7); 176 | mv.visitLineNumber(21, l7); 177 | mv.visitVarInsn(ALOAD, 5); 178 | mv.visitJumpInsn(IFNULL, l15); 179 | mv.visitVarInsn(ALOAD, 6); 180 | Label l29 = new Label(); 181 | mv.visitJumpInsn(IFNULL, l29); 182 | mv.visitLabel(l0); 183 | mv.visitVarInsn(ALOAD, 5); 184 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "close", "()V", false); 185 | mv.visitLabel(l1); 186 | mv.visitJumpInsn(GOTO, l15); 187 | mv.visitLabel(l2); 188 | mv.visitFrame(Opcodes.F_FULL, 8, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.INTEGER, "java/io/IOException", "java/io/ByteArrayOutputStream", "java/lang/Throwable", "[B"}, 1, new Object[] {"java/lang/Throwable"}); 189 | mv.visitVarInsn(ASTORE, 8); 190 | mv.visitVarInsn(ALOAD, 6); 191 | mv.visitVarInsn(ALOAD, 8); 192 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V", false); 193 | mv.visitJumpInsn(GOTO, l15); 194 | mv.visitLabel(l29); 195 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 196 | mv.visitVarInsn(ALOAD, 5); 197 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "close", "()V", false); 198 | mv.visitLabel(l15); 199 | mv.visitLineNumber(26, l15); 200 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 201 | mv.visitVarInsn(ALOAD, 4); 202 | mv.visitJumpInsn(IFNONNULL, l3); 203 | mv.visitVarInsn(ALOAD, 0); 204 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/InputStream", "close", "()V", false); 205 | Label l30 = new Label(); 206 | mv.visitJumpInsn(GOTO, l30); 207 | mv.visitLabel(l3); 208 | mv.visitLineNumber(28, l3); 209 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 210 | mv.visitVarInsn(ALOAD, 0); 211 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/InputStream", "close", "()V", false); 212 | mv.visitLabel(l4); 213 | mv.visitLineNumber(31, l4); 214 | mv.visitJumpInsn(GOTO, l30); 215 | mv.visitLabel(l5); 216 | mv.visitLineNumber(29, l5); 217 | mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/io/IOException"}); 218 | mv.visitVarInsn(ASTORE, 8); 219 | Label l31 = new Label(); 220 | mv.visitLabel(l31); 221 | mv.visitLineNumber(30, l31); 222 | mv.visitVarInsn(ALOAD, 4); 223 | mv.visitVarInsn(ALOAD, 8); 224 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "addSuppressed", "(Ljava/lang/Throwable;)V", false); 225 | mv.visitLabel(l30); 226 | mv.visitLineNumber(20, l30); 227 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 228 | mv.visitVarInsn(ALOAD, 7); 229 | mv.visitInsn(ARETURN); 230 | mv.visitLabel(l8); 231 | mv.visitLineNumber(16, l8); 232 | mv.visitFrame(Opcodes.F_FULL, 7, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.TOP, "java/io/IOException", "java/io/ByteArrayOutputStream", "java/lang/Throwable"}, 1, new Object[] {"java/lang/Throwable"}); 233 | mv.visitVarInsn(ASTORE, 7); 234 | mv.visitVarInsn(ALOAD, 7); 235 | mv.visitVarInsn(ASTORE, 6); 236 | mv.visitVarInsn(ALOAD, 7); 237 | mv.visitInsn(ATHROW); 238 | mv.visitLabel(l9); 239 | mv.visitLineNumber(21, l9); 240 | mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"}); 241 | mv.visitVarInsn(ASTORE, 9); 242 | mv.visitLabel(l13); 243 | mv.visitVarInsn(ALOAD, 5); 244 | Label l32 = new Label(); 245 | mv.visitJumpInsn(IFNULL, l32); 246 | mv.visitVarInsn(ALOAD, 6); 247 | Label l33 = new Label(); 248 | mv.visitJumpInsn(IFNULL, l33); 249 | mv.visitLabel(l10); 250 | mv.visitVarInsn(ALOAD, 5); 251 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "close", "()V", false); 252 | mv.visitLabel(l11); 253 | mv.visitJumpInsn(GOTO, l32); 254 | mv.visitLabel(l12); 255 | mv.visitFrame(Opcodes.F_FULL, 10, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.TOP, "java/io/IOException", "java/io/ByteArrayOutputStream", "java/lang/Throwable", Opcodes.TOP, Opcodes.TOP, "java/lang/Throwable"}, 1, new Object[] {"java/lang/Throwable"}); 256 | mv.visitVarInsn(ASTORE, 10); 257 | mv.visitVarInsn(ALOAD, 6); 258 | mv.visitVarInsn(ALOAD, 10); 259 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V", false); 260 | mv.visitJumpInsn(GOTO, l32); 261 | mv.visitLabel(l33); 262 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 263 | mv.visitVarInsn(ALOAD, 5); 264 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "close", "()V", false); 265 | mv.visitLabel(l32); 266 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 267 | mv.visitVarInsn(ALOAD, 9); 268 | mv.visitInsn(ATHROW); 269 | mv.visitLabel(l16); 270 | mv.visitLineNumber(22, l16); 271 | mv.visitFrame(Opcodes.F_FULL, 5, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.TOP, "java/io/IOException"}, 1, new Object[] {"java/io/IOException"}); 272 | mv.visitVarInsn(ASTORE, 5); 273 | Label l34 = new Label(); 274 | mv.visitLabel(l34); 275 | mv.visitLineNumber(23, l34); 276 | mv.visitVarInsn(ALOAD, 5); 277 | mv.visitVarInsn(ASTORE, 4); 278 | Label l35 = new Label(); 279 | mv.visitLabel(l35); 280 | mv.visitLineNumber(24, l35); 281 | mv.visitVarInsn(ALOAD, 5); 282 | mv.visitInsn(ATHROW); 283 | mv.visitLabel(l17); 284 | mv.visitLineNumber(26, l17); 285 | mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"}); 286 | mv.visitVarInsn(ASTORE, 11); 287 | mv.visitLabel(l21); 288 | mv.visitVarInsn(ALOAD, 4); 289 | mv.visitJumpInsn(IFNONNULL, l18); 290 | mv.visitVarInsn(ALOAD, 0); 291 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/InputStream", "close", "()V", false); 292 | Label l36 = new Label(); 293 | mv.visitJumpInsn(GOTO, l36); 294 | mv.visitLabel(l18); 295 | mv.visitLineNumber(28, l18); 296 | mv.visitFrame(Opcodes.F_FULL, 12, new Object[] {"java/io/InputStream", Opcodes.INTEGER, "[B", Opcodes.TOP, "java/io/IOException", Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, "java/lang/Throwable"}, 0, new Object[] {}); 297 | mv.visitVarInsn(ALOAD, 0); 298 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/InputStream", "close", "()V", false); 299 | mv.visitLabel(l19); 300 | mv.visitLineNumber(31, l19); 301 | mv.visitJumpInsn(GOTO, l36); 302 | mv.visitLabel(l20); 303 | mv.visitLineNumber(29, l20); 304 | mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/io/IOException"}); 305 | mv.visitVarInsn(ASTORE, 12); 306 | Label l37 = new Label(); 307 | mv.visitLabel(l37); 308 | mv.visitLineNumber(30, l37); 309 | mv.visitVarInsn(ALOAD, 4); 310 | mv.visitVarInsn(ALOAD, 12); 311 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "addSuppressed", "(Ljava/lang/Throwable;)V", false); 312 | mv.visitLabel(l36); 313 | mv.visitLineNumber(32, l36); 314 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 315 | mv.visitVarInsn(ALOAD, 11); 316 | mv.visitInsn(ATHROW); 317 | Label l38 = new Label(); 318 | mv.visitLabel(l38); 319 | mv.visitMaxs(4, 13); 320 | mv.visitEnd(); 321 | } 322 | cw.visitEnd(); 323 | 324 | return cw.toByteArray(); 325 | } 326 | 327 | 328 | public static byte[] classLoaderDump () { 329 | 330 | ClassWriter cw = new ClassWriter(0); 331 | FieldVisitor fv; 332 | MethodVisitor mv; 333 | AnnotationVisitor av0; 334 | 335 | cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "me/javapacker/PackerClassLoader", null, "java/lang/ClassLoader", null); 336 | 337 | cw.visitSource("PackerClassLoader.java", null); 338 | 339 | { 340 | fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "classes", "Ljava/util/HashMap;", "Ljava/util/HashMap;", null); 341 | fv.visitEnd(); 342 | } 343 | { 344 | mv = cw.visitMethod(ACC_PUBLIC, "", "(Ljava/lang/ClassLoader;Ljava/util/jar/JarInputStream;)V", null, null); 345 | mv.visitCode(); 346 | Label l0 = new Label(); 347 | mv.visitLabel(l0); 348 | mv.visitLineNumber(19, l0); 349 | mv.visitVarInsn(ALOAD, 0); 350 | mv.visitVarInsn(ALOAD, 1); 351 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ClassLoader", "", "(Ljava/lang/ClassLoader;)V", false); 352 | Label l1 = new Label(); 353 | mv.visitLabel(l1); 354 | mv.visitLineNumber(16, l1); 355 | mv.visitVarInsn(ALOAD, 0); 356 | mv.visitTypeInsn(NEW, "java/util/HashMap"); 357 | mv.visitInsn(DUP); 358 | mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "", "()V", false); 359 | mv.visitFieldInsn(PUTFIELD, "me/javapacker/PackerClassLoader", "classes", "Ljava/util/HashMap;"); 360 | Label l2 = new Label(); 361 | mv.visitLabel(l2); 362 | mv.visitLineNumber(20, l2); 363 | mv.visitVarInsn(ALOAD, 0); 364 | mv.visitVarInsn(ALOAD, 2); 365 | mv.visitMethodInsn(INVOKEVIRTUAL, "me/javapacker/PackerClassLoader", "loadResources", "(Ljava/util/jar/JarInputStream;)V", false); 366 | Label l3 = new Label(); 367 | mv.visitLabel(l3); 368 | mv.visitLineNumber(21, l3); 369 | mv.visitInsn(RETURN); 370 | Label l4 = new Label(); 371 | mv.visitLabel(l4); 372 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l0, l4, 0); 373 | mv.visitLocalVariable("parent", "Ljava/lang/ClassLoader;", null, l0, l4, 1); 374 | mv.visitLocalVariable("stream", "Ljava/util/jar/JarInputStream;", null, l0, l4, 2); 375 | mv.visitMaxs(3, 3); 376 | mv.visitEnd(); 377 | } 378 | { 379 | mv = cw.visitMethod(ACC_PUBLIC, "getResourceAsStream", "(Ljava/lang/String;)Ljava/io/InputStream;", null, null); 380 | mv.visitCode(); 381 | Label l0 = new Label(); 382 | mv.visitLabel(l0); 383 | mv.visitLineNumber(25, l0); 384 | mv.visitVarInsn(ALOAD, 0); 385 | mv.visitVarInsn(ALOAD, 1); 386 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ClassLoader", "getResourceAsStream", "(Ljava/lang/String;)Ljava/io/InputStream;", false); 387 | mv.visitInsn(ARETURN); 388 | Label l1 = new Label(); 389 | mv.visitLabel(l1); 390 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l0, l1, 0); 391 | mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l1, 1); 392 | mv.visitMaxs(2, 2); 393 | mv.visitEnd(); 394 | } 395 | { 396 | mv = cw.visitMethod(ACC_PUBLIC, "getResource", "(Ljava/lang/String;)Ljava/net/URL;", null, null); 397 | mv.visitCode(); 398 | Label l0 = new Label(); 399 | mv.visitLabel(l0); 400 | mv.visitLineNumber(30, l0); 401 | mv.visitVarInsn(ALOAD, 0); 402 | mv.visitVarInsn(ALOAD, 1); 403 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ClassLoader", "getResource", "(Ljava/lang/String;)Ljava/net/URL;", false); 404 | mv.visitInsn(ARETURN); 405 | Label l1 = new Label(); 406 | mv.visitLabel(l1); 407 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l0, l1, 0); 408 | mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l1, 1); 409 | mv.visitMaxs(2, 2); 410 | mv.visitEnd(); 411 | } 412 | { 413 | mv = cw.visitMethod(ACC_PROTECTED, "findResources", "(Ljava/lang/String;)Ljava/util/Enumeration;", "(Ljava/lang/String;)Ljava/util/Enumeration;", new String[] { "java/io/IOException" }); 414 | mv.visitCode(); 415 | Label l0 = new Label(); 416 | mv.visitLabel(l0); 417 | mv.visitLineNumber(35, l0); 418 | mv.visitVarInsn(ALOAD, 0); 419 | mv.visitVarInsn(ALOAD, 1); 420 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ClassLoader", "findResources", "(Ljava/lang/String;)Ljava/util/Enumeration;", false); 421 | mv.visitInsn(ARETURN); 422 | Label l1 = new Label(); 423 | mv.visitLabel(l1); 424 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l0, l1, 0); 425 | mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l1, 1); 426 | mv.visitMaxs(2, 2); 427 | mv.visitEnd(); 428 | } 429 | { 430 | mv = cw.visitMethod(ACC_PUBLIC, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;", "(Ljava/lang/String;)Ljava/lang/Class<*>;", new String[] { "java/lang/ClassNotFoundException" }); 431 | mv.visitCode(); 432 | Label l0 = new Label(); 433 | mv.visitLabel(l0); 434 | mv.visitLineNumber(41, l0); 435 | mv.visitVarInsn(ALOAD, 0); 436 | mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); 437 | mv.visitInsn(DUP); 438 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "", "()V", false); 439 | mv.visitVarInsn(ALOAD, 1); 440 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 441 | mv.visitLdcInsn(".class"); 442 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); 443 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); 444 | mv.visitMethodInsn(INVOKEVIRTUAL, "me/javapacker/PackerClassLoader", "getClass", "(Ljava/lang/String;)[B", false); 445 | mv.visitVarInsn(ASTORE, 2); 446 | Label l1 = new Label(); 447 | mv.visitLabel(l1); 448 | mv.visitLineNumber(42, l1); 449 | mv.visitVarInsn(ALOAD, 2); 450 | Label l2 = new Label(); 451 | mv.visitJumpInsn(IFNULL, l2); 452 | Label l3 = new Label(); 453 | mv.visitLabel(l3); 454 | mv.visitLineNumber(43, l3); 455 | mv.visitVarInsn(ALOAD, 0); 456 | mv.visitVarInsn(ALOAD, 1); 457 | mv.visitVarInsn(ALOAD, 2); 458 | mv.visitInsn(ICONST_0); 459 | mv.visitVarInsn(ALOAD, 2); 460 | mv.visitInsn(ARRAYLENGTH); 461 | mv.visitLdcInsn(Type.getType("Lme/javapacker/Main;")); 462 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getProtectionDomain", "()Ljava/security/ProtectionDomain;", false); 463 | mv.visitMethodInsn(INVOKEVIRTUAL, "me/javapacker/PackerClassLoader", "defineClass", "(Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", false); 464 | mv.visitInsn(ARETURN); 465 | mv.visitLabel(l2); 466 | mv.visitLineNumber(45, l2); 467 | mv.visitFrame(Opcodes.F_APPEND,1, new Object[] {"[B"}, 0, null); 468 | mv.visitTypeInsn(NEW, "java/lang/ClassNotFoundException"); 469 | mv.visitInsn(DUP); 470 | mv.visitVarInsn(ALOAD, 1); 471 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ClassNotFoundException", "", "(Ljava/lang/String;)V", false); 472 | mv.visitInsn(ATHROW); 473 | Label l4 = new Label(); 474 | mv.visitLabel(l4); 475 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l0, l4, 0); 476 | mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l4, 1); 477 | mv.visitLocalVariable("data", "[B", null, l1, l4, 2); 478 | mv.visitMaxs(6, 3); 479 | mv.visitEnd(); 480 | } 481 | { 482 | mv = cw.visitMethod(ACC_PUBLIC, "loadResources", "(Ljava/util/jar/JarInputStream;)V", null, null); 483 | mv.visitCode(); 484 | Label l0 = new Label(); 485 | Label l1 = new Label(); 486 | Label l2 = new Label(); 487 | mv.visitTryCatchBlock(l0, l1, l2, "java/io/IOException"); 488 | Label l3 = new Label(); 489 | mv.visitLabel(l3); 490 | mv.visitLineNumber(50, l3); 491 | mv.visitIntInsn(SIPUSH, 1024); 492 | mv.visitIntInsn(NEWARRAY, T_BYTE); 493 | mv.visitVarInsn(ASTORE, 2); 494 | mv.visitLabel(l0); 495 | mv.visitLineNumber(54, l0); 496 | mv.visitInsn(ACONST_NULL); 497 | mv.visitVarInsn(ASTORE, 4); 498 | Label l4 = new Label(); 499 | mv.visitLabel(l4); 500 | mv.visitLineNumber(55, l4); 501 | mv.visitFrame(Opcodes.F_APPEND,3, new Object[] {"[B", Opcodes.TOP, "java/util/jar/JarEntry"}, 0, null); 502 | mv.visitVarInsn(ALOAD, 1); 503 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/jar/JarInputStream", "getNextJarEntry", "()Ljava/util/jar/JarEntry;", false); 504 | mv.visitInsn(DUP); 505 | mv.visitVarInsn(ASTORE, 4); 506 | mv.visitJumpInsn(IFNULL, l1); 507 | Label l5 = new Label(); 508 | mv.visitLabel(l5); 509 | mv.visitLineNumber(56, l5); 510 | mv.visitTypeInsn(NEW, "java/io/ByteArrayOutputStream"); 511 | mv.visitInsn(DUP); 512 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/ByteArrayOutputStream", "", "()V", false); 513 | mv.visitVarInsn(ASTORE, 5); 514 | Label l6 = new Label(); 515 | mv.visitLabel(l6); 516 | mv.visitLineNumber(57, l6); 517 | mv.visitFrame(Opcodes.F_APPEND,1, new Object[] {"java/io/ByteArrayOutputStream"}, 0, null); 518 | mv.visitVarInsn(ALOAD, 1); 519 | mv.visitVarInsn(ALOAD, 2); 520 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/jar/JarInputStream", "read", "([B)I", false); 521 | mv.visitInsn(DUP); 522 | mv.visitVarInsn(ISTORE, 3); 523 | Label l7 = new Label(); 524 | mv.visitLabel(l7); 525 | mv.visitInsn(ICONST_M1); 526 | Label l8 = new Label(); 527 | mv.visitJumpInsn(IF_ICMPEQ, l8); 528 | Label l9 = new Label(); 529 | mv.visitLabel(l9); 530 | mv.visitLineNumber(58, l9); 531 | mv.visitVarInsn(ALOAD, 5); 532 | mv.visitVarInsn(ALOAD, 2); 533 | mv.visitInsn(ICONST_0); 534 | mv.visitVarInsn(ILOAD, 3); 535 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "write", "([BII)V", false); 536 | mv.visitJumpInsn(GOTO, l6); 537 | mv.visitLabel(l8); 538 | mv.visitLineNumber(60, l8); 539 | mv.visitFrame(Opcodes.F_FULL, 6, new Object[] {"me/javapacker/PackerClassLoader", "java/util/jar/JarInputStream", "[B", Opcodes.INTEGER, "java/util/jar/JarEntry", "java/io/ByteArrayOutputStream"}, 0, new Object[] {}); 540 | mv.visitVarInsn(ALOAD, 5); 541 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "close", "()V", false); 542 | Label l10 = new Label(); 543 | mv.visitLabel(l10); 544 | mv.visitLineNumber(61, l10); 545 | mv.visitVarInsn(ALOAD, 5); 546 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/ByteArrayOutputStream", "toByteArray", "()[B", false); 547 | mv.visitVarInsn(ASTORE, 6); 548 | Label l11 = new Label(); 549 | mv.visitLabel(l11); 550 | mv.visitLineNumber(62, l11); 551 | mv.visitVarInsn(ALOAD, 4); 552 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/jar/JarEntry", "getName", "()Ljava/lang/String;", false); 553 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "toLowerCase", "()Ljava/lang/String;", false); 554 | mv.visitLdcInsn(".class"); 555 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "endsWith", "(Ljava/lang/String;)Z", false); 556 | Label l12 = new Label(); 557 | mv.visitJumpInsn(IFEQ, l12); 558 | Label l13 = new Label(); 559 | mv.visitLabel(l13); 560 | mv.visitLineNumber(63, l13); 561 | mv.visitVarInsn(ALOAD, 0); 562 | mv.visitFieldInsn(GETFIELD, "me/javapacker/PackerClassLoader", "classes", "Ljava/util/HashMap;"); 563 | mv.visitVarInsn(ALOAD, 4); 564 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/jar/JarEntry", "getName", "()Ljava/lang/String;", false); 565 | mv.visitLdcInsn("/"); 566 | mv.visitLdcInsn("."); 567 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "replaceAll", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false); 568 | mv.visitVarInsn(ALOAD, 6); 569 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false); 570 | mv.visitInsn(POP); 571 | mv.visitLabel(l12); 572 | mv.visitLineNumber(65, l12); 573 | mv.visitFrame(Opcodes.F_CHOP,1, null, 0, null); 574 | mv.visitJumpInsn(GOTO, l4); 575 | mv.visitLabel(l1); 576 | mv.visitLineNumber(68, l1); 577 | mv.visitFrame(Opcodes.F_CHOP,2, null, 0, null); 578 | Label l14 = new Label(); 579 | mv.visitJumpInsn(GOTO, l14); 580 | mv.visitLabel(l2); 581 | mv.visitLineNumber(66, l2); 582 | mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/io/IOException"}); 583 | mv.visitVarInsn(ASTORE, 4); 584 | Label l15 = new Label(); 585 | mv.visitLabel(l15); 586 | mv.visitLineNumber(67, l15); 587 | mv.visitVarInsn(ALOAD, 4); 588 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "printStackTrace", "()V", false); 589 | mv.visitLabel(l14); 590 | mv.visitLineNumber(69, l14); 591 | mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); 592 | mv.visitInsn(RETURN); 593 | Label l16 = new Label(); 594 | mv.visitLabel(l16); 595 | mv.visitLocalVariable("out", "Ljava/io/ByteArrayOutputStream;", null, l6, l12, 5); 596 | mv.visitLocalVariable("array", "[B", null, l11, l12, 6); 597 | mv.visitLocalVariable("count", "I", null, l7, l1, 3); 598 | mv.visitLocalVariable("entry", "Ljava/util/jar/JarEntry;", null, l4, l1, 4); 599 | mv.visitLocalVariable("e", "Ljava/io/IOException;", null, l15, l14, 4); 600 | mv.visitLocalVariable("this", "Lme/javapacker/PackerClassLoader;", null, l3, l16, 0); 601 | mv.visitLocalVariable("stream", "Ljava/util/jar/JarInputStream;", null, l3, l16, 1); 602 | mv.visitLocalVariable("buffer", "[B", null, l0, l16, 2); 603 | mv.visitMaxs(4, 7); 604 | mv.visitEnd(); 605 | } 606 | { 607 | mv = cw.visitMethod(ACC_PUBLIC, "getClass", "(Ljava/lang/String;)[B", null, null); 608 | mv.visitCode(); 609 | Label l0 = new Label(); 610 | mv.visitLabel(l0); 611 | mv.visitLineNumber(72, l0); 612 | mv.visitVarInsn(ALOAD, 0); 613 | mv.visitFieldInsn(GETFIELD, "me/javapacker/PackerClassLoader", "classes", "Ljava/util/HashMap;"); 614 | mv.visitVarInsn(ALOAD, 1); 615 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false); 616 | mv.visitTypeInsn(CHECKCAST, "[B"); 617 | mv.visitVarInsn(ASTORE, 2); 618 | Label l1 = new Label(); 619 | mv.visitLabel(l1); 620 | mv.visitLineNumber(73, l1); 621 | mv.visitVarInsn(ALOAD, 0); 622 | mv.visitFieldInsn(GETFIELD, "me/javapacker/PackerClassLoader", "classes", "Ljava/util/HashMap;"); 623 | mv.visitVarInsn(ALOAD, 1); 624 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "remove", "(Ljava/lang/Object;)Ljava/lang/Object;", false); 625 | mv.visitInsn(POP); 626 | Label l2 = new Label(); 627 | mv.visitLabel(l2); 628 | mv.visitLineNumber(74, l2); 629 | mv.visitVarInsn(ALOAD, 2); 630 | mv.visitInsn(ARETURN); 631 | Label l3 = new Label(); 632 | mv.visitLabel(l3); 633 | mv.visitMaxs(2, 3); 634 | mv.visitEnd(); 635 | } 636 | cw.visitEnd(); 637 | 638 | return cw.toByteArray(); 639 | } 640 | 641 | 642 | public byte[] mainDump() { 643 | 644 | ClassWriter cw = new ClassWriter(0); 645 | MethodVisitor mv; 646 | 647 | cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "me/javapacker/Main", null, "java/lang/Object", null); 648 | 649 | { 650 | mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); 651 | mv.visitCode(); 652 | Label l0 = new Label(); 653 | mv.visitLabel(l0); 654 | mv.visitLineNumber(17, l0); 655 | mv.visitVarInsn(ALOAD, 0); 656 | mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); 657 | mv.visitInsn(RETURN); 658 | Label l1 = new Label(); 659 | mv.visitLabel(l1); 660 | mv.visitMaxs(1, 1); 661 | mv.visitEnd(); 662 | } 663 | { 664 | mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, new String[] { "java/lang/Exception" }); 665 | mv.visitCode(); 666 | Label l0 = new Label(); 667 | mv.visitLabel(l0); 668 | mv.visitLineNumber(20, l0); 669 | mv.visitTypeInsn(NEW, "java/util/zip/ZipFile"); 670 | mv.visitInsn(DUP); 671 | mv.visitLdcInsn(Type.getType("Lme/javapacker/Main;")); 672 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getProtectionDomain", "()Ljava/security/ProtectionDomain;", false); 673 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/security/ProtectionDomain", "getCodeSource", "()Ljava/security/CodeSource;", false); 674 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/security/CodeSource", "getLocation", "()Ljava/net/URL;", false); 675 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/net/URL", "getPath", "()Ljava/lang/String;", false); 676 | mv.visitMethodInsn(INVOKESPECIAL, "java/util/zip/ZipFile", "", "(Ljava/lang/String;)V", false); 677 | mv.visitVarInsn(ASTORE, 1); 678 | Label l1 = new Label(); 679 | mv.visitLabel(l1); 680 | mv.visitLineNumber(21, l1); 681 | mv.visitVarInsn(ALOAD, 1); 682 | mv.visitLdcInsn(getPackerFilesManager().getEncryptable().getEncryptableConfig()); 683 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/zip/ZipFile", "getEntry", "(Ljava/lang/String;)Ljava/util/zip/ZipEntry;", false); 684 | mv.visitVarInsn(ASTORE, 2); 685 | Label l2 = new Label(); 686 | mv.visitLabel(l2); 687 | mv.visitLineNumber(22, l2); 688 | mv.visitVarInsn(ALOAD, 1); 689 | mv.visitVarInsn(ALOAD, 2); 690 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/zip/ZipFile", "getInputStream", "(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;", false); 691 | mv.visitVarInsn(ASTORE, 3); 692 | Label l3 = new Label(); 693 | mv.visitLabel(l3); 694 | mv.visitLineNumber(23, l3); 695 | mv.visitVarInsn(ALOAD, 3); 696 | mv.visitMethodInsn(INVOKESTATIC, "me/javapacker/Util", "readAllBytes", "(Ljava/io/InputStream;)[B", false); 697 | mv.visitVarInsn(ASTORE, 4); 698 | Label l4 = new Label(); 699 | mv.visitLabel(l4); 700 | mv.visitLineNumber(24, l4); 701 | mv.visitTypeInsn(NEW, "java/io/ByteArrayInputStream"); 702 | mv.visitInsn(DUP); 703 | mv.visitVarInsn(ALOAD, 4); 704 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/ByteArrayInputStream", "", "([B)V", false); 705 | mv.visitVarInsn(ASTORE, 5); 706 | Label l5 = new Label(); 707 | mv.visitLabel(l5); 708 | mv.visitLineNumber(25, l5); 709 | mv.visitTypeInsn(NEW, "java/io/DataInputStream"); 710 | mv.visitInsn(DUP); 711 | mv.visitVarInsn(ALOAD, 5); 712 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/DataInputStream", "", "(Ljava/io/InputStream;)V", false); 713 | mv.visitVarInsn(ASTORE, 6); 714 | Label l6 = new Label(); 715 | mv.visitLabel(l6); 716 | mv.visitLineNumber(26, l6); 717 | mv.visitVarInsn(ALOAD, 6); 718 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/DataInputStream", "readUTF", "()Ljava/lang/String;", false); 719 | mv.visitVarInsn(ASTORE, 7); 720 | Label l8 = new Label(); 721 | mv.visitLabel(l8); 722 | mv.visitLineNumber(28, l8); 723 | mv.visitVarInsn(ALOAD, 6); 724 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/DataInputStream", "readUTF", "()Ljava/lang/String;", false); 725 | mv.visitVarInsn(ASTORE, 8); 726 | Label l10 = new Label(); 727 | mv.visitLabel(l10); 728 | mv.visitLineNumber(30, l10); 729 | mv.visitLdcInsn(Type.getType("Lme/javapacker/Main;")); 730 | mv.visitLdcInsn("/" + getPackerFilesManager().getEncryptable().getEncryptableFile()); 731 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getResourceAsStream", "(Ljava/lang/String;)Ljava/io/InputStream;", false); 732 | mv.visitVarInsn(ASTORE, 9); 733 | Label l11 = new Label(); 734 | mv.visitLabel(l11); 735 | mv.visitLineNumber(31, l11); 736 | mv.visitLdcInsn("AES/CBC/NOPADDING"); 737 | mv.visitMethodInsn(INVOKESTATIC, "javax/crypto/Cipher", "getInstance", "(Ljava/lang/String;)Ljavax/crypto/Cipher;", false); 738 | mv.visitVarInsn(ASTORE, 10); 739 | Label l12 = new Label(); 740 | mv.visitLabel(l12); 741 | mv.visitLineNumber(32, l12); 742 | mv.visitTypeInsn(NEW, "javax/crypto/spec/SecretKeySpec"); 743 | mv.visitInsn(DUP); 744 | mv.visitVarInsn(ALOAD, 8); 745 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "getBytes", "()[B", false); 746 | mv.visitLdcInsn("AES"); 747 | mv.visitMethodInsn(INVOKESPECIAL, "javax/crypto/spec/SecretKeySpec", "", "([BLjava/lang/String;)V", false); 748 | mv.visitVarInsn(ASTORE, 11); 749 | Label l13 = new Label(); 750 | mv.visitLabel(l13); 751 | mv.visitLineNumber(33, l13); 752 | mv.visitVarInsn(ALOAD, 10); 753 | mv.visitInsn(ICONST_2); 754 | mv.visitVarInsn(ALOAD, 11); 755 | mv.visitTypeInsn(NEW, "javax/crypto/spec/IvParameterSpec"); 756 | mv.visitInsn(DUP); 757 | mv.visitVarInsn(ALOAD, 8); 758 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "getBytes", "()[B", false); 759 | mv.visitMethodInsn(INVOKESPECIAL, "javax/crypto/spec/IvParameterSpec", "", "([B)V", false); 760 | mv.visitMethodInsn(INVOKEVIRTUAL, "javax/crypto/Cipher", "init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V", false); 761 | Label l14 = new Label(); 762 | mv.visitLabel(l14); 763 | mv.visitLineNumber(34, l14); 764 | mv.visitTypeInsn(NEW, "java/util/jar/JarInputStream"); 765 | mv.visitInsn(DUP); 766 | mv.visitTypeInsn(NEW, "javax/crypto/CipherInputStream"); 767 | mv.visitInsn(DUP); 768 | mv.visitVarInsn(ALOAD, 9); 769 | mv.visitVarInsn(ALOAD, 10); 770 | mv.visitMethodInsn(INVOKESPECIAL, "javax/crypto/CipherInputStream", "", "(Ljava/io/InputStream;Ljavax/crypto/Cipher;)V", false); 771 | mv.visitMethodInsn(INVOKESPECIAL, "java/util/jar/JarInputStream", "", "(Ljava/io/InputStream;)V", false); 772 | mv.visitVarInsn(ASTORE, 12); 773 | Label l15 = new Label(); 774 | mv.visitLabel(l15); 775 | mv.visitLineNumber(35, l15); 776 | mv.visitTypeInsn(NEW, "me/javapacker/PackerClassLoader"); 777 | mv.visitInsn(DUP); 778 | mv.visitLdcInsn(Type.getType("Lme/javapacker/Main;")); 779 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", "()Ljava/lang/ClassLoader;", false); 780 | mv.visitVarInsn(ALOAD, 12); 781 | mv.visitMethodInsn(INVOKESPECIAL, "me/javapacker/PackerClassLoader", "", "(Ljava/lang/ClassLoader;Ljava/util/jar/JarInputStream;)V", false); 782 | mv.visitVarInsn(ASTORE, 13); 783 | Label l16 = new Label(); 784 | mv.visitLabel(l16); 785 | mv.visitLineNumber(37, l16); 786 | mv.visitVarInsn(ALOAD, 13); 787 | mv.visitVarInsn(ALOAD, 7); 788 | mv.visitMethodInsn(INVOKEVIRTUAL, "me/javapacker/PackerClassLoader", "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;", false); 789 | mv.visitVarInsn(ASTORE, 14); 790 | Label l17 = new Label(); 791 | mv.visitLabel(l17); 792 | mv.visitLineNumber(38, l17); 793 | mv.visitVarInsn(ALOAD, 14); 794 | mv.visitLdcInsn("main"); 795 | mv.visitInsn(ICONST_1); 796 | mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); 797 | mv.visitInsn(DUP); 798 | mv.visitInsn(ICONST_0); 799 | mv.visitLdcInsn(Type.getType("[Ljava/lang/String;")); 800 | mv.visitInsn(AASTORE); 801 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false); 802 | mv.visitVarInsn(ASTORE, 15); 803 | Label l18 = new Label(); 804 | mv.visitLabel(l18); 805 | mv.visitLineNumber(40, l18); 806 | mv.visitVarInsn(ALOAD, 15); 807 | mv.visitVarInsn(ALOAD, 14); 808 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "newInstance", "()Ljava/lang/Object;", false); 809 | mv.visitInsn(ICONST_1); 810 | mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); 811 | mv.visitInsn(DUP); 812 | mv.visitInsn(ICONST_0); 813 | mv.visitVarInsn(ALOAD, 0); 814 | mv.visitInsn(AASTORE); 815 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false); 816 | mv.visitInsn(POP); 817 | Label l19 = new Label(); 818 | mv.visitLabel(l19); 819 | mv.visitLineNumber(42, l19); 820 | mv.visitVarInsn(ALOAD, 12); 821 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/jar/JarInputStream", "close", "()V", false); 822 | Label l20 = new Label(); 823 | mv.visitLabel(l20); 824 | mv.visitLineNumber(43, l20); 825 | mv.visitInsn(RETURN); 826 | Label l21 = new Label(); 827 | mv.visitLabel(l21); 828 | mv.visitMaxs(6, 16); 829 | mv.visitEnd(); 830 | } 831 | cw.visitEnd(); 832 | 833 | return cw.toByteArray(); 834 | } 835 | 836 | 837 | } 838 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/steps/impl/S06AttachManifest.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.steps.impl; 2 | 3 | import me.javapacker.file.api.PackerFilesManager; 4 | import me.javapacker.steps.api.PackerStep; 5 | import org.apache.commons.io.IOUtils; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.net.URL; 11 | import java.util.logging.Level; 12 | import java.util.zip.ZipEntry; 13 | import java.util.zip.ZipOutputStream; 14 | 15 | public class S06AttachManifest extends PackerStep { 16 | 17 | public S06AttachManifest(PackerFilesManager packerFilesManager) { 18 | super(packerFilesManager); 19 | } 20 | 21 | @Override 22 | public boolean completeStep() { 23 | final ZipOutputStream out = getPackerFilesManager().asZipOutputStream(); 24 | try { 25 | URL resource = getClass().getClassLoader().getResource("MANIFEST.MF"); 26 | if (resource == null) { 27 | logMessage(Level.WARNING, "MANIFEST.MF not found!"); 28 | return false; 29 | } else { 30 | 31 | final File manifest = new File(resource.toURI()); 32 | ZipEntry entry = new ZipEntry("META-INF/" + manifest.getName()); 33 | out.putNextEntry(entry); 34 | out.write(IOUtils.toByteArray(new FileInputStream(manifest))); 35 | out.closeEntry(); 36 | } 37 | 38 | out.close(); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | return false; 42 | } 43 | logMessage(Level.INFO, "S06AttachManifest completed!"); 44 | return checkNext(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/utils/JarUtil.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.utils; 2 | 3 | import java.io.File; 4 | 5 | public class JarUtil { 6 | 7 | public static File getCurrentFile() 8 | { 9 | return new File(JarUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace("file:", "")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/me/javapacker/utils/RandomUtil.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.utils; 2 | 3 | 4 | import java.util.Random; 5 | 6 | public class RandomUtil { 7 | 8 | private final static Random r = new Random(); 9 | 10 | public static int fromRange(int rangeNumber){ 11 | Random rand = new Random(); 12 | int randomNum = rand.nextInt((rangeNumber - 1) + 1) + 1; 13 | return randomNum; 14 | } 15 | 16 | public static int fromRange(int min, int max) { 17 | 18 | if (min >= max) { 19 | throw new IllegalArgumentException("max must be greater than min"); 20 | } 21 | 22 | return r.nextInt((max - min) + 1) + min; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/me/javapacker/utils/StringUtil.java: -------------------------------------------------------------------------------- 1 | package me.javapacker.utils; 2 | 3 | import me.javapacker.config.PackerConfiguration; 4 | 5 | import java.util.HashSet; 6 | import java.util.Random; 7 | import java.util.Set; 8 | 9 | public class StringUtil { 10 | 11 | private final static String fileExtension = ".javapacker"; 12 | private final static Set usedNames = new HashSet<>(); 13 | 14 | public static String randomPackerName(int length){ 15 | StringBuilder s = new StringBuilder(); 16 | for(int i=0; i