Advertisement
Guest User

Untitled

a guest
Jun 16th, 2011
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.02 KB | None | 0 0
  1. /*
  2.  * This file is part of Apparat.
  3.  *
  4.  * Apparat is free software: you can redistribute it and/or modify
  5.  * it under the terms of the GNU Lesser General Public License as published by
  6.  * the Free Software Foundation, either version 3 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * Apparat is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU Lesser General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Lesser General Public License
  15.  * along with Apparat. If not, see <http://www.gnu.org/licenses/>.
  16.  *
  17.  * Copyright (C) 2009 Joa Ebert
  18.  * http://www.joa-ebert.com/
  19.  *
  20.  * User: Patrick Le Clec'h
  21.  */
  22.  
  23. // usage : ABCMerger("input file", "output file")
  24.  
  25. import apparat.log.{Log, SimpleLog}
  26. import apparat.log.output.ConsoleOutput
  27.  
  28. object ABCMerger extends SimpleLog {
  29.     def apply(input: String, output: String) {
  30.         import apparat.abc.Abc
  31.         import apparat.utils.TagContainer
  32.         import apparat.swf.{SwfTags, DoABC}
  33.         import apparat.abc.analysis.AbcConstantPoolBuilder
  34.  
  35.         Log.addOutput(new ConsoleOutput())
  36.  
  37.         val cont = TagContainer fromFile input
  38.         var buffer: Option[Abc] = None
  39.  
  40.         log.info("Merging abc from : " + input)
  41.         for(tag <- cont.tags filter (tag => tag.kind == SwfTags.DoABC || tag.kind == SwfTags.DoABC1)) {
  42.             tag match {
  43.                 case doABC: DoABC => {
  44.                     val abc = Abc fromDoABC doABC
  45.                     abc.loadBytecode()
  46.  
  47.                     buffer = buffer match {
  48.                         case Some(b) => Some(b + abc)
  49.                         case None => Some(abc)
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.  
  55.         buffer match {
  56.             case Some(b) => {
  57.                 val doABC = new DoABC()
  58.  
  59.                 doABC.flags = 1
  60.                 doABC.name = "apparat.googlecode.com"
  61.  
  62.                 b.bytecodeAvailable = true
  63.  
  64.                 log.info("Rebuilding cpool...")
  65.                 b.cpool = AbcConstantPoolBuilder using b
  66.  
  67.                 b.saveBytecode()
  68.                 b write doABC
  69.  
  70.                 log.info("Saving merged abc into " + output)
  71.                 Abc.fromDoABC(doABC).write(output)
  72.             }
  73.             case _ => log.info("No abc data found into : " + input)
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement