Skip to content

Commit

Permalink
Fix opening legacy files from the pre-open-source era
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian committed Feb 5, 2024
1 parent dd6e0b2 commit 6e54106
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0 (2024-02-05)
### Fixed
- Ability to open files from old JDigitalSimulator versions (before open-sourcing, version < 1.*), see the README.md instructions

## 2.2.0 (2022-06-18)
### Added
- US / ANSI style gate symbols and option to switch in the menu, thanks to Sett17
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ JDigitalSimulator is a platform independent open source Electronic Design Automa

Please download the latest release from the [releases section](https://github.com/kristian/JDigitalSimulator/releases/latest) here on GitHub. Visit the [project homepage](http://kra.lc/projects/jdigitalsimulator/) for some additional information.

Run
---

To run JDigitalSimulator download the JAR file and run it with:
```
java -jar jds-2.x.x.jar
```
Note that if you are using a latest Java version (such as Java 21), it will require you to use a `--add-opens java.base/java.io=ALL-UNNAMED` to the command, in order to be able to open legacy files from JDigitalSimulator version > 1.*.

Build
-----

To build `JDigitalSimulator` on your machine, checkout the repository, `cd` into it, and call:
To build JDigitalSimulator on your machine, checkout the repository, `cd` into it, and call:
```
mvn clean install
```
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>lc.kra.jds</groupId>
<artifactId>jds</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>

<name>JDigitalSimulator</name>
<url>http://kra.lc/projects/jdigitalsimulator/</url>
Expand Down Expand Up @@ -99,6 +99,7 @@
<jdkPreference>preferJre</jdkPreference>
<opts>
<opt>-Xss4m</opt>
<opt>--add-opens java.base/java.io=ALL-UNNAMED</opt>
</opts>
</jre>
<versionInfo>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/lc/kra/jds/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ public final static Simulation readSimulation(InputStream in, String password) t
objectData = objectIn.readObject();
} finally { objectIn.close(); }
} catch(StreamCorruptedException e) { //cypher required or corrupted input
e.printStackTrace();
if(password==null||password.isEmpty())
throw new PasswordRequiredException();
ObjectInputStream objectIn = new LegacyObjectInputStream(new CipherInputStream(in, Utilities.createCipher(Utilities.computeHash(password), Cipher.DECRYPT_MODE)));
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/lc/kra/jds/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,29 @@ public AlternateClassLoaderObjectInputStream(InputStream in, ClassLoader alterna
public static class LegacyObjectInputStream extends AlternateClassLoaderObjectInputStream {
public static final String LEGACY_PACKAGE_PREFIX = "de.ksquared.", PACKAGE_PREFIX = "lc.kra.";
public LegacyObjectInputStream(InputStream in) throws IOException {
super(in, getSimpleClassLoader()); }
super(in, getSimpleClassLoader());
}
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
ObjectStreamClass descriptor = super.readClassDescriptor(); String name = descriptor.getName();
if(name.contains(LEGACY_PACKAGE_PREFIX)) descriptor = ObjectStreamClass.lookup(Class.forName(replaceLegacyPackage(name), false, alternateClassLoader));
if(name.contains(LEGACY_PACKAGE_PREFIX)) {
String newName = replaceLegacyPackage(name);
try {
// Do not return a new ObjectStreamClass looked up from new class definitions, but modify the descriptor read from the stream.
// Otherwise some flags could be wrong, like the flag "hasWriteObjectData" when reading objects from 7.6/7.7.
Field nameField = ObjectStreamClass.class.getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(descriptor, newName);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
return descriptor;
}
@Override
protected Object resolveObject(Object obj) throws IOException {
// TODO Auto-generated method stub
return super.resolveObject(obj);
}
public static String replaceLegacyPackage(String name) {
return name.replaceFirst("^(\\[L)?"+Pattern.quote(LEGACY_PACKAGE_PREFIX), "$1"+Matcher.quoteReplacement(PACKAGE_PREFIX));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/lc/kra/jds/gui/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@
/**
* JDigitalSimulator
* @author Kristian Kraljic
* @version 2.2.0
* @version 2.3.0
*/
public class Application extends JFrame {
private static final long serialVersionUID = -4693271310855486553L;

public static final String FILE_EXTENSION = "jdsim";
public static File pluginDirectory, currentDirectory;

private static final String VERSION = "2.2.0", COPYRIGHT = "2010-2022", LINES_OF_CODE = "9.509", WORDS_OF_CODE = "36.133", PAGES_OF_CODE = "245";
private static final String VERSION = "2.3.0", COPYRIGHT = "2010-2024", LINES_OF_CODE = "9.509", WORDS_OF_CODE = "36.133", PAGES_OF_CODE = "245";

private static final String[]
TOOLBAR_FRAME_FOCUS = new String[]{"save", "print", "print_level", "simulate", "left", "right", "up", "down", "grid", "secure", "zoom_default", "zoom", "zoom_in", "zoom_out"},
Expand Down

0 comments on commit 6e54106

Please sign in to comment.