Replacing strings inside SWF

℡╲_俬逩灬. 提交于 2020-01-01 03:12:26

问题


We've got dozens of versions of an SWF modified for different customers of a big Flash project, and now would have to replace some strings embedded in scripts in each copy. The FLA file for some of these is very difficult to locate or even missing (I inherited this mess and refactoring it is currently not an option).

Is there a (free) tool to replace strings used inside ActionScript? I tried swfmill to convert the files to XML and back but it can't handle international characters contained in the strings so I could get them only partially converted. Most of the strings were correctly extracted so another tool might do the job.


回答1:


You could try Burak's URL Action Editor -- it says URL, but I'm pretty sure it lets you edit any text in a SWF. I haven't used it, but I have used his ActionScript Viewer, which works wonderfully.




回答2:


You can use Apparat for this kind of task. It allows you to alter ActionScript 3 bytecode in SWF and SWC files.

I would prefer the Scala source branch for your task. Basically the code would look like this:

val swf = Swf from "in.swf"
for(tag <- swf.tags) {
  (Abc fromTag tag) match {
    case Some(abc) => {
      val strings = abc.cpool.strings
      for(i <- 1 until strings.length) {
        if(strings(i) == 'search) {
          strings(i) = 'replacement
        }
      }
      abc write tag
    }
    case None =>
}
swf write "out.swf"



回答3:


Well the only advice I can come up with is to fix swfmill to support international characters. You might want to ask in swfmill mailing list (swfmill@swfmill.org as far as I know) for a best way how to do it, shouldn't be too difficult if you know C/C++ a bit.




回答4:


If the files are using actionscript 2 maybe you can disassemble and reassemble using http://flasm.sourceforge.net/ (And of course: modify the strings before reassembling). For as3 adobe provides a decompiler that might be usable to achieve the same, but I don't think your flash will be as3 if you've inherited it.




回答5:


This one works really well too and it is free:

http://www.free-decompiler.com/flash/




回答6:


tricky - it might not be any easier, but you could load the 'locked' swf into one you control, then spider through its objects until you hit TextBox, using some for...in loops - it'd be a long, arduous process to map them out then change them, especially if the previous developer didn't name things in a helpful way, but if it's a fairly simple .swf then it might be too bad...

Also, there's a mac-only utility for decompiling swfs that I remember a coworker swearing by, but I don't recall the name... anybody?




回答7:


Tough one - have you tried the Sothink decompiler? If that doesn't work, I'd say try loading the the swf into another swf, then drill down and change the content of the textfield - something like _root.loadedswf.clip1.box2.textField.text = "New text"; Obviously, this might not work if the application is complex.




回答8:


How about this one? http://code.google.com/p/swfreplacer/wiki/Intro




回答9:


It seems to me that swfmill has updated their tool to support international characters, at least for Latvian language (which requires UTF-8). Strings are encoded as HTML entities.

Solved some similar problems with legacy swf file.




回答10:


You could try Swiffotron which includes the ability to replace text both on the stage and in actionscript.

Here is a unit test input file from the project which shows how it could be done:




回答11:


Apparat ended up working great for this (I have some legacy files that needed to be modified). I couldn't get Joa's Scala code to work, so I ended up implementing his solution in Java.

  1. Download binaries.
  2. Make sure Scala is installed (the libraries are still required, even though the solution is in pure Java).
  3. Compile and run the code below using the appropriate classpath (pointing to the folder with Apparat binaries as well as your Scala libraries).
    1. javac -classpath ".;apparat/*;C:/path/to/scala/lib/*" SwfEditor.java
    2. java -classpath ".;apparat/*;C:/path/to/scala/lib/*" SwfEditor
import apparat.swf.Swf;
import apparat.abc.Abc;
import apparat.swf.SwfTag;
import scala.collection.Iterator;
import scala.Symbol;
import apparat.swf.DoABC;

class SwfEditor {

  public static void main(String[] args){
    Swf input = Swf.fromFile("in.swf");
    Iterator<SwfTag> iter = input.tags().iterator();
    while (iter.hasNext()) {
      SwfTag tag = iter.next();
      if(tag instanceof DoABC) {
        DoABC doABCTag = (DoABC) tag;
        Abc abc = Abc.fromTag(doABCTag).getOrElse(null);
        Symbol[] strings = abc.cpool().strings();
        for(int i=0; i<strings.length; i++) {
          String string = strings[i].toString();
          if(string == "'search")) {
            strings[i] = new Symbol("replacement");
          }
        }
        abc.write(doABCTag);
      }
    }
    input.write("out.swf");
  }
}


来源:https://stackoverflow.com/questions/119694/replacing-strings-inside-swf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!