├── .editorconfig ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── XEncrypt ├── XEncrypt.vcxproj ├── XEncrypt.vcxproj.filters └── encrypt │ ├── RuntimeApi.cpp │ ├── RuntimeApi.h │ ├── common │ ├── Allocator.cpp │ ├── Allocator.h │ ├── Logging.cpp │ ├── Logging.h │ ├── XAssert.cpp │ └── XAssert.h │ ├── config.h │ ├── config_api.h │ ├── platforms.h │ ├── plugin │ ├── Decoder.h │ ├── Encoder.h │ ├── XPlugin.h │ └── xef │ │ ├── XEFDecoder.cpp │ │ ├── XEFDecoder.h │ │ ├── XEFEncoder.cpp │ │ ├── XEFEncoder.h │ │ ├── XEFHeader.h │ │ ├── XEFPlugin.cpp │ │ ├── XEFPlugin.h │ │ ├── XEFRuntimeApi.cpp │ │ ├── XEFRuntimeApi.h │ │ ├── XEncodeType.h │ │ ├── ZipUtils.cpp │ │ ├── ZipUtils.h │ │ ├── define.h │ │ ├── xxHash │ │ ├── README.md │ │ ├── xxh3.h │ │ ├── xxhash.c │ │ └── xxhash.h │ │ └── zlib │ │ ├── README │ │ ├── adler32.c │ │ ├── compress.c │ │ ├── crc32.c │ │ ├── crc32.h │ │ ├── deflate.c │ │ ├── deflate.h │ │ ├── gzclose.c │ │ ├── gzguts.h │ │ ├── gzlib.c │ │ ├── gzread.c │ │ ├── gzwrite.c │ │ ├── infback.c │ │ ├── inffast.c │ │ ├── inffast.h │ │ ├── inffixed.h │ │ ├── inflate.c │ │ ├── inflate.h │ │ ├── inftrees.c │ │ ├── inftrees.h │ │ ├── trees.c │ │ ├── trees.h │ │ ├── uncompr.c │ │ ├── zconf.h │ │ ├── zlib.h │ │ ├── zlib.map │ │ ├── zutil.c │ │ └── zutil.h │ └── service │ ├── Common.h │ ├── XContext.cpp │ ├── XContext.h │ ├── XResult.cpp │ ├── XResult.h │ ├── XService.cpp │ └── XService.h ├── XEncryptApi ├── DecryptScope.cs ├── EncryptScope.cs ├── NativeLibrary.cs ├── ResultCode.cs ├── XEncryptAPI.csproj ├── XEncryptApi.cs └── plugin │ ├── IPlugin.cs │ └── XEFPlugin.cs ├── XFileEncoder.sln ├── XFileEncoder ├── Generator.cs ├── Program.cs ├── Properties │ └── launchSettings.json └── XFileEncoder.csproj └── x64 ├── global-metadata.dat └── global-metadata.xef /.editorconfig: -------------------------------------------------------------------------------- 1 | ############################### 2 | # Core EditorConfig Options # 3 | ############################### 4 | root = true 5 | # All files 6 | [*] 7 | indent_style = space 8 | end_of_line = lf 9 | # XML project files 10 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 11 | indent_size = 2 12 | 13 | # XML config files 14 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 15 | indent_size = 2 16 | 17 | # Code files 18 | [*.{cs,csx,vb,vbx,c,c++,h,hpp,cxx}] 19 | indent_size = 4 20 | insert_final_newline = true 21 | charset = utf-8 22 | ############################### 23 | # .NET Coding Conventions # 24 | ############################### 25 | [*.{cs,vb}] 26 | # Organize usings 27 | dotnet_sort_system_directives_first = true 28 | # this. preferences 29 | dotnet_style_qualification_for_field = false:silent 30 | dotnet_style_qualification_for_property = false:silent 31 | dotnet_style_qualification_for_method = false:silent 32 | dotnet_style_qualification_for_event = false:silent 33 | # Language keywords vs BCL types preferences 34 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent 35 | dotnet_style_predefined_type_for_member_access = true:silent 36 | # Parentheses preferences 37 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent 38 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent 39 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent 40 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent 41 | # Modifier preferences 42 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent 43 | dotnet_style_readonly_field = true:suggestion 44 | # Expression-level preferences 45 | dotnet_style_object_initializer = true:suggestion 46 | dotnet_style_collection_initializer = true:suggestion 47 | dotnet_style_explicit_tuple_names = true:suggestion 48 | dotnet_style_null_propagation = true:suggestion 49 | dotnet_style_coalesce_expression = true:suggestion 50 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent 51 | dotnet_style_prefer_inferred_tuple_names = true:suggestion 52 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 53 | dotnet_style_prefer_auto_properties = true:silent 54 | dotnet_style_prefer_conditional_expression_over_assignment = true:silent 55 | dotnet_style_prefer_conditional_expression_over_return = true:silent 56 | ############################### 57 | # Naming Conventions # 58 | ############################### 59 | # Style Definitions 60 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 61 | # Use PascalCase for constant fields 62 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 63 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 64 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 65 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 66 | dotnet_naming_symbols.constant_fields.applicable_accessibilities = * 67 | dotnet_naming_symbols.constant_fields.required_modifiers = const 68 | dotnet_code_quality_unused_parameters = all:suggestion 69 | dotnet_style_allow_statement_immediately_after_block_experimental = true:silent 70 | dotnet_style_allow_multiple_blank_lines_experimental = true:silent 71 | dotnet_style_prefer_simplified_boolean_expressions = true:suggestion 72 | dotnet_style_prefer_compound_assignment = true:suggestion 73 | dotnet_style_prefer_simplified_interpolation = true:suggestion 74 | dotnet_style_namespace_match_folder = true:suggestion 75 | tab_width = 4 76 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 77 | ############################### 78 | # C# Coding Conventions # 79 | ############################### 80 | [*.cs] 81 | # var preferences 82 | csharp_style_var_for_built_in_types = true:silent 83 | csharp_style_var_when_type_is_apparent = true:silent 84 | csharp_style_var_elsewhere = true:silent 85 | # Expression-bodied members 86 | csharp_style_expression_bodied_methods = false:silent 87 | csharp_style_expression_bodied_constructors = false:silent 88 | csharp_style_expression_bodied_operators = false:silent 89 | csharp_style_expression_bodied_properties = true:silent 90 | csharp_style_expression_bodied_indexers = true:silent 91 | csharp_style_expression_bodied_accessors = true:silent 92 | # Pattern matching preferences 93 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 94 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 95 | # Null-checking preferences 96 | csharp_style_throw_expression = true:suggestion 97 | csharp_style_conditional_delegate_call = true:suggestion 98 | # Modifier preferences 99 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion 100 | # Expression-level preferences 101 | csharp_prefer_braces = true:silent 102 | csharp_style_deconstructed_variable_declaration = true:suggestion 103 | csharp_prefer_simple_default_expression = true:suggestion 104 | csharp_style_pattern_local_over_anonymous_function = true:suggestion 105 | csharp_style_inlined_variable_declaration = true:suggestion 106 | ############################### 107 | # C# Formatting Rules # 108 | ############################### 109 | # New line preferences 110 | csharp_new_line_before_open_brace = all 111 | csharp_new_line_before_else = true 112 | csharp_new_line_before_catch = true 113 | csharp_new_line_before_finally = true 114 | csharp_new_line_before_members_in_object_initializers = true 115 | csharp_new_line_before_members_in_anonymous_types = true 116 | csharp_new_line_between_query_expression_clauses = true 117 | # Indentation preferences 118 | csharp_indent_case_contents = true 119 | csharp_indent_switch_labels = true 120 | csharp_indent_labels = flush_left 121 | # Space preferences 122 | csharp_space_after_cast = false 123 | csharp_space_after_keywords_in_control_flow_statements =false 124 | csharp_space_between_method_call_parameter_list_parentheses = false 125 | csharp_space_between_method_declaration_parameter_list_parentheses = false 126 | csharp_space_between_parentheses = false 127 | csharp_space_before_colon_in_inheritance_clause = true 128 | csharp_space_after_colon_in_inheritance_clause = true 129 | csharp_space_around_binary_operators = before_and_after 130 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 131 | csharp_space_between_method_call_name_and_opening_parenthesis = false 132 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 133 | # Wrapping preferences 134 | csharp_preserve_single_line_statements = true 135 | csharp_preserve_single_line_blocks = true 136 | csharp_using_directive_placement = outside_namespace:silent 137 | csharp_style_expression_bodied_lambdas = true:silent 138 | csharp_style_expression_bodied_local_functions = false:silent 139 | csharp_style_prefer_parameter_null_checking = true:suggestion 140 | csharp_prefer_simple_using_statement = true:suggestion 141 | csharp_style_namespace_declarations = block_scoped:silent 142 | csharp_style_prefer_method_group_conversion = true:silent 143 | csharp_prefer_static_local_function = true:suggestion 144 | csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent 145 | csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent 146 | csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent 147 | csharp_style_prefer_pattern_matching = true:silent 148 | csharp_style_prefer_switch_expression = true:suggestion 149 | csharp_style_prefer_not_pattern = true:suggestion 150 | csharp_style_prefer_extended_property_pattern = true:suggestion 151 | csharp_style_prefer_null_check_over_type_check = true:suggestion 152 | csharp_style_prefer_local_over_anonymous_function = true:suggestion 153 | csharp_style_prefer_index_operator = true:suggestion 154 | csharp_style_prefer_range_operator = true:suggestion 155 | csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion 156 | csharp_style_prefer_tuple_swap = true:suggestion 157 | csharp_style_unused_value_assignment_preference = discard_variable:suggestion 158 | csharp_style_unused_value_expression_statement_preference = discard_variable:silent 159 | ############################### 160 | # VB Coding Conventions # 161 | ############################### 162 | [*.vb] 163 | # Modifier preferences 164 | visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion 165 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.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/main/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 | [Ww][Ii][Nn]32/ 25 | [Aa][Rr][Mm]/ 26 | [Aa][Rr][Mm]64/ 27 | bld/ 28 | [Bb]in/ 29 | [Oo]bj/ 30 | [Ll]og/ 31 | [Ll]ogs/ 32 | 33 | # Visual Studio 2015/2017 cache/options directory 34 | .vs/ 35 | # Uncomment if you have tasks that create the project's static files in wwwroot 36 | #wwwroot/ 37 | 38 | # Visual Studio 2017 auto generated files 39 | Generated\ Files/ 40 | 41 | # MSTest test Results 42 | [Tt]est[Rr]esult*/ 43 | [Bb]uild[Ll]og.* 44 | 45 | # NUnit 46 | *.VisualState.xml 47 | TestResult.xml 48 | nunit-*.xml 49 | 50 | # Build Results of an ATL Project 51 | [Dd]ebugPS/ 52 | [Rr]eleasePS/ 53 | dlldata.c 54 | 55 | # Benchmark Results 56 | BenchmarkDotNet.Artifacts/ 57 | 58 | # .NET Core 59 | project.lock.json 60 | project.fragment.lock.json 61 | artifacts/ 62 | 63 | # ASP.NET Scaffolding 64 | ScaffoldingReadMe.txt 65 | 66 | # StyleCop 67 | StyleCopReport.xml 68 | 69 | # Files built by Visual Studio 70 | *_i.c 71 | *_p.c 72 | *_h.h 73 | *.ilk 74 | *.meta 75 | *.obj 76 | *.iobj 77 | *.pch 78 | *.pdb 79 | *.ipdb 80 | *.pgc 81 | *.pgd 82 | *.rsp 83 | *.sbr 84 | *.tlb 85 | *.tli 86 | *.tlh 87 | *.tmp 88 | *.tmp_proj 89 | *_wpftmp.csproj 90 | *.log 91 | *.tlog 92 | *.vspscc 93 | *.vssscc 94 | .builds 95 | *.pidb 96 | *.svclog 97 | *.scc 98 | 99 | # Chutzpah Test files 100 | _Chutzpah* 101 | 102 | # Visual C++ cache files 103 | ipch/ 104 | *.aps 105 | *.ncb 106 | *.opendb 107 | *.opensdf 108 | *.sdf 109 | *.cachefile 110 | *.VC.db 111 | *.VC.VC.opendb 112 | 113 | # Visual Studio profiler 114 | *.psess 115 | *.vsp 116 | *.vspx 117 | *.sap 118 | 119 | # Visual Studio Trace Files 120 | *.e2e 121 | 122 | # TFS 2012 Local Workspace 123 | $tf/ 124 | 125 | # Guidance Automation Toolkit 126 | *.gpState 127 | 128 | # ReSharper is a .NET coding add-in 129 | _ReSharper*/ 130 | *.[Rr]e[Ss]harper 131 | *.DotSettings.user 132 | 133 | # TeamCity is a build add-in 134 | _TeamCity* 135 | 136 | # DotCover is a Code Coverage Tool 137 | *.dotCover 138 | 139 | # AxoCover is a Code Coverage Tool 140 | .axoCover/* 141 | !.axoCover/settings.json 142 | 143 | # Coverlet is a free, cross platform Code Coverage Tool 144 | coverage*.json 145 | coverage*.xml 146 | coverage*.info 147 | 148 | # Visual Studio code coverage results 149 | *.coverage 150 | *.coveragexml 151 | 152 | # NCrunch 153 | _NCrunch_* 154 | .*crunch*.local.xml 155 | nCrunchTemp_* 156 | 157 | # MightyMoose 158 | *.mm.* 159 | AutoTest.Net/ 160 | 161 | # Web workbench (sass) 162 | .sass-cache/ 163 | 164 | # Installshield output folder 165 | [Ee]xpress/ 166 | 167 | # DocProject is a documentation generator add-in 168 | DocProject/buildhelp/ 169 | DocProject/Help/*.HxT 170 | DocProject/Help/*.HxC 171 | DocProject/Help/*.hhc 172 | DocProject/Help/*.hhk 173 | DocProject/Help/*.hhp 174 | DocProject/Help/Html2 175 | DocProject/Help/html 176 | 177 | # Click-Once directory 178 | publish/ 179 | 180 | # Publish Web Output 181 | *.[Pp]ublish.xml 182 | *.azurePubxml 183 | # Note: Comment the next line if you want to checkin your web deploy settings, 184 | # but database connection strings (with potential passwords) will be unencrypted 185 | *.pubxml 186 | *.publishproj 187 | 188 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 189 | # checkin your Azure Web App publish settings, but sensitive information contained 190 | # in these scripts will be unencrypted 191 | PublishScripts/ 192 | 193 | # NuGet Packages 194 | *.nupkg 195 | # NuGet Symbol Packages 196 | *.snupkg 197 | # The packages folder can be ignored because of Package Restore 198 | **/[Pp]ackages/* 199 | # except build/, which is used as an MSBuild target. 200 | !**/[Pp]ackages/build/ 201 | # Uncomment if necessary however generally it will be regenerated when needed 202 | #!**/[Pp]ackages/repositories.config 203 | # NuGet v3's project.json files produces more ignorable files 204 | *.nuget.props 205 | *.nuget.targets 206 | 207 | # Microsoft Azure Build Output 208 | csx/ 209 | *.build.csdef 210 | 211 | # Microsoft Azure Emulator 212 | ecf/ 213 | rcf/ 214 | 215 | # Windows Store app package directories and files 216 | AppPackages/ 217 | BundleArtifacts/ 218 | Package.StoreAssociation.xml 219 | _pkginfo.txt 220 | *.appx 221 | *.appxbundle 222 | *.appxupload 223 | 224 | # Visual Studio cache files 225 | # files ending in .cache can be ignored 226 | *.[Cc]ache 227 | # but keep track of directories ending in .cache 228 | !?*.[Cc]ache/ 229 | 230 | # Others 231 | ClientBin/ 232 | ~$* 233 | *~ 234 | *.dbmdl 235 | *.dbproj.schemaview 236 | *.jfm 237 | *.pfx 238 | *.publishsettings 239 | orleans.codegen.cs 240 | 241 | # Including strong name files can present a security risk 242 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 243 | #*.snk 244 | 245 | # Since there are multiple workflows, uncomment next line to ignore bower_components 246 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 247 | #bower_components/ 248 | 249 | # RIA/Silverlight projects 250 | Generated_Code/ 251 | 252 | # Backup & report files from converting an old project file 253 | # to a newer Visual Studio version. Backup files are not needed, 254 | # because we have git ;-) 255 | _UpgradeReport_Files/ 256 | Backup*/ 257 | UpgradeLog*.XML 258 | UpgradeLog*.htm 259 | ServiceFabricBackup/ 260 | *.rptproj.bak 261 | 262 | # SQL Server files 263 | *.mdf 264 | *.ldf 265 | *.ndf 266 | 267 | # Business Intelligence projects 268 | *.rdl.data 269 | *.bim.layout 270 | *.bim_*.settings 271 | *.rptproj.rsuser 272 | *- [Bb]ackup.rdl 273 | *- [Bb]ackup ([0-9]).rdl 274 | *- [Bb]ackup ([0-9][0-9]).rdl 275 | 276 | # Microsoft Fakes 277 | FakesAssemblies/ 278 | 279 | # GhostDoc plugin setting file 280 | *.GhostDoc.xml 281 | 282 | # Node.js Tools for Visual Studio 283 | .ntvs_analysis.dat 284 | node_modules/ 285 | 286 | # Visual Studio 6 build log 287 | *.plg 288 | 289 | # Visual Studio 6 workspace options file 290 | *.opt 291 | 292 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 293 | *.vbw 294 | 295 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 296 | *.vbp 297 | 298 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 299 | *.dsw 300 | *.dsp 301 | 302 | # Visual Studio 6 technical files 303 | *.ncb 304 | *.aps 305 | 306 | # Visual Studio LightSwitch build output 307 | **/*.HTMLClient/GeneratedArtifacts 308 | **/*.DesktopClient/GeneratedArtifacts 309 | **/*.DesktopClient/ModelManifest.xml 310 | **/*.Server/GeneratedArtifacts 311 | **/*.Server/ModelManifest.xml 312 | _Pvt_Extensions 313 | 314 | # Paket dependency manager 315 | .paket/paket.exe 316 | paket-files/ 317 | 318 | # FAKE - F# Make 319 | .fake/ 320 | 321 | # CodeRush personal settings 322 | .cr/personal 323 | 324 | # Python Tools for Visual Studio (PTVS) 325 | __pycache__/ 326 | *.pyc 327 | 328 | # Cake - Uncomment if you are using it 329 | # tools/** 330 | # !tools/packages.config 331 | 332 | # Tabs Studio 333 | *.tss 334 | 335 | # Telerik's JustMock configuration file 336 | *.jmconfig 337 | 338 | # BizTalk build output 339 | *.btp.cs 340 | *.btm.cs 341 | *.odx.cs 342 | *.xsd.cs 343 | 344 | # OpenCover UI analysis results 345 | OpenCover/ 346 | 347 | # Azure Stream Analytics local run output 348 | ASALocalRun/ 349 | 350 | # MSBuild Binary and Structured Log 351 | *.binlog 352 | 353 | # NVidia Nsight GPU debugger configuration file 354 | *.nvuser 355 | 356 | # MFractors (Xamarin productivity tool) working folder 357 | .mfractor/ 358 | 359 | # Local History for Visual Studio 360 | .localhistory/ 361 | 362 | # Visual Studio History (VSHistory) files 363 | .vshistory/ 364 | 365 | # BeatPulse healthcheck temp database 366 | healthchecksdb 367 | 368 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 369 | MigrationBackup/ 370 | 371 | # Ionide (cross platform F# VS Code tools) working folder 372 | .ionide/ 373 | 374 | # Fody - auto-generated XML schema 375 | FodyWeavers.xsd 376 | 377 | # VS Code files for those working on multiple tools 378 | .vscode/* 379 | !.vscode/settings.json 380 | !.vscode/tasks.json 381 | !.vscode/launch.json 382 | !.vscode/extensions.json 383 | *.code-workspace 384 | 385 | # Local History for Visual Studio Code 386 | .history/ 387 | 388 | # Windows Installer files from build outputs 389 | *.cab 390 | *.msi 391 | *.msix 392 | *.msm 393 | *.msp 394 | 395 | # JetBrains Rider 396 | *.sln.iml 397 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Y-way 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xFileEncoder 2 | 自定义文件头部加密 3 | 4 | 使用[x-encrypt](https://github.com/Y-way/x-encrypt)(v3.2.0)库进行加密/解密 5 | 6 | # 使用方法 7 | 8 | ```sh 9 | git clone --recursive https://github.com/Y-way/xFileEncoder.git 10 | 11 | ``` 12 | 进入`xFileEncoder`目录, 13 | 使用 Visual Studio 打开XFileEncoder.sln工程 14 | 15 | 编译并测试 16 | 17 | 打开`xFileEncoder/XFileEncoder/Properties/launchSettings.json`文件 18 | 19 | 修改`commandLineArgs` 命令行参数测试加密/解密功能 20 | 21 | ``` 22 | Usage: 23 | 24 | XFileEncoder command args 25 | 26 | command:执行命令,必须参数 27 | encrypt:加密命令 28 | decrypt:解密命令 29 | args:命令参数 30 | -load:加载欲加密文件,必须参数 31 | -out:输出文件名字.可选参数,默认文件名out.xfe 32 | -encrypt-size:加密数据长度,可选参数,默认16字节. 取值范围:Min(Clamp(encrypt-size, 1, 255), file_size) 33 | -encode-type:加密源数据方式,可选参数. none:只加密源文件内容, 默认;zip:加密并zip压缩源文件内容 34 | -help:查看帮助 35 | 例: 36 | 加密: 37 | XFileEncoder encrypt -load test.png -out test.png -encrypt-size 32 -encode-type zip 38 | 解密: 39 | XFileEncoder edcrypt -load test.png -out test.png 40 | 41 | ``` 42 | 43 | ********** 44 | 45 | # 该项目已迁移到[x-encrypt](https://github.com/Y-way/x-encrypt/tree/main/C%23) 46 | -------------------------------------------------------------------------------- /XEncrypt/XEncrypt.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {6320e5c7-fc7b-4e4a-be19-9304103ff1f3} 10 | 11 | 12 | {9f79d390-f8b4-41f0-aa51-6b4eac822658} 13 | 14 | 15 | {573a0790-084e-4575-a915-acb5aec66f4b} 16 | 17 | 18 | {a253bc7e-76d9-447a-ab0b-42c268b08fdc} 19 | 20 | 21 | {e42ff1fe-d7ae-4270-b399-8bed9ab57845} 22 | 23 | 24 | {de5bea3a-ee75-4840-bb9a-c70f748f18ac} 25 | 26 | 27 | {a361ddaf-29b4-43ec-9e01-2cf90dec6017} 28 | 29 | 30 | 31 | 32 | encrypt\common 33 | 34 | 35 | encrypt\common 36 | 37 | 38 | encrypt\common 39 | 40 | 41 | encrypt 42 | 43 | 44 | encrypt 45 | 46 | 47 | encrypt 48 | 49 | 50 | encrypt\plugin\xef 51 | 52 | 53 | encrypt\plugin\xef 54 | 55 | 56 | encrypt\plugin\xef 57 | 58 | 59 | encrypt\plugin\xef 60 | 61 | 62 | encrypt\plugin\xef 63 | 64 | 65 | encrypt\plugin\xef 66 | 67 | 68 | encrypt\plugin 69 | 70 | 71 | encrypt\plugin 72 | 73 | 74 | encrypt\plugin 75 | 76 | 77 | encrypt\service 78 | 79 | 80 | encrypt\service 81 | 82 | 83 | encrypt\service 84 | 85 | 86 | encrypt\service 87 | 88 | 89 | encrypt 90 | 91 | 92 | encrypt\plugin\xef 93 | 94 | 95 | encrypt\plugin\xef 96 | 97 | 98 | encrypt\plugin\xef\zlib 99 | 100 | 101 | encrypt\plugin\xef\zlib 102 | 103 | 104 | encrypt\plugin\xef\zlib 105 | 106 | 107 | encrypt\plugin\xef\zlib 108 | 109 | 110 | encrypt\plugin\xef\zlib 111 | 112 | 113 | encrypt\plugin\xef\zlib 114 | 115 | 116 | encrypt\plugin\xef\zlib 117 | 118 | 119 | encrypt\plugin\xef\zlib 120 | 121 | 122 | encrypt\plugin\xef\zlib 123 | 124 | 125 | encrypt\plugin\xef\zlib 126 | 127 | 128 | encrypt\plugin\xef\zlib 129 | 130 | 131 | encrypt\plugin\xef\xxHash 132 | 133 | 134 | encrypt\plugin\xef\xxHash 135 | 136 | 137 | 138 | 139 | encrypt\common 140 | 141 | 142 | encrypt\common 143 | 144 | 145 | encrypt\common 146 | 147 | 148 | encrypt 149 | 150 | 151 | encrypt\plugin\xef 152 | 153 | 154 | encrypt\plugin\xef 155 | 156 | 157 | encrypt\plugin\xef 158 | 159 | 160 | encrypt\plugin\xef 161 | 162 | 163 | encrypt\service 164 | 165 | 166 | encrypt\service 167 | 168 | 169 | encrypt\service 170 | 171 | 172 | encrypt\plugin\xef 173 | 174 | 175 | encrypt\plugin\xef\zlib 176 | 177 | 178 | encrypt\plugin\xef\zlib 179 | 180 | 181 | encrypt\plugin\xef\zlib 182 | 183 | 184 | encrypt\plugin\xef\zlib 185 | 186 | 187 | encrypt\plugin\xef\zlib 188 | 189 | 190 | encrypt\plugin\xef\zlib 191 | 192 | 193 | encrypt\plugin\xef\zlib 194 | 195 | 196 | encrypt\plugin\xef\zlib 197 | 198 | 199 | encrypt\plugin\xef\zlib 200 | 201 | 202 | encrypt\plugin\xef\zlib 203 | 204 | 205 | encrypt\plugin\xef\zlib 206 | 207 | 208 | encrypt\plugin\xef\zlib 209 | 210 | 211 | encrypt\plugin\xef\zlib 212 | 213 | 214 | encrypt\plugin\xef\zlib 215 | 216 | 217 | encrypt\plugin\xef\zlib 218 | 219 | 220 | encrypt\plugin\xef\xxHash 221 | 222 | 223 | 224 | 225 | encrypt\plugin\xef\zlib 226 | 227 | 228 | encrypt\plugin\xef\zlib 229 | 230 | 231 | encrypt\plugin\xef\xxHash 232 | 233 | 234 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/RuntimeApi.cpp: -------------------------------------------------------------------------------- 1 | #include "RuntimeApi.h" 2 | #include "service/Common.h" 3 | #include "service/XService.h" 4 | #include "service/XResult.h" 5 | 6 | using namespace xencrypt; 7 | 8 | #if defined(__cplusplus) 9 | extern "C" 10 | { 11 | #endif // __cplusplus 12 | 13 | XENCRYPT_API void* xencrypt_service_initialize(void* plugin) 14 | { 15 | return (void*)(new XService(reinterpret_cast(plugin))); 16 | } 17 | 18 | XENCRYPT_API bool xencrypt_service_is_encrypted(void* service, const byte* data, int64_t size) 19 | { 20 | if (service == nullptr) 21 | { 22 | return false; 23 | } 24 | 25 | return reinterpret_cast(service)->IsEncrypted(data, size); 26 | } 27 | 28 | XENCRYPT_API void xencrypt_service_deinitialize(void* service) 29 | { 30 | if (service == nullptr) 31 | { 32 | return; 33 | } 34 | delete reinterpret_cast(service); 35 | } 36 | 37 | XENCRYPT_API xencrypt_result xencrypt_service_encrypt(void* service, const byte* in, int64_t in_size) 38 | { 39 | XService* x = reinterpret_cast(service); 40 | xencrypt_result retVal = { ResultCode::Unknown, 0, nullptr, nullptr }; 41 | if (x == nullptr) 42 | { 43 | retVal.code = ResultCode::UnInitialize; 44 | return retVal; 45 | } 46 | XResult* result = x->Encrypt(in, in_size); 47 | 48 | if (result != nullptr) 49 | { 50 | retVal.code = result->GetCode(); 51 | retVal.data = result->GetData(); 52 | retVal.size = result->GetDataSize(); 53 | } 54 | retVal.result = result; 55 | return retVal; 56 | } 57 | 58 | XENCRYPT_API xencrypt_result xencrypt_service_decrypt(void* service, const byte* in, int64_t in_size, bool cloneInput/* = false */) 59 | { 60 | XService* x = reinterpret_cast(service); 61 | xencrypt_result retVal = { ResultCode::Unknown, 0, nullptr, nullptr }; 62 | if (x == nullptr) 63 | { 64 | retVal.code = ResultCode::UnInitialize; 65 | return retVal; 66 | } 67 | XResult* result = x->Decrypt(in, in_size, cloneInput); 68 | 69 | if (result != nullptr) 70 | { 71 | retVal.code = result->GetCode(); 72 | retVal.data = result->GetData(); 73 | retVal.size = result->GetDataSize(); 74 | } 75 | retVal.result = result; 76 | return retVal; 77 | } 78 | 79 | XENCRYPT_API void xencrypt_service_release_result(void* service, xencrypt_result* result) 80 | { 81 | if (service == nullptr || result == nullptr || result->result == nullptr) 82 | { 83 | return; 84 | } 85 | reinterpret_cast(service)->ReleaseResult(reinterpret_cast(result->result)); 86 | result->result = nullptr; 87 | } 88 | 89 | #if defined(__cplusplus) 90 | } 91 | #endif // __cplusplus 92 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/RuntimeApi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif // __cplusplus 9 | /// @brief 加密/解密结果 10 | typedef struct xencrypt_result 11 | { 12 | /// @brief 结果码 13 | int code; 14 | /// @brief 结果数据大小 15 | int64_t size; 16 | /// @brief 结果数据 17 | byte* data; 18 | /// @brief XReult指针, 用于释放内存 19 | void* result; 20 | }xencrypt_result; 21 | 22 | /// @brief 初始化服务 23 | /// @param plugin 加密/解密插件实例 24 | XENCRYPT_API void* xencrypt_service_initialize(void* plugin); 25 | /// @brief 检查数据是否已加密 26 | /// @param service 加密/解密服务实例 27 | /// @param data 内存数据地址 28 | /// @param size 数据长度 29 | /// @return 数据是否已加密.返回true,数据已加密,否则,未加密. 30 | XENCRYPT_API bool xencrypt_service_is_encrypted(void* service, const byte* data, int64_t size); 31 | /// @brief 加密数据 32 | /// @param service 加密/解密服务实例 33 | /// @param in 待加密数据 34 | /// @param in_size 待加密数据长度 35 | /// @return 加密结果 36 | XENCRYPT_API xencrypt_result xencrypt_service_encrypt(void* service, const byte* in, int64_t in_size); 37 | /// @brief 解密数据 38 | /// @param service 加密/解密服务实例 39 | /// @param in 待解密数据 40 | /// @param in_size 密数据长度 41 | /// @return 解密结果 42 | XENCRYPT_API xencrypt_result xencrypt_service_decrypt(void* service, const byte* in, int64_t in_size, bool cloneInput = false); 43 | /// @brief 销毁结果 44 | /// @param service 加密/解密服务实例 45 | /// @param result 加/解密结果指针 46 | XENCRYPT_API void xencrypt_service_release_result(void* service, xencrypt_result* result); 47 | /// @brief 注销服务 48 | /// @param service 加密/解密服务实例 49 | XENCRYPT_API void xencrypt_service_deinitialize(void* service); 50 | 51 | #if defined(__cplusplus) 52 | } 53 | #endif // __cplusplus 54 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/Allocator.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "Allocator.h" 3 | #include 4 | #include 5 | 6 | #if defined(__ANDROID_API__) && (__ANDROID_API__ < 16) 7 | static void* aligned_alloc(size_t alignment, size_t size) 8 | { 9 | // alignment must be >= sizeof(void*) 10 | if(alignment < sizeof(void*)) 11 | { 12 | alignment = sizeof(void*); 13 | } 14 | 15 | return memalign(alignment, size); 16 | } 17 | 18 | #elif defined(__APPLE__) || defined(__ANDROID__) || (defined(__linux__) && defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)) 19 | 20 | #if defined(__APPLE__) 21 | #include 22 | #endif 23 | 24 | void* aligned_alloc(size_t alignment, size_t size) 25 | { 26 | // Unfortunately, aligned_alloc causes VMA to crash due to it returning null pointers. (At least under 11.4) 27 | // Therefore, for now disable this specific exception until a proper solution is found. 28 | //#if defined(__APPLE__) && (defined(MAC_OS_X_VERSION_10_16) || defined(__IPHONE_14_0)) 29 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 30 | // // For C++14, usr/include/malloc/_malloc.h declares aligned_alloc()) only 31 | // // with the MacOSX11.0 SDK in Xcode 12 (which is what adds 32 | // // MAC_OS_X_VERSION_10_16), even though the function is marked 33 | // // availabe for 10.15. That is why the preprocessor checks for 10.16 but 34 | // // the __builtin_available checks for 10.15. 35 | // // People who use C++17 could call aligned_alloc with the 10.15 SDK already. 36 | // if (__builtin_available(macOS 10.15, iOS 13, *)) 37 | // return aligned_alloc(alignment, size); 38 | //#endif 39 | //#endif 40 | 41 | // alignment must be >= sizeof(void*) 42 | if(alignment < sizeof(void*)) 43 | { 44 | alignment = sizeof(void*); 45 | } 46 | 47 | void *pointer; 48 | if(posix_memalign(&pointer, alignment, size) == 0) 49 | return pointer; 50 | return NULL; 51 | } 52 | #endif 53 | 54 | #if defined(_WIN32) || defined(WINDOWS) 55 | 56 | static void* native_aligned_alloc(size_t alignment, size_t size) 57 | { 58 | return _aligned_malloc(size, alignment); 59 | } 60 | 61 | static void* native_aligned_realloc(void* memory, size_t newSize, size_t alignment) 62 | { 63 | return _aligned_realloc(memory, newSize, alignment); 64 | } 65 | 66 | static void native_aligned_free(void* ptr) 67 | { 68 | _aligned_free(ptr); 69 | } 70 | 71 | #else 72 | 73 | static void* native_aligned_alloc(size_t alignment, size_t size) 74 | { 75 | return aligned_alloc(alignment, size); 76 | } 77 | 78 | static void* native_aligned_realloc(void* memory, size_t newSize, size_t alignment) 79 | { 80 | void* newMemory = realloc(memory, newSize); 81 | 82 | // Fast path: realloc returned aligned memory 83 | if ((reinterpret_cast(newMemory) & (alignment - 1)) == 0) 84 | return newMemory; 85 | 86 | // Slow path: realloc returned non-aligned memory 87 | void* alignedMemory = native_aligned_alloc(newSize, alignment); 88 | memcpy(alignedMemory, newMemory, newSize); 89 | free(newMemory); 90 | return alignedMemory; 91 | } 92 | 93 | static void native_aligned_free(void* ptr) 94 | { 95 | free(ptr); 96 | } 97 | #endif 98 | 99 | namespace XMemory 100 | { 101 | void* AlignedAlloc(size_t size, size_t alignment) 102 | { 103 | return native_aligned_alloc(size, alignment); 104 | } 105 | 106 | void* AlignedReAlloc(void* memory, size_t newSize, size_t alignment) 107 | { 108 | return native_aligned_realloc(memory, newSize, alignment); 109 | } 110 | 111 | void AlignedFree(void* memory) 112 | { 113 | return native_aligned_free(memory); 114 | } 115 | 116 | XMemoryCallbacks DefaultCallbacks = 117 | { 118 | malloc, 119 | XMemory::AlignedAlloc, 120 | free, 121 | XMemory::AlignedFree, 122 | calloc, 123 | realloc, 124 | XMemory::AlignedReAlloc 125 | }; 126 | } 127 | 128 | namespace xencrypt 129 | { 130 | static XMemory::XMemoryCallbacks s_Callbacks = XMemory::DefaultCallbacks; 131 | 132 | void MemoryAllocator::SetMemoryCallbacks(XMemory::XMemoryCallbacks* callbacks) 133 | { 134 | memcpy(&s_Callbacks, callbacks, sizeof(XMemory::XMemoryCallbacks)); 135 | } 136 | 137 | void* MemoryAllocator::Malloc(size_t size) 138 | { 139 | return s_Callbacks.malloc_func(size); 140 | } 141 | 142 | void* MemoryAllocator::AlignedMalloc(size_t size, size_t alignment) 143 | { 144 | return s_Callbacks.aligned_malloc_func(size, alignment); 145 | } 146 | 147 | void MemoryAllocator::Free(void* memory) 148 | { 149 | return s_Callbacks.free_func(memory); 150 | } 151 | 152 | void MemoryAllocator::AlignedFree(void* memory) 153 | { 154 | return s_Callbacks.aligned_free_func(memory); 155 | } 156 | 157 | void* MemoryAllocator::Calloc(size_t count, size_t size) 158 | { 159 | return s_Callbacks.calloc_func(count, size); 160 | } 161 | 162 | void* MemoryAllocator::Realloc(void* memory, size_t newSize) 163 | { 164 | return s_Callbacks.realloc_func(memory, newSize); 165 | } 166 | 167 | void* MemoryAllocator::AlignedRealloc(void* memory, size_t newSize, size_t alignment) 168 | { 169 | return s_Callbacks.aligned_realloc_func(memory, newSize, alignment); 170 | } 171 | } /* namespace xencrypt */ 172 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/Allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | namespace XMemory 6 | { 7 | void* AlignedAlloc(size_t size, size_t alignment); 8 | void* AlignedReAlloc(void* memory, size_t newSize, size_t alignment); 9 | void AlignedFree(void* memory); 10 | 11 | typedef struct 12 | { 13 | void* (*malloc_func)(size_t size); 14 | void* (*aligned_malloc_func)(size_t size, size_t alignment); 15 | void (*free_func)(void* ptr); 16 | void (*aligned_free_func)(void* ptr); 17 | void* (*calloc_func)(size_t nmemb, size_t size); 18 | void* (*realloc_func)(void* ptr, size_t size); 19 | void* (*aligned_realloc_func)(void* ptr, size_t size, size_t alignment); 20 | } XMemoryCallbacks; 21 | 22 | extern XMemoryCallbacks DefaultCallbacks; 23 | } 24 | 25 | namespace xencrypt 26 | { 27 | struct XENCRYPT_API MemoryAllocator 28 | { 29 | static void SetMemoryCallbacks(XMemory::XMemoryCallbacks* callbacks); 30 | 31 | static void* Malloc(size_t size); 32 | static void* AlignedMalloc(size_t size, size_t alignment); 33 | static void Free(void* memory); 34 | static void AlignedFree(void* memory); 35 | static void* Calloc(size_t count, size_t size); 36 | static void* Realloc(void* memory, size_t newSize); 37 | static void* AlignedRealloc(void* memory, size_t newSize, size_t alignment); 38 | }; 39 | } /* namespace xencrypt */ 40 | 41 | #define XMEMORY_MALLOC(size) xencrypt::MemoryAllocator::Malloc(size) 42 | #define XMEMORY_MALLOC_ALIGNED(size, alignment) xencrypt::MemoryAllocator::AlignedMalloc(size, alignment) 43 | #define XMEMORY_MALLOC_ZERO(size) xencrypt::MemoryAllocator::Calloc(1,size) 44 | #define XMEMORY_FREE(memory) xencrypt::MemoryAllocator::Free(memory) 45 | #define XMEMORY_FREE_ALIGNED(memory) xencrypt::MemoryAllocator::AlignedFree(memory) 46 | #define XMEMORY_CALLOC(count, size) xencrypt::MemoryAllocator::Calloc(count,size) 47 | #define XMEMORY_REALLOC(memory, newSize) xencrypt::MemoryAllocator::Realloc(memory,newSize) 48 | #define XMEMORY_REALLOC_ALIGNED(memory, newSize, alignment) xencrypt::MemoryAllocator::AlignedRealloc(memory, newSize, alignment) 49 | 50 | #define XMEMORY_SAFE_FREE(memory) \ 51 | {\ 52 | void* pMem = (void*)(memory); \ 53 | if(pMem != nullptr) \ 54 | xencrypt::MemoryAllocator::Free(pMem); \ 55 | pMem = nullptr; \ 56 | } 57 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/Logging.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Logging.h" 5 | 6 | using namespace xencrypt; 7 | 8 | static void DefaultLogCallback(const char* message) 9 | { 10 | printf("%s\n", message); 11 | } 12 | 13 | XLogCallback Logging::s_Callback = DefaultLogCallback; 14 | 15 | void Logging::Write(const char* format, ...) 16 | { 17 | X_ENCRYPT_ASSERT(s_Callback != NULL); 18 | 19 | if (format == NULL) 20 | return; 21 | 22 | va_list va; 23 | va_start(va, format); 24 | 25 | const char* prefix = "[xfe] "; 26 | const int bufferSize = 1024 * 5; 27 | char buffer[bufferSize]; 28 | memcpy(buffer, prefix, 6); 29 | vsnprintf(buffer + 6, bufferSize - 6, format, va); 30 | if (s_Callback != NULL) 31 | { 32 | s_Callback(buffer); 33 | } 34 | va_end(va); 35 | } 36 | 37 | void Logging::SetLogCallback(XLogCallback method) 38 | { 39 | s_Callback = method; 40 | } 41 | 42 | bool Logging::IsLogCallbackSet() 43 | { 44 | return s_Callback != DefaultLogCallback; 45 | } 46 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/Logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | namespace xencrypt 6 | { 7 | typedef void (*XLogCallback)(const char*); 8 | 9 | class Logging 10 | { 11 | public: 12 | static void Write(const char* format, ...); 13 | static void SetLogCallback(XLogCallback method); 14 | static bool IsLogCallbackSet(); 15 | 16 | private: 17 | static XLogCallback s_Callback; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/XAssert.cpp: -------------------------------------------------------------------------------- 1 | #include "XAssert.h" 2 | 3 | #if X_ENCRYPT_DEBUG 4 | #include 5 | #include 6 | 7 | void xencrypt_assert(const char* assertion, const char* file, unsigned int line) 8 | { 9 | #if X_ENCRYPT_USE_GENERIC_ASSERT 10 | printf("Assertion failed: %s, file %s, line %u\n", assertion, file, line); 11 | abort(); 12 | #else 13 | X_ENCRYPT_DEBUG_BREAK 14 | #endif // X_ENCRYPT_USE_GENERIC_ASSERT 15 | } 16 | 17 | #endif // X_ENCRYPT_DEBUG 18 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/common/XAssert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | #if X_ENCRYPT_DEBUG 6 | void xencrypt_assert(const char* assertion, const char* file, unsigned int line); 7 | #endif 8 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /* first setup platform defines*/ 8 | #include "platforms.h" 9 | 10 | #include "config_api.h" 11 | 12 | #if !defined(__cplusplus) 13 | #define bool uint8_t 14 | #endif // !__cplusplus 15 | 16 | #if !__SNC__ // SNC doesn't like the following define: "warning 1576: predefined meaning of __has_feature discarded" 17 | #ifndef __has_feature // clang specific __has_feature check 18 | #define __has_feature(x) 0 // Compatibility with non-clang compilers. 19 | #endif 20 | #endif 21 | 22 | typedef uint8_t byte; 23 | 24 | static const int32_t kInt32Min = INT32_MIN; 25 | static const int32_t kInt32Max = INT32_MAX; 26 | static const uint32_t kUInt32Max = UINT32_MAX; 27 | static const int64_t kInt64Min = INT64_MIN; 28 | static const int64_t kInt64Max = INT64_MAX; 29 | static const uint64_t kUInt64Max = UINT64_MAX; 30 | 31 | #if X_ENCRYPT_SIZEOF_VOID_P == 8 32 | static const intptr_t kIntPtrMin = INT64_MIN; 33 | static const intptr_t kIntPtrMax = INT64_MAX; 34 | static const uintptr_t kUIntPtrMax = UINT64_MAX; 35 | #else 36 | static const intptr_t kIntPtrMin = INT32_MIN; 37 | static const intptr_t kIntPtrMax = INT32_MAX; 38 | static const uintptr_t kUIntPtrMax = UINT32_MAX; 39 | #endif 40 | 41 | #if defined(__ARMCC_VERSION) 42 | #include 43 | #include 44 | #define INTPTR_MAX 2147483647 45 | #endif 46 | 47 | #if defined(__cplusplus) 48 | #define X_ENCRYPT_EXTERN_C extern "C" 49 | #define X_ENCRYPT_EXTERN_C_CONST extern "C" const 50 | #define X_ENCRYPT_EXTERN_C_BEGIN extern "C" { 51 | #define X_ENCRYPT_EXTERN_C_END } 52 | #else 53 | #define X_ENCRYPT_EXTERN_C 54 | #define X_ENCRYPT_EXTERN_C_CONST extern const 55 | #define X_ENCRYPT_EXTERN_C_BEGIN 56 | #define X_ENCRYPT_EXTERN_C_END 57 | #endif 58 | 59 | #if X_ENCRYPT_COMPILER_MSVC || defined(__ARMCC_VERSION) 60 | #define X_ENCRYPT_NO_INLINE __declspec(noinline) 61 | #define X_ENCRYPT_NO_ALIAS __declspec(noalias) 62 | #define X_ENCRYPT_PARAMETER_RESTRICT __restrict 63 | #define X_ENCRYPT_METHOD_RESTRICT __declspec(restrict) 64 | #define X_ENCRYPT_ASSUME(x) __assume(x) 65 | #else 66 | #define X_ENCRYPT_NO_INLINE __attribute__ ((noinline)) 67 | #define X_ENCRYPT_NO_ALIAS 68 | #define X_ENCRYPT_PARAMETER_RESTRICT 69 | #define X_ENCRYPT_METHOD_RESTRICT 70 | #define X_ENCRYPT_ASSUME(x) 71 | #endif 72 | 73 | #ifndef ALIGN_OF // Baselib header can also define this - if so use their definition. 74 | #if defined(__GNUC__) || defined(__SNC__) || defined(__clang__) 75 | #define ALIGN_OF(T) __alignof__(T) 76 | #define ALIGN_TYPE(val) __attribute__((aligned(val))) 77 | #define ALIGN_FIELD(val) ALIGN_TYPE(val) 78 | #define X_ENCRYPT_FORCE_INLINE inline __attribute__ ((always_inline)) 79 | #define X_ENCRYPT_MANAGED_FORCE_INLINE X_ENCRYPT_FORCE_INLINE 80 | #elif defined(_MSC_VER) 81 | #define ALIGN_OF(T) __alignof(T) 82 | #if _MSC_VER >= 1900 && defined(__cplusplus) 83 | #define ALIGN_TYPE(val) alignas(val) 84 | #else 85 | #define ALIGN_TYPE(val) __declspec(align(val)) 86 | #endif 87 | #define ALIGN_FIELD(val) __declspec(align(val)) 88 | #define X_ENCRYPT_FORCE_INLINE __forceinline 89 | #define X_ENCRYPT_MANAGED_FORCE_INLINE inline 90 | #else 91 | #define ALIGN_TYPE(size) 92 | #define ALIGN_FIELD(size) 93 | #define X_ENCRYPT_FORCE_INLINE inline 94 | #define X_ENCRYPT_MANAGED_FORCE_INLINE X_ENCRYPT_FORCE_INLINE 95 | #endif 96 | #endif 97 | 98 | /* Debugging */ 99 | #ifndef X_ENCRYPT_DEBUG 100 | #define X_ENCRYPT_DEBUG 0 101 | #endif 102 | 103 | #if defined(_MSC_VER) 104 | #define X_ENCRYPT_HAS_CXX_CONSTEXPR (_MSC_VER >= 1900) 105 | #else 106 | #define X_ENCRYPT_HAS_CXX_CONSTEXPR (__has_feature (cxx_constexpr)) 107 | #endif 108 | 109 | #if X_ENCRYPT_HAS_CXX_CONSTEXPR 110 | #define COMPILE_TIME_CONST constexpr 111 | #else 112 | #define COMPILE_TIME_CONST const 113 | #endif 114 | 115 | /* clang specific __has_builtin check */ 116 | #ifndef __has_builtin 117 | #define __has_builtin(x) 0 // Compatibility with non-clang compilers. 118 | #endif 119 | 120 | #if _MSC_VER 121 | #define X_ENCRYPT_UNREACHABLE __assume(0) 122 | #elif __has_builtin(__builtin_unreachable) 123 | #define X_ENCRYPT_UNREACHABLE __builtin_unreachable() 124 | #else 125 | #define X_ENCRYPT_UNREACHABLE 126 | #endif 127 | 128 | /* Debug macros */ 129 | 130 | #if defined(_MSC_VER) && _MSC_VER >= 1900 // UTF-8 literals are only supported in VS2015+ 131 | // On MSVC, __FILE__ will expand to ANSI string literal and will fail to compile if there are unicode characters in the path 132 | // So we specify it to be UTF-8 literal explicitly 133 | #define MAKE_UTF8_LITERAL_HELPER(x) u8 ## x 134 | #define MAKE_UTF8_LITERAL(x) MAKE_UTF8_LITERAL_HELPER(x) 135 | #else 136 | #define MAKE_UTF8_LITERAL(x) x 137 | #endif 138 | 139 | #define __FILE_UTF8__ MAKE_UTF8_LITERAL(__FILE__) 140 | #define STRINGIZE(L) #L 141 | #define MAKE_STRING(M, L) M(L) 142 | #define $Line MAKE_STRING( STRINGIZE, __LINE__ ) 143 | #define FIXME "FIXME: " 144 | #define ICALLMESSAGE(name) __FILE_UTF8__ "(" $Line ") : FIXME: Missing internal call implementation: " name 145 | #define RUNTIMEMESSAGE(name) __FILE_UTF8__ "(" $Line ") : FIXME: Missing runtime implementation: " name 146 | #define NOTSUPPORTEDICALLMESSAGE(target, name, reason) __FILE_UTF8__ "(" $Line ") : Unsupported internal call for " target ":" name " - " reason 147 | 148 | #if X_ENCRYPT_COMPILER_MSVC 149 | #define X_ENCRYPT_DIR_SEPARATOR '\\' /* backslash */ 150 | #else 151 | #define X_ENCRYPT_DIR_SEPARATOR '/' /* forward slash */ 152 | #endif 153 | 154 | #ifdef __cplusplus 155 | template 156 | struct XEncryptStaticAssertHelper; 157 | 158 | template<> 159 | struct XEncryptStaticAssertHelper 160 | { 161 | }; 162 | 163 | 164 | #define XEncryptAssert(x) do { (void)(x); X_ENCRYPT_ASSERT(x); } while (false) 165 | #define XEncryptStaticAssert(...) do { XEncryptStaticAssertHelper<(__VA_ARGS__)>(); } while (false) 166 | #endif 167 | 168 | #ifndef NO_UNUSED_WARNING 169 | #define NO_UNUSED_WARNING(expr) (void)(expr) 170 | #endif // !NO_UNUSED_WARNING 171 | 172 | #if (defined(_MSC_VER) && _MSC_VER > 1600) || (__has_feature(cxx_override_control)) 173 | #define X_ENCRYPT_OVERRIDE override 174 | #define X_ENCRYPT_FINAL final 175 | #else 176 | #define X_ENCRYPT_OVERRIDE 177 | #define X_ENCRYPT_FINAL 178 | #endif 179 | 180 | #if (__has_feature(cxx_deleted_functions) || (defined(_MSC_VER) && _MSC_VER >= 1800)) 181 | #define X_ENCRYPT_HAS_DELETED_FUNCTIONS 1 182 | #else 183 | #define X_ENCRYPT_HAS_DELETED_FUNCTIONS 0 184 | #endif 185 | 186 | #if X_ENCRYPT_COMPILER_MSVC 187 | #define X_ENCRYPT_ATTRIBUTE_WEAK 188 | #else 189 | #define X_ENCRYPT_ATTRIBUTE_WEAK __attribute__((weak)) 190 | #endif 191 | 192 | #ifdef _MSC_VER 193 | #define X_ENCRYPT_DEBUG_BREAK() __debugbreak() 194 | #else 195 | #define X_ENCRYPT_DEBUG_BREAK() 196 | #endif 197 | 198 | #define X_ENCRYPT_USE_GENERIC_ASSERT !(X_ENCRYPT_TARGET_WINDOWS || X_ENCRYPT_TARGET_XBOXONE || X_ENCRYPT_TARGET_WINRT || X_ENCRYPT_TARGET_PS4 || X_ENCRYPT_TARGET_PS5) 199 | 200 | #if !X_ENCRYPT_DEBUG 201 | #define X_ENCRYPT_ASSERT(expr) void(0) 202 | #else 203 | #if defined(__cplusplus) 204 | #define X_ENCRYPT_ASSERT(expr) (static_cast(expr) ? void(0) : xencrypt_assert(#expr, __FILE__, __LINE__)) 205 | #else 206 | #define X_ENCRYPT_ASSERT(expr) (expr) ? void(0) : xencrypt_assert(#expr, __FILE__, __LINE__)) 207 | #endif 208 | extern void xencrypt_assert(const char* assertion, const char* file, unsigned int line); 209 | #endif 210 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/config_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "platforms.h" 4 | 5 | #if X_ENCRYPT_TARGET_ARMV7 6 | // On ARMv7 with Thumb instructions the lowest bit is always set. 7 | // With Thumb2 the second-to-lowest bit is also set. Mask both of 8 | // them off so that we can do a comparison properly based on the data 9 | // from the linker map file. 10 | #define X_ENCRYPT_POINTER_SPARE_BITS 3 11 | #else 12 | // Some compilers align functions by default (MSVC), some do not (GCC). 13 | // Do not mask bits on platforms that do not absolutely require it. 14 | #define X_ENCRYPT_POINTER_SPARE_BITS 0 15 | #endif 16 | 17 | #if X_ENCRYPT_COMPILER_MSVC || defined(__ARMCC_VERSION) 18 | #define NORETURN __declspec(noreturn) 19 | #elif (X_ENCRYPT_POINTER_SPARE_BITS == 0) && (defined(__clang__) || defined(__GNUC__)) 20 | #define NORETURN __attribute__ ((noreturn)) 21 | #else 22 | #define NORETURN 23 | #endif 24 | 25 | #if X_ENCRYPT_TARGET_IOS || X_ENCRYPT_TARGET_ANDROID || X_ENCRYPT_TARGET_DARWIN 26 | #define REAL_NORETURN __attribute__ ((noreturn)) 27 | #else 28 | #define REAL_NORETURN NORETURN 29 | #endif 30 | 31 | #if !defined(X_ENCRYPT_EXPORT) 32 | #ifdef _MSC_VER 33 | # include 34 | # define X_ENCRYPT_EXPORT __declspec(dllexport) 35 | #elif X_ENCRYPT_TARGET_PSP2 || X_ENCRYPT_TARGET_PS4 36 | # define X_ENCRYPT_EXPORT __declspec(dllexport) 37 | #else 38 | # define X_ENCRYPT_EXPORT __attribute__ ((visibility ("default"))) 39 | #endif 40 | #endif 41 | 42 | #if !defined(X_ENCRYPT_IMPORT) 43 | #ifdef _MSC_VER 44 | # include 45 | # define X_ENCRYPT_IMPORT __declspec(dllimport) 46 | #elif X_ENCRYPT_TARGET_PSP2 || X_ENCRYPT_TARGET_PS4 47 | # define X_ENCRYPT_IMPORT __declspec(dllimport) 48 | #else 49 | # define X_ENCRYPT_IMPORT 50 | #endif 51 | #endif 52 | 53 | #ifdef XENCRYPT_EXPORT_API 54 | # define XENCRYPT_API X_ENCRYPT_EXPORT 55 | #elif XENCRYPT_IMPORT_API 56 | # define XENCRYPT_API X_ENCRYPT_IMPORT 57 | #else 58 | # define XENCRYPT_API 59 | #endif -------------------------------------------------------------------------------- /XEncrypt/encrypt/platforms.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include // ptrdiff_t 4 | 5 | #if defined(__aarch64__) && defined(__arm__) 6 | #error We assume both __aarch64__ and __arm__ cannot be defined at tha same time. 7 | #endif 8 | 9 | #if defined(__aarch64__) || defined(_M_ARM64) 10 | #define X_ENCRYPT_TARGET_ARM64 1 11 | #define X_ENCRYPT_TARGET_ARMV7 0 12 | #elif defined(__arm__) 13 | #define X_ENCRYPT_TARGET_ARM64 0 14 | #define X_ENCRYPT_TARGET_ARMV7 1 15 | #else 16 | #define X_ENCRYPT_TARGET_ARM64 0 17 | #define X_ENCRYPT_TARGET_ARMV7 0 18 | #endif 19 | 20 | // Large executables on ARM64 and ARMv7 can cause linker errors. 21 | // Specifically, the arm instruction set limits the range a branch can 22 | // take (e.g. 128MB on ARM64). Normally, the linker will insert branch 23 | // islands to bridge gaps larger than the maximum branch range. However, 24 | // branch islands only work within a section, not across sections. So if 25 | // IL2CPP puts managed code into a specific section of the binary, branch 26 | // isalnds won't work. That means that proejcts with a large executable 27 | // size may fail to link. 28 | // 29 | // Set the define X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND to a value of 1 30 | // work around this issue. 31 | // 32 | // The cost of this define is in correctness of managed stack traces. 33 | // With this define enabled, managed stack traces maybe not be correct 34 | // in some cases, because the stack trace generation code must use 35 | // fuzzy heuristics to detemine if a given instrion pointer is in a 36 | // managed method. 37 | #if X_ENCRYPT_TARGET_ARM64 || X_ENCRYPT_TARGET_ARMV7 38 | #ifndef X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 39 | #define X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 0 40 | #endif 41 | #endif 42 | 43 | #define X_ENCRYPT_BINARY_SECTION_NAME "x-encrypt" 44 | #if defined(_MSC_VER) 45 | #define X_ENCRYPT_TARGET_WINDOWS 1 46 | 47 | #if X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 48 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 0 49 | #else 50 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS !X_ENCRYPT_MONO_DEBUGGER 51 | #endif 52 | 53 | #if X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 54 | #define X_ENCRYPT_METHOD_ATTR __declspec(code_seg (X_ENCRYPT_BINARY_SECTION_NAME)) 55 | #endif 56 | #if defined(_XBOX_ONE) 57 | #define X_ENCRYPT_TARGET_XBOXONE 1 58 | #define X_ENCRYPT_ENABLE_PLATFORM_THREAD_AFFINTY 1 59 | #elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) 60 | #define X_ENCRYPT_TARGET_WINRT 1 61 | #elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) 62 | #define X_ENCRYPT_TARGET_WINDOWS_GAMES 1 63 | #define X_ENCRYPT_ENABLE_PLATFORM_THREAD_AFFINTY 1 64 | #elif (X_ENCRYPT_CUSTOM_PLATFORM) 65 | 66 | #else 67 | #define X_ENCRYPT_TARGET_WINDOWS_DESKTOP 1 68 | // Windows 7 is the min OS we support, so we cannot link newer APIs 69 | #define NTDDI_VERSION 0x06010000 70 | #define _WIN32_WINNT 0x0601 71 | #define WINVER 0x0601 72 | #endif 73 | 74 | #define _UNICODE 1 75 | #define UNICODE 1 76 | #define STRICT 1 77 | #elif defined(__APPLE__) 78 | #define X_ENCRYPT_TARGET_DARWIN 1 79 | 80 | #include "TargetConditionals.h" 81 | #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV || TARGET_TVOS_SIMULATOR 82 | #define X_ENCRYPT_TARGET_IOS 1 83 | #else 84 | #define X_ENCRYPT_TARGET_OSX 1 85 | #endif 86 | 87 | #if X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 88 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 0 89 | #else 90 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS (!(X_ENCRYPT_TARGET_IOS && X_ENCRYPT_TARGET_ARMV7) && !X_ENCRYPT_MONO_DEBUGGER) 91 | #endif 92 | 93 | #if X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 94 | #define X_ENCRYPT_METHOD_ATTR __attribute__((section ("__TEXT," X_ENCRYPT_BINARY_SECTION_NAME ",regular,pure_instructions"))) 95 | #endif 96 | 97 | // because it's android based, __ANDROID__ is *also* defined on Lumin. 98 | // so we need to check for that *before* we check __ANDROID__ to avoid false 99 | // positives. 100 | #elif defined(LUMIN) 101 | #define X_ENCRYPT_ENABLE_PLATFORM_THREAD_RENAME 1 102 | #define X_ENCRYPT_TARGET_LUMIN 1 103 | #define X_ENCRYPT_USE_GENERIC_DEBUG_LOG 0 104 | #define X_ENCRYPT_SUPPORTS_PROCESS 1 105 | #elif defined(__ANDROID__) 106 | #define X_ENCRYPT_TARGET_ANDROID 1 107 | #define X_ENCRYPT_ENABLE_PLATFORM_THREAD_RENAME 1 108 | #if X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 109 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 0 110 | #else 111 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS !X_ENCRYPT_MONO_DEBUGGER 112 | #endif 113 | 114 | #define X_ENCRYPT_PLATFORM_DISABLE_LIBC_PINVOKE 1 115 | #if X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 116 | #define X_ENCRYPT_METHOD_ATTR __attribute__((section(X_ENCRYPT_BINARY_SECTION_NAME))) 117 | #endif 118 | #elif defined(__EMSCRIPTEN__) 119 | #define X_ENCRYPT_TARGET_JAVASCRIPT 1 120 | #elif defined(__linux__) 121 | #define X_ENCRYPT_TARGET_LINUX 1 122 | 123 | #if X_ENCRYPT_LARGE_EXECUTABLE_ARM_WORKAROUND 124 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 0 125 | #else 126 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS !X_ENCRYPT_MONO_DEBUGGER 127 | #endif 128 | 129 | #if X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 130 | #define X_ENCRYPT_METHOD_ATTR __attribute__((section(X_ENCRYPT_BINARY_SECTION_NAME))) 131 | #endif 132 | #elif defined(NN_PLATFORM_CTR) 133 | #define X_ENCRYPT_TARGET_N3DS 1 134 | #elif X_ENCRYPT_TARGET_CUSTOM 135 | // defined handled externally 136 | #else 137 | #error please define your target platform 138 | #endif 139 | 140 | #if X_ENCRYPT_TARGET_PS5 141 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 1 142 | #define X_ENCRYPT_METHOD_ATTR __attribute__((section(X_ENCRYPT_BINARY_SECTION_NAME))) 143 | #endif 144 | 145 | #ifndef X_ENCRYPT_TARGET_WINDOWS 146 | #define X_ENCRYPT_TARGET_WINDOWS 0 147 | #endif 148 | 149 | #ifndef X_ENCRYPT_TARGET_WINDOWS_DESKTOP 150 | #define X_ENCRYPT_TARGET_WINDOWS_DESKTOP 0 151 | #endif 152 | 153 | #ifndef X_ENCRYPT_TARGET_WINDOWS_GAMES 154 | #define X_ENCRYPT_TARGET_WINDOWS_GAMES 0 155 | #endif 156 | 157 | #ifndef X_ENCRYPT_TARGET_WINRT 158 | #define X_ENCRYPT_TARGET_WINRT 0 159 | #endif 160 | 161 | #ifndef X_ENCRYPT_TARGET_XBOXONE 162 | #define X_ENCRYPT_TARGET_XBOXONE 0 163 | #endif 164 | 165 | #ifndef X_ENCRYPT_TARGET_DARWIN 166 | #define X_ENCRYPT_TARGET_DARWIN 0 167 | #endif 168 | 169 | #ifndef X_ENCRYPT_TARGET_IOS 170 | #define X_ENCRYPT_TARGET_IOS 0 171 | #endif 172 | 173 | #ifndef X_ENCRYPT_TARGET_OSX 174 | #define X_ENCRYPT_TARGET_OSX 0 175 | #endif 176 | 177 | #ifndef X_ENCRYPT_TARGET_ANDROID 178 | #define X_ENCRYPT_TARGET_ANDROID 0 179 | #endif 180 | 181 | #ifndef X_ENCRYPT_TARGET_JAVASCRIPT 182 | #define X_ENCRYPT_TARGET_JAVASCRIPT 0 183 | #endif 184 | 185 | #ifndef X_ENCRYPT_TARGET_LINUX 186 | #define X_ENCRYPT_TARGET_LINUX 0 187 | #endif 188 | 189 | #ifndef X_ENCRYPT_TARGET_N3DS 190 | #define X_ENCRYPT_TARGET_N3DS 0 191 | #endif 192 | 193 | #ifndef X_ENCRYPT_TARGET_PS4 194 | #define X_ENCRYPT_TARGET_PS4 0 195 | #endif 196 | 197 | #ifndef X_ENCRYPT_TARGET_PSP2 198 | #define X_ENCRYPT_TARGET_PSP2 0 199 | #endif 200 | 201 | #ifndef X_ENCRYPT_TARGET_SWITCH 202 | #define X_ENCRYPT_TARGET_SWITCH 0 203 | #endif 204 | 205 | #ifndef X_ENCRYPT_TARGET_LUMIN 206 | #define X_ENCRYPT_TARGET_LUMIN 0 207 | #endif 208 | 209 | #ifndef X_ENCRYPT_TARGET_POSIX 210 | #define X_ENCRYPT_TARGET_POSIX (X_ENCRYPT_TARGET_DARWIN || X_ENCRYPT_TARGET_JAVASCRIPT || X_ENCRYPT_TARGET_LINUX || X_ENCRYPT_TARGET_ANDROID || X_ENCRYPT_TARGET_PS4 || X_ENCRYPT_TARGET_PSP2 || X_ENCRYPT_TARGET_LUMIN) 211 | #endif 212 | 213 | #define X_ENCRYPT_TINY_DEBUGGER (X_ENCRYPT_TINY && X_ENCRYPT_MONO_DEBUGGER) 214 | 215 | #define X_ENCRYPT_X_ENCRYPT_TINY_SUPPORT_THREADS X_ENCRYPT_TINY && X_ENCRYPT_TINY_DEBUGGER 216 | #define X_ENCRYPT_X_ENCRYPT_TINY_SUPPORT_SOCKETS X_ENCRYPT_TINY && X_ENCRYPT_TINY_DEBUGGER 217 | 218 | #ifndef X_ENCRYPT_SUPPORT_THREADS 219 | #define X_ENCRYPT_SUPPORT_THREADS ((!X_ENCRYPT_TARGET_JAVASCRIPT || X_ENCRYPT_TINY_DEBUGGER) && (!X_ENCRYPT_TINY || X_ENCRYPT_X_ENCRYPT_TINY_SUPPORT_THREADS)) 220 | #endif 221 | 222 | #ifndef X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 223 | #define X_ENCRYPT_PLATFORM_SUPPORTS_CUSTOM_SECTIONS 0 224 | #endif 225 | 226 | #ifndef X_ENCRYPT_DEBUG 227 | #define X_ENCRYPT_DEBUG 0 228 | #endif 229 | 230 | #define X_ENCRYPT_USE_STD_THREAD 0 231 | 232 | #define X_ENCRYPT_THREADS_STD X_ENCRYPT_USE_STD_THREAD 233 | #define X_ENCRYPT_THREADS_PTHREAD (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_POSIX) 234 | #define X_ENCRYPT_THREADS_WIN32 (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_WINDOWS) 235 | #define X_ENCRYPT_THREADS_N3DS (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_N3DS) 236 | #define X_ENCRYPT_THREADS_PS4 (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_PS4) 237 | #define X_ENCRYPT_THREADS_PSP2 (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_PSP2) 238 | #define X_ENCRYPT_THREADS_SWITCH (!X_ENCRYPT_THREADS_STD && X_ENCRYPT_TARGET_SWITCH) 239 | 240 | #define X_ENCRYPT_THREAD_HAS_CPU_SET X_ENCRYPT_TARGET_POSIX && !X_ENCRYPT_THREADS_PS4 241 | 242 | /* Trigger assert if 'ptr' is not aligned to 'alignment'. */ 243 | #define X_ENCRYPT_ASSERT_ALIGNMENT(ptr, alignment) \ 244 | X_ENCRYPT_ASSERT((((ptrdiff_t) ptr) & (alignment - 1)) == 0 && "Unaligned pointer!") 245 | 246 | #if defined(_MSC_VER) 247 | #if defined(_M_X64) || defined(_M_ARM64) 248 | #define X_ENCRYPT_SIZEOF_VOID_P 8 249 | #elif defined(_M_IX86) || defined(_M_ARM) 250 | #define X_ENCRYPT_SIZEOF_VOID_P 4 251 | #else 252 | #error invalid windows architecture 253 | #endif 254 | #elif defined(__GNUC__) || defined(__SNC__) 255 | #if defined(__x86_64__) 256 | #define X_ENCRYPT_SIZEOF_VOID_P 8 257 | #elif defined(__i386__) 258 | #define X_ENCRYPT_SIZEOF_VOID_P 4 259 | #elif defined(__EMSCRIPTEN__) 260 | #define X_ENCRYPT_SIZEOF_VOID_P 4 261 | #elif defined(__arm__) 262 | #define X_ENCRYPT_SIZEOF_VOID_P 4 263 | #elif defined(__arm64__) || defined(__aarch64__) 264 | #define X_ENCRYPT_SIZEOF_VOID_P 8 265 | #else 266 | #error invalid windows architecture 267 | #endif 268 | #else 269 | #error please define your target architecture size 270 | #endif 271 | 272 | #ifndef X_ENCRYPT_USE_GENERIC_CRASH_HELPERS 273 | #define X_ENCRYPT_USE_GENERIC_CRASH_HELPERS (!X_ENCRYPT_TARGET_WINDOWS && !X_ENCRYPT_TARGET_POSIX) 274 | #endif 275 | 276 | #ifndef X_ENCRYPT_SUPPORTS_CONSOLE_EXTENSION 277 | #define X_ENCRYPT_SUPPORTS_CONSOLE_EXTENSION X_ENCRYPT_TARGET_ANDROID 278 | #endif 279 | 280 | #define X_ENCRYPT_COMPILER_MSVC (X_ENCRYPT_TARGET_WINDOWS || X_ENCRYPT_TARGET_XBOXONE) 281 | 282 | #if X_ENCRYPT_COMPILER_MSVC 283 | #ifndef STDCALL 284 | #define STDCALL __stdcall 285 | #endif 286 | #ifndef CDECL 287 | #define CDECL __cdecl 288 | #endif 289 | #ifndef FASTCALL 290 | #define FASTCALL __fastcall 291 | #endif 292 | #ifndef THISCALL 293 | #define THISCALL __thiscall 294 | #endif 295 | #else 296 | #define STDCALL 297 | #define CDECL 298 | #define FASTCALL 299 | #define THISCALL 300 | #endif 301 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/Decoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "service/XContext.h" 4 | 5 | namespace xencrypt 6 | { 7 | /// @brief 解密器接口 8 | class XENCRYPT_API Decoder 9 | { 10 | public: 11 | /// @brief 解密数据 12 | /// @param context 解密器上下文 13 | virtual void Decode(XContext* context) = 0; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/Encoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "service/XContext.h" 4 | 5 | namespace xencrypt 6 | { 7 | /// @brief 加密器 8 | class XENCRYPT_API Encoder 9 | { 10 | public: 11 | /// @brief 加密处理 12 | /// @param context 加密上下文 13 | virtual void Encode(XContext* context) = 0; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/XPlugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | #include "Encoder.h" 5 | #include "Decoder.h" 6 | 7 | namespace xencrypt 8 | { 9 | /// @brief 加密/解密器插件抽象基类 10 | class XENCRYPT_API XPlugin 11 | { 12 | public: 13 | XPlugin():_encoder(nullptr), _decoder(nullptr) {} 14 | virtual ~XPlugin() = default; 15 | 16 | public: 17 | /// @brief 根据XContext上下文类型,判定当前插件是否支持 18 | /// @param type 加密/解密上下文类型 19 | /// @return 返回true,支持该类型;否则,不支持. 20 | bool IsSupport(XContextType type) const; 21 | 22 | public: 23 | /// @brief 加密抽象接口 24 | /// @param context 上下文实例 25 | virtual void Encrypt(XContext* context) = 0; 26 | /// @brief 解密抽象接口 27 | /// @param context 上下文实例 28 | virtual void Decrypt(XContext* context) = 0; 29 | /// @brief 检查数据是否已加密 30 | /// @param data 内存数据地址 31 | /// @param size 数据长度 32 | /// @return 数据是否已加密.返回true,数据已加密,否则,未加密. 33 | virtual bool IsEncrypted(const byte* data, int64_t size) = 0; 34 | 35 | protected: 36 | Encoder* _encoder; 37 | Decoder* _decoder; 38 | }; 39 | 40 | inline bool XPlugin::IsSupport(XContextType type) const 41 | { 42 | bool support = false; 43 | if (type == XContextType::XDecrypt) 44 | { 45 | support = _decoder != nullptr; 46 | } 47 | else if (type == XContextType::XEncrypt) 48 | { 49 | support = _encoder != nullptr; 50 | } 51 | return support; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFDecoder.cpp: -------------------------------------------------------------------------------- 1 | #include "common/Logging.h" 2 | #include "common/Allocator.h" 3 | #include "service/Common.h" 4 | #include "service/XService.h" 5 | 6 | #include "XEFDecoder.h" 7 | #include "XEFHeader.h" 8 | #include "XEncodeType.h" 9 | #include "XEFPlugin.h" 10 | #include "ZipUtils.h" 11 | namespace xencrypt 12 | { 13 | namespace 14 | { 15 | class CopyDataScope 16 | { 17 | public: 18 | CopyDataScope(const byte* data, int64_t size):_holder(nullptr) 19 | { 20 | _holder = (byte*)XMEMORY_MALLOC(size); 21 | memcpy(_holder, data, size); 22 | } 23 | 24 | byte* GetData() const { return _holder; } 25 | 26 | ~CopyDataScope() 27 | { 28 | if (_holder != nullptr) 29 | { 30 | XMEMORY_FREE(_holder); 31 | } 32 | _holder = nullptr; 33 | } 34 | 35 | private: 36 | CopyDataScope(const CopyDataScope& other); 37 | CopyDataScope& operator= (const CopyDataScope& other); 38 | 39 | private: 40 | byte* _holder; 41 | }; 42 | } 43 | 44 | 45 | bool XEFDecoder::DecryptData(XContext* context, byte* data, byte** out, size_t& unpackedLen) 46 | { 47 | #ifdef XEF_DECRYPT_SERVICE 48 | XEFHeader* xHeader = (XEFHeader*)data; 49 | 50 | byte* rawdata = (byte*)(data + xHeader->offset); 51 | 52 | //decrypt the data. 53 | for (int i = 0; i < xHeader->encrypt_data_size; i++) 54 | { 55 | byte* c = &rawdata[i]; 56 | *c = ((*c << 0x04) | (*c >> 0x04)); 57 | } 58 | 59 | byte* unpackedData = rawdata; 60 | unpackedLen = xHeader->length; 61 | if (xHeader->encode_type == XEncodeType::XGZip) 62 | { 63 | //Unzip the compressed data 64 | if (!ZipUtils::IsGZipBuffer(rawdata, xHeader->length)) 65 | { 66 | context->SetResultCode(ResultCode::InvalidUnzip); 67 | return false; 68 | } 69 | if (!ZipUtils::GZipUncompress(rawdata, xHeader->length, &unpackedData, &unpackedLen)) 70 | { 71 | context->SetResultCode(ResultCode::InvalidUnzip); 72 | return false; 73 | } 74 | context->SetMemoryType(XCodeMemoryType::AllocateMemory); 75 | } 76 | if (out != nullptr) 77 | { 78 | *out = unpackedData; 79 | } 80 | #endif 81 | return true; 82 | } 83 | 84 | void XEFDecoder::Decode(XContext* context) 85 | { 86 | X_ENCRYPT_ASSERT(context != nullptr); 87 | if(context->GetType() != XContextType::XDecrypt) 88 | { 89 | context->SetResultCode(ResultCode::ContextTypeError); 90 | return; 91 | } 92 | 93 | #ifdef XEF_DECRYPT_SERVICE 94 | byte* input = const_cast(context->GetInputData()); 95 | int64_t inSize = context->GetInputDataLength(); 96 | if (input == nullptr) 97 | { 98 | context->SetResultCode(ResultCode::InvalidInputData); 99 | return; 100 | } 101 | if (inSize <= 0) 102 | { 103 | context->SetResultCode(ResultCode::InvalidInputDataSize); 104 | return; 105 | } 106 | 107 | byte* unpackedData = input; 108 | size_t unpackedLen = inSize; 109 | context->SetMemoryType(XCodeMemoryType::OriginalOffset); 110 | 111 | if (!context->IsEncrypted(input, inSize))//Decrypt data. 112 | { 113 | context->SetResultCode(ResultCode::InvalidInputData); 114 | return; 115 | } 116 | if (context->IsCloneInputData()) 117 | { 118 | //copy the original data. 119 | CopyDataScope scope(context->GetInputData(), inSize); 120 | if (!DecryptData(context, scope.GetData(), &unpackedData, unpackedLen)) 121 | { 122 | return; 123 | } 124 | } 125 | else 126 | { 127 | if (!DecryptData(context, input, &unpackedData, unpackedLen)) 128 | { 129 | return; 130 | } 131 | } 132 | context->SetResultCode(ResultCode::Ok); 133 | context->SetResultData(unpackedData, unpackedLen); 134 | #else 135 | context->SetResultCode(ResultCode::NotSupportDecrypt); 136 | #endif // !XEF_DECRYPT_SERVICE 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFDecoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "config.h" 5 | #include "plugin/Decoder.h" 6 | 7 | namespace xencrypt 8 | { 9 | /// @brief XEF格式解密器 10 | class XENCRYPT_API XEFDecoder final : public Decoder 11 | { 12 | public: 13 | XEFDecoder() = default; 14 | virtual ~XEFDecoder() = default; 15 | XEFDecoder(XEFDecoder&&) noexcept = default; 16 | XEFDecoder(const XEFDecoder&) = delete; 17 | 18 | XEFDecoder& operator=(const XEFDecoder&) = delete; 19 | /// @brief 解密数据 20 | /// @param context 解密器上下文 21 | virtual void Decode(XContext* context) final override; 22 | 23 | private: 24 | bool DecryptData(XContext* context, byte* data, byte** out, size_t& unpackedLen); 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFEncoder.cpp: -------------------------------------------------------------------------------- 1 | #include "common/Logging.h" 2 | #include "common/Allocator.h" 3 | 4 | #include "service/Common.h" 5 | #include "service/XService.h" 6 | 7 | #include "XEFEncoder.h" 8 | #include "XEFHeader.h" 9 | #include "XEncodeType.h" 10 | #include "XEFPlugin.h" 11 | #include "ZipUtils.h" 12 | 13 | namespace xencrypt 14 | { 15 | void XEFEncoder::Encode(XContext* context) 16 | { 17 | X_ENCRYPT_ASSERT(context != nullptr); 18 | if (context->GetType() != XContextType::XEncrypt) 19 | { 20 | context->SetResultCode(ResultCode::ContextTypeError); 21 | return; 22 | } 23 | #ifdef XEF_ENCRYPT_SERVICE 24 | byte* input = const_cast(context->GetInputData()); 25 | int64_t inSize = context->GetInputDataLength(); 26 | if (input == nullptr) 27 | { 28 | context->SetResultCode(ResultCode::InvalidInputData); 29 | return; 30 | } 31 | if (inSize <= 0) 32 | { 33 | context->SetResultCode(ResultCode::InvalidInputDataSize); 34 | return; 35 | } 36 | 37 | byte* unpackedData = input; 38 | size_t unpackedLen = inSize; 39 | context->SetMemoryType(XCodeMemoryType::OriginalOffset); 40 | 41 | if (context->IsEncrypted(input, inSize))//XEncode file. 42 | { 43 | context->SetResultCode(ResultCode::EncryptedData); 44 | return; 45 | } 46 | 47 | XEFHeader xHeader; 48 | memset(&xHeader, 0, sizeof(XEFHeader)); 49 | xHeader.sign = (*((unsigned*)(&kXFileSignatureCode))); 50 | xHeader.offset = sizeof(XEFHeader); 51 | xHeader.encode_type = (uint8_t)_encodeType; 52 | xHeader.version = 1; 53 | xHeader.encrypt_data_size = _encryptSize; 54 | byte* xefData = nullptr; 55 | byte* encodeData = nullptr; 56 | unsigned long dataSize = 0; 57 | if (xHeader.encode_type == XEncodeType::XGZip) 58 | { 59 | dataSize = (unsigned long)inSize; 60 | //data too small. 61 | if (dataSize < 32) 62 | { 63 | dataSize = 32; 64 | } 65 | dataSize = ZipUtils::CompressMemoryBound(dataSize); 66 | xefData = (byte*)XMEMORY_MALLOC(xHeader.offset + dataSize); 67 | if (xefData == nullptr) 68 | { 69 | context->SetResultCode(ResultCode::OutMemory); 70 | return; 71 | } 72 | 73 | bool tryAgain = false; 74 | encodeData = xefData + xHeader.offset; 75 | if (!ZipUtils::GZipCompress(input, inSize, encodeData, &dataSize)) 76 | { 77 | XMEMORY_FREE(xefData); 78 | context->SetResultCode(ResultCode::InvalidZip); 79 | 80 | tryAgain = true; 81 | } 82 | 83 | if (tryAgain) 84 | { 85 | std::string outData; 86 | int retCode = ZipUtils::GZipCompress(input, inSize, outData); 87 | if (retCode != 0) 88 | { 89 | context->SetResultCode(ResultCode::InvalidZip); 90 | return; 91 | } 92 | dataSize = (unsigned long)outData.length(); 93 | xefData = (byte*)XMEMORY_MALLOC(xHeader.offset + dataSize); 94 | if (xefData == nullptr) 95 | { 96 | context->SetResultCode(ResultCode::OutMemory); 97 | return; 98 | } 99 | encodeData = xefData + xHeader.offset; 100 | memcpy(encodeData, outData.data(), dataSize); 101 | } 102 | 103 | context->SetMemoryType(XCodeMemoryType::AllocateMemory); 104 | } 105 | else 106 | { 107 | xefData = (byte*)XMEMORY_MALLOC(xHeader.offset + inSize); 108 | if (xefData == nullptr) 109 | { 110 | context->SetResultCode(ResultCode::OutMemory); 111 | return; 112 | } 113 | dataSize = (unsigned long)inSize; 114 | encodeData = xefData + xHeader.offset; 115 | memcpy(encodeData, input, inSize); 116 | context->SetMemoryType(XCodeMemoryType::AllocateMemory); 117 | } 118 | 119 | if (xHeader.encrypt_data_size > dataSize) 120 | { 121 | xHeader.encrypt_data_size = (uint8_t)dataSize; 122 | } 123 | xHeader.length = (uint32_t)dataSize; 124 | 125 | EncryptData(encodeData, xHeader.encrypt_data_size); 126 | memcpy(xefData, &xHeader, sizeof(XEFHeader)); 127 | context->SetResultData(xefData, xHeader.offset + xHeader.length); 128 | context->SetResultCode(ResultCode::Ok); 129 | #else 130 | context->SetResultCode(ResultCode::NotSupportEncrypt); 131 | #endif // !XEF_ENCRYPT_SERVICE 132 | } 133 | 134 | byte* XEFEncoder::EncryptData(byte* rawdata, int size) 135 | { 136 | #ifdef XEF_ENCRYPT_SERVICE 137 | X_ENCRYPT_ASSERT(rawdata != NULL); 138 | //encrypt the data. 139 | for (int i = 0; i < size; i++) 140 | { 141 | byte* c = &rawdata[i]; 142 | *c = ((*c << 0x04) | (*c >> 0x04)); 143 | } 144 | #endif // XEF_ENCRYPT_SERVICE 145 | return rawdata; 146 | } 147 | 148 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFEncoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "config.h" 5 | #include "plugin/Encoder.h" 6 | #include "XEncodeType.h" 7 | 8 | namespace xencrypt 9 | { 10 | /// @brief XEF格式加密器 11 | class XENCRYPT_API XEFEncoder final : public Encoder 12 | { 13 | public: 14 | XEFEncoder(XEncodeType encodeType, uint8_t encryptSize):_encodeType(encodeType),_encryptSize(encryptSize){}; 15 | virtual ~XEFEncoder() = default; 16 | XEFEncoder (XEFEncoder&&) noexcept = default; 17 | XEFEncoder (const XEFEncoder&) = delete; 18 | XEFEncoder& operator=(XEFEncoder&&) = delete; 19 | /// @brief 加密处理 20 | /// @param context 加密上下文 21 | virtual void Encode(XContext* context) final override; 22 | 23 | private: 24 | byte* EncryptData(byte* rawdata, int size); 25 | /// @brief 加密数据长度 26 | uint8_t _encryptSize; 27 | /// @brief 加密编码类型 28 | XEncodeType _encodeType; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFHeader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace xencrypt 3 | { 4 | /// @brief XEF格式数据加密头部 5 | typedef struct 6 | { 7 | /// @brief 格式签名标记 8 | uint32_t sign; 9 | /// @brief 源数据偏移 10 | uint8_t offset; 11 | /// @brief 加密数据长度 12 | uint8_t encrypt_data_size; 13 | /// @brief 数据加密编码类型.0:默认,不做处理. 1: gzip 压缩. 14 | uint8_t encode_type; 15 | /// @brief 编码格式版本 16 | uint8_t version; 17 | /// @brief 源数据长度 18 | uint32_t length; 19 | /// @brief 预留字段 20 | uint32_t reserved; 21 | }XEFHeader; 22 | 23 | 24 | static const byte kXFileSignatureCode[] = { '@', 'X', 'F', 'E' }; 25 | template 26 | bool IS_XFILE_SIGNATURE_CODE(T code) { return (code == *((uint32_t*)(&kXFileSignatureCode))); } 27 | } 28 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include "common/Logging.h" 2 | #include "define.h" 3 | #include "XEFPlugin.h" 4 | #include "XEFHeader.h" 5 | #include "XEFEncoder.h" 6 | #include "XEFDecoder.h" 7 | namespace xencrypt 8 | { 9 | XEFPlugin::XEFPlugin(XEncodeType type, uint8_t encryptSize) 10 | { 11 | #if XEF_ENCRYPT_SERVICE 12 | _encoder = new XEFEncoder(type, encryptSize); 13 | #endif // XEF_ENCRYPT_SERVICE 14 | 15 | #if XEF_DECRYPT_SERVICE 16 | _decoder = new XEFDecoder(); 17 | #endif // XEF_DECRYPT_SERVICE 18 | } 19 | 20 | XEFPlugin::~XEFPlugin() 21 | { 22 | #if XEF_ENCRYPT_SERVICE 23 | delete _encoder; 24 | _encoder = nullptr; 25 | #endif // XEF_ENCRYPT_SERVICE 26 | 27 | #if XEF_DECRYPT_SERVICE 28 | delete _decoder; 29 | _decoder = nullptr; 30 | #endif // XEF_DECRYPT_SERVICE 31 | } 32 | 33 | bool XEFPlugin::IsEncrypted(const byte* data, int64_t size) 34 | { 35 | if (data == nullptr || size < sizeof(XEFHeader)) 36 | { 37 | return false; 38 | } 39 | XEFHeader* xHeader = (XEFHeader*)data; 40 | bool ret = IS_XFILE_SIGNATURE_CODE(xHeader->sign); 41 | Logging::Write("IsEncrypted:%s", (ret ? "True" : "False")); 42 | 43 | return ret; 44 | } 45 | 46 | void XEFPlugin::Encrypt(XContext* context) 47 | { 48 | X_ENCRYPT_ASSERT(context != nullptr); 49 | if (_encoder == nullptr) 50 | { 51 | context->SetResultCode(ResultCode::InvalidEncoder); 52 | return; 53 | } 54 | _encoder->Encode(context); 55 | } 56 | 57 | void XEFPlugin::Decrypt(XContext* context) 58 | { 59 | X_ENCRYPT_ASSERT(context != nullptr); 60 | if (_decoder == nullptr) 61 | { 62 | context->SetResultCode(ResultCode::InvalidDecoder); 63 | return; 64 | } 65 | _decoder->Decode(context); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFPlugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "plugin/XPlugin.h" 5 | #include "XEncodeType.h" 6 | 7 | namespace xencrypt 8 | { 9 | /// @brief XEF 格式加密/解密器插件 10 | class XENCRYPT_API XEFPlugin final : public XPlugin 11 | { 12 | public: 13 | XEFPlugin(XEncodeType type, uint8_t encryptSize); 14 | ~XEFPlugin(); 15 | XEFPlugin(const XEFPlugin&) = delete; 16 | XEFPlugin(XEFPlugin&&) = delete; 17 | XEFPlugin& operator=(const XEFPlugin&) = delete; 18 | public: 19 | /// @brief 检查数据是否已加密 20 | /// @param data 内存数据地址 21 | /// @param size 数据长度 22 | /// @return 数据是否已加密.返回true,数据已加密,否则,未加密. 23 | virtual bool IsEncrypted(const byte* data, int64_t size) override; 24 | /// @brief 加密 25 | /// @param context 加密上下文 26 | virtual void Encrypt(XContext* context) override; 27 | /// @brief 解密 28 | /// @param context 解密上下文 29 | virtual void Decrypt(XContext* context) override; 30 | }; 31 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFRuntimeApi.cpp: -------------------------------------------------------------------------------- 1 | #include "XEFRuntimeApi.h" 2 | #include "XEFPlugin.h" 3 | 4 | using namespace xencrypt; 5 | 6 | XENCRYPT_API void* xef_plugin_create(int type, uint8_t encryptSize) 7 | { 8 | return new XEFPlugin((XEncodeType)type, encryptSize); 9 | } 10 | 11 | XENCRYPT_API void xef_plugin_destroy(void* plugin) 12 | { 13 | XEFPlugin* pluginPtr = reinterpret_cast(plugin); 14 | if (pluginPtr == nullptr) 15 | { 16 | return; 17 | } 18 | delete pluginPtr; 19 | pluginPtr = nullptr; 20 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEFRuntimeApi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif // __cplusplus 9 | 10 | /// @brief 创建XEF格式加密/解密器插件实例 11 | /// @param type 数据加密编码类型 12 | /// @param encryptSize 数据加密长度 13 | /// @return 插件实例指针 14 | XENCRYPT_API void* xef_plugin_create(int type, uint8_t encryptSize); 15 | /// @brief 销毁XEF格式 加密/解密插件实例 16 | /// @param plugin 已创建的插件实例 17 | XENCRYPT_API void xef_plugin_destroy(void* plugin); 18 | 19 | #if defined(__cplusplus) 20 | } 21 | #endif // __cplusplus -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/XEncodeType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace xencrypt 4 | { 5 | /// @brief 加密服务时,源数据加密编码格式 6 | enum XEncodeType 7 | { 8 | /// @brief 源数据不重新编码 9 | XNone, 10 | /// @brief 源数据重新GZip压缩编码 11 | XGZip, 12 | }; 13 | 14 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/ZipUtils.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ZipUtils.h" 3 | 4 | #include "zlib/zlib.h" 5 | 6 | #include "common/Logging.h" 7 | #include "common/Allocator.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace xencrypt 13 | { 14 | #define BUFFER_INC_FACTOR (2) 15 | 16 | int ZipUtils::GZipUncompressWithHint(const byte* in, size_t inLength, size_t outLengthHint, byte** out, size_t* outLength) 17 | { 18 | X_ENCRYPT_ASSERT(in != NULL); 19 | X_ENCRYPT_ASSERT(inLength > 0); 20 | 21 | X_ENCRYPT_ASSERT(out != NULL); 22 | X_ENCRYPT_ASSERT(outLength != NULL); 23 | 24 | /* ret value */ 25 | int err = Z_OK; 26 | 27 | size_t bufferSize = outLengthHint; 28 | *out = (byte*)XMEMORY_MALLOC(bufferSize); 29 | 30 | z_stream d_stream; /* decompression stream */ 31 | d_stream.zalloc = (alloc_func)0; 32 | d_stream.zfree = (free_func)0; 33 | d_stream.opaque = (voidpf)0; 34 | 35 | d_stream.next_in = (z_const Bytef*)in; 36 | d_stream.avail_in = static_cast(inLength); 37 | d_stream.next_out = *out; 38 | d_stream.avail_out = static_cast(bufferSize); 39 | 40 | /* window size to hold 256k */ 41 | if ((err = inflateInit2(&d_stream, 15 + 32)) != Z_OK) 42 | { 43 | return err; 44 | } 45 | 46 | while (true) 47 | { 48 | err = inflate(&d_stream, Z_NO_FLUSH); 49 | 50 | if (err == Z_STREAM_END) 51 | { 52 | break; 53 | } 54 | 55 | switch (err) 56 | { 57 | case Z_NEED_DICT: 58 | err = Z_DATA_ERROR; 59 | case Z_DATA_ERROR: 60 | case Z_MEM_ERROR: 61 | inflateEnd(&d_stream); 62 | return err; 63 | } 64 | 65 | // not enough memory ? 66 | if (err != Z_STREAM_END) 67 | { 68 | *out = (byte*)XMEMORY_REALLOC(*out, bufferSize * BUFFER_INC_FACTOR); 69 | 70 | /* not enough memory, ouch */ 71 | if (!*out) 72 | { 73 | Logging::Write("ZipUtils: realloc failed"); 74 | inflateEnd(&d_stream); 75 | return Z_MEM_ERROR; 76 | } 77 | 78 | d_stream.next_out = *out + bufferSize; 79 | d_stream.avail_out = static_cast(bufferSize); 80 | bufferSize *= BUFFER_INC_FACTOR; 81 | } 82 | } 83 | *outLength = bufferSize - d_stream.avail_out; 84 | err = inflateEnd(&d_stream); 85 | return err; 86 | } 87 | 88 | bool ZipUtils::GZipUncompressWithHint(const byte* in, size_t inLength, byte** out, size_t* outSize, size_t outLengthHint) 89 | { 90 | X_ENCRYPT_ASSERT(outSize != NULL); 91 | int err = GZipUncompressWithHint(in, inLength, outLengthHint, out, outSize); 92 | 93 | if (err != Z_OK || *out == nullptr) 94 | { 95 | if (err == Z_MEM_ERROR) 96 | { 97 | Logging::Write("ZipUtils: Out of memory while decompressing map data!"); 98 | } 99 | else if (err == Z_VERSION_ERROR) 100 | { 101 | Logging::Write("ZipUtils: Incompatible zlib version!"); 102 | } 103 | else if (err == Z_DATA_ERROR) 104 | { 105 | Logging::Write("ZipUtils: Incorrect zlib compressed data!"); 106 | } 107 | else 108 | { 109 | Logging::Write("ZipUtils: Unknown error while decompressing map data!"); 110 | } 111 | 112 | if (*out != nullptr) 113 | { 114 | XMEMORY_FREE(*out); 115 | *out = nullptr; 116 | } 117 | *outSize = 0; 118 | return false; 119 | } 120 | return true; 121 | } 122 | 123 | bool ZipUtils::GZipUncompress(const byte* in, size_t inLength, byte** out, size_t* outSize) 124 | { 125 | // 256k for hint 126 | return Z_OK == GZipUncompressWithHint(in, inLength, 256 * 1024, out, outSize); 127 | } 128 | 129 | unsigned long ZipUtils::CompressMemoryBound(unsigned long inLength) 130 | { 131 | return compressBound(inLength); 132 | } 133 | 134 | bool ZipUtils::GZipCompress(const byte* in, size_t inLength, byte* out, unsigned long* outLength) 135 | { 136 | X_ENCRYPT_ASSERT(in != NULL); 137 | X_ENCRYPT_ASSERT(inLength > 0); 138 | 139 | X_ENCRYPT_ASSERT(out != NULL); 140 | X_ENCRYPT_ASSERT(outLength != NULL); 141 | 142 | z_stream stream; 143 | int err; 144 | const uInt max = (uInt)-1; 145 | uLong left; 146 | 147 | left = *outLength; 148 | *outLength = 0; 149 | 150 | stream.zalloc = (alloc_func)0; 151 | stream.zfree = (free_func)0; 152 | stream.opaque = (voidpf)0; 153 | 154 | //Initialize the state of zlib, if success return Z_OK. 155 | //deflateInit:zlib, deflateInit2:gzip 156 | // err = deflateInit(&strm, Z_DEFAULT_COMPRESSION); 157 | // hard to believe they don't have a macro for gzip encoding,"Add 16" is the best thing zlib can do: 158 | //"Add 16 to windowBits to write a simple gzip header and trailer around the compressed data instead of a zlib wrapper" 159 | err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); 160 | if (err == Z_OK) 161 | { 162 | stream.next_out = out; 163 | stream.avail_out = 0; 164 | stream.next_in = (z_const Bytef*)in; 165 | stream.avail_in = 0; 166 | do { 167 | if (stream.avail_out == 0) { 168 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 169 | left -= stream.avail_out; 170 | } 171 | if (stream.avail_in == 0) { 172 | stream.avail_in = inLength > (uLong)max ? max : (uInt)inLength; 173 | inLength -= stream.avail_in; 174 | } 175 | err = deflate(&stream, inLength ? Z_NO_FLUSH : Z_FINISH); 176 | } while (err == Z_OK); 177 | *outLength = stream.total_out; 178 | deflateEnd(&stream); 179 | } 180 | int ret = err == Z_STREAM_END ? Z_OK : err; 181 | if (ret != Z_OK) 182 | { 183 | if (ret == Z_MEM_ERROR) 184 | { 185 | Logging::Write("ZipUtils: Out of memory while compressing map data!"); 186 | } 187 | else if (ret == Z_BUF_ERROR) 188 | { 189 | Logging::Write("ZipUtils: There was not enough room in the output buffer!"); 190 | } 191 | *outLength = 0; 192 | return false; 193 | } 194 | return true; 195 | } 196 | 197 | 198 | #ifndef GZIP_CHUNK_SIZE 199 | #define GZIP_CHUNK_SIZE 16384 200 | #endif // !GZIP_CHUNK_SIZE 201 | 202 | int ZipUtils::GZipCompress(const byte* in_str, size_t in_len, std::string& out_str, int level) 203 | { 204 | if (!in_str) 205 | return Z_DATA_ERROR; 206 | 207 | int ret, flush; 208 | unsigned have; 209 | z_stream strm; 210 | 211 | unsigned char out[GZIP_CHUNK_SIZE] = { 0 }; 212 | 213 | /* allocate deflate state */ 214 | strm.zalloc = Z_NULL; 215 | strm.zfree = Z_NULL; 216 | strm.opaque = Z_NULL; 217 | 218 | //ret = deflateInit(&strm, level); 219 | ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); 220 | if (ret != Z_OK) 221 | return ret; 222 | 223 | std::shared_ptr sp_strm(&strm, [](z_stream* strm) { (void)deflateEnd(strm); }); 224 | 225 | const byte* end = in_str + in_len; 226 | 227 | size_t pos_index = 0; 228 | size_t distance = 0; 229 | /* compress until end of file */ 230 | do { 231 | distance = end - in_str; 232 | strm.avail_in = (uInt)((distance >= GZIP_CHUNK_SIZE) ? GZIP_CHUNK_SIZE : distance); 233 | strm.next_in = (Bytef*)in_str; 234 | 235 | // next pos 236 | in_str += strm.avail_in; 237 | flush = (in_str == end) ? Z_FINISH : Z_NO_FLUSH; 238 | 239 | /* run deflate() on input until output buffer not full, finish 240 | compression if all of source has been read in */ 241 | do { 242 | strm.avail_out = GZIP_CHUNK_SIZE; 243 | strm.next_out = out; 244 | ret = deflate(&strm, flush); /* no bad return value */ 245 | if (ret == Z_STREAM_ERROR) 246 | break; 247 | have = GZIP_CHUNK_SIZE - strm.avail_out; 248 | out_str.append((const char*)out, have); 249 | } while (strm.avail_out == 0); 250 | 251 | if (strm.avail_in != 0) /* all input will be used */ 252 | break; 253 | 254 | /* done when last data in file processed */ 255 | } while (flush != Z_FINISH); 256 | 257 | if (ret != Z_STREAM_END) /* stream will be complete */ 258 | return Z_STREAM_ERROR; 259 | /* clean up and return */ 260 | return Z_OK; 261 | } 262 | 263 | int ZipUtils::GZipDecompress(const byte* in_str, size_t in_len, std::string& out_str) 264 | { 265 | if (!in_str) 266 | return Z_DATA_ERROR; 267 | 268 | int ret; 269 | unsigned have; 270 | z_stream strm; 271 | unsigned char out[GZIP_CHUNK_SIZE] = { 0 }; 272 | 273 | /* allocate inflate state */ 274 | strm.zalloc = Z_NULL; 275 | strm.zfree = Z_NULL; 276 | strm.opaque = Z_NULL; 277 | strm.avail_in = 0; 278 | strm.next_in = Z_NULL; 279 | ret = inflateInit(&strm); 280 | if (ret != Z_OK) 281 | return ret; 282 | 283 | std::shared_ptr sp_strm(&strm, [](z_stream* strm) { (void)inflateEnd(strm); }); 284 | 285 | const byte* end = in_str + in_len; 286 | 287 | size_t pos_index = 0; 288 | size_t distance = 0; 289 | 290 | int flush = 0; 291 | /* decompress until deflate stream ends or end of file */ 292 | do { 293 | distance = end - in_str; 294 | strm.avail_in = (uInt)((distance >= GZIP_CHUNK_SIZE) ? GZIP_CHUNK_SIZE : distance); 295 | strm.next_in = (Bytef*)in_str; 296 | 297 | // next pos 298 | in_str += strm.avail_in; 299 | flush = (in_str == end) ? Z_FINISH : Z_NO_FLUSH; 300 | 301 | /* run inflate() on input until output buffer not full */ 302 | do { 303 | strm.avail_out = GZIP_CHUNK_SIZE; 304 | strm.next_out = out; 305 | ret = inflate(&strm, Z_NO_FLUSH); 306 | if (ret == Z_STREAM_ERROR) /* state not clobbered */ 307 | break; 308 | switch (ret) 309 | { 310 | case Z_NEED_DICT: 311 | ret = Z_DATA_ERROR; /* and fall through */ 312 | case Z_DATA_ERROR: 313 | case Z_MEM_ERROR: 314 | return ret; 315 | } 316 | have = GZIP_CHUNK_SIZE - strm.avail_out; 317 | out_str.append((const char*)out, have); 318 | } while (strm.avail_out == 0); 319 | 320 | /* done when inflate() says it's done */ 321 | } while (flush != Z_FINISH); 322 | 323 | /* clean up and return */ 324 | return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 325 | } 326 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/ZipUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "config.h" 5 | namespace xencrypt 6 | { 7 | class XENCRYPT_API ZipUtils 8 | { 9 | public: 10 | /** 11 | * Inflates either zlib or gzip deflated memory. The inflated memory is expected to be freed by the caller. 12 | * It will allocate 256k for the destination buffer. If it is not enough it will multiply the previous buffer size per 2, until there is enough memory. 13 | * @return The length of the deflated buffer. 14 | */ 15 | static bool GZipUncompress(const byte* in, size_t inLength, byte** out, size_t* outSize); 16 | 17 | static unsigned long CompressMemoryBound(unsigned long inLength); 18 | /** 19 | * Deflates either zlib or gzip deflated memory. The Deflated memory is expected to be freed by the caller. 20 | * It will allocate 256k for the destination buffer. If it is not enough it will multiply the previous buffer size per 2, until there is enough memory. 21 | * @return The length of the deflated buffer. 22 | */ 23 | static bool GZipCompress(const byte* in, size_t inLength, byte* out, unsigned long* outSize); 24 | /** 25 | * Compress from file source to file dest until EOF on source. 26 | * returns Z_OK on success 27 | * Z_MEM_ERROR if memory could not be allocated for processing 28 | * Z_STREAM_ERROR if an invalid compression level is supplied 29 | * Z_VERSION_ERROR if the version of zlib.h and the version of the library linked do not match, 30 | * or Z_ERRNO if there is an error reading or writing the files. 31 | */ 32 | static int GZipCompress(const byte* in_str, size_t in_len, std::string& out_str, int level = -1); 33 | /** 34 | * Decompress from file source to file dest until stream ends or EOF. 35 | * returns Z_OK on success 36 | * Z_MEM_ERROR if memory could not be allocated for processing 37 | * Z_DATA_ERROR if the deflate data is invalid or incomplete 38 | * Z_VERSION_ERROR if the version of zlib.h and the version of the library linked do not match 39 | * or Z_ERRNO if there is an error reading or writing the files. 40 | */ 41 | static int GZipDecompress(const byte* in_str, size_t in_len, std::string& out_str); 42 | /** 43 | * Inflates either zlib or gzip deflated memory. The inflated memory is expected to be freed by the caller. 44 | * @param outLengthHint It is assumed to be the needed room to allocate the inflated buffer. 45 | * @return The length of the deflated buffer. 46 | */ 47 | static bool GZipUncompressWithHint(const byte* in, size_t inLength, byte** out, size_t* outSize, size_t outLengthHint); 48 | 49 | /** 50 | * Test the buffer is GZip format or not. 51 | * @return True is GZip format. false is not. 52 | */ 53 | static bool IsGZipBuffer(const byte* buffer, size_t len) 54 | { 55 | return (len >= 2 && (buffer[0] == 0x1F && buffer[1] == 0x8B)); 56 | } 57 | 58 | private: 59 | static int GZipUncompressWithHint(const byte* in, size_t inLength, size_t outLengthHint, byte** out, size_t* outLength); 60 | }; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/define.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined(XEF_DECRYPT_SERVICE) && !defined(XEF_ENCRYPT_SERVICE) 4 | #error "Must define one of 'XEF_DECRYPT_SERVICE' or 'XEF_ENCRYPT_SERVICE' at least one." 5 | #endif 6 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/xxHash/README.md: -------------------------------------------------------------------------------- 1 | xxHash - Extremely fast hash algorithm 2 | ====================================== 3 | 4 | xxHash is an Extremely fast Hash algorithm, running at RAM speed limits. 5 | It successfully completes the [SMHasher](http://code.google.com/p/smhasher/wiki/SMHasher) test suite 6 | which evaluates collision, dispersion and randomness qualities of hash functions. 7 | Code is highly portable, and hashes are identical on all platforms (little / big endian). 8 | 9 | |Branch |Status | 10 | |------------|---------| 11 | |master | [![Build Status](https://travis-ci.org/Cyan4973/xxHash.svg?branch=master)](https://travis-ci.org/Cyan4973/xxHash?branch=master) | 12 | |dev | [![Build Status](https://travis-ci.org/Cyan4973/xxHash.svg?branch=dev)](https://travis-ci.org/Cyan4973/xxHash?branch=dev) | 13 | 14 | 15 | 16 | Benchmarks 17 | ------------------------- 18 | 19 | The benchmark uses SMHasher speed test, compiled with Visual 2010 on a Windows Seven 32-bit box. 20 | The reference system uses a Core 2 Duo @3GHz 21 | 22 | 23 | | Name | Speed | Quality | Author | 24 | |---------------|----------|:-------:|------------------| 25 | | [xxHash] | 5.4 GB/s | 10 | Y.C. | 26 | | MurmurHash 3a | 2.7 GB/s | 10 | Austin Appleby | 27 | | SBox | 1.4 GB/s | 9 | Bret Mulvey | 28 | | Lookup3 | 1.2 GB/s | 9 | Bob Jenkins | 29 | | CityHash64 | 1.05 GB/s| 10 | Pike & Alakuijala| 30 | | FNV | 0.55 GB/s| 5 | Fowler, Noll, Vo | 31 | | CRC32 | 0.43 GB/s| 9 | | 32 | | MD5-32 | 0.33 GB/s| 10 | Ronald L.Rivest | 33 | | SHA1-32 | 0.28 GB/s| 10 | | 34 | 35 | [xxHash]: http://www.xxhash.com 36 | 37 | Q.Score is a measure of quality of the hash function. 38 | It depends on successfully passing SMHasher test set. 39 | 10 is a perfect score. 40 | Algorithms with a score < 5 are not listed on this table. 41 | 42 | A more recent version, XXH64, has been created thanks to [Mathias Westerdahl](https://github.com/JCash), 43 | which offers superior speed and dispersion for 64-bit systems. 44 | Note however that 32-bit applications will still run faster using the 32-bit version. 45 | 46 | SMHasher speed test, compiled using GCC 4.8.2, on Linux Mint 64-bit. 47 | The reference system uses a Core i5-3340M @2.7GHz 48 | 49 | | Version | Speed on 64-bit | Speed on 32-bit | 50 | |------------|------------------|------------------| 51 | | XXH64 | 13.8 GB/s | 1.9 GB/s | 52 | | XXH32 | 6.8 GB/s | 6.0 GB/s | 53 | 54 | This project also includes a command line utility, named `xxhsum`, offering similar features as `md5sum`, 55 | thanks to [Takayuki Matsuoka](https://github.com/t-mat) contributions. 56 | 57 | 58 | ### License 59 | 60 | The library files `xxhash.c` and `xxhash.h` are BSD licensed. 61 | The utility `xxhsum` is GPL licensed. 62 | 63 | 64 | ### Build modifiers 65 | 66 | The following macros can be set at compilation time, 67 | they modify xxhash behavior. They are all disabled by default. 68 | 69 | - `XXH_INLINE_ALL` : Make all functions `inline`, with bodies directly included within `xxhash.h`. 70 | There is no need for an `xxhash.o` module in this case. 71 | Inlining functions is generally beneficial for speed on small keys. 72 | It's especially effective when key length is a compile time constant, 73 | with observed performance improvement in the +200% range . 74 | See [this article](https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html) for details. 75 | - `XXH_ACCEPT_NULL_INPUT_POINTER` : if set to `1`, when input is a null-pointer, 76 | xxhash result is the same as a zero-length key 77 | (instead of a dereference segfault). 78 | - `XXH_FORCE_MEMORY_ACCESS` : default method `0` uses a portable `memcpy()` notation. 79 | Method `1` uses a gcc-specific `packed` attribute, which can provide better performance for some targets. 80 | Method `2` forces unaligned reads, which is not standard compliant, but might sometimes be the only way to extract better performance. 81 | - `XXH_CPU_LITTLE_ENDIAN` : by default, endianess is determined at compile time. 82 | It's possible to skip auto-detection and force format to little-endian, by setting this macro to 1. 83 | Setting it to 0 forces big-endian. 84 | - `XXH_PRIVATE_API` : same impact as `XXH_INLINE_ALL`. 85 | Name underlines that symbols will not be published on library public interface. 86 | - `XXH_NAMESPACE` : prefix all symbols with the value of `XXH_NAMESPACE`. 87 | Useful to evade symbol naming collisions, 88 | in case of multiple inclusions of xxHash source code. 89 | Client applications can still use regular function name, 90 | symbols are automatically translated through `xxhash.h`. 91 | - `XXH_STATIC_LINKING_ONLY` : gives access to state declaration for static allocation. 92 | Incompatible with dynamic linking, due to risks of ABI changes. 93 | - `XXH_NO_LONG_LONG` : removes support for XXH64, 94 | for targets without 64-bit support. 95 | - `XXH_IMPORT` : should only be defined for dynamic linking, it prevents linkage errors with MSVC. 96 | 97 | 98 | ### Example 99 | 100 | Calling xxhash 64-bit variant from a C program : 101 | 102 | ```C 103 | #include "xxhash.h" 104 | 105 | unsigned long long calcul_hash(const void* buffer, size_t length) 106 | { 107 | unsigned long long const seed = 0; /* or any other value */ 108 | unsigned long long const hash = XXH64(buffer, length, seed); 109 | return hash; 110 | } 111 | ``` 112 | 113 | Using streaming variant is more involved, but makes it possible to provide data in multiple rounds : 114 | ```C 115 | #include "stdlib.h" /* abort() */ 116 | #include "xxhash.h" 117 | 118 | 119 | unsigned long long calcul_hash_streaming(someCustomType handler) 120 | { 121 | /* create a hash state */ 122 | XXH64_state_t* const state = XXH64_createState(); 123 | if (state==NULL) abort(); 124 | 125 | size_t const bufferSize = SOME_SIZE; 126 | void* const buffer = malloc(bufferSize); 127 | if (buffer==NULL) abort(); 128 | 129 | /* Initialize state with selected seed */ 130 | unsigned long long const seed = 0; /* or any other value */ 131 | XXH_errorcode const resetResult = XXH64_reset(state, seed); 132 | if (resetResult == XXH_ERROR) abort(); 133 | 134 | /* Feed the state with input data, any size, any number of times */ 135 | (...) 136 | while ( /* any condition */ ) { 137 | size_t const length = get_more_data(buffer, bufferSize, handler); 138 | XXH_errorcode const updateResult = XXH64_update(state, buffer, length); 139 | if (updateResult == XXH_ERROR) abort(); 140 | (...) 141 | } 142 | (...) 143 | 144 | /* Get the hash */ 145 | XXH64_hash_t const hash = XXH64_digest(state); 146 | 147 | /* State can then be re-used; in this example, it is simply freed */ 148 | free(buffer); 149 | XXH64_freeState(state); 150 | 151 | return (unsigned long long)hash; 152 | } 153 | ``` 154 | 155 | ### New experimental hash algorithm 156 | 157 | Starting with `v0.7.0`, the library includes a new algorithm, named `XXH3`, 158 | able to generate 64 and 128-bits hashes. 159 | 160 | The new algorithm is much faster than its predecessors, 161 | for both long and small inputs, 162 | as can be observed in following graphs : 163 | 164 | ![XXH3, bargraph](https://github.com/Cyan4973/xxHash/releases/download/graphs/H_bandwidth_bargraph.png) 165 | 166 | ![XXH3, latency, random size](https://github.com/Cyan4973/xxHash/releases/download/graphs/H_latency_randomS.png) 167 | 168 | The algorithm is currently labelled experimental, as it may change in a future version. 169 | To access it, one need to unlock its declaration using macro `XXH_STATIC_LINKING_ONLY`. 170 | It can be used for ephemeral data, and for tests, but avoid storing long-term hash values yet. 171 | `XXH3` will be stabilized in a future version. 172 | This period will be used to collect users' feedback. 173 | 174 | 175 | ### Other programming languages 176 | 177 | Beyond the C reference version, 178 | xxHash is also available on many programming languages, 179 | thanks to great contributors. 180 | They are [listed here](http://www.xxhash.com/#other-languages). 181 | 182 | 183 | ### Branch Policy 184 | 185 | > - The "master" branch is considered stable, at all times. 186 | > - The "dev" branch is the one where all contributions must be merged 187 | before being promoted to master. 188 | > + If you plan to propose a patch, please commit into the "dev" branch, 189 | or its own feature branch. 190 | Direct commit to "master" are not permitted. 191 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/README: -------------------------------------------------------------------------------- 1 | ZLIB DATA COMPRESSION LIBRARY 2 | 3 | This source code has been modified by Unity for distribution with IL2CPP. 4 | Contact Josh Peterson with questions. 5 | It is located at: https://github.com/Unity-Technologies/zlib 6 | 7 | zlib 1.2.11 is a general purpose data compression library. All the code is 8 | thread safe. The data format used by the zlib library is described by RFCs 9 | (Request for Comments) 1950 to 1952 in the files 10 | http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and 11 | rfc1952 (gzip format). 12 | 13 | All functions of the compression library are documented in the file zlib.h 14 | (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example 15 | of the library is given in the file test/example.c which also tests that 16 | the library is working correctly. Another example is given in the file 17 | test/minigzip.c. The compression library itself is composed of all source 18 | files in the root directory. 19 | 20 | To compile all files and run the test program, follow the instructions given at 21 | the top of Makefile.in. In short "./configure; make test", and if that goes 22 | well, "make install" should work for most flavors of Unix. For Windows, use 23 | one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use 24 | make_vms.com. 25 | 26 | Questions about zlib should be sent to , or to Gilles Vollant 27 | for the Windows DLL version. The zlib home page is 28 | http://zlib.net/ . Before reporting a problem, please check this site to 29 | verify that you have the latest version of zlib; otherwise get the latest 30 | version and check whether the problem still exists or not. 31 | 32 | PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. 33 | 34 | Mark Nelson wrote an article about zlib for the Jan. 1997 35 | issue of Dr. Dobb's Journal; a copy of the article is available at 36 | http://marknelson.us/1997/01/01/zlib-engine/ . 37 | 38 | The changes made in version 1.2.11 are documented in the file ChangeLog. 39 | 40 | Unsupported third party contributions are provided in directory contrib/ . 41 | 42 | zlib is available in Java using the java.util.zip package, documented at 43 | http://java.sun.com/developer/technicalArticles/Programming/compression/ . 44 | 45 | A Perl interface to zlib written by Paul Marquess is available 46 | at CPAN (Comprehensive Perl Archive Network) sites, including 47 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . 48 | 49 | A Python interface to zlib written by A.M. Kuchling is 50 | available in Python 1.5 and later versions, see 51 | http://docs.python.org/library/zlib.html . 52 | 53 | zlib is built into tcl: http://wiki.tcl.tk/4610 . 54 | 55 | An experimental package to read and write files in .zip format, written on top 56 | of zlib by Gilles Vollant , is available in the 57 | contrib/minizip directory of zlib. 58 | 59 | 60 | Notes for some targets: 61 | 62 | - For Windows DLL versions, please see win32/DLL_FAQ.txt 63 | 64 | - For 64-bit Irix, deflate.c must be compiled without any optimization. With 65 | -O, one libpng test fails. The test works in 32 bit mode (with the -n32 66 | compiler flag). The compiler bug has been reported to SGI. 67 | 68 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works 69 | when compiled with cc. 70 | 71 | - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is 72 | necessary to get gzprintf working correctly. This is done by configure. 73 | 74 | - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with 75 | other compilers. Use "make test" to check your compiler. 76 | 77 | - gzdopen is not supported on RISCOS or BEOS. 78 | 79 | - For PalmOs, see http://palmzlib.sourceforge.net/ 80 | 81 | 82 | Acknowledgments: 83 | 84 | The deflate format used by zlib was defined by Phil Katz. The deflate and 85 | zlib specifications were written by L. Peter Deutsch. Thanks to all the 86 | people who reported problems and suggested various improvements in zlib; they 87 | are too numerous to cite here. 88 | 89 | Copyright notice: 90 | 91 | (C) 1995-2017 Jean-loup Gailly and Mark Adler 92 | 93 | This software is provided 'as-is', without any express or implied 94 | warranty. In no event will the authors be held liable for any damages 95 | arising from the use of this software. 96 | 97 | Permission is granted to anyone to use this software for any purpose, 98 | including commercial applications, and to alter it and redistribute it 99 | freely, subject to the following restrictions: 100 | 101 | 1. The origin of this software must not be misrepresented; you must not 102 | claim that you wrote the original software. If you use this software 103 | in a product, an acknowledgment in the product documentation would be 104 | appreciated but is not required. 105 | 2. Altered source versions must be plainly marked as such, and must not be 106 | misrepresented as being the original software. 107 | 3. This notice may not be removed or altered from any source distribution. 108 | 109 | Jean-loup Gailly Mark Adler 110 | jloup@gzip.org madler@alumni.caltech.edu 111 | 112 | If you use the zlib library in a product, we would appreciate *not* receiving 113 | lengthy legal documents to sign. The sources are provided for free but without 114 | warranty of any kind. The library has been entirely written by Jean-loup 115 | Gailly and Mark Adler; it does not include third-party code. 116 | 117 | If you redistribute modified sources, we would appreciate that you include in 118 | the file ChangeLog history information documenting your changes. Please read 119 | the FAQ for more information on the distribution of modified source versions. 120 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2011, 2016 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 11 | 12 | #define BASE 65521U /* largest prime smaller than 65536 */ 13 | #define NMAX 5552 14 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 15 | 16 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 17 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 18 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 19 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 20 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 21 | 22 | /* use NO_DIVIDE if your processor does not do division in hardware -- 23 | try it both ways to see which is faster */ 24 | #ifdef NO_DIVIDE 25 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 26 | (thank you to John Reiser for pointing this out) */ 27 | # define CHOP(a) \ 28 | do { \ 29 | unsigned long tmp = a >> 16; \ 30 | a &= 0xffffUL; \ 31 | a += (tmp << 4) - tmp; \ 32 | } while (0) 33 | # define MOD28(a) \ 34 | do { \ 35 | CHOP(a); \ 36 | if (a >= BASE) a -= BASE; \ 37 | } while (0) 38 | # define MOD(a) \ 39 | do { \ 40 | CHOP(a); \ 41 | MOD28(a); \ 42 | } while (0) 43 | # define MOD63(a) \ 44 | do { /* this assumes a is not negative */ \ 45 | z_off64_t tmp = a >> 32; \ 46 | a &= 0xffffffffL; \ 47 | a += (tmp << 8) - (tmp << 5) + tmp; \ 48 | tmp = a >> 16; \ 49 | a &= 0xffffL; \ 50 | a += (tmp << 4) - tmp; \ 51 | tmp = a >> 16; \ 52 | a &= 0xffffL; \ 53 | a += (tmp << 4) - tmp; \ 54 | if (a >= BASE) a -= BASE; \ 55 | } while (0) 56 | #else 57 | # define MOD(a) a %= BASE 58 | # define MOD28(a) a %= BASE 59 | # define MOD63(a) a %= BASE 60 | #endif 61 | 62 | /* ========================================================================= */ 63 | uLong ZEXPORT adler32_z(adler, buf, len) 64 | uLong adler; 65 | const Bytef *buf; 66 | z_size_t len; 67 | { 68 | unsigned long sum2; 69 | unsigned n; 70 | 71 | /* split Adler-32 into component sums */ 72 | sum2 = (adler >> 16) & 0xffff; 73 | adler &= 0xffff; 74 | 75 | /* in case user likes doing a byte at a time, keep it fast */ 76 | if (len == 1) { 77 | adler += buf[0]; 78 | if (adler >= BASE) 79 | adler -= BASE; 80 | sum2 += adler; 81 | if (sum2 >= BASE) 82 | sum2 -= BASE; 83 | return adler | (sum2 << 16); 84 | } 85 | 86 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 87 | if (buf == Z_NULL) 88 | return 1L; 89 | 90 | /* in case short lengths are provided, keep it somewhat fast */ 91 | if (len < 16) { 92 | while (len--) { 93 | adler += *buf++; 94 | sum2 += adler; 95 | } 96 | if (adler >= BASE) 97 | adler -= BASE; 98 | MOD28(sum2); /* only added so many BASE's */ 99 | return adler | (sum2 << 16); 100 | } 101 | 102 | /* do length NMAX blocks -- requires just one modulo operation */ 103 | while (len >= NMAX) { 104 | len -= NMAX; 105 | n = NMAX / 16; /* NMAX is divisible by 16 */ 106 | do { 107 | DO16(buf); /* 16 sums unrolled */ 108 | buf += 16; 109 | } while (--n); 110 | MOD(adler); 111 | MOD(sum2); 112 | } 113 | 114 | /* do remaining bytes (less than NMAX, still just one modulo) */ 115 | if (len) { /* avoid modulos if none remaining */ 116 | while (len >= 16) { 117 | len -= 16; 118 | DO16(buf); 119 | buf += 16; 120 | } 121 | while (len--) { 122 | adler += *buf++; 123 | sum2 += adler; 124 | } 125 | MOD(adler); 126 | MOD(sum2); 127 | } 128 | 129 | /* return recombined sums */ 130 | return adler | (sum2 << 16); 131 | } 132 | 133 | /* ========================================================================= */ 134 | uLong ZEXPORT adler32(adler, buf, len) 135 | uLong adler; 136 | const Bytef *buf; 137 | uInt len; 138 | { 139 | return adler32_z(adler, buf, len); 140 | } 141 | 142 | /* ========================================================================= */ 143 | local uLong adler32_combine_(adler1, adler2, len2) 144 | uLong adler1; 145 | uLong adler2; 146 | z_off64_t len2; 147 | { 148 | unsigned long sum1; 149 | unsigned long sum2; 150 | unsigned rem; 151 | 152 | /* for negative len, return invalid adler32 as a clue for debugging */ 153 | if (len2 < 0) 154 | return 0xffffffffUL; 155 | 156 | /* the derivation of this formula is left as an exercise for the reader */ 157 | MOD63(len2); /* assumes len2 >= 0 */ 158 | rem = (unsigned)len2; 159 | sum1 = adler1 & 0xffff; 160 | sum2 = rem * sum1; 161 | MOD(sum2); 162 | sum1 += (adler2 & 0xffff) + BASE - 1; 163 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 164 | if (sum1 >= BASE) sum1 -= BASE; 165 | if (sum1 >= BASE) sum1 -= BASE; 166 | if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1); 167 | if (sum2 >= BASE) sum2 -= BASE; 168 | return sum1 | (sum2 << 16); 169 | } 170 | 171 | /* ========================================================================= */ 172 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 173 | uLong adler1; 174 | uLong adler2; 175 | z_off_t len2; 176 | { 177 | return adler32_combine_(adler1, adler2, len2); 178 | } 179 | 180 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 181 | uLong adler1; 182 | uLong adler2; 183 | z_off64_t len2; 184 | { 185 | return adler32_combine_(adler1, adler2, len2); 186 | } 187 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2(dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | const uInt max = (uInt)-1; 32 | uLong left; 33 | 34 | left = *destLen; 35 | *destLen = 0; 36 | 37 | stream.zalloc = (alloc_func)0; 38 | stream.zfree = (free_func)0; 39 | stream.opaque = (voidpf)0; 40 | 41 | err = deflateInit(&stream, level); 42 | if (err != Z_OK) return err; 43 | 44 | stream.next_out = dest; 45 | stream.avail_out = 0; 46 | stream.next_in = (z_const Bytef *)source; 47 | stream.avail_in = 0; 48 | 49 | do { 50 | if (stream.avail_out == 0) { 51 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 52 | left -= stream.avail_out; 53 | } 54 | if (stream.avail_in == 0) { 55 | stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen; 56 | sourceLen -= stream.avail_in; 57 | } 58 | err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); 59 | } while (err == Z_OK); 60 | 61 | *destLen = stream.total_out; 62 | deflateEnd(&stream); 63 | return err == Z_STREAM_END ? Z_OK : err; 64 | } 65 | 66 | /* =========================================================================== 67 | */ 68 | int ZEXPORT compress(dest, destLen, source, sourceLen) 69 | Bytef *dest; 70 | uLongf *destLen; 71 | const Bytef *source; 72 | uLong sourceLen; 73 | { 74 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 75 | } 76 | 77 | /* =========================================================================== 78 | If the default memLevel or windowBits for deflateInit() is changed, then 79 | this function needs to be updated. 80 | */ 81 | uLong ZEXPORT compressBound(sourceLen) 82 | uLong sourceLen; 83 | { 84 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 85 | (sourceLen >> 25) + 13; 86 | } 87 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/gzguts.h: -------------------------------------------------------------------------------- 1 | /* gzguts.h -- zlib internal header definitions for gz* operations 2 | * Copyright (C) 2004-2019 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #ifdef _LARGEFILE64_SOURCE 7 | # ifndef _LARGEFILE_SOURCE 8 | # define _LARGEFILE_SOURCE 1 9 | # endif 10 | # ifdef _FILE_OFFSET_BITS 11 | # undef _FILE_OFFSET_BITS 12 | # endif 13 | #endif 14 | 15 | #ifdef HAVE_HIDDEN 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 | #else 18 | # define ZLIB_INTERNAL 19 | #endif 20 | 21 | #include 22 | #include "zlib.h" 23 | #ifdef STDC 24 | # include 25 | # include 26 | # include 27 | #endif 28 | 29 | #ifndef _POSIX_SOURCE 30 | # define _POSIX_SOURCE 31 | #endif 32 | #include 33 | 34 | #ifdef _WIN32 35 | # include 36 | #endif 37 | 38 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) 39 | # include 40 | #endif 41 | 42 | #if defined(_WIN32) 43 | # define WIDECHAR 44 | #endif 45 | 46 | #ifdef WINAPI_FAMILY 47 | # define open _open 48 | # define read _read 49 | # define write _write 50 | # define close _close 51 | #endif 52 | 53 | #ifdef NO_DEFLATE /* for compatibility with old definition */ 54 | # define NO_GZCOMPRESS 55 | #endif 56 | 57 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 58 | # ifndef HAVE_VSNPRINTF 59 | # define HAVE_VSNPRINTF 60 | # endif 61 | #endif 62 | 63 | #if defined(__CYGWIN__) 64 | # ifndef HAVE_VSNPRINTF 65 | # define HAVE_VSNPRINTF 66 | # endif 67 | #endif 68 | 69 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) 70 | # ifndef HAVE_VSNPRINTF 71 | # define HAVE_VSNPRINTF 72 | # endif 73 | #endif 74 | 75 | #ifndef HAVE_VSNPRINTF 76 | # ifdef MSDOS 77 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 78 | but for now we just assume it doesn't. */ 79 | # define NO_vsnprintf 80 | # endif 81 | # ifdef __TURBOC__ 82 | # define NO_vsnprintf 83 | # endif 84 | # ifdef WIN32 85 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 86 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 87 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 88 | # define vsnprintf _vsnprintf 89 | # endif 90 | # endif 91 | # endif 92 | # ifdef __SASC 93 | # define NO_vsnprintf 94 | # endif 95 | # ifdef VMS 96 | # define NO_vsnprintf 97 | # endif 98 | # ifdef __OS400__ 99 | # define NO_vsnprintf 100 | # endif 101 | # ifdef __MVS__ 102 | # define NO_vsnprintf 103 | # endif 104 | #endif 105 | 106 | /* unlike snprintf (which is required in C99), _snprintf does not guarantee 107 | null termination of the result -- however this is only used in gzlib.c where 108 | the result is assured to fit in the space provided */ 109 | #if defined(_MSC_VER) && _MSC_VER < 1900 110 | # define snprintf _snprintf 111 | #endif 112 | 113 | #ifndef local 114 | # define local static 115 | #endif 116 | /* since "static" is used to mean two completely different things in C, we 117 | define "local" for the non-static meaning of "static", for readability 118 | (compile with -Dlocal if your debugger can't find static symbols) */ 119 | 120 | /* gz* functions always use library allocation functions */ 121 | #ifndef STDC 122 | extern voidp malloc OF((uInt size)); 123 | extern void free OF((voidpf ptr)); 124 | #endif 125 | 126 | /* get errno and strerror definition */ 127 | #if defined UNDER_CE 128 | # include 129 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 130 | #else 131 | # ifndef NO_STRERROR 132 | # include 133 | # define zstrerror() strerror(errno) 134 | # else 135 | # define zstrerror() "stdio error (consult errno)" 136 | # endif 137 | #endif 138 | 139 | /* provide prototypes for these when building zlib without LFS */ 140 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 141 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 142 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 143 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 144 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 145 | #endif 146 | 147 | /* default memLevel */ 148 | #if MAX_MEM_LEVEL >= 8 149 | # define DEF_MEM_LEVEL 8 150 | #else 151 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 152 | #endif 153 | 154 | /* default i/o buffer size -- double this for output when reading (this and 155 | twice this must be able to fit in an unsigned type) */ 156 | #define GZBUFSIZE 8192 157 | 158 | /* gzip modes, also provide a little integrity check on the passed structure */ 159 | #define GZ_NONE 0 160 | #define GZ_READ 7247 161 | #define GZ_WRITE 31153 162 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 163 | 164 | /* values for gz_state how */ 165 | #define LOOK 0 /* look for a gzip header */ 166 | #define COPY 1 /* copy input directly */ 167 | #define GZIP 2 /* decompress a gzip stream */ 168 | 169 | /* internal gzip file state data structure */ 170 | typedef struct { 171 | /* exposed contents for gzgetc() macro */ 172 | struct gzFile_s x; /* "x" for exposed */ 173 | /* x.have: number of bytes available at x.next */ 174 | /* x.next: next output data to deliver or write */ 175 | /* x.pos: current position in uncompressed data */ 176 | /* used for both reading and writing */ 177 | int mode; /* see gzip modes above */ 178 | int fd; /* file descriptor */ 179 | char *path; /* path or fd for error messages */ 180 | unsigned size; /* buffer size, zero if not allocated yet */ 181 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ 182 | unsigned char *in; /* input buffer (double-sized when writing) */ 183 | unsigned char *out; /* output buffer (double-sized when reading) */ 184 | int direct; /* 0 if processing gzip, 1 if transparent */ 185 | /* just for reading */ 186 | int how; /* 0: get header, 1: copy, 2: decompress */ 187 | z_off64_t start; /* where the gzip data started, for rewinding */ 188 | int eof; /* true if end of input file reached */ 189 | int past; /* true if read requested past end */ 190 | /* just for writing */ 191 | int level; /* compression level */ 192 | int strategy; /* compression strategy */ 193 | int reset; /* true if a reset is pending after a Z_FINISH */ 194 | /* seek request */ 195 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ 196 | int seek; /* true if seek request pending */ 197 | /* error information */ 198 | int err; /* error code */ 199 | char *msg; /* error message */ 200 | /* zlib inflate or deflate stream */ 201 | z_stream strm; /* stream structure in-place (not a pointer) */ 202 | } gz_state; 203 | typedef gz_state FAR *gz_statep; 204 | 205 | /* shared functions */ 206 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 207 | #if defined UNDER_CE 208 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 209 | #endif 210 | 211 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 212 | value -- needed when comparing unsigned to z_off64_t, which is signed 213 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ 214 | #ifdef INT_MAX 215 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 216 | #else 217 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); 218 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 219 | #endif 220 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 |  /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. 6 | It is part of the implementation of this library and is 7 | subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2019 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD = 16180, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* State maintained between inflate() calls -- approximately 7K bytes, not 81 | including the allocated sliding window, which is up to 32K bytes. */ 82 | struct inflate_state { 83 | z_streamp strm; /* pointer back to this zlib stream */ 84 | inflate_mode mode; /* current inflate mode */ 85 | int last; /* true if processing last block */ 86 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip, 87 | bit 2 true to validate check value */ 88 | int havedict; /* true if dictionary provided */ 89 | int flags; /* gzip header method and flags, 0 if zlib, or 90 | -1 if raw or no header yet */ 91 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 92 | unsigned long check; /* protected copy of check value */ 93 | unsigned long total; /* protected copy of output count */ 94 | gz_headerp head; /* where to save gzip header information */ 95 | /* sliding window */ 96 | unsigned wbits; /* log base 2 of requested window size */ 97 | unsigned wsize; /* window size or zero if not using window */ 98 | unsigned whave; /* valid bytes in the window */ 99 | unsigned wnext; /* window write index */ 100 | unsigned char FAR *window; /* allocated sliding window, if needed */ 101 | /* bit accumulator */ 102 | unsigned long hold; /* input bit accumulator */ 103 | unsigned bits; /* number of bits in "in" */ 104 | /* for string and stored block copying */ 105 | unsigned length; /* literal or length of data to copy */ 106 | unsigned offset; /* distance back to copy string from */ 107 | /* for table and code decoding */ 108 | unsigned extra; /* extra bits needed */ 109 | /* fixed and dynamic code tables */ 110 | code const FAR *lencode; /* starting table for length/literal codes */ 111 | code const FAR *distcode; /* starting table for distance codes */ 112 | unsigned lenbits; /* index bits for lencode */ 113 | unsigned distbits; /* index bits for distcode */ 114 | /* dynamic table building */ 115 | unsigned ncode; /* number of code length code lengths */ 116 | unsigned nlen; /* number of length code lengths */ 117 | unsigned ndist; /* number of distance code lengths */ 118 | unsigned have; /* number of code lengths in lens[] */ 119 | code FAR *next; /* next available space in codes[] */ 120 | unsigned short lens[320]; /* temporary storage for code lengths */ 121 | unsigned short work[288]; /* work area for code table building */ 122 | code codes[ENOUGH]; /* space for code tables */ 123 | int sane; /* if false, allow invalid distance too far */ 124 | int back; /* bits back of last unprocessed length/lit */ 125 | unsigned was; /* initial length of match */ 126 | }; 127 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. *sourceLen is 13 | the byte length of the source buffer. Upon entry, *destLen is the total size 14 | of the destination buffer, which must be large enough to hold the entire 15 | uncompressed data. (The size of the uncompressed data must have been saved 16 | previously by the compressor and transmitted to the decompressor by some 17 | mechanism outside the scope of this compression library.) Upon exit, 18 | *destLen is the size of the decompressed data and *sourceLen is the number 19 | of source bytes consumed. Upon return, source + *sourceLen points to the 20 | first unused input byte. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough 23 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, or 24 | Z_DATA_ERROR if the input data was corrupted, including if the input data is 25 | an incomplete zlib stream. 26 | */ 27 | int ZEXPORT uncompress2(dest, destLen, source, sourceLen) 28 | Bytef *dest; 29 | uLongf *destLen; 30 | const Bytef *source; 31 | uLong *sourceLen; 32 | { 33 | z_stream stream; 34 | int err; 35 | const uInt max = (uInt)-1; 36 | uLong len, left; 37 | Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ 38 | 39 | len = *sourceLen; 40 | if (*destLen) { 41 | left = *destLen; 42 | *destLen = 0; 43 | } 44 | else { 45 | left = 1; 46 | dest = buf; 47 | } 48 | 49 | stream.next_in = (z_const Bytef *)source; 50 | stream.avail_in = 0; 51 | stream.zalloc = (alloc_func)0; 52 | stream.zfree = (free_func)0; 53 | stream.opaque = (voidpf)0; 54 | 55 | err = inflateInit(&stream); 56 | if (err != Z_OK) return err; 57 | 58 | stream.next_out = dest; 59 | stream.avail_out = 0; 60 | 61 | do { 62 | if (stream.avail_out == 0) { 63 | stream.avail_out = left > (uLong)max ? max : (uInt)left; 64 | left -= stream.avail_out; 65 | } 66 | if (stream.avail_in == 0) { 67 | stream.avail_in = len > (uLong)max ? max : (uInt)len; 68 | len -= stream.avail_in; 69 | } 70 | err = inflate(&stream, Z_NO_FLUSH); 71 | } while (err == Z_OK); 72 | 73 | *sourceLen -= len + stream.avail_in; 74 | if (dest != buf) 75 | *destLen = stream.total_out; 76 | else if (stream.total_out && err == Z_BUF_ERROR) 77 | left = 1; 78 | 79 | inflateEnd(&stream); 80 | return err == Z_STREAM_END ? Z_OK : 81 | err == Z_NEED_DICT ? Z_DATA_ERROR : 82 | err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : 83 | err; 84 | } 85 | 86 | int ZEXPORT uncompress(dest, destLen, source, sourceLen) 87 | Bytef *dest; 88 | uLongf *destLen; 89 | const Bytef *source; 90 | uLong sourceLen; 91 | { 92 | return uncompress2(dest, destLen, source, &sourceLen); 93 | } 94 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/zlib.map: -------------------------------------------------------------------------------- 1 | ZLIB_1.2.0 { 2 | global: 3 | compressBound; 4 | deflateBound; 5 | inflateBack; 6 | inflateBackEnd; 7 | inflateBackInit_; 8 | inflateCopy; 9 | local: 10 | deflate_copyright; 11 | inflate_copyright; 12 | inflate_fast; 13 | inflate_table; 14 | zcalloc; 15 | zcfree; 16 | z_errmsg; 17 | gz_error; 18 | gz_intmax; 19 | _*; 20 | }; 21 | 22 | ZLIB_1.2.0.2 { 23 | gzclearerr; 24 | gzungetc; 25 | zlibCompileFlags; 26 | } ZLIB_1.2.0; 27 | 28 | ZLIB_1.2.0.8 { 29 | deflatePrime; 30 | } ZLIB_1.2.0.2; 31 | 32 | ZLIB_1.2.2 { 33 | adler32_combine; 34 | crc32_combine; 35 | deflateSetHeader; 36 | inflateGetHeader; 37 | } ZLIB_1.2.0.8; 38 | 39 | ZLIB_1.2.2.3 { 40 | deflateTune; 41 | gzdirect; 42 | } ZLIB_1.2.2; 43 | 44 | ZLIB_1.2.2.4 { 45 | inflatePrime; 46 | } ZLIB_1.2.2.3; 47 | 48 | ZLIB_1.2.3.3 { 49 | adler32_combine64; 50 | crc32_combine64; 51 | gzopen64; 52 | gzseek64; 53 | gztell64; 54 | inflateUndermine; 55 | } ZLIB_1.2.2.4; 56 | 57 | ZLIB_1.2.3.4 { 58 | inflateReset2; 59 | inflateMark; 60 | } ZLIB_1.2.3.3; 61 | 62 | ZLIB_1.2.3.5 { 63 | gzbuffer; 64 | gzoffset; 65 | gzoffset64; 66 | gzclose_r; 67 | gzclose_w; 68 | } ZLIB_1.2.3.4; 69 | 70 | ZLIB_1.2.5.1 { 71 | deflatePending; 72 | } ZLIB_1.2.3.5; 73 | 74 | ZLIB_1.2.5.2 { 75 | deflateResetKeep; 76 | gzgetc_; 77 | inflateResetKeep; 78 | } ZLIB_1.2.5.1; 79 | 80 | ZLIB_1.2.7.1 { 81 | inflateGetDictionary; 82 | gzvprintf; 83 | } ZLIB_1.2.5.2; 84 | 85 | ZLIB_1.2.9 { 86 | inflateCodesUsed; 87 | inflateValidate; 88 | uncompress2; 89 | gzfread; 90 | gzfwrite; 91 | deflateGetDictionary; 92 | adler32_z; 93 | crc32_z; 94 | } ZLIB_1.2.7.1; 95 | 96 | ZLIB_1.2.12 { 97 | crc32_combine_gen; 98 | crc32_combine_gen64; 99 | crc32_combine_op; 100 | } ZLIB_1.2.9; 101 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2017 Jean-loup Gailly 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | #ifndef Z_SOLO 10 | # include "gzguts.h" 11 | #endif 12 | 13 | z_const char * const z_errmsg[10] = { 14 | (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ 15 | (z_const char *)"stream end", /* Z_STREAM_END 1 */ 16 | (z_const char *)"", /* Z_OK 0 */ 17 | (z_const char *)"file error", /* Z_ERRNO (-1) */ 18 | (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ 19 | (z_const char *)"data error", /* Z_DATA_ERROR (-3) */ 20 | (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ 21 | (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ 22 | (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ 23 | (z_const char *)"" 24 | }; 25 | 26 | 27 | const char * ZEXPORT zlibVersion() 28 | { 29 | return ZLIB_VERSION; 30 | } 31 | 32 | uLong ZEXPORT zlibCompileFlags() 33 | { 34 | uLong flags; 35 | 36 | flags = 0; 37 | switch ((int)(sizeof(uInt))) { 38 | case 2: break; 39 | case 4: flags += 1; break; 40 | case 8: flags += 2; break; 41 | default: flags += 3; 42 | } 43 | switch ((int)(sizeof(uLong))) { 44 | case 2: break; 45 | case 4: flags += 1 << 2; break; 46 | case 8: flags += 2 << 2; break; 47 | default: flags += 3 << 2; 48 | } 49 | switch ((int)(sizeof(voidpf))) { 50 | case 2: break; 51 | case 4: flags += 1 << 4; break; 52 | case 8: flags += 2 << 4; break; 53 | default: flags += 3 << 4; 54 | } 55 | switch ((int)(sizeof(z_off_t))) { 56 | case 2: break; 57 | case 4: flags += 1 << 6; break; 58 | case 8: flags += 2 << 6; break; 59 | default: flags += 3 << 6; 60 | } 61 | #ifdef ZLIB_DEBUG 62 | flags += 1 << 8; 63 | #endif 64 | /* 65 | #if defined(ASMV) || defined(ASMINF) 66 | flags += 1 << 9; 67 | #endif 68 | */ 69 | #ifdef ZLIB_WINAPI 70 | flags += 1 << 10; 71 | #endif 72 | #ifdef BUILDFIXED 73 | flags += 1 << 12; 74 | #endif 75 | #ifdef DYNAMIC_CRC_TABLE 76 | flags += 1 << 13; 77 | #endif 78 | #ifdef NO_GZCOMPRESS 79 | flags += 1L << 16; 80 | #endif 81 | #ifdef NO_GZIP 82 | flags += 1L << 17; 83 | #endif 84 | #ifdef PKZIP_BUG_WORKAROUND 85 | flags += 1L << 20; 86 | #endif 87 | #ifdef FASTEST 88 | flags += 1L << 21; 89 | #endif 90 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 91 | # ifdef NO_vsnprintf 92 | flags += 1L << 25; 93 | # ifdef HAS_vsprintf_void 94 | flags += 1L << 26; 95 | # endif 96 | # else 97 | # ifdef HAS_vsnprintf_void 98 | flags += 1L << 26; 99 | # endif 100 | # endif 101 | #else 102 | flags += 1L << 24; 103 | # ifdef NO_snprintf 104 | flags += 1L << 25; 105 | # ifdef HAS_sprintf_void 106 | flags += 1L << 26; 107 | # endif 108 | # else 109 | # ifdef HAS_snprintf_void 110 | flags += 1L << 26; 111 | # endif 112 | # endif 113 | #endif 114 | return flags; 115 | } 116 | 117 | #ifdef ZLIB_DEBUG 118 | #include 119 | # ifndef verbose 120 | # define verbose 0 121 | # endif 122 | int ZLIB_INTERNAL z_verbose = verbose; 123 | 124 | void ZLIB_INTERNAL z_error(m) 125 | char *m; 126 | { 127 | fprintf(stderr, "%s\n", m); 128 | exit(1); 129 | } 130 | #endif 131 | 132 | /* exported to allow conversion of error code to string for compress() and 133 | * uncompress() 134 | */ 135 | const char * ZEXPORT zError(err) 136 | int err; 137 | { 138 | return ERR_MSG(err); 139 | } 140 | 141 | #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800 142 | /* The older Microsoft C Run-Time Library for Windows CE doesn't have 143 | * errno. We define it as a global variable to simplify porting. 144 | * Its value is always 0 and should not be used. 145 | */ 146 | int errno = 0; 147 | #endif 148 | 149 | #ifndef HAVE_MEMCPY 150 | 151 | void ZLIB_INTERNAL zmemcpy(dest, source, len) 152 | Bytef* dest; 153 | const Bytef* source; 154 | uInt len; 155 | { 156 | if (len == 0) return; 157 | do { 158 | *dest++ = *source++; /* ??? to be unrolled */ 159 | } while (--len != 0); 160 | } 161 | 162 | int ZLIB_INTERNAL zmemcmp(s1, s2, len) 163 | const Bytef* s1; 164 | const Bytef* s2; 165 | uInt len; 166 | { 167 | uInt j; 168 | 169 | for (j = 0; j < len; j++) { 170 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 171 | } 172 | return 0; 173 | } 174 | 175 | void ZLIB_INTERNAL zmemzero(dest, len) 176 | Bytef* dest; 177 | uInt len; 178 | { 179 | if (len == 0) return; 180 | do { 181 | *dest++ = 0; /* ??? to be unrolled */ 182 | } while (--len != 0); 183 | } 184 | #endif 185 | 186 | #ifndef Z_SOLO 187 | 188 | #ifdef SYS16BIT 189 | 190 | #ifdef __TURBOC__ 191 | /* Turbo C in 16-bit mode */ 192 | 193 | # define MY_ZCALLOC 194 | 195 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 196 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 197 | * must fix the pointer. Warning: the pointer must be put back to its 198 | * original form in order to free it, use zcfree(). 199 | */ 200 | 201 | #define MAX_PTR 10 202 | /* 10*64K = 640K */ 203 | 204 | local int next_ptr = 0; 205 | 206 | typedef struct ptr_table_s { 207 | voidpf org_ptr; 208 | voidpf new_ptr; 209 | } ptr_table; 210 | 211 | local ptr_table table[MAX_PTR]; 212 | /* This table is used to remember the original form of pointers 213 | * to large buffers (64K). Such pointers are normalized with a zero offset. 214 | * Since MSDOS is not a preemptive multitasking OS, this table is not 215 | * protected from concurrent access. This hack doesn't work anyway on 216 | * a protected system like OS/2. Use Microsoft C instead. 217 | */ 218 | 219 | voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) 220 | { 221 | voidpf buf; 222 | ulg bsize = (ulg)items*size; 223 | 224 | (void)opaque; 225 | 226 | /* If we allocate less than 65520 bytes, we assume that farmalloc 227 | * will return a usable pointer which doesn't have to be normalized. 228 | */ 229 | if (bsize < 65520L) { 230 | buf = farmalloc(bsize); 231 | if (*(ush*)&buf != 0) return buf; 232 | } else { 233 | buf = farmalloc(bsize + 16L); 234 | } 235 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 236 | table[next_ptr].org_ptr = buf; 237 | 238 | /* Normalize the pointer to seg:0 */ 239 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 240 | *(ush*)&buf = 0; 241 | table[next_ptr++].new_ptr = buf; 242 | return buf; 243 | } 244 | 245 | void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) 246 | { 247 | int n; 248 | 249 | (void)opaque; 250 | 251 | if (*(ush*)&ptr != 0) { /* object < 64K */ 252 | farfree(ptr); 253 | return; 254 | } 255 | /* Find the original pointer */ 256 | for (n = 0; n < next_ptr; n++) { 257 | if (ptr != table[n].new_ptr) continue; 258 | 259 | farfree(table[n].org_ptr); 260 | while (++n < next_ptr) { 261 | table[n-1] = table[n]; 262 | } 263 | next_ptr--; 264 | return; 265 | } 266 | Assert(0, "zcfree: ptr not found"); 267 | } 268 | 269 | #endif /* __TURBOC__ */ 270 | 271 | 272 | #ifdef M_I86 273 | /* Microsoft C in 16-bit mode */ 274 | 275 | # define MY_ZCALLOC 276 | 277 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 278 | # define _halloc halloc 279 | # define _hfree hfree 280 | #endif 281 | 282 | voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) 283 | { 284 | (void)opaque; 285 | return _halloc((long)items, size); 286 | } 287 | 288 | void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) 289 | { 290 | (void)opaque; 291 | _hfree(ptr); 292 | } 293 | 294 | #endif /* M_I86 */ 295 | 296 | #endif /* SYS16BIT */ 297 | 298 | 299 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 300 | 301 | #ifndef STDC 302 | extern voidp malloc OF((uInt size)); 303 | extern voidp calloc OF((uInt items, uInt size)); 304 | extern void free OF((voidpf ptr)); 305 | #endif 306 | 307 | voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) 308 | voidpf opaque; 309 | unsigned items; 310 | unsigned size; 311 | { 312 | (void)opaque; 313 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 314 | (voidpf)calloc(items, size); 315 | } 316 | 317 | void ZLIB_INTERNAL zcfree(opaque, ptr) 318 | voidpf opaque; 319 | voidpf ptr; 320 | { 321 | (void)opaque; 322 | free(ptr); 323 | } 324 | 325 | #endif /* MY_ZCALLOC */ 326 | 327 | #endif /* !Z_SOLO */ 328 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/plugin/xef/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #ifdef HAVE_HIDDEN 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #if defined(STDC) && !defined(Z_SOLO) 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifndef local 33 | # define local static 34 | #endif 35 | /* since "static" is used to mean two completely different things in C, we 36 | define "local" for the non-static meaning of "static", for readability 37 | (compile with -Dlocal if your debugger can't find static symbols) */ 38 | 39 | typedef unsigned char uch; 40 | typedef uch FAR uchf; 41 | typedef unsigned short ush; 42 | typedef ush FAR ushf; 43 | typedef unsigned long ulg; 44 | 45 | #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC) 46 | # include 47 | # if (ULONG_MAX == 0xffffffffffffffff) 48 | # define Z_U8 unsigned long 49 | # elif (ULLONG_MAX == 0xffffffffffffffff) 50 | # define Z_U8 unsigned long long 51 | # elif (UINT_MAX == 0xffffffffffffffff) 52 | # define Z_U8 unsigned 53 | # endif 54 | #endif 55 | 56 | extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 57 | /* (size given to avoid silly warnings with Visual C++) */ 58 | 59 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 60 | 61 | #define ERR_RETURN(strm,err) \ 62 | return (strm->msg = ERR_MSG(err), (err)) 63 | /* To be used only when the state is known to be valid */ 64 | 65 | /* common constants */ 66 | 67 | #ifndef DEF_WBITS 68 | # define DEF_WBITS MAX_WBITS 69 | #endif 70 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 71 | 72 | #if MAX_MEM_LEVEL >= 8 73 | # define DEF_MEM_LEVEL 8 74 | #else 75 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 76 | #endif 77 | /* default memLevel */ 78 | 79 | #define STORED_BLOCK 0 80 | #define STATIC_TREES 1 81 | #define DYN_TREES 2 82 | /* The three kinds of block type */ 83 | 84 | #define MIN_MATCH 3 85 | #define MAX_MATCH 258 86 | /* The minimum and maximum match lengths */ 87 | 88 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 89 | 90 | /* target dependencies */ 91 | 92 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 93 | # define OS_CODE 0x00 94 | # ifndef Z_SOLO 95 | # if defined(__TURBOC__) || defined(__BORLANDC__) 96 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 97 | /* Allow compilation with ANSI keywords only enabled */ 98 | void _Cdecl farfree( void *block ); 99 | void *_Cdecl farmalloc( unsigned long nbytes ); 100 | # else 101 | # include 102 | # endif 103 | # else /* MSC or DJGPP */ 104 | # include 105 | # endif 106 | # endif 107 | #endif 108 | 109 | #ifdef AMIGA 110 | # define OS_CODE 1 111 | #endif 112 | 113 | #if defined(VAXC) || defined(VMS) 114 | # define OS_CODE 2 115 | # define F_OPEN(name, mode) \ 116 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 117 | #endif 118 | 119 | #ifdef __370__ 120 | # if __TARGET_LIB__ < 0x20000000 121 | # define OS_CODE 4 122 | # elif __TARGET_LIB__ < 0x40000000 123 | # define OS_CODE 11 124 | # else 125 | # define OS_CODE 8 126 | # endif 127 | #endif 128 | 129 | #if defined(ATARI) || defined(atarist) 130 | # define OS_CODE 5 131 | #endif 132 | 133 | #ifdef OS2 134 | # define OS_CODE 6 135 | # if defined(M_I86) && !defined(Z_SOLO) 136 | # include 137 | # endif 138 | #endif 139 | 140 | #if defined(MACOS) || defined(TARGET_OS_MAC) 141 | # define OS_CODE 7 142 | # ifndef Z_SOLO 143 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 144 | # include /* for fdopen */ 145 | # else 146 | # ifndef fdopen 147 | # define fdopen(fd,mode) NULL /* No fdopen() */ 148 | # endif 149 | # endif 150 | # endif 151 | #endif 152 | 153 | #ifdef __acorn 154 | # define OS_CODE 13 155 | #endif 156 | 157 | #if defined(WIN32) && !defined(__CYGWIN__) 158 | # define OS_CODE 10 159 | #endif 160 | 161 | #ifdef _BEOS_ 162 | # define OS_CODE 16 163 | #endif 164 | 165 | #ifdef __TOS_OS400__ 166 | # define OS_CODE 18 167 | #endif 168 | 169 | #ifdef __APPLE__ 170 | # define OS_CODE 19 171 | #endif 172 | 173 | #if defined(_BEOS_) || defined(RISCOS) 174 | # define fdopen(fd,mode) NULL /* No fdopen() */ 175 | #endif 176 | 177 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 178 | # if defined(_WIN32_WCE) 179 | # define fdopen(fd,mode) NULL /* No fdopen() */ 180 | # else 181 | # define fdopen(fd,type) _fdopen(fd,type) 182 | # endif 183 | #endif 184 | 185 | #if defined(__BORLANDC__) && !defined(MSDOS) 186 | #pragma warn -8004 187 | #pragma warn -8008 188 | #pragma warn -8066 189 | #endif 190 | 191 | /* provide prototypes for these when building zlib without LFS */ 192 | #if !defined(_WIN32) && \ 193 | (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 194 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 195 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 196 | ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); 197 | #endif 198 | 199 | /* common defaults */ 200 | 201 | #ifndef OS_CODE 202 | # define OS_CODE 3 /* assume Unix */ 203 | #endif 204 | 205 | #ifndef F_OPEN 206 | # define F_OPEN(name, mode) fopen((name), (mode)) 207 | #endif 208 | 209 | /* functions */ 210 | 211 | #if defined(pyr) || defined(Z_SOLO) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef ZLIB_DEBUG 242 | # include 243 | extern int ZLIB_INTERNAL z_verbose; 244 | extern void ZLIB_INTERNAL z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | #ifndef Z_SOLO 261 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 262 | unsigned size)); 263 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 264 | #endif 265 | 266 | #define ZALLOC(strm, items, size) \ 267 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 268 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 269 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 270 | 271 | /* Reverse the bytes in a 32-bit value */ 272 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 273 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 274 | 275 | #endif /* ZUTIL_H */ 276 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace xencrypt 4 | { 5 | /// @brief 服务上下文处理输出数据时,使用的内存缓存类型 6 | enum XCodeMemoryType 7 | { 8 | None, 9 | /// @brief 申请新内存 10 | AllocateMemory, 11 | /// @brief 源数据内存偏移 12 | OriginalOffset, 13 | }; 14 | /// @brief 服务上下文类型 15 | enum XContextType 16 | { 17 | /// @brief 未知 18 | XUnknown, 19 | /// @brief 加密上下文 20 | XEncrypt, 21 | /// @brief 解密上下文 22 | XDecrypt, 23 | }; 24 | /// @brief 服务上下文处理数据结构状态 25 | enum ResultCode 26 | { 27 | /// @brief 完成 28 | Ok, 29 | /// @brief 未知 30 | Unknown, 31 | /// @brief 服务未初始化 32 | UnInitialize, 33 | /// @brief 无效的加密/解密插件 34 | InvalidPlugin, 35 | /// @brief 无效的输入数据 36 | InvalidInputData, 37 | /// @brief 无效的上下文 38 | InvalidXContext, 39 | /// @brief 解密数据长度错误 40 | InvalidInputDataSize, 41 | /// @brief 无效的解密器 42 | InvalidDecoder, 43 | /// @brief 解密数据解压缩失败 44 | InvalidUnzip, 45 | /// @brief 无效的加密器 46 | InvalidEncoder, 47 | /// @brief 数据GZip压缩编码失败 48 | InvalidZip, 49 | /// @brief 数据已加密 50 | EncryptedData, 51 | /// @brief 内存不足 52 | OutMemory, 53 | /// @brief 服务上下文类型不匹配 54 | ContextTypeError, 55 | /// @brief 不支持解密服务 56 | NotSupportDecrypt, 57 | /// @brief 不支持加密服务 58 | NotSupportEncrypt, 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XContext.cpp: -------------------------------------------------------------------------------- 1 | #include "XContext.h" 2 | #include "XService.h" 3 | #include "common/Allocator.h" 4 | 5 | namespace xencrypt 6 | { 7 | XContext::XContext(XContextType type, XService* service) 8 | :_type(type), _clone(false), _data(nullptr), _input(nullptr), _service(service) 9 | { 10 | Reset(); 11 | } 12 | 13 | XContext::~XContext() 14 | { 15 | { Reset(); } 16 | } 17 | 18 | bool XContext::IsEncrypted(const byte* data, int64_t size) 19 | { 20 | return _service != nullptr ? _service->IsEncrypted(data, size) : false; 21 | } 22 | 23 | void XContext::Reset() 24 | { 25 | ReleaseData(); 26 | _clone = false; 27 | _code = ResultCode::Unknown; 28 | _memoryType = XCodeMemoryType::None; 29 | _input = nullptr; 30 | _inputLength = 0; 31 | } 32 | 33 | void XContext::ReleaseData() 34 | { 35 | _length = 0; 36 | if (_memoryType == XCodeMemoryType::AllocateMemory && _data != nullptr) 37 | { 38 | XMEMORY_FREE(_data); 39 | _data = nullptr; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | #include "Common.h" 5 | 6 | namespace xencrypt 7 | { 8 | class XService; 9 | /// @brief 加密/解密上下文 10 | class XENCRYPT_API XContext final 11 | { 12 | public: 13 | XContext(XContextType type, XService* service); 14 | ~XContext(); 15 | 16 | XContext(const XContext&) = delete; 17 | XContext& operator=(const XContext&) = delete; 18 | XContext(XContext&&) = delete; 19 | 20 | /// @brief 获取上下文类型 21 | /// @return 上下文类型 22 | XContextType GetType() const { return _type; } 23 | /// @brief 设置是否复制输入数据 24 | /// @param keep 标记是否复制数据数据.true:深度复制;否则,不复制. 25 | void SetCloneInputDataFlag(bool keep) { _clone = keep; } 26 | /// @brief 是否复制输入数据 27 | /// @return 是否复制数据数据.true:深度复制;否则,不复制. 28 | bool IsCloneInputData() const { return _clone; } 29 | /// @brief 设置内存申请类型 30 | /// @param type 31 | void SetMemoryType(XCodeMemoryType type) { _memoryType = type;} 32 | XCodeMemoryType GetMemoryType() const { return _memoryType;} 33 | /// @brief 设置加密/解密结果状态码 34 | /// @param code 状态码 35 | void SetResultCode(ResultCode code) { _code = code;} 36 | /// @brief 获取加密/解密结果状态码 37 | /// @return 加密/解密结果状态码 38 | ResultCode GetResultCode() const { return _code;} 39 | /// @brief 重置 40 | void Reset(); 41 | /// @brief 释放申请的内存数据 42 | void ReleaseData(); 43 | /// @brief 设置输入数据 44 | /// @param data 源数据 45 | /// @param length 源数据长度 46 | void SetInputData(const byte* data, int64_t length) 47 | { 48 | _input = data; 49 | _inputLength = length; 50 | } 51 | /// @brief 检查数据是否已加密 52 | /// @param data 内存数据地址 53 | /// @param size 数据长度 54 | /// @return 数据是否已加密.返回true,数据已加密,否则,未加密. 55 | bool IsEncrypted(const byte* data, int64_t size); 56 | 57 | /// @brief 获取源数据 58 | /// @return 源数据地址 59 | const byte* GetInputData() const { return _input;} 60 | /// @brief 获取源数据长度 61 | /// @return 源数据长度 62 | int64_t GetInputDataLength() const {return _inputLength;} 63 | /// @brief 设置结果数据 64 | /// @param data 结果数据地址 65 | /// @param length 结果数据长度 66 | void SetResultData(byte* data, int64_t length) 67 | { 68 | this->_data = data; 69 | this->_length = length; 70 | } 71 | /// @brief 获取结果数据地址 72 | /// @return 结果数据地址 73 | const byte* GetResultData() const {return _data;} 74 | /// @brief 获取结果数据地址 75 | /// @return 结果数据地址 76 | byte* GetResultData() {return _data;} 77 | /// @brief 获取结果数据长度 78 | /// @return 结果数据长度 79 | int64_t GetResultDataLength() const {return _length;} 80 | private: 81 | XContextType _type; 82 | ResultCode _code; 83 | XCodeMemoryType _memoryType; 84 | XService* _service; 85 | byte* _data; 86 | int64_t _length; 87 | const byte* _input; 88 | int64_t _inputLength; 89 | bool _clone; 90 | 91 | }; 92 | 93 | } 94 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XResult.cpp: -------------------------------------------------------------------------------- 1 | #include "XResult.h" 2 | 3 | namespace xencrypt 4 | { 5 | XResult::~XResult() 6 | { 7 | if (_context != nullptr) 8 | { 9 | delete _context; 10 | } 11 | _context = nullptr; 12 | 13 | _resultCode = ResultCode::Unknown; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XResult.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | #include "Common.h" 5 | #include "XContext.h" 6 | 7 | namespace xencrypt 8 | { 9 | /// @brief 加密/解密结果 10 | class XENCRYPT_API XResult final 11 | { 12 | public: 13 | XResult():_context(nullptr) {} 14 | ~XResult(); 15 | 16 | XResult(const XResult&) = delete; 17 | XResult(XResult&&) = delete; 18 | XResult& operator=(const XResult&) = delete; 19 | /// @brief 获取结果数据缓存地址指针.该数据在XResult对象销毁时会被释放. 20 | /// @return 结果数据缓存地址 21 | byte* GetData() const 22 | { 23 | return _context != nullptr ? _context->GetResultData() : nullptr; 24 | } 25 | /// @brief 获取结果数据大小 26 | int64_t GetDataSize() const 27 | { 28 | return _context != nullptr ? _context->GetResultDataLength() : 0; 29 | } 30 | /// @brief 加密/解密结果状态 31 | ResultCode GetCode() const { return _resultCode; } 32 | private: 33 | 34 | void SetResultCode(ResultCode code) { _resultCode = code; } 35 | 36 | void SetContext(XContext* context) { _context = context; } 37 | private: 38 | XContext* _context; 39 | ResultCode _resultCode = ResultCode::Unknown; 40 | friend class XService; 41 | }; 42 | } -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XService.cpp: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | #include "common/Allocator.h" 3 | #include "XService.h" 4 | #include "XContext.h" 5 | 6 | namespace xencrypt 7 | { 8 | bool XService::IsEncrypted(const byte* data, int64_t size) 9 | { 10 | X_ENCRYPT_ASSERT(_plugin != nullptr); 11 | return _plugin->IsEncrypted(data, size); 12 | } 13 | 14 | XResult* XService::Decrypt(const byte* input, int64_t length, bool cloneInput /*= false*/) 15 | { 16 | XResult* pResult = new XResult(); 17 | X_ENCRYPT_ASSERT(pResult != nullptr); 18 | 19 | if (_plugin == nullptr) 20 | { 21 | pResult->SetResultCode(ResultCode::InvalidPlugin); 22 | return pResult; 23 | } 24 | 25 | XContext* context = new XContext(XContextType::XDecrypt, this); 26 | X_ENCRYPT_ASSERT(context != nullptr); 27 | pResult->SetContext(context); 28 | 29 | if (!_plugin->IsSupport(context->GetType())) 30 | { 31 | pResult->SetResultCode(ResultCode::InvalidDecoder); 32 | context->SetResultCode(ResultCode::InvalidDecoder); 33 | } 34 | else 35 | { 36 | context->SetCloneInputDataFlag(cloneInput); 37 | context->SetInputData(input, length); 38 | _plugin->Decrypt(context); 39 | } 40 | 41 | pResult->SetResultCode(context->GetResultCode()); 42 | 43 | return pResult; 44 | } 45 | 46 | XResult* XService::Encrypt(const byte* in, int64_t length) 47 | { 48 | XResult* pResult = new XResult(); 49 | X_ENCRYPT_ASSERT(pResult != nullptr); 50 | if (_plugin == nullptr) 51 | { 52 | pResult->SetResultCode(ResultCode::InvalidPlugin); 53 | return pResult; 54 | } 55 | 56 | XContext* context = new XContext(XContextType::XEncrypt, this); 57 | X_ENCRYPT_ASSERT(context != nullptr); 58 | pResult->SetContext(context); 59 | 60 | if (!_plugin->IsSupport(XContextType::XEncrypt)) 61 | { 62 | pResult->SetResultCode(ResultCode::InvalidEncoder); 63 | context->SetResultCode(ResultCode::InvalidEncoder); 64 | } 65 | else 66 | { 67 | context->SetInputData(in, length); 68 | _plugin->Encrypt(context); 69 | } 70 | pResult->SetResultCode(context->GetResultCode()); 71 | return pResult; 72 | } 73 | 74 | void XService::ReleaseResult(XResult* result) 75 | { 76 | if (result != nullptr) 77 | { 78 | delete result; 79 | } 80 | result = nullptr; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /XEncrypt/encrypt/service/XService.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "plugin/XPlugin.h" 4 | #include "XResult.h" 5 | 6 | namespace xencrypt 7 | { 8 | /// @brief 加密/解密服务类 9 | class XENCRYPT_API XService final 10 | { 11 | public: 12 | XService(XPlugin* plugin) :_plugin(plugin) {} 13 | ~XService() = default; 14 | 15 | XService(const XService& other) = delete; 16 | XService(XService&& other) = delete; 17 | XService& operator=(const XService&) = delete; 18 | 19 | /// @brief 检查数据是否已加密 20 | /// @param data 内存数据地址 21 | /// @param size 数据长度 22 | /// @return 数据是否已加密.返回true,数据已加密,否则,未加密. 23 | bool IsEncrypted(const byte* data, int64_t size); 24 | 25 | /// @brief 数据解密处理 26 | /// @param in 已加密数据 27 | /// @param length 输入数据长度 28 | /// @param cloneInput 是否复制内存数据 29 | /// @return 返回解密结果指针.该指针需要手动释放. 30 | XResult* Decrypt(const byte* in, int64_t length, bool cloneInput = false); 31 | 32 | /// @brief 数据加密 33 | /// @param in 待加密数据 34 | /// @param length 数据长度 35 | /// @return 返回加密结果指针.该指针需要手动释放. 36 | XResult* Encrypt(const byte* in, int64_t length); 37 | /// @brief 释放加密/解密结果 38 | /// @param result 加密/解密结果 39 | void ReleaseResult(XResult* result); 40 | private: 41 | XPlugin* _plugin; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /XEncryptApi/DecryptScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using static XEncryptAPI.XService; 4 | 5 | namespace XEncryptAPI 6 | { 7 | /// 8 | /// 解密Scope 9 | /// 10 | public class DecryptScope : IDisposable 11 | { 12 | IntPtr _plugin = IntPtr.Zero; 13 | IntPtr _service = IntPtr.Zero; 14 | public DecryptScope() 15 | { 16 | #if DEBUG 17 | DebugLog("DecryptScope Initialize"); 18 | #endif 19 | _plugin = XEFPlugin.Create(XEFPlugin.XEncodeType.XNone, 0); 20 | } 21 | 22 | public void Begin() 23 | { 24 | #if DEBUG 25 | DebugLog("DecryptScope Begin"); 26 | #endif 27 | _service = XService.Initialize(_plugin); 28 | } 29 | 30 | public ResultCode DecryptData(byte[] rawdata, out byte[] data) 31 | { 32 | #if DEBUG 33 | DebugLog("DecryptScope DecryptData"); 34 | #endif 35 | data = rawdata; 36 | unsafe 37 | { 38 | fixed(byte* rawdataPtr = rawdata) 39 | { 40 | if(!XService.IsEncrypted(_service, rawdataPtr, rawdata.LongLength)) 41 | { 42 | return ResultCode.InvalidInputData; 43 | } 44 | 45 | XResult result = XService.Decrypt(_service, rawdataPtr, rawdata.LongLength); 46 | #if DEBUG 47 | DebugLog($"Decrypt data state({result.code})"); 48 | #endif 49 | if(result.code == ResultCode.Ok) 50 | { 51 | data = new byte[result.size]; 52 | Marshal.Copy(result.data, data, 0, (int)result.size); 53 | } 54 | XService.ReleaseResult(_service, ref result); 55 | return result.code; 56 | } 57 | } 58 | } 59 | 60 | public void End() 61 | { 62 | #if DEBUG 63 | DebugLog("DecryptScope End"); 64 | #endif 65 | if(_service != IntPtr.Zero) 66 | { 67 | XService.Deinitialize(_service); 68 | } 69 | } 70 | 71 | public void Dispose() 72 | { 73 | if(_plugin != IntPtr.Zero) 74 | { 75 | XEFPlugin.Destroy(_plugin); 76 | } 77 | _plugin = IntPtr.Zero; 78 | #if DEBUG 79 | DebugLog("DecryptScope UnInitialize"); 80 | #endif 81 | 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /XEncryptApi/EncryptScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using static XEncryptAPI.XService; 4 | 5 | namespace XEncryptAPI 6 | { 7 | /// 8 | /// 加密Scope 9 | /// 10 | public class EncryptScope : IDisposable 11 | { 12 | IntPtr _plugin = IntPtr.Zero; 13 | IntPtr _service = IntPtr.Zero; 14 | public EncryptScope(XEFPlugin.XEncodeType type, byte encryptSize = 16) 15 | { 16 | #if DEBUG 17 | DebugLog("EncryptScope Initialize"); 18 | #endif 19 | _plugin = XEFPlugin.Create(type, encryptSize); 20 | } 21 | 22 | public void Begin() 23 | { 24 | #if DEBUG 25 | DebugLog("EncryptScope Begin"); 26 | #endif 27 | _service = XService.Initialize(_plugin); 28 | } 29 | 30 | public ResultCode EncryptData(byte[] rawdata, out byte[] data, byte encryptSize = 16, XEFPlugin.XEncodeType type = XEFPlugin.XEncodeType.XNone) 31 | { 32 | #if DEBUG 33 | DebugLog("EncryptScope EncryptData"); 34 | #endif 35 | data = rawdata; 36 | unsafe 37 | { 38 | fixed(byte* rawdataPtr = rawdata) 39 | { 40 | if(XService.IsEncrypted(_service, rawdataPtr, rawdata.LongLength)) 41 | { 42 | return ResultCode.EncryptedData; 43 | } 44 | 45 | XResult result = XService.Encrypt(_service, rawdataPtr, rawdata.LongLength); 46 | #if DEBUG 47 | DebugLog($"Encrypt data state({result.code})"); 48 | #endif 49 | if(result.code == ResultCode.Ok) 50 | { 51 | data = new byte[result.size]; 52 | 53 | Marshal.Copy(result.data, data, 0, (int)result.size); 54 | } 55 | XService.ReleaseResult(_service, ref result); 56 | return result.code; 57 | } 58 | } 59 | } 60 | 61 | public void End() 62 | { 63 | #if DEBUG 64 | DebugLog("EncryptScope End"); 65 | #endif 66 | if(_service != IntPtr.Zero) 67 | { 68 | XService.Deinitialize(_service); 69 | } 70 | _service = IntPtr.Zero; 71 | } 72 | 73 | public void Dispose() 74 | { 75 | #if DEBUG 76 | DebugLog("EncryptScope UnInitialize"); 77 | #endif 78 | if(_plugin != IntPtr.Zero) 79 | { 80 | XEFPlugin.Destroy(_plugin); 81 | } 82 | _plugin = IntPtr.Zero; 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /XEncryptApi/NativeLibrary.cs: -------------------------------------------------------------------------------- 1 | public static class NativeLibrary 2 | { 3 | #if UNITY_EDITOR 4 | public const string Name = "XEncrypt"; 5 | #else 6 | #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX 7 | public const string Name = "XEncrypt"; 8 | #elif UNITY_IOS 9 | public const string Name = "__Internal"; 10 | #elif UNITY_ANDROID 11 | public const string Name = "__Internal"; 12 | #else 13 | public const string Name = "XEncrypt"; 14 | #endif 15 | #endif 16 | } 17 | -------------------------------------------------------------------------------- /XEncryptApi/ResultCode.cs: -------------------------------------------------------------------------------- 1 | namespace XEncryptAPI 2 | { 3 | /// 4 | /// 加密/解密结果状态码 5 | /// 6 | public enum ResultCode : int 7 | { 8 | /// 9 | /// 完成 10 | /// 11 | Ok, 12 | /// 13 | /// 未知 14 | /// 15 | Unknown, 16 | /// 17 | /// 服务未初始化 18 | /// 19 | UnInitialize, 20 | /// 21 | /// 无效的加密/解密插件 22 | /// 23 | InvalidPlugin, 24 | /// 25 | /// 无效的输入数据 26 | /// 27 | InvalidInputData, 28 | /// 29 | /// 无效的上下文 30 | /// 31 | InvalidXContext, 32 | /// 33 | /// 解密数据长度错误 34 | /// 35 | InvalidInputDataSize, 36 | /// 37 | /// 无效的解密器 38 | /// 39 | InvalidDecoder, 40 | /// 41 | /// 解密数据解压缩失败 42 | /// 43 | InvalidUnzip, 44 | /// 45 | /// 无效的加密器 46 | /// 47 | InvalidEncoder, 48 | /// 49 | /// 数据GZip压缩编码失败 50 | /// 51 | InvalidZip, 52 | /// 53 | /// 数据已加密 54 | /// 55 | EncryptedData, 56 | /// 57 | /// 内存不足 58 | /// 59 | OutMemory, 60 | /// 61 | /// 服务上下文类型不匹配 62 | /// 63 | ContextTypeError, 64 | /// 65 | /// 不支持解密服务 66 | /// 67 | NotSupportDecrypt, 68 | /// 69 | /// 不支持加密服务 70 | /// 71 | NotSupportEncrypt, 72 | }; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /XEncryptApi/XEncryptAPI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | .NET6 5 | True 6 | ..\x64 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /XEncryptApi/XEncryptApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | namespace XEncryptAPI 4 | { 5 | public sealed class XService : IDisposable 6 | { 7 | /// 8 | /// 加密/解密结果 9 | /// 10 | [StructLayout(LayoutKind.Sequential)] 11 | public struct XResult 12 | { 13 | /// 14 | /// 结果状态码 15 | /// 16 | public ResultCode code; 17 | /// 18 | /// 结果数据大小 19 | /// 20 | public long size; 21 | /// 22 | /// 结果数据 23 | /// 24 | public IntPtr data; 25 | /// 26 | /// XReult指针, 用于释放内存 27 | /// 28 | private IntPtr result; 29 | } 30 | 31 | #region C# API 32 | private IntPtr _service; 33 | 34 | public XService(IPlugin plugin) 35 | { 36 | _service = XService.Initialize(plugin.Native); 37 | } 38 | 39 | public unsafe bool IsEncrypted(byte[] data, long size) 40 | { 41 | fixed(byte* ptr = data) 42 | { 43 | return XService.IsEncrypted(_service, ptr, size); 44 | } 45 | } 46 | 47 | public unsafe XResult Encrypt(byte[] data, long size) 48 | { 49 | fixed(byte* ptr = data) 50 | { 51 | return XService.Encrypt(_service, ptr, data.Length); 52 | } 53 | } 54 | 55 | public unsafe XResult Decrypt(byte[] data, long size) 56 | { 57 | fixed(byte* ptr = data) 58 | { 59 | return XService.Decrypt(_service, ptr, data.Length); 60 | } 61 | } 62 | 63 | public unsafe void ReleaseResult(XResult result) 64 | { 65 | XService.ReleaseResult(_service, ref result); 66 | } 67 | 68 | public void Dispose() 69 | { 70 | if(_service != IntPtr.Zero) 71 | { 72 | Deinitialize(_service); 73 | } 74 | _service = IntPtr.Zero; 75 | } 76 | #endregion 77 | 78 | #region Log 79 | public static void DebugLog(string format, params object[] args) 80 | { 81 | #if UNITY_EDITOR 82 | UnityEngine.Debug.LogFormat(format, args); 83 | #else 84 | Console.WriteLine(format, args); 85 | #endif 86 | } 87 | 88 | public static void DebugWarn(string format, params object[] args) 89 | { 90 | #if UNITY_EDITOR 91 | UnityEngine.Debug.LogWarningFormat(format, args); 92 | #else 93 | Console.WriteLine(format, args); 94 | #endif 95 | } 96 | 97 | public static void DebugError(string format, params object[] args) 98 | { 99 | #if UNITY_EDITOR 100 | UnityEngine.Debug.LogErrorFormat(format, args); 101 | #else 102 | Console.WriteLine(format, args); 103 | #endif 104 | } 105 | #endregion 106 | 107 | #region Native API 108 | /// 109 | /// 初始化服务
110 | /// void* xencrypt_service_initialize(void* plugin) 111 | ///
112 | /// 加密/解密插件实例 113 | /// 加密/解密服务实例 114 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_initialize", CallingConvention = CallingConvention.Cdecl)] 115 | public static extern IntPtr Initialize(IntPtr plugin); 116 | 117 | /// 118 | /// 检查数据是否已加密
119 | /// bool xencrypt_service_is_encrypted(void* service, const byte* data, int64_t size) 120 | ///
121 | /// 加密/解密服务实例 122 | /// 内存数据地址 123 | /// 数据长度 124 | /// 数据是否已加密.返回true,数据已加密,否则,未加密. 125 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_is_encrypted", CallingConvention = CallingConvention.Cdecl)] 126 | public static extern unsafe bool IsEncrypted(IntPtr service, byte* data, long size); 127 | /// 128 | /// 加密数据
129 | /// void* xencrypt_service_encrypt(void* service, const byte* in, int64_t in_size) 130 | /// 加密/解密服务实例 131 | /// 待加密数据 132 | /// 待加密数据长度 133 | /// 解密结果实例指针 134 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_encrypt", CallingConvention = CallingConvention.Cdecl)] 135 | public static extern unsafe XResult Encrypt(IntPtr service, byte* inData, long size); 136 | /// 137 | /// 解密数据
138 | /// void* xencrypt_service_decrypt(void* service, const byte* in, int64_t in_size) 139 | ///
140 | /// 加密/解密服务实例 141 | /// 待解密数据 142 | /// 密数据长度 143 | /// 解密结果实例指针 144 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_decrypt", CallingConvention = CallingConvention.Cdecl)] 145 | public static extern unsafe XResult Decrypt(IntPtr service, byte* inData, long size, bool cloneInput = false); 146 | /// 147 | /// 销毁结果
148 | /// void xencrypt_service_release_result(void* service, void* result) 149 | ///
150 | /// 加密/解密服务实例 151 | /// 加/解密结果指针 152 | /// 153 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_release_result", CallingConvention = CallingConvention.Cdecl)] 154 | public static extern unsafe void ReleaseResult(IntPtr service, ref XResult result); 155 | /// 156 | /// 注销服务
157 | /// void xencrypt_service_deinitialize(void* service) 158 | ///
159 | /// 加密/解密服务实例 160 | [DllImport(NativeLibrary.Name, EntryPoint = "xencrypt_service_deinitialize", CallingConvention = CallingConvention.Cdecl)] 161 | public static extern unsafe void Deinitialize(IntPtr service); 162 | #endregion 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /XEncryptApi/plugin/IPlugin.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace XEncryptAPI 5 | { 6 | public interface IPlugin 7 | { 8 | IntPtr Native { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /XEncryptApi/plugin/XEFPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace XEncryptAPI 5 | { 6 | public sealed class XEFPlugin : IPlugin, IDisposable 7 | { 8 | #region C# API 9 | private IntPtr _native; 10 | /// 11 | /// 加密服务时,源数据加密编码格式 12 | /// 13 | public enum XEncodeType : int 14 | { 15 | /// 16 | /// 源文件不作处理,只增加加密文件头部 17 | /// 18 | XNone, 19 | /// 20 | /// 源数据重新GZip压缩编码 21 | /// 22 | XGZip, 23 | }; 24 | 25 | public IntPtr Native => _native; 26 | 27 | public XEFPlugin(XEncodeType type, byte encryptSize = 16) 28 | { 29 | _native = Create(type, encryptSize); 30 | } 31 | 32 | public void Dispose() 33 | { 34 | if(_native != IntPtr.Zero) 35 | { 36 | Destroy(_native); 37 | } 38 | _native = IntPtr.Zero; 39 | } 40 | #endregion 41 | 42 | #region Native API 43 | 44 | /// 45 | /// 创建XEF格式加密/解密器插件实例
46 | /// void* xef_plugin_create(int type, uint8_t encryptSize) 47 | ///
48 | /// 数据加密编码类型 49 | /// 数据加密长度 50 | /// 插件实例指针 51 | [DllImport(NativeLibrary.Name, EntryPoint = "xef_plugin_create", CallingConvention = CallingConvention.Cdecl)] 52 | public static extern IntPtr Create(XEncodeType type, byte encryptSize); 53 | 54 | /// 55 | /// 销毁XEF格式 加密/解密插件实例
56 | /// void xef_plugin_destroy(void* plugin) 57 | ///
58 | /// 已创建的插件实例 59 | [DllImport(NativeLibrary.Name, EntryPoint = "xef_plugin_destroy", CallingConvention = CallingConvention.Cdecl)] 60 | public static extern void Destroy(IntPtr plugin); 61 | } 62 | #endregion 63 | } 64 | -------------------------------------------------------------------------------- /XFileEncoder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32616.157 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XFileEncoder", "XFileEncoder\XFileEncoder.csproj", "{A7654FCE-A873-4416-A118-8163B8A4E92E}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2} = {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2} 9 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5} = {8A04487E-7B53-4A6C-AABE-BA48446F11B5} 10 | EndProjectSection 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEncrypt", "XEncrypt\XEncrypt.vcxproj", "{8A04487E-7B53-4A6C-AABE-BA48446F11B5}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XEncryptAPI", "XEncryptAPI\XEncryptAPI.csproj", "{8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}" 15 | ProjectSection(ProjectDependencies) = postProject 16 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5} = {8A04487E-7B53-4A6C-AABE-BA48446F11B5} 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Debug|x64 = Debug|x64 23 | Debug|x86 = Debug|x86 24 | Release|Any CPU = Release|Any CPU 25 | Release|x64 = Release|x64 26 | Release|x86 = Release|x86 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|x64.ActiveCfg = Debug|Any CPU 32 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|x64.Build.0 = Debug|Any CPU 33 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|x86.ActiveCfg = Debug|Any CPU 34 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Debug|x86.Build.0 = Debug|Any CPU 35 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|x64.ActiveCfg = Release|Any CPU 38 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|x64.Build.0 = Release|Any CPU 39 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|x86.ActiveCfg = Release|Any CPU 40 | {A7654FCE-A873-4416-A118-8163B8A4E92E}.Release|x86.Build.0 = Release|Any CPU 41 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|Any CPU.ActiveCfg = Debug|x64 42 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|Any CPU.Build.0 = Debug|x64 43 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|x64.ActiveCfg = Debug|x64 44 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|x64.Build.0 = Debug|x64 45 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|x86.ActiveCfg = Debug|Win32 46 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Debug|x86.Build.0 = Debug|Win32 47 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|Any CPU.ActiveCfg = Release|x64 48 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|Any CPU.Build.0 = Release|x64 49 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|x64.ActiveCfg = Release|x64 50 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|x64.Build.0 = Release|x64 51 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|x86.ActiveCfg = Release|Win32 52 | {8A04487E-7B53-4A6C-AABE-BA48446F11B5}.Release|x86.Build.0 = Release|Win32 53 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 54 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|Any CPU.Build.0 = Debug|Any CPU 55 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|x64.ActiveCfg = Debug|Any CPU 56 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|x64.Build.0 = Debug|Any CPU 57 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|x86.ActiveCfg = Debug|Any CPU 58 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Debug|x86.Build.0 = Debug|Any CPU 59 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|Any CPU.ActiveCfg = Release|Any CPU 60 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|Any CPU.Build.0 = Release|Any CPU 61 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|x64.ActiveCfg = Release|Any CPU 62 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|x64.Build.0 = Release|Any CPU 63 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|x86.ActiveCfg = Release|Any CPU 64 | {8603BEA3-6188-4C5F-8D1C-5FBC3FA6AAD2}.Release|x86.Build.0 = Release|Any CPU 65 | EndGlobalSection 66 | GlobalSection(SolutionProperties) = preSolution 67 | HideSolutionNode = FALSE 68 | EndGlobalSection 69 | GlobalSection(ExtensibilityGlobals) = postSolution 70 | SolutionGuid = {DDC6B0BE-4688-47CC-8B8D-F1A1D55F1523} 71 | EndGlobalSection 72 | EndGlobal 73 | -------------------------------------------------------------------------------- /XFileEncoder/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace XFileEncoder 8 | { 9 | public class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | Generator.Gen(args); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /XFileEncoder/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "XFileEncoder": { 4 | "commandName": "Project", 5 | "commandLineArgs": "encrypt -load global-metadata.dat -out global-metadata.xef -encode-type zip", 6 | "workingDirectory": "..\\x64", 7 | "nativeDebugging": true 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /XFileEncoder/XFileEncoder.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | XFileEncoder.Program 6 | True 7 | False 8 | True 9 | .NET6 10 | ..\x64 11 | true 12 | disable 13 | 14 | 15 | 16 | True 17 | 4 18 | 19 | 20 | 21 | True 22 | 4 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /x64/global-metadata.dat: -------------------------------------------------------------------------------- 1 | This is a test data. 2 | This is a test data. 3 | This is a test data. 4 | This is a test data. -------------------------------------------------------------------------------- /x64/global-metadata.xef: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Y-way/xFileEncoder/feb40701c640e3ee451bb8aad10a0fb8cc49b676/x64/global-metadata.xef --------------------------------------------------------------------------------