diff --git a/HashingCmd/App.config b/HashingCmd/App.config new file mode 100644 index 0000000000000000000000000000000000000000..8e15646352ec1d9a84bbc6504ef6b46e16bf7823 --- /dev/null +++ b/HashingCmd/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> + </startup> +</configuration> \ No newline at end of file diff --git a/HashingCmd/HashingCmd.csproj b/HashingCmd/HashingCmd.csproj new file mode 100644 index 0000000000000000000000000000000000000000..ec77475b5e1d27daccf5e9a1ded6325072c8c14b --- /dev/null +++ b/HashingCmd/HashingCmd.csproj @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{33F9848E-9257-4BE2-915F-68E748AEB204}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>HashingCmd</RootNamespace> + <AssemblyName>hashingcmd</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Properties\Version.cs"> + <DependentUpon>Version.tt</DependentUpon> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + </Compile> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="Properties\Version.tt"> + <Generator>TextTemplatingFileGenerator</Generator> + <LastGenOutput>Version.cs</LastGenOutput> + </None> + </ItemGroup> + <ItemGroup> + <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\VectoCommon\VectoHashing\VectoHashing.csproj"> + <Project>{B673E12F-D323-4C4C-8805-9915B2C72D3D}</Project> + <Name>VectoHashing</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file diff --git a/HashingCmd/Program.cs b/HashingCmd/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..0d63d73d9b8e8cdecd4fc0559e50280ce4f8645e --- /dev/null +++ b/HashingCmd/Program.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using TUGraz.VectoHashing; + +namespace HashingCmd +{ + class Program + { + public delegate void HashingAction(VectoHash h); + + private const string Usage = @" +hashingcmd.exe -v <file.xml> + +"; + + private const string Help = @" +hashingcmd.exe + +-h: help +-v: verify hashed file +-s: create hashed file file +-c: compute hash and write to stdout +-r: read hash from file and write to stdout +"; + + static Dictionary<string, HashingAction> actions = new Dictionary<string, HashingAction>(); + + static int Main(string[] args) + { + try { + if (args.Contains("-h")) { + ShowVersionInformation(); + Console.Write(Help); + return 0; + } + actions["-v"] = VerifyHashAction; + actions["-c"] = ComputeHashAction; + actions["-r"] = ReadHashAction; + actions["-s"] = CreateHashedFileAction; + + var fileList = args.Except(actions.Keys); + foreach (var file in fileList) { + WriteLine("processing " + Path.GetFileName(file)); + foreach (var arg in args) { + if (actions.ContainsKey(arg)) { + try { + var h = VectoHash.Load(file); + actions[arg](h); + } catch (Exception e) { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(e.Message); + Console.ResetColor(); + } + } + } + } + } catch (Exception e) { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine(e.Message); + Console.ResetColor(); + + //Console.Error.WriteLine("Please see log-file for further details (logs/log.txt)"); + Environment.ExitCode = Environment.ExitCode != 0 ? Environment.ExitCode : 1; + } +#if DEBUG + Console.WriteLine("done."); + Console.ReadKey(); +#endif + return Environment.ExitCode; + } + + private static void CreateHashedFileAction(VectoHash h) + { + h.AddHash(); + } + + private static void ReadHashAction(VectoHash h) + { + var components = h.GetContainigComponents(); + foreach (var component in components) { + var readHash = h.ReadHash(); + WriteLine(" " + component.XMLElementName() + "\t ... " + readHash); + } + } + + private static void ComputeHashAction(VectoHash h) + { + var hash = h.ComputeHash(); + WriteLine("computed hash: <" + hash + ">"); + } + + private static void VerifyHashAction(VectoHash h) + { + WriteLine("validating hashes"); + + var components = h.GetContainigComponents(); + foreach (var component in components) { + var result = h.ValidateHash(component); + + WriteLine(" " + component.XMLElementName() + "\t ... " + (result ? "valid" : "invalid"), + result ? ConsoleColor.Green : ConsoleColor.Red); + } + } + + private static void WriteLine(string message, ConsoleColor foregroundColor = ConsoleColor.Gray) + { + Console.ForegroundColor = foregroundColor; + Console.WriteLine(message); + Console.ResetColor(); + } + + private static void ShowVersionInformation() + { + var hashingLib = AssemblyName.GetAssemblyName("VectoHashing.dll"); + WriteLine(string.Format(@"HashingLibrary: {0}", hashingLib.Version)); + } + } +} \ No newline at end of file diff --git a/HashingCmd/Properties/AssemblyInfo.cs b/HashingCmd/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000000000000000000000000000000..30e4883fd8013b0a1991200c23b923b4180612ca --- /dev/null +++ b/HashingCmd/Properties/AssemblyInfo.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("HashingCmd")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HashingCmd")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("d476e18e-1c6a-434c-806c-ee52b13c4ef9")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/HashingCmd/Properties/Version.cs b/HashingCmd/Properties/Version.cs new file mode 100644 index 0000000000000000000000000000000000000000..109c12aa52a7a912a12fe6927b14b9eaa5bcb4f7 --- /dev/null +++ b/HashingCmd/Properties/Version.cs @@ -0,0 +1,34 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2016 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +using System.Reflection; +[assembly: AssemblyVersion("0.1.0.127")] +[assembly: AssemblyFileVersion("0.1.0.127")] diff --git a/HashingCmd/Properties/Version.tt b/HashingCmd/Properties/Version.tt new file mode 100644 index 0000000000000000000000000000000000000000..ce60176128751b903ebfe4cab78a59db0ace3308 --- /dev/null +++ b/HashingCmd/Properties/Version.tt @@ -0,0 +1,39 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2016 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +<#@ template language="C#" #> +<#@ output extension=".cs"#> +using System.Reflection; +[assembly: AssemblyVersion("0.1.0.<#= this.RevisionNumber #>")] +[assembly: AssemblyFileVersion("0.1.0.<#= this.RevisionNumber #>")] +<#+ + int RevisionNumber = (int)(DateTime.UtcNow - new DateTime(2017, 1, 1)).TotalDays; +#> \ No newline at end of file diff --git a/HashingTool/HashingTool.csproj b/HashingTool/HashingTool.csproj index c5688cee8ed1295530588108aef1401e59929d8c..7fd102e465c75cba559d046dce36637f2425dd54 100644 --- a/HashingTool/HashingTool.csproj +++ b/HashingTool/HashingTool.csproj @@ -53,6 +53,11 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition> + <Compile Include="Properties\Version.cs"> + <DependentUpon>Version.tt</DependentUpon> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + </Compile> <Page Include="MainWindow.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -89,10 +94,17 @@ <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> <AppDesigner Include="Properties\" /> + <None Include="Properties\Version.tt"> + <Generator>TextTemplatingFileGenerator</Generator> + <LastGenOutput>Version.cs</LastGenOutput> + </None> </ItemGroup> <ItemGroup> <None Include="App.config" /> </ItemGroup> + <ItemGroup> + <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. diff --git a/VECTO.sln b/VECTO.sln index 7036956263b6c4f2dfb0944ca55f0a7c9c7b9187..f6601e5fd41736ec568ec48329b1322282b60441 100644 --- a/VECTO.sln +++ b/VECTO.sln @@ -62,6 +62,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoHashingTest", "VectoCo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashingTool", "HashingTool\HashingTool.csproj", "{E14FC935-30EA-4BE6-AA8A-85CB76FEBA6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashingCmd", "HashingCmd\HashingCmd.csproj", "{33F9848E-9257-4BE2-915F-68E748AEB204}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -256,6 +258,14 @@ Global {E14FC935-30EA-4BE6-AA8A-85CB76FEBA6A}.Release|Any CPU.Build.0 = Release|Any CPU {E14FC935-30EA-4BE6-AA8A-85CB76FEBA6A}.Release|x64.ActiveCfg = Release|Any CPU {E14FC935-30EA-4BE6-AA8A-85CB76FEBA6A}.Release|x86.ActiveCfg = Release|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Debug|x64.ActiveCfg = Debug|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Debug|x86.ActiveCfg = Debug|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Release|Any CPU.Build.0 = Release|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Release|x64.ActiveCfg = Release|Any CPU + {33F9848E-9257-4BE2-915F-68E748AEB204}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -279,6 +289,5 @@ Global {7C364099-9B85-473A-8A42-BBEBE4798FF5} = {CC93EA68-F3FE-4BCB-9292-1101F94A4D09} {B673E12F-D323-4C4C-8805-9915B2C72D3D} = {73A5BF70-6168-456F-95E5-A1402BFA488C} {760C1C5B-A767-463E-BA85-F0BCFC23A550} = {73A5BF70-6168-456F-95E5-A1402BFA488C} - {E14FC935-30EA-4BE6-AA8A-85CB76FEBA6A} = {73A5BF70-6168-456F-95E5-A1402BFA488C} EndGlobalSection EndGlobal