├── Resources ├── ico.ico └── refesh.png ├── App.config ├── packages.config ├── Properties ├── Settings.settings ├── Settings.Designer.cs ├── AssemblyInfo.cs ├── Resources.Designer.cs └── Resources.resx ├── Program.cs ├── TiKey.sln ├── .gitattributes ├── README.md ├── app.manifest ├── TiKey.csproj ├── .gitignore ├── MainForm.Designer.cs └── MainForm.cs /Resources/ico.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liamhnam/TiKey/HEAD/Resources/ico.ico -------------------------------------------------------------------------------- /Resources/refesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liamhnam/TiKey/HEAD/Resources/refesh.png -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace TiKey 8 | { 9 | internal static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new MainForm()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TiKey.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.13.35913.81 d17.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiKey", "TiKey.csproj", "{566B7578-4D98-49D4-877A-28B58115C4C6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {566B7578-4D98-49D4-877A-28B58115C4C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {566B7578-4D98-49D4-877A-28B58115C4C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {566B7578-4D98-49D4-877A-28B58115C4C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {566B7578-4D98-49D4-877A-28B58115C4C6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9D77701D-F016-4FEF-871A-B6DF6BE961B7} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TiKey.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TiKey")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("TIKOTEK")] 12 | [assembly: AssemblyProduct("TiKey")] 13 | [assembly: AssemblyCopyright("Copyright © TIKOTEK")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("566b7578-4d98-49d4-877a-28b58115c4c6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔐 TiKey – Phần mềm tạo và sử dụng USB mã hóa dễ dàng 2 | 3 | **TiKey** là phần mềm giúp bạn tạo một USB bảo mật bằng mã hóa mạnh, bảo vệ dữ liệu cá nhân khỏi truy cập trái phép. 4 | Không cần hiểu kỹ thuật, không cần cài phần mềm rắc rối – chỉ cần làm theo vài bước đơn giản là bạn đã có một USB riêng tư, chỉ bạn mới mở được. 5 | 6 | --- 7 | 8 | ## 🧾 Tính năng nổi bật 9 | 10 | - ✅ Tạo USB bảo mật bằng mã hóa chuẩn mạnh 11 | - 🔐 Đặt mật khẩu riêng để bảo vệ dữ liệu 12 | - 🧽 Xóa toàn bộ USB và chuẩn bị lại từ đầu (Reset) 13 | - 💻 Hoạt động hoàn toàn tự động, không cần cài thêm phần mềm ngoài 14 | - 🪟 Giao diện dễ dùng, hỗ trợ tiếng Việt 15 | 16 | --- 17 | 18 | ## 📦 Bạn cần chuẩn bị 19 | 20 | - Một **USB trống** hoặc chấp nhận **xóa toàn bộ dữ liệu trong USB** 21 | - Một máy tính Windows (Windows 7 trở lên) 22 | 23 | --- 24 | 25 | ## 🚀 Hướng dẫn sử dụng 26 | 27 | ### 🔧 BƯỚC 1: Cắm USB vào máy 28 | 29 | 1. Mở phần mềm `TiKey.exe` 30 | 2. Giao diện chính sẽ hiện ra và **tự động nhận USB** 31 | 3. Nếu không thấy USB xuất hiện, nhấn nút **"Tải lại"** 32 | 33 | --- 34 | 35 | ### 📝 BƯỚC 2: Cài đặt USB mã hóa 36 | 37 | 1. **Chọn USB** trong danh sách thiết bị 38 | 2. **Nhập mật khẩu** bạn muốn dùng để bảo vệ dữ liệu 39 | 3. Nhập lại mật khẩu để xác nhận 40 | 4. Nhấn nút **"Cài đặt"** 41 | 42 | > ⚠ **Lưu ý:** Sau bước này, toàn bộ dữ liệu trong USB sẽ bị xóa. 43 | 44 | 5. Quá trình sẽ: 45 | - Tự động xóa/format USB 46 | - Tạo vùng chứa mã hóa bằng mật khẩu bạn đã nhập 47 | - Cài các file cần thiết 48 | 49 | 6. Khi hoàn tất, sẽ có thông báo. Bạn có thể rút USB ra và sử dụng như bình thường. 50 | 51 | --- 52 | 53 | ### 🔓 BƯỚC 3: Mở USB để sử dụng 54 | 55 | 1. Mỗi lần cắm USB đã được mã hóa: 56 | - Chạy lại phần mềm TiKey 57 | - Nhập đúng mật khẩu 58 | - USB sẽ được **mở khóa** 59 | 2. Nếu chọn chế độ **chỉ đọc**, bạn có thể xem dữ liệu nhưng không chỉnh sửa 60 | 61 | --- 62 | 63 | ### 🔁 BƯỚC 4: Reset nếu cần dùng lại USB từ đầu 64 | 65 | 1. Mở phần mềm, chọn đúng USB 66 | 2. Nhấn **Reset** 67 | 3. Xác nhận để xóa và format lại USB 68 | 4. USB sẽ trở về trạng thái trống, không mã hóa 69 | 70 | --- 71 | 72 | ## 🛟 Mẹo an toàn 73 | 74 | - Hãy **nhớ mật khẩu** – nếu quên, **không thể khôi phục dữ liệu** 75 | - Không chia sẻ phần mềm hoặc USB đã cài đặt nếu không muốn bị truy cập trái phép 76 | - Nếu không chắc chắn thiết bị USB là gì, đừng chọn bừa – có thể chọn nhầm ổ đĩa 77 | 78 | --- 79 | 80 | ## 📌 Câu hỏi thường gặp 81 | 82 | ### ❓ Nếu tôi quên mật khẩu thì sao? 83 | 👉 Rất tiếc, không thể mở khóa. Bạn phải reset và mất toàn bộ dữ liệu cũ. 84 | 85 | ### ❓ USB sau khi mã hóa có dùng bình thường được không? 86 | 👉 Có, nhưng cần chạy phần mềm TiKey để mở khóa trước khi sử dụng. 87 | 88 | ### ❓ Phần mềm có an toàn không? 89 | 👉 TiKey sử dụng công cụ mã hóa từ **VeraCrypt**, phần mềm bảo mật nổi tiếng, được nhiều tổ chức tin dùng. 90 | 91 | --- 92 | 93 | ## 👤 Liên hệ hỗ trợ 94 | 95 | - Email: hoangnam.liam@gmail.com 96 | 97 | --- 98 | 99 | 100 | -------------------------------------------------------------------------------- /app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 55 | 63 | 64 | 65 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TiKey.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TiKey.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap Paomedia_Small_N_Flat_Lock_512 { 67 | get { 68 | object obj = ResourceManager.GetObject("Paomedia-Small-N-Flat-Lock.512", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap refesh { 77 | get { 78 | object obj = ResourceManager.GetObject("refesh", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /TiKey.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {566B7578-4D98-49D4-877A-28B58115C4C6} 8 | WinExe 9 | TiKey 10 | TiKey 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | app.manifest 37 | 38 | 39 | Resources\ico.ico 40 | 41 | 42 | 43 | 44 | packages\System.CodeDom.9.0.4\lib\net462\System.CodeDom.dll 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Form 61 | 62 | 63 | MainForm.cs 64 | 65 | 66 | 67 | 68 | MainForm.cs 69 | 70 | 71 | ResXFileCodeGenerator 72 | Resources.Designer.cs 73 | Designer 74 | 75 | 76 | True 77 | Resources.resx 78 | True 79 | 80 | 81 | 82 | 83 | SettingsSingleFileGenerator 84 | Settings.Designer.cs 85 | 86 | 87 | True 88 | Settings.settings 89 | True 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\refesh.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\ico.ico;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace TiKey 2 | { 3 | partial class MainForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); 32 | this.btnReload = new System.Windows.Forms.Button(); 33 | this.cbbUSB = new System.Windows.Forms.ComboBox(); 34 | this.txtPw1 = new System.Windows.Forms.TextBox(); 35 | this.txtPw2 = new System.Windows.Forms.TextBox(); 36 | this.txtLog = new System.Windows.Forms.TextBox(); 37 | this.progressBar1 = new System.Windows.Forms.ProgressBar(); 38 | this.btnRun = new System.Windows.Forms.Button(); 39 | this.label1 = new System.Windows.Forms.Label(); 40 | this.label2 = new System.Windows.Forms.Label(); 41 | this.label4 = new System.Windows.Forms.Label(); 42 | this.btnReset = new System.Windows.Forms.Button(); 43 | this.SuspendLayout(); 44 | // 45 | // btnReload 46 | // 47 | this.btnReload.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 48 | this.btnReload.Location = new System.Drawing.Point(484, 19); 49 | this.btnReload.Name = "btnReload"; 50 | this.btnReload.Size = new System.Drawing.Size(78, 31); 51 | this.btnReload.TabIndex = 0; 52 | this.btnReload.Text = "Tải lại"; 53 | this.btnReload.UseVisualStyleBackColor = true; 54 | this.btnReload.Click += new System.EventHandler(this.btnReload_Click); 55 | // 56 | // cbbUSB 57 | // 58 | this.cbbUSB.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 59 | this.cbbUSB.FormattingEnabled = true; 60 | this.cbbUSB.Location = new System.Drawing.Point(141, 19); 61 | this.cbbUSB.Name = "cbbUSB"; 62 | this.cbbUSB.Size = new System.Drawing.Size(337, 28); 63 | this.cbbUSB.TabIndex = 1; 64 | // 65 | // txtPw1 66 | // 67 | this.txtPw1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 68 | this.txtPw1.Location = new System.Drawing.Point(186, 89); 69 | this.txtPw1.Name = "txtPw1"; 70 | this.txtPw1.PasswordChar = '*'; 71 | this.txtPw1.Size = new System.Drawing.Size(376, 26); 72 | this.txtPw1.TabIndex = 2; 73 | // 74 | // txtPw2 75 | // 76 | this.txtPw2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 77 | this.txtPw2.Location = new System.Drawing.Point(186, 121); 78 | this.txtPw2.Name = "txtPw2"; 79 | this.txtPw2.PasswordChar = '*'; 80 | this.txtPw2.Size = new System.Drawing.Size(376, 26); 81 | this.txtPw2.TabIndex = 3; 82 | // 83 | // txtLog 84 | // 85 | this.txtLog.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 86 | this.txtLog.Location = new System.Drawing.Point(16, 235); 87 | this.txtLog.Multiline = true; 88 | this.txtLog.Name = "txtLog"; 89 | this.txtLog.Size = new System.Drawing.Size(546, 177); 90 | this.txtLog.TabIndex = 4; 91 | // 92 | // progressBar1 93 | // 94 | this.progressBar1.Location = new System.Drawing.Point(16, 206); 95 | this.progressBar1.Name = "progressBar1"; 96 | this.progressBar1.Size = new System.Drawing.Size(546, 23); 97 | this.progressBar1.TabIndex = 5; 98 | // 99 | // btnRun 100 | // 101 | this.btnRun.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 102 | this.btnRun.ForeColor = System.Drawing.Color.DarkCyan; 103 | this.btnRun.Location = new System.Drawing.Point(145, 153); 104 | this.btnRun.Name = "btnRun"; 105 | this.btnRun.Size = new System.Drawing.Size(417, 47); 106 | this.btnRun.TabIndex = 6; 107 | this.btnRun.Text = "TẠO USB BẢO MẬT "; 108 | this.btnRun.UseVisualStyleBackColor = true; 109 | this.btnRun.Click += new System.EventHandler(this.btnRun_Click); 110 | // 111 | // label1 112 | // 113 | this.label1.AutoSize = true; 114 | this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 115 | this.label1.Location = new System.Drawing.Point(12, 22); 116 | this.label1.Name = "label1"; 117 | this.label1.Size = new System.Drawing.Size(114, 20); 118 | this.label1.TabIndex = 7; 119 | this.label1.Text = "USB đã cắm: "; 120 | // 121 | // label2 122 | // 123 | this.label2.AutoSize = true; 124 | this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 125 | this.label2.Location = new System.Drawing.Point(12, 92); 126 | this.label2.Name = "label2"; 127 | this.label2.Size = new System.Drawing.Size(82, 20); 128 | this.label2.TabIndex = 8; 129 | this.label2.Text = "Mật khẩu:"; 130 | // 131 | // label4 132 | // 133 | this.label4.AutoSize = true; 134 | this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 135 | this.label4.Location = new System.Drawing.Point(12, 124); 136 | this.label4.Name = "label4"; 137 | this.label4.Size = new System.Drawing.Size(148, 20); 138 | this.label4.TabIndex = 9; 139 | this.label4.Text = "Nhập lại mật khẩu:"; 140 | // 141 | // btnReset 142 | // 143 | this.btnReset.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 144 | this.btnReset.ForeColor = System.Drawing.Color.Crimson; 145 | this.btnReset.Location = new System.Drawing.Point(16, 153); 146 | this.btnReset.Name = "btnReset"; 147 | this.btnReset.Size = new System.Drawing.Size(123, 47); 148 | this.btnReset.TabIndex = 10; 149 | this.btnReset.Text = "Xoá USB"; 150 | this.btnReset.UseVisualStyleBackColor = true; 151 | this.btnReset.Click += new System.EventHandler(this.btnReset_Click); 152 | // 153 | // MainForm 154 | // 155 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 156 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 157 | this.ClientSize = new System.Drawing.Size(574, 428); 158 | this.Controls.Add(this.btnReset); 159 | this.Controls.Add(this.label4); 160 | this.Controls.Add(this.label2); 161 | this.Controls.Add(this.label1); 162 | this.Controls.Add(this.btnRun); 163 | this.Controls.Add(this.progressBar1); 164 | this.Controls.Add(this.txtLog); 165 | this.Controls.Add(this.txtPw2); 166 | this.Controls.Add(this.txtPw1); 167 | this.Controls.Add(this.cbbUSB); 168 | this.Controls.Add(this.btnReload); 169 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 170 | this.Name = "MainForm"; 171 | this.Text = "TiKey v1.0"; 172 | this.ResumeLayout(false); 173 | this.PerformLayout(); 174 | 175 | } 176 | 177 | #endregion 178 | 179 | private System.Windows.Forms.Button btnReload; 180 | private System.Windows.Forms.ComboBox cbbUSB; 181 | private System.Windows.Forms.TextBox txtPw1; 182 | private System.Windows.Forms.TextBox txtPw2; 183 | private System.Windows.Forms.TextBox txtLog; 184 | private System.Windows.Forms.ProgressBar progressBar1; 185 | private System.Windows.Forms.Button btnRun; 186 | private System.Windows.Forms.Label label1; 187 | private System.Windows.Forms.Label label2; 188 | private System.Windows.Forms.Label label4; 189 | private System.Windows.Forms.Button btnReset; 190 | } 191 | } -------------------------------------------------------------------------------- /MainForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Management; 11 | using System.Windows.Forms; 12 | using System.Diagnostics; 13 | using System.Text.RegularExpressions; 14 | using static System.Windows.Forms.VisualStyles.VisualStyleElement; 15 | 16 | namespace TiKey 17 | { 18 | public partial class MainForm : Form 19 | { 20 | private const int WM_DEVICECHANGE = 0x0219; 21 | private const int DBT_DEVICEARRIVAL = 0x8000; 22 | private const int DBT_DEVICEREMOVECOMPLETE = 0x8004; 23 | private const string USB_INTERFACE_TYPE = "USB"; 24 | private const string VERACRYPT_HIDDEN_FOLDER = ".DO_NOT_DELETE"; 25 | private const string AUTORUN_FOLDER = "AUTORUN.INF"; 26 | private const string DEFAULT_PASSWORD = "111"; 27 | 28 | public MainForm() 29 | { 30 | InitializeComponent(); 31 | LoadUSBDevices(); 32 | } 33 | 34 | protected override void WndProc(ref Message m) 35 | { 36 | base.WndProc(ref m); 37 | 38 | if (m.Msg == WM_DEVICECHANGE) 39 | { 40 | int wParam = m.WParam.ToInt32(); 41 | if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) 42 | { 43 | // Sử dụng BeginInvoke để tránh xung đột luồng 44 | BeginInvoke(new Action(LoadUSBDevices)); 45 | } 46 | } 47 | } 48 | 49 | private void LoadUSBDevices() 50 | { 51 | LogMessage("Đang tải danh sách thiết bị USB..."); 52 | cbbUSB.Items.Clear(); 53 | var usbDevices = new HashSet(); // Sử dụng HashSet để tránh trùng lặp 54 | 55 | try 56 | { 57 | using (var searcher = new ManagementObjectSearcher("SELECT Model FROM Win32_DiskDrive WHERE InterfaceType='" + USB_INTERFACE_TYPE + "'")) 58 | { 59 | foreach (ManagementObject device in searcher.Get()) 60 | { 61 | string name = device["Model"]?.ToString(); 62 | if (!string.IsNullOrWhiteSpace(name)) 63 | { 64 | usbDevices.Add(name); 65 | } 66 | } 67 | } 68 | 69 | // Thêm các thiết bị vào ComboBox 70 | foreach (var device in usbDevices) 71 | { 72 | cbbUSB.Items.Add(device); 73 | } 74 | 75 | // Cập nhật chọn lựa 76 | cbbUSB.SelectedIndex = cbbUSB.Items.Count > 0 ? 0 : -1; 77 | cbbUSB.Text = cbbUSB.SelectedIndex == -1 ? "" : cbbUSB.SelectedItem.ToString(); 78 | 79 | LogMessage($"Đã tìm thấy {usbDevices.Count} thiết bị USB."); 80 | } 81 | catch (Exception ex) 82 | { 83 | LogMessage($"Lỗi khi tải danh sách USB: {ex.Message}", true); 84 | MessageBox.Show($"Lỗi khi tải danh sách USB: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 85 | } 86 | } 87 | 88 | private void btnReload_Click(object sender, EventArgs e) 89 | { 90 | LoadUSBDevices(); 91 | } 92 | 93 | private int ExtractDiskNumber(string deviceId) 94 | { 95 | if (string.IsNullOrEmpty(deviceId)) return -1; 96 | 97 | var match = Regex.Match(deviceId, @"PHYSICALDRIVE(\d+)"); 98 | return match.Success ? int.Parse(match.Groups[1].Value) : -1; 99 | } 100 | 101 | private List GetUSBDriveLetters() 102 | { 103 | var result = new List(); 104 | try 105 | { 106 | using (var searcher = new ManagementObjectSearcher("SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType = 2")) 107 | { 108 | foreach (ManagementObject disk in searcher.Get()) 109 | { 110 | string driveLetter = disk["DeviceID"]?.ToString(); 111 | if (!string.IsNullOrEmpty(driveLetter)) 112 | { 113 | result.Add(driveLetter); 114 | } 115 | } 116 | } 117 | } 118 | catch (Exception ex) 119 | { 120 | LogMessage($"Lỗi khi tìm ký tự ổ đĩa USB: {ex.Message}", true); 121 | MessageBox.Show($"Lỗi khi tìm ký tự ổ đĩa USB: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 122 | } 123 | return result; 124 | } 125 | 126 | private async Task> WaitForUSBDriveLetters(int maxAttempts = 5) 127 | { 128 | LogMessage("Đang chờ hệ thống nhận diện USB..."); 129 | List usbDrives = new List(); 130 | int attempts = 0; 131 | 132 | while (usbDrives.Count == 0 && attempts < maxAttempts) 133 | { 134 | usbDrives = GetUSBDriveLetters(); 135 | if (usbDrives.Count == 0) 136 | { 137 | // Chờ một khoảng thời gian trước khi thử lại 138 | LogMessage($"Đang thử lại ({attempts + 1}/{maxAttempts})..."); 139 | await Task.Delay(1000); 140 | attempts++; 141 | } 142 | } 143 | 144 | if (usbDrives.Count > 0) 145 | { 146 | LogMessage($"Đã tìm thấy ổ USB: {string.Join(", ", usbDrives)}"); 147 | } 148 | else 149 | { 150 | LogMessage("Không tìm thấy ổ USB sau nhiều lần thử.", true); 151 | } 152 | 153 | return usbDrives; 154 | } 155 | 156 | private async Task CreateVeraCryptContainer(string driveLetter) 157 | { 158 | try 159 | { 160 | LogMessage("Đang kiểm tra ổ đĩa..."); 161 | UpdateProgress(60); 162 | 163 | // Kiểm tra ổ đĩa 164 | DriveInfo drive = new DriveInfo(driveLetter); 165 | if (!drive.IsReady) 166 | { 167 | LogMessage($"Ổ đĩa {driveLetter} chưa sẵn sàng.", true); 168 | MessageBox.Show($"Ổ đĩa {driveLetter} chưa sẵn sàng.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 169 | return false; 170 | } 171 | 172 | // Đường dẫn đến VeraCryptFormat.exe nằm trên USB 173 | string hiddenFolder = Path.Combine(driveLetter, VERACRYPT_HIDDEN_FOLDER); 174 | string veraCryptExe = Path.Combine(hiddenFolder, "VeraCryptFormat.exe"); 175 | string containerPath = Path.Combine(hiddenFolder, "vc-container.vc"); 176 | 177 | if (!File.Exists(veraCryptExe)) 178 | { 179 | LogMessage("Không tìm thấy VeraCryptFormat.exe trên USB!", true); 180 | MessageBox.Show("Không tìm thấy VeraCryptFormat.exe trên USB!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 181 | return false; 182 | } 183 | 184 | // Chuẩn bị tham số 185 | long availableSpace = drive.AvailableFreeSpace; 186 | LogMessage($"Không gian khả dụng: {availableSpace / (1024 * 1024)} MB"); 187 | LogMessage("Đang tạo container..."); 188 | UpdateProgress(70); 189 | 190 | string arguments = $"/create \"{containerPath}\" /size \"{availableSpace / (1024 * 1024)}\"M /password \"{txtPw1.Text}\" /encryption AES /filesystem FAT /quick /FastCreateFile /silent"; 191 | 192 | // Chuẩn bị thông tin tiến trình 193 | ProcessStartInfo psi = new ProcessStartInfo 194 | { 195 | FileName = veraCryptExe, 196 | Arguments = arguments, 197 | UseShellExecute = false, 198 | CreateNoWindow = true, 199 | RedirectStandardOutput = true 200 | }; 201 | 202 | // Thực thi tiến trình 203 | using (Process process = Process.Start(psi)) 204 | { 205 | LogMessage("Đang tạo container (quá trình này có thể mất vài phút)..."); 206 | await Task.Run(() => process.WaitForExit()); 207 | 208 | bool success = process.ExitCode == 0; 209 | if (success) 210 | { 211 | LogMessage("Tạo container thành công."); 212 | UpdateProgress(90); 213 | } 214 | else 215 | { 216 | LogMessage($"Lỗi khi tạo container(Exit code: {process.ExitCode}).", true); 217 | } 218 | return success; 219 | } 220 | } 221 | catch (Exception ex) 222 | { 223 | LogMessage($"Lỗi khi tạo container: {ex.Message}", true); 224 | MessageBox.Show($"Lỗi khi tạo container: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 225 | return false; 226 | } 227 | } 228 | 229 | private async Task CopyDirectoryAsync(string sourceDir, string destDir) 230 | { 231 | LogMessage($"Đang sao chép dữ liệu từ {sourceDir} đến {destDir}..."); 232 | UpdateProgress(40); 233 | 234 | await Task.Run(() => { 235 | CopyDirectoryInternal(sourceDir, destDir); 236 | }); 237 | 238 | // Ẩn các thư mục quan trọng 239 | if (Directory.Exists(destDir)) 240 | { 241 | LogMessage("Đang cấu hình thuộc tính thư mục..."); 242 | UpdateProgress(50); 243 | HideDirectory(destDir, VERACRYPT_HIDDEN_FOLDER); 244 | HideDirectory(destDir, AUTORUN_FOLDER); 245 | } 246 | } 247 | 248 | private void CopyDirectoryInternal(string sourceDir, string destDir) 249 | { 250 | try 251 | { 252 | // Kiểm tra thư mục nguồn 253 | if (!Directory.Exists(sourceDir)) 254 | { 255 | LogMessage($"Thư mục nguồn không tồn tại: {sourceDir}", true); 256 | return; 257 | } 258 | 259 | // Tạo thư mục đích nếu cần 260 | Directory.CreateDirectory(destDir); 261 | 262 | // Sao chép tất cả các file trong thư mục hiện tại 263 | foreach (string file in Directory.GetFiles(sourceDir)) 264 | { 265 | string destFile = Path.Combine(destDir, Path.GetFileName(file)); 266 | File.Copy(file, destFile, true); 267 | LogMessage($"Đã sao chép: {Path.GetFileName(file)}"); 268 | } 269 | 270 | // Sao chép các thư mục con đệ quy 271 | foreach (string subDir in Directory.GetDirectories(sourceDir)) 272 | { 273 | string subDirName = Path.GetFileName(subDir); 274 | LogMessage($"Đang sao chép thư mục: {subDirName}..."); 275 | string destSubDir = Path.Combine(destDir, subDirName); 276 | CopyDirectoryInternal(subDir, destSubDir); 277 | } 278 | } 279 | catch (Exception ex) 280 | { 281 | LogMessage($"Lỗi sao chép thư mục: {ex.Message}", true); 282 | MessageBox.Show($"Lỗi sao chép thư mục: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 283 | } 284 | } 285 | 286 | private void HideDirectory(string parentDir, string dirName) 287 | { 288 | try 289 | { 290 | string fullPath = Path.Combine(parentDir, dirName); 291 | if (Directory.Exists(fullPath)) 292 | { 293 | // Ẩn thư mục 294 | DirectoryInfo dirInfo = new DirectoryInfo(fullPath); 295 | if ((dirInfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) 296 | { 297 | dirInfo.Attributes |= FileAttributes.Hidden; 298 | LogMessage($"Đã ẩn thư mục: {dirName}"); 299 | } 300 | } 301 | else 302 | { 303 | // Ẩn file 304 | string fullFilePath = Path.Combine(parentDir, dirName); 305 | if (File.Exists(fullFilePath)) 306 | { 307 | FileInfo fileInfo = new FileInfo(fullFilePath); 308 | if ((fileInfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) 309 | { 310 | fileInfo.Attributes |= FileAttributes.Hidden; 311 | LogMessage($"Đã ẩn tệp tin: {dirName}"); 312 | } 313 | } 314 | } 315 | } 316 | catch (Exception ex) 317 | { 318 | // Log ra lỗi nhưng không hiển thị, vì đây không phải là lỗi nghiêm trọng 319 | LogMessage($"Lỗi khi ẩn {dirName}: {ex.Message}", true); 320 | Debug.WriteLine($"Lỗi khi ẩn {dirName}: {ex.Message}"); 321 | } 322 | } 323 | 324 | private void LogMessage(string message, bool isError = false) 325 | { 326 | if (txtLog.InvokeRequired) 327 | { 328 | txtLog.Invoke(new Action(LogMessage), message, isError); 329 | return; 330 | } 331 | 332 | string timestamp = DateTime.Now.ToString("HH:mm:ss"); 333 | string formattedMessage = $"[{timestamp}] {message}"; 334 | 335 | txtLog.AppendText(formattedMessage + Environment.NewLine); 336 | 337 | // Tự động cuộn xuống cuối 338 | txtLog.SelectionStart = txtLog.Text.Length; 339 | txtLog.ScrollToCaret(); 340 | 341 | // Cập nhật màu sắc nếu là lỗi 342 | if (isError) 343 | { 344 | // Lưu vị trí hiện tại 345 | int currentPosition = txtLog.SelectionStart; 346 | 347 | // Chọn dòng vừa thêm vào 348 | txtLog.Select(txtLog.Text.Length - formattedMessage.Length - Environment.NewLine.Length, formattedMessage.Length); 349 | 350 | // Khôi phục vị trí 351 | txtLog.SelectionStart = currentPosition; 352 | txtLog.SelectionLength = 0; 353 | } 354 | 355 | Application.DoEvents(); // Cho phép UI cập nhật 356 | } 357 | 358 | private void UpdateProgress(int value) 359 | { 360 | if (progressBar1.InvokeRequired) 361 | { 362 | progressBar1.Invoke(new Action(UpdateProgress), value); 363 | return; 364 | } 365 | 366 | progressBar1.Value = value; 367 | Application.DoEvents(); // Cho phép UI cập nhật 368 | } 369 | 370 | private async void btnRun_Click(object sender, EventArgs e) 371 | { 372 | if (string.IsNullOrWhiteSpace(txtPw1.Text)) 373 | { 374 | MessageBox.Show("Vui lòng nhập mật khẩu!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 375 | return; 376 | } 377 | // Kiểm tra mật khẩu khớp nhau 378 | if (txtPw1.Text != txtPw2.Text) 379 | { 380 | MessageBox.Show("Mật khẩu không khớp. Vui lòng nhập lại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 381 | return; 382 | } 383 | if (cbbUSB.SelectedItem == null) 384 | { 385 | MessageBox.Show("Vui lòng chọn thiết bị USB!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); 386 | return; 387 | } 388 | 389 | // Vô hiệu hóa nút để tránh click nhiều lần 390 | btnRun.Enabled = false; 391 | btnReload.Enabled = false; 392 | btnReset.Enabled = false; 393 | Cursor = Cursors.WaitCursor; 394 | 395 | // Xóa log cũ và reset progress bar 396 | txtLog.Clear(); 397 | progressBar1.Value = 0; 398 | 399 | try 400 | { 401 | string selectedUSB = cbbUSB.SelectedItem.ToString(); 402 | LogMessage($"Đã chọn thiết bị: {selectedUSB}"); 403 | int diskNumber = -1; 404 | 405 | // Tìm số Disk tương ứng 406 | UpdateProgress(5); 407 | LogMessage("Đang xác định số disk..."); 408 | using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='" + USB_INTERFACE_TYPE + "'")) 409 | { 410 | foreach (ManagementObject device in searcher.Get()) 411 | { 412 | string model = device["Model"]?.ToString() ?? ""; 413 | if (model == selectedUSB) 414 | { 415 | string deviceId = device["DeviceID"]?.ToString(); 416 | diskNumber = ExtractDiskNumber(deviceId); 417 | LogMessage($"Đã xác định được số disk: {diskNumber}"); 418 | break; 419 | } 420 | } 421 | } 422 | 423 | if (diskNumber == -1) 424 | { 425 | LogMessage("Không xác định được số disk.", true); 426 | MessageBox.Show("Không xác định được số disk.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 427 | return; 428 | } 429 | 430 | // Xác nhận từ người dùng 431 | DialogResult result = MessageBox.Show( 432 | $"Bạn có chắc chắn muốn format và cài đặt lên {selectedUSB} không?\n\nLƯU Ý: Tất cả dữ liệu trên thiết bị sẽ bị xóa!", 433 | "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); 434 | 435 | if (result != DialogResult.Yes) 436 | { 437 | LogMessage("Thao tác đã bị hủy bởi người dùng."); 438 | return; 439 | } 440 | 441 | LogMessage("Bắt đầu tiến trình format USB..."); 442 | UpdateProgress(10); 443 | 444 | // Thực thi diskpart với cơ chế retry 445 | bool diskpartSuccess = false; 446 | int retryCount = 0; 447 | const int MAX_RETRIES = 3; 448 | string diskpartErrorMessage = ""; 449 | 450 | while (!diskpartSuccess && retryCount < MAX_RETRIES) 451 | { 452 | try 453 | { 454 | // Tạo file script diskpart mới cho mỗi lần thử 455 | string scriptPath = Path.GetTempFileName(); 456 | File.WriteAllText(scriptPath, $@" 457 | select disk {diskNumber} 458 | clean 459 | create partition primary 460 | format fs=ntfs quick 461 | assign 462 | exit 463 | "); 464 | LogMessage($"Đang chạy diskpart lần thứ {retryCount + 1}..."); 465 | 466 | // Chuẩn bị process diskpart 467 | ProcessStartInfo psi = new ProcessStartInfo("diskpart.exe", $"/s \"{scriptPath}\"") 468 | { 469 | CreateNoWindow = true, 470 | UseShellExecute = false, 471 | WindowStyle = ProcessWindowStyle.Hidden 472 | }; 473 | 474 | using (Process process = Process.Start(psi)) 475 | { 476 | await Task.Run(() => process.WaitForExit()); 477 | 478 | // Kiểm tra kết quả của diskpart 479 | diskpartSuccess = process.ExitCode == 0; 480 | 481 | if (diskpartSuccess) 482 | { 483 | LogMessage("Format USB thành công!"); 484 | UpdateProgress(20); 485 | } 486 | else 487 | { 488 | LogMessage($"Lỗi khi chạy diskpart (Exit code: {process.ExitCode}), đang thử lại...", true); 489 | await Task.Delay(1000); 490 | } 491 | } 492 | 493 | // Xóa file tạm 494 | try { File.Delete(scriptPath); } catch { } 495 | } 496 | catch (Exception ex) 497 | { 498 | diskpartErrorMessage = ex.Message; 499 | LogMessage($"Lỗi khi chạy diskpart: {ex.Message}", true); 500 | } 501 | 502 | retryCount++; 503 | 504 | // Nếu đã thử đủ số lần mà vẫn thất bại 505 | if (!diskpartSuccess && retryCount >= MAX_RETRIES) 506 | { 507 | string errorMsg = string.IsNullOrEmpty(diskpartErrorMessage) 508 | ? "Không thể format USB sau nhiều lần thử" 509 | : $"Lỗi khi chạy diskpart: {diskpartErrorMessage}"; 510 | 511 | LogMessage(errorMsg, true); 512 | MessageBox.Show(errorMsg, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 513 | return; 514 | } 515 | } 516 | 517 | // Chờ hệ thống nhận diện USB mới - tăng thời gian chờ 518 | LogMessage("Đang chờ hệ thống nhận diện USB mới..."); 519 | await Task.Delay(3000); 520 | UpdateProgress(30); 521 | 522 | // Lấy ký tự ổ đĩa của USB sau khi format 523 | List usbDrives = await WaitForUSBDriveLetters(); 524 | if (usbDrives.Count == 0) 525 | { 526 | LogMessage("Không tìm thấy phân vùng USB sau khi format.", true); 527 | MessageBox.Show("Không tìm thấy phân vùng USB sau khi format. Vui lòng thử lại hoặc kiểm tra thiết bị.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 528 | return; 529 | } 530 | 531 | string usbDrive = usbDrives[0]; // Lấy ổ đĩa đầu tiên 532 | LogMessage($"Đang sử dụng ổ đĩa: {usbDrive}"); 533 | 534 | // Sao chép file từ thư mục bin vào USB 535 | string binFolder = Path.Combine(Application.StartupPath, "bin"); 536 | if (!Directory.Exists(binFolder)) 537 | { 538 | LogMessage("Không tìm thấy thư mục bin trong ứng dụng!", true); 539 | MessageBox.Show("Không tìm thấy thư mục bin trong ứng dụng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 540 | return; 541 | } 542 | 543 | await CopyDirectoryAsync(binFolder, usbDrive); 544 | 545 | // Tạo container VeraCrypt 546 | bool containerCreated = await CreateVeraCryptContainer(usbDrive); 547 | if (containerCreated) 548 | { 549 | LogMessage("Đã hoàn tất tất cả các thao tác!"); 550 | UpdateProgress(100); 551 | MessageBox.Show($"Đã hoàn tất cài đặt vào USB ({usbDrive})!", "Hoàn thành", MessageBoxButtons.OK, MessageBoxIcon.Information); 552 | MessageBox.Show($"Vui lòng rút USB ra và cắm lại!", "Hoàn thành", MessageBoxButtons.OK, MessageBoxIcon.Information); 553 | 554 | } 555 | else 556 | { 557 | LogMessage("Cài đặt thành công nhưng không thể tạo container.", true); 558 | UpdateProgress(95); 559 | MessageBox.Show("Cài đặt thành công vui lòng rút/cắm USB ra và thử lại.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); 560 | } 561 | } 562 | catch (Exception ex) 563 | { 564 | LogMessage($"Lỗi không xác định: {ex.Message}", true); 565 | MessageBox.Show($"Lỗi không xác định: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 566 | } 567 | finally 568 | { 569 | // Khôi phục giao diện 570 | btnRun.Enabled = true; 571 | btnReload.Enabled = true; 572 | btnReset.Enabled = true; 573 | Cursor = Cursors.Default; 574 | 575 | // Làm mới danh sách USB 576 | LoadUSBDevices(); 577 | } 578 | } 579 | 580 | 581 | private void MainForm_Load(object sender, EventArgs e) 582 | { 583 | this.ActiveControl = btnRun; 584 | } 585 | 586 | private async void btnReset_Click(object sender, EventArgs e) 587 | { 588 | if (cbbUSB.SelectedItem == null) 589 | { 590 | MessageBox.Show("Vui lòng chọn thiết bị USB!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); 591 | return; 592 | } 593 | 594 | btnReset.Enabled = false; 595 | Cursor = Cursors.WaitCursor; 596 | txtLog.Clear(); 597 | progressBar1.Value = 0; 598 | 599 | try 600 | { 601 | string selectedUSB = cbbUSB.SelectedItem.ToString(); 602 | LogMessage($"Đã chọn thiết bị: {selectedUSB}"); 603 | int diskNumber = -1; 604 | 605 | // Tìm số Disk tương ứng 606 | UpdateProgress(5); 607 | using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='" + USB_INTERFACE_TYPE + "'")) 608 | { 609 | foreach (ManagementObject device in searcher.Get()) 610 | { 611 | string model = device["Model"]?.ToString() ?? ""; 612 | if (model == selectedUSB) 613 | { 614 | string deviceId = device["DeviceID"]?.ToString(); 615 | diskNumber = ExtractDiskNumber(deviceId); 616 | LogMessage($"Đã xác định được số disk: {diskNumber}"); 617 | break; 618 | } 619 | } 620 | } 621 | 622 | if (diskNumber == -1) 623 | { 624 | LogMessage("Không xác định được số disk.", true); 625 | MessageBox.Show("Không xác định được số disk.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 626 | return; 627 | } 628 | 629 | DialogResult confirm = MessageBox.Show( 630 | $"Bạn có chắc chắn muốn **reset** (xóa và format lại) {selectedUSB} không?\n\nDỮ LIỆU TRÊN USB SẼ BỊ MẤT!", 631 | "Xác nhận Reset", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); 632 | 633 | if (confirm != DialogResult.Yes) 634 | { 635 | LogMessage("Thao tác reset đã bị hủy bởi người dùng."); 636 | return; 637 | } 638 | 639 | LogMessage("Bắt đầu reset USB..."); 640 | UpdateProgress(10); 641 | 642 | // Format USB 643 | string scriptPath = Path.GetTempFileName(); 644 | File.WriteAllText(scriptPath, $@" 645 | select disk {diskNumber} 646 | clean 647 | create partition primary 648 | format fs=ntfs quick 649 | assign 650 | exit"); 651 | 652 | ProcessStartInfo psi = new ProcessStartInfo("diskpart.exe", $"/s \"{scriptPath}\"") 653 | { 654 | CreateNoWindow = true, 655 | UseShellExecute = false, 656 | WindowStyle = ProcessWindowStyle.Hidden 657 | }; 658 | 659 | using (Process proc = Process.Start(psi)) 660 | { 661 | await Task.Run(() => proc.WaitForExit()); 662 | if (proc.ExitCode != 0) 663 | { 664 | LogMessage("Lỗi khi format USB bằng diskpart.", true); 665 | MessageBox.Show("Không thể format USB.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 666 | return; 667 | } 668 | } 669 | 670 | try { File.Delete(scriptPath); } catch { } 671 | 672 | LogMessage("Reset USB thành công."); 673 | UpdateProgress(100); 674 | MessageBox.Show("USB đã được reset và format lại thành công!", "Hoàn tất", MessageBoxButtons.OK, MessageBoxIcon.Information); 675 | } 676 | catch (Exception ex) 677 | { 678 | LogMessage($"Lỗi khi reset USB: {ex.Message}", true); 679 | MessageBox.Show($"Lỗi khi reset USB: {ex.Message}", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); 680 | } 681 | finally 682 | { 683 | btnReset.Enabled = true; 684 | Cursor = Cursors.Default; 685 | LoadUSBDevices(); 686 | } 687 | } 688 | 689 | } 690 | } --------------------------------------------------------------------------------