Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>GraxCode</groupId>
<artifactId>JByteMod</artifactId>
<version>1.8.0</version>
<version>1.8.3</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/grax/jbytemod/utils/task/LoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void readJar(JarFile jar, JarEntry en, Map<String, ClassNode> classes, M
try {
final ClassNode cn = ASMUtils.getNode(bytes);
if (cn != null) { // && (cn.name.equals("java/lang/Object") ? true : cn.superName != null)
cn.innerPath = en.getName();
classes.put(cn.name, cn);
}
} catch (Exception e) {
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/me/grax/jbytemod/utils/task/SaveTask.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package me.grax.jbytemod.utils.task;

import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;

import javax.swing.SwingWorker;

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;

import me.grax.jbytemod.JByteMod;
import me.grax.jbytemod.JarArchive;
import me.grax.jbytemod.ui.PageEndPanel;
import me.lpk.util.JarUtils;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;

import javax.swing.*;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;

public class SaveTask extends SwingWorker<Void, Integer> {

Expand Down Expand Up @@ -53,12 +51,17 @@ protected Void doInBackground() throws Exception {
ClassNode node = classes.get(s);
ClassWriter writer = new ClassWriter(flags);
node.accept(writer);
outputBytes.put(s + ".class", writer.toByteArray());
publish((int) ((i++ / size) * 50d));
String name;
if (node.innerPath != null && !node.innerPath.isEmpty()) {
name = node.innerPath;
} else {
name = s + ".class";
}
outputBytes.put(name, writer.toByteArray());
publish((int) ((i++ / size) * 20d));
}
publish(50);
JByteMod.LOGGER.log("Saving..");
JarUtils.saveAsJar(outputBytes, output.getAbsolutePath());
JarUtils.saveAsJar(outputBytes, output.getAbsolutePath(), process -> publish((int) (20d + process*80d)));
JByteMod.LOGGER.log("Saving successful!");
} catch (Exception e) {
e.printStackTrace();
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/me/lpk/util/JarUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.lpk.util;

import org.apache.commons.io.IOUtils;
import org.objectweb.asm.tree.ClassNode;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -8,16 +11,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.commons.io.IOUtils;
import org.objectweb.asm.tree.ClassNode;

public class JarUtils {
/**
* Creates a map of <String(Class name), ClassNode> for a given jar file
Expand Down Expand Up @@ -125,13 +127,34 @@ public static Map<String, byte[]> loadNonClassEntries(File jarFile) throws IOExc
* @param fileName
*/
public static void saveAsJar(Map<String, byte[]> outBytes, String fileName) {
saveAsJar(outBytes, fileName, null);
}
public static void saveAsJar(Map<String, byte[]> outBytes, String fileName, Consumer<Double> progress) {
try {
JarOutputStream out = new JarOutputStream(new java.io.FileOutputStream(fileName));
double i = 1;
double size = outBytes.size();
for (String entry : outBytes.keySet()) {
out.putNextEntry(new ZipEntry(entry));
if (!entry.endsWith("/"))
JarEntry jarEntry = new JarEntry(entry);

if (entry.endsWith("/")) {
out.putNextEntry(jarEntry);
} else {
byte[] content = outBytes.get(entry);
if (entry.endsWith(".jar")) {
jarEntry.setMethod(JarEntry.STORED);
jarEntry.setSize(content.length);
jarEntry.setCompressedSize(content.length);
CRC32 crc32 = new CRC32();
crc32.update(content);
jarEntry.setCrc(crc32.getValue());
}
out.putNextEntry(jarEntry);
out.write(outBytes.get(entry));
}
out.closeEntry();
if (progress != null)
progress.accept(i++/size);
}
out.close();
} catch (IOException e) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/me/lpk/util/drop/JarDropHandler.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package me.lpk.util.drop;

import javax.swing.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.util.List;

import javax.swing.TransferHandler;

public class JarDropHandler extends TransferHandler {
private static final long serialVersionUID = 1232L;
private final IDropUser user;
Expand Down Expand Up @@ -37,10 +36,7 @@ public boolean importData(TransferHandler.TransferSupport info) {
}
user.preLoadJars(id);
for (File jar : data) {
if (jar.getName().toLowerCase().endsWith(".jar")) {
user.onJarLoad(id, jar);
break;
}
user.onJarLoad(id, jar);
}
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/objectweb/asm/tree/ClassNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class ClassNode extends ClassVisitor {
*/
public String name;

/**
* The internal path of the jar file.
*/
public String innerPath;

/**
* The signature of the class. May be <tt>null</tt>.
*/
Expand Down