Skip to content

Commit

Permalink
added an option to remove encrypted files after decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck-rOOt committed Aug 24, 2016
1 parent 0e87a9c commit 27a4160
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
33 changes: 33 additions & 0 deletions LyndaDecryptor/LyndaDecryptor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -52,6 +67,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>lynda-logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -69,6 +87,21 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="lynda-logo.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.102.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.102.0\build\net45\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
59 changes: 41 additions & 18 deletions LyndaDecryptor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ namespace LyndaDecryptor
[Flags]
enum Mode
{
None,
Single,
Folder,
DB_Usage
None = 1,
Single = 2,
Folder = 4,
DB_Usage = 8,
RemoveFiles = 16
};

class Program
Expand All @@ -38,8 +39,6 @@ static void Main(string[] args)
{
try
{


int arg_index = 0;

foreach (string arg in args)
Expand All @@ -57,11 +56,13 @@ static void Main(string[] args)
{
directory = args[arg_index + 1];
usage_mode = Mode.Folder;
WriteToConsole("[ARGS] Changing mode to Folder decryption!", ConsoleColor.Yellow);
}
else
{
WriteToConsole("[ARGS] The directory path is missing..." + Environment.NewLine, ConsoleColor.Red);
Usage();
return;
goto End;
}
break;

Expand All @@ -71,11 +72,14 @@ static void Main(string[] args)
file_source = args[arg_index + 1];
file_destination = args[arg_index + 2];
usage_mode = Mode.Single;
WriteToConsole("[ARGS] Changing mode to Single decryption!", ConsoleColor.Yellow);

}
else
{
WriteToConsole("[ARGS] Some relevant args are missing..." + Environment.NewLine, ConsoleColor.Red);
Usage();
return;
goto End;
}
break;

Expand All @@ -85,25 +89,32 @@ static void Main(string[] args)
if (args.Length-1 > arg_index && File.Exists(args[arg_index + 1]))
db_path = args[arg_index + 1];
break;

case "/RM":
usage_mode |= Mode.RemoveFiles;
WriteToConsole("[ARGS] Removing files after decryption..." + Environment.NewLine, ConsoleColor.Yellow);
WriteToConsole("[ARGS] Press any key to continue..." + Environment.NewLine, ConsoleColor.Yellow);
Console.ReadKey();
break;
}

arg_index++;
}

if(usage_mode.HasFlag(Mode.None))
if((usage_mode & Mode.None) == Mode.None)
{
Usage();
goto End;
}
else
InitDecryptor();

if (usage_mode.HasFlag(Mode.DB_Usage))
if ((usage_mode & Mode.DB_Usage) == Mode.DB_Usage)
InitDB();

if (usage_mode.HasFlag(Mode.Folder))
DecryptAll(directory, usage_mode.HasFlag(Mode.DB_Usage));
else if (usage_mode.HasFlag(Mode.Single))
if ((usage_mode & Mode.Folder) == Mode.Folder)
DecryptAll(directory, (usage_mode & Mode.DB_Usage) == Mode.DB_Usage);
else if ((usage_mode & Mode.Single) == Mode.Single)
Decrypt(file_source, file_destination);


Expand Down Expand Up @@ -166,14 +177,14 @@ private static void InitDecryptor()

static void Usage()
{
Console.WriteLine("Usage (Directory): LyndaDecryptor /D PATH_TO_FOLDER");
Console.WriteLine("Usage (Single File): LyndaDecryptor /F ENCRYPTED_FILE DECRYPTED_FILE");
Console.WriteLine("Usage (with Database): LyndaDecryptor /D PATH_TO_FOLDER /DB PATH_TO_DATABASE");
Console.WriteLine("Usage (Directory): LyndaDecryptor /D PATH_TO_FOLDER [OPTIONS]");
Console.WriteLine("Usage (File): LyndaDecryptor /F ENCRYPTED_FILE DECRYPTED_FILE [OPTIONS]");

Console.WriteLine(Environment.NewLine + Environment.NewLine + "Flags: ");
Console.WriteLine("\t/D\tSource files are located in a folder.");
Console.WriteLine("\t/F\tSource and Destination file are specified.");
Console.WriteLine("\t/DB\tSearch for Database or specify the location on your system.");
Console.WriteLine("\t/RM\tRemoves all files after decryption is complete.");
}

static async void DecryptAll(string folderPath, bool useDB = false)
Expand Down Expand Up @@ -253,7 +264,16 @@ static async void DecryptAll(string folderPath, bool useDB = false)
static void Decrypt(string encryptedFilePath, string decryptedFilePath)
{
if (!File.Exists(encryptedFilePath))
throw new FileNotFoundException();
{
WriteToConsole("[ERR] Couldn't find encrypted file...", ConsoleColor.Red);
return;
}

if(File.Exists(decryptedFilePath))
{
WriteToConsole("[DEC] File " + decryptedFilePath + " exists already and will be skipped!", ConsoleColor.Yellow);
return;
}

FileInfo encryptedFileInfo = new FileInfo(encryptedFilePath);
byte[] buffer = new byte[0x500000];
Expand All @@ -269,7 +289,7 @@ static void Decrypt(string encryptedFilePath, string decryptedFilePath)
using (CryptoStream decryptionStream = new CryptoStream(inStream, decryptor, CryptoStreamMode.Read))
using (FileStream outStream = new FileStream(decryptedFilePath, FileMode.Create))
{
WriteToConsole("[DEC] Decrypting file" + encryptedFileInfo.Name + "...");
WriteToConsole("[DEC] Decrypting file " + encryptedFileInfo.Name + "...");

while ((inStream.Length - inStream.Position) >= buffer.Length)
{
Expand All @@ -285,6 +305,9 @@ static void Decrypt(string encryptedFilePath, string decryptedFilePath)
WriteToConsole("[DEC] File decryption completed: " + decryptedFilePath, ConsoleColor.DarkGreen);
}
}

if((usage_mode & Mode.RemoveFiles) == Mode.RemoveFiles)
encryptedFileInfo.Delete();
}

static void WriteToConsole(string Text, ConsoleColor color = ConsoleColor.Gray)
Expand Down
Binary file added LyndaDecryptor/lynda-logo.ico
Binary file not shown.
Binary file added LyndaDecryptor/lynda-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 27a4160

Please sign in to comment.