-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecloakForm.cs
More file actions
195 lines (173 loc) · 6.53 KB
/
DecloakForm.cs
File metadata and controls
195 lines (173 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.IO;
using System.Windows.Forms;
using Stealth_Compressor.Properties;
namespace Stealth_Compressor
{
public partial class DecloakForm : Form
{
// Create an archive object for accessing later
// This is so we don't have to search for the archive
// twice in the byte stream.
internal StealthArchive stealth;
private bool isEncrypted;
public DecloakForm()
{
InitializeComponent();
this.Icon = Resources.Stealth;
this.ShowIcon = true;
txt_Input.Text = string.Empty;
sts_Main_Seperator.Text = string.Empty;
statusCheck();
col_Size.Text = string.Format("File Size ({0})", Settings.Default.UNITS);
isEncrypted = false;
grp_Output.Enabled = false;
}
private void btn_Input_Click(object sender, EventArgs e)
{
opn_Cloaked.CheckFileExists = true;
opn_Cloaked.CheckPathExists = true;
opn_Cloaked.Multiselect = false;
opn_Cloaked.Filter = "All Files (*.*)|*.*";
opn_Cloaked.FilterIndex = 1;
opn_Cloaked.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
if (opn_Cloaked.ShowDialog() == DialogResult.OK)
{
txt_Input.Text = opn_Cloaked.FileName;
lst_Files.Items.Clear();
canExtract(false);
lbl_Status.Text = "Press 'Decloak' to reveal hidden files...";
}
}
private void btn_Output_Click(object sender, EventArgs e)
{
bws_Output.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
bws_Output.ShowNewFolderButton = true;
if (bws_Output.ShowDialog() == DialogResult.OK)
{
txt_Output.Text = bws_Output.SelectedPath;
statusCheck();
}
}
private void btn_Decloak_Click(object sender, EventArgs e)
{
if (File.Exists(txt_Input.Text))
{
stealth = new StealthArchive(txt_Input.Text);
try
{
foreach (Ionic.Zip.ZipEntry entry in stealth.GetCloakedEntries(StealthArchive.ArchiveType.Zip))
{
ListViewItem item = new ListViewItem();
item.Name = entry.FileName;
item.Text = item.Name;
if (entry.UsesEncryption)
{
item.Text += "*";
isEncrypted = true;
}
item.SubItems.Add((MainForm.formatFileSize(entry.UncompressedSize, Settings.Default.UNITS)));
item.SubItems.Add((entry.CompressionRatio * .01).ToString("0%"));
item.SubItems.Add(entry.Encryption.ToString());
lst_Files.Items.Add(item);
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error de-cloaking file: {0}", ex.Message), "De-Cloak",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (lst_Files.Items.Count > 0)
{
canExtract(true);
lbl_Status.Text = "Select files to extract...";
}
else
{
MessageBox.Show("This file contains no cloaked data.","De-CLoak", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txt_Input.Clear();
statusCheck();
return;
}
}
}
private void btn_Extract_Click(object sender, EventArgs e)
{
enableForm(false);
string[] files = new string[lst_Files.CheckedItems.Count];
for (int i = 0; i < lst_Files.CheckedItems.Count; i++)
{
files[i] = lst_Files.CheckedItems[i].Name;
}
if (isEncrypted)
{
stealth.ExtractCloakedFiles(files, txt_Output.Text, true, getPassword(false));
}
else
{
stealth.ExtractCloakedFiles(files, txt_Output.Text, true);
}
lbl_Status.Text = string.Format("{0} files extracted!", files.Length);
enableForm(true);
}
private void canExtract(bool value)
{
btn_Extract.Visible = value;
btn_Decloak.Visible = !value;
statusCheck();
}
private void statusCheck()
{
if (txt_Input.Text == string.Empty)
{
lbl_Status.Text = lbl_Status.Text = "Choose a cloaked file...";
btn_Decloak.Enabled = false;
return;
}
btn_Decloak.Enabled = true;
if ((lst_Files.CheckedItems.Count > 0) && (txt_Output.Text == string.Empty))
{
lbl_Status.Text = "Choose an output directory...";
return;
}
if ((lst_Files.CheckedItems.Count > 0) && (txt_Output.Text != string.Empty))
{
btn_Extract.Enabled = true;
lbl_Status.Text = "Press 'Extract' to begin!";
return;
}
btn_Extract.Enabled = false;
}
private void enableForm(bool choice)
{
grp_Input.Enabled = choice;
grp_Output.Enabled = choice;
lst_Files.Enabled = choice;
}
private void clearForm()
{
canExtract(false);
lst_Files.Items.Clear();
txt_Output.Clear();
statusCheck();
isEncrypted = false;
}
// Prompts the user for password entry
private string getPassword(bool validate)
{
// Update the status label
lbl_Status.Text = "Setting archive password...";
PassForm pass = new PassForm(validate);
pass.StartPosition = FormStartPosition.CenterParent;
pass.ShowDialog(this);
return pass.Password;
}
private void lst_Files_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (lst_Files.CheckedItems.Count > 0) grp_Output.Enabled = true;
else grp_Output.Enabled = false;
statusCheck();
}
}
}