summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert
diff options
context:
space:
mode:
authorGravatar Thog2016-09-13 11:35:52 +0200
committerGravatar Thog2016-09-13 11:38:05 +0200
commitfc530f49fdbf773c497e3714c1f8e7c79020e0a3 (patch)
tree7bb063e608295d6c7885b3d5fb0aace3f7fefec7 /src/main/java/cuchaz/enigma/convert
parentfix method/argument renaming edge cases, add method/argument name rebuilder, ... (diff)
downloadenigma-fork-fc530f49fdbf773c497e3714c1f8e7c79020e0a3.tar.gz
enigma-fork-fc530f49fdbf773c497e3714c1f8e7c79020e0a3.tar.xz
enigma-fork-fc530f49fdbf773c497e3714c1f8e7c79020e0a3.zip
Make sure to use UTF-8 in any case for I/O, change "Mark as deobfuscated" key and clean up
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassIdentity.java18
-rw-r--r--src/main/java/cuchaz/enigma/convert/MatchesReader.java10
-rw-r--r--src/main/java/cuchaz/enigma/convert/MatchesWriter.java23
3 files changed, 24 insertions, 27 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
index 57cbc06..0960c86 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
@@ -273,20 +273,20 @@ public class ClassIdentity {
273 // update the hash with the opcode 273 // update the hash with the opcode
274 int opcode = iter.byteAt(pos); 274 int opcode = iter.byteAt(pos);
275 digest.update((byte) opcode); 275 digest.update((byte) opcode);
276 276 int constIndex;
277 switch (opcode) { 277 switch (opcode) {
278 case Opcode.LDC: { 278 case Opcode.LDC:
279 int constIndex = iter.byteAt(pos + 1); 279 constIndex = iter.byteAt(pos + 1);
280 updateHashWithConstant(digest, constants, constIndex); 280 updateHashWithConstant(digest, constants, constIndex);
281 } 281 break;
282 break;
283 282
284 case Opcode.LDC_W: 283 case Opcode.LDC_W:
285 case Opcode.LDC2_W: { 284 case Opcode.LDC2_W:
286 int constIndex = (iter.byteAt(pos + 1) << 8) | iter.byteAt(pos + 2); 285 constIndex = (iter.byteAt(pos + 1) << 8) | iter.byteAt(pos + 2);
287 updateHashWithConstant(digest, constants, constIndex); 286 updateHashWithConstant(digest, constants, constIndex);
288 } 287 break;
289 break; 288 default:
289 break;
290 } 290 }
291 } 291 }
292 292
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesReader.java b/src/main/java/cuchaz/enigma/convert/MatchesReader.java
index ee5e482..550da49 100644
--- a/src/main/java/cuchaz/enigma/convert/MatchesReader.java
+++ b/src/main/java/cuchaz/enigma/convert/MatchesReader.java
@@ -12,10 +12,8 @@ package cuchaz.enigma.convert;
12 12
13import com.google.common.collect.Lists; 13import com.google.common.collect.Lists;
14 14
15import java.io.BufferedReader; 15import java.io.*;
16import java.io.File; 16import java.nio.charset.Charset;
17import java.io.FileReader;
18import java.io.IOException;
19import java.util.Collection; 17import java.util.Collection;
20import java.util.List; 18import java.util.List;
21 19
@@ -26,7 +24,7 @@ public class MatchesReader {
26 24
27 public static ClassMatches readClasses(File file) 25 public static ClassMatches readClasses(File file)
28 throws IOException { 26 throws IOException {
29 try (BufferedReader in = new BufferedReader(new FileReader(file))) { 27 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
30 ClassMatches matches = new ClassMatches(); 28 ClassMatches matches = new ClassMatches();
31 String line; 29 String line;
32 while ((line = in.readLine()) != null) { 30 while ((line = in.readLine()) != null) {
@@ -55,7 +53,7 @@ public class MatchesReader {
55 53
56 public static <T extends Entry> MemberMatches<T> readMembers(File file) 54 public static <T extends Entry> MemberMatches<T> readMembers(File file)
57 throws IOException { 55 throws IOException {
58 try (BufferedReader in = new BufferedReader(new FileReader(file))) { 56 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
59 MemberMatches<T> matches = new MemberMatches<T>(); 57 MemberMatches<T> matches = new MemberMatches<T>();
60 String line; 58 String line;
61 while ((line = in.readLine()) != null) { 59 while ((line = in.readLine()) != null) {
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java b/src/main/java/cuchaz/enigma/convert/MatchesWriter.java
index baf7929..dccbf6f 100644
--- a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java
+++ b/src/main/java/cuchaz/enigma/convert/MatchesWriter.java
@@ -10,9 +10,8 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.convert; 11package cuchaz.enigma.convert;
12 12
13import java.io.File; 13import java.io.*;
14import java.io.FileWriter; 14import java.nio.charset.Charset;
15import java.io.IOException;
16import java.util.Map; 15import java.util.Map;
17 16
18import cuchaz.enigma.mapping.BehaviorEntry; 17import cuchaz.enigma.mapping.BehaviorEntry;
@@ -25,14 +24,14 @@ public class MatchesWriter {
25 24
26 public static void writeClasses(ClassMatches matches, File file) 25 public static void writeClasses(ClassMatches matches, File file)
27 throws IOException { 26 throws IOException {
28 try (FileWriter out = new FileWriter(file)) { 27 try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) {
29 for (ClassMatch match : matches) { 28 for (ClassMatch match : matches) {
30 writeClassMatch(out, match); 29 writeClassMatch(out, match);
31 } 30 }
32 } 31 }
33 } 32 }
34 33
35 private static void writeClassMatch(FileWriter out, ClassMatch match) 34 private static void writeClassMatch(OutputStreamWriter out, ClassMatch match)
36 throws IOException { 35 throws IOException {
37 writeClasses(out, match.sourceClasses); 36 writeClasses(out, match.sourceClasses);
38 out.write(":"); 37 out.write(":");
@@ -40,7 +39,7 @@ public class MatchesWriter {
40 out.write("\n"); 39 out.write("\n");
41 } 40 }
42 41
43 private static void writeClasses(FileWriter out, Iterable<ClassEntry> classes) 42 private static void writeClasses(OutputStreamWriter out, Iterable<ClassEntry> classes)
44 throws IOException { 43 throws IOException {
45 boolean isFirst = true; 44 boolean isFirst = true;
46 for (ClassEntry entry : classes) { 45 for (ClassEntry entry : classes) {
@@ -55,7 +54,7 @@ public class MatchesWriter {
55 54
56 public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file) 55 public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file)
57 throws IOException { 56 throws IOException {
58 try (FileWriter out = new FileWriter(file)) { 57 try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) {
59 for (Map.Entry<T, T> match : matches.matches().entrySet()) { 58 for (Map.Entry<T, T> match : matches.matches().entrySet()) {
60 writeMemberMatch(out, match.getKey(), match.getValue()); 59 writeMemberMatch(out, match.getKey(), match.getValue());
61 } 60 }
@@ -71,7 +70,7 @@ public class MatchesWriter {
71 } 70 }
72 } 71 }
73 72
74 private static <T extends Entry> void writeMemberMatch(FileWriter out, T source, T dest) 73 private static <T extends Entry> void writeMemberMatch(OutputStreamWriter out, T source, T dest)
75 throws IOException { 74 throws IOException {
76 if (source != null) { 75 if (source != null) {
77 writeEntry(out, source); 76 writeEntry(out, source);
@@ -83,14 +82,14 @@ public class MatchesWriter {
83 out.write("\n"); 82 out.write("\n");
84 } 83 }
85 84
86 private static <T extends Entry> void writeUnmatchableEntry(FileWriter out, T entry) 85 private static <T extends Entry> void writeUnmatchableEntry(OutputStreamWriter out, T entry)
87 throws IOException { 86 throws IOException {
88 out.write("!"); 87 out.write("!");
89 writeEntry(out, entry); 88 writeEntry(out, entry);
90 out.write("\n"); 89 out.write("\n");
91 } 90 }
92 91
93 private static <T extends Entry> void writeEntry(FileWriter out, T entry) 92 private static <T extends Entry> void writeEntry(OutputStreamWriter out, T entry)
94 throws IOException { 93 throws IOException {
95 if (entry instanceof FieldEntry) { 94 if (entry instanceof FieldEntry) {
96 writeField(out, (FieldEntry) entry); 95 writeField(out, (FieldEntry) entry);
@@ -99,7 +98,7 @@ public class MatchesWriter {
99 } 98 }
100 } 99 }
101 100
102 private static void writeField(FileWriter out, FieldEntry fieldEntry) 101 private static void writeField(OutputStreamWriter out, FieldEntry fieldEntry)
103 throws IOException { 102 throws IOException {
104 out.write(fieldEntry.getClassName()); 103 out.write(fieldEntry.getClassName());
105 out.write(" "); 104 out.write(" ");
@@ -108,7 +107,7 @@ public class MatchesWriter {
108 out.write(fieldEntry.getType().toString()); 107 out.write(fieldEntry.getType().toString());
109 } 108 }
110 109
111 private static void writeBehavior(FileWriter out, BehaviorEntry behaviorEntry) 110 private static void writeBehavior(OutputStreamWriter out, BehaviorEntry behaviorEntry)
112 throws IOException { 111 throws IOException {
113 out.write(behaviorEntry.getClassName()); 112 out.write(behaviorEntry.getClassName());
114 out.write(" "); 113 out.write(" ");