Decode console application project added.

This commit is contained in:
Milan Hanajik 2019-07-10 10:02:36 +02:00
parent df5b240397
commit ed21afd82e
8 changed files with 235 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
Config/bin/
Config/obj/
Decode/bin/
Decode/obj/
DeviceTest/bin/
DeviceTest/obj/
Dirichlet.Numerics/bin

64
Decode/Decode.csproj Normal file
View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D476ABBE-A455-4476-8A8D-3F6151217B51}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Decode</RootNamespace>
<AssemblyName>Decode</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Decode.Program</StartupObject>
</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" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</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>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>config.xml</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<StartArguments>config.xml</StartArguments>
</PropertyGroup>
</Project>

107
Decode/Program.cs Normal file
View File

@ -0,0 +1,107 @@
using System;
using System.IO;
using System.Security.Cryptography;
namespace Decode
{
class Program
{
static byte[] cryptoKey = new byte[] { 235, 7, 236, 58, 24, 225, 97, 102, 231, 1, 121, 12, 177, 145, 87, 200,
102, 85, 152, 73, 230, 203, 101, 169, 242, 213, 228, 219, 239, 157, 245, 156 };
static byte[] cryptoIV = new byte[] { 189, 23, 137, 56, 204, 241, 242, 118, 28, 89, 9, 198, 224, 111, 186, 125 };
static void Main(string[] args)
{
if ((args.Length < 1) || !File.Exists(args[0]))
{
Console.WriteLine("Usage: Decode <file>");
Console.ReadKey();
return;
}
string fileName = args[0];
try
{
using (StreamReader reader = new StreamReader(fileName))
{
if (reader.ReadLine().StartsWith("<?xml version="))
{
Console.WriteLine(string.Format("File {0} was not encrypted.", fileName));
Console.ReadKey();
return;
}
}
bool successful = false;
Stream stream = File.OpenRead(fileName);
using (BinaryReader binaryReader = new BinaryReader(stream))
{
int length = (int)(new FileInfo(fileName).Length);
/// Load encrypted binary data into an array
byte[] encrypted = new byte[length];
int bytesRead = binaryReader.Read(encrypted, 0, length);
if (bytesRead != length)
{
Console.WriteLine(string.Format("Failed to read file {0}.", fileName));
Console.ReadKey();
return;
}
using (RijndaelManaged myRijndael = new RijndaelManaged())
{
/// Create a decryptor to perform the stream transform.
ICryptoTransform decryptor = myRijndael.CreateDecryptor(cryptoKey, cryptoIV);
/// Create the streams used for decryption.
using (MemoryStream msDecrypt = new MemoryStream(encrypted))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
using (TextWriter writer = new StreamWriter(fileName + ".plain"))
{
writer.Write(srDecrypt.ReadToEnd());
successful = true;
}
}
}
}
}
}
if (successful)
{
/// Decoding the file was successfuly completed => rotate files
if (File.Exists(fileName + ".bak")) File.Delete(fileName + ".bak");
File.Move(fileName, fileName + ".bak");
File.Move(fileName + ".plain", fileName);
return;
}
else
{
Failed(fileName);
return;
}
}
catch (Exception)
{
Failed(fileName);
return;
}
}
static void Failed(string fileName)
{
if (File.Exists(fileName + ".plain"))
{
File.Delete(fileName + ".plain");
}
Console.WriteLine(string.Format("Decoding file {0} failed.", fileName));
Console.ReadKey();
}
}
}

View File

@ -0,0 +1,36 @@
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("Decode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Decode")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[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("c17ec788-0e12-4f9c-aadf-ea4e83a9f373")]
// 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.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

3
Decode/app.config Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

12
TBF.sln
View File

@ -48,6 +48,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GemCard", "GemCard\GemCard.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Statistics", "Statistics\Statistics.csproj", "{36755E1D-6FC3-4D9C-8DD3-0250D51532E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decode", "Decode\Decode.csproj", "{D476ABBE-A455-4476-8A8D-3F6151217B51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -186,6 +188,16 @@ Global
{36755E1D-6FC3-4D9C-8DD3-0250D51532E0}.Release|Mixed Platforms.Build.0 = Release|x86
{36755E1D-6FC3-4D9C-8DD3-0250D51532E0}.Release|x86.ActiveCfg = Release|x86
{36755E1D-6FC3-4D9C-8DD3-0250D51532E0}.Release|x86.Build.0 = Release|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Debug|Any CPU.ActiveCfg = Debug|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Debug|Mixed Platforms.Build.0 = Debug|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Debug|x86.ActiveCfg = Debug|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Debug|x86.Build.0 = Debug|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Release|Any CPU.ActiveCfg = Release|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Release|Mixed Platforms.ActiveCfg = Release|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Release|Mixed Platforms.Build.0 = Release|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Release|x86.ActiveCfg = Release|x86
{D476ABBE-A455-4476-8A8D-3F6151217B51}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,5 +1,7 @@
rmdir /s /q Config\bin
rmdir /s /q Config\obj
rmdir /s /q Decode\bin
rmdir /s /q Decode\obj
rmdir /s /q DeviceTest\bin
rmdir /s /q DeviceTest\obj
rmdir /s /q Dirichlet.Numerics\bin