Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled Java plugins do not work #405

Closed
Sculas opened this issue Mar 22, 2022 · 2 comments · Fixed by #406
Closed

Compiled Java plugins do not work #405

Sculas opened this issue Mar 22, 2022 · 2 comments · Fixed by #406

Comments

@Sculas
Copy link
Contributor

Sculas commented Mar 22, 2022

Gradle compiled plugin results in:

java.lang.IllegalArgumentException: MALFORMED
        at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
        at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:300)
        at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:122)
        at the.bytecode.club.bytecodeviewer.plugin.strategies.CompiledJavaPluginLaunchStrategy.loadData(CompiledJavaPluginLaunchStrategy.java:83)

Using any archiving program to add classes into ZIP/JAR:
same result as Gradle

Using javac and jar to compile Template.java to a JAR:

java.io.EOFException
	at java.util.zip.ZipInputStream.readFully(ZipInputStream.java:405)
	at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:296)
	at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:122)
	at the.bytecode.club.bytecodeviewer.plugin.strategies.CompiledJavaPluginLaunchStrategy.loadData(CompiledJavaPluginLaunchStrategy.java:83)

Loading the plain Template.java file:
Works! (different loader strategy: JavaPluginLaunchStrategy)

TLDR: CompiledJavaPluginLaunchStrategy is broken.

@Sculas
Copy link
Contributor Author

Sculas commented Mar 22, 2022

I've found the issue. The class PluginWriter writes the bytes as ASCII strings to the textarea:

area.setText(DiskReader.loadAsString(file.getAbsolutePath()));

This is fine and all, but what it then does is not. It loads the ASCII string and copies it to a file (after which it tries to load it as a plugin):

//write to temporary file location
DiskWriter.replaceFile(tempFile.getAbsolutePath(), area.getText(), false);
//run plugin from that location
PluginManager.runPlugin(tempFile);

This only works for source files that are ASCII. Converting binary (ZIP, JAR, etc.) files to strings will corrupt it, that is self-explanatory.
I've fixed this myself locally by changing it to this:

- DiskWriter.replaceFile(tempFile.getAbsolutePath(), area.getText(), false); 
+ Files.copy(savePath, tempFile);

I used savePath because this function sets the file to savePath.
You can also just make the file variable a class variable, that's better probably.


area.setText(DiskReader.loadAsString(file.getAbsolutePath()));
area.setCaretPosition(0);
}
catch (Exception e)
{
e.printStackTrace();
}
setSourceFile(file);

public void setSourceFile(File file)
{
menuSaveAs.setVisible(false);
menuSave.setVisible(true);
menuSaveAs.updateUI();
menuSave.updateUI();
savePath = file;

@Sculas
Copy link
Contributor Author

Sculas commented Mar 22, 2022

One more solution is to convert the bytes to base64 and then set the base64 string to the textarea.
I just tested this and even this doesn't work. Just don't use textarea's for this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant