export/import symbol classes/export asset tags

This commit is contained in:
honfika@gmail.com
2015-03-13 00:18:11 +01:00
parent eb9d783442
commit 7f68a43079
35 changed files with 359 additions and 72 deletions

View File

@@ -447,9 +447,9 @@ public final class SWF implements SWFContainerItem, Timelined {
for (Tag t : tags) {
if (t instanceof SymbolClassTag) {
SymbolClassTag sc = (SymbolClassTag) t;
for (int i = 0; i < sc.tags.length; i++) {
if (sc.tags[i] == 0) {
return sc.names[i];
for (int i = 0; i < sc.tags.size(); i++) {
if (sc.tags.get(i) == 0) {
return sc.names.get(i);
}
}
}
@@ -952,9 +952,9 @@ public final class SWF implements SWFContainerItem, Timelined {
for (Tag t : tags) {
if (t instanceof SymbolClassTag) {
SymbolClassTag sct = (SymbolClassTag) t;
for (int i = 0; i < sct.tags.length; i++) {
if ((!classes.containsKey(sct.tags[i])) && (!classes.containsValue(sct.names[i]))) {
classes.put(sct.tags[i], sct.names[i]);
for (int i = 0; i < sct.tags.size(); i++) {
if ((!classes.containsKey(sct.tags.get(i))) && (!classes.containsValue(sct.names.get(i)))) {
classes.put(sct.tags.get(i), sct.names.get(i));
}
}
}
@@ -1882,10 +1882,10 @@ public final class SWF implements SWFContainerItem, Timelined {
for (Tag tag : tags) {
if (tag instanceof SymbolClassTag) {
SymbolClassTag sc = (SymbolClassTag) tag;
for (int i = 0; i < sc.names.length; i++) {
String newname = deobfuscation.deobfuscateNameWithPackage(true, sc.names[i], deobfuscated, renameType, deobfuscated);
for (int i = 0; i < sc.names.size(); i++) {
String newname = deobfuscation.deobfuscateNameWithPackage(true, sc.names.get(i), deobfuscated, renameType, deobfuscated);
if (newname != null) {
sc.names[i] = newname;
sc.names.set(i, newname);
}
}
sc.setModified(true);

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.exporters;
import com.jpexs.decompiler.flash.EventListener;
import com.jpexs.decompiler.flash.tags.ExportAssetsTag;
import com.jpexs.decompiler.flash.tags.SymbolClassTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class SymbolClassExporter {
public static final String SYMBOL_CLASS_EXPORT_FILENAME = "symbols.csv";
public List<File> exportNames(final String outdir, List<Tag> tags, EventListener evl) throws IOException {
List<File> ret = new ArrayList<>();
int count = 0;
for (Tag t : tags) {
if (t instanceof ExportAssetsTag || t instanceof SymbolClassTag) {
count++;
}
}
if (count == 0) {
return ret;
}
File foutdir = new File(outdir);
if (!foutdir.exists()) {
if (!foutdir.mkdirs()) {
if (!foutdir.exists()) {
throw new IOException("Cannot create directory " + outdir);
}
}
}
final File file = new File(outdir + File.separator + SYMBOL_CLASS_EXPORT_FILENAME);
try (Writer writer = new BufferedWriter(new Utf8OutputStreamWriter(new FileOutputStream(file)))) {
for (Tag t : tags) {
if (t instanceof ExportAssetsTag) {
ExportAssetsTag eat = (ExportAssetsTag) t;
for (int i = 0; i < eat.tags.size(); i++) {
writer.append(eat.tags.get(i) + ";" + eat.names.get(i) + Helper.newLine);
}
} else if (t instanceof SymbolClassTag) {
SymbolClassTag sct = (SymbolClassTag) t;
for (int i = 0; i < sct.tags.size(); i++) {
writer.append(sct.tags.get(i) + ";" + sct.names.get(i) + Helper.newLine);
}
}
}
}
ret.add(file);
return ret;
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.exporters.modes;
/**
*
* @author JPEXS
*/
public enum SymbolClassExportMode {
CSV
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.importers;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.ExportAssetsTag;
import com.jpexs.decompiler.flash.tags.SymbolClassTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.helpers.Helper;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class SymbolClassImporter {
public void importSymbolClasses(File importFile, SWF swf) {
String texts = Helper.readTextFile(importFile.getPath());
String[] lines = texts.split(Helper.newLine);
Map<Integer, String> nameMap = new HashMap<>();
for (String line : lines) {
String[] pair = line.split(";");
int characterId = Integer.parseInt(pair[0]);
String name = pair[1];
nameMap.put(characterId, name);
}
for (Tag tag : swf.tags) {
if (tag instanceof ExportAssetsTag) {
ExportAssetsTag eat = (ExportAssetsTag) tag;
for (int i = 0; i < eat.tags.size(); i++) {
int id = eat.tags.get(i);
if (nameMap.containsKey(id)) {
eat.names.set(i, nameMap.get(id));
eat.setModified(true);
}
}
} else if (tag instanceof SymbolClassTag) {
SymbolClassTag sct = (SymbolClassTag) tag;
for (int i = 0; i < sct.tags.size(); i++) {
int id = sct.tags.get(i);
if (nameMap.containsKey(id)) {
sct.names.set(i, nameMap.get(id));
sct.setModified(true);
}
}
}
}
}
}

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.SymbolClassTypeTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFArray;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
@@ -34,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class ExportAssetsTag extends Tag {
public class ExportAssetsTag extends SymbolClassTypeTag {
/**
* HashMap with assets
@@ -78,8 +79,8 @@ public class ExportAssetsTag extends Tag {
names = new ArrayList<>();
for (int i = 0; i < count; i++) {
int characterId = sis.readUI16("characterId");
tags.add(characterId);
String name = sis.readString("name");
tags.add(characterId);
names.add(name);
}
}

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.SymbolClassTypeTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFArray;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
@@ -26,15 +27,17 @@ import com.jpexs.helpers.ByteArrayRange;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
public class SymbolClassTag extends Tag {
public class SymbolClassTag extends SymbolClassTypeTag {
@SWFType(value = BasicType.UI16)
@SWFArray(value = "tag", countField = "numSymbols")
public int[] tags;
public List<Integer> tags;
@SWFArray(value = "name", countField = "numSymbols")
public String[] names;
public List<String> names;
public static final int ID = 76;
@@ -45,8 +48,8 @@ public class SymbolClassTag extends Tag {
*/
public SymbolClassTag(SWF swf) {
super(swf, ID, "SymbolClass", null);
tags = new int[0];
names = new String[0];
tags = new ArrayList<>();
names = new ArrayList<>();
}
public SymbolClassTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
@@ -57,13 +60,13 @@ public class SymbolClassTag extends Tag {
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
int numSymbols = sis.readUI16("numSymbols");
tags = new int[numSymbols];
names = new String[numSymbols];
for (int ii = 0; ii < numSymbols; ii++) {
tags = new ArrayList<>(numSymbols);
names = new ArrayList<>(numSymbols);
for (int i = 0; i < numSymbols; i++) {
int tagID = sis.readUI16("tagID");
String className = sis.readString("className");
tags[ii] = tagID;
names[ii] = className;
tags.add(tagID);
names.add(className);
}
}
@@ -78,11 +81,11 @@ public class SymbolClassTag extends Tag {
OutputStream os = baos;
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
try {
int numSymbols = tags.length;
int numSymbols = tags.size();
sos.writeUI16(numSymbols);
for (int ii = 0; ii < numSymbols; ii++) {
sos.writeUI16(tags[ii]);
sos.writeString(names[ii]);
for (int i = 0; i < numSymbols; i++) {
sos.writeUI16(tags.get(i));
sos.writeString(names.get(i));
}
} catch (IOException e) {
throw new Error("This should never happen.", e);

View File

@@ -90,7 +90,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
@Override
public String getExportFileName() {
return getName();
return tagName;
}
/**

View File

@@ -58,7 +58,7 @@ public abstract class CharacterIdTag extends Tag {
@Override
public String getExportFileName() {
String result = super.getName() + "_" + getCharacterId();
String result = super.getExportFileName() + "_" + getCharacterId();
return result + (exportName != null ? "_" + exportName : "");
}

View File

@@ -48,13 +48,13 @@ public abstract class CharacterTag extends CharacterIdTag {
if (className != null) {
nameAppend = ": " + className;
}
if (getCharacterId() != -1) {
return tagName + " (" + getCharacterId() + nameAppend + ")";
}
if (!nameAppend.isEmpty()) {
return tagName + " (" + nameAppend + ")";
}
return tagName;
return tagName + " (" + getCharacterId() + nameAppend + ")";
}
@Override
public String getExportFileName() {
String result = super.getExportFileName();
return result + (className != null ? "_" + className : "");
}
@Override

View File

@@ -170,6 +170,16 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
return tagName + " (" + getCharacterId() + nameAppend + ")";
}
@Override
public String getExportFileName() {
String result = super.getExportFileName();
String fontName = getFontNameIntag();
if (fontName != null) {
fontName = fontName.replace(" ", "_");
}
return result + (fontName != null ? "_" + fontName : "");
}
public String getSystemFontName() {
Map<String, String> fontPairs = Configuration.getFontToNameMap();
String key = swf.getShortFileName() + "_" + getFontId() + "_" + getFontNameIntag();

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags.base;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.helpers.ByteArrayRange;
/**
*
* @author JPEXS
*/
public abstract class SymbolClassTypeTag extends Tag {
public SymbolClassTypeTag(SWF swf, int id, String name, ByteArrayRange data) {
super(swf, id, name, data);
}
}

View File

@@ -2307,9 +2307,9 @@ public class XFLConverter {
for (Tag t : tags) {
if (t instanceof SymbolClassTag) {
SymbolClassTag sc = (SymbolClassTag) t;
for (int i = 0; i < sc.tags.length; i++) {
if (!ret.containsKey(sc.tags[i]) && !ret.containsValue(sc.names[i])) {
ret.put(sc.tags[i], sc.names[i]);
for (int i = 0; i < sc.tags.size(); i++) {
if (!ret.containsKey(sc.tags.get(i)) && !ret.containsValue(sc.names.get(i))) {
ret.put(sc.tags.get(i), sc.names.get(i));
}
}
}