private static void HandleListCommand(string[] args) { string filename = args[1]; if (filename.StartsWith("-")) { PrintHelp(); Console.WriteLine(); Console.WriteLine("Error: List command does not accept any parameters"); return; } string keyfile = null; if (args.Length == 3) { keyfile = args[2]; } BiffFile file = new BiffFile(filename, keyfile); ResourceTableEntry[] table = file.GetResourceTableCopy(); for (int i = 0; i < table.Length; i++) { Console.WriteLine("{0}\t:\t{1}\t({2} bytes)", table[i].ID, table[i].Name, table[i].Size); } Console.WriteLine("{0} entries in the file", table.Length); }
private static void HandleDumpCommand(string[] args) { string oParam = null; int fnStart = 1; if (args[1].StartsWith("-o")) { oParam = args[2]; fnStart += 2; } if (oParam == null) { oParam = Directory.GetCurrentDirectory(); } string filename = args[fnStart]; string keyfile = null; if (args.Length >= fnStart + 2) { keyfile = args[fnStart + 1]; } BiffFile file = new BiffFile(filename, keyfile); file.ShouldCache = false; ResourceTableEntry[] table = file.GetResourceTableCopy(); for (int i = 0; i < table.Length; i++) { ResourceEntry entry = file[table[i].ID]; if (entry == null) { Console.WriteLine("Skipping file {0} due to the entry being invalid", i); continue; } Console.WriteLine("Writing file {0} of {1}", i, table.Length); File.WriteAllBytes(Path.Combine(oParam, entry.Name), entry.Data); } Console.WriteLine("{0} files written to '{1}'", table.Length, oParam); }
private static void HandleExtractCommand(string[] args) { string iParam = null; string oParam = null; int fnStart = 1; if (args[1].StartsWith("-i")) { iParam = args[2]; fnStart += 2; } else if (args[1].StartsWith("-o")) { oParam = args[2]; fnStart += 2; } if (args[3].StartsWith("-i")) { iParam = args[4]; fnStart += 2; } else if (args[3].StartsWith("-o")) { oParam = args[4]; fnStart += 2; } if (oParam == null) { oParam = Directory.GetCurrentDirectory(); } string filename = args[fnStart]; string keyfile = null; if (args.Length >= fnStart + 2) { keyfile = args[fnStart + 1]; } int id = -1; if (int.TryParse(iParam, out id) == false) { PrintHelp(); Console.WriteLine(); Console.WriteLine("Error: Invalid value for param 'i': Must be an integer"); return; } BiffFile file = new BiffFile(filename, keyfile); ResourceEntry entry = file[id]; if (entry == null) { PrintHelp(); Console.WriteLine(); Console.WriteLine("Error: ID '{0}' does not exist in BIFF file", id.ToString()); return; } File.WriteAllBytes(Path.Combine(oParam, entry.Name), entry.Data); Console.WriteLine("{0} bytes written to '{1}'", entry.Data.Length, Path.Combine(oParam, entry.Name)); }