1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using ArcToolkitCLI.Commands.Options;
- using ArcToolkitCLI.Util;
- using COM3D2.Toolkit.Arc;
- using CommandLine;
- namespace ArcToolkitCLI.Commands
- {
- [Verb("info", HelpText = "Display information about the given ARC files")]
- public class InfoCommand : IInputOptions, ICommand
- {
- [Option("only-key",
- HelpText = "If the archive is a WARC file, output only the decryption key as a base64 string",
- Required = false)]
- public bool OnlyKey { get; set; }
- public int Run()
- {
- var first = true;
- foreach (var file in Glob.EnumerateFiles(Input))
- {
- if (!file.Exists)
- return Errors.Error(Errors.ErrorCodes.NotAFile, file.Name);
- if (!first && !OnlyKey)
- Console.WriteLine();
- first = false;
- using (var stream = File.OpenRead(file.FullName))
- {
- var header = new byte[4];
- stream.Read(header, 0, header.Length);
- var headerString = Encoding.ASCII.GetString(header);
- stream.Position = 0;
- if (headerString == "warc")
- {
- var key = new byte[2048];
- stream.Read(key, 0, key.Length);
- var keyBase64 = Convert.ToBase64String(key);
- if (OnlyKey)
- {
- Console.WriteLine($"{Path.GetFileName(file.FullName)}:{keyBase64}");
- continue;
- }
- stream.Position = 0;
- using (var warc = new WarcArc(stream))
- {
- Console.WriteLine($"File name: {file.Name}");
- Console.WriteLine("ARC type: WARC");
- Console.WriteLine($"ARC Name: {warc.Name}");
- Console.WriteLine($"File count: {warc.Entries.Count()}");
- Console.WriteLine($"Decryption key: {keyBase64}");
- }
- }
- else if (headerString == "warp")
- {
- if (OnlyKey)
- continue;
- Console.WriteLine($"File name: {file.Name}");
- Console.WriteLine("ARC type: WARP");
- using (var br = new BinaryReader(stream))
- {
- Console.WriteLine(
- $"Needs a decryption key from the following ARC: {WarpArc.GetKeyWarpName(br)}");
- }
- }
- else
- {
- return Errors.Error(Errors.ErrorCodes.UnknownArcType, file.Name);
- }
- }
- }
- return 0;
- }
- public IEnumerable<string> Input { get; set; }
- }
- }
|