<commit_before>load("../../../lib/DataView.js/DataView.js");

var SWF = {};
load("../../swf/util.js");
load("../../swf/types.js");
load("../../swf/structs.js");
load("../../swf/tags.js");
load("../../swf/inflate.js");
load("../../swf/stream.js");
load("../../swf/templates.js");
load("../../swf/generator.js");
load("../../swf/parser.js");
load("../../swf/bitmap.js");
load("../../swf/button.js");
load("../../swf/font.js");
load("../../swf/image.js");
load("../../swf/label.js");
load("../../swf/shape.js");
load("../../swf/text.js");

load("../util.js");
load("../options.js");
load("../metrics.js");

var Timer = metrics.Timer;
var stdout = new IndentingWriter();
var ArgumentParser = options.ArgumentParser;
var Option = options.Option;
var OptionSet = options.OptionSet;

var argumentParser = new ArgumentParser();
var systemOptions = new OptionSet("System Options");

load("../constants.js");
load("../domain.js");
load("../opcodes.js");
load("../parser.js");
load("../disassembler.js");
load("../analyze.js");
load("../compiler/lljs/src/estransform.js");
load("../compiler/lljs/src/escodegen.js");
load("../compiler/compiler.js");
load("../native.js");
load("../runtime.js");
load("../interpreter.js");

function printUsage() {
  stdout.writeLn("dumpabc.js " + argumentParser.getUsage());
}

argumentParser.addArgument("h", "help", "boolean", {parse: function (x) { printUsage(); }});
var swfFile = argumentParser.addArgument("swf", "swf", "string", { positional: true });
var prefix = argumentParser.addArgument("prefix", "prefix", "string", { defaultValue: "abc" });

try {
  argumentParser.parse(arguments);
} catch (x) {
  stdout.writeLn(x.message);
  quit();
}

/*
SWF.parse(snarf(swfFile.value, "binary"), {
  oncomplete: function(result) {
    var tags = result.tags;
    var abcCount = 0;
    for (var i = 0, n = tags.length; i < n; i++) {
      var tag = tags[i];
      if (tag.type === "abc") {
        stdout.writeLn("<<< BASE64 " + prefix.value + "-" + abcCount++ + ".abc");
        print (base64ArrayBuffer(tag.data));
        stdout.writeLn(">>>");
      }
    }
  }
});
*/

SWF.parse(snarf(swfFile.value, "binary"), {
  oncomplete: function(result) {
    var tags = result.tags;
    var abcCount = 0;
    var offset = 0;
    var files = [];
    var data = "";
    for (var i = 0, n = tags.length; i < n; i++) {
      var tag = tags[i];
      if (tag.type === "abc") {
        offset += tag.data.length;
        files.push({name: tag.name, offset: offset, length: + tag.data.length});
        data += base64ArrayBuffer(tag.data);
      }
    }
    print (JSON.stringify(files, true, 2));
    print (data);
  }
});<commit_msg>Bug fix.<commit_after>load("../../../lib/DataView.js/DataView.js");

var SWF = {};
load("../../swf/util.js");
load("../../swf/types.js");
load("../../swf/structs.js");
load("../../swf/tags.js");
load("../../swf/inflate.js");
load("../../swf/stream.js");
load("../../swf/templates.js");
load("../../swf/generator.js");
load("../../swf/parser.js");
load("../../swf/bitmap.js");
load("../../swf/button.js");
load("../../swf/font.js");
load("../../swf/image.js");
load("../../swf/label.js");
load("../../swf/shape.js");
load("../../swf/text.js");

load("../util.js");
load("../options.js");
load("../metrics.js");

var Timer = metrics.Timer;
var stdout = new IndentingWriter();
var ArgumentParser = options.ArgumentParser;
var Option = options.Option;
var OptionSet = options.OptionSet;

var argumentParser = new ArgumentParser();
var systemOptions = new OptionSet("System Options");

load("../constants.js");
load("../domain.js");
load("../opcodes.js");
load("../parser.js");
load("../disassembler.js");
load("../analyze.js");
load("../compiler/lljs/src/estransform.js");
load("../compiler/lljs/src/escodegen.js");
load("../compiler/compiler.js");
load("../native.js");
load("../runtime.js");
load("../interpreter.js");

function printUsage() {
  stdout.writeLn("dumpabc.js " + argumentParser.getUsage());
}

argumentParser.addArgument("h", "help", "boolean", {parse: function (x) { printUsage(); }});
var swfFile = argumentParser.addArgument("swf", "swf", "string", { positional: true });
var prefix = argumentParser.addArgument("prefix", "prefix", "string", { defaultValue: "abc" });

try {
  argumentParser.parse(arguments);
} catch (x) {
  stdout.writeLn(x.message);
  quit();
}

/*
SWF.parse(snarf(swfFile.value, "binary"), {
  oncomplete: function(result) {
    var tags = result.tags;
    var abcCount = 0;
    for (var i = 0, n = tags.length; i < n; i++) {
      var tag = tags[i];
      if (tag.type === "abc") {
        stdout.writeLn("<<< BASE64 " + prefix.value + "-" + abcCount++ + ".abc");
        print (base64ArrayBuffer(tag.data));
        stdout.writeLn(">>>");
      }
    }
  }
});
*/

SWF.parse(snarf(swfFile.value, "binary"), {
  oncomplete: function(result) {
    var tags = result.tags;
    var abcCount = 0;
    var offset = 0;
    var files = [];
    for (var i = 0, n = tags.length; i < n; i++) {
      var tag = tags[i];
      if (tag.type === "abc") {
        files.push({name: tag.name, offset: offset, length: + tag.data.length, data: tag.data});
        offset += tag.data.length;
      }
    }
    var data = new Uint8Array(offset);
    for (var i = 0; i < files.length; i++) {
      var file = files[i];
      data.set(file.data, file.offset);
      print ("Name: " + file.name + ", Offset: " + file.offset + ", Length: " + file.length);
    }
    print (base64ArrayBuffer(data));
  }
});
{'fraction_non_alphanumeric': 0.25580969807868253, 'fraction_numerical': 0.004574565416285453, 'mean_word_length': 3.0399113082039912, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '626607', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1920, 'n_words': 360}