static int Main(string[] args) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.OSArchitecture != Architecture.X64) { Console.Error.WriteLine("This tool only supports x64 Windows"); return(10); } var argumentModel = Configuration.Configure <CommandParameters>(); CommandParameters command; try { command = argumentModel.CreateAndBind(args); if (!string.IsNullOrEmpty(command.MsSign32Path) && !Path.IsPathRooted(command.MsSign32Path)) { // https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibraryexa#searching-for-dlls-and-dependencies Console.Error.WriteLine("Specifying a relative path for the MSSign32.dll is not supported"); return(9); } } catch (Exception) { PrintHelp(argumentModel); return(1); } try { CodeSigner.SignFile(command.Thumbprint, command.Pin, command.PrivateKeyContainer, command.Store, command.Path, command.TimestampUrl, command.Mode, command.MsSign32Path, new Logger(command.IsVerboseLoggingEnabled)); return(0); } catch (SigningException ex) { Console.Error.WriteLine("Signing operation failed. Error details:"); Console.Error.WriteLine(ex.GetBaseException().Message); return(2); } }
static int Main(string[] args) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.OSArchitecture != Architecture.X64) { Console.Error.WriteLine("This tool only supports x64 Windows"); return(10); } if (args.Length != 7) { Console.WriteLine("usage: signer.exe <certificate thumbprint> <private key container name> <target store> <token PIN> <timestamp URL> <path to file to sign>"); Console.WriteLine("storeString = (appx|pe)"); Console.WriteLine("target store = (user|machine)"); return(1); } int index = 0; var certHash = args[index++]; var containerName = args[index++]; var targetStore = args[index++]; var tokenPin = args[index++]; var timestampUrl = args[index++]; var mode = args[index++]; var fileToSign = args[index++]; try { var signMode = ParseMode(mode); var store = ParseStore(targetStore); CodeSigner.SignFile(certHash, tokenPin, containerName, store, fileToSign, timestampUrl, signMode, Console.WriteLine); return(0); } catch (SigningException ex) { Console.Error.WriteLine("Signing operation failed. Error details:"); Console.Error.WriteLine(ex.GetBaseException().Message); return(2); } }