From a34f9b1565c06cbd4a47e1f0db2fe543f6d7418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 21 Jan 2024 16:09:30 +0100 Subject: [PATCH] instancemetadata command stub --- .../flash/cli/commands/InstanceMetadata.java | 38 +++++++ .../cli/commands/InstanceMetadataGet.java | 81 ++++++++++++++ .../cli/commands/InstanceMetadataRemove.java | 76 +++++++++++++ .../cli/commands/InstanceMetadataSet.java | 101 ++++++++++++++++++ .../decompiler/flash/cli/commands/Main.java | 3 +- .../types/InstanceMetadataFormat.java | 9 ++ 6 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadata.java create mode 100644 libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataGet.java create mode 100644 libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataRemove.java create mode 100644 libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataSet.java create mode 100644 libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/InstanceMetadataFormat.java diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadata.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadata.java new file mode 100644 index 000000000..a5817f81e --- /dev/null +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadata.java @@ -0,0 +1,38 @@ +package com.jpexs.decompiler.flash.cli.commands; + +import com.jpexs.decompiler.flash.cli.VersionProvider; +import com.jpexs.decompiler.flash.cli.commands.types.CompressionKind; +import com.jpexs.decompiler.flash.cli.commands.types.DeobfuscateLevel; +import com.jpexs.decompiler.flash.cli.commands.types.ImportObject; +import com.jpexs.decompiler.flash.cli.commands.types.ReplaceFormat; +import java.util.List; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; +import picocli.CommandLine.ParentCommand; +import picocli.CommandLine.ArgGroup; + +/** + * + * @author JPEXS + */ +@Command( + name = "instancemetadata", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, + header = "Instance metadata operations", + optionListHeading = "%n@|bold,underline Options|@:%n", + parameterListHeading = "%n@|bold,underline Parameters|@:%n", + synopsisHeading = "@|bold,underline Usage|@:", + sortSynopsis = false, + subcommands = { + InstanceMetadataGet.class, + InstanceMetadataSet.class, + InstanceMetadataRemove.class + } +) +public class InstanceMetadata { + + +} diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataGet.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataGet.java new file mode 100644 index 000000000..046ce459f --- /dev/null +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataGet.java @@ -0,0 +1,81 @@ +package com.jpexs.decompiler.flash.cli.commands; + +import com.jpexs.decompiler.flash.cli.VersionProvider; +import com.jpexs.decompiler.flash.cli.commands.types.CompressionKind; +import com.jpexs.decompiler.flash.cli.commands.types.DeobfuscateLevel; +import com.jpexs.decompiler.flash.cli.commands.types.ImportObject; +import com.jpexs.decompiler.flash.cli.commands.types.InstanceMetadataFormat; +import com.jpexs.decompiler.flash.cli.commands.types.ReplaceFormat; +import java.util.List; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; +import picocli.CommandLine.ParentCommand; +import picocli.CommandLine.ArgGroup; + +/** + * + * @author JPEXS + */ +@Command( + name = "get", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, + header = "Get instance metadata", + optionListHeading = "%n@|bold,underline Options|@:%n", + parameterListHeading = "%n@|bold,underline Parameters|@:%n", + synopsisHeading = "@|bold,underline Usage|@:", + footerHeading = "%n@|bold,underline Examples|@:%n", + footer = { + "ffdec-cli instancemetadata get --instance=myitem --key=subkey1 input.swf", + "ffdec-cli instancemetadata get --instance=other --data-file=output.json input.swf", + "ffdec-cli instancemetadata get --instance=third --data-file=output.bin --output-format=raw input.swf", + }, + sortSynopsis = false +) +public class InstanceMetadataGet implements Runnable { + + + @Option( + names = "--output-format", + description = "Format of output. @|bold Enum values|@: ${COMPLETION-CANDIDATES} Default is jslike." + ) + InstanceMetadataFormat outputFormat = InstanceMetadataFormat.jslike; + + + @Option( + names = "--key", + paramLabel = "", + description = "Name of subkey to display. When present, only value from subkey is shown, whole object value otherwise." + ) + String key; + + @Option( + names = "--instance", + description = "Name of instance to fetch metadata from.", + required = true + ) + String instance; + + @Option( + names = "--data-file", + description = "File to write the data to. If ommited, stdout is used." + ) + String outFile = null; + + + + @Parameters( + index = "0", + paramLabel = "IN_FILE", + description = "Input file" + ) + String inFile; + + + @Override + public void run() { + + } +} diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataRemove.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataRemove.java new file mode 100644 index 000000000..166a176ad --- /dev/null +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataRemove.java @@ -0,0 +1,76 @@ +package com.jpexs.decompiler.flash.cli.commands; + +import com.jpexs.decompiler.flash.cli.VersionProvider; +import com.jpexs.decompiler.flash.cli.commands.types.CompressionKind; +import com.jpexs.decompiler.flash.cli.commands.types.DeobfuscateLevel; +import com.jpexs.decompiler.flash.cli.commands.types.ImportObject; +import com.jpexs.decompiler.flash.cli.commands.types.InstanceMetadataFormat; +import com.jpexs.decompiler.flash.cli.commands.types.ReplaceFormat; +import java.util.List; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; +import picocli.CommandLine.ParentCommand; +import picocli.CommandLine.ArgGroup; + +/** + * + * @author JPEXS + */ +@Command( + name = "remove", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, + header = "Remove instance metadata", + optionListHeading = "%n@|bold,underline Options|@:%n", + parameterListHeading = "%n@|bold,underline Parameters|@:%n", + synopsisHeading = "@|bold,underline Usage|@:", + footerHeading = "%n@|bold,underline Examples|@:%n", + footer = { + "ffdec-cli instancemetadata remove --instance=myitem --key=subkey1 input.swf", + "ffdec-cli instancemetadata remove --instance=other --out-file=output.swf input.swf", + }, + sortSynopsis = false +) +public class InstanceMetadataRemove implements Runnable { + + + @Option( + names = "--key", + paramLabel = "", + description = { + "Name of subkey to remove. When present, only the value from subkey of the AMF object is removed.", + "Otherwise all metadata are removed from the instance." + } + ) + String key; + + @Option( + names = "--instance", + description = "Name of instance to remove data from.", + required = true + ) + String instance; + + @Option( + names = "--out-file", + description = "Where to save resulting file. If ommited, original SWF file is overwritten." + ) + String outFile = null; + + + + @Parameters( + index = "0", + paramLabel = "IN_FILE", + description = "Input file" + ) + String inFile; + + + @Override + public void run() { + + } +} diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataSet.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataSet.java new file mode 100644 index 000000000..bfbf96901 --- /dev/null +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/InstanceMetadataSet.java @@ -0,0 +1,101 @@ +package com.jpexs.decompiler.flash.cli.commands; + +import com.jpexs.decompiler.flash.cli.VersionProvider; +import com.jpexs.decompiler.flash.cli.commands.types.CompressionKind; +import com.jpexs.decompiler.flash.cli.commands.types.DeobfuscateLevel; +import com.jpexs.decompiler.flash.cli.commands.types.ImportObject; +import com.jpexs.decompiler.flash.cli.commands.types.InstanceMetadataFormat; +import com.jpexs.decompiler.flash.cli.commands.types.ReplaceFormat; +import java.util.List; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; +import picocli.CommandLine.ParentCommand; +import picocli.CommandLine.ArgGroup; + +/** + * + * @author JPEXS + */ +@Command( + name = "set", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, + header = "Set instance metadata", + optionListHeading = "%n@|bold,underline Options|@:%n", + parameterListHeading = "%n@|bold,underline Parameters|@:%n", + synopsisHeading = "@|bold,underline Usage|@:", + footerHeading = "%n@|bold,underline Examples|@:%n", + footer = { + "ffdec-cli instancemetadata set --instance=myitem --key=subkey1 --value=5 --out-file=output.swf input.swf", + "ffdec-cli instancemetadata set --instance=other --data-file=input.bin --input-format=raw input.swf", + }, + sortSynopsis = false +) +public class InstanceMetadataSet implements Runnable { + + + @Option( + names = "--input-format", + description = "Format of input data. @|bold Enum values|@: ${COMPLETION-CANDIDATES} Default is jslike." + ) + InstanceMetadataFormat inputFormat = InstanceMetadataFormat.jslike; + + + @Option( + names = "--key", + paramLabel = "", + description = { + "Name of subkey to use. When present, the value is set as object property with the name.", + "Otherwise the value is set directly to the instance without any subkeys." + } + ) + String key; + + @ArgGroup(exclusive = true, multiplicity = "1") + ValueOrDataFile valueOrDataFile; + + + static class ValueOrDataFile { + @Option( + names = "--value", + description = "Value to set." + ) + String value = null; + + @Option( + names = "--data-file", + description = "Value to set from file." + ) + String dataFile = null; + + } + + @Option( + names = "--instance", + description = "Name of instance to replace metadata in.", + required = true + ) + String instance; + + @Option( + names = "--out-file", + description = "Where to save resulting file. If ommited, original SWF file is overwritten." + ) + String outFile = null; + + + @Parameters( + index = "0", + paramLabel = "IN_FILE", + description = "Input file" + ) + String inFile; + + + @Override + public void run() { + + } +} diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java index 03b7cdf72..3a94fc195 100644 --- a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java @@ -55,7 +55,8 @@ import picocli.CommandLine.ScopeType; Import.class, Deobfuscate.class, EnableDebugging.class, - GenerateDoc.class + GenerateDoc.class, + InstanceMetadata.class }, descriptionHeading = "%n@|bold,underline Description|@:%n", optionListHeading = "%n@|bold,underline Options|@:%n", diff --git a/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/InstanceMetadataFormat.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/InstanceMetadataFormat.java new file mode 100644 index 000000000..dd794ef30 --- /dev/null +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/InstanceMetadataFormat.java @@ -0,0 +1,9 @@ +package com.jpexs.decompiler.flash.cli.commands.types; + +/** + * + * @author JPEXS + */ +public enum InstanceMetadataFormat { + jslike, raw +}