summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui/FieldMatchingGui.java
diff options
context:
space:
mode:
authorGravatar jeff2015-03-11 11:03:16 -0400
committerGravatar jeff2015-03-11 11:03:16 -0400
commite33b4003a5c423894e7aef575faff359dd1d33b1 (patch)
tree6fa674b5ff8dbc699a44b6423149ad7e6eaae250 /src/cuchaz/enigma/gui/FieldMatchingGui.java
parentnothing of consequence (diff)
downloadenigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.tar.gz
enigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.tar.xz
enigma-fork-e33b4003a5c423894e7aef575faff359dd1d33b1.zip
generalized field matching
added method matching
Diffstat (limited to '')
-rw-r--r--src/cuchaz/enigma/gui/MemberMatchingGui.java (renamed from src/cuchaz/enigma/gui/FieldMatchingGui.java)153
1 files changed, 84 insertions, 69 deletions
diff --git a/src/cuchaz/enigma/gui/FieldMatchingGui.java b/src/cuchaz/enigma/gui/MemberMatchingGui.java
index 3f4a378..52545b3 100644
--- a/src/cuchaz/enigma/gui/FieldMatchingGui.java
+++ b/src/cuchaz/enigma/gui/MemberMatchingGui.java
@@ -33,29 +33,28 @@ import cuchaz.enigma.analysis.EntryReference;
33import cuchaz.enigma.analysis.SourceIndex; 33import cuchaz.enigma.analysis.SourceIndex;
34import cuchaz.enigma.analysis.Token; 34import cuchaz.enigma.analysis.Token;
35import cuchaz.enigma.convert.ClassMatches; 35import cuchaz.enigma.convert.ClassMatches;
36import cuchaz.enigma.convert.FieldMatches; 36import cuchaz.enigma.convert.MemberMatches;
37import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; 37import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener;
38import cuchaz.enigma.mapping.ClassEntry; 38import cuchaz.enigma.mapping.ClassEntry;
39import cuchaz.enigma.mapping.Entry; 39import cuchaz.enigma.mapping.Entry;
40import cuchaz.enigma.mapping.FieldEntry;
41import de.sciss.syntaxpane.DefaultSyntaxKit; 40import de.sciss.syntaxpane.DefaultSyntaxKit;
42 41
43 42
44public class FieldMatchingGui { 43public class MemberMatchingGui<T extends Entry> {
45 44
46 private static enum SourceType { 45 private static enum SourceType {
47 Matched { 46 Matched {
48 47
49 @Override 48 @Override
50 public Collection<ClassEntry> getObfSourceClasses(FieldMatches matches) { 49 public <T extends Entry> Collection<ClassEntry> getObfSourceClasses(MemberMatches<T> matches) {
51 return matches.getSourceClassesWithoutUnmatchedFields(); 50 return matches.getSourceClassesWithoutUnmatchedEntries();
52 } 51 }
53 }, 52 },
54 Unmatched { 53 Unmatched {
55 54
56 @Override 55 @Override
57 public Collection<ClassEntry> getObfSourceClasses(FieldMatches matches) { 56 public <T extends Entry> Collection<ClassEntry> getObfSourceClasses(MemberMatches<T> matches) {
58 return matches.getSourceClassesWithUnmatchedFields(); 57 return matches.getSourceClassesWithUnmatchedEntries();
59 } 58 }
60 }; 59 };
61 60
@@ -67,15 +66,15 @@ public class FieldMatchingGui {
67 return button; 66 return button;
68 } 67 }
69 68
70 public abstract Collection<ClassEntry> getObfSourceClasses(FieldMatches matches); 69 public abstract <T extends Entry> Collection<ClassEntry> getObfSourceClasses(MemberMatches<T> matches);
71 70
72 public static SourceType getDefault() { 71 public static SourceType getDefault() {
73 return values()[0]; 72 return values()[0];
74 } 73 }
75 } 74 }
76 75
77 public static interface SaveListener { 76 public static interface SaveListener<T extends Entry> {
78 public void save(FieldMatches matches); 77 public void save(MemberMatches<T> matches);
79 } 78 }
80 79
81 // controls 80 // controls
@@ -92,25 +91,25 @@ public class FieldMatchingGui {
92 private HighlightPainter m_matchedHighlightPainter; 91 private HighlightPainter m_matchedHighlightPainter;
93 92
94 private ClassMatches m_classMatches; 93 private ClassMatches m_classMatches;
95 private FieldMatches m_fieldMatches; 94 private MemberMatches<T> m_memberMatches;
96 private Deobfuscator m_sourceDeobfuscator; 95 private Deobfuscator m_sourceDeobfuscator;
97 private Deobfuscator m_destDeobfuscator; 96 private Deobfuscator m_destDeobfuscator;
98 private SaveListener m_saveListener; 97 private SaveListener<T> m_saveListener;
99 private SourceType m_sourceType; 98 private SourceType m_sourceType;
100 private ClassEntry m_obfSourceClass; 99 private ClassEntry m_obfSourceClass;
101 private ClassEntry m_obfDestClass; 100 private ClassEntry m_obfDestClass;
102 private FieldEntry m_obfSourceField; 101 private T m_obfSourceEntry;
103 private FieldEntry m_obfDestField; 102 private T m_obfDestEntry;
104 103
105 public FieldMatchingGui(ClassMatches classMatches, FieldMatches fieldMatches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { 104 public MemberMatchingGui(ClassMatches classMatches, MemberMatches<T> fieldMatches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) {
106 105
107 m_classMatches = classMatches; 106 m_classMatches = classMatches;
108 m_fieldMatches = fieldMatches; 107 m_memberMatches = fieldMatches;
109 m_sourceDeobfuscator = sourceDeobfuscator; 108 m_sourceDeobfuscator = sourceDeobfuscator;
110 m_destDeobfuscator = destDeobfuscator; 109 m_destDeobfuscator = destDeobfuscator;
111 110
112 // init frame 111 // init frame
113 m_frame = new JFrame(Constants.Name + " - Field Matcher"); 112 m_frame = new JFrame(Constants.Name + " - Member Matcher");
114 final Container pane = m_frame.getContentPane(); 113 final Container pane = m_frame.getContentPane();
115 pane.setLayout(new BorderLayout()); 114 pane.setLayout(new BorderLayout());
116 115
@@ -225,8 +224,8 @@ public class FieldMatchingGui {
225 m_saveListener = null; 224 m_saveListener = null;
226 m_obfSourceClass = null; 225 m_obfSourceClass = null;
227 m_obfDestClass = null; 226 m_obfDestClass = null;
228 m_obfSourceField = null; 227 m_obfSourceEntry = null;
229 m_obfDestField = null; 228 m_obfDestEntry = null;
230 setSourceType(SourceType.getDefault()); 229 setSourceType(SourceType.getDefault());
231 updateButtons(); 230 updateButtons();
232 } 231 }
@@ -236,7 +235,7 @@ public class FieldMatchingGui {
236 updateSourceClasses(); 235 updateSourceClasses();
237 } 236 }
238 237
239 public void setSaveListener(SaveListener val) { 238 public void setSaveListener(SaveListener<T> val) {
240 m_saveListener = val; 239 m_saveListener = val;
241 } 240 }
242 241
@@ -245,7 +244,7 @@ public class FieldMatchingGui {
245 String selectedPackage = m_sourceClasses.getSelectedPackage(); 244 String selectedPackage = m_sourceClasses.getSelectedPackage();
246 245
247 List<ClassEntry> deobfClassEntries = Lists.newArrayList(); 246 List<ClassEntry> deobfClassEntries = Lists.newArrayList();
248 for (ClassEntry entry : m_sourceType.getObfSourceClasses(m_fieldMatches)) { 247 for (ClassEntry entry : m_sourceType.getObfSourceClasses(m_memberMatches)) {
249 deobfClassEntries.add(m_sourceDeobfuscator.deobfuscateEntry(entry)); 248 deobfClassEntries.add(m_sourceDeobfuscator.deobfuscateEntry(entry));
250 } 249 }
251 m_sourceClasses.setClasses(deobfClassEntries); 250 m_sourceClasses.setClasses(deobfClassEntries);
@@ -256,7 +255,7 @@ public class FieldMatchingGui {
256 255
257 for (SourceType sourceType : SourceType.values()) { 256 for (SourceType sourceType : SourceType.values()) {
258 m_sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)", 257 m_sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)",
259 sourceType.name(), sourceType.getObfSourceClasses(m_fieldMatches).size() 258 sourceType.name(), sourceType.getObfSourceClasses(m_memberMatches).size()
260 )); 259 ));
261 } 260 }
262 } 261 }
@@ -284,30 +283,30 @@ public class FieldMatchingGui {
284 } 283 }
285 284
286 protected void updateSourceHighlights() { 285 protected void updateSourceHighlights() {
287 highlightFields(m_sourceReader, m_sourceDeobfuscator, m_fieldMatches.matches().keySet(), m_fieldMatches.getUnmatchedSourceFields()); 286 highlightEntries(m_sourceReader, m_sourceDeobfuscator, m_memberMatches.matches().keySet(), m_memberMatches.getUnmatchedSourceEntries());
288 } 287 }
289 288
290 protected void updateDestHighlights() { 289 protected void updateDestHighlights() {
291 highlightFields(m_destReader, m_destDeobfuscator, m_fieldMatches.matches().values(), m_fieldMatches.getUnmatchedDestFields()); 290 highlightEntries(m_destReader, m_destDeobfuscator, m_memberMatches.matches().values(), m_memberMatches.getUnmatchedDestEntries());
292 } 291 }
293 292
294 private void highlightFields(CodeReader reader, Deobfuscator deobfuscator, Collection<FieldEntry> obfMatchedFields, Collection<FieldEntry> obfUnmatchedFields) { 293 private void highlightEntries(CodeReader reader, Deobfuscator deobfuscator, Collection<T> obfMatchedEntries, Collection<T> obfUnmatchedEntries) {
295 reader.clearHighlights(); 294 reader.clearHighlights();
296 SourceIndex index = reader.getSourceIndex(); 295 SourceIndex index = reader.getSourceIndex();
297 296
298 // matched fields 297 // matched fields
299 for (FieldEntry obfFieldEntry : obfMatchedFields) { 298 for (T obfT : obfMatchedEntries) {
300 FieldEntry deobfFieldEntry = deobfuscator.deobfuscateEntry(obfFieldEntry); 299 T deobfT = deobfuscator.deobfuscateEntry(obfT);
301 Token token = index.getDeclarationToken(deobfFieldEntry); 300 Token token = index.getDeclarationToken(deobfT);
302 if (token != null) { 301 if (token != null) {
303 reader.setHighlightedToken(token, m_matchedHighlightPainter); 302 reader.setHighlightedToken(token, m_matchedHighlightPainter);
304 } 303 }
305 } 304 }
306 305
307 // unmatched fields 306 // unmatched fields
308 for (FieldEntry obfFieldEntry : obfUnmatchedFields) { 307 for (T obfT : obfUnmatchedEntries) {
309 FieldEntry deobfFieldEntry = deobfuscator.deobfuscateEntry(obfFieldEntry); 308 T deobfT = deobfuscator.deobfuscateEntry(obfT);
310 Token token = index.getDeclarationToken(deobfFieldEntry); 309 Token token = index.getDeclarationToken(deobfT);
311 if (token != null) { 310 if (token != null) {
312 reader.setHighlightedToken(token, m_unmatchedHighlightPainter); 311 reader.setHighlightedToken(token, m_unmatchedHighlightPainter);
313 } 312 }
@@ -315,8 +314,8 @@ public class FieldMatchingGui {
315 } 314 }
316 315
317 private boolean isSelectionMatched() { 316 private boolean isSelectionMatched() {
318 return m_obfSourceField != null && m_obfDestField != null 317 return m_obfSourceEntry != null && m_obfDestEntry != null
319 && m_fieldMatches.isMatched(m_obfSourceField, m_obfDestField); 318 && m_memberMatches.isMatched(m_obfSourceEntry, m_obfDestEntry);
320 } 319 }
321 320
322 protected void onSelectSource(Entry source) { 321 protected void onSelectSource(Entry source) {
@@ -328,16 +327,22 @@ public class FieldMatchingGui {
328 setSource(null); 327 setSource(null);
329 328
330 // then look for a valid source selection 329 // then look for a valid source selection
331 if (source != null && source instanceof FieldEntry) { 330 if (source != null) {
332 FieldEntry sourceField = (FieldEntry)source; 331
333 FieldEntry obfSourceField = m_sourceDeobfuscator.obfuscateEntry(sourceField); 332 // this looks really scary, but it's actually ok
334 if (m_fieldMatches.hasSource(obfSourceField)) { 333 // Deobfuscator.obfuscateEntry can handle all implementations of Entry
335 setSource(obfSourceField); 334 // and MemberMatches.hasSource() will only pass entries that actually match T
335 @SuppressWarnings("unchecked")
336 T sourceEntry = (T)source;
337
338 T obfSourceEntry = m_sourceDeobfuscator.obfuscateEntry(sourceEntry);
339 if (m_memberMatches.hasSource(obfSourceEntry)) {
340 setSource(obfSourceEntry);
336 341
337 // look for a matched dest too 342 // look for a matched dest too
338 FieldEntry obfDestField = m_fieldMatches.matches().get(obfSourceField); 343 T obfDestEntry = m_memberMatches.matches().get(obfSourceEntry);
339 if (obfDestField != null) { 344 if (obfDestEntry != null) {
340 setDest(obfDestField); 345 setDest(obfDestEntry);
341 } 346 }
342 } 347 }
343 } 348 }
@@ -354,16 +359,22 @@ public class FieldMatchingGui {
354 setDest(null); 359 setDest(null);
355 360
356 // then look for a valid dest selection 361 // then look for a valid dest selection
357 if (dest != null && dest instanceof FieldEntry) { 362 if (dest != null) {
358 FieldEntry destField = (FieldEntry)dest; 363
359 FieldEntry obfDestField = m_destDeobfuscator.obfuscateEntry(destField); 364 // this looks really scary, but it's actually ok
360 if (m_fieldMatches.hasDest(obfDestField)) { 365 // Deobfuscator.obfuscateEntry can handle all implementations of Entry
361 setDest(obfDestField); 366 // and MemberMatches.hasSource() will only pass entries that actually match T
367 @SuppressWarnings("unchecked")
368 T destEntry = (T)dest;
369
370 T obfDestEntry = m_destDeobfuscator.obfuscateEntry(destEntry);
371 if (m_memberMatches.hasDest(obfDestEntry)) {
372 setDest(obfDestEntry);
362 373
363 // look for a matched source too 374 // look for a matched source too
364 FieldEntry obfSourceField = m_fieldMatches.matches().inverse().get(obfDestField); 375 T obfSourceEntry = m_memberMatches.matches().inverse().get(obfDestEntry);
365 if (obfSourceField != null) { 376 if (obfSourceEntry != null) {
366 setSource(obfSourceField); 377 setSource(obfSourceEntry);
367 } 378 }
368 } 379 }
369 } 380 }
@@ -371,42 +382,46 @@ public class FieldMatchingGui {
371 updateButtons(); 382 updateButtons();
372 } 383 }
373 384
374 private void setSource(FieldEntry obfField) { 385 private void setSource(T obfEntry) {
375 if (obfField == null) { 386 if (obfEntry == null) {
376 m_obfSourceField = obfField; 387 m_obfSourceEntry = obfEntry;
377 m_sourceLabel.setText(""); 388 m_sourceLabel.setText("");
378 } else { 389 } else {
379 m_obfSourceField = obfField; 390 m_obfSourceEntry = obfEntry;
380 FieldEntry deobfField = m_sourceDeobfuscator.deobfuscateEntry(obfField); 391 m_sourceLabel.setText(getEntryLabel(obfEntry, m_sourceDeobfuscator));
381 m_sourceLabel.setText(deobfField.getName() + " " + deobfField.getType().toString());
382 } 392 }
383 } 393 }
384 394
385 private void setDest(FieldEntry obfField) { 395 private void setDest(T obfEntry) {
386 if (obfField == null) { 396 if (obfEntry == null) {
387 m_obfDestField = obfField; 397 m_obfDestEntry = obfEntry;
388 m_destLabel.setText(""); 398 m_destLabel.setText("");
389 } else { 399 } else {
390 m_obfDestField = obfField; 400 m_obfDestEntry = obfEntry;
391 FieldEntry deobfField = m_destDeobfuscator.deobfuscateEntry(obfField); 401 m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator));
392 m_destLabel.setText(deobfField.getName() + " " + deobfField.getType().toString());
393 } 402 }
394 } 403 }
395 404
405 private String getEntryLabel(T obfEntry, Deobfuscator deobfuscator) {
406 // deobfuscate, then take off the class name
407 T deobfEntry = deobfuscator.deobfuscateEntry(obfEntry);
408 return deobfEntry.toString().substring(deobfEntry.getClassName().length() + 1);
409 }
410
396 private void updateButtons() { 411 private void updateButtons() {
397 412
398 GuiTricks.deactivateButton(m_matchButton); 413 GuiTricks.deactivateButton(m_matchButton);
399 GuiTricks.deactivateButton(m_unmatchableButton); 414 GuiTricks.deactivateButton(m_unmatchableButton);
400 415
401 if (m_obfSourceField != null && m_obfDestField != null) { 416 if (m_obfSourceEntry != null && m_obfDestEntry != null) {
402 if (m_fieldMatches.isMatched(m_obfSourceField, m_obfDestField)) { 417 if (m_memberMatches.isMatched(m_obfSourceEntry, m_obfDestEntry)) {
403 GuiTricks.activateButton(m_matchButton, "Unmatch", new ActionListener() { 418 GuiTricks.activateButton(m_matchButton, "Unmatch", new ActionListener() {
404 @Override 419 @Override
405 public void actionPerformed(ActionEvent event) { 420 public void actionPerformed(ActionEvent event) {
406 unmatch(); 421 unmatch();
407 } 422 }
408 }); 423 });
409 } else if (!m_fieldMatches.isMatchedSourceField(m_obfSourceField) && !m_fieldMatches.isMatchedDestField(m_obfDestField)) { 424 } else if (!m_memberMatches.isMatchedSourceEntry(m_obfSourceEntry) && !m_memberMatches.isMatchedDestEntry(m_obfDestEntry)) {
410 GuiTricks.activateButton(m_matchButton, "Match", new ActionListener() { 425 GuiTricks.activateButton(m_matchButton, "Match", new ActionListener() {
411 @Override 426 @Override
412 public void actionPerformed(ActionEvent event) { 427 public void actionPerformed(ActionEvent event) {
@@ -414,7 +429,7 @@ public class FieldMatchingGui {
414 } 429 }
415 }); 430 });
416 } 431 }
417 } else if (m_obfSourceField != null) { 432 } else if (m_obfSourceEntry != null) {
418 GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", new ActionListener() { 433 GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", new ActionListener() {
419 @Override 434 @Override
420 public void actionPerformed(ActionEvent event) { 435 public void actionPerformed(ActionEvent event) {
@@ -427,7 +442,7 @@ public class FieldMatchingGui {
427 protected void match() { 442 protected void match() {
428 443
429 // update the field matches 444 // update the field matches
430 m_fieldMatches.makeMatch(m_obfSourceField, m_obfDestField); 445 m_memberMatches.makeMatch(m_obfSourceEntry, m_obfDestEntry);
431 save(); 446 save();
432 447
433 // update the ui 448 // update the ui
@@ -441,7 +456,7 @@ public class FieldMatchingGui {
441 protected void unmatch() { 456 protected void unmatch() {
442 457
443 // update the field matches 458 // update the field matches
444 m_fieldMatches.unmakeMatch(m_obfSourceField, m_obfDestField); 459 m_memberMatches.unmakeMatch(m_obfSourceEntry, m_obfDestEntry);
445 save(); 460 save();
446 461
447 // update the ui 462 // update the ui
@@ -455,7 +470,7 @@ public class FieldMatchingGui {
455 protected void unmatchable() { 470 protected void unmatchable() {
456 471
457 // update the field matches 472 // update the field matches
458 m_fieldMatches.makeSourceUnmatchable(m_obfSourceField); 473 m_memberMatches.makeSourceUnmatchable(m_obfSourceEntry);
459 save(); 474 save();
460 475
461 // update the ui 476 // update the ui
@@ -468,7 +483,7 @@ public class FieldMatchingGui {
468 483
469 private void save() { 484 private void save() {
470 if (m_saveListener != null) { 485 if (m_saveListener != null) {
471 m_saveListener.save(m_fieldMatches); 486 m_saveListener.save(m_memberMatches);
472 } 487 }
473 } 488 }
474} 489}