static void Main(string[] args)
        {
            FileStream file = File.OpenRead(args[0]);
            BinaryReader reader = new BinaryReader(file);
            Package package = new Package(reader);

            StreamWriter writer = new StreamWriter(File.Create(String.Format("{0}.txt", args[0])));
            PackagePrinter printer = new PackagePrinter(writer, package);
            printer.Print(package);
            writer.Close();
        }
        public PackageDataSource(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            package = new Package(reader);
            StreamWriter writer = new StreamWriter(File.Create(String.Format("Package.txt")));
            PackagePrinter printer = new PackagePrinter(writer, package);
            printer.Print(package);
            writer.Close();

            nameTableDataSource = new NameTableDataSource(package.nameTable);
            exportTableDataSource = new ExportTableDataSource(package.exportTable, package);
            importTableDataSource = new ImportTableDataSource(package.importTable, package);
        }
        public void Print(Package obj)
        {
            writer.WriteLine();
            Print(obj.header);

            writer.WriteLine();
            Print(obj.nameTable);

            writer.WriteLine();
            Print(obj.exportTable);

            writer.WriteLine();
            Print(obj.importTable);
        }
        public ImportTableDataSource(ImportTable importTable, Package pkg)
            : base(importTable.items.Count)
        {
            dataGetters = new PackageTableDataGetter[] {
                new PackageTableDataGetter { column = "#",
                    sort = (i => { return importTable[i].index; }),
                    data = (i => { return importTable[i].index.ToString(); }),
                },
                new PackageTableDataGetter { column = "offset",
                    sort = (i => { return importTable[i].offset; }),
                    data = (i => { return String.Format("{0:X8}", importTable[i].offset); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return importTable[i].ClassPackage; }),
                    data = (i => { return importTable[i].ClassPackage.ToString(); }),
                                },
                new PackageTableDataGetter { column = "ClassPackage",
                    sort = (i => { return pkg.GetName(importTable[i].ClassPackage); }),
                    data = (i => { return pkg.GetName(importTable[i].ClassPackage); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return importTable[i].ObjectName; }),
                    data = (i => { return importTable[i].ObjectName.ToString(); }),
                },
                new PackageTableDataGetter { column = "ObjectName",
                    sort = (i => { return pkg.GetName(importTable[i].ObjectName); }),
                    data = (i => { return pkg.GetName(importTable[i].ObjectName); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return importTable[i].Package; }),
                    data = (i => { return importTable[i].Package.ToString(); }),
                },
                new PackageTableDataGetter { column = "Package",
                    sort = (i => { return pkg.GetObjNameRec(importTable[i].Package); }),
                    data = (i => { return pkg.GetObjNameRec(importTable[i].Package); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return importTable[i].Class; }),
                    data = (i => { return importTable[i].Class.ToString(); }),
                },
                new PackageTableDataGetter { column = "Class",
                    sort = (i => { return pkg.GetName(importTable[i].Class); }),
                    data = (i => { return pkg.GetName(importTable[i].Class); }),
                },
            };
        }
        public ExportTableDataSource(ExportTable exportTable, Package pkg)
            : base(exportTable.items.Count)
        {
            dataGetters = new PackageTableDataGetter[] {
                new PackageTableDataGetter { column = "#",
                    sort = (i => { return exportTable[i].index; }),
                    data = (i => { return exportTable[i].index.ToString(); }),
                },
                new PackageTableDataGetter { column = "offset",
                    sort = (i => { return exportTable[i].offset; }),
                    data = (i => { return String.Format("{0:X8}", exportTable[i].offset); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return exportTable[i].ObjectName; }),
                    data = (i => { return exportTable[i].ObjectName.ToString(); }),
                },
                new PackageTableDataGetter { column = "ObjectName",
                    sort = (i => { return pkg.GetName(exportTable[i].ObjectName); }),
                    data = (i => { return pkg.GetName(exportTable[i].ObjectName); })
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return exportTable[i].Class; }),
                    data = (i => { return exportTable[i].Class.ToString(); }),
                },
                new PackageTableDataGetter { column = "Class",
                    sort = (i => { return pkg.GetObjNameRec(exportTable[i].Class); }),
                    data = (i => { return pkg.GetObjNameRec(exportTable[i].Class); }),
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return exportTable[i].Super; }),
                    data = (i => { return exportTable[i].Super.ToString(); }),
                },
                new PackageTableDataGetter { column = "Super",
                    sort = (i => { return pkg.GetObjNameRec(exportTable[i].Super); }),
                    data = (i => { return pkg.GetObjNameRec(exportTable[i].Super); })
                },

                new PackageTableDataGetter { column = "# of",
                    sort = (i => { return exportTable[i].Package; }),
                    data = (i => { return exportTable[i].Package.ToString(); }),
                },
                new PackageTableDataGetter { column = "Package",
                    sort = (i => { return pkg.GetObjNameRec(exportTable[i].Package); }),
                    data = (i => { return pkg.GetObjNameRec(exportTable[i].Package); }),
                },

                new PackageTableDataGetter { column = "SerialSize",
                    sort = (i => { return exportTable[i].SerialSize; }),
                    data = (i => { return exportTable[i].SerialSize.ToString(); }),
                },

                new PackageTableDataGetter { column = "SerialOffset",
                    sort = (i => { return exportTable[i].SerialOffset; }),
                    data = (i => { return String.Format("{0:X8}", exportTable[i].SerialOffset); }),
                },

                new PackageTableDataGetter { column = "ObjectFlags",
                    sort = (i => { return exportTable[i].ObjectFlags; }),
                    data = (i => { return exportTable[i].ObjectFlags.ToString(); }),
                },
            };
        }
 public PackagePrinter(TextWriter writer, Package package)
 {
     this.writer = writer;
     this.package = package;
 }