mirror of
https://github.com/DoubleLabyrinth/navicat-keygen.git
synced 2019-12-02 05:10:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1f5900770 | ||
|
|
a15d77bfc9 | ||
|
|
93f355e604 | ||
|
|
8f0986e00e | ||
|
|
286f48c9e0 | ||
|
|
4af61a272b | ||
|
|
0b3bb309b2 | ||
|
|
2f04767075 | ||
|
|
24464f59a0 | ||
|
|
c01bb7f6a5 |
+289
-2
@@ -1,2 +1,289 @@
|
||||
*.DS_Store
|
||||
bin/*
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
MailDataReciever/Renci.SshNet.dll
|
||||
|
||||
@@ -1,233 +0,0 @@
|
||||
# Navicat Keygen - How does it work?
|
||||
|
||||
[中文版 How does it work?](HOW_DOES_IT_WORK.zh-CN.md)
|
||||
|
||||
## 1. Keyword Explanation.
|
||||
|
||||
* __Navicat Activation Public Key__
|
||||
|
||||
It is an __RSA-2048__ public key that Navicat used to encrypt or decrypt offline activation information.
|
||||
|
||||
It is stored in
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
You can see it by any kind of text editor. The content is:
|
||||
|
||||
```
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
If you have the corresponding private key, please tell me. I would be very appreciated for your generous.
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
Start from __Navicat Premuim 12.0.24 for Mac__, the public key is no longer stored in
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
Instead, the public key is stored in Navicat executable file
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/MacOS/Navicat Premium
|
||||
```
|
||||
|
||||
in plaintext. You can see it by searching string `"-----BEGIN PUBLIC KEY----- "`.
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
Start from __Navicat Premium 12.1.14 for Mac__, the public key is still stored in the executable file in plaintext.
|
||||
|
||||
However, it does not load the key from the plaintext. Instead, it loads the key from a piece of ciphertext which is 0x188 bytes long. The ciphertext is
|
||||
|
||||
```c
|
||||
const uint8_t ciphertext[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
```
|
||||
|
||||
The ciphertext is encrypted by XOR encryption where XOR key is
|
||||
|
||||
```
|
||||
\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
|
||||
```
|
||||
|
||||
* __Request Code__
|
||||
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the ciphertext of __Offline Activation Request Information__ encrypted by __Navicat Activation Public Key__.
|
||||
|
||||
* __Offline Activation Request Information__
|
||||
|
||||
It is just a JSON-style UTF-8 string which contains 3 items. Respectively they are `"K"`, `"DI"` and `"P"`, which represent __snKey__, __DeviceIdentifier__, __Platform__.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
{ "K": "xxxxxxxxxxxxxxxx", "P": "Mac 10.13", "DI": "xxxxxxxxxxxxxxxxxxxx" }
|
||||
```
|
||||
|
||||
* __Activation Code__
|
||||
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the ciphertext of __Offline Activation Response Information__ encrypted by __Navicat Activation Private Key__ which, so far, we don't know.
|
||||
|
||||
* __Offline Activation Response Information__
|
||||
|
||||
Just like __Offline Activation Request Information__, it is also a JSON-style UTF-8 string. But it contains 5 items. Respectively they are `"K"`, `"N"`, `"O"`, `"T"`, '`DI`'.
|
||||
|
||||
`"K"` and `"DI"` has the same meaning mentioned in __Offline Activation Request Information__ and must be same with the corresponding items in __Offline Activation Request Information__.
|
||||
|
||||
`"N"`, `"O"`, `"T"` represent __Name__, __Organization__, __Time__ respectively. __Name__ and __Organization__ are string and the type of __Time__ can be string or integer (Thanks for discoveries from @Wizr, issue #10).
|
||||
|
||||
Differ from Navicat Windows version, `"T"` is mandatory and must have -1 ~ +4 days difference from current time.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
{
|
||||
"DI" : "xxxxxxxxxxxxxxxxxxxx",
|
||||
"T" : "1515770827.925012",
|
||||
"K" : "xxxxxxxxxxxxxxxx",
|
||||
"N" : "DoubleLabyrinth",
|
||||
"O" : "Shadow"
|
||||
}
|
||||
```
|
||||
|
||||
* __snKey__
|
||||
|
||||
It is a 4-block-long string, while every block is 4-chars-long.
|
||||
|
||||
__snKey__ is generated by 10-bytes-long data. In order to explain it easily, I use __uint8_t data[10]__ to represent the 10-bytes-long data.
|
||||
|
||||
1. __data[0]__ and __data[1]__ must be `0x68` and `0x2A` respectively.
|
||||
|
||||
These two bytes are Naivcat signature number.
|
||||
|
||||
2. __data[2]__, __data[3]__ and __data[4]__ can be any byte. Just set them whatever you want.
|
||||
|
||||
3. __data[5]__ and __data[6]__ are related with your Navicat product language.
|
||||
|
||||
| Language | data[5] | data[6] | Discoverer |
|
||||
|------------|-----------|-----------|-----------------|
|
||||
| English | 0xAC | 0x88 | |
|
||||
| 简体中文 | 0xCE | 0x32 | |
|
||||
| 繁體中文 | 0xAA | 0x99 | |
|
||||
| 日本語 | 0xAD | 0x82 | @dragonflylee |
|
||||
| Polski | 0xBB | 0x55 | @dragonflylee |
|
||||
| Español | 0xAE | 0x10 | @dragonflylee |
|
||||
| Français | 0xFA | 0x20 | @Deltafox79 |
|
||||
| Deutsch | 0xB1 | 0x60 | @dragonflylee |
|
||||
| 한국어 | 0xB5 | 0x60 | @dragonflylee |
|
||||
| Русский | 0xEE | 0x16 | @dragonflylee |
|
||||
| Português | 0xCD | 0x49 | @dragonflylee |
|
||||
|
||||
4. __data[7]__ is Navicat product ID. (Thanks @dragonflylee and @Deltafox79)
|
||||
|
||||
|Product Name |Enterprise|Standard|Educational|Essentials|
|
||||
|---------------------|:--------:|:------:|:---------:|:--------:|
|
||||
|Navicat Report Viewer|0x0B | | | |
|
||||
|Navicat Data Modeler | |0x47 |0x4A | |
|
||||
|Navicat Premium |0x65 | |0x66 |0x67 |
|
||||
|Navicat MySQL |0x68 |0x69 |0x6A |0x6B |
|
||||
|Navicat PostgreSQL |0x6C |0x6D |0x6E |0x6F |
|
||||
|Navicat Oracle |0x70 |0x71 |0x72 |0x73 |
|
||||
|Navicat SQL Server |0x74 |0x75 |0x76 |0x77 |
|
||||
|Navicat SQLite |0x78 |0x79 |0x7A |0x7B |
|
||||
|Navicat MariaDB |0x7C |0x7D |0x7E |0x7F |
|
||||
|Navicat MongoDB |0x80 |0x81 |0x82 | |
|
||||
|
||||
5. High 4 bits of __data[8]__ represents __major version number__.
|
||||
|
||||
Low 4 bits is unknown, but we can use it to delay activation deadline. Possible values are `0000` or `0001`.
|
||||
|
||||
__Example:__
|
||||
|
||||
For __Navicat 12 x64__: High 4 bits must be `1100`, which is the binary of number `12`.
|
||||
For __Navicat 11 x64__: High 4 bits must be `1011`, which is the binary of number `11`.
|
||||
|
||||
6. __data[9]__ is unknown, but you can set it by `0xFD`, `0xFC` or `0xFB` if you want to use __not-for-resale license__.
|
||||
|
||||
According to symbol information in __Navicat 12 for Mac x64__ version:
|
||||
|
||||
* `0xFB` is __Not-For-Resale-30-days__ license.
|
||||
* `0xFC` is __Not-For-Resale-90-days__ license.
|
||||
* `0xFD` is __Not-For-Resale-365-days__ license.
|
||||
* `0xFE` is __Not-For-Resale__ license.
|
||||
* `0xFF` is __Site__ license.
|
||||
|
||||
After that. Navicat use __DES__ with __ECB mode__ to encrypt the last 8 bytes which are from __data[2]__ to __data[9]__.
|
||||
|
||||
The DES key is:
|
||||
|
||||
```cpp
|
||||
const uint8_t DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
```
|
||||
|
||||
Then use Base32 to encode `uint8_t data[10]` whose encode table is
|
||||
|
||||
```cpp
|
||||
// Thanks for discoveries from @Wizr, issue #10
|
||||
char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
```
|
||||
|
||||
After encoding, you will get a 16-char-long string starting with `"NAV"`.
|
||||
|
||||
Finally, divide the 16-char-long string to four 4-chars-long blocks and join them with `"-"` then you will get __snKey__.
|
||||
|
||||
## 2. Activation Process
|
||||
|
||||
1. Check whether __snKey__ that user inputs is valid.
|
||||
|
||||
2. After user clicks `Activate`, Navicat will start online activation first. If fails, user can choose offline activation.
|
||||
|
||||
3. Navicat will use the __snKey__ that user inputs and some information collected from user's machine to generate __Offline Activation Request Information__. Then Navicat will encrypt it by __Navicat Activation Public Key__ and return a Base64-encoded string as __Request Code__.
|
||||
|
||||
4. In legal way, the __Request Code__ should be sent to Navicat official activation server by a Internet-accessible computer. And Navicat official activation server will return a legal __Activation Code__.
|
||||
|
||||
But now, we use keygen to play the official activation server's role.
|
||||
|
||||
1. According to the __Request Code__, get `"DI"` value and `"K"` value.
|
||||
|
||||
2. Fill __Offline Activation Response Information__ with `"K"` value, name, organization name, `"DI"` value and `"T"` value.
|
||||
|
||||
3. Encrypt __Offline Activation Response Information__ by __Navicat Activation Private Key__ and you will get 256-byte-long data.
|
||||
|
||||
4. Encode the 256-byte-long data by Base64. The result is __Activation Code__.
|
||||
|
||||
5. After user input __Activation Code__, offline activation is done successfully.
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
# Navicat keygen - 注册机是怎么工作的?
|
||||
|
||||
## 1. 关键词解释.
|
||||
|
||||
* __Navicat激活公钥__
|
||||
|
||||
这是一个2048位的RSA公钥,Navicat使用这个公钥来完成相关激活信息的加密和解密。
|
||||
|
||||
这个公钥储存在
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
中,你可以用任何一种文本编辑器打开并查看它。这个公钥的具体内容为:
|
||||
|
||||
```
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
如果您有相应的私钥并乐意公开的话欢迎联系我,我将非常感谢您的慷慨。
|
||||
|
||||
__注意:__
|
||||
|
||||
从 __Navicat Premium for Mac 12.0.24__ 开始,公钥不再存储在
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
中。事实上,公钥放在了Navicat的二进制执行文件
|
||||
|
||||
```
|
||||
Navicat Premium.app/Contents/MacOS/Navicat Premium
|
||||
```
|
||||
|
||||
中,你可以通过搜索`"-----BEGIN PUBLIC KEY-----"`来找到它。
|
||||
|
||||
__注意:__
|
||||
|
||||
从 __Navicat Premium for Mac 12.1.14__ 开始,公钥仍然以明文的方式储存在二进制可执行文件中。
|
||||
|
||||
但是Navicat并不从这个明文中加载公钥。事实上,密钥是从一段0x188字节长的密文中加载的。密文为:
|
||||
|
||||
```c
|
||||
const uint8_t ciphertext[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
```
|
||||
|
||||
这个密文是采用XOR加密得来,XOR密钥为
|
||||
|
||||
```
|
||||
\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba
|
||||
```
|
||||
|
||||
* __请求码__
|
||||
|
||||
这是一个Base64编码的字符串,代表的是长度为256字节的数据。这256字节的数据是 __离线激活信息__ 用 __Navicat激活公钥__ 加密的密文。
|
||||
|
||||
* __离线激活请求信息__
|
||||
|
||||
这是一个JSON风格的UTF-8字符串。它包含了3个Key:`"K"`、`"DI"`和`"P"`,分别代表 __序列号__、__设备识别码__(与你的电脑硬件信息相关)和 __平台__ (其实就是操作系统类型)。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
{ "K": "xxxxxxxxxxxxxxxx", "P": "Mac 10.13", "DI": "xxxxxxxxxxxxxxxxxxxx" }
|
||||
```
|
||||
|
||||
* __激活码__
|
||||
|
||||
这是一个Base64编码的字符串,代表的是长度为256字节的数据。这256字节的数据是 __离线激活回复信息__ 用 __Navicat激活私钥__ 加密的密文。目前我们不知道官方的 __Navicat激活私钥__,所以我们得替换掉软件里的公钥。
|
||||
|
||||
* __离线激活回复信息__
|
||||
|
||||
和 __离线激活请求信息__ 一样,它也是一个JSON风格的UTF-8字符串。但是它包含5个Key,分别为`"K"`、`"N"`、`"O"`、`"T"` 和 `"DI"`.
|
||||
|
||||
`"K"` 和 `"DI"` 的意义与 __离线激活请求信息__ 中的相同,且Value必须与 __离线激活请求信息__ 中的相同。
|
||||
|
||||
`"N"`、`"O"`、`"T"` 分别代表 __注册名__、__组织__、__授权时间__。
|
||||
|
||||
__注册名__ 和 __组织__ 的值类型为UTF-8编码的字符串。__授权时间__ 的值类型可以为字符串或整数(感谢@Wizr在issue #10中的报告)。
|
||||
|
||||
和Windows版本Navicat不同的是,`"T"` 项不可以省略,并且和当前时间的差距必须在-1 ~ +4天之内。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
{
|
||||
"DI" : "xxxxxxxxxxxxxxxxxxxx",
|
||||
"T" : "1515770827.925012",
|
||||
"K" : "xxxxxxxxxxxxxxxx",
|
||||
"N" : "DoubleLabyrinth",
|
||||
"O" : "Shadow"
|
||||
}
|
||||
```
|
||||
|
||||
* __序列号__
|
||||
|
||||
这是一个被分为了4个部分的字符串,其中每个部分都是4个字符长。
|
||||
|
||||
__序列号__ 是通过10个字节的数据来生成的。为了表达方便,我用 __uint8_t data[10]__ 来表示这10个字节。
|
||||
|
||||
1. __data[0]__ 和 __data[1]__ 必须分别为 `0x68` 和 `0x2A`。
|
||||
|
||||
这两个字节为Navicat的标志数。
|
||||
|
||||
2. __data[2]__、__data[3]__ 和 __data[4]__ 可以是任意字节,你想设成什么都行。
|
||||
|
||||
3. __data[5]__ 和 __data[6]__ 是Navicat的语言标志,值如下:
|
||||
|
||||
| 语言类型 | data[5] | data[6] | 发现者 |
|
||||
|------------|:---------:|:---------:|-----------------|
|
||||
| English | 0xAC | 0x88 | |
|
||||
| 简体中文 | 0xCE | 0x32 | |
|
||||
| 繁體中文 | 0xAA | 0x99 | |
|
||||
| 日本語 | 0xAD | 0x82 | @dragonflylee |
|
||||
| Polski | 0xBB | 0x55 | @dragonflylee |
|
||||
| Español | 0xAE | 0x10 | @dragonflylee |
|
||||
| Français | 0xFA | 0x20 | @Deltafox79 |
|
||||
| Deutsch | 0xB1 | 0x60 | @dragonflylee |
|
||||
| 한국어 | 0xB5 | 0x60 | @dragonflylee |
|
||||
| Русский | 0xEE | 0x16 | @dragonflylee |
|
||||
| Português | 0xCD | 0x49 | @dragonflylee |
|
||||
|
||||
4. __data[7]__ 是Navicat产品ID。(感谢 @dragonflylee 和 @Deltafox79提供的数据)
|
||||
|
||||
|产品名 |Enterprise|Standard|Educational|Essentials|
|
||||
|---------------------|:--------:|:------:|:---------:|:--------:|
|
||||
|Navicat Report Viewer|0x0B | | | |
|
||||
|Navicat Data Modeler | |0x47 |0x4A | |
|
||||
|Navicat Premium |0x65 | |0x66 |0x67 |
|
||||
|Navicat MySQL |0x68 |0x69 |0x6A |0x6B |
|
||||
|Navicat PostgreSQL |0x6C |0x6D |0x6E |0x6F |
|
||||
|Navicat Oracle |0x70 |0x71 |0x72 |0x73 |
|
||||
|Navicat SQL Server |0x74 |0x75 |0x76 |0x77 |
|
||||
|Navicat SQLite |0x78 |0x79 |0x7A |0x7B |
|
||||
|Navicat MariaDB |0x7C |0x7D |0x7E |0x7F |
|
||||
|Navicat MongoDB |0x80 |0x81 |0x82 | |
|
||||
|
||||
5. __data[8]__ 的高4位代表 __版本号__。低4位未知,但可以用来延长激活期限,可取的值有`0000`和`0001`。
|
||||
|
||||
例如:
|
||||
|
||||
对于 __Navicat 12__: 高4位必须是`1100`,为`12`的二进制形式。
|
||||
对于 __Navicat 11__: 高4位必须是`1011`,为`11`的二进制形式。
|
||||
|
||||
6. __data[9]__ 目前暂未知,但如果你想要 __not-for-resale license__ 的话可以设成`0xFD`、`0xFC`或`0xFB`。
|
||||
|
||||
根据 __Navicat 12 for Mac x64__ 版本残留的符号信息可知:
|
||||
|
||||
* `0xFB`是 __Not-For-Resale-30-days__ license.
|
||||
* `0xFC`是 __Not-For-Resale-90-days__ license.
|
||||
* `0xFD`是 __Not-For-Resale-365-days__ license.
|
||||
* `0xFE`是 __Not-For-Resale__ license.
|
||||
* `0xFF`是 __Site__ license.
|
||||
|
||||
之后Navicat使用 __ECB__ 模式的 __DES__ 算法来加密 __data[10]__ 的后8字节,也就是 __data[2]__ 到 __data[9]__ 的部分。
|
||||
|
||||
相应的DES密钥为:
|
||||
|
||||
```cpp
|
||||
const uint8_t DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
```
|
||||
|
||||
之后使用Base32编码 __data[10]__,其中编码表改为:
|
||||
|
||||
```cpp
|
||||
// Thanks for discoveries from @Wizr, issue #10
|
||||
char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
```
|
||||
|
||||
编码之后你应该会得到一个16字节长的字符串,并且以"NAV"打头。
|
||||
|
||||
将16字节的字符串分成4个4字节的小块,然后用`"-"`连接就可以得到 __序列号__。
|
||||
|
||||
## 2. 激活过程
|
||||
|
||||
1. 检查用户输入的 __序列号__ 是否合法。
|
||||
|
||||
2. 在用户点击了`激活`按钮之后,Navicat会先尝试在线激活。如果失败,用户可以选择离线激活。
|
||||
|
||||
3. Navicat会使用用户输入的 __序列号__ 以及从用户电脑收集来的信息生成 __离线激活请求信息__,然后用 __Navicat激活公钥__ 加密,并将密文用Base64编码,最后得到 __请求码__。
|
||||
|
||||
4. 正常流程下,__请求码__ 应该通过可联网的电脑发送给Navicat的官方激活服务器。之后Navicat的官方激活服务器会返回一个合法的 __激活码__。
|
||||
|
||||
但现在我们使用注册机来扮演官方激活服务器的角色,只是Navicat软件里的激活公钥得换成自己的公钥:
|
||||
|
||||
1. 根据 __请求码__, 获得`"DI"`值和`"K"`值。
|
||||
|
||||
2. 用`"K"`值、用户名、组织名和`"DI"`值填写 __离线激活回复信息__。
|
||||
|
||||
3. 用自己的2048位RSA私钥加密 __离线激活回复信息__,你将会得到256字节的密文。
|
||||
|
||||
4. 用Base64编码这256字节的密文,就可以得到 __激活码__。
|
||||
|
||||
5. 在Navicat软件中填入 __激活码__ 即可完成离线激活。
|
||||
@@ -1,89 +0,0 @@
|
||||
CC = g++
|
||||
OPENSSL_INCLUDE_PATH = /usr/local/opt/openssl/include
|
||||
OPENSSL_LIB_PATH = /usr/local/opt/openssl/lib
|
||||
CAPSTONE_INCLUDE_PATH = #/usr/local/Cellar/capstone/4.0.1/include
|
||||
CAPSTONE_LIB_PATH = #/usr/local/Cellar/capstone/4.0.1/lib
|
||||
KEYSTONE_INCLUDE_PATH = #/usr/local/Cellar/keystone/0.9.1/include
|
||||
KEYSTONE_LIB_PATH = #/usr/local/Cellar/keystone/0.9.1/lib
|
||||
RAPIDJSON_INCLUDE_PATH = #/usr/local/Cellar/rapidjson/1.1.0/include
|
||||
LIBPLIST_INCLUDE_PATH = #/usr/local/Cellar/libplist/2.0.0_1/include
|
||||
LIBPLIST_LIB_PATH = #/usr/local/Cellar/libplist/2.0.0_1/lib
|
||||
|
||||
OUTPUT_DIR = ./bin/
|
||||
COMMON_DIR = ./common/
|
||||
PATCHER_DIR = ./navicat-patcher/
|
||||
KEYGEN_DIR = ./navicat-keygen/
|
||||
|
||||
COMMON_HEADER = \
|
||||
$(COMMON_DIR)Exception.hpp \
|
||||
$(COMMON_DIR)ExceptionOpenssl.hpp \
|
||||
$(COMMON_DIR)ExceptionSystem.hpp \
|
||||
$(COMMON_DIR)ResourceOwned.hpp \
|
||||
$(COMMON_DIR)ResourceTraitsOpenssl.hpp \
|
||||
$(COMMON_DIR)RSACipher.hpp \
|
||||
|
||||
PATCHER_HEADER = \
|
||||
$(PATCHER_DIR)ExceptionCapstone.hpp \
|
||||
$(PATCHER_DIR)ExceptionKeystone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsCapstone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsKeystone.hpp \
|
||||
$(PATCHER_DIR)ResourceTraitsUnix.hpp \
|
||||
$(PATCHER_DIR)CapstoneDisassembler.hpp \
|
||||
$(PATCHER_DIR)KeystoneAssembler.hpp \
|
||||
$(PATCHER_DIR)X64ImageInterpreter.hpp \
|
||||
$(PATCHER_DIR)PatchSolutions.hpp
|
||||
|
||||
PATCHER_SOURCE = \
|
||||
$(PATCHER_DIR)CapstoneDisassembler.cpp \
|
||||
$(PATCHER_DIR)KeystoneAssembler.cpp \
|
||||
$(PATCHER_DIR)X64ImageInterpreter.cpp \
|
||||
$(PATCHER_DIR)HelperIsResolvedTo.cpp \
|
||||
$(PATCHER_DIR)HelperPrintMemory.cpp \
|
||||
$(PATCHER_DIR)PatchSolution0.cpp \
|
||||
$(PATCHER_DIR)PatchSolution1.cpp \
|
||||
$(PATCHER_DIR)PatchSolution2.cpp \
|
||||
$(PATCHER_DIR)main.cpp
|
||||
|
||||
PATCHER_BINARY = $(OUTPUT_DIR)navicat-patcher
|
||||
|
||||
KEYGEN_HEADER = \
|
||||
$(KEYGEN_DIR)DESCipher.hpp \
|
||||
$(KEYGEN_DIR)NavicatKeygen.hpp
|
||||
|
||||
KEYGEN_SOURCE = \
|
||||
$(KEYGEN_DIR)Base64.cpp \
|
||||
$(KEYGEN_DIR)main.cpp
|
||||
|
||||
KEYGEN_BINARY = $(OUTPUT_DIR)navicat-keygen
|
||||
|
||||
patcher: $(PATCHER_HEADER) $(PATCHER_SOURCE)
|
||||
@if [ ! -d $(OUTPUT_DIR) ]; then mkdir -p $(OUTPUT_DIR); fi
|
||||
$(CC) -std=c++17 -O2 \
|
||||
-I$(OPENSSL_INCLUDE_PATH) -L$(OPENSSL_LIB_PATH) \
|
||||
$(if $(CAPSTONE_INCLUDE_PATH),-I$(CAPSTONE_INCLUDE_PATH),) $(if $(CAPSTONE_LIB_PATH),-L$(CAPSTONE_LIB_PATH),) \
|
||||
$(if $(KEYSTONE_INCLUDE_PATH),-I$(KEYSTONE_INCLUDE_PATH),) $(if $(KEYSTONE_LIB_PATH),-L$(KEYSTONE_LIB_PATH),) \
|
||||
$(if $(LIBPLIST_INCLUDE_PATH),-I$(LIBPLIST_INCLUDE_PATH),) $(if $(LIBPLIST_LIB_PATH),-L$(LIBPLIST_LIB_PATH),) \
|
||||
-lcrypto -lcapstone -lkeystone -lplist++ $(PATCHER_SOURCE) -o $(PATCHER_BINARY)
|
||||
@echo
|
||||
|
||||
keygen: $(KEYGEM_HEADER) $(KEYGEN_SOURCE)
|
||||
@if [ ! -d $(OUTPUT_DIR) ]; then mkdir -p $(OUTPUT_DIR); fi
|
||||
$(CC) -std=c++17 -O2 \
|
||||
-I$(OPENSSL_INCLUDE_PATH) -L$(OPENSSL_LIB_PATH) \
|
||||
$(if $(RAPIDJSON_INCLUDE_PATH),-I$(RAPIDJSON_INCLUDE_PATH),) \
|
||||
-lcrypto $(KEYGEN_SOURCE) -o $(KEYGEN_BINARY)
|
||||
|
||||
all: patcher keygen
|
||||
@echo 'Done.'
|
||||
|
||||
.PHONY: all
|
||||
|
||||
clean:
|
||||
ifeq ($(wildcard $(PATCHER_BINARY)), $(PATCHER_BINARY))
|
||||
rm $(PATCHER_BINARY)
|
||||
endif
|
||||
|
||||
ifeq ($(wildcard $(KEYGEN_BINARY)), $(KEYGEN_BINARY))
|
||||
rm $(KEYGEN_BINARY)
|
||||
endif
|
||||
|
||||
@@ -1,319 +1,301 @@
|
||||
# Navicat Keygen
|
||||
|
||||
[中文版README](README.zh-CN.md)
|
||||
This repository will tell you how Navicat offline activation works.
|
||||
|
||||
This repository will tell you how Navicat offline activation works.
|
||||
## 1. Keyword Explanation.
|
||||
|
||||
[How does it work?](HOW_DOES_IT_WORK.md)
|
||||
* __Navicat Activation Public Key__
|
||||
|
||||
__NOTICE: This keygen only supports Navicat Premium.__
|
||||
It is a __RSA-2048__ public key that Navicat used to encrypt or decrypt offline activation information.
|
||||
|
||||
## 1. How to build
|
||||
It is stored in __navicat.exe__ as a kind of resource called __RCData__. The resource name is `"ActivationPubKey"`. You can see it by a kind of software [___Resource Hacker___](http://www.angusj.com/resourcehacker/). The concrete content is:
|
||||
|
||||
* Before you build keygen, you should make sure you have following libs:
|
||||
|
||||
```
|
||||
openssl
|
||||
capstone
|
||||
keystone
|
||||
rapidjson
|
||||
libplist
|
||||
```
|
||||
> -----BEGIN PUBLIC KEY-----
|
||||
> MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
> qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
> a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
> R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
> WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
> YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
> awIDAQAB
|
||||
> -----END PUBLIC KEY-----
|
||||
|
||||
You can install them by
|
||||
|
||||
```shell
|
||||
$ brew install openssl
|
||||
$ brew install capstone
|
||||
$ brew install keystone
|
||||
$ brew install rapidjson
|
||||
$ brew install libplist
|
||||
```
|
||||
If you have the corresponding private key, please tell me. I would be very appreciated for your generous.
|
||||
|
||||
* Clone `mac` branch and build keygen and patcher:
|
||||
__NOTICE:__
|
||||
|
||||
```shell
|
||||
$ git clone -b mac --single-branch https://github.com/DoubleLabyrinth/navicat-keygen.git
|
||||
$ cd navicat-keygen
|
||||
$ make all
|
||||
```
|
||||
Start from __Navicat Premium 12.0.25__, Navicat do not load this public key from resource in `navicat.exe`. Actually the public key is stored in `libcc.dll` and encrypted. And to avoid being replaced easily, the public key is split into 5 parts:
|
||||
|
||||
You will see two executable files in `bin/` directory:
|
||||
The content below is discovered from `libcc.dll` of Navicat Premium x64 12.0.25 Simplified Chinese version. SHA256 value is `607e0a84c75966b00f3d12fa833e91d159e4f51ac51b6ba66f98d0c3cbefdce0`. I do not guaranteed that __offset__ value is absolutely correct in other versions. But __char string__ and __immediate values__ is highly possible to be found.
|
||||
|
||||
```shell
|
||||
$ ls bin/
|
||||
navicat-keygen navicat-patcher
|
||||
```
|
||||
1. At file offset `+ 0x1A12090` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
## 2. How to Use
|
||||
> "D75125B70767B94145B47C1CB3C0755E
|
||||
> 7CCB8825C5DCE0C58ACF944E08280140
|
||||
> 9A02472FAFFD1CD77864BB821AE36766
|
||||
> FEEDE6A24F12662954168BFA314BD950
|
||||
> 32B9D82445355ED7BC0B880887D650F5"
|
||||
|
||||
1. Build keygen and patcher.
|
||||
2. At file offset `+ 0x59D799` in `libcc.dll`, stored as __immediate value__ in a instruction:
|
||||
|
||||
2. Backup all of your saved database connection configurations (with password).
|
||||
> 0xFE 0xEA 0xBC 0x01
|
||||
|
||||
3. Remove all connections, if have, that Navicat saved in `Keychain Access.app`.
|
||||
In decimal: `29158142`
|
||||
|
||||
You can find them by search with keyword `navicat` in `Keychain Access.app`.
|
||||
3. At file offset `+ 0x1A11DA0` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
4. Use `navicat-patcher` to replace __Navicat Activation Public Key__.
|
||||
|
||||
```
|
||||
Usage:
|
||||
navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]
|
||||
> "E1CED09B9C2186BF71A70C0FE2F1E0AE
|
||||
> F3BD6B75277AAB20DFAF3D110F75912B
|
||||
> FB63AC50EC4C48689D1502715243A79F
|
||||
> 39FF2DE2BF15CE438FF885745ED54573
|
||||
> 850E8A9F40EE2FF505EB7476F95ADB78
|
||||
> 3B28CA374FAC4632892AB82FB3BF4715
|
||||
> FCFE6E82D03731FC3762B6AAC3DF1C3B
|
||||
> C646FE9CD3C62663A97EE72DB932A301
|
||||
> 312B4A7633100C8CC357262C39A2B3A6
|
||||
> 4B224F5276D5EDBDF0804DC3AC4B8351
|
||||
> 62BB1969EAEBADC43D2511D6E0239287
|
||||
> 81B167A48273B953378D3D2080CC0677
|
||||
> 7E8A2364F0234B81064C5C739A8DA28D
|
||||
> C5889072BF37685CBC94C2D31D0179AD
|
||||
> 86D8E3AA8090D4F0B281BE37E0143746
|
||||
> E6049CCC06899401264FA471C016A96C
|
||||
> 79815B55BBC26B43052609D9D175FBCD
|
||||
> E455392F10E51EC162F51CF732E6BB39
|
||||
> 1F56BBFD8D957DF3D4C55B71CEFD54B1
|
||||
> 9C16D458757373E698D7E693A8FC3981
|
||||
> 5A8BF03BA05EA8C8778D38F9873D62B4
|
||||
> 460F41ACF997C30E7C3AF025FA171B5F
|
||||
> 5AD4D6B15E95C27F6B35AD61875E5505
|
||||
> 449B4E"
|
||||
|
||||
<Navicat installation path> Path to `Navicat Premium.app`.
|
||||
Example:
|
||||
/Applications/Navicat\ Premium.app/
|
||||
This parameter must be specified.
|
||||
4. At file offset `+ 0x59D77F` in `libcc.dll`, stored as __immediate value__ in a instruction:
|
||||
|
||||
[RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter is optional.
|
||||
```
|
||||
> 0x59 0x08 0x01 0x00 (in decimal )
|
||||
|
||||
* `<Navicat installation path>`: The path to `Navicat Premium.app`.
|
||||
|
||||
__This parameter must be specified.__
|
||||
In decimal: `67673`
|
||||
|
||||
* `[RSA-2048 PrivateKey(PEM file)]`: The path to an RSA-2048 private key file.
|
||||
|
||||
__This parameter is optional.__
|
||||
|
||||
If not specified, `navicat-patcher` will generate a new RSA-2048 private key file `RegPrivateKey.pem` at current directory.
|
||||
5. At file offset `+ 0x1A11D8C` in `libcc.dll`, stored as __char string__:
|
||||
|
||||
__Example:__
|
||||
> "92933"
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
Then output encrypted public key with format `"%s%d%s%d%s"`, the order is the same as it list:
|
||||
|
||||
It has been tested on __Navicat Premium 12.1.24 For Mac Simplified Chinese__ version.
|
||||
|
||||
The following is an example of output:
|
||||
> D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
***************************************************
|
||||
* Navicat Patcher by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
This encrypted public key can be decrypted by my another repo: [how-does-navicat-encrypt-password](https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password), while the key used is `b'23970790'`
|
||||
|
||||
Press Enter to continue or Ctrl + C to abort.
|
||||
Example:
|
||||
|
||||
[*] Your Navicat version: 12.1.24
|
||||
```cmd
|
||||
E:\GitHub>git clone https://github.com/DoubleLabyrinth/how-does-navicat-encrypt-password.git
|
||||
...
|
||||
E:\GitHub>cd how-does-navicat-encrypt-password\python3
|
||||
E:\GitHub\how-does-navicat-encrypt-password\python3>python
|
||||
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> from NavicatCrypto import *
|
||||
>>> cipher = Navicat11Crypto(b'23970790')
|
||||
>>> print(cipher.DecryptString('D75125B70767B94145B47C1CB3C0755E7CCB8825C5DCE0C58ACF944E082801409A02472FAFFD1CD77864BB821AE36766FEEDE6A24F12662954168BFA314BD95032B9D82445355ED7BC0B880887D650F529158142E1CED09B9C2186BF71A70C0FE2F1E0AEF3BD6B75277AAB20DFAF3D110F75912BFB63AC50EC4C48689D1502715243A79F39FF2DE2BF15CE438FF885745ED54573850E8A9F40EE2FF505EB7476F95ADB783B28CA374FAC4632892AB82FB3BF4715FCFE6E82D03731FC3762B6AAC3DF1C3BC646FE9CD3C62663A97EE72DB932A301312B4A7633100C8CC357262C39A2B3A64B224F5276D5EDBDF0804DC3AC4B835162BB1969EAEBADC43D2511D6E023928781B167A48273B953378D3D2080CC06777E8A2364F0234B81064C5C739A8DA28DC5889072BF37685CBC94C2D31D0179AD86D8E3AA8090D4F0B281BE37E0143746E6049CCC06899401264FA471C016A96C79815B55BBC26B43052609D9D175FBCDE455392F10E51EC162F51CF732E6BB391F56BBFD8D957DF3D4C55B71CEFD54B19C16D458757373E698D7E693A8FC39815A8BF03BA05EA8C8778D38F9873D62B4460F41ACF997C30E7C3AF025FA171B5F5AD4D6B15E95C27F6B35AD61875E5505449B4E6767392933'))
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I
|
||||
qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv
|
||||
a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF
|
||||
R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2
|
||||
WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt
|
||||
YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
[+] PatchSolution0 ...... Ready to apply.
|
||||
Keyword offset = +0x024a7db8
|
||||
[-] PatchSolution1 ...... Omitted.
|
||||
[+] PatchSolution2 ...... Ready to apply.
|
||||
Function offset = +0x00ec9868
|
||||
Keyword offset = +0x0263fd60
|
||||
std::string::append(const char*) RVA = 0x000000010214b726
|
||||
* __Request Code__
|
||||
|
||||
[*] Generating new RSA private key, it may take a long time...
|
||||
[+] New RSA private key has been saved to RegPrivateKey.pem.
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the cipher text of the __offline activation information__ encrypted by __Navicat Activation Public Key__.
|
||||
|
||||
[*] Your RSA public key:
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA030QIDXRx372bGrne9kp
|
||||
uuAqpxaxJX0x6LVaOf8+Uan2SQnFH8frnuMDRg5PjdBnFWEJGqZmRD1fNkLOhhCE
|
||||
iFZWxrDgJcuEBrv5VlduQ4hlYIulcf6qilBZUaaX9Kb3R7+H8ClMb00HwLc/Iht5
|
||||
bd9krhU3CT3g2ZG00GxVhEF4a/zZMDjeuQvTUeeubIeriT/2YC+w/tKfGbqWvjC6
|
||||
wkbjXGbVICSiKzhzztS4BHbtQMl8v6doMhFVd/PEDNFQrbkEr3kbk/oD8AccL8iz
|
||||
aV17UHt4VW2fR8tMyTvcuhTaUtWmt/tL6Z1RzCqH+KvTv8GpH8qFcty89YXja7dL
|
||||
kQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
* __Offline Activation Request Information__
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution0 *
|
||||
**************************************************************
|
||||
@+0x024a7db8
|
||||
Previous:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
After:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
It is just a JSON-style ASCII string which contains 3 items. Respectively they are `"K"`, `"DI"` and `"P"`, which represent __snKey__, __DeviceIdentifier__ (related with your machine), __Platform__ (Appropriately speaking, it should be OS Type).
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution2 *
|
||||
**************************************************************
|
||||
@+0x0263fd60
|
||||
Previous:
|
||||
+0x0000000000000000 42 49 6a 57 79 6f 65 52 52 30 4e 42 67 6b 71 6e BIjWyoeRR0NBgkqn
|
||||
+0x0000000000000010 44 5a 57 78 43 67 4b 43 45 41 77 31 64 71 46 33 DZWxCgKCEAw1dqF3
|
||||
+0x0000000000000020 44 54 76 4f 42 39 31 5a 48 77 65 63 4a 59 46 72 DTvOB91ZHwecJYFr
|
||||
+0x0000000000000030 64 4d 31 4b 45 68 31 79 56 65 52 6f 47 71 53 64 dM1KEh1yVeRoGqSd
|
||||
+0x0000000000000040 4c 4c 47 5a 47 55 6c 6e 67 69 67 33 4f 44 35 6d LLGZGUlngig3OD5m
|
||||
...
|
||||
...
|
||||
...
|
||||
Like:
|
||||
> {"K": "xxxxxxxxxxxxxxxx", "DI": "yyyyyyyyyyyyy", "P": "WIN8"}
|
||||
|
||||
@+0x00ec9868
|
||||
Previous:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 38 49 89 fe c6 45 e5 01 31 c0 88 45 SH..8I...E..1..E
|
||||
+0x0000000000000018 e6 88 45 e7 48 8d 35 c5 70 61 01 48 8d 5d b0 48 ..E.H.5.pa.H.].H
|
||||
+0x0000000000000028 89 df e8 49 d9 ff ff 48 8d 35 ef ed 60 01 48 89 ...I...H.5..`.H.
|
||||
+0x0000000000000038 df e8 80 1e 28 01 e8 3f f4 00 00 88 45 e5 e8 b7 ....(..?....E...
|
||||
+0x0000000000000048 f4 00 00 88 45 e6 e8 2f f5 00 00 88 45 e7 f6 45 ....E../....E..E
|
||||
After:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 48 48 89 fb 48 31 c0 48 89 04 24 48 SH..HH..H1.H..$H
|
||||
+0x0000000000000018 89 44 24 08 48 89 44 24 10 48 8d 3c 24 48 8d 35 .D$.H.D$.H.<$H.5
|
||||
+0x0000000000000028 cc 64 77 01 e8 8d 1e 28 01 48 8b 04 24 48 89 03 .dw....(.H..$H..
|
||||
+0x0000000000000038 48 8b 44 24 08 48 89 43 08 48 8b 44 24 10 48 89 H.D$.H.C.H.D$.H.
|
||||
+0x0000000000000048 43 10 48 89 d8 48 83 c4 48 5b 41 5e 41 5f 5d c3 C.H..H..H[A^A_].
|
||||
* __Activation Code__
|
||||
|
||||
[+] PatchSolution0 has been applied.
|
||||
[+] PatchSolution2 has been applied.
|
||||
It is a Base64 string that represents 256-bytes-long data, while the 256-bytes-long data is the cipher text of the __offline activation response information__ encrypted by __Navicat Activation Private Key__ (so far, we don't know official activation private key).
|
||||
|
||||
**************************************************************
|
||||
* Patch has been done successfully. Have fun and enjoy~~ *
|
||||
* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *
|
||||
**************************************************************
|
||||
```
|
||||
* __Offline Activation Response Information__
|
||||
|
||||
* __FOR Navicat Premium version < 12.0.24 ONLY:__
|
||||
Just like __Offline Activation Request Information__, it is also a JSON-style ASCII string. But it contains 5 items. Respectively they are `"K"`, `"N"`, `"O"`, `"T"`, '`DI`'.
|
||||
|
||||
`navicat-patcher` will abort and won't apply any patch.
|
||||
|
||||
You should use openssl to generate `RegPrivateKey.pem` and `rpk` file.
|
||||
|
||||
```console
|
||||
$ openssl genrsa -out RegPrivateKey.pem 2048
|
||||
$ openssl rsa -in RegPrivateKey.pem -pubout -out rpk
|
||||
```
|
||||
|
||||
Then replace
|
||||
`"K"` and `"DI"` has the same meaning mentioned in __Offline Activation Request Information__ and must be same with the corresponding items in __Offline Activation Request Information__.
|
||||
|
||||
`"N"`, `"O"`, `"T"` represent __Name__, __Organization__, __Time__ respectively. __Name__ and __Organization__ are string and the type of __Time__ can be string or integer (Thanks for discoveries from @Wizr, issue #10).
|
||||
|
||||
`"T"` can be omitted.
|
||||
|
||||
* __snKey__
|
||||
|
||||
It is a 4-block-long string, while every block is 4-chars-long.
|
||||
|
||||
__snKey__ is generated by 10-bytes-long data. In order to explain it easily, I use __data[10]__ to represent the 10-bytes-long data.
|
||||
|
||||
1. __data[0]__ and __data[1]__ must be `0x68` and `0x2A` respectively.
|
||||
|
||||
_`May change when Navicat product changes. Uncertain yet.`_
|
||||
|
||||
2. __data[2]__, __data[3]__ and __data[4]__ can be any byte. Just set them whatever you want.
|
||||
|
||||
_`May change when Navicat product changes. Uncertain yet. But it's very possible right.`_
|
||||
|
||||
3. __data[5]__ and __data[6]__ are related with your Navicat product language. It depends.
|
||||
|
||||
~~_`May change when Navicat product changes. Uncertain yet.`_~~
|
||||
_`Must change when Navicat product changes. Confirmed yet.`_
|
||||
|
||||
| Language | data[5] | data[6] | Discoverer |
|
||||
|------------|-----------|-----------|-----------------|
|
||||
| English | 0xAC | 0x88 | |
|
||||
| 简体中文 | 0xCE | 0x32 | |
|
||||
| 繁體中文 | 0xAA | 0x99 | |
|
||||
| 日本語 | 0xAD | 0x82 | @dragonflylee |
|
||||
| Polski | 0xBB | 0x55 | @dragonflylee |
|
||||
| Español | 0xAE | 0x10 | @dragonflylee |
|
||||
| Français | 0xFA | 0x20 | @Deltafox79 |
|
||||
| Deutsch | 0xB1 | 0x60 | @dragonflylee |
|
||||
| 한국어 | 0xB5 | 0x60 | @dragonflylee |
|
||||
| Русский | 0xEE | 0x16 | @dragonflylee |
|
||||
| Português | 0xCD | 0x49 | @dragonflylee |
|
||||
|
||||
According to __Navicat 12 for Mac x64__ version, what IDA 7.0 indicates is that this two bytes are product signature.
|
||||
|
||||
4. __data[7]__ represents whether it is __commercial license__ or __non-commercial license__.
|
||||
|
||||
For __Navicat 12 x64__: `0x65` is __commercial license__, `0x66` is __non-commercial license__.
|
||||
For __Navicat 11 x64__: `0x15` is __commercial license__, `0x16` is __non-commercial license__.
|
||||
|
||||
_`May change when Navicat product changes. Uncertain yet.`_
|
||||
_`Must change when version change.`_
|
||||
|
||||
According to __Navicat 12 for Mac x64__ version, what IDA 7.0 indicates is that commercial license is __Enterprise License__ and non-commercial license is __Educational License__.
|
||||
|
||||
5. High 4 bits of __data[8]__ represents __version number__. Low 4 bits is unknown, but we can use it to delay activation deadline. Possible value is `0000` or `0001`.
|
||||
|
||||
For __Navicat 12 x64__: High 4 bits must be `1100`, which is the binary of number `12`.
|
||||
For __Navicat 11 x64__: High 4 bits must be `1011`, which is the binary of number `11`.
|
||||
|
||||
_`Must change when version change. Confirmed by Navicat 12 for Mac x64 with IDA Pro 7.0`_
|
||||
|
||||
6. __data[9]__ is unknown, but you can set it `0xFD` or `0xFC` or `0xFB` if you want to use __not-for-resale license__.
|
||||
|
||||
_`May change when Navicat product changes. Uncertain yet.`_
|
||||
|
||||
According to __Navicat 12 for Mac x64__ version, what IDA 7.0 indicates is that:
|
||||
|
||||
* `0xFB` is __Not-For-Resale-30-days__ license.
|
||||
* `0xFC` is __Not-For-Resale-90-days__ license.
|
||||
* `0xFD` is __Not-For-Resale-365-days__ license.
|
||||
* `0xFE` is __Not-For-Resale__ license.
|
||||
* `0xFF` is __Site__ license.
|
||||
|
||||
-----------------
|
||||
|
||||
After that. Navicat use __DES__ with __ECB mode__ to encrypt the last 8 bytes which are from __data[2]__ to __data[9]__.
|
||||
|
||||
The DES key is:
|
||||
|
||||
```cpp
|
||||
unsigned char DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
```
|
||||
|
||||
Then encode the 10-bytes-long data: __(Use Base32 encode if you just want a conclusion.)__
|
||||
|
||||
1. Regard __data[10]__ as a 80-bits-long data.
|
||||
|
||||
If __data[10]__ starts with `0x68` and `0x2A`, so the 80-bits-long data is `01011000 00101010......`
|
||||
|
||||
2. Divide the 80-bits-long data as 16 5-bits-long blocks.
|
||||
|
||||
If __data[10]__ starts with `0x68` and `0x2A`, so the 80-bits-long data is `01011`, `00000`, `10101`, `0....`, ...
|
||||
|
||||
3. So the value every block is less than 32. Map them by a encode-table:
|
||||
|
||||
```cpp
|
||||
char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
```
|
||||
|
||||
Then you will get a 16-char-long string.
|
||||
|
||||
If __data[10]__ starts with `0x68` and `0x2A`, so after encoded, it should starts with `"N"`, `"A"`, `"V"`.
|
||||
|
||||
4. Divide the 16-char-long string to four 4-chars-long blocks, Then you get __snKey__.
|
||||
|
||||
## 3. Activation Process
|
||||
|
||||
1. Check whether __sn_Key__ that user inputs is legal.
|
||||
|
||||
2. After user clicks `Activate`, Navicat will start online activation first. If fails, user can choose offline activation.
|
||||
|
||||
3. Navicat will use the __snKey__ that user inputs and some information collected from user's machine to generate __Offline Activation Request Information__, then encrypt it by __Navicat Activation Public Key__ and return Base64-encoded string as __Request Code__.
|
||||
|
||||
4. In legal way, the __Request Code__ should be sent to Navicat official activation server by a Internet-accessible computer. And Navicat official activation server will return a legal __Activation Code__.
|
||||
|
||||
But now, we use keygen to play the official activation server's role.
|
||||
|
||||
1. According to the __Request Code__, Get `"DI"` value and `"K"` value.
|
||||
|
||||
2. Fill __Offline Activation Response Information__ with `"K"` value, name, organization name and `"DI"` value.
|
||||
|
||||
3. Encrypt __Offline Activation Response Information__ by __Navicat Activation Private Key__ and you will get 256-byte-long data.
|
||||
|
||||
4. Encode 256-byte-long data by Base64. The result is __Activation Code__.
|
||||
|
||||
5. Input __Activation Code__, then offline activation is done.
|
||||
|
||||
## 4. How to use
|
||||
1. Build patcher and keygen in Release configuration or download the latest release.
|
||||
|
||||
2. Replace __Navicat Activation Public Key__ in `navicat.exe` or `libcc.dll`.
|
||||
Example:
|
||||
|
||||
* For Navicat Premium version < 12.0.25
|
||||
```bash
|
||||
E:\GitHub\navicat-keygen\x64\Release>navicat-patcher.exe "D:\Program Files\PremiumSoft\Navicat Premium 12"
|
||||
D:\Program Files\PremiumSoft\Navicat Premium 12\navicat.exe has been backed up.
|
||||
Public key has been replaced.
|
||||
Success!
|
||||
```
|
||||
|
||||
* For Navicat Premium version >= 12.0.25
|
||||
```bash
|
||||
E:\GitHub\navicat-keygen\x64\Release>navicat-patcher.exe "D:\Program Files\PremiumSoft\Navicat Premium 12"
|
||||
D:\Program Files\PremiumSoft\Navicat Premium 12\libcc.dll has been backed up.
|
||||
Public key has been replaced.
|
||||
Success!
|
||||
```
|
||||
You may wait for a few seconds or even longer, because patcher is search for a appropriate RSA key. Finally you will get `RegPrivateKey.pem` file at current directory.
|
||||
|
||||
If you do not want to search, use `RegPrivateKey.pem` in my latest release, then:
|
||||
```bash
|
||||
E:\GitHub\navicat-keygen\x64\Release>navicat-patcher.exe "D:\Program Files\PremiumSoft\Navicat Premium 12" RegPrivateKey.pem
|
||||
D:\Program Files\PremiumSoft\Navicat Premium 12\libcc.dll has been backed up.
|
||||
Public key has been replaced.
|
||||
Success!
|
||||
```
|
||||
|
||||
3. Then in console:
|
||||
|
||||
```bash
|
||||
E:\GitHub\navicat-keygen\x64\Release>navicat-keygen.exe RegPrivateKey.pem
|
||||
|
||||
```
|
||||
/Applications/Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
by `rpk` you just generated.
|
||||
You will get a __snKey__ and be asked to input your name and organization.
|
||||
Just input and then you will be asked to input the request code. Now __DO NOT CLOSE KEYGEN__.
|
||||
|
||||
5. __Generate a self-signed code-sign certificate and always trust it.__
|
||||
4. Disconnect network and open Navicat Premium, find and click `Registration`. Then input `Registration Key` by snKey that keygen gave. Then click `Activate`.
|
||||
|
||||
__Then use `codesign` to re-sign `Navicat Premium.app`.__
|
||||
5. Generally online activation will failed and Navicat will ask you do `Manual Activation`, just choose it.
|
||||
|
||||
```console
|
||||
$ codesign -f -s "Your self-signed code-sign certificate name" <path to Navicat Premium.app>
|
||||
```
|
||||
|
||||
__NOTICE:__
|
||||
|
||||
"Your self-signed code-sign certificate name" is the name of your certificate in `Keychain Access.app`, not path.
|
||||
|
||||
__Example:__
|
||||
|
||||
```console
|
||||
$ codesign -f -s "foobar" /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
|
||||
6. Then use `navicat-keygen` to generate __snKey__ and __Activation Code__.
|
||||
|
||||
```
|
||||
Usage:
|
||||
navicat-keygen <RSA-2048 Private Key File>
|
||||
|
||||
<RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter must be specified.
|
||||
```
|
||||
|
||||
* `<RSA-2048 Private Key File>`: Path to a PEM-format RSA-2048 private key file.
|
||||
|
||||
__This parameter must be specified.__
|
||||
|
||||
__Example:__
|
||||
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
```
|
||||
|
||||
You will be asked to select Navicat language and give major version number. After that an randomly generated __snKey__ will be given.
|
||||
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
***************************************************
|
||||
* Navicat Keygen by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
Which is your Navicat Premium language?
|
||||
0. English
|
||||
1. Simplified Chinese
|
||||
2. Traditional Chinese
|
||||
3. Japanese
|
||||
4. Polish
|
||||
5. Spanish
|
||||
6. French
|
||||
7. German
|
||||
8. Korean
|
||||
9. Russian
|
||||
10. Portuguese
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
(Input major version number, range: 0 ~ 15, default: 12)> 12
|
||||
|
||||
Serial number:
|
||||
NAVG-Z5H9-NK2L-MAZJ
|
||||
|
||||
Your name:
|
||||
```
|
||||
|
||||
You can use this __snKey__ to activate your Navicat preliminarily.
|
||||
|
||||
Then you will be asked to input `Your name` and `Your organization`. Just set them whatever you want, but not too long.
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
Input request code (in Base64), input empty line to end:
|
||||
```
|
||||
|
||||
After that, you will be asked to input request code. Now __DO NOT CLOSE KEYGEN__.
|
||||
|
||||
7. __Disconnect your network__ and open Navicat Premium.
|
||||
|
||||
Find and click `Registration`.
|
||||
|
||||
Fill license key by __Serial number__ that the keygen gave and click `Activate`.
|
||||
|
||||
8. Generally online activation will fail and Navicat will ask you do `Manual Activation`, just choose it.
|
||||
|
||||
9. Copy your request code and paste it in the keygen. Input empty line to tell the keygen that your input ends.
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
|
||||
Input request code (in Base64), input empty line to end:
|
||||
Nuk6pouXNhuGnqb2rBbxpDOiCFxhdJF4/gteYA/UZFUwqmhhphn3PAErvlxCtbUCf9Lzw02gfIFog3gmTB1C5JzPdeE5uuD6SAvhlQ7ZVOmdA66dvt6mDDpuf78cGio1Rpkd0D/6dLzgHnFJJPOfPtlIT5ZOLDiWkiSJm8d83+ckMBoMtcvpXCiwDIGb1KfVZwsgLojyrrO5OzakIzd2xQ8r3mEmbVbMl/zD0S5fO4agxEOp2WvpmM1cqom9Egll7kgcQG8A0z1Abqo1PrVBjjOsb/v8wy5V/469G6/uDT4AkZQSz8m/TX9ZQlZE3QBlzrJ+sTEkpMVhw3h3u6l4JQ==
|
||||
|
||||
Request Info:
|
||||
{"K":"NAVGZ5H9NK2LMAZJ", "DI":"NGVlZjdjOTViMzYyMWI0", "P":"MAC"}
|
||||
|
||||
Response Info:
|
||||
{"K":"NAVGZ5H9NK2LMAZJ","DI":"NGVlZjdjOTViMzYyMWI0","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1564415636}
|
||||
|
||||
License:
|
||||
Vd4QUzEw6DPNpJLYVKV6ZNDny0gsZWCXbKyrf2nF27iTM35YUBouXEcAB/Vy355V2z++7iXe/coKmV4kNZbywlBchI5ts7gOHnhXWzBYQ3yKsBYKob/7sxaiw7CXCmhM4mPLMzrp5okewCWjBjb51keZ4SA3F6j8HGIVYiZW3CAZtkjxs9uUoXvVIJr+Gt83TgU+sqiC4oSplokopAql2zWPieA9KuhPoCKiGLMvuQwv0wWWPc2HorY0AHAetsyZ8MN4utZ2ylQ9z/ZojwX1KViyh3xxnjWF7xXJljIdBA4tCi4QDqDLvTuICfUV7VeKzOUY+ZKCO0xGxkTe1HVwog==
|
||||
```
|
||||
|
||||
10. Finally, you will get __Activation Code__ which looks like a Base64 string.
|
||||
|
||||
Just copy it and paste it in Navicat `Manual Activation` window, then click `Activate`.
|
||||
|
||||
If nothing wrong, activation should be done successfully.
|
||||
6. Copy your request code and paste it in keygen. Input empty line to tell keygen that your input ends.
|
||||
|
||||
7. Then you will get activation code which looks like a Base64 string. Just copy it and paste it in Navicat `Manual Activation` window, then click Activate. If nothing is wrong, activation should be done successfully.
|
||||
|
||||
-310
@@ -1,310 +0,0 @@
|
||||
# Navicat Keygen
|
||||
|
||||
这份repo将会告诉你Navicat是怎么完成离线激活的。
|
||||
|
||||
[注册机是怎么工作的?](HOW_DOES_IT_WORK.zh-CN.md)
|
||||
|
||||
## 1. 如何编译
|
||||
|
||||
* 在编译之前,你应该确保你有如下几个库:
|
||||
|
||||
```
|
||||
openssl
|
||||
capstone
|
||||
keystone
|
||||
rapidjson
|
||||
libplist
|
||||
```
|
||||
|
||||
如果你有`brew`的话,你可以通过
|
||||
|
||||
```
|
||||
$ brew install openssl
|
||||
$ brew install capstone
|
||||
$ brew install keystone
|
||||
$ brew install rapidjson
|
||||
$ brew install libplist
|
||||
```
|
||||
|
||||
来完成它们的安装。
|
||||
|
||||
* Clone `mac` 分支,并编译keygen和patcher
|
||||
|
||||
```bash
|
||||
$ git clone -b mac --single-branch https://github.com/DoubleLabyrinth/navicat-keygen.git
|
||||
$ cd navicat-keygen
|
||||
$ make all
|
||||
```
|
||||
|
||||
编译完成后你会在 `bin/` 文件夹下看到两个可执行文件:
|
||||
|
||||
```bash
|
||||
$ ls bin/
|
||||
navicat-keygen navicat-patcher
|
||||
```
|
||||
|
||||
## 2. 如何使用这个Keygen
|
||||
|
||||
1. 编译好keygen和patcher。
|
||||
|
||||
2. 备份好Navicat中所有已保存的数据库连接(包括密码)。
|
||||
|
||||
3. 移除所有Navicat在 `Keychain Access.app` (即钥匙链)中保存的连接,如果有的话。
|
||||
|
||||
你可以通过在 `Keychain Access.app` 中搜索关键词 `navicat` 来找到它们。
|
||||
|
||||
4. 使用`navicat-patcher`替换掉公钥:
|
||||
|
||||
```
|
||||
Usage:
|
||||
navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]
|
||||
|
||||
<Navicat installation path> Path to `Navicat Premium.app`.
|
||||
Example:
|
||||
/Applications/Navicat\ Premium.app/
|
||||
This parameter must be specified.
|
||||
|
||||
[RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter is optional.
|
||||
```
|
||||
|
||||
* `<Navicat installation path>`: `Navicat Premium.app` 的路径。
|
||||
|
||||
__这个参数必须指定。__
|
||||
|
||||
* `[RSA-2048 PrivateKey(PEM file)]`: PEM格式的RSA-2048私钥文件路径。
|
||||
|
||||
__这个参数是可选的。__
|
||||
|
||||
如果没有指定,`navicat-patcher`将会在当前目录下生成一个新的RSA-2048私钥文件`RegPrivateKey.pem`。
|
||||
|
||||
__例如:__
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
|
||||
__Navicat Premium For Mac 12.1.24 简体中文版__ 已通过测试。下面将是一份样例输出:
|
||||
|
||||
```console
|
||||
$ ./navicat-patcher /Applications/Navicat\ Premium.app/
|
||||
***************************************************
|
||||
* Navicat Patcher by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
Press Enter to continue or Ctrl + C to abort.
|
||||
|
||||
[*] Your Navicat version: 12.1.24
|
||||
|
||||
[+] PatchSolution0 ...... Ready to apply.
|
||||
Keyword offset = +0x024a7db8
|
||||
[-] PatchSolution1 ...... Omitted.
|
||||
[+] PatchSolution2 ...... Ready to apply.
|
||||
Function offset = +0x00ec9868
|
||||
Keyword offset = +0x0263fd60
|
||||
std::string::append(const char*) RVA = 0x000000010214b726
|
||||
|
||||
[*] Generating new RSA private key, it may take a long time...
|
||||
[+] New RSA private key has been saved to RegPrivateKey.pem.
|
||||
|
||||
[*] Your RSA public key:
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA030QIDXRx372bGrne9kp
|
||||
uuAqpxaxJX0x6LVaOf8+Uan2SQnFH8frnuMDRg5PjdBnFWEJGqZmRD1fNkLOhhCE
|
||||
iFZWxrDgJcuEBrv5VlduQ4hlYIulcf6qilBZUaaX9Kb3R7+H8ClMb00HwLc/Iht5
|
||||
bd9krhU3CT3g2ZG00GxVhEF4a/zZMDjeuQvTUeeubIeriT/2YC+w/tKfGbqWvjC6
|
||||
wkbjXGbVICSiKzhzztS4BHbtQMl8v6doMhFVd/PEDNFQrbkEr3kbk/oD8AccL8iz
|
||||
aV17UHt4VW2fR8tMyTvcuhTaUtWmt/tL6Z1RzCqH+KvTv8GpH8qFcty89YXja7dL
|
||||
kQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution0 *
|
||||
**************************************************************
|
||||
@+0x024a7db8
|
||||
Previous:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
After:
|
||||
-0x0000000000000008 2d 2d 2d 2d 2d 42 45 47 -----BEG
|
||||
+0x0000000000000008 49 4e 20 50 55 42 4c 49 43 20 4b 45 59 2d 2d 2d IN PUBLIC KEY---
|
||||
+0x0000000000000018 2d 2d 00 4d 49 49 42 49 6a 41 4e 42 67 6b 71 68 --.MIIBIjANBgkqh
|
||||
+0x0000000000000028 6b 69 47 39 77 30 42 41 51 45 46 41 41 4f 43 41 kiG9w0BAQEFAAOCA
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
**************************************************************
|
||||
* PatchSolution2 *
|
||||
**************************************************************
|
||||
@+0x0263fd60
|
||||
Previous:
|
||||
+0x0000000000000000 42 49 6a 57 79 6f 65 52 52 30 4e 42 67 6b 71 6e BIjWyoeRR0NBgkqn
|
||||
+0x0000000000000010 44 5a 57 78 43 67 4b 43 45 41 77 31 64 71 46 33 DZWxCgKCEAw1dqF3
|
||||
+0x0000000000000020 44 54 76 4f 42 39 31 5a 48 77 65 63 4a 59 46 72 DTvOB91ZHwecJYFr
|
||||
+0x0000000000000030 64 4d 31 4b 45 68 31 79 56 65 52 6f 47 71 53 64 dM1KEh1yVeRoGqSd
|
||||
+0x0000000000000040 4c 4c 47 5a 47 55 6c 6e 67 69 67 33 4f 44 35 6d LLGZGUlngig3OD5m
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
@+0x00ec9868
|
||||
Previous:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 38 49 89 fe c6 45 e5 01 31 c0 88 45 SH..8I...E..1..E
|
||||
+0x0000000000000018 e6 88 45 e7 48 8d 35 c5 70 61 01 48 8d 5d b0 48 ..E.H.5.pa.H.].H
|
||||
+0x0000000000000028 89 df e8 49 d9 ff ff 48 8d 35 ef ed 60 01 48 89 ...I...H.5..`.H.
|
||||
+0x0000000000000038 df e8 80 1e 28 01 e8 3f f4 00 00 88 45 e5 e8 b7 ....(..?....E...
|
||||
+0x0000000000000048 f4 00 00 88 45 e6 e8 2f f5 00 00 88 45 e7 f6 45 ....E../....E..E
|
||||
After:
|
||||
-0x0000000000000008 55 48 89 e5 41 57 41 56 UH..AWAV
|
||||
+0x0000000000000008 53 48 83 ec 48 48 89 fb 48 31 c0 48 89 04 24 48 SH..HH..H1.H..$H
|
||||
+0x0000000000000018 89 44 24 08 48 89 44 24 10 48 8d 3c 24 48 8d 35 .D$.H.D$.H.<$H.5
|
||||
+0x0000000000000028 cc 64 77 01 e8 8d 1e 28 01 48 8b 04 24 48 89 03 .dw....(.H..$H..
|
||||
+0x0000000000000038 48 8b 44 24 08 48 89 43 08 48 8b 44 24 10 48 89 H.D$.H.C.H.D$.H.
|
||||
+0x0000000000000048 43 10 48 89 d8 48 83 c4 48 5b 41 5e 41 5f 5d c3 C.H..H..H[A^A_].
|
||||
|
||||
[+] PatchSolution0 has been applied.
|
||||
[+] PatchSolution2 has been applied.
|
||||
|
||||
**************************************************************
|
||||
* Patch has been done successfully. Have fun and enjoy~~ *
|
||||
* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *
|
||||
**************************************************************
|
||||
```
|
||||
|
||||
* __仅对 Navicat Premium 版本 < 12.0.24 的说明:__
|
||||
|
||||
如果你的Navicat版本小于12.0.24,那么`navicat-patcher`将会终止并且不会修改目标文件。
|
||||
|
||||
你必须使用openssl生成`RegPrivateKey.pem`和`rpk`文件:
|
||||
|
||||
```console
|
||||
$ openssl genrsa -out RegPrivateKey.pem 2048
|
||||
$ openssl rsa -in RegPrivateKey.pem -pubout -out rpk
|
||||
```
|
||||
|
||||
接着用刚生成的`rpk`文件替换
|
||||
|
||||
```
|
||||
/Applications/Navicat Premium.app/Contents/Resources/rpk
|
||||
```
|
||||
|
||||
5. __生成一份自签名的代码证书,并总是信任该证书。这一步非常重要。__
|
||||
|
||||
__然后用`codesign`对`Navicat Premium.app`重签名。__
|
||||
|
||||
```console
|
||||
$ codesign -f -s "Your self-signed code-sign certificate name" <path to Navicat Premium.app>
|
||||
```
|
||||
|
||||
__注意:__
|
||||
|
||||
"Your self-signed code-sign certificate name"是你证书的名字,不是路径。
|
||||
|
||||
__例如:__
|
||||
|
||||
```console
|
||||
$ codesign -f -s "foobar" /Applications/Navicat\ Premium.app/
|
||||
```
|
||||
|
||||
6. 接下来使用`navicat-keygen`来生成 __序列号__ 和 __激活码__。
|
||||
|
||||
```
|
||||
Usage:
|
||||
navicat-keygen <RSA-2048 Private Key File>
|
||||
|
||||
<RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file.
|
||||
This parameter must be specified.
|
||||
```
|
||||
|
||||
* `<RSA-2048 Private Key File>`: PEM格式的RSA-2048私钥文件路径。
|
||||
|
||||
__这个参数必须指定。__
|
||||
|
||||
__例如:__
|
||||
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
```
|
||||
|
||||
你会被要求选择Navicat的语言以及输入主版本号。之后会随机生成一个 __序列号__。
|
||||
|
||||
```console
|
||||
$ ./navicat-keygen ./RegPrivateKey.pem
|
||||
***************************************************
|
||||
* Navicat Keygen by @DoubleLabyrinth *
|
||||
* Version: 4.0 *
|
||||
***************************************************
|
||||
|
||||
Which is your Navicat Premium language?
|
||||
0. English
|
||||
1. Simplified Chinese
|
||||
2. Traditional Chinese
|
||||
3. Japanese
|
||||
4. Polish
|
||||
5. Spanish
|
||||
6. French
|
||||
7. German
|
||||
8. Korean
|
||||
9. Russian
|
||||
10. Portuguese
|
||||
|
||||
(Input index)> 1
|
||||
|
||||
(Input major version number, range: 0 ~ 15, default: 12)> 12
|
||||
|
||||
Serial number:
|
||||
NAVG-Z5H9-NK2L-MAZJ
|
||||
|
||||
Your name:
|
||||
```
|
||||
|
||||
你可以使用这个 __序列号__ 暂时激活Navicat。
|
||||
|
||||
接下来你会被要求输入`用户名`和`组织名`;请随便填写,但不要太长。
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
Input request code (in Base64), input empty line to end:
|
||||
```
|
||||
|
||||
之后你会被要求填入请求码。注意 __不要关闭注册机__。
|
||||
|
||||
7. __断开网络__ 并打开Navicat。
|
||||
|
||||
找到`注册`窗口,填入注册机给你的序列号。然后点击`激活`按钮。
|
||||
|
||||
8. 一般来说在线激活肯定会失败,这时候Navicat会询问你是否`手动激活`,直接选吧。
|
||||
|
||||
9. 在`手动激活`窗口你会得到一个请求码,复制它并把它粘贴到keygen里。最后别忘了连按至少两下回车结束输入。
|
||||
|
||||
```console
|
||||
Your name: DoubleLabyrinth
|
||||
Your organization: DoubleLabyrinth
|
||||
|
||||
Input request code (in Base64), input empty line to end:
|
||||
Nuk6pouXNhuGnqb2rBbxpDOiCFxhdJF4/gteYA/UZFUwqmhhphn3PAErvlxCtbUCf9Lzw02gfIFog3gmTB1C5JzPdeE5uuD6SAvhlQ7ZVOmdA66dvt6mDDpuf78cGio1Rpkd0D/6dLzgHnFJJPOfPtlIT5ZOLDiWkiSJm8d83+ckMBoMtcvpXCiwDIGb1KfVZwsgLojyrrO5OzakIzd2xQ8r3mEmbVbMl/zD0S5fO4agxEOp2WvpmM1cqom9Egll7kgcQG8A0z1Abqo1PrVBjjOsb/v8wy5V/469G6/uDT4AkZQSz8m/TX9ZQlZE3QBlzrJ+sTEkpMVhw3h3u6l4JQ==
|
||||
|
||||
Request Info:
|
||||
{"K":"NAVGZ5H9NK2LMAZJ", "DI":"NGVlZjdjOTViMzYyMWI0", "P":"MAC"}
|
||||
|
||||
Response Info:
|
||||
{"K":"NAVGZ5H9NK2LMAZJ","DI":"NGVlZjdjOTViMzYyMWI0","N":"DoubleLabyrinth","O":"DoubleLabyrinth","T":1564415636}
|
||||
|
||||
License:
|
||||
Vd4QUzEw6DPNpJLYVKV6ZNDny0gsZWCXbKyrf2nF27iTM35YUBouXEcAB/Vy355V2z++7iXe/coKmV4kNZbywlBchI5ts7gOHnhXWzBYQ3yKsBYKob/7sxaiw7CXCmhM4mPLMzrp5okewCWjBjb51keZ4SA3F6j8HGIVYiZW3CAZtkjxs9uUoXvVIJr+Gt83TgU+sqiC4oSplokopAql2zWPieA9KuhPoCKiGLMvuQwv0wWWPc2HorY0AHAetsyZ8MN4utZ2ylQ9z/ZojwX1KViyh3xxnjWF7xXJljIdBA4tCi4QDqDLvTuICfUV7VeKzOUY+ZKCO0xGxkTe1HVwog==
|
||||
```
|
||||
|
||||
10. 如果不出意外,你会得到一个看似用Base64编码的激活码。
|
||||
|
||||
直接复制它,并把它粘贴到Navicat的`手动激活`窗口,最后点`激活`按钮。
|
||||
|
||||
如果没什么意外的话应该能成功激活。
|
||||
@@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class Exception {
|
||||
private:
|
||||
|
||||
const char* pvt_File;
|
||||
const char* pvt_Message;
|
||||
size_t pvt_Line;
|
||||
|
||||
public:
|
||||
|
||||
Exception(const char* File, size_t Line, const char* Message) noexcept :
|
||||
pvt_File(File),
|
||||
pvt_Message(Message),
|
||||
pvt_Line(Line) {}
|
||||
|
||||
[[nodiscard]]
|
||||
const char* File() const noexcept {
|
||||
return pvt_File;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t Line() const noexcept {
|
||||
return pvt_Line;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const char* Message() const noexcept {
|
||||
return pvt_Message;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool HasErrorCode() const noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual intptr_t ErrorCode() const noexcept {
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const char* ErrorString() const noexcept {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/err.h>
|
||||
#include "Exception.hpp"
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class OpensslError final : public Exception {
|
||||
private:
|
||||
|
||||
unsigned long pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
OpensslError(const char* File, unsigned Line, unsigned long ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
ERR_load_crypto_strings();
|
||||
return ERR_reason_error_string(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
#include "Exception.hpp"
|
||||
#include <string.h> // NOLINT
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class SystemError final : public Exception {
|
||||
private:
|
||||
|
||||
int pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
SystemError(const char* File, unsigned Line, int ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ExceptionOpenssl.hpp"
|
||||
#include "ResourceOwned.hpp"
|
||||
#include "ResourceTraitsOpenssl.hpp"
|
||||
|
||||
enum class RSAKeyType {
|
||||
PrivateKey,
|
||||
PublicKey
|
||||
};
|
||||
|
||||
enum class RSAKeyFormat {
|
||||
PEM,
|
||||
PKCS1
|
||||
};
|
||||
|
||||
class RSACipher {
|
||||
private:
|
||||
ResourceOwned<OpensslRSATraits> pvt_RsaObj;
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
static void pvt_WriteRSAToBIO(RSA* lpRSA, BIO* lpBIO) {
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
if (PEM_write_bio_RSAPrivateKey(lpBIO, lpRSA, nullptr, nullptr, 0, nullptr, nullptr) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSAPrivateKey failed.");
|
||||
}
|
||||
} else {
|
||||
if constexpr (__Format == RSAKeyFormat::PEM) {
|
||||
if (PEM_write_bio_RSA_PUBKEY(lpBIO, lpRSA) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSA_PUBKEY failed.");
|
||||
}
|
||||
} else if constexpr (__Format == RSAKeyFormat::PKCS1) {
|
||||
if (PEM_write_bio_RSAPublicKey(lpBIO, lpRSA) == 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_write_bio_RSAPublicKey failed.");
|
||||
}
|
||||
} else {
|
||||
static_assert(__Format == RSAKeyFormat::PEM || __Format == RSAKeyFormat::PKCS1);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<RSAKeyType _Type, RSAKeyFormat _Format>
|
||||
[[nodiscard]]
|
||||
static RSA* pvt_ReadRSAFromBIO(BIO* lpBIO) {
|
||||
RSA* lpRSA;
|
||||
|
||||
if constexpr (_Type == RSAKeyType::PrivateKey) {
|
||||
lpRSA = PEM_read_bio_RSAPrivateKey(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_read_bio_RSAPrivateKey failed.");
|
||||
}
|
||||
} else {
|
||||
if constexpr (_Format == RSAKeyFormat::PEM) {
|
||||
lpRSA = PEM_read_bio_RSA_PUBKEY(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, " -> PEM_read_bio_RSA_PUBKEY failed.");
|
||||
}
|
||||
} else if constexpr (_Format == RSAKeyFormat::PKCS1) {
|
||||
lpRSA = PEM_read_bio_RSAPublicKey(lpBIO, nullptr, nullptr, nullptr);
|
||||
if (lpRSA == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PEM_read_bio_RSAPublicKey failed.");
|
||||
}
|
||||
} else {
|
||||
static_assert(_Format == RSAKeyFormat::PEM || _Format == RSAKeyFormat::PKCS1);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
return lpRSA;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
RSACipher() : pvt_RsaObj(OpensslRSATraits{}, RSA_new()) {
|
||||
if (pvt_RsaObj.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_new failed.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t Bits() const {
|
||||
#if (OPENSSL_VERSION_NUMBER & 0xffff0000) == 0x10000000 // openssl 1.0.x
|
||||
if (pvt_RsaObj->n == nullptr) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "RSA modulus has not been set.");
|
||||
} else {
|
||||
return BN_num_bits(pvt_RsaObj->n);
|
||||
}
|
||||
#elif (OPENSSL_VERSION_NUMBER & 0xffff0000) == 0x10100000 // openssl 1.1.x
|
||||
return RSA_bits(pvt_RsaObj);
|
||||
#else
|
||||
#error "Unexpected openssl version!"
|
||||
#endif
|
||||
}
|
||||
|
||||
void GenerateKey(int bits, unsigned int e = RSA_F4) {
|
||||
ResourceOwned bn_e(OpensslBNTraits{}, BN_new());
|
||||
|
||||
if (bn_e.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "BN_new failed.");
|
||||
}
|
||||
|
||||
if (!BN_set_word(bn_e, e)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BN_set_word failed.");
|
||||
}
|
||||
|
||||
if (!RSA_generate_key_ex(pvt_RsaObj, bits, bn_e, nullptr)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_generate_key_ex failed.");
|
||||
}
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ExportKeyToFile(const std::string& FileName) const {
|
||||
ResourceOwned BioFile(OpensslBIOTraits{}, BIO_new_file(FileName.c_str(), "w"));
|
||||
|
||||
if (BioFile.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new_file failed.");
|
||||
}
|
||||
|
||||
pvt_WriteRSAToBIO<__Type, __Format>(pvt_RsaObj, BioFile);
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
[[nodiscard]]
|
||||
std::string ExportKeyString() const {
|
||||
ResourceOwned BioMemory(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
long StringLength;
|
||||
const char* StringChars = nullptr;
|
||||
|
||||
if (BioMemory.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
pvt_WriteRSAToBIO<__Type, __Format>(pvt_RsaObj, BioMemory);
|
||||
|
||||
StringLength = BIO_get_mem_data(BioMemory, &StringChars);
|
||||
|
||||
return std::string(StringChars, StringLength);
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ImportKeyFromFile(const std::string& FileName) {
|
||||
ResourceOwned BioFile(OpensslBIOTraits{}, BIO_new_file(FileName.c_str(), "r"));
|
||||
|
||||
if (BioFile.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new_file failed.");
|
||||
}
|
||||
|
||||
pvt_RsaObj.TakeOver(pvt_ReadRSAFromBIO<__Type, __Format>(BioFile));
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type, RSAKeyFormat __Format>
|
||||
void ImportKeyString(const std::string& KeyString) {
|
||||
ResourceOwned BioMemory(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
RSA* NewRsaObj;
|
||||
|
||||
if (BioMemory.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
if (BIO_puts(BioMemory, KeyString.c_str()) <= 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_puts failed.");
|
||||
}
|
||||
|
||||
pvt_RsaObj.TakeOver(pvt_ReadRSAFromBIO<__Type, __Format>(BioMemory));
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type = RSAKeyType::PublicKey>
|
||||
size_t Encrypt(const void* lpFrom, size_t cbFrom, void* lpTo, int Padding) const {
|
||||
int BytesWritten;
|
||||
|
||||
if (cbFrom > INT_MAX) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Length overflowed.");
|
||||
}
|
||||
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
BytesWritten = RSA_private_encrypt(
|
||||
static_cast<int>(cbFrom),
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_private_encrypt failed.");
|
||||
}
|
||||
} else {
|
||||
BytesWritten = RSA_public_encrypt(
|
||||
static_cast<int>(cbFrom),
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_public_encrypt failed.");
|
||||
}
|
||||
}
|
||||
|
||||
return BytesWritten;
|
||||
}
|
||||
|
||||
template<RSAKeyType __Type = RSAKeyType::PrivateKey>
|
||||
size_t Decrypt(const void* lpFrom, int cbFrom, void* lpTo, int Padding) const {
|
||||
int BytesWritten;
|
||||
|
||||
if (cbFrom > INT_MAX) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Length overflowed.");
|
||||
}
|
||||
|
||||
if constexpr (__Type == RSAKeyType::PrivateKey) {
|
||||
BytesWritten = RSA_private_decrypt(
|
||||
cbFrom,
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_private_decrypt failed.");
|
||||
}
|
||||
} else {
|
||||
BytesWritten = RSA_public_decrypt(
|
||||
cbFrom,
|
||||
reinterpret_cast<const unsigned char*>(lpFrom),
|
||||
reinterpret_cast<unsigned char*>(lpTo),
|
||||
pvt_RsaObj,
|
||||
Padding
|
||||
);
|
||||
|
||||
if (BytesWritten == -1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived lpFrom std::exception
|
||||
throw nkg::OpensslError(__FILE__, __LINE__, ERR_get_error(), "RSA_public_decrypt failed.");
|
||||
}
|
||||
}
|
||||
|
||||
return BytesWritten;
|
||||
}
|
||||
};
|
||||
@@ -1,304 +0,0 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
template<typename __ResourceTraits, typename __LambdaReleasor = void>
|
||||
class ResourceOwned {
|
||||
private:
|
||||
|
||||
using __HandleType = typename __ResourceTraits::HandleType;
|
||||
static_assert(std::is_pod_v<__HandleType>);
|
||||
|
||||
__HandleType pvt_Handle;
|
||||
__LambdaReleasor pvt_Releasor;
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
// Construct from custom releasor.
|
||||
// ``pvt_Handle` will be set to an invalid value.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, __LambdaReleasor&& Releasor) noexcept :
|
||||
pvt_Handle(__ResourceTraits::InvalidValue),
|
||||
pvt_Releasor(std::forward<__LambdaReleasor>(Releasor)) {}
|
||||
|
||||
//
|
||||
// Construct from handle given and custom releasor.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, const __HandleType& Handle, __LambdaReleasor&& Releasor) noexcept :
|
||||
pvt_Handle(Handle),
|
||||
pvt_Releasor(std::forward<__LambdaReleasor>(Releasor)) {}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned(const ResourceOwned<__ResourceTraits, __LambdaReleasor>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned(ResourceOwned<__ResourceTraits, __LambdaReleasor>&& Other) noexcept :
|
||||
pvt_Handle(Other.pvt_Handle),
|
||||
pvt_Releasor(std::move(Other.pvt_Releasor))
|
||||
{
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, __LambdaReleasor>&
|
||||
operator=(const ResourceOwned<__ResourceTraits, __LambdaReleasor>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, __LambdaReleasor>&
|
||||
operator=(ResourceOwned<__ResourceTraits, __LambdaReleasor>&& Other) noexcept {
|
||||
this->pvt_Handle = Other.pvt_Handle;
|
||||
this->pvt_Releasor = std::move(Other.pvt_Releasor);
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
operator const __HandleType&() const noexcept { // NOLINT: Allow implicit conversion.
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __AsType, bool __IsPointer = std::is_pointer_v<__HandleType>, typename = std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__AsType As() const noexcept {
|
||||
return reinterpret_cast<__AsType>(this->pvt_Handle);
|
||||
}
|
||||
|
||||
template<bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__HandleType operator->() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsValid() const noexcept {
|
||||
return __ResourceTraits::IsValid(this->pvt_Handle);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const __HandleType& Get() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __ReturnType = __HandleType*>
|
||||
[[nodiscard]]
|
||||
__ReturnType GetAddress() noexcept {
|
||||
return reinterpret_cast<__ReturnType>(&this->pvt_Handle);
|
||||
}
|
||||
|
||||
void TakeOver(const __HandleType& Handle) {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle) == true) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
}
|
||||
this->pvt_Handle = Handle;
|
||||
}
|
||||
|
||||
void Discard() noexcept {
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
__HandleType Transfer() noexcept {
|
||||
__HandleType t = this->pvt_Handle;
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
|
||||
~ResourceOwned() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
this->pvt_Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ResourceTraits>
|
||||
class ResourceOwned<__ResourceTraits, void> {
|
||||
private:
|
||||
|
||||
using __HandleType = typename __ResourceTraits::HandleType;
|
||||
static_assert(std::is_pod_v<__HandleType>);
|
||||
|
||||
__HandleType pvt_Handle;
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
// Construct from custom releasor.
|
||||
// ``pvt_Handle` will be set to an invalid value.
|
||||
//
|
||||
explicit
|
||||
ResourceOwned(__ResourceTraits) noexcept :
|
||||
pvt_Handle(__ResourceTraits::InvalidValue) {}
|
||||
|
||||
//
|
||||
// Construct from handle given and custom releasor.
|
||||
//
|
||||
ResourceOwned(__ResourceTraits, const __HandleType& Handle) noexcept :
|
||||
pvt_Handle(Handle) {}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned(const ResourceOwned<__ResourceTraits, void>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned(ResourceOwned<__ResourceTraits, void>&& Other) noexcept :
|
||||
pvt_Handle(Other.pvt_Handle)
|
||||
{
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
//
|
||||
// ResourceOwned doesn't allow to copy.
|
||||
// Because it takes `pvt_Handle` exclusively.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, void>&
|
||||
operator=(const ResourceOwned<__ResourceTraits, void>& Other) = delete;
|
||||
|
||||
//
|
||||
// ResourceOwned allows to move.
|
||||
//
|
||||
ResourceOwned<__ResourceTraits, void>&
|
||||
operator=(ResourceOwned<__ResourceTraits, void>&& Other) noexcept {
|
||||
this->pvt_Handle = Other.pvt_Handle;
|
||||
Other.pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
operator const __HandleType&() const noexcept { // NOLINT: Allow implicit conversion.
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __AsType, bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__AsType As() const noexcept {
|
||||
return reinterpret_cast<__AsType>(this->pvt_Handle);
|
||||
}
|
||||
|
||||
template<bool __IsPointer = std::is_pointer_v<__HandleType>, typename = typename std::enable_if_t<__IsPointer>>
|
||||
[[nodiscard]]
|
||||
__HandleType operator->() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsValid() const noexcept {
|
||||
return __ResourceTraits::IsValid(this->pvt_Handle);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const __HandleType& Get() const noexcept {
|
||||
return this->pvt_Handle;
|
||||
}
|
||||
|
||||
template<typename __ReturnType = __HandleType*>
|
||||
[[nodiscard]]
|
||||
__ReturnType GetAddress() noexcept {
|
||||
return reinterpret_cast<__ReturnType>(&this->pvt_Handle);
|
||||
}
|
||||
|
||||
void TakeOver(const __HandleType& Handle) {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle) == true) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
}
|
||||
this->pvt_Handle = Handle;
|
||||
}
|
||||
|
||||
void Discard() noexcept {
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
__HandleType Transfer() noexcept {
|
||||
__HandleType t = this->pvt_Handle;
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Release() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
|
||||
~ResourceOwned() {
|
||||
if (__ResourceTraits::IsValid(this->pvt_Handle)) {
|
||||
__ResourceTraits::Releasor(this->pvt_Handle);
|
||||
this->pvt_Handle = __ResourceTraits::InvalidValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ResourceTraits>
|
||||
ResourceOwned(__ResourceTraits) ->
|
||||
ResourceOwned<__ResourceTraits, void>;
|
||||
|
||||
template<typename __ResourceTraits, typename __ArgType>
|
||||
ResourceOwned(__ResourceTraits, __ArgType&&) ->
|
||||
ResourceOwned<
|
||||
__ResourceTraits,
|
||||
std::conditional_t<
|
||||
std::is_same_v<std::remove_cv_t<std::remove_reference_t<__ArgType>>, typename __ResourceTraits::HandleType> == false,
|
||||
std::remove_reference_t<__ArgType>,
|
||||
void
|
||||
>
|
||||
>;
|
||||
|
||||
template<typename __ResourceTraits, typename __LambdaReleasor>
|
||||
ResourceOwned(__ResourceTraits, const typename __ResourceTraits::HandleType&, __LambdaReleasor&&) ->
|
||||
ResourceOwned<__ResourceTraits, std::remove_reference_t<__LambdaReleasor>>;
|
||||
|
||||
template<typename __ClassType>
|
||||
struct CppObjectTraits {
|
||||
using HandleType = __ClassType*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
delete Handle;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename __ClassType>
|
||||
struct CppDynamicArrayTraits {
|
||||
using HandleType = __ClassType*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
delete[] Handle;
|
||||
}
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
struct OpensslBIOTraits {
|
||||
using HandleType = BIO*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BIO_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslBIOChainTraits {
|
||||
using HandleType = BIO*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BIO_free_all(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslBNTraits {
|
||||
using HandleType = BIGNUM*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
BN_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
struct OpensslRSATraits {
|
||||
using HandleType = RSA*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
RSA_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "navicat-keygen", "navicat-keygen\navicat-keygen.vcxproj", "{CB49F054-83AB-4C16-B73B-33D7DF696E16}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "navicat-patcher", "navicat-patcher\navicat-patcher.vcxproj", "{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x64.Build.0 = Debug|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Debug|x86.Build.0 = Debug|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x64.ActiveCfg = Release|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x64.Build.0 = Release|x64
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x86.ActiveCfg = Release|Win32
|
||||
{CB49F054-83AB-4C16-B73B-33D7DF696E16}.Release|x86.Build.0 = Release|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x64.Build.0 = Debug|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x64.ActiveCfg = Release|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x64.Build.0 = Release|x64
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,66 +0,0 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <openssl/evp.h>
|
||||
#include "../common/Exception.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "../common/ResourceTraitsOpenssl.hpp"
|
||||
|
||||
std::string base64_encode(const std::vector<uint8_t>& bindata) {
|
||||
ResourceOwned b64(OpensslBIOTraits{}, BIO_new(BIO_f_base64()));
|
||||
if (b64.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
ResourceOwned mem(OpensslBIOTraits{}, BIO_new(BIO_s_mem()));
|
||||
if (mem.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_push(b64, mem);
|
||||
|
||||
if (BIO_write(b64, bindata.data(), bindata.size()) != bindata.size()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_write failed.");
|
||||
}
|
||||
|
||||
if (BIO_flush(b64) != 1) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_flush failed.");
|
||||
}
|
||||
|
||||
const char* data = nullptr;
|
||||
auto len = BIO_get_mem_data(mem, &data);
|
||||
|
||||
BIO_pop(b64);
|
||||
|
||||
return std::string(data, len);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> base64_decode(const std::string& ascdata) {
|
||||
ResourceOwned b64(OpensslBIOTraits{}, BIO_new(BIO_f_base64()));
|
||||
if (b64.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
ResourceOwned mem(OpensslBIOTraits{}, BIO_new_mem_buf(ascdata.c_str(), -1));
|
||||
if (mem.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "BIO_new failed.");
|
||||
}
|
||||
|
||||
BIO_push(b64, mem);
|
||||
|
||||
std::vector<uint8_t> bindata(ascdata.length() / 4 * 3 + 1);
|
||||
bindata.resize(BIO_read(b64, bindata.data(), bindata.size()));
|
||||
|
||||
BIO_pop(b64);
|
||||
|
||||
return bindata;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/des.h>
|
||||
#include <memory.h>
|
||||
|
||||
class DESCipher {
|
||||
private:
|
||||
DES_cblock _Key;
|
||||
DES_key_schedule _Schedule;
|
||||
public:
|
||||
|
||||
DESCipher() noexcept : _Key{}, _Schedule{} {}
|
||||
|
||||
void SetKey(const void* pKey) noexcept {
|
||||
memcpy(&_Key, pKey, sizeof(_Key));
|
||||
DES_set_odd_parity(&_Key);
|
||||
DES_set_key(&_Key, &_Schedule);
|
||||
}
|
||||
|
||||
void Clear() noexcept {
|
||||
OPENSSL_cleanse(&_Key, sizeof(_Key));
|
||||
OPENSSL_cleanse(&_Schedule, sizeof(_Schedule));
|
||||
}
|
||||
|
||||
void EncryptBlock(void* lpBuffer) noexcept {
|
||||
DES_cblock block;
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(lpBuffer), &block, &_Schedule, DES_ENCRYPT);
|
||||
memcpy(lpBuffer, &block, sizeof(block));
|
||||
}
|
||||
|
||||
void DecryptBlock(void* lpBuffer) noexcept {
|
||||
DES_cblock block;
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(lpBuffer), &block, &_Schedule, DES_DECRYPT);
|
||||
memcpy(lpBuffer, &block, sizeof(block));
|
||||
}
|
||||
|
||||
~DESCipher() noexcept {
|
||||
Clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,195 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include "DESCipher.hpp"
|
||||
|
||||
class NavicatKeygen {
|
||||
public:
|
||||
enum class Language {
|
||||
English,
|
||||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
Japanese,
|
||||
Polish,
|
||||
Spanish,
|
||||
French,
|
||||
German,
|
||||
Korean,
|
||||
Russian,
|
||||
Portuguese
|
||||
};
|
||||
|
||||
enum class Product {
|
||||
DataModeler,
|
||||
Premium,
|
||||
MySQL,
|
||||
PostgreSQL,
|
||||
Oracle,
|
||||
SQLServer,
|
||||
SQLite,
|
||||
MariaDB,
|
||||
MongoDB,
|
||||
ReportViewer
|
||||
};
|
||||
private:
|
||||
std::random_device rand_dev;
|
||||
std::default_random_engine rand_eng;
|
||||
std::uniform_int_distribution<int> rand;
|
||||
uint8_t data[10];
|
||||
public:
|
||||
|
||||
NavicatKeygen() : rand_eng(rand_dev()), rand(0, UINT8_MAX), data{} {
|
||||
data[0] = 0x68;
|
||||
data[1] = 0x2A;
|
||||
}
|
||||
|
||||
void SetLanguageSignature(Language _language) {
|
||||
switch (_language) {
|
||||
case Language::English:
|
||||
data[5] = 0xAC; // Must be 0xAC for English version.
|
||||
data[6] = 0x88; // Must be 0x88 for English version.
|
||||
break;
|
||||
case Language::SimplifiedChinese:
|
||||
data[5] = 0xCE; // Must be 0xCE for Simplified Chinese version.
|
||||
data[6] = 0x32; // Must be 0x32 for Simplified Chinese version.
|
||||
break;
|
||||
case Language::TraditionalChinese:
|
||||
data[5] = 0xAA; // Must be 0xAA for Traditional Chinese version.
|
||||
data[6] = 0x99; // Must be 0x99 for Traditional Chinese version.
|
||||
break;
|
||||
case Language::Japanese:
|
||||
data[5] = 0xAD; // Must be 0xAD for Japanese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x82; // Must be 0x82 for Japanese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Polish:
|
||||
data[5] = 0xBB; // Must be 0xBB for Polish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x55; // Must be 0x55 for Polish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Spanish:
|
||||
data[5] = 0xAE; // Must be 0xAE for Spanish version. Discoverer: @dragonflylee
|
||||
data[6] = 0x10; // Must be 0x10 for Spanish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::French:
|
||||
data[5] = 0xFA; // Must be 0xFA for French version. Discoverer: @Deltafox79
|
||||
data[6] = 0x20; // Must be 0x20 for French version. Discoverer: @Deltafox79
|
||||
break;
|
||||
case Language::German:
|
||||
data[5] = 0xB1; // Must be 0xB1 for German version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for German version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Korean:
|
||||
data[5] = 0xB5; // Must be 0xB5 for Korean version. Discoverer: @dragonflylee
|
||||
data[6] = 0x60; // Must be 0x60 for Korean version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Russian:
|
||||
data[5] = 0xEE; // Must be 0xB5 for Russian version. Discoverer: @dragonflylee
|
||||
data[6] = 0x16; // Must be 0x60 for Russian version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Language::Portuguese:
|
||||
data[5] = 0xCD; // Must be 0xCD for Portuguese version. Discoverer: @dragonflylee
|
||||
data[6] = 0x49; // Must be 0x49 for Portuguese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetLanguageSignature(uint8_t value0, uint8_t value1) {
|
||||
data[5] = value0;
|
||||
data[6] = value1;
|
||||
}
|
||||
|
||||
void SetProductSignature(Product _product) {
|
||||
switch (_product) {
|
||||
case Product::DataModeler:
|
||||
data[7] = 0x47;
|
||||
break;
|
||||
case Product::Premium:
|
||||
data[7] = 0x65;
|
||||
break;
|
||||
case Product::MySQL:
|
||||
data[7] = 0x68;
|
||||
break;
|
||||
case Product::PostgreSQL:
|
||||
data[7] = 0x6C;
|
||||
break;
|
||||
case Product::Oracle:
|
||||
data[7] = 0x70;
|
||||
break;
|
||||
case Product::SQLServer:
|
||||
data[7] = 0x74;
|
||||
break;
|
||||
case Product::SQLite:
|
||||
data[7] = 0x78;
|
||||
break;
|
||||
case Product::MariaDB:
|
||||
data[7] = 0x7C;
|
||||
break;
|
||||
case Product::MongoDB:
|
||||
data[7] = 0x80;
|
||||
break;
|
||||
case Product::ReportViewer:
|
||||
data[7] = 0xb;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetProductSignature(uint8_t value) {
|
||||
data[7] = value;
|
||||
}
|
||||
|
||||
void SetVersion(uint8_t version) {
|
||||
data[8] = version << 4;
|
||||
}
|
||||
|
||||
void Generate() {
|
||||
static uint8_t DESKey[] = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
DESCipher cipher;
|
||||
|
||||
data[2] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[3] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[4] = static_cast<uint8_t>(rand(rand_eng));
|
||||
data[9] = 0x32;
|
||||
|
||||
cipher.SetKey(&DESKey);
|
||||
cipher.EncryptBlock(data + 2);
|
||||
}
|
||||
|
||||
std::string GetKey() const {
|
||||
static const char EncodeTable[] = "ABCDEFGH8JKLMN9PQRSTUVWXYZ234567";
|
||||
std::string Key;
|
||||
|
||||
Key.resize(16);
|
||||
|
||||
Key[0] = EncodeTable[data[0] >> 3];
|
||||
Key[1] = EncodeTable[(data[0] & 0x07) << 2 | data[1] >> 6];
|
||||
Key[2] = EncodeTable[data[1] >> 1 & 0x1F];
|
||||
Key[3] = EncodeTable[(data[1] & 0x1) << 4 | data[2] >> 4];
|
||||
Key[4] = EncodeTable[(data[2] & 0xF) << 1 | data[3] >> 7];
|
||||
Key[5] = EncodeTable[data[3] >> 2 & 0x1F];
|
||||
Key[6] = EncodeTable[(data[3] << 3 & 0x1F) | data[4] >> 5];
|
||||
Key[7] = EncodeTable[data[4] & 0x1F];
|
||||
|
||||
Key[8] = EncodeTable[data[5] >> 3];
|
||||
Key[9] = EncodeTable[(data[5] & 0x07) << 2 | data[6] >> 6];
|
||||
Key[10] = EncodeTable[data[6] >> 1 & 0x1F];
|
||||
Key[11] = EncodeTable[(data[6] & 0x1) << 4 | data[7] >> 4];
|
||||
Key[12] = EncodeTable[(data[7] & 0xF) << 1 | data[8] >> 7];
|
||||
Key[13] = EncodeTable[data[8] >> 2 & 0x1F];
|
||||
Key[14] = EncodeTable[(data[8] << 3 & 0x1F) | data[9] >> 5];
|
||||
Key[15] = EncodeTable[data[9] & 0x1F];
|
||||
|
||||
return Key;
|
||||
}
|
||||
|
||||
std::string GetFormatedKey() const {
|
||||
std::string Key = GetKey();
|
||||
Key.insert(Key.begin() + 4, '-');
|
||||
Key.insert(Key.begin() + 5 + 4, '-');
|
||||
Key.insert(Key.begin() + 10 + 4, '-');
|
||||
return Key;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/des.h>
|
||||
|
||||
// OpenSSL precompiled lib, download from https://www.npcglib.org/~stathis/blog/precompiled-openssl/, MSVC2015 version
|
||||
// direct link https://www.npcglib.org/~stathis/downloads/openssl-1.1.0f-vs2015.7z
|
||||
// x86: "D:\openssl-1.1.0f-vs2015\include" has been add to include path. (modify it at project properties if necessary)
|
||||
// "D:\openssl-1.1.0f-vs2015\lib" has been add to library path. (modify it at project properties if necessary)
|
||||
// x64: "D:\openssl-1.1.0f-vs2015\include64" has been add to include path. (modify it at project properties if necessary)
|
||||
// "D:\openssl-1.1.0f-vs2015\lib64" has been add to library path. (modify it at project properties if necessary)
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libcryptoMTd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcryptoMT.lib")
|
||||
#endif
|
||||
#pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL lib
|
||||
#pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL lib
|
||||
|
||||
#define NAVICAT_12
|
||||
|
||||
enum NavicatLanguage {
|
||||
English,
|
||||
SimplifiedChinese,
|
||||
TraditionalChinese,
|
||||
Japanese,
|
||||
Polish,
|
||||
Spanish,
|
||||
French,
|
||||
German,
|
||||
Korean,
|
||||
Russian,
|
||||
Portuguese
|
||||
};
|
||||
|
||||
void GenerateSnKey(char(&SnKey)[16], NavicatLanguage _language) {
|
||||
static char EncodeTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
static DES_cblock DESKey = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||
|
||||
BYTE temp_SnKey[10] = { 0x68, 0x2a }; // must start with 0x68, 0x2a
|
||||
temp_SnKey[2] = rand();
|
||||
temp_SnKey[3] = rand();
|
||||
temp_SnKey[4] = rand();
|
||||
|
||||
switch (_language) {
|
||||
case English:
|
||||
temp_SnKey[5] = 0xAC; // Must be 0xAC for English version.
|
||||
temp_SnKey[6] = 0x88; // Must be 0x88 for English version.
|
||||
break;
|
||||
case SimplifiedChinese:
|
||||
temp_SnKey[5] = 0xCE; // Must be 0xCE for Simplified Chinese version.
|
||||
temp_SnKey[6] = 0x32; // Must be 0x32 for Simplified Chinese version.
|
||||
break;
|
||||
case TraditionalChinese:
|
||||
temp_SnKey[5] = 0xAA; // Must be 0xAA for Traditional Chinese version.
|
||||
temp_SnKey[6] = 0x99; // Must be 0x99 for Traditional Chinese version.
|
||||
break;
|
||||
case Japanese:
|
||||
temp_SnKey[5] = 0xAD; // Must be 0xAD for Japanese version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x82; // Must be 0x82 for Japanese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Polish:
|
||||
temp_SnKey[5] = 0xBB; // Must be 0xBB for Polish version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x55; // Must be 0x55 for Polish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Spanish:
|
||||
temp_SnKey[5] = 0xAE; // Must be 0xAE for Spanish version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x10; // Must be 0x10 for Spanish version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case French:
|
||||
temp_SnKey[5] = 0xFA; // Must be 0xFA for French version. Discoverer: @Deltafox79
|
||||
temp_SnKey[6] = 0x20; // Must be 0x20 for French version. Discoverer: @Deltafox79
|
||||
break;
|
||||
case German:
|
||||
temp_SnKey[5] = 0xB1; // Must be 0xB1 for German version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x60; // Must be 0x60 for German version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Korean:
|
||||
temp_SnKey[5] = 0xB5; // Must be 0xB5 for Korean version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x60; // Must be 0x60 for Korean version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Russian:
|
||||
temp_SnKey[5] = 0xEE; // Must be 0xB5 for Russian version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x16; // Must be 0x60 for Russian version. Discoverer: @dragonflylee
|
||||
break;
|
||||
case Portuguese:
|
||||
temp_SnKey[5] = 0xCD; // Must be 0xCD for Portuguese version. Discoverer: @dragonflylee
|
||||
temp_SnKey[6] = 0x49; // Must be 0x49 for Portuguese version. Discoverer: @dragonflylee
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(NAVICAT_12)
|
||||
temp_SnKey[7] = 0x65; // 0x65 - commercial, 0x66 - non-commercial
|
||||
temp_SnKey[8] = 0xC0; // High 4-bits = version number. Low 4-bits doesn't know, but can be used to delay activation time.
|
||||
#elif defined(NAVICAT_11)
|
||||
temp_SnKey[7] = 0x15; // 0x15 - commercial, 0x16 - non-commercial
|
||||
temp_SnKey[8] = 0xB0; // High 4-bits = version number. Low 4-bits doesn't know, but can be used to delay activation time.
|
||||
#else
|
||||
#error "Navicat version is not specified."
|
||||
#endif
|
||||
temp_SnKey[9] = 0x32; // 0xFB is Not-For-Resale-30-days license.
|
||||
// 0xFC is Not-For-Resale-90-days license.
|
||||
// 0xFD is Not-For-Resale-365-days license.
|
||||
// 0xFE is Not-For-Resale license.
|
||||
// 0xFF is Site license.
|
||||
// Must not be 0x00. 0x01-0xFA is ok.
|
||||
|
||||
DES_key_schedule schedule;
|
||||
DES_set_key_unchecked(&DESKey, &schedule);
|
||||
DES_cblock enc_temp_snKey;
|
||||
|
||||
DES_ecb_encrypt(reinterpret_cast<const_DES_cblock*>(temp_SnKey + 2), &enc_temp_snKey, &schedule, DES_ENCRYPT);
|
||||
memmove_s(temp_SnKey + 2, sizeof(enc_temp_snKey), enc_temp_snKey, sizeof(enc_temp_snKey));
|
||||
|
||||
SnKey[0] = EncodeTable[temp_SnKey[0] >> 3];
|
||||
SnKey[1] = EncodeTable[(temp_SnKey[0] & 0x07) << 2 | temp_SnKey[1] >> 6];
|
||||
SnKey[2] = EncodeTable[temp_SnKey[1] >> 1 & 0x1F];
|
||||
SnKey[3] = EncodeTable[(temp_SnKey[1] & 0x1) << 4 | temp_SnKey[2] >> 4];
|
||||
SnKey[4] = EncodeTable[(temp_SnKey[2] & 0xF) << 1 | temp_SnKey[3] >> 7];
|
||||
SnKey[5] = EncodeTable[temp_SnKey[3] >> 2 & 0x1F];
|
||||
SnKey[6] = EncodeTable[temp_SnKey[3] << 3 & 0x1F | temp_SnKey[4] >> 5];
|
||||
SnKey[7] = EncodeTable[temp_SnKey[4] & 0x1F];
|
||||
|
||||
SnKey[8] = EncodeTable[temp_SnKey[5] >> 3];
|
||||
SnKey[9] = EncodeTable[(temp_SnKey[5] & 0x07) << 2 | temp_SnKey[6] >> 6];
|
||||
SnKey[10] = EncodeTable[temp_SnKey[6] >> 1 & 0x1F];
|
||||
SnKey[11] = EncodeTable[(temp_SnKey[6] & 0x1) << 4 | temp_SnKey[7] >> 4];
|
||||
SnKey[12] = EncodeTable[(temp_SnKey[7] & 0xF) << 1 | temp_SnKey[8] >> 7];
|
||||
SnKey[13] = EncodeTable[temp_SnKey[8] >> 2 & 0x1F];
|
||||
SnKey[14] = EncodeTable[temp_SnKey[8] << 3 & 0x1F | temp_SnKey[9] >> 5];
|
||||
SnKey[15] = EncodeTable[temp_SnKey[9] & 0x1F];
|
||||
|
||||
_tprintf_s(TEXT("\r\n"));
|
||||
_tprintf_s(TEXT("SnKey:\r\n"));
|
||||
_tprintf_s(TEXT("%.4hs-%.4hs-%.4hs-%.4hs\r\n"), SnKey, SnKey + 4, SnKey + 8, SnKey + 12);
|
||||
_tprintf_s(TEXT("\r\n"));
|
||||
}
|
||||
|
||||
BOOL GenerateLicense(RSA* RSAPrivateKey,
|
||||
const char* SnKey,
|
||||
const char* Name,
|
||||
const char* Organization,
|
||||
const char* DeviceIdentifier) {
|
||||
|
||||
char LicenseJson[2048 / 8] = { };
|
||||
#if defined(NAVICAT_12)
|
||||
sprintf_s(LicenseJson, "{\"K\":\"%.16s\", \"N\":\"%s\", \"O\":\"%s\", \"DI\":\"%s\"}", SnKey, Name, Organization, DeviceIdentifier);
|
||||
#elif defined(NAVICAT_11)
|
||||
sprintf_s(LicenseJson, "{\"K\":\"%.16s\", \"N\":\"%s\", \"O\":\"%s\"}", SnKey, Name, Organization);
|
||||
#else
|
||||
#error "Navicat version is not specified."
|
||||
#endif
|
||||
unsigned char EncryptedLicenseData[2048 / 8] = { };
|
||||
if (RSA_private_encrypt(static_cast<int>(strlen(LicenseJson)),
|
||||
reinterpret_cast<uint8_t*>(LicenseJson),
|
||||
EncryptedLicenseData,
|
||||
RSAPrivateKey,
|
||||
RSA_PKCS1_PADDING) == -1) {
|
||||
_tprintf_s(TEXT("Failed to encrypt license data.\r\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if defined(NAVICAT_12)
|
||||
DWORD LicenseStringLength = 1024;
|
||||
TCHAR LicenseString[1024] = { };
|
||||
if (!CryptBinaryToString(EncryptedLicenseData, sizeof(EncryptedLicenseData), CRYPT_STRING_BASE64, LicenseString, &LicenseStringLength)) {
|
||||
_tprintf_s(TEXT("Cannot get Base64 string. CODE: 0x%08x\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("License:\r\n%s"), LicenseString);
|
||||
return TRUE;
|
||||
#elif defined(NAVICAT_11)
|
||||
HANDLE hLicenseFile = CreateFile(TEXT("license_file"), GENERIC_ALL, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (hLicenseFile == NULL) {
|
||||
_tprintf_s(TEXT("Failed to create \"license_file\".\r\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!WriteFile(hLicenseFile, EncryptedLicenseData, sizeof(EncryptedLicenseData), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write \"license_file\".\r\n"));
|
||||
CloseHandle(hLicenseFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CloseHandle(hLicenseFile);
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
RSA* ReadRSAPrivateKeyFromFile(LPCTSTR filename) {
|
||||
#ifdef UNICODE
|
||||
int req_size = WideCharToMultiByte(CP_ACP, 0, filename, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (req_size == 0) {
|
||||
_tprintf_s(TEXT("Failed to convert wchar* to char*. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> WideCharToMultiByte]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char* temp_filename = new char[req_size]();
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, temp_filename, req_size, nullptr, nullptr);
|
||||
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_read_filename(b, temp_filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_read_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
delete[] temp_filename;
|
||||
#else
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_read_filename(b, filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_read_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
RSA* ret = PEM_read_bio_RSAPrivateKey(b, nullptr, nullptr, nullptr);
|
||||
if (ret == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to read RSA private key. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> PEM_read_bio_RSAPrivateKey]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return nullptr;
|
||||
} else {
|
||||
BIO_free_all(b);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
int _tmain(int argc, TCHAR* argv[]) {
|
||||
if (argc != 2) {
|
||||
_tprintf_s(TEXT("Usage:\r\n"));
|
||||
_tprintf_s(TEXT(" navicat-keygen.exe <RSA-2048 PrivateKey(PEM file)>\r\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
|
||||
RSA* PrivateKey = ReadRSAPrivateKeyFromFile(argv[1]);
|
||||
if (PrivateKey == nullptr)
|
||||
return 0;
|
||||
|
||||
std::cout
|
||||
<< "Which is your Navicat language?" << std::endl
|
||||
<< "0. English" << std::endl
|
||||
<< "1. Simplified Chinese" << std::endl
|
||||
<< "2. Traditional Chinese" << std::endl
|
||||
<< "3. Japanese" << std::endl
|
||||
<< "4. Polish" << std::endl
|
||||
<< "5. Spanish" << std::endl
|
||||
<< "6. French" << std::endl
|
||||
<< "7. German" << std::endl
|
||||
<< "8. Korean" << std::endl
|
||||
<< "9. Russian" << std::endl
|
||||
<< "10. Portuguese" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
int LanguageIndex = -1;
|
||||
while (true) {
|
||||
std::cout << "(input index)>";
|
||||
|
||||
std::string temp;
|
||||
if (!std::getline(std::cin, temp)) {
|
||||
RSA_free(PrivateKey);
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
LanguageIndex = std::stoi(temp);
|
||||
if (LanguageIndex < 0 || LanguageIndex > 10)
|
||||
throw std::invalid_argument("Invalid index");
|
||||
break;
|
||||
} catch (...) {
|
||||
std::cout << "Invalid index." << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
char SnKey[16] = { };
|
||||
GenerateSnKey(SnKey, static_cast<NavicatLanguage>(LanguageIndex));
|
||||
|
||||
std::string strName;
|
||||
std::string strOrganization;
|
||||
_tprintf_s(TEXT("Your name: "));
|
||||
std::getline(std::cin, strName);
|
||||
_tprintf_s(TEXT("Your organization: "));
|
||||
std::getline(std::cin, strOrganization);
|
||||
|
||||
#if defined(NAVICAT_12)
|
||||
std::string RequestCode;
|
||||
_tprintf_s(TEXT("Input request code (in Base64), empty line to return:\r\n"));
|
||||
while (true) {
|
||||
std::string temp;
|
||||
std::getline(std::cin, temp);
|
||||
if (temp.empty())
|
||||
break;
|
||||
|
||||
RequestCode += temp;
|
||||
}
|
||||
|
||||
BYTE EncryptedRequestData[1024] = { };
|
||||
DWORD EncryptedRequestDataLength = sizeof(EncryptedRequestData);
|
||||
if (!CryptStringToBinaryA(RequestCode.c_str(), NULL, CRYPT_STRING_BASE64, EncryptedRequestData, &EncryptedRequestDataLength, NULL, NULL)) {
|
||||
_tprintf_s(TEXT("Failed to decode Base64 string. CODE: 0x%08x\r\n"), GetLastError());
|
||||
RSA_free(PrivateKey);
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
char RequestData[1024] = { };
|
||||
if (RSA_private_decrypt(EncryptedRequestDataLength,
|
||||
EncryptedRequestData,
|
||||
reinterpret_cast<BYTE*>(RequestData),
|
||||
PrivateKey, RSA_PKCS1_PADDING) == -1) {
|
||||
_tprintf_s(TEXT("Failed to decrypt request code.\r\n"));
|
||||
RSA_free(PrivateKey);
|
||||
return -2;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
std::cout << "-----------Begin Request Code Data---------------" << std::endl;
|
||||
std::cout << RequestData << std::endl;
|
||||
std::cout << "-----------End Request Code Data---------------" << std::endl;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
std::string strDeviceIdentifier;
|
||||
for (int i = 0, length = static_cast<int>(strlen(RequestData)) - 4; i < length; ++i) {
|
||||
if (RequestData[i] == '"' &&
|
||||
RequestData[i + 1] == 'D' &&
|
||||
RequestData[i + 2] == 'I' &&
|
||||
RequestData[i + 3] == '"') {
|
||||
|
||||
char temp[256] = { };
|
||||
int x = i + 4, j = 0;
|
||||
while (RequestData[x] != '"' && x < length)
|
||||
x++;
|
||||
x++;
|
||||
while (RequestData[x] != '"' && j < 256) {
|
||||
temp[j++] = RequestData[x];
|
||||
x++;
|
||||
}
|
||||
strDeviceIdentifier += temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strDeviceIdentifier.empty()) {
|
||||
_tprintf_s(TEXT("Not a valid request code.\r\n"));
|
||||
RSA_free(PrivateKey);
|
||||
return -3;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
GenerateLicense(PrivateKey, SnKey, strName.c_str(), strOrganization.c_str(), strDeviceIdentifier.c_str());
|
||||
#elif defined(NAVICAT_11)
|
||||
GenerateLicense(PrivateKey, SnKey, strName.c_str(), strOrganization.c_str(), nullptr);
|
||||
#else
|
||||
#error "Navicat version is not specified."
|
||||
#endif
|
||||
|
||||
RSA_free(PrivateKey);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "../common/RSACipher.hpp"
|
||||
#include "NavicatKeygen.hpp"
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
|
||||
template<int min_num, int max_num>
|
||||
bool read_int(int& num, const char* prompt, const char* err_msg) {
|
||||
int temp;
|
||||
std::string input;
|
||||
|
||||
while (true) {
|
||||
std::cout << prompt;
|
||||
if (!std::getline(std::cin, input))
|
||||
return false;
|
||||
|
||||
try {
|
||||
temp = std::stoi(input, nullptr, 0);
|
||||
if (min_num <= temp && temp <= max_num) {
|
||||
num = temp;
|
||||
return true;
|
||||
} else {
|
||||
throw std::invalid_argument(err_msg);
|
||||
}
|
||||
} catch (...) {
|
||||
std::cout << err_msg << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string base64_encode(const std::vector<uint8_t>& bindata);
|
||||
std::vector<uint8_t> base64_decode(const std::string& ascdata);
|
||||
|
||||
void Help() {
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << "* Navicat Keygen by @DoubleLabyrinth *" << std::endl;
|
||||
std::cout << "* Version: 4.0 *" << std::endl;
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Usage:" << std::endl;
|
||||
std::cout << " navicat-keygen <RSA-2048 Private Key File>" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " <RSA-2048 Private Key File> Path to a PEM-format RSA-2048 private key file." << std::endl;
|
||||
std::cout << " This parameter must be specified." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
Help();
|
||||
return -1;
|
||||
} else {
|
||||
try {
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << "* Navicat Keygen by @DoubleLabyrinth *" << std::endl;
|
||||
std::cout << "* Version: 4.0 *" << std::endl;
|
||||
std::cout << "***************************************************" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
RSACipher RsaCipher;
|
||||
|
||||
int select_num;
|
||||
|
||||
NavicatKeygen keygen;
|
||||
std::string username;
|
||||
std::string organization;
|
||||
|
||||
std::string RequestCode_b64;
|
||||
std::vector<uint8_t> RequestCode;
|
||||
char RequestInfo[256] = {};
|
||||
char ResponseInfo[256] = {};
|
||||
std::vector<uint8_t> ResponseCode;
|
||||
std::string ResponseCode_b64;
|
||||
|
||||
rapidjson::Document json;
|
||||
rapidjson::Value N_Key;
|
||||
rapidjson::Value N_Value;
|
||||
rapidjson::Value O_Key;
|
||||
rapidjson::Value O_Value;
|
||||
rapidjson::Value T_Key;
|
||||
rapidjson::Value T_Value;
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
RsaCipher.ImportKeyFromFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>(argv[1]);
|
||||
if (RsaCipher.Bits() != 2048) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not RSA-2048 private key file.");
|
||||
}
|
||||
|
||||
keygen.SetProductSignature(NavicatKeygen::Product::Premium);
|
||||
|
||||
std::cout
|
||||
<< "Which is your Navicat Premium language?" << std::endl
|
||||
<< "0. English" << std::endl
|
||||
<< "1. Simplified Chinese" << std::endl
|
||||
<< "2. Traditional Chinese" << std::endl
|
||||
<< "3. Japanese" << std::endl
|
||||
<< "4. Polish" << std::endl
|
||||
<< "5. Spanish" << std::endl
|
||||
<< "6. French" << std::endl
|
||||
<< "7. German" << std::endl
|
||||
<< "8. Korean" << std::endl
|
||||
<< "9. Russian" << std::endl
|
||||
<< "10. Portuguese" << std::endl
|
||||
<< std::endl;
|
||||
if (read_int<0, 10>(select_num, "(Input index)> ", "Invalid index.")) {
|
||||
keygen.SetLanguageSignature(static_cast<NavicatKeygen::Language>(select_num));
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
if (read_int<0, 15>(select_num, "(Input major version number, range: 0 ~ 15, default: 12)> ", "Invalid number.")) {
|
||||
keygen.SetVersion(static_cast<uint8_t>(select_num));
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate snKey
|
||||
//
|
||||
keygen.Generate();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Serial number:" << std::endl;
|
||||
std::cout << keygen.GetFormatedKey() << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Get user name
|
||||
//
|
||||
std::cout << "Your name: ";
|
||||
if (!std::getline(std::cin, username)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Get organization name
|
||||
//
|
||||
std::cout << "Your organization: ";
|
||||
if (!std::getline(std::cin, organization)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Get request code in base64
|
||||
//
|
||||
std::cout << "Input request code (in Base64), input empty line to end:" << std::endl;
|
||||
while (true) {
|
||||
std::string temp;
|
||||
if (!std::getline(std::cin, temp))
|
||||
return 0;
|
||||
|
||||
if (temp.empty())
|
||||
break;
|
||||
|
||||
RequestCode_b64 += temp;
|
||||
}
|
||||
|
||||
//
|
||||
// Get request code in raw bytes
|
||||
//
|
||||
RequestCode = base64_decode(RequestCode_b64);
|
||||
if (RequestCode.size() > ((RsaCipher.Bits() + 7) / 8)) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Request code is too long.");
|
||||
}
|
||||
|
||||
//
|
||||
// Decrypt to get request info
|
||||
//
|
||||
RsaCipher.Decrypt(RequestCode.data(), static_cast<int>(RequestCode.size()), RequestInfo, RSA_PKCS1_PADDING);
|
||||
|
||||
//
|
||||
// print out request info
|
||||
//
|
||||
std::cout << "Request Info:" << std::endl;
|
||||
std::cout << RequestInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// Generate response info
|
||||
//
|
||||
json.Parse(RequestInfo);
|
||||
json.RemoveMember("P"); // remove Platform info
|
||||
|
||||
N_Key.SetString("N", 1);
|
||||
N_Value.SetString(username.c_str(), static_cast<rapidjson::SizeType>(username.length()));
|
||||
O_Key.SetString("O", 1);
|
||||
O_Value.SetString(organization.c_str(), static_cast<rapidjson::SizeType>(organization.length()));
|
||||
T_Key.SetString("T", 1);
|
||||
T_Value.SetUint(static_cast<unsigned>(std::time(nullptr)));
|
||||
|
||||
json.AddMember(N_Key, N_Value, json.GetAllocator());
|
||||
json.AddMember(O_Key, O_Value, json.GetAllocator());
|
||||
json.AddMember(T_Key, T_Value, json.GetAllocator());
|
||||
|
||||
json.Accept(writer);
|
||||
|
||||
if (buffer.GetSize() > 240) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Response info is too long.");
|
||||
}
|
||||
|
||||
//
|
||||
// print out response info
|
||||
//
|
||||
memcpy(ResponseInfo, buffer.GetString(), buffer.GetSize());
|
||||
std::cout << "Response Info:" << std::endl;
|
||||
std::cout << ResponseInfo << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
//
|
||||
// encrypt response info
|
||||
//
|
||||
ResponseCode.resize((RsaCipher.Bits() + 7) / 8);
|
||||
RsaCipher.Encrypt<RSAKeyType::PrivateKey>(ResponseInfo, static_cast<int>(strlen(ResponseInfo)), ResponseCode.data(), RSA_PKCS1_PADDING);
|
||||
|
||||
//
|
||||
// encode encrypted response info in base64 format
|
||||
//
|
||||
ResponseCode_b64 = base64_encode(ResponseCode);
|
||||
|
||||
//
|
||||
// print out activation code
|
||||
//
|
||||
std::cout << "License:" << std::endl;
|
||||
std::cout << ResponseCode_b64 << std::endl;
|
||||
|
||||
return 0;
|
||||
} catch (nkg::Exception& e) {
|
||||
std::cout << "[-] " << e.File() << ":" << e.Line() << " ->" << std::endl;
|
||||
std::cout << " " << e.Message() << std::endl;
|
||||
if (e.HasErrorCode()) {
|
||||
std::cout << " " << e.ErrorString() << std::endl;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{CB49F054-83AB-4C16-B73B-33D7DF696E16}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>navicatkeygen</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="_tmain.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="_tmain.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,76 +0,0 @@
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
|
||||
CapstoneDisassembler CapstoneDisassembler::Create(cs_arch ArchType, cs_mode Mode) {
|
||||
CapstoneDisassembler NewDisassembler;
|
||||
|
||||
auto err = cs_open(ArchType, Mode, NewDisassembler.pvt_Handle.GetAddress());
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "cs_open failed.");
|
||||
}
|
||||
|
||||
NewDisassembler.pvt_Insn.TakeOver(cs_malloc(NewDisassembler.pvt_Handle));
|
||||
if (NewDisassembler.pvt_Insn.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, cs_errno(NewDisassembler.pvt_Handle), "cs_malloc failed.");
|
||||
}
|
||||
|
||||
return NewDisassembler;
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::Option(cs_opt_type Type, size_t Value) {
|
||||
auto err = cs_option(pvt_Handle, Type, Value);
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "cs_option failed.");
|
||||
}
|
||||
|
||||
pvt_CurrentInsn = nullptr;
|
||||
|
||||
pvt_Insn.TakeOver(cs_malloc(pvt_Handle));
|
||||
if (pvt_Insn.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, cs_errno(pvt_Handle), "cs_malloc failed.");
|
||||
}
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::SetContext(uintptr_t lpOpcode, size_t cbOpcode, uint64_t Address) noexcept {
|
||||
pvt_CurrentCtx.pbOpcode = reinterpret_cast<const uint8_t*>(lpOpcode);
|
||||
pvt_CurrentCtx.cbOpcode = cbOpcode;
|
||||
pvt_CurrentCtx.Address = Address;
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
|
||||
void CapstoneDisassembler::SetContext(const void* lpOpcode, size_t cbOpcode, uint64_t Address) noexcept {
|
||||
pvt_CurrentCtx.pbOpcode = reinterpret_cast<const uint8_t*>(lpOpcode);
|
||||
pvt_CurrentCtx.cbOpcode = cbOpcode;
|
||||
pvt_CurrentCtx.Address = Address;
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
|
||||
const CapstoneDisassembler::Context& CapstoneDisassembler::GetContext() const noexcept {
|
||||
return pvt_CurrentCtx;
|
||||
}
|
||||
|
||||
const cs_insn* CapstoneDisassembler::GetInstruction() const noexcept {
|
||||
return pvt_CurrentInsn;
|
||||
}
|
||||
|
||||
CapstoneDisassembler::Context CapstoneDisassembler::GetInstructionContext() const noexcept {
|
||||
Context CtxOfInsn = {};
|
||||
CtxOfInsn.pbOpcode = pvt_CurrentCtx.pbOpcode - pvt_CurrentInsn->size;
|
||||
CtxOfInsn.cbOpcode = pvt_CurrentCtx.cbOpcode + pvt_CurrentInsn->size;
|
||||
CtxOfInsn.Address = pvt_CurrentCtx.Address - pvt_CurrentInsn->size;
|
||||
return CtxOfInsn;
|
||||
}
|
||||
|
||||
bool CapstoneDisassembler::Next() noexcept {
|
||||
bool bSucceed = cs_disasm_iter(pvt_Handle, &pvt_CurrentCtx.pbOpcode, &pvt_CurrentCtx.cbOpcode, &pvt_CurrentCtx.Address, pvt_Insn);
|
||||
if (bSucceed) {
|
||||
if (pvt_CurrentInsn == nullptr) pvt_CurrentInsn = pvt_Insn.Get();
|
||||
} else {
|
||||
pvt_CurrentInsn = nullptr;
|
||||
}
|
||||
return bSucceed;
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#include <capstone/capstone.h>
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsCapstone.hpp"
|
||||
|
||||
class CapstoneDisassembler {
|
||||
public:
|
||||
|
||||
struct Context {
|
||||
const uint8_t* pbOpcode;
|
||||
size_t cbOpcode;
|
||||
uint64_t Address;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
ResourceOwned<CapstoneHandleTraits> pvt_Handle;
|
||||
ResourceOwned<CapstoneInsnTraits> pvt_Insn;
|
||||
Context pvt_CurrentCtx;
|
||||
cs_insn* pvt_CurrentInsn;
|
||||
|
||||
CapstoneDisassembler() noexcept :
|
||||
pvt_Handle(CapstoneHandleTraits{}),
|
||||
pvt_Insn(CapstoneInsnTraits{}),
|
||||
pvt_CurrentCtx{},
|
||||
pvt_CurrentInsn(nullptr) {}
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static CapstoneDisassembler Create(cs_arch ArchType, cs_mode Mode);
|
||||
|
||||
void Option(cs_opt_type Type, size_t Value);
|
||||
|
||||
void SetContext(uintptr_t lpOpcode, size_t cbOpcode, uint64_t Address = 0) noexcept ;
|
||||
|
||||
void SetContext(const void* lpOpcode, size_t cbOpcode, uint64_t Address = 0) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const Context& GetContext() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const cs_insn* GetInstruction() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Context GetInstructionContext() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool Next() noexcept;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// to avoid "AES_KEY" definaition conflict
|
||||
#include "NavicatCrypto/NavicatCrypto.hpp"
|
||||
|
||||
namespace patcher {
|
||||
|
||||
std::string EncryptPublicKey(const char* public_key, size_t len) {
|
||||
Navicat11Crypto cipher("23970790", 8);
|
||||
auto&& temp = cipher.EncryptString(public_key, len);
|
||||
return std::string(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include <capstone/capstone.h>
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class CapstoneError final : public Exception {
|
||||
private:
|
||||
|
||||
cs_err pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
CapstoneError(const char* File, unsigned Line, cs_err ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return cs_strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include <keystone/keystone.h>
|
||||
|
||||
namespace nkg {
|
||||
|
||||
class KeystoneError final : public Exception {
|
||||
private:
|
||||
|
||||
ks_err pvt_ErrorCode;
|
||||
|
||||
public:
|
||||
|
||||
KeystoneError(const char* File, unsigned Line, ks_err ErrorCode, const char* Message) noexcept :
|
||||
Exception(File, Line, Message),
|
||||
pvt_ErrorCode(ErrorCode) {}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool HasErrorCode() const noexcept override {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual intptr_t ErrorCode() const noexcept override {
|
||||
return pvt_ErrorCode;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual const char* ErrorString() const noexcept override {
|
||||
return ks_strerror(pvt_ErrorCode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
#include <string.h> // NOLINT
|
||||
#include "ExceptionCapstone.hpp"
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
|
||||
namespace nkg {
|
||||
|
||||
bool IsResolvedTo(const X64ImageInterpreter& Image, const void* StubHelperProc, const char *Symbol) {
|
||||
CapstoneDisassembler Disassembler = CapstoneDisassembler::Create(CS_ARCH_X86, CS_MODE_64);
|
||||
|
||||
Disassembler.Option(CS_OPT_DETAIL, CS_OPT_ON);
|
||||
|
||||
// A stub-helper proc must look like:
|
||||
// push xxxxh;
|
||||
// jmp loc_xxxxxxxx
|
||||
// which should be 10 bytes long.
|
||||
Disassembler.SetContext(StubHelperProc, 10);
|
||||
|
||||
if (Disassembler.Next() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto insn = Disassembler.GetInstruction();
|
||||
if (strcasecmp(insn->mnemonic, "push") != 0 || insn->detail->x86.operands[0].type != X86_OP_IMM) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bind_opcode_offset = static_cast<uint32_t>(insn->detail->x86.operands[0].imm);
|
||||
if (Image.CommandOf<LC_DYLD_INFO_ONLY>() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bind_opcode_ptr =
|
||||
Image.ImageOffset<uint8_t*>(Image.CommandOf<LC_DYLD_INFO_ONLY>()->lazy_bind_off) +
|
||||
bind_opcode_offset;
|
||||
|
||||
while ((*bind_opcode_ptr & BIND_OPCODE_MASK) != BIND_OPCODE_DONE) {
|
||||
switch (*bind_opcode_ptr & BIND_OPCODE_MASK) {
|
||||
case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: // 0x10
|
||||
case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: // 0x30
|
||||
case BIND_OPCODE_SET_TYPE_IMM: // 0x50
|
||||
case BIND_OPCODE_DO_BIND: // 0x90
|
||||
case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: // 0xB0
|
||||
++bind_opcode_ptr;
|
||||
break;
|
||||
case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: // 0x20
|
||||
case BIND_OPCODE_SET_ADDEND_SLEB: // 0x60
|
||||
case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: // 0x70
|
||||
case BIND_OPCODE_ADD_ADDR_ULEB: // 0x80
|
||||
case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: // 0xA0
|
||||
while (*(++bind_opcode_ptr) & 0x80u);
|
||||
++bind_opcode_ptr;
|
||||
break;
|
||||
case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: // 0x40
|
||||
return strcmp(reinterpret_cast<const char *>(bind_opcode_ptr + 1), Symbol) == 0;
|
||||
case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: // 0xC0
|
||||
//
|
||||
// This opcode is too rare to appear,
|
||||
// It is okay to dismiss this opcode
|
||||
//
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#include <stddef.h> // NOLINT
|
||||
#include <stdint.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <signal.h> // NOLINT
|
||||
#include <setjmp.h> // NOLINT
|
||||
|
||||
static jmp_buf env;
|
||||
|
||||
static void SIGSEGV_Handler(int sig) {
|
||||
siglongjmp(env, 1);
|
||||
}
|
||||
|
||||
//
|
||||
// read byte(s) at address `p` as __Type to `out`
|
||||
// succeed if return true, otherwise return false
|
||||
//
|
||||
template<typename __Type>
|
||||
static inline bool ProbeForRead(const void* p, void* out) {
|
||||
int r = sigsetjmp(env, 1);
|
||||
if (r == 0) {
|
||||
*reinterpret_cast<__Type*>(out) = *reinterpret_cast<const __Type*>(p);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
namespace nkg {
|
||||
|
||||
void PrintMemory(const void *from, const void *to, const void *base) {
|
||||
auto start = reinterpret_cast<const uint8_t *>(from);
|
||||
auto end = reinterpret_cast<const uint8_t *>(to);
|
||||
auto base_ptr = reinterpret_cast<const uint8_t *>(base);
|
||||
|
||||
if (start >= end)
|
||||
return;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(start) % 16)
|
||||
start--;
|
||||
|
||||
while (reinterpret_cast<uintptr_t>(end) % 16)
|
||||
end++;
|
||||
|
||||
void (*prev_handler)(int) = signal(SIGSEGV, SIGSEGV_Handler);
|
||||
while (start < end) {
|
||||
uint16_t value[16] = {};
|
||||
|
||||
if (base_ptr) {
|
||||
uintptr_t d = start >= base ? start - base_ptr : base_ptr - start;
|
||||
if (start >= base) {
|
||||
printf("+0x%.*zx ", static_cast<int>(2 * sizeof(void *)), d);
|
||||
} else {
|
||||
printf("-0x%.*zx ", static_cast<int>(2 * sizeof(void *)), d);
|
||||
}
|
||||
} else {
|
||||
printf("0x%.*zx ", static_cast<int>(2 * sizeof(void *)), reinterpret_cast<uintptr_t >(start));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (start + i < from) {
|
||||
printf(" ");
|
||||
value[i] = 0xfffe;
|
||||
} else if (ProbeForRead<uint8_t>(start + i, value + i)) {
|
||||
printf("%02x ", value[i]);
|
||||
} else {
|
||||
printf("?? ");
|
||||
value[i] = 0xffff;
|
||||
}
|
||||
}
|
||||
|
||||
printf(" ");
|
||||
|
||||
for (int i = 0; i < 16; ++i) { // NOLINT
|
||||
if (0x20 <= value[i] && value[i] < 0x7f) {
|
||||
printf("%c", value[i]);
|
||||
} else if (value[i] == 0xfffe) {
|
||||
printf(" ");
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
start += 0x10;
|
||||
}
|
||||
signal(SIGSEGV, prev_handler);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#include "KeystoneAssembler.hpp"
|
||||
|
||||
[[nodiscard]]
|
||||
KeystoneAssembler KeystoneAssembler::Create(ks_arch ArchType, ks_mode Mode) {
|
||||
KeystoneAssembler NewAssembler;
|
||||
|
||||
auto err = ks_open(ArchType, Mode, NewAssembler.pvt_Engine.GetAddress());
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_open failed.");
|
||||
}
|
||||
|
||||
return NewAssembler;
|
||||
}
|
||||
|
||||
void KeystoneAssembler::Option(ks_opt_type Type, size_t Value) {
|
||||
auto err = ks_option(pvt_Engine, Type, Value);
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_open failed.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> KeystoneAssembler::GenerateOpcode(const char *AssemblyCode, uint64_t Address) const {
|
||||
ResourceOwned pbOpcode(KeystoneMallocTraits{});
|
||||
size_t cbOpCode = 0;
|
||||
size_t InstructionsProcessed = 0;
|
||||
|
||||
if (ks_asm(pvt_Engine, AssemblyCode, Address, pbOpcode.GetAddress(), &cbOpCode, &InstructionsProcessed) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, ks_errno(pvt_Engine), "ks_asm failed.");
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(pbOpcode.Get(), pbOpcode.Get() + cbOpCode);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> KeystoneAssembler::GenerateOpcode(const std::string& AssemblyCode, uint64_t Address) const {
|
||||
ResourceOwned pbOpcode(KeystoneMallocTraits{});
|
||||
size_t cbOpCode = 0;
|
||||
size_t InstructionsProcessed = 0;
|
||||
|
||||
if (ks_asm(pvt_Engine, AssemblyCode.c_str(), Address, pbOpcode.GetAddress(), &cbOpCode, &InstructionsProcessed) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, ks_errno(pvt_Engine), "ks_asm failed.");
|
||||
}
|
||||
|
||||
return std::vector<uint8_t>(pbOpcode.Get(), pbOpcode.Get() + cbOpCode);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsKeystone.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class KeystoneAssembler {
|
||||
private:
|
||||
|
||||
ResourceOwned<KeystoneHandleTraits> pvt_Engine;
|
||||
|
||||
KeystoneAssembler() noexcept :
|
||||
pvt_Engine(KeystoneHandleTraits{}) {}
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static KeystoneAssembler Create(ks_arch ArchType, ks_mode Mode);
|
||||
|
||||
void Option(ks_opt_type Type, size_t Value);
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> GenerateOpcode(const char* AssemblyCode, uint64_t Address = 0) const;
|
||||
|
||||
[[nodiscard]]
|
||||
std::vector<uint8_t> GenerateOpcode(const std::string& AssemblyCode, uint64_t Address = 0) const;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
#pragma once
|
||||
#include "aes.h"
|
||||
#include "blowfish.h"
|
||||
#include "SHA1.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Navicat11Crypto {
|
||||
protected:
|
||||
BLOWFISH_KEY BlowfishKey;
|
||||
|
||||
void BytesToHex(const void* src, size_t len, char* dst) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
char h = reinterpret_cast<const uint8_t*>(src)[i] >> 4;
|
||||
char l = reinterpret_cast<const uint8_t*>(src)[i] & 0x0F;
|
||||
|
||||
h += h >= 10 ? 'A' - 10 : '0';
|
||||
l += l >= 10 ? 'A' - 10 : '0';
|
||||
dst[2 * i] = h;
|
||||
dst[2 * i + 1] = l;
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckHex(const char* src, size_t len) {
|
||||
if (len % 2 != 0)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
char h = src[i];
|
||||
char l = src[i + 1];
|
||||
|
||||
if (src[i] < '0' || src[i] > 'F')
|
||||
return false;
|
||||
if (src[i] < 'A' && src[i] > '9')
|
||||
return false;
|
||||
if (src[i + 1] < '0' || src[i + 1] > 'F')
|
||||
return false;
|
||||
if (src[i + 1] < 'A' && src[i + 1] > '9')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HexToBytes(const char* src, size_t len, void* dst) {
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
uint8_t h = src[i];
|
||||
uint8_t l = src[i + 1];
|
||||
|
||||
h -= h > '9' ? 'A' - 10 : '0';
|
||||
l -= l > '9' ? 'A' - 10 : '0';
|
||||
|
||||
reinterpret_cast<uint8_t*>(dst)[i / 2] = (h << 4 )^ l;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Navicat11Crypto() {
|
||||
const uint8_t DefaultKey[8] = {
|
||||
'3', 'D', 'C', '5', 'C', 'A', '3', '9'
|
||||
};
|
||||
SHA1_DIGEST KeyHash;
|
||||
accelc_SHA1(DefaultKey, sizeof(DefaultKey), &KeyHash);
|
||||
accelc_Blowfish_set_key(KeyHash.byte, sizeof(KeyHash), &BlowfishKey);
|
||||
}
|
||||
|
||||
Navicat11Crypto(const void* srcBytes, size_t srclen) {
|
||||
if (srclen == 0)
|
||||
srclen = BLOWFISH_MIN_KEY_LENGTH;
|
||||
if (srclen > BLOWFISH_MAX_KEY_LENGTH)
|
||||
srclen = BLOWFISH_MAX_KEY_LENGTH;
|
||||
SHA1_DIGEST KeyHash;
|
||||
accelc_SHA1(srcBytes, srclen, &KeyHash);
|
||||
accelc_Blowfish_set_key(KeyHash.byte, sizeof(KeyHash), &BlowfishKey);
|
||||
}
|
||||
|
||||
std::vector<char> EncryptString(const void* srcBytes, size_t srclen) {
|
||||
std::vector<char> ret;
|
||||
if (srclen == 0)
|
||||
return ret;
|
||||
|
||||
ret.resize(srclen * 2 + 1);
|
||||
ret[srclen * 2] = 0;
|
||||
|
||||
uint8_t CV[BLOWFISH_BLOCK_SIZE] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
accelc_Blowfish_encrypt(CV, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
|
||||
const uint64_t* blocks = reinterpret_cast<const uint64_t*>(srcBytes);
|
||||
size_t blocks_len = srclen / BLOWFISH_BLOCK_SIZE;
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp;
|
||||
|
||||
temp.qword = blocks[i];
|
||||
temp.qword ^= *reinterpret_cast<uint64_t*>(CV);
|
||||
accelc_Blowfish_encrypt(temp.byte, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
*reinterpret_cast<uint64_t*>(CV) ^= temp.qword;
|
||||
|
||||
BytesToHex(temp.byte, 8, ret.data() + 16 * i);
|
||||
}
|
||||
|
||||
if (srclen % BLOWFISH_BLOCK_SIZE) {
|
||||
accelc_Blowfish_encrypt(CV, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
for (size_t i = 0; i < srclen % BLOWFISH_BLOCK_SIZE; ++i)
|
||||
CV[i] ^= reinterpret_cast<const uint8_t*>(blocks + blocks_len)[i];
|
||||
BytesToHex(CV, srclen % BLOWFISH_BLOCK_SIZE, ret.data() + 16 * blocks_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> DecryptString(const char* srchex, size_t srclen) {
|
||||
std::vector<uint8_t> ret;
|
||||
if (CheckHex(srchex, srclen) == false)
|
||||
return ret;
|
||||
|
||||
ret.resize(srclen / 2);
|
||||
uint8_t CV[BLOWFISH_BLOCK_SIZE] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
accelc_Blowfish_encrypt(CV, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
|
||||
const char (*blocks)[16] = reinterpret_cast<const char (*)[16]>(srchex);
|
||||
size_t blocks_len = srclen / 16;
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp, temp2;
|
||||
|
||||
HexToBytes(blocks[i], 16, temp.byte);
|
||||
std::memcpy(temp2.byte, temp.byte, 8);
|
||||
accelc_Blowfish_decrypt(temp.byte, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
temp.qword ^= *reinterpret_cast<uint64_t*>(CV);
|
||||
*reinterpret_cast<uint64_t*>(ret.data() + 8 * i) = temp.qword;
|
||||
*reinterpret_cast<uint64_t*>(CV) ^= temp2.qword;
|
||||
}
|
||||
|
||||
if (srclen % 16) {
|
||||
union {
|
||||
uint8_t byte[8];
|
||||
uint64_t qword;
|
||||
} temp = { };
|
||||
HexToBytes(blocks[blocks_len], srclen % 16, temp.byte);
|
||||
|
||||
accelc_Blowfish_encrypt(CV, &BlowfishKey, BLOWFISH_BIG_ENDIAN);
|
||||
for (size_t i = 0; i < (srclen % 16) / 2; ++i)
|
||||
ret[blocks_len * 8 + i] = temp.byte[i] ^ CV[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Navicat12Crypto : public Navicat11Crypto {
|
||||
protected:
|
||||
AES_KEY AES128Key;
|
||||
public:
|
||||
|
||||
Navicat12Crypto() : Navicat11Crypto() {
|
||||
uint8_t DefaultKey[16] = {
|
||||
'l', 'i', 'b', 'c', 'c', 'k', 'e', 'y',
|
||||
'l', 'i', 'b', 'c', 'c', 'k', 'e', 'y'
|
||||
};
|
||||
accelc_AES128_set_key(DefaultKey, &AES128Key);
|
||||
}
|
||||
|
||||
Navicat12Crypto(const void* srcBytes, size_t srclen) :
|
||||
Navicat11Crypto(srcBytes, srclen) {
|
||||
|
||||
uint8_t DefaultKey[16] = {
|
||||
'l', 'i', 'b', 'c', 'c', 'k', 'e', 'y',
|
||||
'l', 'i', 'b', 'c', 'c', 'k', 'e', 'y'
|
||||
};
|
||||
accelc_AES128_set_key(DefaultKey, &AES128Key);
|
||||
}
|
||||
|
||||
std::vector<char> EncryptString(const void* srcBytes, size_t srclen) {
|
||||
std::vector<char> ret;
|
||||
if (srclen == 0)
|
||||
return ret;
|
||||
|
||||
ret.resize((srclen / AES_BLOCK_SIZE + 1) * AES_BLOCK_SIZE * 2);
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} CV = {
|
||||
'l', 'i', 'b', 'c', 'c', 'i', 'v', ' ',
|
||||
'l', 'i', 'b', 'c', 'c', 'i', 'v', ' '
|
||||
};
|
||||
|
||||
const uint8_t (*blocks)[AES_BLOCK_SIZE] = reinterpret_cast<const uint8_t (*)[AES_BLOCK_SIZE]>(srcBytes);
|
||||
size_t blocks_len = srclen / AES_BLOCK_SIZE;
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} temp;
|
||||
|
||||
std::memcpy(temp.byte, blocks[i], AES_BLOCK_SIZE);
|
||||
temp.qword[0] ^= CV.qword[0];
|
||||
temp.qword[1] ^= CV.qword[1];
|
||||
accelc_AES128_encrypt(temp.byte, &AES128Key);
|
||||
BytesToHex(temp.byte, AES_BLOCK_SIZE, ret.data() + 2 * AES_BLOCK_SIZE * i);
|
||||
CV.qword[0] = temp.qword[0];
|
||||
CV.qword[1] = temp.qword[1];
|
||||
}
|
||||
|
||||
uint8_t padding = AES_BLOCK_SIZE - srclen % AES_BLOCK_SIZE;
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} temp;
|
||||
|
||||
std::memcpy(temp.byte, blocks[blocks_len], srclen % AES_BLOCK_SIZE);
|
||||
for (size_t i = srclen % AES_BLOCK_SIZE; i < AES_BLOCK_SIZE; ++i)
|
||||
temp.byte[i] = padding;
|
||||
|
||||
temp.qword[0] ^= CV.qword[0];
|
||||
temp.qword[1] ^= CV.qword[1];
|
||||
accelc_AES128_encrypt(temp.byte, &AES128Key);
|
||||
BytesToHex(temp.byte, AES_BLOCK_SIZE, ret.data() + 2 * AES_BLOCK_SIZE * blocks_len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> DecryptString(const char* srchex, size_t srclen) {
|
||||
std::vector<uint8_t> ret;
|
||||
if (srclen % (2 * AES_BLOCK_SIZE) != 0 || CheckHex(srchex, srclen) == false)
|
||||
return ret;
|
||||
|
||||
ret.reserve(srclen / 2);
|
||||
ret.resize(srclen / 2 - AES_BLOCK_SIZE);
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} CV = {
|
||||
'l', 'i', 'b', 'c', 'c', 'i', 'v', ' ',
|
||||
'l', 'i', 'b', 'c', 'c', 'i', 'v', ' '
|
||||
};
|
||||
|
||||
const char (*blocks)[2 * AES_BLOCK_SIZE] = reinterpret_cast<const char(*)[2 * AES_BLOCK_SIZE]>(srchex);
|
||||
size_t blocks_len = srclen / (2 * AES_BLOCK_SIZE);
|
||||
for (size_t i = 0; i < blocks_len; ++i) {
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} temp, NextVector;
|
||||
|
||||
HexToBytes(blocks[i], 2 * AES_BLOCK_SIZE, temp.byte);
|
||||
std::memcpy(NextVector.byte, temp.byte, AES_BLOCK_SIZE);
|
||||
accelc_AES128_decrypt(temp.byte, &AES128Key);
|
||||
temp.qword[0] ^= CV.qword[0];
|
||||
temp.qword[1] ^= CV.qword[1];
|
||||
|
||||
std::memcpy(ret.data() + AES_BLOCK_SIZE * i, temp.byte, AES_BLOCK_SIZE);
|
||||
std::memcpy(CV.byte, NextVector.byte, AES_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
union {
|
||||
uint8_t byte[AES_BLOCK_SIZE];
|
||||
uint64_t qword[2];
|
||||
} temp;
|
||||
HexToBytes(blocks[blocks_len], 2 * AES_BLOCK_SIZE, temp.byte);
|
||||
accelc_AES128_decrypt(temp.byte, &AES128Key);
|
||||
temp.qword[0] ^= CV.qword[0];
|
||||
temp.qword[1] ^= CV.qword[1];
|
||||
|
||||
if (temp.byte[AES_BLOCK_SIZE - 1] > AES_BLOCK_SIZE) {
|
||||
ret.clear();
|
||||
return ret;
|
||||
} else {
|
||||
uint8_t padding = temp.byte[AES_BLOCK_SIZE - 1];
|
||||
for (int i = AES_BLOCK_SIZE - padding; i < AES_BLOCK_SIZE; ++i)
|
||||
if (temp.byte[i] != padding) {
|
||||
ret.clear();
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < (AES_BLOCK_SIZE - padding); ++i)
|
||||
ret.emplace_back(temp.byte[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,438 @@
|
||||
#include "aes.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
extern const uint32_t accelc_aes_rcon[11];
|
||||
|
||||
extern const uint8_t accelc_aes_SBox[256];
|
||||
extern const uint8_t accelc_aes_InverseSBox[256];
|
||||
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x02[256];
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x03[256];
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x09[256];
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x0B[256];
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x0D[256];
|
||||
extern const uint8_t accelc_aes_GF2p8_Mul_0x0E[256];
|
||||
|
||||
#define Swap(X, Y, Temp) \
|
||||
Temp = X; \
|
||||
X = Y; \
|
||||
Y = Temp;
|
||||
|
||||
void accelc_AES128_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
for (int i = 1; i < 10; ++i) {
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x02[temp[0]] ^ accelc_aes_GF2p8_Mul_0x03[temp[1]] ^ temp[2] ^ temp[3]);
|
||||
srcBytes[j + 1] = (uint8_t)(temp[0] ^ accelc_aes_GF2p8_Mul_0x02[temp[1]] ^ accelc_aes_GF2p8_Mul_0x03[temp[2]] ^ temp[3]);
|
||||
srcBytes[j + 2] = (uint8_t)(temp[0] ^ temp[1] ^ accelc_aes_GF2p8_Mul_0x02[temp[2]] ^ accelc_aes_GF2p8_Mul_0x03[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x03[temp[0]] ^ temp[1] ^ temp[2] ^ accelc_aes_GF2p8_Mul_0x02[temp[3]]);
|
||||
}
|
||||
|
||||
((uint64_t*)(srcBytes))[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)(srcBytes))[1] ^= srcKey->qword[i * 2 + 1];
|
||||
}
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[20];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[21];
|
||||
}
|
||||
|
||||
void accelc_AES128_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[20];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[21];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
|
||||
for (int i = 9; i > 0; --i) {
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[i * 2 + 1];
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0E[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[2]] ^ accelc_aes_GF2p8_Mul_0x09[temp[3]]);
|
||||
srcBytes[j + 1] = (uint8_t)(accelc_aes_GF2p8_Mul_0x09[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[3]]);
|
||||
srcBytes[j + 2] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0D[temp[0]] ^ accelc_aes_GF2p8_Mul_0x09[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0B[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[1]] ^ accelc_aes_GF2p8_Mul_0x09[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[3]]);
|
||||
}
|
||||
}
|
||||
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
}
|
||||
|
||||
void accelc_AES128_set_key(const uint8_t srcUserKey[16], AES_KEY* dstKey) {
|
||||
dstKey->qword[0] = ((const uint64_t*)srcUserKey)[0];
|
||||
dstKey->qword[1] = ((const uint64_t*)srcUserKey)[1];
|
||||
|
||||
for (int i = 4; i < 44; ++i) {
|
||||
uint32_t temp = dstKey->dword[i - 1];
|
||||
if (i % 4 == 0) {
|
||||
temp = _rotr(temp, 8);
|
||||
((uint8_t*)&temp)[0] = accelc_aes_SBox[((uint8_t*)&temp)[0]];
|
||||
((uint8_t*)&temp)[1] = accelc_aes_SBox[((uint8_t*)&temp)[1]];
|
||||
((uint8_t*)&temp)[2] = accelc_aes_SBox[((uint8_t*)&temp)[2]];
|
||||
((uint8_t*)&temp)[3] = accelc_aes_SBox[((uint8_t*)&temp)[3]];
|
||||
temp ^= accelc_aes_rcon[i / 4];
|
||||
}
|
||||
dstKey->dword[i] = dstKey->dword[i - 4] ^ temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void accelc_AES192_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
for (int i = 1; i < 12; ++i) {
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x02[temp[0]] ^ accelc_aes_GF2p8_Mul_0x03[temp[1]] ^ temp[2] ^ temp[3]);
|
||||
srcBytes[j + 1] = (uint8_t)(temp[0] ^ accelc_aes_GF2p8_Mul_0x02[temp[1]] ^ accelc_aes_GF2p8_Mul_0x03[temp[2]] ^ temp[3]);
|
||||
srcBytes[j + 2] = (uint8_t)(temp[0] ^ temp[1] ^ accelc_aes_GF2p8_Mul_0x02[temp[2]] ^ accelc_aes_GF2p8_Mul_0x03[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x03[temp[0]] ^ temp[1] ^ temp[2] ^ accelc_aes_GF2p8_Mul_0x02[temp[3]]);
|
||||
}
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[i * 2 + 1];
|
||||
}
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp) //Swap is a MACRO, no need to add ';'.
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[24];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[25];
|
||||
}
|
||||
|
||||
void accelc_AES192_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[24];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[25];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
|
||||
for (int i = 11; i > 0; --i) {
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[i * 2 + 1];
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0E[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[2]] ^ accelc_aes_GF2p8_Mul_0x09[temp[3]]);
|
||||
srcBytes[j + 1] = (uint8_t)(accelc_aes_GF2p8_Mul_0x09[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[3]]);
|
||||
srcBytes[j + 2] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0D[temp[0]] ^ accelc_aes_GF2p8_Mul_0x09[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0B[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[1]] ^ accelc_aes_GF2p8_Mul_0x09[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[3]]);
|
||||
}
|
||||
}
|
||||
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (uint8_t j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
}
|
||||
|
||||
void accelc_AES192_set_key(const uint8_t srcUserKey[24], AES_KEY* dstKey) {
|
||||
dstKey->qword[0] = ((const uint64_t*)srcUserKey)[0];
|
||||
dstKey->qword[1] = ((const uint64_t*)srcUserKey)[1];
|
||||
dstKey->qword[2] = ((const uint64_t*)srcUserKey)[2];
|
||||
|
||||
for (int i = 6; i < 52; ++i) {
|
||||
uint32_t temp = dstKey->dword[i - 1];
|
||||
if (i % 6 == 0) {
|
||||
temp = _rotr(temp, 8);
|
||||
((uint8_t*)&temp)[0] = accelc_aes_SBox[((uint8_t*)&temp)[0]];
|
||||
((uint8_t*)&temp)[1] = accelc_aes_SBox[((uint8_t*)&temp)[1]];
|
||||
((uint8_t*)&temp)[2] = accelc_aes_SBox[((uint8_t*)&temp)[2]];
|
||||
((uint8_t*)&temp)[3] = accelc_aes_SBox[((uint8_t*)&temp)[3]];
|
||||
temp ^= accelc_aes_rcon[i / 6];
|
||||
}
|
||||
dstKey->dword[i] = dstKey->dword[i - 6] ^ temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void accelc_AES256_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
for (int i = 1; i < 14; ++i) {
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x02[temp[0]] ^ accelc_aes_GF2p8_Mul_0x03[temp[1]] ^ temp[2] ^ temp[3]);
|
||||
srcBytes[j + 1] = (uint8_t)(temp[0] ^ accelc_aes_GF2p8_Mul_0x02[temp[1]] ^ accelc_aes_GF2p8_Mul_0x03[temp[2]] ^ temp[3]);
|
||||
srcBytes[j + 2] = (uint8_t)(temp[0] ^ temp[1] ^ accelc_aes_GF2p8_Mul_0x02[temp[2]] ^ accelc_aes_GF2p8_Mul_0x03[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x03[temp[0]] ^ temp[1] ^ temp[2] ^ accelc_aes_GF2p8_Mul_0x02[temp[3]]);
|
||||
}
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[i * 2 + 1];
|
||||
}
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_SBox[srcBytes[j]];
|
||||
|
||||
//Shift rows starts;
|
||||
//Shift the second row;
|
||||
Swap(srcBytes[1], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[13], ShiftTemp)
|
||||
//Shift the third row;
|
||||
Swap(srcBytes[2], srcBytes[10], ShiftTemp)
|
||||
Swap(srcBytes[6], srcBytes[14], ShiftTemp)
|
||||
//Shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[15], ShiftTemp)
|
||||
Swap(srcBytes[15], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[7], ShiftTemp)
|
||||
//Shift rows ends;
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[28];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[29];
|
||||
}
|
||||
|
||||
void accelc_AES256_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey) {
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[28];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[29];
|
||||
|
||||
uint8_t ShiftTemp = 0;
|
||||
for (int i = 13; i > 0; --i) {
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[i * 2];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[i * 2 + 1];
|
||||
|
||||
for (int j = 0; j < 16; j += 4) {
|
||||
uint8_t temp[4];
|
||||
*(uint32_t*)temp = ((uint32_t*)srcBytes)[j / 4];
|
||||
|
||||
srcBytes[j] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0E[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[2]] ^ accelc_aes_GF2p8_Mul_0x09[temp[3]]);
|
||||
srcBytes[j + 1] = (uint8_t)(accelc_aes_GF2p8_Mul_0x09[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[3]]);
|
||||
srcBytes[j + 2] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0D[temp[0]] ^ accelc_aes_GF2p8_Mul_0x09[temp[1]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0B[temp[3]]);
|
||||
srcBytes[j + 3] = (uint8_t)(accelc_aes_GF2p8_Mul_0x0B[temp[0]] ^ accelc_aes_GF2p8_Mul_0x0D[temp[1]] ^ accelc_aes_GF2p8_Mul_0x09[temp[2]] ^ accelc_aes_GF2p8_Mul_0x0E[temp[3]]);
|
||||
}
|
||||
}
|
||||
|
||||
//Inverse Shift rows starts;
|
||||
//Inverse shift the second row;
|
||||
Swap(srcBytes[13], srcBytes[9], ShiftTemp)
|
||||
Swap(srcBytes[9], srcBytes[5], ShiftTemp)
|
||||
Swap(srcBytes[5], srcBytes[1], ShiftTemp)
|
||||
//Inverse shift the third row;
|
||||
Swap(srcBytes[14], srcBytes[6], ShiftTemp)
|
||||
Swap(srcBytes[10], srcBytes[2], ShiftTemp)
|
||||
//Inverse shift the fourth row;
|
||||
Swap(srcBytes[3], srcBytes[7], ShiftTemp)
|
||||
Swap(srcBytes[7], srcBytes[11], ShiftTemp)
|
||||
Swap(srcBytes[11], srcBytes[15], ShiftTemp)
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
srcBytes[j] = accelc_aes_InverseSBox[srcBytes[j]];
|
||||
|
||||
((uint64_t*)srcBytes)[0] ^= srcKey->qword[0];
|
||||
((uint64_t*)srcBytes)[1] ^= srcKey->qword[1];
|
||||
}
|
||||
|
||||
void accelc_AES256_set_key(const uint8_t srcUserKey[32], AES_KEY* dstKey) {
|
||||
dstKey->qword[0] = ((const uint64_t*)srcUserKey)[0];
|
||||
dstKey->qword[1] = ((const uint64_t*)srcUserKey)[1];
|
||||
dstKey->qword[2] = ((const uint64_t*)srcUserKey)[2];
|
||||
dstKey->qword[3] = ((const uint64_t*)srcUserKey)[3];
|
||||
|
||||
for (int i = 8; i < 60; ++i) {
|
||||
uint32_t temp = dstKey->dword[i - 1];
|
||||
if (i % 8 == 0) {
|
||||
temp = _rotr(temp, 8);
|
||||
((uint8_t*)&temp)[0] = accelc_aes_SBox[((uint8_t*)&temp)[0]];
|
||||
((uint8_t*)&temp)[1] = accelc_aes_SBox[((uint8_t*)&temp)[1]];
|
||||
((uint8_t*)&temp)[2] = accelc_aes_SBox[((uint8_t*)&temp)[2]];
|
||||
((uint8_t*)&temp)[3] = accelc_aes_SBox[((uint8_t*)&temp)[3]];
|
||||
temp ^= accelc_aes_rcon[i / 8];
|
||||
}
|
||||
if (i % 8 == 4) {
|
||||
((uint8_t*)&temp)[0] = accelc_aes_SBox[((uint8_t*)&temp)[0]];
|
||||
((uint8_t*)&temp)[1] = accelc_aes_SBox[((uint8_t*)&temp)[1]];
|
||||
((uint8_t*)&temp)[2] = accelc_aes_SBox[((uint8_t*)&temp)[2]];
|
||||
((uint8_t*)&temp)[3] = accelc_aes_SBox[((uint8_t*)&temp)[3]];
|
||||
}
|
||||
dstKey->dword[i] = dstKey->dword[i - 8] ^ temp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
#define AES128_USERKEY_LENGTH 16
|
||||
#define AES192_USERKEY_LENGTH 24
|
||||
#define AES256_USERKEY_LENGTH 32
|
||||
|
||||
typedef struct _AES_KEY {
|
||||
union {
|
||||
uint8_t byte[240];
|
||||
uint16_t word[120];
|
||||
uint32_t dword[60];
|
||||
uint64_t qword[30];
|
||||
};
|
||||
} AES_KEY;
|
||||
|
||||
//
|
||||
// encrypt
|
||||
//
|
||||
void accelc_AES128_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES192_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES256_encrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
|
||||
//
|
||||
// dncrypt
|
||||
//
|
||||
void accelc_AES128_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES192_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES256_decrypt(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
|
||||
//
|
||||
// set_key
|
||||
//
|
||||
void accelc_AES128_set_key(const uint8_t srcUserKey[AES128_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
void accelc_AES192_set_key(const uint8_t srcUserKey[AES192_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
void accelc_AES256_set_key(const uint8_t srcUserKey[AES256_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
|
||||
//
|
||||
// encrypt_aesni
|
||||
//
|
||||
void accelc_AES128_encrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES192_encrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES256_encrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
|
||||
//
|
||||
// decrypt_aesni
|
||||
//
|
||||
void accelc_AES128_decrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES192_decrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
void accelc_AES256_decrypt_aesni(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcKey);
|
||||
|
||||
//
|
||||
// decrypt_aesni_fast
|
||||
//
|
||||
void accelc_AES128_decrypt_aesni_fast(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcInverseKey);
|
||||
void accelc_AES192_decrypt_aesni_fast(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcInverseKey);
|
||||
void accelc_AES256_decrypt_aesni_fast(uint8_t srcBytes[AES_BLOCK_SIZE], const AES_KEY* srcInverseKey);
|
||||
|
||||
//
|
||||
// set_key_aesni
|
||||
//
|
||||
void accelc_AES128_set_key_aesni(const uint8_t srcUserKey[AES128_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
void accelc_AES192_set_key_aesni(const uint8_t srcUserKey[AES128_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
void accelc_AES256_set_key_aesni(const uint8_t srcUserKey[AES256_USERKEY_LENGTH], AES_KEY* dstKey);
|
||||
|
||||
//
|
||||
// set_invkey_aesni
|
||||
//
|
||||
void accelc_AES128_set_invkey_aesni(const AES_KEY* __restrict srcKey, AES_KEY* __restrict dstInverseKey);
|
||||
void accelc_AES192_set_invkey_aesni(const AES_KEY* __restrict srcKey, AES_KEY* __restrict dstInverseKey);
|
||||
void accelc_AES256_set_invkey_aesni(const AES_KEY* __restrict srcKey, AES_KEY* __restrict dstInverseKey);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
#include <stdint.h>
|
||||
|
||||
const uint8_t accelc_aes_SBox[256] = {
|
||||
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
|
||||
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
|
||||
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
|
||||
0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
|
||||
0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
|
||||
0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
|
||||
0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
|
||||
0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
|
||||
0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
|
||||
0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
|
||||
0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
|
||||
0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
|
||||
0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
|
||||
0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
|
||||
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
|
||||
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
|
||||
};
|
||||
|
||||
const uint32_t accelc_aes_rcon[11] = {
|
||||
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x02[256] = {
|
||||
0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E,
|
||||
0x20, 0x22, 0x24, 0x26, 0x28, 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E,
|
||||
0x40, 0x42, 0x44, 0x46, 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E,
|
||||
0x60, 0x62, 0x64, 0x66, 0x68, 0x6A, 0x6C, 0x6E, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E,
|
||||
0x80, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C, 0x8E, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9A, 0x9C, 0x9E,
|
||||
0xA0, 0xA2, 0xA4, 0xA6, 0xA8, 0xAA, 0xAC, 0xAE, 0xB0, 0xB2, 0xB4, 0xB6, 0xB8, 0xBA, 0xBC, 0xBE,
|
||||
0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE, 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
|
||||
0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE, 0xF0, 0xF2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE,
|
||||
0x1B, 0x19, 0x1F, 0x1D, 0x13, 0x11, 0x17, 0x15, 0x0B, 0x09, 0x0F, 0x0D, 0x03, 0x01, 0x07, 0x05,
|
||||
0x3B, 0x39, 0x3F, 0x3D, 0x33, 0x31, 0x37, 0x35, 0x2B, 0x29, 0x2F, 0x2D, 0x23, 0x21, 0x27, 0x25,
|
||||
0x5B, 0x59, 0x5F, 0x5D, 0x53, 0x51, 0x57, 0x55, 0x4B, 0x49, 0x4F, 0x4D, 0x43, 0x41, 0x47, 0x45,
|
||||
0x7B, 0x79, 0x7F, 0x7D, 0x73, 0x71, 0x77, 0x75, 0x6B, 0x69, 0x6F, 0x6D, 0x63, 0x61, 0x67, 0x65,
|
||||
0x9B, 0x99, 0x9F, 0x9D, 0x93, 0x91, 0x97, 0x95, 0x8B, 0x89, 0x8F, 0x8D, 0x83, 0x81, 0x87, 0x85,
|
||||
0xBB, 0xB9, 0xBF, 0xBD, 0xB3, 0xB1, 0xB7, 0xB5, 0xAB, 0xA9, 0xAF, 0xAD, 0xA3, 0xA1, 0xA7, 0xA5,
|
||||
0xDB, 0xD9, 0xDF, 0xDD, 0xD3, 0xD1, 0xD7, 0xD5, 0xCB, 0xC9, 0xCF, 0xCD, 0xC3, 0xC1, 0xC7, 0xC5,
|
||||
0xFB, 0xF9, 0xFF, 0xFD, 0xF3, 0xF1, 0xF7, 0xF5, 0xEB, 0xE9, 0xEF, 0xED, 0xE3, 0xE1, 0xE7, 0xE5
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x03[256] = {
|
||||
0x00, 0x03, 0x06, 0x05, 0x0C, 0x0F, 0x0A, 0x09, 0x18, 0x1B, 0x1E, 0x1D, 0x14, 0x17, 0x12, 0x11,
|
||||
0x30, 0x33, 0x36, 0x35, 0x3C, 0x3F, 0x3A, 0x39, 0x28, 0x2B, 0x2E, 0x2D, 0x24, 0x27, 0x22, 0x21,
|
||||
0x60, 0x63, 0x66, 0x65, 0x6C, 0x6F, 0x6A, 0x69, 0x78, 0x7B, 0x7E, 0x7D, 0x74, 0x77, 0x72, 0x71,
|
||||
0x50, 0x53, 0x56, 0x55, 0x5C, 0x5F, 0x5A, 0x59, 0x48, 0x4B, 0x4E, 0x4D, 0x44, 0x47, 0x42, 0x41,
|
||||
0xC0, 0xC3, 0xC6, 0xC5, 0xCC, 0xCF, 0xCA, 0xC9, 0xD8, 0xDB, 0xDE, 0xDD, 0xD4, 0xD7, 0xD2, 0xD1,
|
||||
0xF0, 0xF3, 0xF6, 0xF5, 0xFC, 0xFF, 0xFA, 0xF9, 0xE8, 0xEB, 0xEE, 0xED, 0xE4, 0xE7, 0xE2, 0xE1,
|
||||
0xA0, 0xA3, 0xA6, 0xA5, 0xAC, 0xAF, 0xAA, 0xA9, 0xB8, 0xBB, 0xBE, 0xBD, 0xB4, 0xB7, 0xB2, 0xB1,
|
||||
0x90, 0x93, 0x96, 0x95, 0x9C, 0x9F, 0x9A, 0x99, 0x88, 0x8B, 0x8E, 0x8D, 0x84, 0x87, 0x82, 0x81,
|
||||
0x9B, 0x98, 0x9D, 0x9E, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8F, 0x8C, 0x89, 0x8A,
|
||||
0xAB, 0xA8, 0xAD, 0xAE, 0xA7, 0xA4, 0xA1, 0xA2, 0xB3, 0xB0, 0xB5, 0xB6, 0xBF, 0xBC, 0xB9, 0xBA,
|
||||
0xFB, 0xF8, 0xFD, 0xFE, 0xF7, 0xF4, 0xF1, 0xF2, 0xE3, 0xE0, 0xE5, 0xE6, 0xEF, 0xEC, 0xE9, 0xEA,
|
||||
0xCB, 0xC8, 0xCD, 0xCE, 0xC7, 0xC4, 0xC1, 0xC2, 0xD3, 0xD0, 0xD5, 0xD6, 0xDF, 0xDC, 0xD9, 0xDA,
|
||||
0x5B, 0x58, 0x5D, 0x5E, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4F, 0x4C, 0x49, 0x4A,
|
||||
0x6B, 0x68, 0x6D, 0x6E, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7F, 0x7C, 0x79, 0x7A,
|
||||
0x3B, 0x38, 0x3D, 0x3E, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2F, 0x2C, 0x29, 0x2A,
|
||||
0x0B, 0x08, 0x0D, 0x0E, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1F, 0x1C, 0x19, 0x1A
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_InverseSBox[256] = {
|
||||
0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
|
||||
0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
|
||||
0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
|
||||
0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
|
||||
0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
|
||||
0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
|
||||
0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
|
||||
0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
|
||||
0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
|
||||
0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
|
||||
0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
|
||||
0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
|
||||
0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
|
||||
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
|
||||
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x09[256] = {
|
||||
0x00, 0x09, 0x12, 0x1B, 0x24, 0x2D, 0x36, 0x3F, 0x48, 0x41, 0x5A, 0x53, 0x6C, 0x65, 0x7E, 0x77,
|
||||
0x90, 0x99, 0x82, 0x8B, 0xB4, 0xBD, 0xA6, 0xAF, 0xD8, 0xD1, 0xCA, 0xC3, 0xFC, 0xF5, 0xEE, 0xE7,
|
||||
0x3B, 0x32, 0x29, 0x20, 0x1F, 0x16, 0x0D, 0x04, 0x73, 0x7A, 0x61, 0x68, 0x57, 0x5E, 0x45, 0x4C,
|
||||
0xAB, 0xA2, 0xB9, 0xB0, 0x8F, 0x86, 0x9D, 0x94, 0xE3, 0xEA, 0xF1, 0xF8, 0xC7, 0xCE, 0xD5, 0xDC,
|
||||
0x76, 0x7F, 0x64, 0x6D, 0x52, 0x5B, 0x40, 0x49, 0x3E, 0x37, 0x2C, 0x25, 0x1A, 0x13, 0x08, 0x01,
|
||||
0xE6, 0xEF, 0xF4, 0xFD, 0xC2, 0xCB, 0xD0, 0xD9, 0xAE, 0xA7, 0xBC, 0xB5, 0x8A, 0x83, 0x98, 0x91,
|
||||
0x4D, 0x44, 0x5F, 0x56, 0x69, 0x60, 0x7B, 0x72, 0x05, 0x0C, 0x17, 0x1E, 0x21, 0x28, 0x33, 0x3A,
|
||||
0xDD, 0xD4, 0xCF, 0xC6, 0xF9, 0xF0, 0xEB, 0xE2, 0x95, 0x9C, 0x87, 0x8E, 0xB1, 0xB8, 0xA3, 0xAA,
|
||||
0xEC, 0xE5, 0xFE, 0xF7, 0xC8, 0xC1, 0xDA, 0xD3, 0xA4, 0xAD, 0xB6, 0xBF, 0x80, 0x89, 0x92, 0x9B,
|
||||
0x7C, 0x75, 0x6E, 0x67, 0x58, 0x51, 0x4A, 0x43, 0x34, 0x3D, 0x26, 0x2F, 0x10, 0x19, 0x02, 0x0B,
|
||||
0xD7, 0xDE, 0xC5, 0xCC, 0xF3, 0xFA, 0xE1, 0xE8, 0x9F, 0x96, 0x8D, 0x84, 0xBB, 0xB2, 0xA9, 0xA0,
|
||||
0x47, 0x4E, 0x55, 0x5C, 0x63, 0x6A, 0x71, 0x78, 0x0F, 0x06, 0x1D, 0x14, 0x2B, 0x22, 0x39, 0x30,
|
||||
0x9A, 0x93, 0x88, 0x81, 0xBE, 0xB7, 0xAC, 0xA5, 0xD2, 0xDB, 0xC0, 0xC9, 0xF6, 0xFF, 0xE4, 0xED,
|
||||
0x0A, 0x03, 0x18, 0x11, 0x2E, 0x27, 0x3C, 0x35, 0x42, 0x4B, 0x50, 0x59, 0x66, 0x6F, 0x74, 0x7D,
|
||||
0xA1, 0xA8, 0xB3, 0xBA, 0x85, 0x8C, 0x97, 0x9E, 0xE9, 0xE0, 0xFB, 0xF2, 0xCD, 0xC4, 0xDF, 0xD6,
|
||||
0x31, 0x38, 0x23, 0x2A, 0x15, 0x1C, 0x07, 0x0E, 0x79, 0x70, 0x6B, 0x62, 0x5D, 0x54, 0x4F, 0x46
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x0B[256] = {
|
||||
0x00, 0x0B, 0x16, 0x1D, 0x2C, 0x27, 0x3A, 0x31, 0x58, 0x53, 0x4E, 0x45, 0x74, 0x7F, 0x62, 0x69,
|
||||
0xB0, 0xBB, 0xA6, 0xAD, 0x9C, 0x97, 0x8A, 0x81, 0xE8, 0xE3, 0xFE, 0xF5, 0xC4, 0xCF, 0xD2, 0xD9,
|
||||
0x7B, 0x70, 0x6D, 0x66, 0x57, 0x5C, 0x41, 0x4A, 0x23, 0x28, 0x35, 0x3E, 0x0F, 0x04, 0x19, 0x12,
|
||||
0xCB, 0xC0, 0xDD, 0xD6, 0xE7, 0xEC, 0xF1, 0xFA, 0x93, 0x98, 0x85, 0x8E, 0xBF, 0xB4, 0xA9, 0xA2,
|
||||
0xF6, 0xFD, 0xE0, 0xEB, 0xDA, 0xD1, 0xCC, 0xC7, 0xAE, 0xA5, 0xB8, 0xB3, 0x82, 0x89, 0x94, 0x9F,
|
||||
0x46, 0x4D, 0x50, 0x5B, 0x6A, 0x61, 0x7C, 0x77, 0x1E, 0x15, 0x08, 0x03, 0x32, 0x39, 0x24, 0x2F,
|
||||
0x8D, 0x86, 0x9B, 0x90, 0xA1, 0xAA, 0xB7, 0xBC, 0xD5, 0xDE, 0xC3, 0xC8, 0xF9, 0xF2, 0xEF, 0xE4,
|
||||
0x3D, 0x36, 0x2B, 0x20, 0x11, 0x1A, 0x07, 0x0C, 0x65, 0x6E, 0x73, 0x78, 0x49, 0x42, 0x5F, 0x54,
|
||||
0xF7, 0xFC, 0xE1, 0xEA, 0xDB, 0xD0, 0xCD, 0xC6, 0xAF, 0xA4, 0xB9, 0xB2, 0x83, 0x88, 0x95, 0x9E,
|
||||
0x47, 0x4C, 0x51, 0x5A, 0x6B, 0x60, 0x7D, 0x76, 0x1F, 0x14, 0x09, 0x02, 0x33, 0x38, 0x25, 0x2E,
|
||||
0x8C, 0x87, 0x9A, 0x91, 0xA0, 0xAB, 0xB6, 0xBD, 0xD4, 0xDF, 0xC2, 0xC9, 0xF8, 0xF3, 0xEE, 0xE5,
|
||||
0x3C, 0x37, 0x2A, 0x21, 0x10, 0x1B, 0x06, 0x0D, 0x64, 0x6F, 0x72, 0x79, 0x48, 0x43, 0x5E, 0x55,
|
||||
0x01, 0x0A, 0x17, 0x1C, 0x2D, 0x26, 0x3B, 0x30, 0x59, 0x52, 0x4F, 0x44, 0x75, 0x7E, 0x63, 0x68,
|
||||
0xB1, 0xBA, 0xA7, 0xAC, 0x9D, 0x96, 0x8B, 0x80, 0xE9, 0xE2, 0xFF, 0xF4, 0xC5, 0xCE, 0xD3, 0xD8,
|
||||
0x7A, 0x71, 0x6C, 0x67, 0x56, 0x5D, 0x40, 0x4B, 0x22, 0x29, 0x34, 0x3F, 0x0E, 0x05, 0x18, 0x13,
|
||||
0xCA, 0xC1, 0xDC, 0xD7, 0xE6, 0xED, 0xF0, 0xFB, 0x92, 0x99, 0x84, 0x8F, 0xBE, 0xB5, 0xA8, 0xA3
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x0D[256] = {
|
||||
0x00, 0x0D, 0x1A, 0x17, 0x34, 0x39, 0x2E, 0x23, 0x68, 0x65, 0x72, 0x7F, 0x5C, 0x51, 0x46, 0x4B,
|
||||
0xD0, 0xDD, 0xCA, 0xC7, 0xE4, 0xE9, 0xFE, 0xF3, 0xB8, 0xB5, 0xA2, 0xAF, 0x8C, 0x81, 0x96, 0x9B,
|
||||
0xBB, 0xB6, 0xA1, 0xAC, 0x8F, 0x82, 0x95, 0x98, 0xD3, 0xDE, 0xC9, 0xC4, 0xE7, 0xEA, 0xFD, 0xF0,
|
||||
0x6B, 0x66, 0x71, 0x7C, 0x5F, 0x52, 0x45, 0x48, 0x03, 0x0E, 0x19, 0x14, 0x37, 0x3A, 0x2D, 0x20,
|
||||
0x6D, 0x60, 0x77, 0x7A, 0x59, 0x54, 0x43, 0x4E, 0x05, 0x08, 0x1F, 0x12, 0x31, 0x3C, 0x2B, 0x26,
|
||||
0xBD, 0xB0, 0xA7, 0xAA, 0x89, 0x84, 0x93, 0x9E, 0xD5, 0xD8, 0xCF, 0xC2, 0xE1, 0xEC, 0xFB, 0xF6,
|
||||
0xD6, 0xDB, 0xCC, 0xC1, 0xE2, 0xEF, 0xF8, 0xF5, 0xBE, 0xB3, 0xA4, 0xA9, 0x8A, 0x87, 0x90, 0x9D,
|
||||
0x06, 0x0B, 0x1C, 0x11, 0x32, 0x3F, 0x28, 0x25, 0x6E, 0x63, 0x74, 0x79, 0x5A, 0x57, 0x40, 0x4D,
|
||||
0xDA, 0xD7, 0xC0, 0xCD, 0xEE, 0xE3, 0xF4, 0xF9, 0xB2, 0xBF, 0xA8, 0xA5, 0x86, 0x8B, 0x9C, 0x91,
|
||||
0x0A, 0x07, 0x10, 0x1D, 0x3E, 0x33, 0x24, 0x29, 0x62, 0x6F, 0x78, 0x75, 0x56, 0x5B, 0x4C, 0x41,
|
||||
0x61, 0x6C, 0x7B, 0x76, 0x55, 0x58, 0x4F, 0x42, 0x09, 0x04, 0x13, 0x1E, 0x3D, 0x30, 0x27, 0x2A,
|
||||
0xB1, 0xBC, 0xAB, 0xA6, 0x85, 0x88, 0x9F, 0x92, 0xD9, 0xD4, 0xC3, 0xCE, 0xED, 0xE0, 0xF7, 0xFA,
|
||||
0xB7, 0xBA, 0xAD, 0xA0, 0x83, 0x8E, 0x99, 0x94, 0xDF, 0xD2, 0xC5, 0xC8, 0xEB, 0xE6, 0xF1, 0xFC,
|
||||
0x67, 0x6A, 0x7D, 0x70, 0x53, 0x5E, 0x49, 0x44, 0x0F, 0x02, 0x15, 0x18, 0x3B, 0x36, 0x21, 0x2C,
|
||||
0x0C, 0x01, 0x16, 0x1B, 0x38, 0x35, 0x22, 0x2F, 0x64, 0x69, 0x7E, 0x73, 0x50, 0x5D, 0x4A, 0x47,
|
||||
0xDC, 0xD1, 0xC6, 0xCB, 0xE8, 0xE5, 0xF2, 0xFF, 0xB4, 0xB9, 0xAE, 0xA3, 0x80, 0x8D, 0x9A, 0x97
|
||||
};
|
||||
|
||||
const uint8_t accelc_aes_GF2p8_Mul_0x0E[256] = {
|
||||
0x00, 0x0E, 0x1C, 0x12, 0x38, 0x36, 0x24, 0x2A, 0x70, 0x7E, 0x6C, 0x62, 0x48, 0x46, 0x54, 0x5A,
|
||||
0xE0, 0xEE, 0xFC, 0xF2, 0xD8, 0xD6, 0xC4, 0xCA, 0x90, 0x9E, 0x8C, 0x82, 0xA8, 0xA6, 0xB4, 0xBA,
|
||||
0xDB, 0xD5, 0xC7, 0xC9, 0xE3, 0xED, 0xFF, 0xF1, 0xAB, 0xA5, 0xB7, 0xB9, 0x93, 0x9D, 0x8F, 0x81,
|
||||
0x3B, 0x35, 0x27, 0x29, 0x03, 0x0D, 0x1F, 0x11, 0x4B, 0x45, 0x57, 0x59, 0x73, 0x7D, 0x6F, 0x61,
|
||||
0xAD, 0xA3, 0xB1, 0xBF, 0x95, 0x9B, 0x89, 0x87, 0xDD, 0xD3, 0xC1, 0xCF, 0xE5, 0xEB, 0xF9, 0xF7,
|
||||
0x4D, 0x43, 0x51, 0x5F, 0x75, 0x7B, 0x69, 0x67, 0x3D, 0x33, 0x21, 0x2F, 0x05, 0x0B, 0x19, 0x17,
|
||||
0x76, 0x78, 0x6A, 0x64, 0x4E, 0x40, 0x52, 0x5C, 0x06, 0x08, 0x1A, 0x14, 0x3E, 0x30, 0x22, 0x2C,
|
||||
0x96, 0x98, 0x8A, 0x84, 0xAE, 0xA0, 0xB2, 0xBC, 0xE6, 0xE8, 0xFA, 0xF4, 0xDE, 0xD0, 0xC2, 0xCC,
|
||||
0x41, 0x4F, 0x5D, 0x53, 0x79, 0x77, 0x65, 0x6B, 0x31, 0x3F, 0x2D, 0x23, 0x09, 0x07, 0x15, 0x1B,
|
||||
0xA1, 0xAF, 0xBD, 0xB3, 0x99, 0x97, 0x85, 0x8B, 0xD1, 0xDF, 0xCD, 0xC3, 0xE9, 0xE7, 0xF5, 0xFB,
|
||||
0x9A, 0x94, 0x86, 0x88, 0xA2, 0xAC, 0xBE, 0xB0, 0xEA, 0xE4, 0xF6, 0xF8, 0xD2, 0xDC, 0xCE, 0xC0,
|
||||
0x7A, 0x74, 0x66, 0x68, 0x42, 0x4C, 0x5E, 0x50, 0x0A, 0x04, 0x16, 0x18, 0x32, 0x3C, 0x2E, 0x20,
|
||||
0xEC, 0xE2, 0xF0, 0xFE, 0xD4, 0xDA, 0xC8, 0xC6, 0x9C, 0x92, 0x80, 0x8E, 0xA4, 0xAA, 0xB8, 0xB6,
|
||||
0x0C, 0x02, 0x10, 0x1E, 0x34, 0x3A, 0x28, 0x26, 0x7C, 0x72, 0x60, 0x6E, 0x44, 0x4A, 0x58, 0x56,
|
||||
0x37, 0x39, 0x2B, 0x25, 0x0F, 0x01, 0x13, 0x1D, 0x47, 0x49, 0x5B, 0x55, 0x7F, 0x71, 0x63, 0x6D,
|
||||
0xD7, 0xD9, 0xCB, 0xC5, 0xEF, 0xE1, 0xF3, 0xFD, 0xA7, 0xA9, 0xBB, 0xB5, 0x9F, 0x91, 0x83, 0x8D
|
||||
};
|
||||
@@ -0,0 +1,281 @@
|
||||
#include "blowfish.h"
|
||||
#include <memory.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#define _bswap _byteswap_ulong
|
||||
#elif defined(__GNUC__)
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
const uint32_t accelc_Blowfish_Original_PBox[18] = {
|
||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
|
||||
0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B
|
||||
};
|
||||
|
||||
const uint32_t accelc_Blowfish_Original_SBox[4][256] = {
|
||||
{
|
||||
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
|
||||
0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
|
||||
0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
|
||||
0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
|
||||
0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239, 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
|
||||
0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3, 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
|
||||
0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
|
||||
0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463, 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
|
||||
0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3, 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
|
||||
0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82, 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB, 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
|
||||
0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B, 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
|
||||
0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4, 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
|
||||
0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299, 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
|
||||
0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF, 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
|
||||
0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA, 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
|
||||
0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400, 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664, 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
|
||||
},
|
||||
|
||||
{
|
||||
0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1, 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
|
||||
0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1, 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
|
||||
0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737, 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
|
||||
0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41, 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
|
||||
0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF, 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
|
||||
0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C, 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16, 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
|
||||
0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B, 0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509, 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E, 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
|
||||
0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F, 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A, 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4, 0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
|
||||
0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66, 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28, 0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802, 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
|
||||
0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510, 0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF, 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14, 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
|
||||
0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50, 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7, 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8, 0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
|
||||
0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99, 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696, 0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128, 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
|
||||
0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0, 0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0, 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105, 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
|
||||
0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3, 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285, 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00, 0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
|
||||
0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB, 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E, 0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735, 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
|
||||
0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9, 0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340, 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20, 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
|
||||
},
|
||||
|
||||
{
|
||||
0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068, 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF, 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
|
||||
0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45, 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504, 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A, 0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
|
||||
0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE, 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6, 0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42, 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
|
||||
0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2, 0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB, 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527, 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
|
||||
0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33, 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C, 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3, 0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
|
||||
0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17, 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564, 0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B, 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
|
||||
0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922, 0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728, 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0, 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
|
||||
0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37, 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D, 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804, 0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
|
||||
0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3, 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB, 0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D, 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
|
||||
0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350, 0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9, 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A, 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
|
||||
0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D, 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC, 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F, 0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
|
||||
0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2, 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9, 0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2, 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
|
||||
0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E, 0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633, 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10, 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
|
||||
0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52, 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027, 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5, 0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
|
||||
0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634, 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76, 0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24, 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
|
||||
0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4, 0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C, 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837, 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
|
||||
},
|
||||
|
||||
{
|
||||
0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE, 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B, 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
|
||||
0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8, 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6, 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304, 0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
|
||||
0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4, 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6, 0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9, 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
|
||||
0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593, 0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51, 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28, 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
|
||||
0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B, 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28, 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C, 0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
|
||||
0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A, 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319, 0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB, 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
|
||||
0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991, 0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32, 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680, 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
|
||||
0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE, 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB, 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5, 0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
|
||||
0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370, 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D, 0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84, 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
|
||||
0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8, 0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD, 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9, 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
|
||||
0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38, 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F, 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C, 0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
|
||||
0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1, 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442, 0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964, 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
|
||||
0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8, 0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D, 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F, 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
|
||||
0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02, 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC, 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614, 0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
|
||||
0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6, 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B, 0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0, 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
|
||||
0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E, 0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9, 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F, 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
|
||||
}
|
||||
};
|
||||
|
||||
#define f_transform(_x, _S) ((((_S)[0][(_x)[3]] + (_S)[1][(_x)[2]]) ^ (_S)[2][(_x)[1]]) + (_S)[3][(_x)[0]])
|
||||
|
||||
void accelc_Blowfish_encrypt(uint8_t srcBytes[8],
|
||||
const BLOWFISH_KEY* srcKey,
|
||||
int Endian) {
|
||||
uint32_t* const L = (uint32_t*)srcBytes;
|
||||
uint32_t* const R = (uint32_t*)(srcBytes + 4);
|
||||
|
||||
if (Endian == BLOWFISH_BIG_ENDIAN) {
|
||||
*L = _bswap(*L);
|
||||
*R = _bswap(*R);
|
||||
}
|
||||
|
||||
*L ^= srcKey->SubKey[0];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[1];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[2];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[3];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[4];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[5];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[6];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[7];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[8];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[9];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[10];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[11];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[12];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[13];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[14];
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
|
||||
*R ^= srcKey->SubKey[15];
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
|
||||
*L ^= srcKey->SubKey[16];
|
||||
*R ^= srcKey->SubKey[17];
|
||||
|
||||
uint32_t temp = *R;
|
||||
*R = *L;
|
||||
*L = temp;
|
||||
|
||||
if (Endian == BLOWFISH_BIG_ENDIAN) {
|
||||
*L = _bswap(*L);
|
||||
*R = _bswap(*R);
|
||||
}
|
||||
}
|
||||
|
||||
void accelc_Blowfish_decrypt(uint8_t srcBytes[8],
|
||||
const BLOWFISH_KEY* srcKey,
|
||||
int Endian) {
|
||||
uint32_t* const L = (uint32_t*)srcBytes;
|
||||
uint32_t* const R = (uint32_t*)(srcBytes + 4);
|
||||
|
||||
if (Endian == BLOWFISH_BIG_ENDIAN) {
|
||||
*L = _bswap(*L);
|
||||
*R = _bswap(*R);
|
||||
}
|
||||
|
||||
uint32_t temp = *R;
|
||||
*R = *L;
|
||||
*L = temp;
|
||||
|
||||
*L ^= srcKey->SubKey[16];
|
||||
*R ^= srcKey->SubKey[17];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[15];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[14];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[13];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[12];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[11];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[10];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[9];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[8];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[7];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[6];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[5];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[4];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[3];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[2];
|
||||
|
||||
*L ^= f_transform(srcBytes + 4, srcKey->SBox);
|
||||
*R ^= srcKey->SubKey[1];
|
||||
|
||||
*R ^= f_transform(srcBytes, srcKey->SBox);
|
||||
*L ^= srcKey->SubKey[0];
|
||||
|
||||
if (Endian == BLOWFISH_BIG_ENDIAN) {
|
||||
*L = _bswap(*L);
|
||||
*R = _bswap(*R);
|
||||
}
|
||||
}
|
||||
|
||||
int accelc_Blowfish_set_key(const uint8_t srcUserKey[], uint8_t UserKeyLength,
|
||||
BLOWFISH_KEY* dstKey) {
|
||||
if (UserKeyLength == 0)
|
||||
return STATUS_BLOWFISH_INVALID_KEY_LENGTH;
|
||||
if (UserKeyLength > BLOWFISH_MAX_KEY_LENGTH)
|
||||
return STATUS_BLOWFISH_KEY_TOO_LONG;
|
||||
|
||||
memcpy(dstKey->SubKey, accelc_Blowfish_Original_PBox, sizeof(accelc_Blowfish_Original_PBox));
|
||||
memcpy(dstKey->SBox, accelc_Blowfish_Original_SBox, sizeof(accelc_Blowfish_Original_SBox));
|
||||
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
uint32_t temp = 0;
|
||||
|
||||
temp <<= 8;
|
||||
temp |= srcUserKey[(i * 4) % UserKeyLength];
|
||||
|
||||
temp <<= 8;
|
||||
temp |= srcUserKey[(i * 4 + 1) % UserKeyLength];
|
||||
|
||||
temp <<= 8;
|
||||
temp |= srcUserKey[(i * 4 + 2) % UserKeyLength];
|
||||
|
||||
temp <<= 8;
|
||||
temp |= srcUserKey[(i * 4 + 3) % UserKeyLength];
|
||||
|
||||
dstKey->SubKey[i] ^= temp;
|
||||
}
|
||||
|
||||
uint8_t temp[8] = { 0 };
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
accelc_Blowfish_encrypt(temp, dstKey, BLOWFISH_LITTLE_ENDIAN);
|
||||
((uint64_t*)dstKey->SubKey)[i] = *(uint64_t*)temp;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 512; ++i) {
|
||||
accelc_Blowfish_encrypt(temp, dstKey, BLOWFISH_LITTLE_ENDIAN);
|
||||
((uint64_t*)dstKey->SBox)[i] = *(uint64_t*)temp;
|
||||
}
|
||||
|
||||
return STATUS_BLOWFISH_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define STATUS_BLOWFISH_SUCCESS 0
|
||||
#define STATUS_BLOWFISH_INVALID_KEY_LENGTH (-1)
|
||||
#define STATUS_BLOWFISH_KEY_TOO_LONG (-2)
|
||||
|
||||
#define BLOWFISH_LITTLE_ENDIAN 0
|
||||
#define BLOWFISH_BIG_ENDIAN 1
|
||||
|
||||
#define BLOWFISH_MIN_KEY_LENGTH 1
|
||||
#define BLOWFISH_MAX_KEY_LENGTH 56
|
||||
|
||||
#define BLOWFISH_BLOCK_SIZE 8
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _BLOWFISH_KEY {
|
||||
uint32_t SubKey[18];
|
||||
uint32_t SBox[4][256];
|
||||
} BLOWFISH_KEY;
|
||||
|
||||
void accelc_Blowfish_encrypt(uint8_t srcBytes[8],
|
||||
const BLOWFISH_KEY* srcKey,
|
||||
int Endian);
|
||||
|
||||
void accelc_Blowfish_decrypt(uint8_t srcBytes[8],
|
||||
const BLOWFISH_KEY* srcKey,
|
||||
int Endian);
|
||||
|
||||
int accelc_Blowfish_set_key(const uint8_t srcUserKey[], uint8_t UserKeyLength,
|
||||
BLOWFISH_KEY* dstKey);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "sha1.h"
|
||||
#include <memory.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#define _bswap _byteswap_ulong
|
||||
#define _bswap64 _byteswap_uint64
|
||||
#elif defined(__GNUC__)
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
#define SHA1_BLOCKSIZE 64
|
||||
|
||||
void accelc_SHA1_init(SHA1_BUFFER* HashBuffer) {
|
||||
HashBuffer->dword[0] = 0x67452301;
|
||||
HashBuffer->dword[1] = 0xEFCDAB89;
|
||||
HashBuffer->dword[2] = 0x98BADCFE;
|
||||
HashBuffer->dword[3] = 0x10325476;
|
||||
HashBuffer->dword[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
void accelc_SHA1_update(const void* __restrict srcBytes, size_t srcBytesLength,
|
||||
SHA1_BUFFER* __restrict HashBuffer) {
|
||||
uint32_t Buffer[80] = { 0 };
|
||||
uint32_t a, b, c, d, e;
|
||||
const uint32_t (*MessageBlock)[16] = srcBytes;
|
||||
|
||||
size_t RoundsOfMainCycle = srcBytesLength / SHA1_BLOCKSIZE;
|
||||
for (size_t i = 0; i < RoundsOfMainCycle; ++i) {
|
||||
|
||||
for (int j = 0; j < 16; ++j)
|
||||
Buffer[j] = _bswap(MessageBlock[i][j]);
|
||||
|
||||
for (int j = 16; j < 80; ++j) {
|
||||
uint32_t temp = Buffer[j - 3] ^ Buffer[j - 8] ^ Buffer[j - 14] ^ Buffer[j - 16];
|
||||
Buffer[j] = _rotl(temp, 1);
|
||||
}
|
||||
a = HashBuffer->dword[0];
|
||||
b = HashBuffer->dword[1];
|
||||
c = HashBuffer->dword[2];
|
||||
d = HashBuffer->dword[3];
|
||||
e = HashBuffer->dword[4];
|
||||
|
||||
for (int j = 0; j < 20; ++j) {
|
||||
uint32_t T = _rotl(a, 5);
|
||||
T += ((b & c) ^ (~b & d)) + e + 0x5A827999 + Buffer[j];
|
||||
e = d;
|
||||
d = c;
|
||||
c = _rotl(b, 30);
|
||||
b = a;
|
||||
a = T;
|
||||
}
|
||||
for (int j = 20; j < 40; ++j) {
|
||||
uint32_t T = _rotl(a, 5);
|
||||
T += (b ^ c ^ d) + e + 0x6ED9EBA1 + Buffer[j];
|
||||
e = d;
|
||||
d = c;
|
||||
c = _rotl(b, 30);
|
||||
b = a;
|
||||
a = T;
|
||||
}
|
||||
for (int j = 40; j < 60; ++j) {
|
||||
uint32_t T = _rotl(a, 5);
|
||||
T += ((b & c) ^ (b & d) ^ (c & d)) + e + 0x8F1BBCDC + Buffer[j];
|
||||
e = d;
|
||||
d = c;
|
||||
c = _rotl(b, 30);
|
||||
b = a;
|
||||
a = T;
|
||||
}
|
||||
for (int j = 60; j < 80; ++j) {
|
||||
uint32_t T = _rotl(a, 5);
|
||||
T += (b ^ c ^ d) + e + 0xCA62C1D6 + Buffer[j];
|
||||
e = d;
|
||||
d = c;
|
||||
c = _rotl(b, 30);
|
||||
b = a;
|
||||
a = T;
|
||||
}
|
||||
HashBuffer->dword[0] += a;
|
||||
HashBuffer->dword[1] += b;
|
||||
HashBuffer->dword[2] += c;
|
||||
HashBuffer->dword[3] += d;
|
||||
HashBuffer->dword[4] += e;
|
||||
}
|
||||
}
|
||||
|
||||
void accelc_SHA1_final(const void* __restrict LeftBytes, size_t LeftBytesLength, uint64_t TotalBytesLength,
|
||||
const SHA1_BUFFER* HashBuffer, SHA1_DIGEST* Hash) {
|
||||
if (HashBuffer != Hash)
|
||||
memcpy(Hash, HashBuffer, sizeof(SHA1_BUFFER));
|
||||
|
||||
if (LeftBytesLength >= SHA1_BLOCKSIZE) {
|
||||
accelc_SHA1_update(LeftBytes, LeftBytesLength, Hash);
|
||||
LeftBytes = (const uint8_t*)LeftBytes + (LeftBytesLength / SHA1_BLOCKSIZE) * SHA1_BLOCKSIZE;
|
||||
LeftBytesLength %= SHA1_BLOCKSIZE;
|
||||
}
|
||||
|
||||
uint8_t Extra[128] = { 0 };
|
||||
for (size_t i = 0; i < LeftBytesLength; ++i)
|
||||
Extra[i] = ((const uint8_t*)LeftBytes)[i];
|
||||
|
||||
Extra[LeftBytesLength] = 0x80;
|
||||
*(uint64_t*)(Extra + (LeftBytesLength >= 64 - 8 ? 128 - 8 : 64 - 8)) = _bswap64(TotalBytesLength * 8);
|
||||
|
||||
accelc_SHA1_update(Extra, LeftBytesLength >= 56 ? 128 : 64, Hash);
|
||||
|
||||
Hash->dword[0] = _bswap(Hash->dword[0]);
|
||||
Hash->dword[1] = _bswap(Hash->dword[1]);
|
||||
Hash->dword[2] = _bswap(Hash->dword[2]);
|
||||
Hash->dword[3] = _bswap(Hash->dword[3]);
|
||||
Hash->dword[4] = _bswap(Hash->dword[4]);
|
||||
}
|
||||
|
||||
void accelc_SHA1(const void* __restrict srcBytes, size_t srclen,
|
||||
SHA1_DIGEST* __restrict Hash) {
|
||||
accelc_SHA1_init(Hash);
|
||||
accelc_SHA1_update(srcBytes, srclen, Hash);
|
||||
accelc_SHA1_final((uint8_t*)srcBytes + (srclen / SHA1_BLOCKSIZE) * SHA1_BLOCKSIZE, srclen % SHA1_BLOCKSIZE, srclen, Hash, Hash);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SHA1_DIGEST {
|
||||
union {
|
||||
uint8_t byte[20];
|
||||
uint32_t dword[5];
|
||||
};
|
||||
} SHA1_DIGEST, SHA1_BUFFER;
|
||||
|
||||
void accelc_SHA1_init(SHA1_BUFFER* HashBuffer);
|
||||
|
||||
void accelc_SHA1_update(const void* __restrict srcBytes, size_t srcBytesLength,
|
||||
SHA1_BUFFER* __restrict HashBuffer);
|
||||
|
||||
void accelc_SHA1_final(const void* __restrict LeftBytes, size_t LeftBytesLength, uint64_t TotalBytesLength,
|
||||
const SHA1_BUFFER* HashBuffer, SHA1_DIGEST* Hash);
|
||||
|
||||
void accelc_SHA1(const void* __restrict srcBytes, size_t srclen,
|
||||
SHA1_DIGEST* __restrict Hash);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -1,78 +0,0 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const char PatchSolution0::Keyword[452] =
|
||||
"-----BEGIN PUBLIC KEY-----\x00"
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw1dqF3SkCaAAmMzs889I\x00"
|
||||
"qdW9M2dIdh3jG9yPcmLnmJiGpBF4E9VHSMGe8oPAy2kJDmdNt4BcEygvssEfginv\x00"
|
||||
"a5t5jm352UAoDosUJkTXGQhpAWMF4fBmBpO3EedG62rOsqMBgmSdAyxCSPBRJIOF\x00"
|
||||
"R0QgZFbRnU0frj34fiVmgYiLuZSAmIbs8ZxiHPdp1oD4tUpvsFci4QJtYNjNnGU2\x00"
|
||||
"WPH6rvChGl1IRKrxMtqLielsvajUjyrgOC6NmymYMvZNER3htFEtL1eQbCyTfDmt\x00"
|
||||
"YyQ1Wt4Ot12lxf0wVIR5mcGN7XCXJRHOFHSf1gzXWabRSvmt1nrl7sW6cjxljuuQ\x00"
|
||||
"awIDAQAB\x00"
|
||||
"-----END PUBLIC KEY-----\x00";
|
||||
|
||||
PatchSolution0::PatchSolution0(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_PatchOffset(X64ImageInterpreter::InvalidOffset) {}
|
||||
|
||||
bool PatchSolution0::FindPatchOffset() noexcept {
|
||||
try {
|
||||
pvt_PatchOffset = pvt_Image.SearchSectionOffset("__TEXT", "__cstring", [](const uint8_t* p) {
|
||||
return memcmp(p, Keyword, sizeof(Keyword) - 1) == 0;
|
||||
});
|
||||
|
||||
printf("[+] PatchSolution0 ...... Ready to apply.\n");
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_PatchOffset);
|
||||
return true;
|
||||
} catch (...) {
|
||||
printf("[-] PatchSolution0 ...... Omitted.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PatchSolution0::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
try {
|
||||
if (RsaCipher.Bits() != 2048) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (c == '\n') c = '\x00';
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == sizeof(Keyword) - 1;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PatchSolution0::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_PatchOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution0 is not ready.");
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (c == '\n') c = '\x00';
|
||||
}
|
||||
|
||||
auto pbPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_PatchOffset);
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution0 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_PatchOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
memcpy(pbPatch, PublicKeyPEM.data(), PublicKeyPEM.size());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const uint8_t PatchSolution1::Keyword[0x188] = {
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xfe, 0xd2, 0xf8, 0xf4, 0xf1, 0xd3, 0xde, 0xc7, 0xdf, 0xd3, 0xd0, 0xfd,
|
||||
0x8a, 0xc3, 0x85, 0xf4, 0xf6, 0xe9, 0xfc, 0xfc, 0xf2, 0xf5, 0xfa, 0xf5, 0xf6, 0xe9, 0x81, 0xfb,
|
||||
0xfe, 0xfd, 0xfc, 0xf4, 0xf4, 0xdf, 0xf2, 0xf9, 0xf2, 0xe5, 0xf0, 0xf7, 0xc0, 0x89, 0xdd, 0xcb,
|
||||
0xf5, 0x87, 0xe6, 0xdd, 0xf4, 0xd9, 0xf8, 0xfb, 0xde, 0xf9, 0xcf, 0xc5, 0x8f, 0x80, 0x80, 0xf3,
|
||||
0xc2, 0xd0, 0xe2, 0x8f, 0xfa, 0x8a, 0xdd, 0xf3, 0xd7, 0xdc, 0x86, 0xdc, 0xf0, 0x81, 0xc0, 0xea,
|
||||
0xd0, 0xd9, 0xf9, 0xd8, 0xda, 0xf2, 0xd0, 0xfd, 0xc3, 0xf6, 0xf3, 0x82, 0xf2, 0x81, 0xef, 0xf2,
|
||||
0xe0, 0xf9, 0xf2, 0xd3, 0x8f, 0xd7, 0xe9, 0xfb, 0xca, 0x86, 0xde, 0xfc, 0xf3, 0xd5, 0xdd, 0xf4,
|
||||
0xc7, 0x80, 0xf7, 0xd5, 0xf2, 0xc1, 0xde, 0xcc, 0xc0, 0xc7, 0xf0, 0xd0, 0xd0, 0xd1, 0xd7, 0xcc,
|
||||
0xd2, 0x81, 0xc1, 0x83, 0xdd, 0xd5, 0x8a, 0x8f, 0x81, 0xe1, 0xf4, 0xd9, 0xf3, 0xd7, 0xca, 0xef,
|
||||
0xf9, 0xdf, 0xe1, 0xee, 0xf0, 0xe9, 0xd1, 0xca, 0xf2, 0xe3, 0xf8, 0xf0, 0x83, 0xde, 0xfb, 0xd7,
|
||||
0xf1, 0xc4, 0xfa, 0x85, 0xf2, 0xdd, 0xdd, 0xfd, 0x85, 0x86, 0xc7, 0xf9, 0xc4, 0xc9, 0xf4, 0xf8,
|
||||
0xd4, 0xd9, 0xe6, 0xd2, 0xf6, 0xc1, 0xc1, 0xf9, 0xe0, 0xe4, 0xf7, 0xe4, 0xfd, 0xf1, 0xf6, 0xfc,
|
||||
0xe1, 0x84, 0xe4, 0xd1, 0xed, 0xfe, 0xdb, 0xe8, 0xdd, 0xe1, 0x85, 0xd0, 0xc5, 0xd2, 0x8a, 0x8e,
|
||||
0xd5, 0xdd, 0xe3, 0xdb, 0xd0, 0xe1, 0xd0, 0xf6, 0xc6, 0xee, 0xe6, 0xf7, 0xda, 0xf1, 0xdb, 0xc9,
|
||||
0x8b, 0xee, 0xcd, 0xdf, 0xff, 0xe8, 0xdd, 0xca, 0x82, 0xdb, 0xf1, 0x82, 0xc3, 0xed, 0xc9, 0xcc,
|
||||
0xc0, 0xf2, 0xd6, 0xdf, 0x83, 0xe9, 0xf3, 0xce, 0xea, 0xfa, 0xdf, 0xf8, 0xd9, 0xff, 0xec, 0x88,
|
||||
0xe4, 0xe4, 0xfd, 0x80, 0xc5, 0xce, 0xfa, 0xd2, 0xf4, 0xd8, 0x84, 0xff, 0xe5, 0xf3, 0xcb, 0xc2,
|
||||
0xfe, 0xc0, 0xc4, 0xfa, 0xde, 0xdd, 0xd5, 0xc9, 0xc5, 0xd5, 0xdf, 0xe3, 0xdd, 0xc1, 0xcb, 0xdd,
|
||||
0xfc, 0xf7, 0x83, 0xf8, 0xda, 0xc1, 0xd4, 0xe3, 0xfe, 0xc2, 0xef, 0xf8, 0xf2, 0xea, 0x8a, 0xd2,
|
||||
0xc7, 0xf2, 0xf0, 0xc2, 0xfb, 0x89, 0xdc, 0xeb, 0xd1, 0xf7, 0xcc, 0xe2, 0xd1, 0xfc, 0xd4, 0xce,
|
||||
0xea, 0xcd, 0xe4, 0x87, 0xe0, 0xcc, 0x8d, 0xf5, 0xc7, 0x85, 0x87, 0xda, 0xcf, 0xde, 0x89, 0xcd,
|
||||
0xe5, 0xfd, 0xe7, 0x83, 0xda, 0xdb, 0xfe, 0xf4, 0x84, 0xec, 0xf6, 0xee, 0xfd, 0xea, 0xf1, 0xf5,
|
||||
0xf5, 0xfc, 0xe6, 0xd0, 0x86, 0xdf, 0xc3, 0xe2, 0xe4, 0xd5, 0xd7, 0xe4, 0xe4, 0xce, 0xd4, 0xce,
|
||||
0x82, 0xda, 0xc7, 0xda, 0x80, 0xcb, 0xee, 0x8c, 0xd0, 0xde, 0xcd, 0xda, 0xdd, 0xcd, 0xcc, 0xeb,
|
||||
0xd2, 0xc3, 0xfc, 0xf2, 0xf6, 0xe9, 0xf8, 0xf8
|
||||
};
|
||||
|
||||
PatchSolution1::PatchSolution1(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_PatchOffset(X64ImageInterpreter::InvalidOffset) {}
|
||||
|
||||
bool PatchSolution1::FindPatchOffset() noexcept {
|
||||
uint8_t* pbPatch = nullptr;
|
||||
|
||||
for (size_t i = 0; i < pvt_Image.NumberOfSections(); ++i) {
|
||||
auto pbSectionView = pvt_Image.SectionView<uint8_t*>(i);
|
||||
auto cbSectiveView = pvt_Image.ImageSection(i)->size;
|
||||
|
||||
if (cbSectiveView < sizeof(Keyword)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < cbSectiveView - sizeof(Keyword); ++j) {
|
||||
if (memcmp(pbSectionView + j, Keyword, sizeof(Keyword)) == 0) {
|
||||
pbPatch = pbSectionView + j;
|
||||
i = pvt_Image.NumberOfSections();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pbPatch == nullptr) {
|
||||
printf("[-] PatchSolution1 ...... Omitted.\n");
|
||||
return false;
|
||||
} else {
|
||||
pvt_PatchOffset = pbPatch - pvt_Image.ImageBase<uint8_t*>();
|
||||
|
||||
printf("[+] PatchSolution1 ...... Ready to apply.\n");
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_PatchOffset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PatchSolution1::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
try {
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == sizeof(Keyword);
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PatchSolution1::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_PatchOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution1 is not ready.");
|
||||
}
|
||||
|
||||
auto pbPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_PatchOffset);
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t key = 8;
|
||||
for (auto& c : PublicKeyPEM) {
|
||||
if (key == 0) key = 8;
|
||||
reinterpret_cast<uint8_t&>(c) ^= 0xbbu - key;
|
||||
--key;
|
||||
}
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution1 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_PatchOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
memcpy(pbPatch, PublicKeyPEM.data(), PublicKeyPEM.length());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbPatch, pbPatch + sizeof(Keyword), pbPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
|
||||
@@ -1,254 +0,0 @@
|
||||
#include "PatchSolutions.hpp"
|
||||
#include <memory.h>
|
||||
|
||||
const char PatchSolution2::Keyword[1114] =
|
||||
"BIjWyoeRR0NBgkqnDZWxCgKCEAw1dqF3DTvOB91ZHwecJYFrdM1KEh"
|
||||
"1yVeRoGqSdLLGZGUlngig3OD5mMzs889IqWqqfHSeHMvzyg1p6UPCY"
|
||||
"nesxa9M2dDUrXHomRHOFHSfsbSXRFwt5GivtnJG9lLJHZ7XWeIQABi"
|
||||
"dKionYD3O6c9tvUAoDosUJAdQ1RaSXTzyETbHTRtnTPeLpO3EedGMs"
|
||||
"v3jG9yPcmmdYkddSeJRwn2raPJmnvdHScHUACw0sUNuosAqPaQbTQN"
|
||||
"PATDzcrnd1Sf8RIbUp4MQJFVJugPLVZbP53Gjtyyniqe5q75kva8Qm"
|
||||
"Hr1uOuXkVppe3cwECaGamupG43L1XfcpRjCMrxRep3s2VlbL01xmfz"
|
||||
"5cIhrj34iVmgZSAmIb8ZxiHPdp1oDMFkbNetZyWegqjAHQQ9eoSOTD"
|
||||
"bERbKEwZ5FLeLsbNAxfqsapB1XBvCavFHualx6bxVxuRQceh4z8kaZ"
|
||||
"iv2pOKbZQSJ2Dx5HEq0bYZ6y6b7sN9IaeDFNQwjzQn1K7k3XlYAPWC"
|
||||
"IvDe8Ln0FUe4yMNmuUhu5RTjxE05hUqtz1HjJvYQ9Es1VA6LflKQ87"
|
||||
"TwIXBNvfrcHaZ72QM4dQtDUyEMrLgMDkJBDM9wqIDps65gSlAz6eHD"
|
||||
"8tYWUttrWose0cH0yykVnqFzPtdRiZyZRfio6lGyK48mIC9z7T6MN3"
|
||||
"a7OaLZHZSwzcpQLcGi7M9q1wXLq4Ms1UvlwntB9FLHc63tHPpG8rhn"
|
||||
"XhZIk4QrSm4GYuEKQVHwku6ulw6wfggVL8FZPhoPCGsrb2rQGurBUL"
|
||||
"3lkVJ6RO9VGHcczDYomXqAJqlt4y9pkQIj9kgwTrxTzEZgMGdYZqsV"
|
||||
"4Bd5JjtrL7u3LA0N2Hq9Xvmmis2jDVhSQoUoGukNIoqng3SBsf0E7b"
|
||||
"4W0S1aZSSOJ90nQHQkQShE9YIMDBbNwIg2ncthwADYqibYUgIvJcK9"
|
||||
"89XHnYmZsdMWtt53lICsXE1vztR5WrQjSw4WXDiB31LXTrvudCB6vw"
|
||||
"kCQa4leutETpKLJ2bYaOYBdoiBFOwvf36YaSuRoY4SP2x1pWOwGFTg"
|
||||
"d90J2uYyCqUa3Q3iX52iigT4EKL2vJKdJ";
|
||||
|
||||
const uint8_t PatchSolution2::FunctionHeader[9] = {
|
||||
0x55, // push rbp
|
||||
0x48, 0x89, 0xe5, // mov rbp, rsp
|
||||
0x41, 0x57, // push r15
|
||||
0x41, 0x56, // push r14
|
||||
0x53, // push rbx
|
||||
};
|
||||
|
||||
PatchSolution2::PatchSolution2(const X64ImageInterpreter& Image) noexcept :
|
||||
pvt_Image(Image),
|
||||
pvt_Disassembler(CapstoneDisassembler::Create(CS_ARCH_X86, CS_MODE_64)),
|
||||
pvt_Assembler(KeystoneAssembler::Create(KS_ARCH_X86, KS_MODE_64)),
|
||||
pvt_FunctionOffset(X64ImageInterpreter::InvalidOffset),
|
||||
pvt_KeywordOffset(X64ImageInterpreter::InvalidOffset),
|
||||
pvt_StdStringAppendStubRva(X64ImageInterpreter::InvalidAddress)
|
||||
{
|
||||
pvt_Disassembler.Option(CS_OPT_DETAIL, CS_OPT_ON);
|
||||
}
|
||||
|
||||
bool PatchSolution2::FindPatchOffset() noexcept {
|
||||
auto FunctionOffset = X64ImageInterpreter::InvalidOffset;
|
||||
auto KeywordOffset = X64ImageInterpreter::InvalidOffset;
|
||||
auto StdStringAppendStubRva = X64ImageInterpreter::InvalidAddress;
|
||||
|
||||
try {
|
||||
auto Sec__text = pvt_Image.ImageSection("__TEXT", "__text");
|
||||
auto Sec__const = pvt_Image.ImageSection("__TEXT", "__const");
|
||||
auto Sec__stubs = pvt_Image.ImageSection("__TEXT", "__stubs");
|
||||
auto SecView__text = pvt_Image.SectionView<uint8_t*>(Sec__text);
|
||||
auto SecView__const = pvt_Image.SectionView<uint8_t*>(Sec__const);
|
||||
auto SecView__stubs = pvt_Image.SectionView<uint8_t*>(Sec__stubs);
|
||||
|
||||
KeywordOffset = pvt_Image.SearchSectionOffset("__TEXT", "__const", [](const uint8_t* p) {
|
||||
return memcmp(p, Keyword, sizeof(Keyword)) == 0;
|
||||
});
|
||||
|
||||
auto KeywordRva = pvt_Image.OffsetToRva(KeywordOffset);
|
||||
|
||||
auto Hint = pvt_Image.SearchSectionOffset("__TEXT", "__text", [Sec__text, SecView__text, KeywordRva](const uint8_t* p) {
|
||||
auto rip = (p - SecView__text) + Sec__text->addr + 4;
|
||||
auto off = *reinterpret_cast<const uint32_t*>(p);
|
||||
return rip + off == KeywordRva;
|
||||
}) - 0xc0;
|
||||
|
||||
for (uint32_t i = 0; i < 0xc0; ++i) {
|
||||
if (memcmp(pvt_Image.ImageOffset(Hint + i), FunctionHeader, sizeof(FunctionHeader)) == 0) {
|
||||
FunctionOffset = Hint + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (FunctionOffset == X64ImageInterpreter::InvalidOffset) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not found.");
|
||||
}
|
||||
|
||||
pvt_Disassembler.SetContext(SecView__stubs, Sec__stubs->size, Sec__stubs->addr);
|
||||
while (pvt_Disassembler.Next()) {
|
||||
auto insn = pvt_Disassembler.GetInstruction();
|
||||
|
||||
//
|
||||
// As far as I know, all stub functions have a pattern looking like:
|
||||
// jmp qword ptr [RIP + xxxx]
|
||||
//
|
||||
if (strcasecmp(insn->mnemonic, "jmp") == 0 && insn->detail->x86.operands[0].type == X86_OP_MEM && insn->detail->x86.operands[0].mem.base == X86_REG_RIP) {
|
||||
uint64_t la_symbol_ptr_rva = pvt_Disassembler.GetContext().Address + insn->detail->x86.operands[0].mem.disp;
|
||||
uint32_t la_symbol_ptr_offset = pvt_Image.RvaToOffset(la_symbol_ptr_rva);
|
||||
if (la_symbol_ptr_offset == X64ImageInterpreter::InvalidOffset)
|
||||
continue;
|
||||
|
||||
uint64_t stub_helper_rva = *pvt_Image.ImageOffset<const uint64_t*>(la_symbol_ptr_offset);
|
||||
uint32_t stub_helper_offset = pvt_Image.RvaToOffset(stub_helper_rva);
|
||||
if (stub_helper_offset == X64ImageInterpreter::InvalidOffset)
|
||||
continue;
|
||||
|
||||
//
|
||||
// __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
|
||||
// is the mangled name of "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*)",
|
||||
// which is, as known as, "std::string::append(const char*)"
|
||||
// You can demangle it by c++flit
|
||||
// e.g.
|
||||
// c++filt -_ '__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc'
|
||||
//
|
||||
if (nkg::IsResolvedTo(pvt_Image, pvt_Image.ImageOffset(stub_helper_offset), "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc")) {
|
||||
auto StdStringAppendStubOffset = pvt_Disassembler.GetInstructionContext().pbOpcode - pvt_Image.ImageBase<const uint8_t*>();
|
||||
StdStringAppendStubRva = pvt_Image.OffsetToRva(StdStringAppendStubOffset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StdStringAppendStubRva == X64ImageInterpreter::InvalidAddress) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Not found.");
|
||||
}
|
||||
|
||||
pvt_FunctionOffset = FunctionOffset;
|
||||
pvt_KeywordOffset = KeywordOffset;
|
||||
pvt_StdStringAppendStubRva = StdStringAppendStubRva;
|
||||
|
||||
printf("[+] PatchSolution2 ...... Ready to apply.\n");
|
||||
printf(" Function offset = +0x%.8x\n", pvt_FunctionOffset);
|
||||
printf(" Keyword offset = +0x%.8x\n", pvt_KeywordOffset);
|
||||
printf(" std::string::append(const char*) RVA = 0x%.16llx\n", pvt_StdStringAppendStubRva);
|
||||
return true;
|
||||
} catch (...) {
|
||||
printf("[-] PatchSolution2 ...... Omitted.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool PatchSolution2::CheckKey(const RSACipher& RsaCipher) const noexcept {
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PublicKeyPEM.length() == 0x188;
|
||||
}
|
||||
|
||||
void PatchSolution2::MakePatch(const RSACipher& RsaCipher) const {
|
||||
if (pvt_FunctionOffset == X64ImageInterpreter::InvalidOffset ||
|
||||
pvt_KeywordOffset == X64ImageInterpreter::InvalidOffset ||
|
||||
pvt_StdStringAppendStubRva == X64ImageInterpreter::InvalidAddress)
|
||||
{
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "PatchSolution2 is not ready.");
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare public key string
|
||||
//
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----BEGIN PUBLIC KEY-----"), 26);
|
||||
PublicKeyPEM.erase(PublicKeyPEM.find("-----END PUBLIC KEY-----"), 24);
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = PublicKeyPEM.find('\n', pos)) != std::string::npos) {
|
||||
PublicKeyPEM.erase(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare new function opcodes
|
||||
//
|
||||
uint64_t FunctionRVA = pvt_Image.OffsetToRva(pvt_FunctionOffset);
|
||||
uint64_t KeywordRVA = pvt_Image.OffsetToRva(pvt_KeywordOffset);
|
||||
|
||||
char AssemblyCode[512] = {};
|
||||
sprintf(AssemblyCode,
|
||||
"push rbp;"
|
||||
"mov rbp, rsp;"
|
||||
"push r15;"
|
||||
"push r14;"
|
||||
"push rbx;"
|
||||
"sub rsp, 0x48;"
|
||||
|
||||
"mov rbx, rdi;"
|
||||
|
||||
"xor rax, rax;" // initialize std::string with null
|
||||
"mov qword ptr[rsp], rax;"
|
||||
"mov qword ptr[rsp + 0x8], rax;"
|
||||
"mov qword ptr[rsp + 0x10], rax;"
|
||||
|
||||
"lea rdi, qword ptr[rsp];"
|
||||
"lea rsi, qword ptr[0x%.16llx];" // filled with address to Keyword
|
||||
"call 0x%.16llx;" // filled with address to std::string::append(const char*)
|
||||
|
||||
"mov rax, qword ptr[rsp];"
|
||||
"mov qword ptr[rbx], rax;"
|
||||
"mov rax, qword ptr[rsp + 0x8];"
|
||||
"mov qword ptr[rbx + 0x8], rax;"
|
||||
"mov rax, qword ptr[rsp + 0x10];"
|
||||
"mov qword ptr[rbx + 0x10], rax;"
|
||||
|
||||
"mov rax, rbx;"
|
||||
"add rsp, 0x48;"
|
||||
"pop rbx;"
|
||||
"pop r14;"
|
||||
"pop r15;"
|
||||
"pop rbp;"
|
||||
"ret;",
|
||||
KeywordRVA,
|
||||
pvt_StdStringAppendStubRva
|
||||
);
|
||||
|
||||
auto NewFunctionOpcode = pvt_Assembler.GenerateOpcode(AssemblyCode, FunctionRVA);
|
||||
|
||||
auto pbFunctionPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_FunctionOffset);
|
||||
auto pbKeywordPatch = pvt_Image.ImageOffset<uint8_t*>(pvt_KeywordOffset);
|
||||
|
||||
puts("**************************************************************");
|
||||
puts("* PatchSolution2 *");
|
||||
puts("**************************************************************");
|
||||
printf("@+0x%.8x\n", pvt_KeywordOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbKeywordPatch, pbKeywordPatch + sizeof(Keyword) - 1, pbKeywordPatch);
|
||||
|
||||
memcpy(pbKeywordPatch, PublicKeyPEM.c_str(), PublicKeyPEM.length() + 1); // with a null-terminator
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbKeywordPatch, pbKeywordPatch + sizeof(Keyword) - 1, pbKeywordPatch);
|
||||
|
||||
|
||||
|
||||
|
||||
puts("");
|
||||
printf("@+0x%.8x\n", pvt_FunctionOffset);
|
||||
|
||||
puts("Previous:");
|
||||
nkg::PrintMemory(pbFunctionPatch, pbFunctionPatch + NewFunctionOpcode.size(), pbFunctionPatch);
|
||||
|
||||
memcpy(pbFunctionPatch, NewFunctionOpcode.data(), NewFunctionOpcode.size());
|
||||
|
||||
puts("After:");
|
||||
nkg::PrintMemory(pbFunctionPatch, pbFunctionPatch + NewFunctionOpcode.size(), pbFunctionPatch);
|
||||
|
||||
puts("");
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
#pragma once
|
||||
#include "../common/Exception.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "../common/RSACipher.hpp"
|
||||
#include "ResourceTraitsUnix.hpp"
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
#include "CapstoneDisassembler.hpp"
|
||||
#include "KeystoneAssembler.hpp"
|
||||
|
||||
namespace nkg {
|
||||
//
|
||||
// Print memory data in [from, to) at least
|
||||
// If `base` is not nullptr, print address as offset. Otherwise, as absolute address.
|
||||
// NOTICE:
|
||||
// `base` must >= `from`
|
||||
//
|
||||
void PrintMemory(const void *from, const void *to, const void *base = nullptr);
|
||||
bool IsResolvedTo(const X64ImageInterpreter& Image, const void* StubHelperProc, const char *Symbol);
|
||||
}
|
||||
|
||||
class PatchSolution {
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool FindPatchOffset() noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept = 0;
|
||||
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const = 0;
|
||||
|
||||
virtual ~PatchSolution() = default;
|
||||
};
|
||||
|
||||
class PatchSolution0 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const char Keyword[452];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
uint32_t pvt_PatchOffset;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution0(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
class PatchSolution1 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const uint8_t Keyword[0x188];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
uint32_t pvt_PatchOffset;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution1(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
class PatchSolution2 : public PatchSolution {
|
||||
private:
|
||||
|
||||
static const char Keyword[1114];
|
||||
static const uint8_t FunctionHeader[9];
|
||||
|
||||
const X64ImageInterpreter& pvt_Image;
|
||||
CapstoneDisassembler pvt_Disassembler;
|
||||
KeystoneAssembler pvt_Assembler;
|
||||
uint32_t pvt_FunctionOffset;
|
||||
uint32_t pvt_KeywordOffset;
|
||||
uint64_t pvt_StdStringAppendStubRva;
|
||||
|
||||
public:
|
||||
|
||||
explicit
|
||||
PatchSolution2(const X64ImageInterpreter& Image) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool FindPatchOffset() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual bool CheckKey(const RSACipher& RsaCipher) const noexcept override;
|
||||
|
||||
// NOLINTNEXTLINE: mark "virtual" explicitly for more readability
|
||||
virtual void MakePatch(const RSACipher& RsaCipher) const override;
|
||||
};
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <capstone/capstone.h>
|
||||
#include "ExceptionCapstone.hpp"
|
||||
|
||||
struct CapstoneHandleTraits {
|
||||
using HandleType = csh;
|
||||
|
||||
static inline const HandleType InvalidValue = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(HandleType& Handle) {
|
||||
auto err = cs_close(&Handle);
|
||||
if (err != CS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::CapstoneError(__FILE__, __LINE__, err, "ks_close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CapstoneInsnTraits {
|
||||
using HandleType = cs_insn*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
cs_free(Handle, 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <keystone/keystone.h>
|
||||
#include "ExceptionKeystone.hpp"
|
||||
|
||||
struct KeystoneHandleTraits {
|
||||
using HandleType = ks_engine*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
auto err = ks_close(Handle);
|
||||
if (err != KS_ERR_OK) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::KeystoneError(__FILE__, __LINE__, err, "ks_close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct KeystoneMallocTraits {
|
||||
using HandleType = uint8_t*;
|
||||
|
||||
static inline const HandleType InvalidValue = nullptr;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) noexcept {
|
||||
ks_free(Handle);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <errno.h> // NOLINT
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include "../common/ExceptionSystem.hpp"
|
||||
|
||||
struct FileHandleTraits {
|
||||
using HandleType = int;
|
||||
|
||||
static inline const HandleType InvalidValue = -1;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
|
||||
static void Releasor(const HandleType& Handle) {
|
||||
if (close(Handle) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "close failed.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct MapViewTraits {
|
||||
using HandleType = void*;
|
||||
|
||||
static inline const HandleType InvalidValue = MAP_FAILED;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool IsValid(const HandleType& Handle) noexcept {
|
||||
return Handle != InvalidValue;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "def.hpp"
|
||||
|
||||
// Solution0 is for navicat premium of which the version < 12.0.25
|
||||
namespace patcher::Solution0 {
|
||||
|
||||
BOOL Do(LPCTSTR navicat_exe_path, LPCTSTR prepared_key_file) {
|
||||
if (!BackupFile(navicat_exe_path))
|
||||
return FALSE;
|
||||
|
||||
RSA* PrivateKey = nullptr;
|
||||
if (prepared_key_file == nullptr) {
|
||||
PrivateKey = GenerateRSAKey();
|
||||
if (PrivateKey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
if (!WriteRSAPrivateKeyToFile(TEXT("RegPrivateKey.pem"), PrivateKey)) {
|
||||
RSA_free(PrivateKey);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
PrivateKey = ReadRSAPrivateKeyFromFile(prepared_key_file);
|
||||
if (PrivateKey == nullptr)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char* pem_pubkey = GetPEMText(PrivateKey);
|
||||
if (pem_pubkey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
RSA_free(PrivateKey); // we do not need it anymore
|
||||
|
||||
HANDLE hUpdater = BeginUpdateResource(navicat_exe_path, FALSE);
|
||||
if (hUpdater == NULL) {
|
||||
_tprintf_s(TEXT("Cannot modify navicat.exe. CODE: 0x%08x @[patcher::Solution0::Do -> BeginUpdateResource]\r\n"), GetLastError());
|
||||
|
||||
delete[] pem_pubkey;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!UpdateResource(hUpdater,
|
||||
RT_RCDATA,
|
||||
TEXT("ACTIVATIONPUBKEY"),
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
||||
pem_pubkey, strlen(pem_pubkey))) {
|
||||
_tprintf_s(TEXT("Cannot replace public key. CODE: 0x%08x @[patcher::Solution0::Do -> UpdateResource]\r\n"), GetLastError());
|
||||
|
||||
EndUpdateResource(hUpdater, TRUE);
|
||||
delete[] pem_pubkey;
|
||||
return FALSE;
|
||||
} else {
|
||||
_tprintf_s(TEXT("@[patcher::Solution0::Do]: Public key has been replaced by:\r\n%hs"), pem_pubkey);
|
||||
|
||||
EndUpdateResource(hUpdater, FALSE);
|
||||
delete[] pem_pubkey;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
#include "def.hpp"
|
||||
|
||||
// Solution1 is for navicat premium of which the version = 12.0.25
|
||||
namespace patcher::Solution1 {
|
||||
|
||||
static BOOL CheckRSAKeyIsAppropriate(RSA* PrivateKey) {
|
||||
char* pem_pubkey = GetPEMText(PrivateKey);
|
||||
if (pem_pubkey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
std::string encrypted_pem_text = EncryptPublicKey(pem_pubkey, strlen(pem_pubkey));
|
||||
delete[] pem_pubkey;
|
||||
|
||||
if (encrypted_pem_text[160] > '9' || encrypted_pem_text[160] < '1')
|
||||
return FALSE;
|
||||
for (int i = 1; i < 8; ++i)
|
||||
if (encrypted_pem_text[160 + i] > '9' || encrypted_pem_text[160 + i] < '0')
|
||||
return FALSE;
|
||||
|
||||
if (encrypted_pem_text[910] > '9' || encrypted_pem_text[910] < '1')
|
||||
return FALSE;
|
||||
for (int i = 1; i < 5; ++i)
|
||||
if (encrypted_pem_text[910 + i] > '9' || encrypted_pem_text[910 + i] < '0')
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static RSA* GenerateAppropriateRSAKey() {
|
||||
while (true) {
|
||||
RSA* Key = GenerateRSAKey();
|
||||
if (Key == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if (CheckRSAKeyIsAppropriate(Key)) {
|
||||
return Key;
|
||||
} else {
|
||||
RSA_free(Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL FindPatchOffset(LPCTSTR libcc_dll_path, DWORD Offset[5]) {
|
||||
Offset[0] = 0;
|
||||
Offset[1] = 0;
|
||||
Offset[2] = 0;
|
||||
Offset[3] = 0;
|
||||
Offset[4] = 0;
|
||||
|
||||
HANDLE h_libcc = CreateFile(libcc_dll_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (h_libcc == INVALID_HANDLE_VALUE) {
|
||||
_tprintf_s(TEXT("Failed to open libcc.dll. CODE: 0x%08x @[FindPatchOffset -> CreateFile]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// DWORD is enough, you know libcc.dll cannot be larger than 4GB
|
||||
DWORD libcc_size = GetFileSize(h_libcc, nullptr);
|
||||
HANDLE h_libcc_map = CreateFileMapping(h_libcc, nullptr, PAGE_READONLY, 0, 0, nullptr);
|
||||
if (h_libcc_map == NULL) {
|
||||
_tprintf_s(TEXT("Failed to create mapping for libcc.dll. CODE: 0x%08x @[FindPatchOffset -> CreateFileMapping]\r\n"), GetLastError());
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const uint8_t* libcc = reinterpret_cast<const uint8_t*>(MapViewOfFile(h_libcc_map, FILE_MAP_READ, 0, 0, 0));
|
||||
if (libcc == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to map libcc.dll. CODE: 0x%08x @[FindPatchOffset -> MapViewOfFile]\r\n"), GetLastError());
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const IMAGE_DOS_HEADER* libcc_dos_header = reinterpret_cast<const IMAGE_DOS_HEADER*>(libcc);
|
||||
|
||||
// check dos signature
|
||||
if (libcc_dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
|
||||
_tprintf_s(TEXT("libcc.dll does not have a valid DOS header. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const IMAGE_NT_HEADERS* libcc_nt_header = reinterpret_cast<const IMAGE_NT_HEADERS*>(libcc + libcc_dos_header->e_lfanew);
|
||||
|
||||
// check nt signature
|
||||
if (libcc_nt_header->Signature != IMAGE_NT_SIGNATURE) {
|
||||
_tprintf_s(TEXT("libcc.dll does not have a valid NT header. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// check if a dll
|
||||
if ((libcc_nt_header->FileHeader.Characteristics & IMAGE_FILE_DLL) == 0) {
|
||||
_tprintf_s(TEXT("libcc.dll is not a DLL file. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// check if 32-bits or 64-bits
|
||||
#if defined(_M_X64)
|
||||
if (libcc_nt_header->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64 || libcc_nt_header->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
|
||||
_tprintf_s(TEXT("libcc.dll is not a 64-bits DLL file. @[FindPatchOffset]\r\n"));
|
||||
#elif defined(_M_IX86)
|
||||
if (libcc_nt_header->FileHeader.Machine != IMAGE_FILE_MACHINE_I386 || libcc_nt_header->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
||||
#else
|
||||
#error "unknown arch"
|
||||
#endif
|
||||
_tprintf_s(TEXT("libcc.dll is not a 32-bits DLL file. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WORD section_num = libcc_nt_header->FileHeader.NumberOfSections;
|
||||
const IMAGE_SECTION_HEADER* libcc_section_headers = reinterpret_cast<const IMAGE_SECTION_HEADER*>(
|
||||
libcc + libcc_dos_header->e_lfanew + sizeof(libcc_nt_header->Signature) + sizeof(libcc_nt_header->FileHeader) + libcc_nt_header->FileHeader.SizeOfOptionalHeader
|
||||
);
|
||||
|
||||
const IMAGE_SECTION_HEADER* rdata_section = nullptr;
|
||||
for (WORD i = 0; i < section_num; ++i) {
|
||||
if (*reinterpret_cast<const uint64_t*>(libcc_section_headers[i].Name) == 0x61746164722e) { // b'\x00\x00atadr.'
|
||||
rdata_section = libcc_section_headers + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rdata_section == nullptr) {
|
||||
_tprintf_s(TEXT(".rdata section is not found. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const IMAGE_SECTION_HEADER* text_section = nullptr;
|
||||
for (WORD i = 0; i < section_num; ++i) {
|
||||
if (*reinterpret_cast<const uint64_t*>(libcc_section_headers[i].Name) == 0x747865742e) { // b'\x00\x00\x00txet.'
|
||||
text_section = libcc_section_headers + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (text_section == nullptr) {
|
||||
_tprintf_s(TEXT(".text section is not found. @[FindPatchOffset]\r\n"));
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// search offset[0]
|
||||
{
|
||||
const uint8_t keyword[] = "D75125B70767B94145B47C1CB3C0755E";
|
||||
const uint8_t* start = libcc + rdata_section->PointerToRawData;
|
||||
DWORD section_size = rdata_section->SizeOfRawData;
|
||||
for (DWORD i = 0; i < section_size; ++i) {
|
||||
if (start[i] == keyword[0]) {
|
||||
bool found = true;
|
||||
for (DWORD j = 1; j < sizeof(keyword) - 1; ++j)
|
||||
if (start[i + j] != keyword[j]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
Offset[0] = rdata_section->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search offset[2]
|
||||
{
|
||||
const uint8_t keyword[] = "E1CED09B9C2186BF71A70C0FE2F1E0AE";
|
||||
const uint8_t* start = libcc + rdata_section->PointerToRawData;
|
||||
DWORD section_size = rdata_section->SizeOfRawData;
|
||||
for (DWORD i = 0; i < section_size; ++i) {
|
||||
if (start[i] == keyword[0]) {
|
||||
bool found = true;
|
||||
for (DWORD j = 1; j < sizeof(keyword) - 1; ++j)
|
||||
if (start[i + j] != keyword[j]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
Offset[2] = rdata_section->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search offset[4]
|
||||
{
|
||||
const uint8_t keyword[] = "92933";
|
||||
const uint8_t* start = libcc + rdata_section->PointerToRawData;
|
||||
DWORD section_size = rdata_section->SizeOfRawData;
|
||||
for (DWORD i = 0; i < section_size; ++i) {
|
||||
if (start[i] == keyword[0]) {
|
||||
bool found = true;
|
||||
for (DWORD j = 1; j < sizeof(keyword) - 1; ++j)
|
||||
if (start[i + j] != keyword[j]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
Offset[4] = rdata_section->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search offset[1]
|
||||
{
|
||||
const uint8_t keyword[] = { 0xfe, 0xea, 0xbc, 0x01 };
|
||||
const uint8_t* start = libcc + text_section->PointerToRawData;
|
||||
DWORD section_size = text_section->SizeOfRawData;
|
||||
for (DWORD i = 0; i < section_size; ++i) {
|
||||
if (start[i] == keyword[0]) {
|
||||
bool found = true;
|
||||
for (DWORD j = 1; j < sizeof(keyword); ++j)
|
||||
if (start[i + j] != keyword[j]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
Offset[1] = text_section->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search offset[3]
|
||||
{
|
||||
const uint8_t keyword[] = { 0x59, 0x08, 0x01, 0x00 };
|
||||
const uint8_t* start = libcc + text_section->PointerToRawData;
|
||||
DWORD section_size = text_section->SizeOfRawData;
|
||||
for (DWORD i = 0; i < section_size; ++i) {
|
||||
if (start[i] == keyword[0]) {
|
||||
bool found = true;
|
||||
for (DWORD j = 1; j < sizeof(keyword); ++j)
|
||||
if (start[i + j] != keyword[j]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
Offset[3] = text_section->PointerToRawData + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UnmapViewOfFile(libcc);
|
||||
CloseHandle(h_libcc_map);
|
||||
CloseHandle(h_libcc);
|
||||
|
||||
if (Offset[0] == 0 || Offset[1] == 0 || Offset[2] == 0 || Offset[3] == 0 || Offset[4] == 0) {
|
||||
_tprintf_s(TEXT("Failed to find all patch offset. Is libcc.dll from official? Or you've patched?\r\n"));
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL Do(LPCTSTR libcc_dll_path, LPCTSTR prepared_key_file) {
|
||||
// uint8_t expected_hash[SHA256_DIGEST_LENGTH] = {
|
||||
// 0x60, 0x7e, 0x0a, 0x84, 0xc7, 0x59, 0x66, 0xb0,
|
||||
// 0x0f, 0x3d, 0x12, 0xfa, 0x83, 0x3e, 0x91, 0xd1,
|
||||
// 0x59, 0xe4, 0xf5, 0x1a, 0xc5, 0x1b, 0x6b, 0xa6,
|
||||
// 0x6f, 0x98, 0xd0, 0xc3, 0xcb, 0xef, 0xdc, 0xe0
|
||||
// };
|
||||
//
|
||||
// if (!Check_libcc_Hash(libcc_dll_path, expected_hash))
|
||||
// return FALSE;
|
||||
|
||||
DWORD Patch_Offset[5];
|
||||
if (!FindPatchOffset(libcc_dll_path, Patch_Offset))
|
||||
return FALSE;
|
||||
|
||||
|
||||
|
||||
if (!BackupFile(libcc_dll_path))
|
||||
return FALSE;
|
||||
|
||||
RSA* PrivateKey = nullptr;
|
||||
if (prepared_key_file != nullptr) {
|
||||
PrivateKey = ReadRSAPrivateKeyFromFile(prepared_key_file);
|
||||
if (PrivateKey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
if (!CheckRSAKeyIsAppropriate(PrivateKey)) {
|
||||
_tprintf_s(TEXT("The key is not appropriate to use. @[patcher::Solution1::Do -> CheckRSAKeyIsAppropriate]\r\n"));
|
||||
RSA_free(PrivateKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
} else {
|
||||
PrivateKey = GenerateAppropriateRSAKey();
|
||||
if (PrivateKey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
if (!WriteRSAPrivateKeyToFile(TEXT("RegPrivateKey.pem"), PrivateKey)) {
|
||||
RSA_free(PrivateKey);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
char* pem_pubkey = GetPEMText(PrivateKey);
|
||||
if (pem_pubkey == nullptr)
|
||||
return FALSE;
|
||||
|
||||
std::string encrypted_pem_pubkey = EncryptPublicKey(pem_pubkey, strlen(pem_pubkey));
|
||||
|
||||
delete[] pem_pubkey; // we do not need it anymore
|
||||
RSA_free(PrivateKey); // we do not need it anymore
|
||||
|
||||
// split encrypted_pem_pubkey to 5 part: |160 chars|8 chars|742 chars|5 chars|5 chars|
|
||||
// | |
|
||||
// \ / \ /
|
||||
// imm1 imm3
|
||||
std::string encrypted_pem_pubkey0(encrypted_pem_pubkey.begin(), encrypted_pem_pubkey.begin() + 160);
|
||||
std::string encrypted_pem_pubkey1(encrypted_pem_pubkey.begin() + 160, encrypted_pem_pubkey.begin() + 160 + 8);
|
||||
std::string encrypted_pem_pubkey2(encrypted_pem_pubkey.begin() + 160 + 8, encrypted_pem_pubkey.begin() + 160 + 8 + 742);
|
||||
std::string encrypted_pem_pubkey3(encrypted_pem_pubkey.begin() + 160 + 8 + 742, encrypted_pem_pubkey.begin() + 160 + 8 + 742 + 5);
|
||||
std::string encrypted_pem_pubkey4(encrypted_pem_pubkey.begin() + 160 + 8 + 742 + 5, encrypted_pem_pubkey.end());
|
||||
|
||||
uint32_t imm1 = std::stoul(encrypted_pem_pubkey1.c_str());
|
||||
uint32_t imm3 = std::stoul(encrypted_pem_pubkey3.c_str());
|
||||
|
||||
HANDLE hFile = CreateFile(libcc_dll_path, GENERIC_WRITE, NULL, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
_tprintf_s(TEXT("Failed to open libcc.dll. CODE: 0x%08x @[patcher::Solution1::Do -> CreateFile]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// start patch 0
|
||||
_tprintf_s(TEXT("----------Start to do patch 0----------\r\n"));
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, Patch_Offset[0], nullptr, FILE_BEGIN)) {
|
||||
_tprintf_s(TEXT("Failed to set file pointer. CODE: 0x%08x @[patcher::Solution1::Do -> SetFilePointer]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("At offset +0x%08x, write:\r\n\"%hs\"\r\n"), Patch_Offset[0], encrypted_pem_pubkey0.c_str());
|
||||
if (FALSE == WriteFile(hFile, encrypted_pem_pubkey0.c_str(), encrypted_pem_pubkey0.length(), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write patch 0. CODE: 0x%08x @[patcher::Solution1::Do -> WriteFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("----------patch 0 done----------\r\n"));
|
||||
|
||||
// start patch 1
|
||||
_tprintf_s(TEXT("----------Start to do patch 1----------\r\n"));
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, Patch_Offset[1], nullptr, FILE_BEGIN)) {
|
||||
_tprintf_s(TEXT("Failed to set file pointer. CODE: 0x%08x @[patcher::Solution1::Do -> SetFilePointer]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("At offset +0x%08x, write immediate value %d (type: uint32_t)\r\n"), Patch_Offset[1], imm1);
|
||||
if (FALSE == WriteFile(hFile, &imm1, sizeof(imm1), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write patch 1. CODE: 0x%08x @[patcher::Solution1::Do -> WriteFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("----------patch 1 done----------\r\n"));
|
||||
|
||||
// start patch 2
|
||||
_tprintf_s(TEXT("----------Start to do patch 2----------\r\n"));
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, Patch_Offset[2], nullptr, FILE_BEGIN)) {
|
||||
_tprintf_s(TEXT("Failed to set file pointer. CODE: 0x%08x @[patcher::Solution1::Do -> SetFilePointer]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("At offset +0x%08x, write:\r\n\"%hs\"\r\n"), Patch_Offset[2], encrypted_pem_pubkey2.c_str());
|
||||
if (FALSE == WriteFile(hFile, encrypted_pem_pubkey2.c_str(), encrypted_pem_pubkey2.length(), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write patch 2. CODE: 0x%08x @[patcher::Solution1::Do -> WriteFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("----------patch 2 done----------\r\n"));
|
||||
|
||||
// start patch 3
|
||||
_tprintf_s(TEXT("----------Start to do patch 3----------\r\n"));
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, Patch_Offset[3], nullptr, FILE_BEGIN)) {
|
||||
_tprintf_s(TEXT("Failed to set file pointer. CODE: 0x%08x @[patcher::Solution1::Do -> SetFilePointer]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("At offset +0x%08x, write immediate value %d (type: uint32_t)\r\n"), Patch_Offset[3], imm3);
|
||||
if (FALSE == WriteFile(hFile, &imm3, sizeof(imm3), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write patch 3. CODE: 0x%08x @[patcher::Solution1::Do -> WriteFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("----------patch 3 done----------\r\n"));
|
||||
|
||||
// start patch 4
|
||||
_tprintf_s(TEXT("----------Start to do patch 4----------\r\n"));
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, Patch_Offset[4], nullptr, FILE_BEGIN)) {
|
||||
_tprintf_s(TEXT("Failed to set file pointer. CODE: 0x%08x @[patcher::Solution1::Do -> SetFilePointer]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("At offset +0x%08x, write:\r\n\"%hs\"\r\n"), Patch_Offset[4], encrypted_pem_pubkey4.c_str());
|
||||
if (FALSE == WriteFile(hFile, encrypted_pem_pubkey4.c_str(), encrypted_pem_pubkey4.length(), nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write patch 4. CODE: 0x%08x @[patcher::Solution1::Do -> WriteFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("----------patch 4 done----------\r\n"));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
#include "X64ImageInterpreter.hpp"
|
||||
|
||||
[[nodiscard]]
|
||||
X64ImageInterpreter X64ImageInterpreter::Parse(void* ImageBase) {
|
||||
X64ImageInterpreter NewImage;
|
||||
|
||||
NewImage.pvt_MachHeader = reinterpret_cast<mach_header_64*>(ImageBase);
|
||||
if (NewImage.pvt_MachHeader->magic != MH_MAGIC_64) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Bad Image");
|
||||
}
|
||||
|
||||
auto cmd_p = reinterpret_cast<load_command*>(NewImage.pvt_MachHeader + 1);
|
||||
for (uint32_t i = 0; i < NewImage.pvt_MachHeader->ncmds; ++i) {
|
||||
switch (cmd_p->cmd) {
|
||||
case LC_SEGMENT_64: {
|
||||
auto segcmd_p = reinterpret_cast<segment_command_64*>(cmd_p);
|
||||
auto section_p = reinterpret_cast<section_64*>(segcmd_p + 1);
|
||||
|
||||
NewImage.pvt_SegmentCommands.emplace_back(segcmd_p);
|
||||
|
||||
for (uint32_t j = 0; j < segcmd_p->nsects; ++j) {
|
||||
NewImage.pvt_Sections.ByIndex[NewImage.pvt_Sections.ByIndex.size()] = §ion_p[j];
|
||||
NewImage.pvt_Sections.ByMapAddress[section_p[j].addr] = §ion_p[j];
|
||||
NewImage.pvt_Sections.ByFileOffset[section_p[j].offset] = §ion_p[j];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case LC_DYSYMTAB: {
|
||||
NewImage.pvt_DynamicSymbol.SegmentCommand = reinterpret_cast<dysymtab_command*>(cmd_p);
|
||||
break;
|
||||
}
|
||||
case LC_SYMTAB: {
|
||||
NewImage.pvt_Symbol.SegmentCommand = reinterpret_cast<symtab_command*>(cmd_p);
|
||||
NewImage.pvt_Symbol.StringTable = NewImage.ImageOffset<char*>(NewImage.pvt_Symbol.SegmentCommand->stroff);
|
||||
NewImage.pvt_Symbol.SymbolTable = NewImage.ImageOffset<nlist_64*>(NewImage.pvt_Symbol.SegmentCommand->symoff);
|
||||
break;
|
||||
}
|
||||
case LC_DYLD_INFO_ONLY: { // NOLINT
|
||||
NewImage.pvt_DynamicLoaderInfoOnly.SegmentCommand = reinterpret_cast<dyld_info_command*>(cmd_p);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cmd_p = reinterpret_cast<load_command*>(
|
||||
reinterpret_cast<uint8_t*>(cmd_p) + cmd_p->cmdsize
|
||||
);
|
||||
}
|
||||
|
||||
return NewImage;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t X64ImageInterpreter::NumberOfSections() const noexcept {
|
||||
return pvt_Sections.ByIndex.size();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSection(size_t Index) const {
|
||||
auto it = pvt_Sections.ByIndex.find(Index);
|
||||
if (it != pvt_Sections.ByIndex.cend()) {
|
||||
return it->second;
|
||||
} else {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSection(const char* SegmentName, const char* SectionName) const {
|
||||
for (auto segcmd_p : pvt_SegmentCommands) {
|
||||
if (strncmp(SegmentName, segcmd_p->segname, sizeof(segcmd_p->segname)) == 0) {
|
||||
auto sec_p = reinterpret_cast<section_64*>(segcmd_p + 1);
|
||||
|
||||
for (uint32_t i = 0; i < segcmd_p->nsects; ++i) {
|
||||
if (strncmp(SectionName, sec_p[i].sectname, sizeof(sec_p[i].sectname)) == 0)
|
||||
return &sec_p[i];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSectionByOffset(uint32_t Offset) const {
|
||||
for (const auto& it : pvt_Sections.ByFileOffset) {
|
||||
if (it.first <= Offset && Offset < it.first + it.second->size) {
|
||||
return it.second;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* X64ImageInterpreter::ImageSectionByRva(uint64_t Rva) const {
|
||||
for (const auto& it : pvt_Sections.ByMapAddress) {
|
||||
if (it.first <= Rva && Rva < it.first + it.second->size) {
|
||||
return it.second;
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Section is not found.");
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint64_t X64ImageInterpreter::OffsetToRva(uint32_t Offset) const {
|
||||
auto section = ImageSectionByOffset(Offset);
|
||||
return section->addr + (Offset - section->offset);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint32_t X64ImageInterpreter::RvaToOffset(uint64_t Rva) const {
|
||||
auto section = ImageSectionByRva(Rva);
|
||||
return section->offset + (Rva - section->addr);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
nlist_64* X64ImageInterpreter::ImageSymbolTable() const noexcept {
|
||||
return pvt_Symbol.SymbolTable;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
#pragma once
|
||||
#include <string.h> // NOLINT
|
||||
#include <mach-o/loader.h>
|
||||
#include <mach-o/nlist.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "../common/Exception.hpp"
|
||||
|
||||
class X64ImageInterpreter {
|
||||
public:
|
||||
static constexpr uint64_t InvalidAddress = static_cast<uint64_t>(-1);
|
||||
static constexpr uint32_t InvalidOffset = static_cast<uint32_t>(-1);
|
||||
private:
|
||||
|
||||
mach_header_64* pvt_MachHeader;
|
||||
std::vector<segment_command_64*> pvt_SegmentCommands;
|
||||
|
||||
struct {
|
||||
std::map<size_t, section_64*> ByIndex;
|
||||
std::map<uint64_t, section_64*> ByMapAddress;
|
||||
std::map<uint32_t, section_64*> ByFileOffset;
|
||||
} pvt_Sections;
|
||||
|
||||
struct {
|
||||
dysymtab_command* SegmentCommand;
|
||||
} pvt_DynamicSymbol;
|
||||
|
||||
struct {
|
||||
symtab_command* SegmentCommand;
|
||||
char* StringTable;
|
||||
nlist_64* SymbolTable;
|
||||
} pvt_Symbol;
|
||||
|
||||
struct {
|
||||
dyld_info_command* SegmentCommand;
|
||||
} pvt_DynamicLoaderInfoOnly;
|
||||
|
||||
X64ImageInterpreter() :
|
||||
pvt_MachHeader(nullptr),
|
||||
pvt_DynamicSymbol{},
|
||||
pvt_Symbol{},
|
||||
pvt_DynamicLoaderInfoOnly{} {}
|
||||
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
static X64ImageInterpreter Parse(void* ImageBase);
|
||||
|
||||
template<typename __ReturnType = void*>
|
||||
[[nodiscard]]
|
||||
__ReturnType ImageBase() const noexcept {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
return reinterpret_cast<__ReturnType>(pvt_MachHeader);
|
||||
}
|
||||
|
||||
template<typename __ReturnType = void*>
|
||||
[[nodiscard]]
|
||||
__ReturnType ImageOffset(size_t Offset) const noexcept {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
return reinterpret_cast<__ReturnType>(
|
||||
reinterpret_cast<uint8_t*>(pvt_MachHeader) + Offset
|
||||
);
|
||||
}
|
||||
|
||||
template<unsigned __CommandMacro>
|
||||
[[nodiscard]]
|
||||
auto CommandOf() const noexcept {
|
||||
if constexpr (__CommandMacro == LC_DYSYMTAB) {
|
||||
return pvt_DynamicSymbol.SegmentCommand;
|
||||
} else if constexpr (__CommandMacro == LC_SYMTAB) {
|
||||
return pvt_Symbol.SegmentCommand;
|
||||
} else if constexpr (__CommandMacro == LC_DYLD_INFO_ONLY) { // NOLINT
|
||||
return pvt_DynamicLoaderInfoOnly.SegmentCommand;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
size_t NumberOfSections() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSection(size_t Index) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSection(const char* SegmentName, const char* SectionName) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSectionByOffset(uint32_t Offset) const;
|
||||
|
||||
[[nodiscard]]
|
||||
section_64* ImageSectionByRva(uint64_t Rva) const;
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(size_t Index) const {
|
||||
auto Section = ImageSection(Index);
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(const char* SegmentName, const char* SectionName) const {
|
||||
auto Section = ImageSection(SegmentName, SectionName);
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType>
|
||||
[[nodiscard]]
|
||||
__ReturnType SectionView(section_64* Section) const {
|
||||
return ImageOffset<__ReturnType>(Section->offset);
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(size_t Index, __Hint&& Hint) const {
|
||||
return SearchSection<__ReturnType>(ImageSection(Index), std::forward<__Hint>(Hint));
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
return SearchSection<__ReturnType>(ImageSection(SegmentName, SectionName), std::forward<__Hint>(Hint));
|
||||
}
|
||||
|
||||
template<typename __ReturnType, typename __Hint>
|
||||
[[nodiscard]]
|
||||
__ReturnType SearchSection(section_64* Section, __Hint&& Hint) const {
|
||||
static_assert(std::is_pointer_v<__ReturnType>);
|
||||
|
||||
auto begin = SectionView<const uint8_t*>(Section);
|
||||
auto end = begin + Section->size;
|
||||
|
||||
for (; begin < end; ++begin) {
|
||||
if (Hint(begin) == true) {
|
||||
return reinterpret_cast<__ReturnType>(const_cast<uint8_t*>(begin));
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Data is not found.");
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(size_t Index, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(Index, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(SegmentName, SectionName, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint32_t SearchSectionOffset(section_64* Section, __Hint&& Hint) const {
|
||||
return SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - ImageBase<uint8_t*>();
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(size_t Index, __Hint&& Hint) const {
|
||||
auto Section = ImageSection(Index);
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(const char* SegmentName, const char* SectionName, __Hint&& Hint) const {
|
||||
auto Section = ImageSection(SegmentName, SectionName);
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
template<typename __Hint>
|
||||
[[nodiscard]]
|
||||
uint64_t SearchSectionRva(section_64* Section, __Hint&& Hint) const {
|
||||
auto Offset = SearchSection<uint8_t*>(Section, std::forward<__Hint>(Hint)) - SectionView<uint8_t*>(Section);
|
||||
return Section->addr + Offset;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
uint64_t OffsetToRva(uint32_t Offset) const;
|
||||
|
||||
[[nodiscard]]
|
||||
uint32_t RvaToOffset(uint64_t Address) const;
|
||||
|
||||
[[nodiscard]]
|
||||
nlist_64* ImageSymbolTable() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
char* LookupStringTable(size_t Offset) const noexcept {
|
||||
return pvt_Symbol.StringTable + Offset;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "def.hpp"
|
||||
|
||||
namespace std {
|
||||
#ifdef UNICODE
|
||||
typedef wstring Tstring;
|
||||
#else
|
||||
typedef string Tstring;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _tmain(int argc, TCHAR* argv[]) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
_tprintf_s(TEXT("Usage:\r\n"));
|
||||
_tprintf_s(TEXT(" navicat-patcher.exe <Navicat installation path> [RSA-2048 PEM file]\r\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
{ // check path validity
|
||||
DWORD attr = GetFileAttributes(argv[1]);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) {
|
||||
_tprintf_s(TEXT("Failed to get installation path attribute. CODE: 0x%08x @[GetFileAttributes]\r\n"), GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
_tprintf_s(TEXT("Error: Path is not a directory.\r\n"));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::Tstring navicat_exe_path(argv[1]);
|
||||
if (navicat_exe_path.back() != TEXT('/') && navicat_exe_path.back() != TEXT('\\'))
|
||||
navicat_exe_path.push_back(TEXT('\\'));
|
||||
navicat_exe_path += TEXT("navicat.exe");
|
||||
|
||||
std::Tstring libcc_dll_path(argv[1]);
|
||||
if (libcc_dll_path.back() != TEXT('/') && libcc_dll_path.back() != TEXT('\\'))
|
||||
libcc_dll_path.push_back(TEXT('\\'));
|
||||
libcc_dll_path += TEXT("libcc.dll");
|
||||
|
||||
DWORD NavicatMajorVersion;
|
||||
DWORD NavicatMinorVersion;
|
||||
if (!patcher::GetNavicatVerion(navicat_exe_path.c_str(), &NavicatMajorVersion, &NavicatMinorVersion))
|
||||
return 0;
|
||||
|
||||
BOOL status;
|
||||
if (NavicatMajorVersion <= 0x000C0000 && NavicatMinorVersion < 0x00190000) { // for navicat ver < 12.0.25
|
||||
status = patcher::Solution0::Do(navicat_exe_path.c_str());
|
||||
} else if (NavicatMajorVersion == 0x000C0000 && NavicatMinorVersion == 0x00190000) { // for navicat ver = 12.0.25
|
||||
status = patcher::Solution1::Do(libcc_dll_path.c_str(), argc == 3 ? argv[2] : nullptr);
|
||||
} else if (NavicatMajorVersion == 0x000C0000 && NavicatMinorVersion == 0x001A0000) { // for navicat ver = 12.0.26
|
||||
status = patcher::Solution1::Do(libcc_dll_path.c_str(), argc == 3 ? argv[2] : nullptr);
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("%s\r\n"), status == TRUE ? TEXT("Success!") : TEXT("Failed!"));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
#include "def.hpp"
|
||||
|
||||
namespace patcher {
|
||||
|
||||
BOOL BackupFile(LPCTSTR file_path) {
|
||||
size_t file_path_len = _tcslen(file_path);
|
||||
|
||||
TCHAR* backup_file_path = new TCHAR[file_path_len + 16]();
|
||||
_stprintf_s(backup_file_path, file_path_len + 16, TEXT("%s%s"), file_path, TEXT(".backup"));
|
||||
|
||||
if (!CopyFile(file_path, backup_file_path, TRUE)) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
_tprintf_s(TEXT("@[BackupFile]: Cannot find %s.\r\n"), file_path);
|
||||
break;
|
||||
case ERROR_FILE_EXISTS:
|
||||
_tprintf_s(TEXT("@[BackupFile]: Backup file already exists.\r\n"));
|
||||
break;
|
||||
case ERROR_ACCESS_DENIED:
|
||||
_tprintf_s(TEXT("@[BackupFile]: Access denied, please run as administrator.\r\n"));
|
||||
break;
|
||||
default:
|
||||
_tprintf_s(TEXT("Unknown error. CODE: 0x%08x @[BackupFile -> CopyFile]\r\n"), GetLastError());
|
||||
}
|
||||
delete[] backup_file_path;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_tprintf_s(TEXT("@[BackupFile]: %s has been backed up.\r\n"), file_path);
|
||||
delete[] backup_file_path;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
RSA* GenerateRSAKey(int bits) {
|
||||
RSA* ret = RSA_generate_key(bits, RSA_F4, nullptr, nullptr);
|
||||
if (ret == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to generate RSA key. CODE: 0x%08x @[GenerateRSAKey -> RSA_generate_key]\r\n"), ERR_get_error());
|
||||
return nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WriteRSAPrivateKeyToFile(LPCTSTR filename, RSA* PrivateKey) {
|
||||
#ifdef UNICODE
|
||||
int req_size = WideCharToMultiByte(CP_ACP, 0, filename, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (req_size == 0) {
|
||||
_tprintf_s(TEXT("Failed to convert wchar* to char*. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> WideCharToMultiByte]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char* temp_filename = new char[req_size]();
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, temp_filename, req_size, nullptr, nullptr);
|
||||
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_write_filename(b, temp_filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> BIO_write_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
delete[] temp_filename;
|
||||
#else
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_write_filename(b, filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> BIO_write_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
if (1 != PEM_write_bio_RSAPrivateKey(b, PrivateKey, nullptr, nullptr, 0, nullptr, nullptr)) {
|
||||
_tprintf_s(TEXT("Failed to write RSA private key. CODE: 0x%08x @[WriteRSAPrivateKeyToFile -> PEM_write_bio_RSAPrivateKey]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return FALSE;
|
||||
} else {
|
||||
BIO_free_all(b);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
RSA* ReadRSAPrivateKeyFromFile(LPCTSTR filename) {
|
||||
#ifdef UNICODE
|
||||
int req_size = WideCharToMultiByte(CP_ACP, 0, filename, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (req_size == 0) {
|
||||
_tprintf_s(TEXT("Failed to convert wchar* to char*. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> WideCharToMultiByte]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char* temp_filename = new char[req_size]();
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, temp_filename, req_size, nullptr, nullptr);
|
||||
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_read_filename(b, temp_filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_read_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
delete[] temp_filename;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
delete[] temp_filename;
|
||||
#else
|
||||
BIO* b = BIO_new(BIO_s_file());
|
||||
if (b == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to create BIO object. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_new]\r\n"), ERR_get_error());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (1 != BIO_read_filename(b, filename)) {
|
||||
_tprintf_s(TEXT("Failed to set target file of BIO. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> BIO_read_filename]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
RSA* ret = PEM_read_bio_RSAPrivateKey(b, nullptr, nullptr, nullptr);
|
||||
if (ret == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to read RSA private key. CODE: 0x%08x @[ReadRSAPrivateKeyFromFile -> PEM_read_bio_RSAPrivateKey]\r\n"), ERR_get_error());
|
||||
|
||||
BIO_free_all(b);
|
||||
return nullptr;
|
||||
} else {
|
||||
BIO_free_all(b);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL GetNavicatVerion(LPCTSTR exe_path, DWORD* major_ver, DWORD* minor_ver) {
|
||||
DWORD FileVersionInfoSize = GetFileVersionInfoSize(exe_path, nullptr);
|
||||
if (FileVersionInfoSize == 0) {
|
||||
_tprintf_s(TEXT("Failed to get navicat.exe verion info. CODE: 0x%08x @[GetNavicatVerion -> GetFileVersionInfoSize]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
LPVOID buf = new unsigned char[FileVersionInfoSize]();
|
||||
if (FALSE == GetFileVersionInfo(exe_path, 0, FileVersionInfoSize, buf)) {
|
||||
_tprintf_s(TEXT("Failed to get navicat.exe verion info. CODE: 0x%08x @[GetNavicatVerion -> GetFileVersionInfo]\r\n"), GetLastError());
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LPVOID info_ptr;
|
||||
UINT info_len;
|
||||
if (FALSE == VerQueryValue(buf, TEXT("\\"), &info_ptr, &info_len)) {
|
||||
_tprintf_s(TEXT("Failed to get navicat.exe verion info. CODE: 0x%08x @[GetNavicatVerion -> VerQueryValue]\r\n"), GetLastError());
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*major_ver = static_cast<VS_FIXEDFILEINFO*>(info_ptr)->dwFileVersionMS;
|
||||
*minor_ver = static_cast<VS_FIXEDFILEINFO*>(info_ptr)->dwFileVersionLS;
|
||||
delete[] buf;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL Check_libcc_Hash(LPCTSTR libcc_dll_path, const uint8_t expected_hash[SHA256_DIGEST_LENGTH]) {
|
||||
HANDLE hFile = CreateFile(libcc_dll_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
_tprintf_s(TEXT("Failed to open libcc.dll. CODE: 0x%08x @[Check_libcc_Hash -> CreateFile]\r\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LARGE_INTEGER FileSize;
|
||||
if (FALSE == GetFileSizeEx(hFile, &FileSize)) {
|
||||
_tprintf_s(TEXT("Failed to get libcc.dll size. CODE: 0x%08x @[Check_libcc_Hash -> GetFileSizeEx]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HANDLE hFileMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
|
||||
if (hFileMap == NULL) {
|
||||
_tprintf_s(TEXT("Failed to create mapping for libcc.dll. CODE: 0x%08x @[Check_libcc_Hash -> CreateFileMapping]\r\n"), GetLastError());
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const uint8_t* libcc_data = reinterpret_cast<const uint8_t*>(MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0));
|
||||
if (libcc_data == nullptr) {
|
||||
_tprintf_s(TEXT("Failed to map libcc.dll. CODE: 0x%08x @[Check_libcc_Hash -> MapViewOfFile]\r\n"), GetLastError());
|
||||
CloseHandle(hFileMap);
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
uint8_t real_hash[SHA256_DIGEST_LENGTH] = { };
|
||||
|
||||
SHA256(libcc_data, FileSize.LowPart, real_hash);
|
||||
UnmapViewOfFile(libcc_data);
|
||||
CloseHandle(hFileMap);
|
||||
CloseHandle(hFile);
|
||||
|
||||
if (memcmp(expected_hash, real_hash, SHA256_DIGEST_LENGTH) != 0) {
|
||||
_tprintf_s(TEXT("ERROR: SHA256 do not match.\r\n"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char* GetPEMText(RSA* PrivateKey) {
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (bio == nullptr) {
|
||||
_tprintf_s(TEXT("Cannot create BIO object. CODE: 0x%08x @[GetPEMText -> BIO_new]\r\n"), ERR_get_error());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (1 != PEM_write_bio_RSA_PUBKEY(bio, PrivateKey)) {
|
||||
_tprintf_s(TEXT("Cannot write RSA-2048 public key. CODE: 0x%08x @[GetPEMText -> PEM_write_bio_RSA_PUBKEY]\r\n"), ERR_get_error());
|
||||
BIO_free_all(bio);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* pem_data_ptr;
|
||||
int pem_data_len = BIO_get_mem_data(bio, &pem_data_ptr);
|
||||
|
||||
char* ret = new char[pem_data_len + 256]();
|
||||
for (int i = 0, j = 0; i < pem_data_len; ++i, ++j) {
|
||||
if (pem_data_ptr[i] == '\n') {
|
||||
ret[j++] = '\r';
|
||||
ret[j] = pem_data_ptr[i];
|
||||
} else {
|
||||
ret[j] = pem_data_ptr[i];
|
||||
}
|
||||
}
|
||||
|
||||
BIO_free_all(bio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
// OpenSSL precompiled lib, download from https://www.npcglib.org/~stathis/blog/precompiled-openssl/, MSVC2015 version
|
||||
// direct link https://www.npcglib.org/~stathis/downloads/openssl-1.1.0f-vs2015.7z
|
||||
// x86: "D:\openssl-1.1.0f-vs2015\include" has been add to include path. (modify it at project properties if necessary)
|
||||
// "D:\openssl-1.1.0f-vs2015\lib" has been add to library path. (modify it at project properties if necessary)
|
||||
// x64: "D:\openssl-1.1.0f-vs2015\include64" has been add to include path. (modify it at project properties if necessary)
|
||||
// "D:\openssl-1.1.0f-vs2015\lib64" has been add to library path. (modify it at project properties if necessary)
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libcryptoMTd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcryptoMT.lib")
|
||||
#endif
|
||||
#pragma comment(lib, "WS2_32.lib") // some symbol are used in OpenSSL lib
|
||||
#pragma comment(lib, "Crypt32.lib") // some symbol are used in OpenSSL lib
|
||||
#pragma comment(lib, "version.lib") // GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue are in this lib
|
||||
|
||||
namespace patcher {
|
||||
|
||||
BOOL BackupFile(LPCTSTR file_path);
|
||||
|
||||
RSA* GenerateRSAKey(int bits = 2048);
|
||||
|
||||
BOOL WriteRSAPrivateKeyToFile(LPCTSTR filename, RSA* PrivateKey);
|
||||
RSA* ReadRSAPrivateKeyFromFile(LPCTSTR filename);
|
||||
|
||||
BOOL GetNavicatVerion(LPCTSTR exe_path, DWORD* major_ver, DWORD* minor_ver);
|
||||
|
||||
std::string EncryptPublicKey(const char* public_key, size_t len);
|
||||
|
||||
BOOL Check_libcc_Hash(LPCTSTR libcc_dll_path, const uint8_t expected_hash[SHA256_DIGEST_LENGTH]);
|
||||
|
||||
char* GetPEMText(RSA* PrivateKey);
|
||||
|
||||
namespace Solution0 {
|
||||
BOOL Do(LPCTSTR navicat_exe_path, LPCTSTR prepared_key_file = nullptr);
|
||||
}
|
||||
|
||||
namespace Solution1 {
|
||||
BOOL Do(LPCTSTR libcc_dll_path, LPCTSTR prepared_key_file = nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <plist/plist++.h>
|
||||
#include <string>
|
||||
|
||||
#include "../common/ExceptionSystem.hpp"
|
||||
#include "../common/ResourceOwned.hpp"
|
||||
#include "ResourceTraitsUnix.hpp"
|
||||
#include "PatchSolutions.hpp"
|
||||
|
||||
static void Welcome() {
|
||||
puts("***************************************************");
|
||||
puts("* Navicat Patcher by @DoubleLabyrinth *");
|
||||
puts("* Version: 4.0 *");
|
||||
puts("***************************************************");
|
||||
puts("");
|
||||
puts("Press Enter to continue or Ctrl + C to abort.");
|
||||
getchar();
|
||||
}
|
||||
|
||||
static void Help() {
|
||||
puts("***************************************************");
|
||||
puts("* Navicat Patcher by @DoubleLabyrinth *");
|
||||
puts("* Version: 4.0 *");
|
||||
puts("***************************************************");
|
||||
puts("");
|
||||
puts("Usage:");
|
||||
puts(" navicat-patcher <Navicat installation path> [RSA-2048 Private Key File]");
|
||||
puts("");
|
||||
puts(" <Navicat installation path> Path to `Navicat Premium.app`.");
|
||||
puts(" Example:");
|
||||
puts(" /Applications/Navicat\\ Premium.app/");
|
||||
puts(" This parameter must be specified.");
|
||||
puts("");
|
||||
puts(" [RSA-2048 Private Key File] Path to a PEM-format RSA-2048 private key file.");
|
||||
puts(" This parameter is optional.");
|
||||
puts("");
|
||||
}
|
||||
|
||||
static std::string GetNavicatVersion(const char* AppPath) {
|
||||
ResourceOwned hInfoPlist(FileHandleTraits{});
|
||||
ResourceOwned InfoPlist(CppObjectTraits<PList::Dictionary>{});
|
||||
|
||||
hInfoPlist.TakeOver(open((std::string(AppPath) + "/Contents/Info.plist").c_str(), O_RDONLY));
|
||||
if (hInfoPlist.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to open Contents/Info.plist.");
|
||||
}
|
||||
|
||||
struct stat statInfoPlist = {};
|
||||
if (fstat(hInfoPlist, &statInfoPlist) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to get file size of Contents/Info.plist.");
|
||||
}
|
||||
|
||||
std::string contentInfoPlist(statInfoPlist.st_size, '\x00');
|
||||
if (read(hInfoPlist, contentInfoPlist.data(), contentInfoPlist.size()) != contentInfoPlist.size()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to read Contents/Info.plist.");
|
||||
}
|
||||
|
||||
InfoPlist.TakeOver(dynamic_cast<PList::Dictionary*>(PList::Structure::FromXml(contentInfoPlist)));
|
||||
if (InfoPlist.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Failed to parse Contents/Info.plist.");
|
||||
}
|
||||
|
||||
auto kv = InfoPlist->Find("CFBundleShortVersionString");
|
||||
if (kv == InfoPlist->End()) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Cannot find CFBundleShortVersionString in Contents/Info.plist.");
|
||||
}
|
||||
|
||||
if (kv->second->GetType() == PLIST_STRING) {
|
||||
return dynamic_cast<PList::String*>(kv->second)->GetValue();
|
||||
} else {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "Failed to get Navicat version.");
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadKey(RSACipher& RsaCipher, const char* RsaKeyFileName,
|
||||
PatchSolution* lpSolution0,
|
||||
PatchSolution* lpSolution1,
|
||||
PatchSolution* lpSolution2) {
|
||||
if (RsaKeyFileName) {
|
||||
RsaCipher.ImportKeyFromFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>(RsaKeyFileName);
|
||||
|
||||
if ((lpSolution0 && !lpSolution0->CheckKey(RsaCipher)) ||
|
||||
(lpSolution1 && !lpSolution1->CheckKey(RsaCipher)) ||
|
||||
(lpSolution2 && !lpSolution2->CheckKey(RsaCipher)))
|
||||
{
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::Exception(__FILE__, __LINE__, "The RSA private key you provide cannot be used.");
|
||||
}
|
||||
} else {
|
||||
puts("");
|
||||
puts("[*] Generating new RSA private key, it may take a long time...");
|
||||
|
||||
do {
|
||||
RsaCipher.GenerateKey(2048);
|
||||
} while ((lpSolution0 && !lpSolution0->CheckKey(RsaCipher)) ||
|
||||
(lpSolution1 && !lpSolution1->CheckKey(RsaCipher)) ||
|
||||
(lpSolution2 && !lpSolution2->CheckKey(RsaCipher))); // re-generate RSA key if CheckKey return false
|
||||
|
||||
RsaCipher.ExportKeyToFile<RSAKeyType::PrivateKey, RSAKeyFormat::PEM>("RegPrivateKey.pem");
|
||||
|
||||
puts("[+] New RSA private key has been saved to RegPrivateKey.pem.");
|
||||
}
|
||||
|
||||
std::string PublicKeyPEM = RsaCipher.ExportKeyString<RSAKeyType::PublicKey, RSAKeyFormat::PEM>();
|
||||
puts("");
|
||||
puts("[*] Your RSA public key:");
|
||||
puts(PublicKeyPEM.c_str());
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
Help();
|
||||
return -1;
|
||||
} else {
|
||||
Welcome();
|
||||
|
||||
try {
|
||||
RSACipher RsaCipher;
|
||||
ResourceOwned Solution0(CppObjectTraits<PatchSolution>{});
|
||||
ResourceOwned Solution1(CppObjectTraits<PatchSolution>{});
|
||||
ResourceOwned Solution2(CppObjectTraits<PatchSolution>{});
|
||||
|
||||
ResourceOwned hMainApp(FileHandleTraits{}, open((std::string(argv[1]) + "/Contents/MacOS/Navicat Premium").c_str(), O_RDWR));
|
||||
if (hMainApp.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "open failed.");
|
||||
}
|
||||
|
||||
struct stat statMainApp = {};
|
||||
if (fstat(hMainApp, &statMainApp) != 0) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "fstat failed.");
|
||||
}
|
||||
|
||||
ResourceOwned lpMainApp(MapViewTraits{},
|
||||
mmap(nullptr, static_cast<size_t>(statMainApp.st_size), PROT_READ | PROT_WRITE, MAP_SHARED, hMainApp, 0),
|
||||
[&statMainApp](void* p) { munmap(p, statMainApp.st_size); }
|
||||
);
|
||||
if (lpMainApp.IsValid() == false) {
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "mmap failed.");
|
||||
}
|
||||
|
||||
int Ver0, Ver1, Ver2;
|
||||
if (sscanf(GetNavicatVersion(argv[1]).c_str(), "%d.%d.%d", &Ver0, &Ver1, &Ver2) != 3) { // NOLINT
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Failed to get version of Navicat.");
|
||||
}
|
||||
|
||||
X64ImageInterpreter MainApp = X64ImageInterpreter::Parse(lpMainApp);
|
||||
|
||||
printf("[*] Your Navicat version: %d.%d.%d\n", Ver0, Ver1, Ver2);
|
||||
printf("\n");
|
||||
|
||||
Solution0.TakeOver(new PatchSolution0(MainApp));
|
||||
Solution1.TakeOver(new PatchSolution1(MainApp));
|
||||
Solution2.TakeOver(new PatchSolution2(MainApp));
|
||||
|
||||
if (Solution0->FindPatchOffset() == false) {
|
||||
Solution0.Release();
|
||||
}
|
||||
if (Solution1->FindPatchOffset() == false) {
|
||||
Solution1.Release();
|
||||
}
|
||||
if (Solution2->FindPatchOffset() == false) {
|
||||
Solution2.Release();
|
||||
}
|
||||
|
||||
//
|
||||
// Begin strategies by different Navicat versions
|
||||
//
|
||||
if (Ver0 < 12) { // ver < 12.0.0
|
||||
// NOLINTNEXTLINE: allow exceptions that is not derived from std::exception
|
||||
throw nkg::SystemError(__FILE__, __LINE__, errno, "Unsupported version of Navicat.");
|
||||
} else if (Ver0 == 12 && Ver1 == 0 && Ver2 < 24) { // ver < 12.0.24
|
||||
std::string path(argv[1]);
|
||||
while(path.back() == '/') {
|
||||
path.pop_back();
|
||||
}
|
||||
|
||||
printf("[*] Your Navicat version is < 12.0.24. So there would be nothing patched.\n");
|
||||
printf(" Just use `openssl` to generate `RegPrivateKey.pem` and `rpk` file:\n");
|
||||
printf(" openssl genrsa -out RegPrivateKey.pem 2048\n");
|
||||
printf(" openssl rsa -in RegPrivateKey.pem -pubout -out rpk\n");
|
||||
printf(" and replace `%s/Contents/Resources/rpk` with the `rpk` file you just generated.\n", path.c_str());
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
} else if (Ver0 == 12 && (Ver1 == 0 || (Ver1 == 1 && Ver2 < 14))) { // 12.0.24 <= ver && ver < 12.1.14
|
||||
// In this case, Solution0 must be applied
|
||||
if (Solution0.IsValid() == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
} else if (Ver0 == 12 && Ver1 == 1 && Ver2 == 14) { // ver == 12.1.14
|
||||
// In this case, Solution0 and Solution1 must be applied
|
||||
if ((Solution0.IsValid() && Solution1.IsValid()) == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
} else { // ver > 12.1.14
|
||||
// In this case, Solution0 and Solution2 must be applied
|
||||
if ((Solution0.IsValid() && Solution2.IsValid()) == false) {
|
||||
puts("[-] Patch abort. None of PatchSolutions will be applied.");
|
||||
puts(" Are you sure your Navicat has not been patched before?");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//
|
||||
// End strategies by different Navicat versions
|
||||
//
|
||||
|
||||
LoadKey(RsaCipher, argc == 3 ? argv[2] : nullptr, Solution0, Solution1, Solution2);
|
||||
|
||||
if (Solution0.IsValid()) {
|
||||
Solution0->MakePatch(RsaCipher);
|
||||
}
|
||||
if (Solution1.IsValid()) {
|
||||
Solution1->MakePatch(RsaCipher);
|
||||
}
|
||||
if (Solution2.IsValid()) {
|
||||
Solution2->MakePatch(RsaCipher);
|
||||
}
|
||||
|
||||
if (Solution0.IsValid())
|
||||
puts("[+] PatchSolution0 has been applied.");
|
||||
if (Solution1.IsValid())
|
||||
puts("[+] PatchSolution1 has been applied.");
|
||||
if (Solution2.IsValid())
|
||||
puts("[+] PatchSolution2 has been applied.");
|
||||
|
||||
puts("");
|
||||
puts("**************************************************************");
|
||||
puts("* Patch has been done successfully. Have fun and enjoy~~ *");
|
||||
puts("* DO NOT FORGET TO SIGN NAVICAT BY YOUR CERTIFICATE!!! *");
|
||||
puts("**************************************************************");
|
||||
|
||||
return 0;
|
||||
} catch (nkg::Exception& e) {
|
||||
printf("[-] %s:%zu -> \n", e.File(), e.Line());
|
||||
printf(" %s\n", e.Message());
|
||||
if (e.HasErrorCode()) {
|
||||
printf(" %s\n", e.ErrorString());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{30BE8CAB-6137-4441-9F64-599D0A6EEA0C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>navicatpatcher</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>D:\openssl-1.1.0f-vs2015\include64;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>D:\openssl-1.1.0f-vs2015\lib64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<AdditionalOptions>/std:c++latest</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="common.cpp" />
|
||||
<ClCompile Include="EncryptPublicKey.cpp" />
|
||||
<ClCompile Include="NavicatCrypto\aes.c" />
|
||||
<ClCompile Include="NavicatCrypto\aes_constant.c" />
|
||||
<ClCompile Include="NavicatCrypto\blowfish.c" />
|
||||
<ClCompile Include="NavicatCrypto\sha1.c" />
|
||||
<ClCompile Include="Solution0.cpp" />
|
||||
<ClCompile Include="Solution1.cpp" />
|
||||
<ClCompile Include="_tmain.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="def.hpp" />
|
||||
<ClInclude Include="NavicatCrypto\aes.h" />
|
||||
<ClInclude Include="NavicatCrypto\blowfish.h" />
|
||||
<ClInclude Include="NavicatCrypto\NavicatCrypto.hpp" />
|
||||
<ClInclude Include="NavicatCrypto\sha1.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="_tmain.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NavicatCrypto\aes.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NavicatCrypto\aes_constant.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NavicatCrypto\blowfish.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NavicatCrypto\sha1.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EncryptPublicKey.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Solution0.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="common.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Solution1.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NavicatCrypto\aes.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NavicatCrypto\blowfish.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NavicatCrypto\NavicatCrypto.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NavicatCrypto\sha1.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="def.hpp">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user