mirror of
https://github.com/Neo-Desktop/WindowsXPKg
synced 2025-06-13 09:04:17 +03:00
Compare commits
261 Commits
Server-200
...
neo-refact
Author | SHA1 | Date | |
---|---|---|---|
1cedbff4ef | |||
7a0faa42e8 | |||
c7eb049c0b | |||
015fd00d3f | |||
2ac7f9bc1e | |||
a827844cbd | |||
3e51fe1c8b | |||
783a5afb3a | |||
cb557c1ed8 | |||
d378c6499e | |||
5e68e1c8e1 | |||
bf6365916d | |||
3ea8731271 | |||
018f9f533c | |||
f1f1e0e6ea | |||
c4b63c15b2 | |||
1548e14169 | |||
c0a4c76b54 | |||
8cc691b72f | |||
72d48dd38b | |||
00d4906b28 | |||
88f60630c1 | |||
2ac6920e2c | |||
8f843ad4c3 | |||
2753bf2a40 | |||
d17ada2e64 | |||
6685b38aac | |||
884d8c9703 | |||
5ba2dbddd4 | |||
bf40bb6402 | |||
12a041c380 | |||
ecd9cd8dd2 | |||
6989ae6c94 | |||
ac510f8253 | |||
72c42f66c9 | |||
759c4009ef | |||
78c358c933 | |||
1d5e233c19 | |||
6c06732331 | |||
f347231362 | |||
a7e97e45ee | |||
bf57c32eae | |||
25db955b61 | |||
1aeceb28f1 | |||
b451a04f3c | |||
3e5e03df4d | |||
e3bdc93249 | |||
36b2eb3e7d | |||
49fefca596 | |||
178c9e0689 | |||
214d2d38a5 | |||
3ae078e3c5 | |||
12e511b3a5 | |||
21bac3b66c | |||
09842ace12 | |||
0d016b8872 | |||
b1743f4bff | |||
cc765edb4f | |||
4d1b5d6681 | |||
f59d77bdd1 | |||
71cbd19017 | |||
974f400cfc | |||
a2d521c230 | |||
d53409f5bd | |||
2703e17f69 | |||
680239bdb7 | |||
104bdb19e3 | |||
f2f859faeb | |||
a2d9c46a4b | |||
f65533bbb3 | |||
90e31b667a | |||
492d245f86 | |||
361a39e204 | |||
31993afb62 | |||
b3f64e6330 | |||
ccf93a0089 | |||
ae391a5e50 | |||
3620cf5af6 | |||
33774f7ad2 | |||
06ed5ef240 | |||
161aa2de4c | |||
a50688657d | |||
1679583e64 | |||
02c85b50b1 | |||
93732e152b | |||
95803054ba | |||
8619fccb11 | |||
06b9d937b1 | |||
453151f20f | |||
1bb00cf53d | |||
a787fc8e85 | |||
582ddf1bb8 | |||
13bf69c7e1 | |||
b7965f19e8 | |||
52c9a57ea2 | |||
283df1c1fe | |||
c1eb81490b | |||
2ee6a99acd | |||
1370a6ecff | |||
e3a6b78407 | |||
9fec269ad0 | |||
6ae5c9e435 | |||
a6bfaed6e8 | |||
f7b41a9810 | |||
e76eb7ac33 | |||
c91bbad69a | |||
75e81e7049 | |||
e9131e45c8 | |||
c664ea7f9c | |||
f95501b789 | |||
444f8c45c7 | |||
de09feb18f | |||
bde4371cbe | |||
f43a2d5c37 | |||
46c39df15d | |||
c078247bea | |||
232be6aba2 | |||
c0c3149be7 | |||
8e15a4f5b8 | |||
d411d56d81 | |||
11253c5e2c | |||
9f7920ca2d | |||
9063e32a89 | |||
958169ccb5 | |||
63fbbd83ef | |||
de659846d4 | |||
7c4bcdc847 | |||
859a21656c | |||
4b2ef7ac72 | |||
216c9cdf9d | |||
8f685a022c | |||
e4058ddf19 | |||
45004623be | |||
a4cb524fed | |||
03ae90163a | |||
c1e9a0f021 | |||
152c03456c | |||
ea51438766 | |||
8ee1acc2be | |||
3134a6f7a3 | |||
b75d08b3be | |||
20c84661b2 | |||
fefc8552b6 | |||
503fa3e1d8 | |||
15cbe19006 | |||
de04746c5e | |||
9817a83e74 | |||
bcd51e0e4e | |||
4b60737bb4 | |||
bc23fc5233 | |||
dc64133adf | |||
477f5c9af2 | |||
32a14cb8d9 | |||
db5ff7cd74 | |||
ca9ccc43ee | |||
57b2477e44 | |||
73a9cb3b2a | |||
40c60e656f | |||
62ab8caf87 | |||
7ea57ed136 | |||
529543ceef | |||
b1c80d3fa9 | |||
149f525a51 | |||
3e100d79a6 | |||
4bc029e645 | |||
fa0f832919 | |||
c306573fe8 | |||
88640191e8 | |||
e3b4485aa2 | |||
34619a2202 | |||
d4d50d9885 | |||
f11552509a | |||
eed869981b | |||
947fd48f38 | |||
0b94791ee1 | |||
f6755b0c22 | |||
3a7a37d814 | |||
4973d71d64 | |||
aa8e5ff8e7 | |||
4f7fb772a5 | |||
cc3900d4d0 | |||
726be7da20 | |||
98c8db7e02 | |||
8c295cf973 | |||
fcaa449ead | |||
42c24b57a1 | |||
0204d8486b | |||
6d3fd0031d | |||
cd3cc31cd6 | |||
29465ffb37 | |||
11dedcbd5f | |||
b69dbd541c | |||
530e5cdc21 | |||
da7e88b970 | |||
04e6362d7e | |||
1603dbd6e2 | |||
150f7433dc | |||
79d62a3b1b | |||
35c18d473b | |||
632c84249c | |||
d20cb1fa49 | |||
983acba760 | |||
974695b178 | |||
9b3abe7fb9 | |||
9812529903 | |||
21e31fd1b6 | |||
799fee5a68 | |||
1c5f93b687 | |||
3922223b9f | |||
9302ebd751 | |||
08ec7cb9bb | |||
8e4285c960 | |||
63bc103384 | |||
06920ede2a | |||
3f95974e61 | |||
166a0b5df7 | |||
e9a10e2882 | |||
728bf2a781 | |||
7c62596aa5 | |||
574b7b3b32 | |||
7944a9b15f | |||
6b85db12c9 | |||
19cce11bc2 | |||
475241e608 | |||
a14d44cdca | |||
d930648230 | |||
72d441b539 | |||
e437cc548a | |||
cc009d0ad4 | |||
96639bbaf7 | |||
1f30ff762d | |||
62e2e37373 | |||
814b8e48fb | |||
8088c455ff | |||
88619134bc | |||
bd11fb5eed | |||
5bf1da663a | |||
f5423a8eb0 | |||
3999ed0996 | |||
46adbee701 | |||
44dbb1e722 | |||
05ee5eb933 | |||
ac47a88f7e | |||
f5a76d8df5 | |||
388464da68 | |||
b6ade7c890 | |||
3764743558 | |||
ad91633ae1 | |||
aadeb8fe46 | |||
b7c6621809 | |||
1564056d68 | |||
fa12ad2c48 | |||
78194d7ab9 | |||
04601b7260 | |||
2af9f6db64 | |||
8c506fe798 | |||
a7a670be02 | |||
92938eb908 | |||
a40632a7fe | |||
9b040f9613 | |||
3d300e0c84 |
220
.clang-format
Normal file
220
.clang-format
Normal file
@ -0,0 +1,220 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Microsoft
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: false
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
QualifierAlignment: Leave
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
PackConstructorInitializers: BinPack
|
||||
BasedOnStyle: ''
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseLabels: false
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: Signature
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RequiresClausePosition: OwnLine
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
...
|
||||
---
|
||||
Language: Json
|
||||
BasedOnStyle: LLVM
|
||||
...
|
||||
|
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
build*/
|
||||
cmake*/
|
12
.gitattributes
vendored
Normal file
12
.gitattributes
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto eol=lf
|
||||
|
||||
*.c text
|
||||
*.h text
|
||||
*.cpp text
|
||||
*.hpp text
|
||||
*.json text
|
||||
*.txt text
|
||||
LICENSE text
|
||||
*.md text
|
||||
fully-licensed-wpa.txt -text
|
146
.github/workflows/dos-djgpp.yml
vendored
Normal file
146
.github/workflows/dos-djgpp.yml
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 06/19/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
name: C/C++ CI (DOS DJGPP)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CC: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-gcc
|
||||
CXX: ${{ github.workspace }}/djgpp/bin/i586-pc-msdosdjgpp-g++
|
||||
CMAKE_FIND_ROOT_PATH: ${{ github.workspace }}/djgpp
|
||||
GCC_EXEC_PREFIX: ${{ github.workspace }}/lib/gcc/
|
||||
DJDIR: ${{ github.workspace }}/djgpp/i586-pc-msdosdjgpp
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Setup build environment
|
||||
run: |
|
||||
sudo apt -y update
|
||||
sudo apt -y install build-essential cmake wget 7zip git flex libfl-dev nasm libslang2-dev pkg-config libslang2-modules gcc-multilib
|
||||
|
||||
- name: Download and Setup DJGPP Toolchain
|
||||
run: |
|
||||
wget https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/djgpp-linux64-gcc1220.tar.bz2
|
||||
tar xjf djgpp-linux64-gcc1220.tar.bz2
|
||||
echo "${{ github.workspace }}/djgpp/i586-pc-msdosdjgpp/bin/" >> "$GITHUB_ENV"
|
||||
echo "${{ github.workspace }}/djgpp/bin/" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Build UMSKT for MSDOS via DJGPP
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_DJGPP_COMPILE=On CMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH} CMAKE_BUILD_TYPE=Release
|
||||
build-dir: build
|
||||
c-compiler: ${CC}
|
||||
cxx-compiler: ${CXX}
|
||||
build-args: -j 2
|
||||
|
||||
- name: Move executable to upload directory
|
||||
run: |
|
||||
mkdir build/actions_upload
|
||||
mv build/umskt.exe build/actions_upload/
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-DOS
|
||||
path: build/actions_upload
|
||||
|
||||
build-dos-win32-combined:
|
||||
needs: build
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
# https://github.com/actions/runner-images/issues/6067#issuecomment-1213069040
|
||||
- name: Install Windows XP Support for Visual Studio
|
||||
run: |
|
||||
Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
|
||||
$InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
|
||||
$componentsToAdd = @(
|
||||
"Microsoft.VisualStudio.Component.WinXP"
|
||||
)
|
||||
[string]$workloadArgs = $componentsToAdd | ForEach-Object {" --add " + $_}
|
||||
$Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache')
|
||||
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
|
||||
if ($process.ExitCode -eq 0)
|
||||
{
|
||||
Write-Host "components have been successfully added"
|
||||
Get-ChildItem C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Windows.XPSupport.*
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "components were not installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Download Built DOS Artifact
|
||||
uses: actions/download-artifact@v4.1.2
|
||||
with:
|
||||
name: UMSKT-DOS
|
||||
|
||||
- name: Configure and build UMSKT for DOS+Win32
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_MSVC_WINXP=On CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache UMSKT_MSVC_MSDOS_STUB=${{ github.workspace }}/umskt.exe
|
||||
generator: "Visual Studio 17 2022"
|
||||
args: -A "Win32" -T "v141_xp"
|
||||
run-build: true
|
||||
build-args: "--config Release -j 2"
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-DOS+Win32
|
||||
path: build/Release
|
74
.github/workflows/freebsd.yml
vendored
Normal file
74
.github/workflows/freebsd.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by techguy16 on 07/23/2023
|
||||
# @Maintainer techguy16
|
||||
|
||||
name: C/C++ CI (FreeBSD)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: build-x86_64
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Build & Test in FreeBSD
|
||||
id: test
|
||||
uses: vmactions/freebsd-vm@v1.0.6
|
||||
with:
|
||||
usesh: true
|
||||
prepare: |
|
||||
pkg install -y cmake git bash
|
||||
|
||||
run: |
|
||||
mkdir build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCPM_SOURCE_CACHE= ${{ github.workspace }}/.cpm-cache -DBUILD_TESTING=On -B build/
|
||||
cmake --build build/ -j 2
|
||||
cd build
|
||||
ctest
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-FreeBSD
|
||||
path: build/actions_upload
|
89
.github/workflows/linux.yml
vendored
Normal file
89
.github/workflows/linux.yml
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by TheTank20 on 06/13/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
name: C/C++ CI (Linux)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch:
|
||||
- x86
|
||||
- x86_64
|
||||
- aarch64
|
||||
- armhf
|
||||
- armv7
|
||||
- ppc64le
|
||||
- s390x
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Setup latest Alpine Linux for ${{ matrix.arch }}
|
||||
uses: jirutka/setup-alpine@v1
|
||||
with:
|
||||
packages: >
|
||||
bash
|
||||
build-base
|
||||
cmake
|
||||
git
|
||||
musl-dev
|
||||
arch: ${{ matrix.arch }}
|
||||
shell-name: alpine-target.sh
|
||||
|
||||
- name: Configure and build UMSKT
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: UMSKT_MUSL_STATIC=ON CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache BUILD_TESTING=On
|
||||
run-build: true
|
||||
build-args: -j 2
|
||||
run-test: true
|
||||
shell: alpine-target.sh {0}
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-linux-${{ matrix.arch }}-static
|
||||
path: build/actions_upload
|
71
.github/workflows/macos.yml
vendored
Normal file
71
.github/workflows/macos.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by techguy16 on 07/23/2023
|
||||
# @Maintainer techguy16
|
||||
|
||||
name: C/C++ CI (macOS)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**' ] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch:
|
||||
- { name: arm64;x86_64, displayName: all-x86_64_arm64 }
|
||||
- { name: x86_64, displayName: x86_64 }
|
||||
- { name: arm64, displayName: arm64 }
|
||||
steps:
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Configure and build UMSKT for ${{ matrix.arch.displayName }}
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: MUSL_STATIC=ON CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache CMAKE_OSX_ARCHITECTURES="${{ matrix.arch.name }}" BUILD_TESTING=On
|
||||
run-build: true
|
||||
build-args: -j 2
|
||||
run-test: true
|
||||
|
||||
- name: Move files to correct directory
|
||||
run: |
|
||||
mkdir -p build/actions_upload
|
||||
mv build/umskt build/actions_upload/umskt
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-macOS-${{ matrix.arch.displayName }}
|
||||
path: build/actions_upload
|
90
.github/workflows/windows.yml
vendored
Normal file
90
.github/workflows/windows.yml
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by TheTank20 on 06/13/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
name: C/C++ CI (Windows)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
pull_request:
|
||||
branches: [ "*" ]
|
||||
paths-ignore: [ '**.md', 'doc/**', '.idea/**'] # If only these files are edited, skip
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [ { name: Win32, displayName: x86 }, { name: x64, displayName: x64 } ]
|
||||
steps:
|
||||
# https://github.com/actions/runner-images/issues/6067#issuecomment-1213069040
|
||||
- name: Install Windows XP Support for Visual Studio
|
||||
run: |
|
||||
Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
|
||||
$InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
|
||||
$componentsToAdd = @(
|
||||
"Microsoft.VisualStudio.Component.WinXP"
|
||||
)
|
||||
[string]$workloadArgs = $componentsToAdd | ForEach-Object {" --add " + $_}
|
||||
$Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache')
|
||||
$process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden
|
||||
if ($process.ExitCode -eq 0)
|
||||
{
|
||||
Write-Host "components have been successfully added"
|
||||
Get-ChildItem C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Windows.XPSupport.*
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "components were not installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Set up CPM cache
|
||||
id: cache-cpm
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/.cpm-cache
|
||||
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cpm-
|
||||
|
||||
- name: Checkout Source Tree
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
|
||||
- name: Configure and build UMSKT for ${{ matrix.values.displayName }}
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: CMAKE_BUILD_TYPE=Release CPM_SOURCE_CACHE=${{ github.workspace }}/.cpm-cache BUILD_TESTING=On
|
||||
generator: "Visual Studio 17 2022"
|
||||
args: -A "${{ matrix.arch.name }}" -T "v141_xp"
|
||||
run-build: true
|
||||
build-args: --config Release -j 2
|
||||
run-test: true
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: UMSKT-${{ matrix.values.displayName }}
|
||||
path: build/Release
|
256
.gitignore
vendored
Normal file
256
.gitignore
vendored
Normal file
@ -0,0 +1,256 @@
|
||||
build*/
|
||||
*.tar
|
||||
*.exe
|
||||
*.wasm
|
||||
umskt
|
||||
.cpm-cache
|
||||
|
||||
### NotepadPP template
|
||||
# Notepad++ backups #
|
||||
*.bak
|
||||
|
||||
### VisualStudioCode template
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### JetBrains+all template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Linux template
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
### Windows template
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### Vim template
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
### macOS template
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### SublimeText template
|
||||
# Cache files for Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# Workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# Project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using Sublime Text
|
||||
# *.sublime-project
|
||||
|
||||
# SFTP configuration file
|
||||
sftp-config.json
|
||||
sftp-config-alt*.json
|
||||
|
||||
# Package control specific files
|
||||
Package Control.last-run
|
||||
Package Control.ca-list
|
||||
Package Control.ca-bundle
|
||||
Package Control.system-ca-bundle
|
||||
Package Control.cache/
|
||||
Package Control.ca-certs/
|
||||
Package Control.merged-ca-bundle
|
||||
Package Control.user-ca-bundle
|
||||
oscrypto-ca-bundle.crt
|
||||
bh_unicode_properties.cache
|
||||
|
||||
# Sublime-github package stores a github token in this file
|
||||
# https://packagecontrol.io/packages/sublime-github
|
||||
GitHub.sublime-settings
|
||||
|
||||
### CMake template
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
CMakeSettings.json
|
||||
|
||||
# Visual Studio
|
||||
.vs/
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
UMSKT
|
2
.idea/UMSKT.iml
generated
Normal file
2
.idea/UMSKT.iml
generated
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
2
.idea/WindowsXPKg.iml
generated
Normal file
2
.idea/WindowsXPKg.iml
generated
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
90
.idea/editor.xml
generated
Normal file
90
.idea/editor.xml
generated
Normal file
@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="BackendCodeEditorSettings">
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
|
||||
</component>
|
||||
</project>
|
15
.idea/misc.xml
generated
Normal file
15
.idea/misc.xml
generated
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="CidrRootsConfiguration">
|
||||
<sourceRoots>
|
||||
<file path="$PROJECT_DIR$/src" />
|
||||
</sourceRoots>
|
||||
<libraryRoots>
|
||||
<file path="$PROJECT_DIR$/lib" />
|
||||
</libraryRoots>
|
||||
<excludeRoots>
|
||||
<file path="$PROJECT_DIR$/build" />
|
||||
</excludeRoots>
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/UMSKT.iml" filepath="$PROJECT_DIR$/.idea/UMSKT.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
14
.idea/remote-targets.xml
generated
Normal file
14
.idea/remote-targets.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteTargetsManager">
|
||||
<option name="projectDefaultTargetUuid" value="36c80fd0-a122-4ef6-8ee6-1bd41007a378" />
|
||||
<targets>
|
||||
<target name="WSL - Ubuntu" type="wsl" uuid="36c80fd0-a122-4ef6-8ee6-1bd41007a378">
|
||||
<config>
|
||||
<option name="distributionMsId" value="Ubuntu" />
|
||||
<option name="projectRootOnTarget" value="{exitCode=0, timeout=false, cancelled=false, stdout=/mnt/c/Users/neo/AppData/Local/Programs/CLion/jbr/bin , stderr=}/UMSKT" />
|
||||
</config>
|
||||
</target>
|
||||
</targets>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
30
.pre-commit-config.yaml
Normal file
30
.pre-commit-config.yaml
Normal file
@ -0,0 +1,30 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 01/03/2024
|
||||
# @Maintainer Neo
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: 'v17.0.6' # Use the sha / tag you want to point at
|
||||
hooks:
|
||||
- id: clang-format
|
||||
|
||||
# - repo: https://github.com/cheshirekow/cmake-format-precommit
|
||||
# rev: v0.6.10
|
||||
# hooks:
|
||||
# - id: cmake-format
|
264
CMakeLists.txt
Normal file
264
CMakeLists.txt
Normal file
@ -0,0 +1,264 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Andrew on 05/30/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
|
||||
SET(PROJECT_NAME UMSKT)
|
||||
PROJECT(${PROJECT_NAME})
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
SET(CMAKE_OSX_SYSROOT "macosx" CACHE PATH "macOS SDK path")
|
||||
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
OPTION(BUILD_TESTING "Build testing binaries for CTest" OFF)
|
||||
OPTION(BUILD_SHARED_LIBS "Build all dependant libraries as shared" OFF)
|
||||
|
||||
OPTION(UMSKT_BUILD_SHARED_LIB "Build libumskt.so/.dll/.dylib" ON)
|
||||
OPTION(UMSKT_BUILD_STATIC_LIB "Build libumskt_static.a/.lib" ON)
|
||||
OPTION(UMSKT_MUSL_STATIC "Enable fully static builds in a muslc environment (i.e. Alpine Linux)" OFF)
|
||||
OPTION(UMSKT_DJGPP_COMPILE "Enable compilation and linking with DJGPP" OFF)
|
||||
OPTION(UMSKT_MSVC_MSDOS_STUB "Specify a custom MS-DOS stub for a 32-bit MSVC compilation" OFF)
|
||||
OPTION(UMSKT_MSVC_WINXP "Specify compile-time flag overrides for Windows XP" OFF)
|
||||
|
||||
IF (NOT MSVC)
|
||||
SET(CMAKE_CXX_FLAGS "-Os -fdata-sections -ffunction-sections -flto=auto -Wl,--gc-sections")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG_INIT "-Wall -Wextra -pedantic")
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-Wall -Wextra -pedantic")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE_INIT "-s")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--gc-sections")
|
||||
ENDIF ()
|
||||
|
||||
IF (UMSKT_DJGPP_COMPILE)
|
||||
SET(CMAKE_SYSTEM_NAME MSDOS)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
SET(UMSKT_BUILD_SHARED_LIB OFF)
|
||||
SET(UMSKT_BUILD_STATIC_LIB OFF)
|
||||
SET(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -march=i386 -mtune=i386")
|
||||
MESSAGE(STATUS "[UMSKT] DJGPP Build requested - Shared libraries forced OFF")
|
||||
ENDIF ()
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
SET(BUILD_SHARED_LIBS ON)
|
||||
MESSAGE(STATUS "[UMSKT] macOS Build requested - Shared libraries forced ON")
|
||||
ENDIF ()
|
||||
|
||||
# if we're compiling with MSVC, respect the DEBUG compile option
|
||||
IF (MSVC)
|
||||
SET(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
SET(CMAKE_CXX_FLAGS "/Os /LTCG /Gy /OPT:REF /OPT:ICF /EHsc")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/MT")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /LTCG")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
|
||||
SET(CMAKE_ENABLE_EXPORTS ON)
|
||||
SET(UMSKT_EXE_WINDOWS_EXTRA src/windows/umskt.rc)
|
||||
SET(UMSKT_EXE_WINDOWS_DLL src/windows/dllmain.cpp)
|
||||
IF (UMSKT_MSVC_WINXP)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /U_WIN32_WINNT /DWINVER=0x0501 /D_WIN32_WINNT=0x0501")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF (MUSL_STATIC)
|
||||
MESSAGE(STATUS "[UMSKT] musl libc Build requested - Shared librares forced OFF")
|
||||
SET(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
||||
ENDIF ()
|
||||
|
||||
# initialize cpm.CMake
|
||||
FILE(
|
||||
DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
|
||||
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
|
||||
)
|
||||
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
|
||||
CPMUsePackageLock(${CMAKE_SOURCE_DIR}/package-lock.cmake)
|
||||
|
||||
# fetch cpm.CMake dependencies
|
||||
# Include JSON development library
|
||||
CPMAddPackage(
|
||||
NAME nlohmann_json
|
||||
GITHUB_REPOSITORY nlohmann/json
|
||||
VERSION 3.11.3
|
||||
)
|
||||
|
||||
# Include fmt development library
|
||||
CPMAddPackage(
|
||||
NAME fmt
|
||||
GITHUB_REPOSITORY fmtlib/fmt
|
||||
GIT_TAG 10.2.0
|
||||
VERSION 10.2.0
|
||||
)
|
||||
|
||||
# Include cmrc resource compiler
|
||||
CPMAddPackage(
|
||||
NAME cmrc
|
||||
GITHUB_REPOSITORY vector-of-bool/cmrc
|
||||
GIT_TAG 2.0.1
|
||||
VERSION 2.0.1
|
||||
)
|
||||
|
||||
# Include stdint128
|
||||
CPMAddPackage(
|
||||
NAME stdint128
|
||||
GITHUB_REPOSITORY UMSKT/stdint128-cmake
|
||||
GIT_TAG v1.0.0
|
||||
VERSION 1.0.0
|
||||
)
|
||||
|
||||
# Include Crypto++ development library
|
||||
CPMAddPackage(
|
||||
NAME cryptopp-cmake
|
||||
GITHUB_REPOSITORY UMSKT/cryptopp-cmake
|
||||
GIT_TAG CRYPTOPP_8_9_0
|
||||
VERSION 8.9.0
|
||||
OPTIONS "CRYPTOPP_BUILD_TESTING OFF"
|
||||
)
|
||||
|
||||
### Resource compilation
|
||||
CMRC_ADD_RESOURCE_LIBRARY(umskt-rc ALIAS umskt::rc NAMESPACE umskt keys.json)
|
||||
|
||||
SET(LIBUMSKT_PIDGEN2 src/libumskt/pidgen2/PIDGEN2.cpp)
|
||||
SET(LIBUMSKT_PIDGEN3 src/libumskt/pidgen3/PIDGEN3.cpp src/libumskt/pidgen3/BINK1998.cpp src/libumskt/pidgen3/BINK2002.cpp)
|
||||
SET(LIBUMSKT_CONFID src/libumskt/confid/confid.cpp src/libumskt/confid/polynomial.cpp src/libumskt/confid/residue.cpp src/libumskt/confid/divisor.cpp)
|
||||
SET(LIBUMSKT_SRC src/libumskt/libumskt.cpp src/libumskt/init.cpp src/libumskt/pidgen.cpp ${LIBUMSKT_PIDGEN2} ${LIBUMSKT_PIDGEN3} ${LIBUMSKT_CONFID})
|
||||
SET(UMSKT_CLI_SRC src/main.cpp src/cli/help.cpp src/cli/cli.cpp src/cli/confirmationid.cpp src/cli/options.cpp src/cli/pidgen.cpp)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} fmt cryptopp stdint128)
|
||||
|
||||
IF (NOT MSVC)
|
||||
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} umskt::rc)
|
||||
SET(UMSKT_CLI_SRC ${UMSKT_CLI_SRC} src/rc.cpp)
|
||||
ELSE()
|
||||
SET(UMSKT_CLI_SRC ${UMSKT_CLI_SRC} src/windows/platform.cpp)
|
||||
ENDIF()
|
||||
|
||||
#### Separate Build Path for emscripten
|
||||
IF (EMSCRIPTEN)
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${LIBUMSKT_SRC})
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC ${UMSKT_LINK_LIBS})
|
||||
SET(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES COMPILE_FLAGS "-sEXPORTED_RUNTIME_METHODS=ccall,cwrap")
|
||||
SET_TARGET_PROPERTIES(umskt PROPERTIES LINK_FLAGS "-sWASM=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=ccall,cwrap --no-entry")
|
||||
ELSE ()
|
||||
## umskt.so/.dll creation
|
||||
IF (UMSKT_BUILD_SHARED_LIB)
|
||||
ADD_LIBRARY(libumskt SHARED ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(libumskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(libumskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(libumskt PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF (MSVC)
|
||||
SET_TARGET_PROPERTIES(libumskt PROPERTIES OUTPUT_NAME libumskt)
|
||||
ELSE ()
|
||||
SET_TARGET_PROPERTIES(libumskt PROPERTIES OUTPUT_NAME umskt)
|
||||
ENDIF ()
|
||||
ENDIF()
|
||||
|
||||
## umskt_static.a/.lib creation
|
||||
IF (UMSKT_BUILD_STATIC_LIB)
|
||||
ADD_LIBRARY(libumskt_static ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
||||
TARGET_INCLUDE_DIRECTORIES(libumskt_static PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(libumskt_static PUBLIC ${UMSKT_LINK_DIRS})
|
||||
TARGET_LINK_LIBRARIES(libumskt_static PUBLIC ${UMSKT_LINK_LIBS})
|
||||
IF (MSVC)
|
||||
SET_TARGET_PROPERTIES(libumskt_static PROPERTIES OUTPUT_NAME libumskt_static)
|
||||
ELSE ()
|
||||
SET_TARGET_PROPERTIES(libumskt_static PROPERTIES OUTPUT_NAME umskt_static)
|
||||
ENDIF ()
|
||||
ENDIF()
|
||||
|
||||
### UMSKT executable compilation
|
||||
IF (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
### only build CLI if we're building UMSKT explicitly
|
||||
IF (UMSKT_BUILD_STATIC_LIB)
|
||||
## Link against the static lib
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC libumskt_static ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ELSEIF (UMSKT_BUILD_SHARED_LIB)
|
||||
## Link against the dynamic lib
|
||||
ADD_EXECUTABLE(umskt ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC libumskt ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ELSE()
|
||||
## Don't link against our output, do a full libumskt+cli compile
|
||||
ADD_EXECUTABLE(umskt ${LIBUMSKT_SRC} ${UMSKT_CLI_SRC} ${UMSKT_EXE_WINDOWS_EXTRA})
|
||||
TARGET_LINK_LIBRARIES(umskt PUBLIC ${UMSKT_LINK_LIBS} nlohmann_json::nlohmann_json)
|
||||
ENDIF()
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
|
||||
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
||||
IF (MSVC)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY COMPILE_FLAGS /DUMSKT_CLI_WINRC_EMBED_JSON)
|
||||
IF (MSVC_MSDOS_STUB)
|
||||
SET_PROPERTY(TARGET umskt APPEND PROPERTY LINK_FLAGS /STUB:${MSVC_MSDOS_STUB})
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
INSTALL(TARGETS umskt DESTINATION bin)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
### Strip the built binary
|
||||
IF (${CMAKE_BUILD_TYPE} MATCHES "Release" AND NOT MSVC)
|
||||
ADD_CUSTOM_COMMAND(TARGET umskt POST_BUILD
|
||||
COMMAND strip $<TARGET_FILE:umskt>
|
||||
COMMENT "Stripping symbols for release"
|
||||
)
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
|
||||
#### Build Path for Unit Tests
|
||||
IF ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR UMSKT_BUILD_TESTING) AND BUILD_TESTING)
|
||||
INCLUDE(CTest)
|
||||
ENABLE_TESTING()
|
||||
|
||||
#include googletest unit testing library
|
||||
CPMAddPackage(
|
||||
NAME googletest
|
||||
GITHUB_REPOSITORY google/googletest
|
||||
VERSION 1.14.0
|
||||
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
|
||||
)
|
||||
|
||||
MACRO(ADD_GTEST TEST)
|
||||
ADD_EXECUTABLE(${TEST} ${ARGN})
|
||||
TARGET_LINK_LIBRARIES(${TEST} gtest gmock gtest_main libumskt_static)
|
||||
TARGET_COMPILE_FEATURES(${TEST} PRIVATE cxx_std_17)
|
||||
SET_TARGET_PROPERTIES(${TEST} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
ADD_TEST(${TEST} tests/${TEST})
|
||||
ENDMACRO()
|
||||
|
||||
ADD_GTEST(TEST_PIDGEN2 src/libumskt/pidgen2/PIDGEN2_unittest.cpp)
|
||||
ADD_GTEST(TEST_PIDGEN3_BINK1998 src/libumskt/pidgen3/BINK1998_unittest.cpp)
|
||||
ADD_GTEST(TEST_PIDGEN3_BINK2002 src/libumskt/pidgen3/BINK2002_unittest.cpp)
|
||||
ADD_GTEST(TEST_CONFIRMATIONID src/libumskt/confid/confid_unittest.cpp)
|
||||
|
||||
ENDIF ()
|
52
Dockerfile
Normal file
52
Dockerfile
Normal file
@ -0,0 +1,52 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 06/19/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
# Stage 1: Install Prereqisites
|
||||
FROM alpine:latest as prereqisites
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
build-base \
|
||||
cmake \
|
||||
git \
|
||||
musl-dev
|
||||
|
||||
|
||||
# Stage 2: Build
|
||||
FROM prereqisites as builder
|
||||
|
||||
WORKDIR /src
|
||||
COPY . /src
|
||||
|
||||
# Build UMSKT from the local directory
|
||||
RUN mkdir /src/build \
|
||||
&& cmake -B /src/build -DCPM_SOURCE_CACHE=/src/.cpm-cache -DCMAKE_BUILD_TYPE=Release -DUMSKT_MUSL_STATIC=ON \
|
||||
&& cmake --build /src/build -j 10
|
||||
|
||||
# Stage 3: Output
|
||||
FROM scratch as output
|
||||
|
||||
COPY --from=builder /src/build/umskt /
|
||||
COPY --from=builder /src/build/libumskt_static.a /
|
||||
COPY --from=builder /src/build/libumskt.so /
|
||||
|
||||
# invoke via
|
||||
# docker build -o type=tar,dest=build-musl/umskt.tar .
|
73
Dockerfile.djgpp
Normal file
73
Dockerfile.djgpp
Normal file
@ -0,0 +1,73 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 06/19/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
# Stage 1: Install Prerequisites
|
||||
FROM ubuntu:latest as prerequisites
|
||||
|
||||
# Stage 1: Install build dependencies
|
||||
RUN apt-get update && apt-get -y install \
|
||||
build-essential \
|
||||
cmake \
|
||||
wget \
|
||||
7zip \
|
||||
git \
|
||||
flex \
|
||||
libfl-dev \
|
||||
nasm \
|
||||
libslang2-dev \
|
||||
pkg-config \
|
||||
libslang2-modules \
|
||||
gcc-multilib \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
FROM prerequisites as djgpp
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
WORKDIR /
|
||||
|
||||
ENV CC=/djgpp/bin/i586-pc-msdosdjgpp-gcc CXX=/djgpp/bin/i586-pc-msdosdjgpp-g++ CMAKE_FIND_ROOT_PATH=/djgpp
|
||||
|
||||
# Stage 2: setup djgpp
|
||||
RUN wget https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/djgpp-linux64-gcc1220.tar.bz2 \
|
||||
&& tar xjf djgpp-linux64-gcc1220.tar.bz2 \
|
||||
&& rm -rf djgpp-linux64-gcc1220.tar.bz2
|
||||
|
||||
# Stage 3: compile UMSKT
|
||||
FROM djgpp as build
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
WORKDIR /src
|
||||
COPY . /src
|
||||
|
||||
# Build UMSKT from the local directory
|
||||
RUN mkdir /src/build \
|
||||
&& source /djgpp/setenv \
|
||||
&& cmake -DUMSKT_DJGPP_COMPILE=On -DCMAKE_BUILD_TYPE=Release -DCPM_SOURCE_CACHE=`pwd`/.cpm-cache -B build \
|
||||
&& cmake --build build -j 10 --verbose
|
||||
|
||||
CMD ["bash"]
|
||||
|
||||
# Stage 6: Output
|
||||
FROM scratch as output
|
||||
|
||||
COPY --from=build /src/build/umskt.exe /
|
||||
|
||||
# invoke via
|
||||
# docker build -f Dockerfile.djgpp -o type=tar,dest=build-djgpp/umskt-dos.tar .
|
64
Dockerfile.emscripten
Normal file
64
Dockerfile.emscripten
Normal file
@ -0,0 +1,64 @@
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 06/25/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
# Stage 1: Install Prerequisites
|
||||
FROM emscripten/emsdk:latest as prerequisites
|
||||
RUN apt update \
|
||||
&& apt -y install pkg-config \
|
||||
&& apt -y clean autoclean autoremove
|
||||
|
||||
# Stage 2: compile OpenSSL for emscripten
|
||||
FROM prerequisites as openssl
|
||||
WORKDIR /tmp
|
||||
ENV EMSCRIPTEN=/emsdk/upstream/emscripten VERBOSE=1
|
||||
RUN git clone https://github.com/openssl/openssl.git openssl \
|
||||
&& cd openssl \
|
||||
&& git checkout openssl-3.1.1 \
|
||||
&& emconfigure ./Configure gcc -no-tests -no-asm -static -fPIC -no-sock -no-afalgeng -DOPENSSL_SYS_NETWARE -DSIG_DFL=0 -DSIG_IGN=0 -DHAVE_FORK=0 -DOPENSSL_NO_AFALGENG=1 --with-rand-seed=getrandom --prefix=$EMSCRIPTEN/cache/sysroot|| exit $? \
|
||||
&& sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile \
|
||||
&& emmake make -j 12 build_generated libssl.a libcrypto.a build_libs_nodep \
|
||||
&& rm -rf $EMSCRIPTEN/cache/sysroot/include/openssl \
|
||||
&& cp -R include/openssl $EMSCRIPTEN/cache/sysroot/include \
|
||||
&& cp libcrypto.a libssl.a $EMSCRIPTEN/cache/sysroot/lib \
|
||||
&& cp libcrypto.pc libssl.pc openssl.pc $EMSCRIPTEN/cache/sysroot/lib/pkgconfig/ \
|
||||
&& cd .. \
|
||||
&& rm -rf openssl
|
||||
|
||||
# Stage 3: compile UMSKT
|
||||
FROM openssl as build
|
||||
|
||||
WORKDIR /src
|
||||
COPY . /src
|
||||
|
||||
# Build UMSKT from the local directory
|
||||
RUN mkdir /src/build \
|
||||
&& cd /src/build \
|
||||
&& emcmake cmake .. \
|
||||
&& emmake make
|
||||
|
||||
CMD ["bash"]
|
||||
|
||||
# Stage 4: Output
|
||||
FROM scratch as output
|
||||
|
||||
COPY --from=build /src/build/umskt.html /src/build/umskt.wasm /src/build/umskt.js /
|
||||
|
||||
# invoke via
|
||||
# docker build -f Dockerfile.emscripten -o type=tar,dest=umskt-wasm.tar .
|
73
Dockerfile.windows
Normal file
73
Dockerfile.windows
Normal file
@ -0,0 +1,73 @@
|
||||
# escape=`
|
||||
|
||||
# This file is a part of the UMSKT Project
|
||||
#
|
||||
# Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @FileCreated by Neo on 06/19/2023
|
||||
# @Maintainer Neo
|
||||
|
||||
# Stage 1: Install Visual Studio
|
||||
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8.1 as visualstudio
|
||||
# Download and install Build Tools for Visual Studio 2022 for native desktop workload.
|
||||
ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
#ADD vs_buildtools.exe C:\TEMP\vs_buildtools.exe
|
||||
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
|
||||
--add Microsoft.VisualStudio.Workload.VCTools `
|
||||
--add Microsoft.VisualStudio.Workload.MSBuildTools `
|
||||
--add Microsoft.VisualStudio.Component.WinXP `
|
||||
--includeRecommended `
|
||||
--installPath C:\BuildTools \
|
||||
|
||||
# Stage 2: Install Chocolatey and Prereqisites
|
||||
FROM visualstudio as prereqisites
|
||||
WORKDIR C:\TEMP\
|
||||
|
||||
RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"]
|
||||
RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "choco feature enable -n allowGlobalConfirmation"]
|
||||
RUN ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass", "choco install git --params \"'/GitAndUnixToolsOnPath /WindowsTerminal /NoShellIntegration /NoGuiHereIntegration /NoShellHereIntegration /NoCredentialManager /SChannel'\""]
|
||||
|
||||
# Stage 3: Build the 32-bit version of UMSKT
|
||||
FROM prereqisites as Build32
|
||||
WORKDIR C:\umskt\
|
||||
COPY . C:\umskt\
|
||||
|
||||
RUN C:\BuildTools\Common7\Tools\VsDevCmd.bat && `
|
||||
mkdir C:\umskt\build && cd C:\umskt && `
|
||||
cmake -B build -DCPM_SOURCE_CACHE=../.cpm-cache -DUMSKT_MSVC_WINXP=On -DCMAKE_BUILD_TYPE=Release -DMSVC_MSDOS_STUB=..\umskt.exe -G "Visual Studio 17 2022" -A "Win32" -T v141_xp && `
|
||||
cmake --build build --config Release -j 10
|
||||
|
||||
# Stage 4: Build the 64-bit version of UMSKT
|
||||
FROM prereqisites as Build64
|
||||
|
||||
WORKDIR C:\umskt\
|
||||
COPY . C:\umskt\
|
||||
|
||||
RUN C:\BuildTools\Common7\Tools\VsDevCmd.bat && `
|
||||
cd C:\umskt && `
|
||||
cmake -B build -DCPM_SOURCE_CACHE=../.cpm-cache -DCMAKE_BUILD_TYPE=Release && `
|
||||
cmake --build build --config Release -j 10
|
||||
|
||||
# Stage 5: Copy binaries to an output/runtime image
|
||||
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8.1 as output
|
||||
|
||||
COPY --from=Build32 C:\umskt\build\Release\umskt.exe C:\umskt\umskt.exe
|
||||
COPY --from=Build64 C:\umskt\build\Release\umskt.exe C:\umskt\umskt64.exe
|
||||
|
||||
#invoke via
|
||||
# docker build -f Dockerfile.windows .
|
||||
# docker run <hash>
|
||||
# docker cp <plug>:C:\umskt umskt-win
|
674
LICENSE
674
LICENSE
@ -1,21 +1,661 @@
|
||||
MIT License
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (c) 2019 TheMCHK
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
130
README.md
130
README.md
@ -1,33 +1,119 @@
|
||||
## **Windows XP Keygen!**
|
||||
# Universal MS Key Toolkit (UMSKT)
|
||||
|
||||
# **FAQ**
|
||||
**Connect with us**
|
||||
|
||||
* **What does it do?**
|
||||
[](https://umskt.zulipchat.com)
|
||||
[](https://web.libera.chat/gamja/?nick=Guest?#mspid)
|
||||
[](https://discord.gg/PpBSpuphWM)
|
||||
|
||||
This program allows you to generate endless Windows XP keys.
|
||||
You also can use it to check your already existing keys.
|
||||
**Build status**
|
||||
|
||||
* **How does it work?**
|
||||
[](../../actions/workflows/windows.yml)
|
||||
|
||||
This program is based on [this paper](https://www.licenturion.com/xp/fully-licensed-wpa.txt) Basically,
|
||||
it uses a cracked private key from Microsoft to sign some stuff encoded in the 25-digit product key. It also does this process in reverse to check for the validation of the keys.
|
||||
[](../../actions/workflows/macos.yml)
|
||||
|
||||
* **How do I use it?**
|
||||
[](../../actions/workflows/linux.yml)
|
||||
|
||||
It all comes down to four simple steps:
|
||||
|
||||
|
||||
**1.** Use this program to generate a key, and use such key during installation.
|
||||
|
||||
**2.** After installation, you will be prompted to activate Windows. Select the
|
||||
*telephone activation* method, then, fire up [this website](https://msdev.gointeract.io/interact/index?interaction=1461173234028-3884f8602eccbe259104553afa8415434b4581-05d1&accountId=microsoft&appkey=196de13c-e946-4531-98f6-2719ec8405ce) and enter the installation ID that the activation wizard gave you.
|
||||
|
||||
**3.** Click "**Next**"
|
||||
|
||||
**4.** Profit!
|
||||
[](../../actions/workflows/freebsd.yml)
|
||||
|
||||
[](../../actions/workflows/dos-djgpp.yml)
|
||||
|
||||
------
|
||||
|
||||
### Plan of Action / ToDo List
|
||||
|
||||
In light of the recent exponential interest in this project I've decided to put updates of this project here:
|
||||
|
||||
[Please see ticket #8 for more information](https://github.com/UMSKT/UMSKT/issues/8)
|
||||
|
||||
------
|
||||
|
||||
### **FAQ**
|
||||
|
||||
#### **What does it do?**
|
||||
|
||||
* This program is a tool for researching and experimenting with retro Microsoft product licensing, for products released before 2012.
|
||||
|
||||
#### **How does it work?**
|
||||
|
||||
* [Enderman's XPKeygen Readme explains everything in detail.](https://github.com/Endermanch/XPKeygen)
|
||||
|
||||
#### **How do I use it?**
|
||||
|
||||
* It all comes down to four simple steps:
|
||||
|
||||
------
|
||||
|
||||
### **Usage**
|
||||
#### 1. Download the latest version of UMSKT
|
||||
|
||||
* *(GitHub account required)*
|
||||
* Download the latest experimental version using the Actions tab ([Windows](../../actions/workflows/windows.yml?query=branch%3Amaster+is%3Asuccess), [Linux](../../actions/workflows/linux.yml?query=branch%3Amaster+is%3Asuccess), [macOS](../../actions/workflows/macos.yml?query=branch%3Amaster+is%3Asuccess), [FreeBSD](../../actions/workflows/freebsd.yml?query=branch%3Amaster+is%3Asuccess), [DOS DJGPP](../../actions/workflows/dos-djgpp.yml?query=branch%3Amaster+is%3Asuccess))
|
||||
|
||||
|
||||
* ~~*(GitHub account \*not\* required)*~~
|
||||
* ~~Download the latest release for your operating system and architecture from [the releases page](../../releases)~~
|
||||
* No official releases right now, use the other method to get the latest version.
|
||||
|
||||
**REQUIREMENTS:**
|
||||
* **Note:** Before continuing, please ensure you have the `umskt` executable extracted and on UNIX-like systems, have execution permissions (`chmod +x umskt`).
|
||||
|
||||
* `OpenSSL >0.9.8b`
|
||||
#### 2. Run `umskt` to generate a key, or add `--help` or `-h` to see more options.
|
||||
|
||||
#### 3. *(Activation step for `Retail` and `OEM` only)*
|
||||
* After installation, you will be prompted to activate Windows.
|
||||
|
||||
|
||||
* Select the **telephone activation** method, then, run `umskt -i <Installation ID>` using the `Installation ID` the activation Wizard provides for you
|
||||
* If you're activating a non-Windows product, use `umskt -i <Installation ID> -m <Product>`, where `<Product>` is one of `OFFICEXP`, `OFFICE2K3`, `OFFICE2K7`, or `PLUSDME`
|
||||
* If activating Office 2003/2007, use `umskt -i <Installation ID> -m <Product> -p <Product ID>`
|
||||
|
||||
#### 4. Profit!
|
||||
|
||||
|
||||
------
|
||||
|
||||
|
||||
### Authors
|
||||
The list of people who have helped to bring the XP generation to where it is now:
|
||||
* z22
|
||||
* MSKey
|
||||
* diamondggg
|
||||
* pottzman
|
||||
* david4599
|
||||
* Endermanch
|
||||
* Neo-Desktop
|
||||
* WitherOrNot
|
||||
* TheTank20
|
||||
* InvoxiPlayGames
|
||||
* brakmic
|
||||
* techguy16
|
||||
|
||||
(the list will be updated to add more collaborators)
|
||||
|
||||
------
|
||||
|
||||
### **Development Requirements:**
|
||||
|
||||
* `build-essential`
|
||||
* `cmake`
|
||||
* `make`
|
||||
* `gcc`
|
||||
* `g++`
|
||||
* `git`
|
||||
|
||||
#### Build Steps:
|
||||
|
||||
1. `git clone https://github.com/UMSKT/UMSKT`
|
||||
2. `cd UMSKT/build`
|
||||
3. `cmake ..`
|
||||
4. `make`
|
||||
|
||||
|
||||
-----
|
||||
|
||||
### **Known Ports**
|
||||
|
||||
| Language | Author | Repo URL |
|
||||
|----------|-----------|-----------------------------------------------------------|
|
||||
| Rust | Alex Page | [anpage/umskt-rs](https://github.com/anpage/umskt-rs) |
|
||||
| Python | techguy16 | [techguy16/umsktpy](https://github.com/techguy16/umsktpy) |
|
||||
|
99
doc/Vista+.md
Normal file
99
doc/Vista+.md
Normal file
@ -0,0 +1,99 @@
|
||||
## 6. Product ID
|
||||
|
||||
Product ID is 5 groups of decimals, e.g.:
|
||||
|
||||
```
|
||||
AAAAA BBB CCCCCCC DD EEE
|
||||
52273 005 6861993 09 146
|
||||
```
|
||||
|
||||
If you search `ProductID` in registry, you will find a product ID associated with your currently installed one.
|
||||
|
||||
The meaning of each group of numbers:
|
||||
|
||||
| Number | Meaning |
|
||||
| --------- | ----------------------------------------------------------------------------------------------- |
|
||||
| `AAAAA` | Product code. e.g.: `55661` for Windows Pro; `55660` for Windows Home. |
|
||||
| `BBB` | First 3 effective number digits of Primary Product Serial. |
|
||||
| `CCCCCCC` | Last 6 effective number digits of Primary Product Serial, and a digit of checksum. |
|
||||
| `DD` | Public key index number for product validation. e.g.: Pro is 22, VLK is 23. |
|
||||
| `EEE` | Nonce (random number), for generating different install ID when doing activation via telephone. |
|
||||
|
||||
For `CCCCCCC` mentioned above, it had two parts including 1 digit and 6 digits. The checksum is calculated as follows: **Add all digits together (including the checksum digit), it is divisible by 7.**
|
||||
For example: the last 6 digits of Primary Product Serial is `728439`, then `7 + 2 + 8 + 4 + 3 + 9 = 33` , then the checksum digit should be `2`, because `7 + 2 + 8 + 4 + 3 + 9 + 2 = 33 + 2 = 35`, and 35 is divisible by 7. So the `CCCCCCC` in Product ID should be `7284392`.
|
||||
|
||||
## 7. OEM related mechanism
|
||||
<!-- Oh boy this section is a total mess... The original content itself is confusing as hell.. -->
|
||||
|
||||
For licensed product to OEMs, starting from Windows XP, Microsoft is using SLP (System-Locked Preinstallation) technology, aka.: before installing the OS, lock in the motherboard with the OS. Windows XP used SLP 1.0, it works by detecting specific string set by OEM in BIOS. This method is easy to be spoofed, but the VLK crack is more easy to use so this method is not wide-spread.
|
||||
From the Windows Vista, SLP upgraded to 2.0 . Primarily the change is using cryptographic key pairs to sign the data to prevent spoofing. This requires a special SLIC (Software Licensing Internal Code) table in BIOS to support this.
|
||||
In Windows 7 series of product, SLP 2.1 is used, but there is no major changes in SLP for this revision, only updated the marker in SLIC to 2.1 .
|
||||
|
||||
SLIC is the important part of SLP, usually directly backed in BIOS ROM, as the most underlying information of OS activation. SLIC contains the digital signature of OEM, when OS is activating, the upper level certificate must can be verified with the OEM information inside SLIC. SLIC usually contained inside SLDT(Software Licensing Description Table), which 374 bytes long, and SLDT itself is contained inside ACPI(Advanced Configuration and Power Management Interface).
|
||||
|
||||
OEM certificate is a certification file provided by Microsoft, including to some mandatory information provided by OEM, the extension for the file is `xrm-ms`. The OEM certificate including the OEM identification information and digitally signed by Microsoft. When OS is activating, the OEM certificate must can be validated against SLIC.
|
||||
|
||||
OEM product key seems no difference with retail product key, but OEM key is only valid for OEM activation, and it identifies the Windows product variation. Windows Vista cancelled the VLK model, only OEM activation is provided, and used SLP 2.0, used public key instead plain text for validation, caused difficulties for cracking.
|
||||
|
||||
### Windows Vista (SLP 2.0)
|
||||
<!-- Following procedure is for SLP 2.0, which is for Windows Vista. -->
|
||||
The procedure for SLP 2.0 verification is as follows:
|
||||
|
||||
1. When installing Windows Vista, retail version user need to input the serial (CD-KEY) presented on the box. For users who got the OEM version of Windows Vista with the computer, they can find a sticker that corresponding the version they got with the computer, as a voucher for purchasing the Windows Vista OEM version. The system identifies different versions of Windows Vista based on their serial numbers, such as Home Basic, Home Advanced, Business, Ultimate, and so on. After installation, the serial number is converted into 4 sets of letters or numbers, which is the "Product ID" shown in the "System Properties". The second group is the "OEM" one, which is the serial number (CD-KEY) of the OEM version. From now on, the product ID replaces the CD-KEY <!-- as user inputted their retail CD-KEY on the box, this OEM product ID became the CD-KEY in this case -->, and the installer generates an OEM certificate for the OEM version of the installation <!-- "product certificate" maybe? And, installed to where? usually the installation is done by OEM. The information is conflicting with the "OEM certificate is a certification file provided by Microsoft" mentioned above. -->.
|
||||
|
||||
2. The information in the BIOS got loaded into RAM every time system boots.
|
||||
|
||||
3. After logging into the Windows Vista, OS calls SLP service to check the licensed rights of running product, especially the activation status. It starts to identify the licensing status of the system based on the product ID. If no product ID is detected or no valid retail version product ID is detected, it is considered as inactivated. If a valid retail version product ID is detected, it is considered successfully activated. If an OEM version of the product ID is detected, continue with the OEM verification.
|
||||
|
||||
4. If the OEM product ID is detected, the OEM verification process starts, and it will check the installed OEM certificate <!-- "product certificate" ? --> is valid. It mainly uses the SLIC public key from BIOS which is loaded into the RAM, to verify the digital signature of product certificate <!-- Yes, this "product certificate" came from nowhere, so I guess this the OEM certificate that installed while installing the Windows Vista by OEM. -->. If validation failed, it is considered as inactivated.
|
||||
|
||||
5. Validate the OEM ID field between SLIC and RSDT (Root System Description Table), and compare the OEM ID field and OEM Table ID fields between SLIC and XSDT (Extended System Description Table). If they didn't match, it is considered as inactivated.
|
||||
|
||||
6. After the above hurdles, the OEM license will be considered as activated. If not then fallback to inactivated and continue with normal procedure, like require user to activate the Windows.
|
||||
|
||||
### Windows 7 (SLP 2.1)
|
||||
<!-- Following procedure is for SLP 2.1, which is for Windows 7. -->
|
||||
Windows 7 still retains the OEM activation policy, but using SLP 2.1 instead.
|
||||
|
||||
Here is more detailed verification process:
|
||||
|
||||
1. After the activation process starts, if the correct SLP Key is detected, the OEM activation process starts, otherwise the WPA activation (online or telephone activation) is performed.
|
||||
|
||||
2. Detect the OEM certificate <!-- "product certificate" ? -->, and use the digital signature inside the OEM certificate to validate the it (Microsoft used their private key to sign the OEM certificate, and verified against the public key), if verified then continue on OEM activation process, otherwise continue on WPA activation process.
|
||||
|
||||
3. Compare the OEM public key, OEM ID and various fields with the information presented in the OEM certificate <!-- "product certificate" ? -->. If they match (this means OEM public key and etc. are correct), then continue on OEM activation process, otherwise continue on WPA activation process.
|
||||
|
||||
4. Use OEM public key verify against the digital signature of the Marker inside SLIC. if verified (this means the Message in the Marker is correct. <!-- There is no where talked about what is that Message and Marker. -->) then continue on OEM activation process, otherwise continue on WPA activation process.
|
||||
|
||||
5. Validate the Windows Logo <!-- I guess? "Windows Logo" part can be directly translate to "Windows Flag Mark", and this "Flag" means that actual waving thing, not a digital bit. I guess this approach is similar as the Nintendo logo bitmap inside Game Boy game cartridge ROM thing. --> inside the Marker. If the Windows Logo is present, then continue on OEM activation process, otherwise continue on WPA activation process.
|
||||
|
||||
6. Validate the version of Marker. If it's at least `0x20001` then continue on OEM activation process, otherwise OEM activation failed, and continue on WPA activation process.
|
||||
|
||||
7. Compare the OEM ID and OEM Table ID against all corresponding ACPI table headers. If they match, then OEM activation completed successfully, otherwise continue on WPA activation process.
|
||||
|
||||
Key points (Not containing all details, this info is only there to emphasize the key points of Microsoft encryption):
|
||||
|
||||
1. OEM certificate <!-- "product certificate" ? --> contains
|
||||
- Data (OEM ID and other information, Microsoft public key, etc.)
|
||||
- Hash (Hash of data)
|
||||
- Signature (Hash were signed with Microsoft private key)
|
||||
|
||||
2. SLIC contains:
|
||||
- Data (OEM ID, Marker version, etc., Microsoft public key, etc.)
|
||||
- Hash (Hash the data)
|
||||
- Signature (Hash were signed with Microsoft private key)
|
||||
|
||||
3. First, use the public key to verify whether the signatures of OEM and SLIC, then, compare the OEM ID, public key and other information in OEM and SLIC to see whether they are the same; verify the Marker version is matching the type of system currently installed.
|
||||
|
||||
* * *
|
||||
Oh boy what a mess...
|
||||
|
||||
This source is from CSDN.net, and this is a known "copy paste and profit" site that infamous in China.
|
||||
|
||||
This article is old enough that the author is actually had integrity and cited all the actual juicy sources. However, all the actual juicy sources were long gone, because the BBS that the author cited is down,only unusable archives were left (reported by discord member @itsmefeng ).
|
||||
|
||||
This article isn't providing enough information on how to crack the Windows Vista/7 activation process. We may need more actual good sources for this.
|
||||
|
||||
For better understanding I provided some comment (as HTML comments for Markdown compatibility). Hopefully it will be useful.
|
||||
|
||||
-- Some Anonymous Person
|
607
doc/fully-licensed-wpa.txt
Normal file
607
doc/fully-licensed-wpa.txt
Normal file
@ -0,0 +1,607 @@
|
||||
|
||||
Inside Windows Product Activation
|
||||
|
||||
A Fully Licensed Paper
|
||||
|
||||
July 2001
|
||||
|
||||
Fully Licensed GmbH, Rudower Chaussee 29, 12489 Berlin, Germany
|
||||
|
||||
http://www.licenturion.com
|
||||
|
||||
|
||||
>> INTRODUCTION
|
||||
|
||||
The current public discussion of Windows Product Activation (WPA) is
|
||||
characterized by uncertainty and speculation. In this paper we supply
|
||||
the technical details of WPA - as implemented in Windows XP - that
|
||||
Microsoft should have published long ago.
|
||||
|
||||
While we strongly believe that every software vendor has the right to
|
||||
enforce the licensing terms governing the use of a piece of licensed
|
||||
software by technical means, we also do believe that each individual
|
||||
has the right to detailed knowledge about the full implications of the
|
||||
employed means and possible limitations imposed by it on software
|
||||
usage.
|
||||
|
||||
In this paper we answer what we think are currently the two most
|
||||
important open questions related to Windows Product Activation.
|
||||
|
||||
* Exactly what information is transmitted during activation?
|
||||
|
||||
* How do hardware modifications affect an already activated
|
||||
installation of Windows XP?
|
||||
|
||||
Our answers to these questions are based on Windows XP Release
|
||||
Candidate 1 (build 2505). Later builds as well as the final version of
|
||||
Windows XP might differ from build 2505, e.g. in the employed
|
||||
cryptographic keys or the layout of some of the data
|
||||
structures.
|
||||
|
||||
However, beyond such minor modifications we expect Microsoft to cling
|
||||
to the general architecture of their activation mechanism. Thus, we
|
||||
are convinced that the answers provided by this paper will still be
|
||||
useful when the final version of Windows XP ships.
|
||||
|
||||
This paper supplies in-depth technical information about the inner
|
||||
workings of WPA. Still, the discussion is a little vague at some
|
||||
points in order not to facilitate the task of an attacker attempting
|
||||
to circumvent the license enforcement supplied by the activation
|
||||
mechanism.
|
||||
|
||||
XPDec, a command line utility suitable for verifying the presented
|
||||
information, can be obtained from http://www.licenturion.com/xp/. It
|
||||
implements the algorithms presented in this paper. Reading its source
|
||||
code, which is available from the same location, is highly
|
||||
recommended.
|
||||
|
||||
We have removed an important cryptographic key from the XPDec source
|
||||
code. Recompiling the source code will thus fail to produce a working
|
||||
executable. The XPDec executable on our website, however, contains
|
||||
this key and is fully functional.
|
||||
|
||||
So, download the source code to learn about the inner workings of WPA,
|
||||
but obtain the executable to experiment with your installation of
|
||||
Windows XP.
|
||||
|
||||
We expect the reader to be familiar with the general procedure of
|
||||
Windows Product Activation.
|
||||
|
||||
>> INSIDE THE INSTALLATION ID
|
||||
|
||||
We focused our research on product activation via telephone. We did
|
||||
so, because we expected this variant of activation to be the most
|
||||
straight-forward to analyze.
|
||||
|
||||
The first step in activating Windows XP via telephone is supplying the
|
||||
call-center agent with the Installation ID displayed by msoobe.exe,
|
||||
the application that guides a user through the activation process. The
|
||||
Installation ID is a number consisting of 50 decimal digits that are
|
||||
divided into groups of six digits each, as in
|
||||
|
||||
002666-077894-484890-114573-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XX
|
||||
|
||||
In this authentic Installation ID we have substituted digits that we
|
||||
prefer not to disclose by 'X' characters.
|
||||
|
||||
If msoobe.exe is invoked more than once, it provides a different
|
||||
Installation ID each time.
|
||||
|
||||
In return, the call-center agent provides a Confirmation ID matching
|
||||
the given Installation ID. Entering the Confirmation ID completes the
|
||||
activation process.
|
||||
|
||||
Since the Installation ID is the only piece of information revealed
|
||||
during activation, the above question concerning the information
|
||||
transmitted during the activation process is equivalent to the
|
||||
question
|
||||
|
||||
'How is the Installation ID generated?'
|
||||
|
||||
To find an answer to this question, we trace back each digit of the
|
||||
Installation ID to its origins.
|
||||
|
||||
>>> Check digits
|
||||
|
||||
The rightmost digit in each of the groups is a check digit to guard
|
||||
against simple errors such as the call center agent's mistyping of one
|
||||
of the digits read to him or her. The value of the check digit is
|
||||
calculated by adding the other five digits in the group, adding the
|
||||
digits at even positions a second time, and dividing the sum by
|
||||
seven. The remainder of the division is the value of the check
|
||||
digit. In the above example the check digit for the first group (6) is
|
||||
calculated as follows.
|
||||
|
||||
1 | 2 | 3 | 4 | 5 <- position
|
||||
---+---+---+---+---
|
||||
0 | 0 | 2 | 6 | 6 <- digits
|
||||
|
||||
0 + 0 + 2 + 6 + 6 = 14 (step 1: add all digits)
|
||||
0 + 6 + 14 = 20 (step 2: add even digits again)
|
||||
|
||||
step 3: division
|
||||
20 / 7 = 2, remainder is 20 - (2 * 7) = 6
|
||||
|
||||
=> check digit is 6
|
||||
|
||||
Adding the even digits twice is probably intended to guard against the
|
||||
relatively frequent error of accidentally swapping two digits while
|
||||
typing, as in 00626 vs. 00266, which yield different check digits.
|
||||
|
||||
>>> Decoding
|
||||
|
||||
Removing the check digits results in a 41-digit decimal number. A
|
||||
decimal number of this length roughly corresponds to a 136-bit binary
|
||||
number. In fact, the 41-digit number is just the decimal encoding of
|
||||
such a 136-bit multi-precision integer, which is stored in little
|
||||
endian byte order as a byte array. Hence, the above Installation ID
|
||||
can also be represented as a sequence of 17 bytes as in
|
||||
|
||||
0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX
|
||||
0x94 0xAA 0x46 0xD6 0x0F 0xBD 0x2C 0xC8
|
||||
0x00
|
||||
|
||||
In this representation of the above Installation ID 'X' characters
|
||||
again substitute the digits that we prefer not to disclose. The '0x'
|
||||
prefix denotes hex notation throughout this paper.
|
||||
|
||||
>>> Decryption
|
||||
|
||||
When decoding arbitrary Installation IDs it can be noticed that the
|
||||
most significant byte always seems to be 0x00 or 0x01, whereas the
|
||||
other bytes look random. The reason for this is that the lower 16
|
||||
bytes of the Installation ID are encrypted, whereas the most
|
||||
significant byte is kept in plaintext.
|
||||
|
||||
The cryptographic algorithm employed to encrypt the Installation ID is
|
||||
a proprietary four-round Feistel cipher. Since the block of input
|
||||
bytes passed to a Feistel cipher is divided into two blocks of equal
|
||||
size, this class of ciphers is typically applied to input blocks
|
||||
consisting of an even number of bytes - in this case the lower 16 of
|
||||
the 17 input bytes. The round function of the cipher is the SHA-1
|
||||
message digest algorithm keyed with a four-byte sequence.
|
||||
|
||||
Let + denote the concatenation of two byte sequences, ^ the XOR
|
||||
operation, L and R the left and right eight-byte input half for one
|
||||
round, L' and R' the output halves of said round, and First-8() a
|
||||
function that returns the first eight bytes of an SHA-1 message
|
||||
digest. Then one round of decryption looks as follows.
|
||||
|
||||
L' = R ^ First-8(SHA-1(L + Key))
|
||||
R' = L
|
||||
|
||||
The result of the decryption is 16 bytes of plaintext, which are -
|
||||
together with the 17th unencrypted byte - from now on interpreted as
|
||||
four double words in little endian byte order followed by a single
|
||||
byte as in
|
||||
|
||||
name | size | offset
|
||||
-----+-------------+-------
|
||||
H1 | double word | 0
|
||||
H2 | double word | 4
|
||||
P1 | double word | 8
|
||||
P2 | double word | 12
|
||||
P3 | byte | 16
|
||||
|
||||
H1 and H2 specify the hardware configuration that the Installation ID
|
||||
is linked to. P1 and P2 as well as the remaining byte P3 contain the
|
||||
Product ID associated with the Installation ID.
|
||||
|
||||
>>> Product ID
|
||||
|
||||
The Product ID consists of five groups of decimal digits, as in
|
||||
|
||||
AAAAA-BBB-CCCCCCC-DDEEE
|
||||
|
||||
If you search your registry for a value named 'ProductID', you will
|
||||
discover the ID that applies to your installation. The 'About' window
|
||||
of Internet Explorer should also yield your Product ID.
|
||||
|
||||
>>>> Decoding
|
||||
|
||||
The mapping between the Product ID in decimal representation and its
|
||||
binary encoding in the double words P1 and P2 and the byte P3 is
|
||||
summarized in the following table.
|
||||
|
||||
digits | length | encoding
|
||||
--------+---------+---------------------------------------
|
||||
AAAAA | 17 bits | bit 0 to bit 16 of P1
|
||||
BBB | 10 bits | bit 17 to bit 26 of P1
|
||||
CCCCCCC | 28 bits | bit 27 to bit 31 of P1 (lower 5 bits)
|
||||
| | bit 0 to bit 22 of P2 (upper 23 bits)
|
||||
DDEEE | 17 bits | bit 23 to bit 31 of P2 (lower 9 bits)
|
||||
| | bit 0 to bit 7 of P3 (upper 8 bits)
|
||||
|
||||
The meaning of each of the five groups of digits is documented in the
|
||||
next table.
|
||||
|
||||
digits | meaning
|
||||
--------+-------------------------------------------------
|
||||
AAAAA | apparently always 55034 (in Windows XP RC1)
|
||||
BBB | most significant three digits of Raw Product Key
|
||||
| (see below)
|
||||
CCCCCCC | least significant six digits of Raw Product Key
|
||||
| plus check digit (see below)
|
||||
DD | index of the public key used to verify the
|
||||
| Product Key (see below)
|
||||
EEE | random value
|
||||
|
||||
As can be seen, the (Raw) Product Key plays an important role in
|
||||
generating the Product ID.
|
||||
|
||||
>>>> Product Key
|
||||
|
||||
The Raw Product Key is buried inside the Product Key that is printed
|
||||
on the sticker distributed with each Windows XP CD. It consists of
|
||||
five alphanumeric strings separated by '-' characters, where each
|
||||
string is composed of five characters, as in
|
||||
|
||||
FFFFF-GGGGG-HHHHH-JJJJJ-KKKKK
|
||||
|
||||
Each character is one of the following 24 letters and digits:
|
||||
|
||||
B C D F G H J K M P Q R T V W X Y 2 3 4 6 7 8 9
|
||||
|
||||
Very similar to the decimal encoding of the Installation ID the 25
|
||||
characters of the Product Key form a base-24 encoding of the binary
|
||||
representation of the Product Key. Decoding the Product Key yields a
|
||||
multi-precision integer of roughly 115 bits, which is stored - again
|
||||
in little endian byte order - in an array of 15 bytes. Decoding the
|
||||
above Product Key results in the following byte sequence.
|
||||
|
||||
0x6F 0xFA 0x95 0x45 0xFC 0x75 0xB5 0x52
|
||||
0xBB 0xEF 0xB1 0x17 0xDA 0xCD 0x00
|
||||
|
||||
Of these 15 bytes the least significant four bytes contain the Raw
|
||||
Product Key in little endian byte order. The least significant bit is
|
||||
removed by shifting this 32-bit value (0x4595FA6F - remember the
|
||||
little endian byte order) to the left by one bit position, resulting
|
||||
in a Raw Product Key of 0x22CAFD37, or
|
||||
|
||||
583728439
|
||||
|
||||
in decimal notation.
|
||||
|
||||
The eleven remaining bytes form a digital signature, allowing
|
||||
verification of the authenticity of the Product Key by means of a
|
||||
hard-coded public key.
|
||||
|
||||
>>>> Product Key -> Product ID
|
||||
|
||||
The three most significant digits, i.e. 583, of the Raw Product Key's
|
||||
nine-digit decimal representation directly map to the BBB component of
|
||||
the Product ID described above.
|
||||
|
||||
To obtain the CCCCCCC component, a check digit is appended to the
|
||||
remaining six digits 728439. The check digit is chosen such that the
|
||||
sum of all digits - including the check digit - is divisible by
|
||||
seven. In the given case, the sum of the six digits is
|
||||
|
||||
7 + 2 + 8 + 4 + 3 + 9 = 33
|
||||
|
||||
which results in a check digit of 2, since
|
||||
|
||||
7 + 2 + 8 + 4 + 3 + 9 + 2 = 33 + 2 = 35
|
||||
|
||||
which is divisible by seven. The CCCCCCC component of the Product ID
|
||||
is therefore 7284392.
|
||||
|
||||
For verifying a Product Key, more than one public key is available. If
|
||||
verification with the first public key fails, the second is tried,
|
||||
etc. The DD component of the Product ID specifies which of the public
|
||||
keys in this sequence was successfully used to verify the Product Key.
|
||||
|
||||
This mechanism might be intended to support several different parties
|
||||
generating valid Product Keys with different individual private keys.
|
||||
|
||||
However, the different private keys might also represent different
|
||||
versions of a product. A Product Key for the 'professional' release
|
||||
could then be signed with a different key than a Product Key for the
|
||||
'server' release. The DD component would then represent the product
|
||||
version.
|
||||
|
||||
Finally, a valid Product ID derived from our example Product Key might
|
||||
be
|
||||
|
||||
55034-583-7284392-00123
|
||||
|
||||
which indicates that the first public key (DD = index = 0) matched and
|
||||
123 was chosen as the random number EEE.
|
||||
|
||||
The randomly selected EEE component is the reason for msoobe.exe
|
||||
presenting a different Installation ID at each invocation. Because of
|
||||
the applied encryption this small change results in a completely
|
||||
different Installation ID.
|
||||
|
||||
So, the Product ID transmitted during activation will most probably
|
||||
differ in the last three digits from your Product ID as displayed by
|
||||
Internet Explorer or as stored in the registry.
|
||||
|
||||
>>> Hardware Information
|
||||
|
||||
As discussed above, the hardware configuration linked to the
|
||||
Installation ID is represented by the two double words H1 and H2.
|
||||
|
||||
>>>> Bit-fields
|
||||
|
||||
For this purpose, the double words are divided into twelve
|
||||
bit-fields. The relationship between the computer hardware and the
|
||||
bit-fields is given in the following table.
|
||||
|
||||
double word | offset | length | bit-field value based on
|
||||
------------+--------+--------+----------------------------
|
||||
H1 | 0 | 10 | volume serial number string
|
||||
| | | of system volume
|
||||
H1 | 10 | 10 | network adapter MAC address
|
||||
| | | string
|
||||
H1 | 20 | 7 | CD-ROM drive hardware
|
||||
| | | identification string
|
||||
H1 | 27 | 5 | graphics adapter hardware
|
||||
| | | identification string
|
||||
H2 | 0 | 3 | unused, set to 001
|
||||
H2 | 3 | 6 | CPU serial number string
|
||||
H2 | 9 | 7 | harddrive hardware
|
||||
| | | identification string
|
||||
H2 | 16 | 5 | SCSI host adapter hardware
|
||||
| | | identification string
|
||||
H2 | 21 | 4 | IDE controller hardware
|
||||
| | | identification string
|
||||
H2 | 25 | 3 | processor model string
|
||||
H2 | 28 | 3 | RAM size
|
||||
H2 | 31 | 1 | 1 = dockable
|
||||
| | | 0 = not dockable
|
||||
|
||||
Bit 31 of H2 specifies, whether the bit-fields represent a notebook
|
||||
computer that supports a docking station. If docking is possible, the
|
||||
activation mechanism will be more tolerant with respect to future
|
||||
hardware modifications. Here, the idea is that plugging a notebook
|
||||
into its docking station possibly results in changes to its hardware
|
||||
configuration, e.g. a SCSI host adapter built into the docking station
|
||||
may become available.
|
||||
|
||||
Bits 2 through 0 of H2 are unused and always set to 001.
|
||||
|
||||
If the hardware component corresponding to one of the remaining ten
|
||||
bit-fields is present, the respective bit-field contains a non-zero
|
||||
value describing the component. A value of zero marks the hardware
|
||||
component as not present.
|
||||
|
||||
All hardware components are identified by a hardware identification
|
||||
string obtained from the registry. Hashing this string provides the
|
||||
value for the corresponding bit-field.
|
||||
|
||||
>>>> Hashing
|
||||
|
||||
The hash result is obtained by feeding the hardware identification
|
||||
string into the MD5 message digest algorithm and picking the number of
|
||||
bits required for a bit-field from predetermined locations in the
|
||||
resulting message digest. Different predetermined locations are used
|
||||
for different bit-fields. In addition, a hash result of zero is
|
||||
avoided by calculating
|
||||
|
||||
Hash = (Hash % BitFieldMax) + 1
|
||||
|
||||
where BitFieldMax is the maximal value that may be stored in the
|
||||
bit-field in question, e.g. 1023 for a 10-bit bit-field, and 'x % y'
|
||||
denotes the remainder of the division of x by y. This results in
|
||||
values between 1 and BitFieldMax. The obtained value is then stored in
|
||||
the respective bit-field.
|
||||
|
||||
>>>> RAM bit-field
|
||||
|
||||
The bit-field related to the amount of RAM available to the operating
|
||||
system is calculated differently. The seven valid values specify the
|
||||
approximate amount of available RAM as documented in the following
|
||||
table.
|
||||
|
||||
value | amount of RAM available
|
||||
------+---------------------------
|
||||
0 | (bit-field unused)
|
||||
1 | below 32 MB
|
||||
2 | between 32 MB and 63 MB
|
||||
3 | between 64 MB and 127 MB
|
||||
4 | between 128 MB and 255 MB
|
||||
5 | between 256 MB and 511 MB
|
||||
6 | between 512 MB and 1023 MB
|
||||
7 | above 1023 MB
|
||||
|
||||
It is important to note that the amount of RAM is retrieved by calling
|
||||
the GlobalMemoryStatus() function, which reports a few hundred
|
||||
kilobytes less than the amount of RAM physically installed. So, 128 MB
|
||||
of RAM would typically be classified as "between 64 MB and 127 MB".
|
||||
|
||||
>>>> Real-world example
|
||||
|
||||
Let us have a look at a real-world example. On one of our test systems
|
||||
the hardware information consists of the following eight bytes.
|
||||
|
||||
0xC5 0x95 0x12 0xAC 0x01 0x6E 0x2C 0x32
|
||||
|
||||
Converting the bytes into H1 and H2, we obtain
|
||||
|
||||
H1 = 0xAC1295C5 and H2 = 0x322C6E01
|
||||
|
||||
Splitting H1 and H2 yields the next table in which we give the value
|
||||
of each of the bit-fields and the information from which each value is
|
||||
derived.
|
||||
|
||||
dw & | |
|
||||
offset | value | derived from
|
||||
-------+-------+-----------------------------------------------
|
||||
H1 0 | 0x1C5 | '1234-ABCD'
|
||||
H1 10 | 0x0A5 | '00C0DF089E44'
|
||||
H1 20 | 0x37 | 'SCSI\CDROMPLEXTOR_CD-ROM_PX-32TS__1.01'
|
||||
H1 27 | 0x15 | 'PCI\VEN_102B&DEV_0519&SUBSYS_00000000&REV_01'
|
||||
H2 0 | 0x1 | (unused, always 0x1)
|
||||
H2 3 | 0x00 | (CPU serial number not present)
|
||||
H2 9 | 0x37 | 'SCSI\DISKIBM_____DCAS-34330______S65A'
|
||||
H2 16 | 0x0C | 'PCI\VEN_9004&DEV_7178&SUBSYS_00000000&REV_03'
|
||||
H2 21 | 0x1 | 'PCI\VEN_8086&DEV_7111&SUBSYS_00000000&REV_01'
|
||||
H2 25 | 0x1 | 'GenuineIntel Family 6 Model 3'
|
||||
H2 28 | 0x3 | (system has 128 MB of RAM)
|
||||
H2 31 | 0x0 | (system is not dockable)
|
||||
|
||||
>>> Using XPDec
|
||||
|
||||
XPDec is a utility to be run from the command prompt. It may be
|
||||
invoked with one of four command line options to carry out one of four
|
||||
tasks.
|
||||
|
||||
>>>> XPDec -i
|
||||
|
||||
This option enables you to access the information hidden in an
|
||||
Installation ID. It decodes the Installation ID, decrypts it, and
|
||||
displays the values of the hardware bit-fields as well as the Product
|
||||
ID of your product. Keep in mind that the last three digits of the
|
||||
Product ID contained in the Installation ID are randomly selected and
|
||||
differ from the Product ID displayed by Internet Explorer.
|
||||
|
||||
The only argument needed for the '-i' option is the Installation ID,
|
||||
as in
|
||||
|
||||
XPDec -i 002666-077894-484890-114573-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XX
|
||||
|
||||
>>>> XPDec -p
|
||||
|
||||
To help you trace the origin of your Product ID, this option decodes a
|
||||
Product Key and displays the Raw Product Key as it would be used in a
|
||||
Product ID.
|
||||
|
||||
The only argument needed for the '-p' option is the Product Key, as in
|
||||
|
||||
XPDec -p FFFFF-GGGGG-HHHHH-JJJJJ-KKKKK
|
||||
|
||||
Note that this option does not verify the digital signature of the
|
||||
Product Key.
|
||||
|
||||
>>>> XPDec -v
|
||||
|
||||
This option calculates the hash of a given volume serial number. It
|
||||
was implemented to illustrate our description of string hashing. First
|
||||
use '-i' to display the hardware bit-fields. Then use this option to
|
||||
verify our claims concerning the volume serial number hash.
|
||||
|
||||
The only argument needed for the '-v' option is the volume serial
|
||||
number of your system volume, as in
|
||||
|
||||
XPDec -v 1234-ABCD
|
||||
|
||||
(The volume serial number is part of the 'dir' command's output.)
|
||||
|
||||
>>>> XPDec -m
|
||||
|
||||
This option calculates the network adapter bit-field value
|
||||
corresponding to the given MAC address. Similar to '-v' this option
|
||||
was implemented as a proof of concept.
|
||||
|
||||
The only argument needed for the '-m' option is the MAC address of
|
||||
your network adapter, as in
|
||||
|
||||
XPDec -m 00-C0-DF-08-9E-44
|
||||
|
||||
(Use the 'route print' command to obtain the MAC address of your
|
||||
network adapter.)
|
||||
|
||||
>> HARDWARE MODIFICATIONS
|
||||
|
||||
When looking at the effects of hardware modifications on an already
|
||||
activated installation of Windows XP, the file 'wpa.dbl' in the
|
||||
'system32' directory plays a central role. It is a simple
|
||||
RC4-encrypted database that stores, among other things like expiration
|
||||
information and the Confirmation ID of an activated installation,
|
||||
|
||||
a) the bit-field values representing the current hardware
|
||||
configuration,
|
||||
|
||||
and
|
||||
|
||||
b) the bit-field values representing the hardware configuration
|
||||
at the time of product activation.
|
||||
|
||||
While a) is automatically updated each time the hardware configuration
|
||||
is modified in order to reflect the changes, b) remains fixed. Hence,
|
||||
b) can be thought of as a snapshot of the hardware configuration at
|
||||
the time of product activation.
|
||||
|
||||
This snapshot does not exist in the database before product activation
|
||||
and if we compare the size of 'wpa.dbl' before and after activation,
|
||||
we will notice an increased file size. This is because the snapshot is
|
||||
added to the database.
|
||||
|
||||
When judging whether re-activation is necessary, the bit-field values
|
||||
of a) are compared to the bit-field values of b), i.e. the current
|
||||
hardware configuration is compared to the hardware configuration at
|
||||
the time of activation.
|
||||
|
||||
>>> Non-dockable computer
|
||||
|
||||
Typically all bit-fields with the exception of the unused field and
|
||||
the 'dockable' field are compared. If more than three of these ten
|
||||
bit-fields have changed in a) since product activation, re-activation
|
||||
is required.
|
||||
|
||||
This means, for example, that in our above real-world example, we
|
||||
could replace the harddrive and the CD-ROM drive and substantially
|
||||
upgrade our RAM without having to re-activate our Windows XP
|
||||
installation.
|
||||
|
||||
However, if we completely re-installed Windows XP, the information in
|
||||
b) would be lost and we would have to re-activate our installation,
|
||||
even if we had not changed our hardware.
|
||||
|
||||
>>> Dockable computer
|
||||
|
||||
If bit 31 of H2 indicates that our computer supports a docking
|
||||
station, however, only seven of the ten bit-fields mentioned above are
|
||||
compared. The bit-fields corresponding to the SCSI host adapter, the
|
||||
IDE controller, and the graphics board are omitted. But again, of
|
||||
these remaining seven bit-fields, only up to three may change without
|
||||
requiring re-activation.
|
||||
|
||||
>> CONCLUSIONS
|
||||
|
||||
In this paper we have given a technical overview of Windows Product
|
||||
Activation as implemented in Windows XP. We have shown what
|
||||
information the data transmitted during product activation is derived
|
||||
from and how hardware upgrades affect an already activated
|
||||
installation.
|
||||
|
||||
Looking at the technical details of WPA, we do not think that it is as
|
||||
problematic as many people have expected. We think so, because WPA is
|
||||
tolerant with respect to hardware modifications. In addition, it is
|
||||
likely that more than one hardware component map to a certain value
|
||||
for a given bit-field. From the above real-world example we know that
|
||||
the PX-32TS maps to the value 0x37 = 55. But there are probably many
|
||||
other CD-ROM drives that map to the same value. Hence, it is
|
||||
impossible to tell from the bit-field value whether it is a PX-32TS
|
||||
that we are using or one of the other drives that map to the same
|
||||
value.
|
||||
|
||||
In contrast to many critics of Windows Product Activation, we think
|
||||
that WPA does not prevent typical hardware modifications and,
|
||||
moreover, respects the user's right to privacy.
|
||||
|
||||
>> ABOUT THE AUTHORS
|
||||
|
||||
Fully Licensed GmbH is a start-up company focusing on novel approaches
|
||||
to online software licensing and distribution. Have a look at their
|
||||
website at
|
||||
|
||||
http://www.licenturion.com
|
||||
|
||||
for more information.
|
||||
|
||||
Their research branch every now and then analyzes licensing solutions
|
||||
implemented by other companies.
|
||||
|
||||
>> COPYRIGHT
|
||||
|
||||
Copyright (C) 2001 Fully Licensed GmbH (www.licenturion.com)
|
||||
All rights reserved.
|
||||
|
||||
You are free to do whatever you want with this paper. However, you
|
||||
have to supply the URL of its online version
|
||||
|
||||
http://www.licenturion.com/xp/
|
||||
|
||||
with any work derived from this paper to give credit to its authors.
|
557
main.cpp
557
main.cpp
@ -1,557 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/ec.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define FIELD_BITS 384
|
||||
|
||||
#define FIELD_BYTES 48
|
||||
|
||||
unsigned char cset[] = "BCDFGHJKMPQRTVWXY2346789";
|
||||
|
||||
static void unpack(unsigned long *pid, unsigned long *hash, unsigned long *sig, unsigned long *raw)
|
||||
|
||||
{
|
||||
|
||||
// pid = Bit 0..30
|
||||
|
||||
pid[0] = raw[0] & 0x7fffffff;
|
||||
|
||||
// hash(s) = Bit 31..58
|
||||
|
||||
hash[0] = ((raw[0] >> 31) | (raw[1] << 1)) & 0xfffffff;
|
||||
|
||||
// sig(e) = bit 58..113
|
||||
|
||||
sig[0] = (raw[1] >> 27) | (raw[2] << 5);
|
||||
|
||||
sig[1] = (raw[2] >> 27) | (raw[3] << 5);
|
||||
|
||||
}
|
||||
|
||||
static void pack(unsigned long *raw, unsigned long *pid, unsigned long *hash, unsigned long *sig)
|
||||
|
||||
{
|
||||
|
||||
raw[0] = pid[0] | ((hash[0] & 1) << 31);
|
||||
|
||||
raw[1] = (hash[0] >> 1) | ((sig[0] & 0x1f) << 27);
|
||||
|
||||
raw[2] = (sig[0] >> 5) | (sig[1] << 27);
|
||||
|
||||
raw[3] = sig[1] >> 5;
|
||||
|
||||
}
|
||||
|
||||
// Reverse data
|
||||
|
||||
static void endian(unsigned char *data, int len)
|
||||
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len/2; i++) {
|
||||
|
||||
unsigned char temp;
|
||||
|
||||
temp = data;
|
||||
|
||||
data = data[len-i-1];
|
||||
|
||||
data[len-i-1] = temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void unbase24(unsigned long *x, unsigned char *c)
|
||||
|
||||
{
|
||||
|
||||
memset(x, 0, 16);
|
||||
|
||||
int i, n;
|
||||
|
||||
BIGNUM *y = BN_new();
|
||||
|
||||
BN_zero(y);
|
||||
|
||||
for (i = 0; i < 25; i++)
|
||||
|
||||
{
|
||||
|
||||
BN_mul_word(y, 24);
|
||||
|
||||
BN_add_word(y, c);
|
||||
|
||||
}
|
||||
|
||||
n = BN_num_bytes(y);
|
||||
|
||||
BN_bn2bin(y, (unsigned char *)x);
|
||||
|
||||
BN_free(y);
|
||||
|
||||
endian((unsigned char *)x, n);
|
||||
|
||||
}
|
||||
|
||||
void base24(unsigned char *c, unsigned long *x)
|
||||
|
||||
{
|
||||
|
||||
unsigned char y[16];
|
||||
|
||||
int i;
|
||||
|
||||
BIGNUM *z;
|
||||
|
||||
// Convert x to BigNum z
|
||||
|
||||
memcpy(y, x, sizeof(y)); // Copy X to Y; Y=X
|
||||
|
||||
for (i = 15; y == 0; i--) {} i++; // skip following nulls
|
||||
|
||||
endian(y, i); // Reverse y
|
||||
|
||||
z = BN_bin2bn(y, i, NULL); // Convert y to BigNum z
|
||||
|
||||
// Divide z by 24 and convert remainder with cset to Base24-CDKEY Char
|
||||
|
||||
c[25] = 0;
|
||||
|
||||
for (i = 24; i >= 0; i--) {
|
||||
|
||||
unsigned char t = BN_div_word(z, 24);
|
||||
|
||||
c = cset[t];
|
||||
|
||||
}
|
||||
|
||||
BN_free(z);
|
||||
|
||||
}
|
||||
|
||||
void print_product_id(unsigned long *pid)
|
||||
|
||||
{
|
||||
|
||||
char raw[12];
|
||||
|
||||
char b[6], c[8];
|
||||
|
||||
int i, digit = 0;
|
||||
|
||||
// Cut a away last bit of pid and convert it to an accii-number (=raw)
|
||||
|
||||
sprintf(raw, "%d", pid[0] >> 1);
|
||||
|
||||
// Make b-part {640-....}
|
||||
|
||||
strncpy(b, raw, 3);
|
||||
|
||||
b[3] = 0;
|
||||
|
||||
// Make c-part {...-123456X...}
|
||||
|
||||
strcpy(c, raw + 3);
|
||||
|
||||
// Make checksum digit-part {...56X-}
|
||||
|
||||
assert(strlen© == 6);
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
|
||||
digit -= c - '0'; // Sum digits
|
||||
|
||||
while (digit < 0)
|
||||
|
||||
digit += 7;
|
||||
|
||||
c[6] = digit + '0';
|
||||
|
||||
c[7] = 0;
|
||||
|
||||
printf("Product ID: 55274-%s-%s-23xxx\n", b, c);
|
||||
|
||||
}
|
||||
|
||||
void print_product_key(unsigned char *pk)
|
||||
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
assert(strlen((const char *)pk) == 25);
|
||||
|
||||
for (i = 0; i < 25; i++) {
|
||||
|
||||
putchar(pk);
|
||||
|
||||
if (i != 24 && i % 5 == 4) putchar('-');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void verify(EC_GROUP *ec, EC_POINT *generator, EC_POINT *public_key, char *cdkey)
|
||||
|
||||
{
|
||||
|
||||
unsigned char key[25];
|
||||
|
||||
int i, j, k;
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
|
||||
// remove Dashs from CDKEY
|
||||
|
||||
for (i = 0, k = 0; i < strlen(cdkey); i++) {
|
||||
|
||||
for (j = 0; j < 24; j++) {
|
||||
|
||||
if (cdkey != '-' && cdkey == cset[j]) {
|
||||
|
||||
key[k++] = j;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
assert(j < 24);
|
||||
|
||||
}
|
||||
|
||||
if (k >= 25) break;
|
||||
|
||||
}
|
||||
|
||||
// Base24_CDKEY -> Bin_CDKEY
|
||||
|
||||
unsigned long bkey[4] = {0};
|
||||
|
||||
unsigned long pid[1], hash[1], sig[2];
|
||||
|
||||
unbase24(bkey, key);
|
||||
|
||||
// Output Bin_CDKEY
|
||||
|
||||
printf("%.8x %.8x %.8x %.8x\n", bkey[3], bkey[2], bkey[1], bkey[0]);
|
||||
|
||||
// Divide/Extract pid_data, hash, sig from Bin_CDKEY
|
||||
|
||||
unpack(pid, hash, sig, bkey);
|
||||
|
||||
print_product_id(pid);
|
||||
|
||||
printf("PID: %.8x\nHash: %.8x\nSig: %.8x %.8x\n", pid[0], hash[0], sig[1], sig[0]);
|
||||
|
||||
BIGNUM *e, *s;
|
||||
|
||||
/* e = hash, s = sig */
|
||||
|
||||
e = BN_new();
|
||||
|
||||
BN_set_word(e, hash[0]);
|
||||
|
||||
endian((unsigned char *)sig, sizeof(sig));
|
||||
|
||||
s = BN_bin2bn((unsigned char *)sig, sizeof(sig), NULL);
|
||||
|
||||
BIGNUM *x = BN_new();
|
||||
|
||||
BIGNUM *y = BN_new();
|
||||
|
||||
EC_POINT *u = EC_POINT_new(ec);
|
||||
|
||||
EC_POINT *v = EC_POINT_new(ec);
|
||||
|
||||
/* v = s*generator + e*(-public_key) */
|
||||
|
||||
EC_POINT_mul(ec, u, NULL, generator, s, ctx);
|
||||
|
||||
EC_POINT_mul(ec, v, NULL, public_key, e, ctx);
|
||||
|
||||
EC_POINT_add(ec, v, u, v, ctx);
|
||||
|
||||
EC_POINT_get_affine_coordinates_GFp(ec, v, x, y, ctx);
|
||||
|
||||
unsigned char buf[FIELD_BYTES], md[20];
|
||||
|
||||
unsigned long h;
|
||||
|
||||
unsigned char t[4];
|
||||
|
||||
SHA_CTX h_ctx;
|
||||
|
||||
/* h = (fist 32 bits of SHA1(pid || v.x, v.y)) >> 4 */
|
||||
|
||||
SHA1_Init(&h_ctx);
|
||||
|
||||
t[0] = pid[0] & 0xff;
|
||||
|
||||
t[1] = (pid[0] & 0xff00) >> 8;
|
||||
|
||||
t[2] = (pid[0] & 0xff0000) >> 16;
|
||||
|
||||
t[3] = (pid[0] & 0xff000000) >> 24;
|
||||
|
||||
SHA1_Update(&h_ctx, t, sizeof(t));
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
BN_bn2bin(x, buf);
|
||||
|
||||
endian((unsigned char *)buf, sizeof(buf));
|
||||
|
||||
SHA1_Update(&h_ctx, buf, sizeof(buf));
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
BN_bn2bin(y, buf);
|
||||
|
||||
endian((unsigned char *)buf, sizeof(buf));
|
||||
|
||||
SHA1_Update(&h_ctx, buf, sizeof(buf));
|
||||
|
||||
SHA1_Final(md, &h_ctx);
|
||||
|
||||
h = (md[0] | (md[1] << 8) | (md[2] << 16) | (md[3] << 24)) >> 4;
|
||||
|
||||
h &= 0xfffffff;
|
||||
|
||||
printf("Calculated hash: %.8x\n", h);
|
||||
|
||||
if (h == hash[0]) printf("Key valid\n");
|
||||
|
||||
else printf("Key invalid\n");
|
||||
|
||||
putchar('\n');
|
||||
|
||||
BN_free(e);
|
||||
|
||||
BN_free(s);
|
||||
|
||||
BN_free(x);
|
||||
|
||||
BN_free(y);
|
||||
|
||||
EC_POINT_free(u);
|
||||
|
||||
EC_POINT_free(v);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
}
|
||||
|
||||
void generate(unsigned char *pkey, EC_GROUP *ec, EC_POINT *generator, BIGNUM *order, BIGNUM *priv, unsigned long *pid)
|
||||
|
||||
{
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
|
||||
BIGNUM *k = BN_new();
|
||||
|
||||
BIGNUM *s = BN_new();
|
||||
|
||||
BIGNUM *x = BN_new();
|
||||
|
||||
BIGNUM *y = BN_new();
|
||||
|
||||
EC_POINT *r = EC_POINT_new(ec);
|
||||
|
||||
unsigned long bkey[4];
|
||||
|
||||
// Loop in case signaturepart will make cdkey(base-24 "digits") longer than 25
|
||||
|
||||
do {
|
||||
|
||||
BN_pseudo_rand(k, FIELD_BITS, -1, 0);
|
||||
|
||||
EC_POINT_mul(ec, r, NULL, generator, k, ctx);
|
||||
|
||||
EC_POINT_get_affine_coordinates_GFp(ec, r, x, y, ctx);
|
||||
|
||||
SHA_CTX h_ctx;
|
||||
|
||||
unsigned char t[4], md[20], buf[FIELD_BYTES];
|
||||
|
||||
unsigned long hash[1];
|
||||
|
||||
/* h = (fist 32 bits of SHA1(pid || r.x, r.y)) >> 4 */
|
||||
|
||||
SHA1_Init(&h_ctx);
|
||||
|
||||
t[0] = pid[0] & 0xff;
|
||||
|
||||
t[1] = (pid[0] & 0xff00) >> 8;
|
||||
|
||||
t[2] = (pid[0] & 0xff0000) >> 16;
|
||||
|
||||
t[3] = (pid[0] & 0xff000000) >> 24;
|
||||
|
||||
SHA1_Update(&h_ctx, t, sizeof(t));
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
BN_bn2bin(x, buf);
|
||||
|
||||
endian((unsigned char *)buf, sizeof(buf));
|
||||
|
||||
SHA1_Update(&h_ctx, buf, sizeof(buf));
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
BN_bn2bin(y, buf);
|
||||
|
||||
endian((unsigned char *)buf, sizeof(buf));
|
||||
|
||||
SHA1_Update(&h_ctx, buf, sizeof(buf));
|
||||
|
||||
SHA1_Final(md, &h_ctx);
|
||||
|
||||
hash[0] = (md[0] | (md[1] << 8) | (md[2] << 16) | (md[3] << 24)) >> 4;
|
||||
|
||||
hash[0] &= 0xfffffff;
|
||||
|
||||
/* s = priv*h + k */
|
||||
|
||||
BN_copy(s, priv);
|
||||
|
||||
BN_mul_word(s, hash[0]);
|
||||
|
||||
BN_mod_add(s, s, k, order, ctx);
|
||||
|
||||
unsigned long sig[2] = {0};
|
||||
|
||||
BN_bn2bin(s, (unsigned char *)sig);
|
||||
|
||||
endian((unsigned char *)sig, BN_num_bytes(s));
|
||||
|
||||
pack(bkey, pid, hash, sig);
|
||||
|
||||
printf("PID: %.8x\nHash: %.8x\nSig: %.8x %.8x\n", pid[0], hash[0], sig[1], sig[0]);
|
||||
|
||||
} while (bkey[3] >= 0x62a32);
|
||||
|
||||
base24(pkey, bkey);
|
||||
|
||||
BN_free(k);
|
||||
|
||||
BN_free(s);
|
||||
|
||||
BN_free(x);
|
||||
|
||||
BN_free(y);
|
||||
|
||||
EC_POINT_free®;
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
{
|
||||
|
||||
// Init
|
||||
|
||||
BIGNUM *a, *b, *p, *gx, *gy, *pubx, *puby, *n, *priv;
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
|
||||
// make BigNumbers
|
||||
|
||||
a = BN_new();
|
||||
|
||||
b = BN_new();
|
||||
|
||||
p = BN_new();
|
||||
|
||||
gx = BN_new();
|
||||
|
||||
gy = BN_new();
|
||||
|
||||
pubx = BN_new();
|
||||
|
||||
puby = BN_new();
|
||||
|
||||
n = BN_new();
|
||||
|
||||
priv = BN_new();
|
||||
|
||||
// Data from pidgen-Bink-resources
|
||||
|
||||
/* Elliptic curve parameters: y^2 = x^3 + ax + b mod p */
|
||||
|
||||
BN_hex2bn(&p, "92ddcf14cb9e71f4489a2e9ba350ae29454d98cb93bdbcc07d62b502ea12238ee904a8b20d017197aae0c103b32713a9");
|
||||
|
||||
BN_set_word(a, 1);
|
||||
|
||||
BN_set_word(b, 0);
|
||||
|
||||
/* base point (generator) G */
|
||||
|
||||
BN_hex2bn(&gx, "46E3775ECE21B0898D39BEA57050D422A0AF989E497962BAEE2CB17E0A28D5360D5476B8DC966443E37A14F1AEF37742");
|
||||
|
||||
BN_hex2bn(&gy, "7C8E741D2C34F4478E325469CD491603D807222C9C4AC09DDB2B31B3CE3F7CC191B3580079932BC6BEF70BE27604F65E");
|
||||
|
||||
/* inverse of public key */
|
||||
|
||||
BN_hex2bn(&pubx, "5D8DBE75198015EC41C45AAB6143542EB098F6A5CC9CE4178A1B8A1E7ABBB5BC64DF64FAF6177DC1B0988AB00BA94BF8");
|
||||
|
||||
BN_hex2bn(&puby, "23A2909A0B4803C89F910C7191758B48746CEA4D5FF07667444ACDB9512080DBCA55E6EBF30433672B894F44ACE92BFA");
|
||||
|
||||
// Computed data
|
||||
|
||||
/* order of G - computed in 18 hours using a P3-450 */
|
||||
|
||||
BN_hex2bn(&n, "DB6B4C58EFBAFD");
|
||||
|
||||
/* THE private key - computed in 10 hours using a P3-450 */
|
||||
|
||||
BN_hex2bn(&priv, "565B0DFF8496C8");
|
||||
|
||||
// Calculation
|
||||
|
||||
EC_GROUP *ec = EC_GROUP_new_curve_GFp(p, a, b, ctx);
|
||||
|
||||
EC_POINT *g = EC_POINT_new(ec);
|
||||
|
||||
EC_POINT_set_affine_coordinates_GFp(ec, g, gx, gy, ctx);
|
||||
|
||||
EC_POINT *pub = EC_POINT_new(ec);
|
||||
|
||||
EC_POINT_set_affine_coordinates_GFp(ec, pub, pubx, puby, ctx);
|
||||
|
||||
unsigned char pkey[26];
|
||||
|
||||
unsigned long pid[1];
|
||||
|
||||
pid[0] = 640000000 << 1; /* <- change */
|
||||
|
||||
// generate a key
|
||||
|
||||
generate(pkey, ec, g, n, priv, pid);
|
||||
|
||||
print_product_key(pkey); printf("\n\n");
|
||||
|
||||
// verify the key
|
||||
|
||||
verify(ec, g, pub, (char*)pkey);
|
||||
|
||||
// Cleanup
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
159
src/cli/cli.cpp
Normal file
159
src/cli/cli.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
// define static storage
|
||||
CLI::Options CLI::options;
|
||||
json CLI::keys;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param argcIn
|
||||
* @param argvIn
|
||||
* @return exit status (where success is 0)
|
||||
*/
|
||||
BYTE CLI::Init(int argcIn, char **argvIn)
|
||||
{
|
||||
// set default options
|
||||
options.argc = argcIn;
|
||||
options.argv = argvIn;
|
||||
options.binkID = "2E";
|
||||
options.productCode = "WINXP";
|
||||
options.productFlavour = "VLK";
|
||||
options.numKeys = 1;
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_3;
|
||||
options.state = Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE;
|
||||
|
||||
SetHelpText();
|
||||
|
||||
BOOL success = parseCommandLine();
|
||||
if (!success)
|
||||
{
|
||||
return options.error;
|
||||
}
|
||||
|
||||
// if we displayed help, without an error
|
||||
// return success
|
||||
if (options.help)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
success = processOptions();
|
||||
if (!success)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filename
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::loadJSON(const fs::path &filename)
|
||||
{
|
||||
if (filename.empty())
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading internal keys file\n");
|
||||
}
|
||||
|
||||
auto retval = loadEmbeddedJSON();
|
||||
|
||||
if (retval && options.verbose)
|
||||
{
|
||||
fmt::print("Loaded internal keys file successfully\n\n");
|
||||
}
|
||||
else if (!retval)
|
||||
{
|
||||
fmt::print("Error loading internal keys file...\n\n");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (!fs::exists(filename))
|
||||
{
|
||||
fmt::print("ERROR: File {} does not exist\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loading keys file: {}\n", options.keysFilename);
|
||||
}
|
||||
|
||||
std::ifstream f(filename);
|
||||
try
|
||||
{
|
||||
keys = json::parse(f, nullptr, false, false);
|
||||
}
|
||||
catch (const json::exception &e)
|
||||
{
|
||||
fmt::print("ERROR: Exception thrown while parsing {}: {}\n", filename.string(), e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keys.is_discarded())
|
||||
{
|
||||
fmt::print("ERROR: Unable to parse keys from: {}\n", filename.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Loaded keys from \"{}\" successfully\n", options.keysFilename);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process application state
|
||||
*
|
||||
* @return application status code
|
||||
*/
|
||||
int CLI::Run()
|
||||
{
|
||||
/**
|
||||
* TODO: we should be checking if the system's pseudorandom facilities work
|
||||
* before attempting generation, validation does not require entropy
|
||||
*/
|
||||
switch (options.state)
|
||||
{
|
||||
case Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE:
|
||||
return PIDGenerate();
|
||||
|
||||
case Options::APPLICATION_STATE::STATE_PIDGEN_VALIDATE:
|
||||
return PIDValidate();
|
||||
|
||||
case Options::APPLICATION_STATE::STATE_CONFIRMATION_ID:
|
||||
return ConfirmationIDGenerate();
|
||||
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
172
src/cli/cli.h
Normal file
172
src/cli/cli.h
Normal file
@ -0,0 +1,172 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_CLI_H
|
||||
#define UMSKT_CLI_H
|
||||
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// fmt <-> json linkage
|
||||
template <> struct fmt::formatter<json> : formatter<string_view>
|
||||
{
|
||||
auto format(const json &j, format_context &ctx) const
|
||||
{
|
||||
if (j.is_string())
|
||||
{
|
||||
return formatter<string_view>::format(j.get<std::string>(), ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream s;
|
||||
s << j;
|
||||
return formatter<string_view>::format(s.str(), ctx);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#include "../libumskt/confid/confid.h"
|
||||
#include "../libumskt/libumskt.h"
|
||||
#include "../libumskt/pidgen2/PIDGEN2.h"
|
||||
#include "../libumskt/pidgen3/BINK1998.h"
|
||||
#include "../libumskt/pidgen3/BINK2002.h"
|
||||
#include "../libumskt/pidgen3/PIDGEN3.h"
|
||||
#include "help.h"
|
||||
|
||||
#ifndef UMSKTCLI_VERSION_STRING
|
||||
#define UMSKTCLI_VERSION_STRING "unknown version-dirty"
|
||||
#endif
|
||||
|
||||
class CLI
|
||||
{
|
||||
std::string pKey;
|
||||
DWORD32 count, total, iBinkID;
|
||||
|
||||
struct Options
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
std::string binkID;
|
||||
std::string keysFilename;
|
||||
std::string installationID;
|
||||
std::string keyToCheck;
|
||||
std::string productID;
|
||||
std::string authInfo;
|
||||
std::string productCode;
|
||||
std::string productFlavour;
|
||||
|
||||
Integer channelID;
|
||||
Integer serial;
|
||||
DWORD32 numKeys;
|
||||
|
||||
BOOL oem;
|
||||
BOOL upgrade;
|
||||
BOOL verbose;
|
||||
BOOL help;
|
||||
BOOL error;
|
||||
BOOL list;
|
||||
|
||||
PIDGEN3::KeyInfo info;
|
||||
|
||||
enum PIDGEN_VERSION
|
||||
{
|
||||
PIDGEN_2 = 2,
|
||||
PIDGEN_3 = 3,
|
||||
};
|
||||
PIDGEN_VERSION pidgenversion;
|
||||
|
||||
enum APPLICATION_STATE
|
||||
{
|
||||
STATE_PIDGEN_GENERATE,
|
||||
STATE_PIDGEN_VALIDATE,
|
||||
STATE_CONFIRMATION_ID
|
||||
};
|
||||
APPLICATION_STATE state;
|
||||
} static options;
|
||||
|
||||
public:
|
||||
CLI()
|
||||
{
|
||||
count = 0;
|
||||
total = options.numKeys;
|
||||
}
|
||||
|
||||
static std::array<CLIHelpOptions, CLIHelpOptionID_END> helpOptions;
|
||||
static json keys;
|
||||
|
||||
static BYTE Init(int argv, char *argc[]);
|
||||
static void SetHelpText();
|
||||
|
||||
static BOOL loadJSON(const fs::path &filename);
|
||||
static BOOL loadEmbeddedJSON();
|
||||
|
||||
static CLIHandlerFunc DisplayHelp;
|
||||
static CLIHandlerFunc DisplayErrorMessage;
|
||||
static CLIHandlerFunc SetVerboseOption;
|
||||
static CLIHandlerFunc SetDebugOption;
|
||||
static CLIHandlerFunc SetListOption;
|
||||
static CLIHandlerFunc SetOEMOption;
|
||||
static CLIHandlerFunc SetUpgradeOption;
|
||||
static CLIHandlerFunc SetFileOption;
|
||||
static CLIHandlerFunc SetNumberOption;
|
||||
static CLIHandlerFunc SetChannelIDOption;
|
||||
static CLIHandlerFunc SetBINKOption;
|
||||
static CLIHandlerFunc SetSerialOption;
|
||||
static CLIHandlerFunc SetActivationIDOption;
|
||||
static CLIHandlerFunc SetProductIDOption;
|
||||
static CLIHandlerFunc SetValidateOption;
|
||||
static CLIHandlerFunc SetProductCodeOption;
|
||||
static CLIHandlerFunc SetFlavourOption;
|
||||
static CLIHandlerFunc SetAuthDataOption;
|
||||
|
||||
static BOOL parseCommandLine();
|
||||
static BOOL processOptions();
|
||||
static BOOL processListCommand();
|
||||
|
||||
BOOL InitPIDGEN3(PIDGEN3 *p3);
|
||||
BOOL InitConfirmationID(ConfirmationID &confid);
|
||||
|
||||
BOOL PIDGenerate();
|
||||
BOOL PIDValidate();
|
||||
|
||||
BOOL PIDGEN2Generate(PIDGEN2 &p2);
|
||||
BOOL PIDGEN2Validate(PIDGEN2 &p2);
|
||||
BOOL PIDGEN3Generate(PIDGEN3 *p3);
|
||||
BOOL PIDGEN3Validate(PIDGEN3 *p3);
|
||||
BOOL ConfirmationIDGenerate();
|
||||
|
||||
int Run();
|
||||
};
|
||||
|
||||
#endif // UMSKT_CLI_H
|
127
src/cli/confirmationid.cpp
Normal file
127
src/cli/confirmationid.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/18/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param confid
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitConfirmationID(ConfirmationID &confid)
|
||||
{
|
||||
if (!keys["products"][options.productCode].contains("meta") ||
|
||||
!keys["products"][options.productCode]["meta"].contains("activation"))
|
||||
{
|
||||
fmt::print("ERROR: product flavour \"{}\" does not have known activation values", options.productCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto meta = keys["products"][options.productCode]["meta"]["activation"];
|
||||
|
||||
if (!keys["activation"].contains(meta["flavour"]))
|
||||
{
|
||||
fmt::print("ERROR: \"{}\" is an unknown activation flavour", meta["flavour"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto flavour = keys["activation"][meta["flavour"]];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following hyperelliptic curve parameters: activation[{}]\n", meta["flavour"]);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>7}: {}\n", "name", flavour["name"]);
|
||||
fmt::print("{:>7}: {}\n", "version", meta["version"]);
|
||||
fmt::print("{:>7}: {}\n", "Fp", flavour["p"]);
|
||||
fmt::print("{:>7}: [{}, {}, {},\n{:>10}{}, {}, {}]\n", "F[]", flavour["x"]["0"], flavour["x"]["1"],
|
||||
flavour["x"]["2"], "", flavour["x"]["3"], flavour["x"]["4"], flavour["x"]["5"]);
|
||||
fmt::print("{:>7}: {}\n", "INV", flavour["quotient"]);
|
||||
fmt::print("{:>7}: {}\n", "mqnr", flavour["non_residue"]);
|
||||
fmt::print("{:>7}: {}\n", "k", flavour["priv"]);
|
||||
fmt::print("{:>7}: {}\n", "IID", flavour["iid_key"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
confid.LoadHyperellipticCurve(flavour["x"]["0"], flavour["x"]["1"], flavour["x"]["2"], flavour["x"]["3"],
|
||||
flavour["x"]["4"], flavour["x"]["5"], flavour["priv"], flavour["quotient"],
|
||||
flavour["non_residue"], flavour["iid_key"], meta["tags"].contains("xpbrand"),
|
||||
meta["tags"].contains("office"), meta["activation"]["version"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::ConfirmationIDGenerate()
|
||||
{
|
||||
auto confid = ConfirmationID();
|
||||
std::string confirmation_id;
|
||||
|
||||
if (!InitConfirmationID(confid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD32 err = confid.Generate(options.installationID, confirmation_id, options.productID);
|
||||
|
||||
if (err == SUCCESS)
|
||||
{
|
||||
fmt::print("{}\n", confirmation_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case ERR_TOO_SHORT:
|
||||
fmt::print("ERROR: Installation ID is too short.\n");
|
||||
break;
|
||||
|
||||
case ERR_TOO_LARGE:
|
||||
fmt::print("ERROR: Installation ID is too long.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHARACTER:
|
||||
fmt::print("ERROR: Invalid character in installation ID.\n");
|
||||
break;
|
||||
|
||||
case ERR_INVALID_CHECK_DIGIT:
|
||||
fmt::print("ERROR: Installation ID checksum failed. Please check that it is typed correctly.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNKNOWN_VERSION:
|
||||
fmt::print("ERROR: Unknown installation ID version.\n");
|
||||
break;
|
||||
|
||||
case ERR_UNLUCKY:
|
||||
fmt::print("ERROR: Unable to generate valid confirmation ID.\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
fmt::print("Unknown error occurred during Confirmation ID generation: {}\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
674
src/cli/help.cpp
Normal file
674
src/cli/help.cpp
Normal file
@ -0,0 +1,674 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 01/02/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
// define static storage
|
||||
std::array<CLIHelpOptions, CLIHelpOptionID_END> CLI::helpOptions;
|
||||
|
||||
void CLI::SetHelpText()
|
||||
{
|
||||
helpOptions[OPTION_HELP] = {"h", "help", "show this help text", false, "", &DisplayHelp};
|
||||
helpOptions[OPTION_HELP2] = {"?", "", "show this help text", false, "", &DisplayHelp};
|
||||
|
||||
helpOptions[OPTION_VERSION] = {"", "version", "show UMSKT CLI / libumskt versions", false, "", nullptr};
|
||||
|
||||
helpOptions[OPTION_VERBOSE] = {"v", "verbose", "enable verbose output", false, "", &SetVerboseOption};
|
||||
|
||||
helpOptions[OPTION_DEBUG] = {"d", "debug", "enable debug output", false, "", &SetDebugOption};
|
||||
|
||||
helpOptions[OPTION_FILE] = {
|
||||
"", "file", "(advanced) specify which keys JSON file to load", true, "[embedded file]", &SetFileOption};
|
||||
|
||||
helpOptions[OPTION_LIST] = {"l", "list", "list supported products", false, "", &SetListOption};
|
||||
|
||||
helpOptions[OPTION_PRODUCT] = {"p", "product", "[REQUIRED] which product to generate keys for",
|
||||
true, options.productCode, &SetProductCodeOption};
|
||||
|
||||
helpOptions[OPTION_FLAVOUR] = {
|
||||
"f", "flavour", "which product flavour to generate keys for (required in some instances)",
|
||||
true, "", &SetFlavourOption};
|
||||
|
||||
helpOptions[OPTION_NUMBER] = {"n", "number", "(PIDGEN only) number of keys to generate",
|
||||
true, "1", &SetNumberOption};
|
||||
|
||||
helpOptions[OPTION_ACTIVATIONID] = {
|
||||
"I", "installationID", "(activation only) installation ID used to generate confirmation ID", true,
|
||||
"", &SetActivationIDOption};
|
||||
|
||||
helpOptions[OPTION_ACTIVATIONPID] = {
|
||||
"P", "productID", "(Office activation only) product ID to generate confirmation ID for",
|
||||
true, "", &SetProductIDOption};
|
||||
|
||||
helpOptions[OPTION_OEM] = {"O", "oem", "(PIDGEN) generate an OEM key", false, "", &SetOEMOption};
|
||||
|
||||
helpOptions[OPTION_UPGRADE] = {"U", "upgrade", "(PIDGEN 3 only) generate an upgrade key",
|
||||
false, "", &SetUpgradeOption};
|
||||
|
||||
helpOptions[OPTION_BINK] = {"", "bink", "(advanced) override which BINK identifier to load",
|
||||
true, "", &SetBINKOption};
|
||||
|
||||
helpOptions[OPTION_CHANNELID] = {"", "channel", "(advanced) override which product channel to use",
|
||||
true, "", &SetChannelIDOption};
|
||||
|
||||
helpOptions[OPTION_SERIAL] = {
|
||||
"", "serial", "(advanced, PIDGEN 2/3 [BINK 1998] only) specify a serial to generate",
|
||||
true, "", &SetSerialOption};
|
||||
|
||||
helpOptions[OPTION_AUTHDATA] = {
|
||||
"a", "authdata", "(advanced, PIDGEN 3 [BINK 2002] only) specify a value for the authentication data field",
|
||||
true, "", &SetAuthDataOption};
|
||||
|
||||
helpOptions[OPTION_VALIDATE] = {
|
||||
"V", "validate", "validate a specified product ID against known BINKs and algorithms",
|
||||
true, "", &SetValidateOption};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::parseCommandLine()
|
||||
{
|
||||
for (DWORD32 i = 1; i < options.argc; i++)
|
||||
{
|
||||
std::string arg = options.argv[i];
|
||||
|
||||
if (arg[0] == '-' || arg[0] == '/')
|
||||
{
|
||||
arg.erase(0, 1 + (arg[1] == '-' ? 1 : 0));
|
||||
}
|
||||
|
||||
if (arg.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (BYTE j = 0; j < CLIHelpOptionID_END; j++)
|
||||
{
|
||||
auto thisOption = helpOptions[j];
|
||||
if (arg != thisOption.Short && arg != thisOption.Long)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string nextarg;
|
||||
if (thisOption.hasArguments)
|
||||
{
|
||||
if (i == options.argc - 1)
|
||||
{
|
||||
options.error = true;
|
||||
goto CommandLineParseEnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
nextarg = std::string(options.argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (thisOption.handler == nullptr)
|
||||
{
|
||||
// prevent accidental segmentation faults
|
||||
continue;
|
||||
}
|
||||
|
||||
auto success = thisOption.handler(nextarg);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
options.error = true;
|
||||
goto CommandLineParseEnd;
|
||||
}
|
||||
if (options.help)
|
||||
{
|
||||
goto CommandLineParseEnd;
|
||||
}
|
||||
goto ParseNextCommandLineOption;
|
||||
}
|
||||
|
||||
fmt::print("unknown option: {}\n", arg);
|
||||
options.error = true;
|
||||
goto CommandLineParseEnd;
|
||||
|
||||
ParseNextCommandLineOption:
|
||||
continue;
|
||||
}
|
||||
|
||||
CommandLineParseEnd:
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
if (options.error)
|
||||
{
|
||||
DisplayErrorMessage("");
|
||||
}
|
||||
return !options.error;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::processOptions()
|
||||
{
|
||||
if (!loadJSON(options.keysFilename))
|
||||
{
|
||||
options.error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.list)
|
||||
{
|
||||
return processListCommand();
|
||||
}
|
||||
|
||||
if (options.productCode.empty())
|
||||
{
|
||||
fmt::print("ERROR: product code is required. Exiting...\n");
|
||||
DisplayHelp("");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!keys["products"].contains(options.productCode))
|
||||
{
|
||||
fmt::print("ERROR: Product \"{}\" is unknown\n", options.productCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto product = keys["products"][options.productCode];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting product: {}\n", options.productCode);
|
||||
}
|
||||
|
||||
json flavour;
|
||||
if (product.contains("flavours"))
|
||||
{
|
||||
// no default flavour, no flavour specified
|
||||
if (!product["meta"].contains("default") && options.productFlavour.empty())
|
||||
{
|
||||
fmt::print("ERROR: Product \"{}\n does not have a default flavour. Please specify a flavour.",
|
||||
options.productCode);
|
||||
return false;
|
||||
}
|
||||
// yes flavour specified, but not found
|
||||
else if (!product["flavours"].contains(options.productFlavour) && !options.productFlavour.empty())
|
||||
{
|
||||
fmt::print("ERROR: Product \"{}\" does not have a flavour named \"{}\"\n", options.productCode,
|
||||
options.productFlavour);
|
||||
return false;
|
||||
}
|
||||
// yes default flavour, no flavour specified
|
||||
else if (product["meta"].contains("default") && options.productFlavour.empty())
|
||||
{
|
||||
flavour = product["flavours"][product["meta"]["default"]];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting default flavour: {}\n", product["meta"]["default"]);
|
||||
}
|
||||
}
|
||||
// yes flavour specified, and is found
|
||||
else
|
||||
{
|
||||
flavour = product["flavours"][options.productFlavour];
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selecting flavour: {}\n", options.productFlavour);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no variants, just go with what we have
|
||||
flavour = product;
|
||||
}
|
||||
|
||||
auto pidtype = product["meta"]["type"];
|
||||
if (flavour["meta"].contains("type"))
|
||||
{
|
||||
pidtype = flavour["meta"]["type"];
|
||||
}
|
||||
|
||||
if (options.state != Options::STATE_PIDGEN_GENERATE && options.state != Options::STATE_PIDGEN_VALIDATE)
|
||||
{
|
||||
// exit early if we're not doing PIDGEN
|
||||
goto processOptionsExitEarly;
|
||||
}
|
||||
|
||||
if (pidtype == "PIDGEN3")
|
||||
{
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_3;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting PIDGEN type to \"PIDGEN3\"\n");
|
||||
}
|
||||
|
||||
if (options.oem)
|
||||
{
|
||||
flavour["BINK"][1].get_to(options.binkID);
|
||||
}
|
||||
else
|
||||
{
|
||||
flavour["BINK"][0].get_to(options.binkID);
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selected BINK: {}\n", options.binkID);
|
||||
}
|
||||
}
|
||||
else if (pidtype == "PIDGEN2")
|
||||
{
|
||||
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_2;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting PIDGEN type to \"PIDGEN2\"\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (options.state != Options::STATE_PIDGEN_GENERATE)
|
||||
{
|
||||
// exit early if we're only validating
|
||||
goto processOptionsExitEarly;
|
||||
}
|
||||
|
||||
if (flavour.contains("DPC") && flavour["DPC"].contains(options.binkID) && options.channelID == 0)
|
||||
{
|
||||
std::vector<json> filtered;
|
||||
for (auto const &i : flavour["DPC"][options.binkID].items())
|
||||
{
|
||||
auto el = i.value();
|
||||
if (!el["isEvaluation"].get<bool>())
|
||||
{
|
||||
filtered.emplace_back(el);
|
||||
}
|
||||
}
|
||||
|
||||
// roll a die to choose which DPC entry to pick
|
||||
auto rand = UMSKT::getRandom<BYTE>();
|
||||
auto dpc = filtered[rand % filtered.size()];
|
||||
auto min = dpc["min"].get<WORD>(), max = dpc["max"].get<WORD>();
|
||||
|
||||
if (min == max)
|
||||
{
|
||||
options.channelID = min;
|
||||
}
|
||||
else
|
||||
{
|
||||
options.channelID = min + (rand % (max - min));
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Selected channel ID: {} (DPC entry {}/{})\n", options.channelID, (rand % filtered.size()) + 1,
|
||||
filtered.size());
|
||||
}
|
||||
}
|
||||
|
||||
if (options.channelID.IsZero())
|
||||
{
|
||||
options.channelID.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
options.channelID %= PIDGEN::MaxChannelID;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Generated channel ID: {}\n", options.channelID);
|
||||
}
|
||||
}
|
||||
|
||||
// FE and FF are BINK 1998, but use a different, currently unhandled encoding scheme, we return an error here
|
||||
if (options.binkID == "TS00" || options.binkID == "TS01")
|
||||
{
|
||||
fmt::print("ERROR: Terminal Services BINKs (TS00 and TS01) are unsupported at this time\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
processOptionsExitEarly:
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the contents of the input JSON file in an
|
||||
* intuitive and attractive pattern
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
BOOL CLI::processListCommand()
|
||||
{
|
||||
// the following code is absolutely unhinged
|
||||
// I'm so sorry
|
||||
|
||||
#if defined(UNICODE) || defined(__GNUC__)
|
||||
auto *leaf = "\u251C", *last = "\u2514", *line = "\u2500";
|
||||
#else
|
||||
auto *leaf = "\xC3", *last = "\xC0", *line = "\xC4";
|
||||
#endif
|
||||
|
||||
fmt::print("Listing known products and flavours: \n\n");
|
||||
|
||||
fmt::print("* The following product list uses this style of formatting:\n");
|
||||
fmt::print("{}: {} \n", fmt::styled("PRODUCT", fmt::emphasis::bold), "Product name");
|
||||
fmt::print("{}{}{} {}: {} \n", last, line, line, "FLAVOUR", "Flavour name");
|
||||
fmt::print("* Products that require a flavour are noted with {}\n\n",
|
||||
fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
|
||||
for (auto const &i : keys["products"].items())
|
||||
{
|
||||
auto el = i.value();
|
||||
auto containsFlavours = el.contains("flavours");
|
||||
|
||||
fmt::print("{:<9} {} ", fmt::styled(fmt::format("{}:", i.key()), fmt::emphasis::bold), el["name"]);
|
||||
if (el.contains("BINK"))
|
||||
{
|
||||
fmt::print("{}\n", el["BINK"]);
|
||||
}
|
||||
else if (el["meta"].contains("default"))
|
||||
{
|
||||
fmt::print("(default: {} {})\n", fmt::styled(el["meta"]["default"], fmt::emphasis::bold),
|
||||
el["flavours"][el["meta"]["default"]]["BINK"]);
|
||||
}
|
||||
else if (el["meta"]["type"] == "PIDGEN3")
|
||||
{
|
||||
fmt::print("[{}]\n", el["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", fmt::styled("(no default)", fmt::emphasis::bold));
|
||||
}
|
||||
|
||||
if (containsFlavours)
|
||||
{
|
||||
auto flavours = el["flavours"];
|
||||
for (auto j = flavours.begin(); j != flavours.end(); j++)
|
||||
{
|
||||
auto el2 = j.value();
|
||||
BOOL isLast = j == --flavours.end();
|
||||
|
||||
fmt::print("{}{}{} {:<9} {} ", !isLast ? leaf : last, line, line, fmt::format("{}:", j.key()),
|
||||
fmt::format("{} {}", el["name"], el2["name"]));
|
||||
|
||||
if (el2.contains("meta") && el2["meta"].contains("type"))
|
||||
{
|
||||
fmt::print("[{}]\n", el2["meta"]["type"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("{}\n", el2["BINK"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::DisplayHelp(const std::string &)
|
||||
{
|
||||
options.help = true;
|
||||
fmt::print("usage: {} \n", options.argv[0]);
|
||||
|
||||
for (BYTE i = 0; i < CLIHelpOptionID_END; i++)
|
||||
{
|
||||
CLIHelpOptions o = helpOptions[i];
|
||||
|
||||
if (o.Short.empty())
|
||||
{
|
||||
fmt::print("\t{:>2} --{:<15} {}", "", o.Long, o.HelpText);
|
||||
}
|
||||
else if (o.Long.empty())
|
||||
{
|
||||
fmt::print("\t-{} {:<15} {}", o.Short, "", o.HelpText);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::print("\t-{} --{:<15} {}", o.Short, o.Long, o.HelpText);
|
||||
}
|
||||
|
||||
if (!o.Default.empty())
|
||||
{
|
||||
fmt::print(" (defaults to {})", o.Default);
|
||||
}
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
fmt::print("\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::DisplayErrorMessage(const std::string &)
|
||||
{
|
||||
fmt::print("Error parsing command line options\n");
|
||||
DisplayHelp("");
|
||||
options.error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL CLI::SetVerboseOption(const std::string &)
|
||||
{
|
||||
options.verbose = true;
|
||||
UMSKT::setVerboseOutput(stdout);
|
||||
fmt::print(UMSKT::verbose, "Enabling verbose option\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetDebugOption(const std::string &)
|
||||
{
|
||||
options.verbose = true;
|
||||
UMSKT::setDebugOutput(stdout);
|
||||
fmt::print(UMSKT::debug, "Enabling debug option\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetListOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting list option\n");
|
||||
}
|
||||
options.list = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetOEMOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting OEM option\n");
|
||||
}
|
||||
options.oem = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetUpgradeOption(const std::string &)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting upgrade option\n");
|
||||
}
|
||||
options.upgrade = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetFileOption(const std::string &file)
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting file option to: {}\n", file);
|
||||
}
|
||||
options.keysFilename = file;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetNumberOption(const std::string &num)
|
||||
{
|
||||
auto nKeys = UMSKT::IntegerS(num);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting generation number option to: {}\n", num);
|
||||
}
|
||||
|
||||
options.numKeys = nKeys.ConvertToLong();
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetChannelIDOption(const std::string &channum)
|
||||
{
|
||||
Integer channelID = UMSKT::IntegerS(channum);
|
||||
|
||||
// channel ids must be between 000 and 999
|
||||
if (channelID >= PIDGEN::MaxChannelID)
|
||||
{
|
||||
fmt::print("ERROR: refusing to create a key with a Channel ID greater than 999\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting Channel ID option to: {}\n", channelID);
|
||||
}
|
||||
|
||||
options.channelID = channelID;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetBINKOption(const std::string &bink)
|
||||
{
|
||||
auto strbinkid = std::string(bink);
|
||||
options.binkID = UMSKT::strtoupper(strbinkid);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting BINK option to: {}\n", strbinkid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetFlavourOption(const std::string &flavour)
|
||||
{
|
||||
auto strFlavour = UMSKT::strtoupper(flavour);
|
||||
options.productFlavour = strFlavour;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting flavour option to: {}\n", strFlavour);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetSerialOption(const std::string &arg)
|
||||
{
|
||||
Integer Serial = UMSKT::IntegerS(arg);
|
||||
|
||||
// serials must be between 000000 and 999999
|
||||
if (Serial >= PIDGEN::MaxSerial)
|
||||
{
|
||||
fmt::print("ERROR: refusing to create a key with a Serial not between 000000 and 999999\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
options.serial = Serial;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting serial number option to: {}\n", Serial);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetActivationIDOption(const std::string &aid)
|
||||
{
|
||||
options.installationID = aid;
|
||||
options.state = Options::STATE_CONFIRMATION_ID;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting program state to Confirmation ID Generation\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetProductIDOption(const std::string &product)
|
||||
{
|
||||
options.productID = product;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product ID option to: {}\n", product);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetValidateOption(const std::string &productID)
|
||||
{
|
||||
options.keyToCheck = productID;
|
||||
options.state = Options::STATE_PIDGEN_VALIDATE;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting program state to PIDGEN Validation\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetProductCodeOption(const std::string &product)
|
||||
{
|
||||
auto strProduct = std::string(product);
|
||||
options.productCode = UMSKT::strtoupper(strProduct);
|
||||
options.productFlavour = "";
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting product code to: {}\n", strProduct);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL CLI::SetAuthDataOption(const std::string &authData)
|
||||
{
|
||||
auto strAuthData = std::string(authData);
|
||||
options.authInfo = strAuthData;
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("Setting authdata option to: {}\n", strAuthData);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
70
src/cli/help.h
Normal file
70
src/cli/help.h
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 01/02/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_HELP_H
|
||||
#define UMSKT_HELP_H
|
||||
|
||||
typedef BOOL CLIHandlerFunc(const std::string &);
|
||||
|
||||
/**
|
||||
* CLI Options List.
|
||||
*
|
||||
* Note: options are processed in the order found in the ENUM
|
||||
* order matters mostly for UX.
|
||||
*
|
||||
*/
|
||||
enum CLIHelpOptionIDs
|
||||
{
|
||||
OPTION_HELP,
|
||||
OPTION_HELP2,
|
||||
OPTION_VERSION,
|
||||
OPTION_VERBOSE,
|
||||
OPTION_DEBUG,
|
||||
OPTION_FILE,
|
||||
OPTION_LIST,
|
||||
OPTION_PRODUCT,
|
||||
OPTION_FLAVOUR,
|
||||
OPTION_NUMBER,
|
||||
OPTION_OEM,
|
||||
OPTION_UPGRADE,
|
||||
OPTION_ACTIVATIONID,
|
||||
OPTION_ACTIVATIONPID,
|
||||
OPTION_BINK,
|
||||
OPTION_CHANNELID,
|
||||
OPTION_SERIAL,
|
||||
OPTION_AUTHDATA,
|
||||
OPTION_VALIDATE,
|
||||
|
||||
CLIHelpOptionID_END
|
||||
};
|
||||
|
||||
struct CLIHelpOptions
|
||||
{
|
||||
std::string Short;
|
||||
std::string Long;
|
||||
std::string HelpText;
|
||||
BOOL hasArguments;
|
||||
std::string Default;
|
||||
CLIHandlerFunc *handler;
|
||||
};
|
||||
|
||||
#endif // UMSKT_HELP_H
|
3
src/cli/options.cpp
Normal file
3
src/cli/options.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by neo on 2/18/2024.
|
||||
//
|
319
src/cli/pidgen.cpp
Normal file
319
src/cli/pidgen.cpp
Normal file
@ -0,0 +1,319 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/18/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen3
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::InitPIDGEN3(PIDGEN3 *p3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("Loaded the following elliptic curve parameters: BINK[{}]\n", options.binkID);
|
||||
fmt::print("{:->80}\n", "");
|
||||
fmt::print("{:>6}: {}\n", "P", bink["p"]);
|
||||
fmt::print("{:>6}: {}\n", "a", bink["a"]);
|
||||
fmt::print("{:>6}: {}\n", "b", bink["b"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "G[x,y]", bink["g"]["x"], "", bink["g"]["y"]);
|
||||
fmt::print("{:>6}: [{},\n{:>9}{}]\n", "K[x,y]", bink["pub"]["x"], "", bink["pub"]["y"]);
|
||||
fmt::print("{:>6}: {}\n", "n", bink["n"]);
|
||||
fmt::print("{:>6}: {}\n", "k", bink["priv"]);
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
p3->LoadEllipticCurve(options.binkID, bink["p"], bink["a"], bink["b"], bink["g"]["x"], bink["g"]["y"],
|
||||
bink["pub"]["x"], bink["pub"]["y"], bink["n"], bink["priv"]);
|
||||
|
||||
if (options.state != Options::APPLICATION_STATE::STATE_PIDGEN_GENERATE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.channelID.IsZero())
|
||||
{
|
||||
options.channelID.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
}
|
||||
|
||||
options.channelID %= 1000;
|
||||
p3->info.ChannelID = options.channelID;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Channel ID: {:d}\n", options.channelID);
|
||||
}
|
||||
|
||||
if (options.serial.NotZero() && p3->checkFieldIsBink1998())
|
||||
{
|
||||
p3->info.Serial = options.serial;
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Serial {:d}\n", options.serial);
|
||||
}
|
||||
}
|
||||
else if (options.serial.NotZero() && !p3->checkFieldIsBink1998())
|
||||
{
|
||||
fmt::print("Warning: Discarding user-supplied serial for BINK2002\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Generate(PIDGEN2 &p2)
|
||||
{
|
||||
p2.info.ChannelID = options.channelID;
|
||||
p2.info.Serial = options.serial;
|
||||
p2.info.isOEM = options.oem;
|
||||
|
||||
std::string serial;
|
||||
p2.Generate(serial);
|
||||
|
||||
serial = p2.StringifyKey(serial);
|
||||
|
||||
fmt::print("{}", serial);
|
||||
|
||||
auto retval = p2.Validate(serial);
|
||||
|
||||
if (!retval)
|
||||
{
|
||||
fmt::print(" [INVALID]");
|
||||
}
|
||||
|
||||
fmt::print("\n");
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pidgen2
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN2Validate(PIDGEN2 &p2)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!p2.ValidateKeyString(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", p2.StringifyKey(product_key));
|
||||
|
||||
if (!p2.Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN3Generate(PIDGEN3 *p3)
|
||||
{
|
||||
// raw PID/serial value
|
||||
Integer serialRnd;
|
||||
|
||||
if (p3->checkFieldIsBink1998())
|
||||
{
|
||||
if (options.serial.NotZero())
|
||||
{
|
||||
// using user-provided serial
|
||||
serialRnd = options.serial;
|
||||
}
|
||||
else
|
||||
{
|
||||
// generate a random number to use as a serial
|
||||
serialRnd.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
|
||||
}
|
||||
|
||||
// make sure it's less than 999999
|
||||
serialRnd %= 1000000;
|
||||
}
|
||||
|
||||
p3->info.isOEM = options.oem;
|
||||
|
||||
for (DWORD32 i = 0; i < total; i++)
|
||||
{
|
||||
if (!p3->checkFieldIsBink1998())
|
||||
{
|
||||
if (options.authInfo.empty())
|
||||
{
|
||||
p3->info.AuthInfo.Randomize(UMSKT::rng, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
p3->info.AuthInfo = CryptoPP::Crop(UMSKT::IntegerS(options.authInfo), 10);
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> AuthInfo: {:d}\n", p3->info.AuthInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p3->info.Serial = serialRnd;
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
p3->Generate(pKey);
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("> Product ID: {}\n\n", p3->StringifyProductID());
|
||||
}
|
||||
|
||||
bool isValid = p3->Validate(pKey);
|
||||
if (isValid)
|
||||
{
|
||||
fmt::print(p3->StringifyKey(pKey));
|
||||
if (i <= total - 1 || options.verbose)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
count += isValid;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("{} [Invalid]", p3->StringifyKey(pKey));
|
||||
if (i <= total - 1)
|
||||
{
|
||||
fmt::print("\n");
|
||||
}
|
||||
}
|
||||
total++; // queue a redo, basically
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose)
|
||||
{
|
||||
fmt::print("\nSuccess count: {}/{}\n", count, total);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGEN3Validate(PIDGEN3 *p3)
|
||||
{
|
||||
std::string product_key;
|
||||
|
||||
if (!p3->ValidateKeyString(options.keyToCheck, product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is in an incorrect format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("{}\n", p3->StringifyKey(product_key));
|
||||
|
||||
if (!p3->Validate(product_key))
|
||||
{
|
||||
fmt::print("ERROR: Product key is invalid! Wrong BINK ID?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
fmt::print("Key validated successfully!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::PIDGenerate()
|
||||
{
|
||||
BOOL retval = false;
|
||||
|
||||
if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_2)
|
||||
{
|
||||
auto p2 = PIDGEN2();
|
||||
retval = PIDGEN2Generate(p2);
|
||||
return retval;
|
||||
}
|
||||
else if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
auto p3 = PIDGEN3::Factory(bink["p"]);
|
||||
InitPIDGEN3(p3);
|
||||
retval = PIDGEN3Generate(p3);
|
||||
|
||||
delete p3;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return isValid
|
||||
*/
|
||||
BOOL CLI::PIDValidate()
|
||||
{
|
||||
BOOL retval = false;
|
||||
|
||||
if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_2)
|
||||
{
|
||||
auto p2 = PIDGEN2();
|
||||
retval = PIDGEN2Validate(p2);
|
||||
return retval;
|
||||
}
|
||||
else if (options.pidgenversion == Options::PIDGEN_VERSION::PIDGEN_3)
|
||||
{
|
||||
auto bink = keys["BINK"][options.binkID];
|
||||
|
||||
auto p3 = PIDGEN3::Factory(bink["p"]);
|
||||
InitPIDGEN3(p3);
|
||||
retval = PIDGEN3Validate(p3);
|
||||
|
||||
delete p3;
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
581
src/libumskt/confid/confid.cpp
Normal file
581
src/libumskt/confid/confid.cpp
Normal file
@ -0,0 +1,581 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by WitherOrNot on 06/02/2023
|
||||
* @Maintainer WitherOrNot
|
||||
*
|
||||
* @History {
|
||||
* This algorithm was provided to the UMSKT project by diamondggg
|
||||
* the history provided by diamondggg is that they are the originator of the code
|
||||
* and was created in tandem with an acquaintance who knows number theory.
|
||||
* The file dates suggest this code was written sometime in 2017/2018
|
||||
*
|
||||
* The algorithm was refactored by Neo in 2023
|
||||
* }
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x0
|
||||
* @param x1
|
||||
* @param x2
|
||||
* @param x3
|
||||
* @param x4
|
||||
* @param x5
|
||||
* @param priv
|
||||
* @param modulus
|
||||
* @param nonresidue
|
||||
* @param isOffice
|
||||
* @param isXPBrand
|
||||
* @param flagVersion
|
||||
* @return
|
||||
*/
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(QWORD x0, QWORD x1, QWORD x2, QWORD x3, QWORD x4, QWORD x5, Q_OWORD priv,
|
||||
QWORD modulus, QWORD nonresidue, DWORD32 iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
QWORD fvals[6] = {x0, x1, x2, x3, x4, x5};
|
||||
|
||||
return LoadHyperellipticCurve(fvals, priv, modulus, nonresidue, iidkey, isOffice, isXPBrand, flagVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param f
|
||||
* @param priv
|
||||
* @param modulus
|
||||
* @param nonresidue
|
||||
* @param isOffice
|
||||
* @param isXPBrand
|
||||
* @param flagVersion
|
||||
* @return
|
||||
*/
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulus, QWORD nonresidue, DWORD32 iidkey,
|
||||
BOOL isOffice, BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
memcpy(&curve, f, sizeof(curve));
|
||||
memcpy(&privateKey, &priv, sizeof(Q_OWORD));
|
||||
|
||||
MOD = modulus;
|
||||
NON_RESIDUE = nonresidue;
|
||||
this->isOffice = isOffice;
|
||||
this->isXPBrand = isXPBrand;
|
||||
this->flagVersion = flagVersion;
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const std::string &x2,
|
||||
const std::string &x3, const std::string &x4, const std::string &x5,
|
||||
const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
std::string f[6];
|
||||
f[0] = x0;
|
||||
f[1] = x1;
|
||||
f[2] = x2;
|
||||
f[3] = x3;
|
||||
f[4] = x4;
|
||||
f[5] = x5;
|
||||
|
||||
return LoadHyperellipticCurve(f, priv, modulus, nonresidue, iidkey, isOffice, isXPBrand, flagVersion);
|
||||
}
|
||||
|
||||
BOOL ConfirmationID::LoadHyperellipticCurve(const std::string *f, const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
EncodeN(IntegerS(f[i]), curve[i]);
|
||||
}
|
||||
|
||||
EncodeN(IntegerS(priv), privateKey);
|
||||
|
||||
EncodeN(IntegerS(modulus), MOD);
|
||||
|
||||
EncodeN(IntegerS(nonresidue), NON_RESIDUE);
|
||||
|
||||
this->isOffice = isOffice;
|
||||
this->isXPBrand = isXPBrand;
|
||||
this->flagVersion = flagVersion;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
DWORD32 ConfirmationID::calculateCheckDigit(DWORD32 pid)
|
||||
{
|
||||
DWORD32 i = 0, j = 0, k = 0;
|
||||
for (j = pid; j; i += k)
|
||||
{
|
||||
k = j % 10;
|
||||
j /= 10;
|
||||
}
|
||||
|
||||
return ((10 * pid) - (i % 7)) + 7;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param iid
|
||||
* @param hwid
|
||||
* @param version
|
||||
*/
|
||||
void ConfirmationID::decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD32 *version)
|
||||
{
|
||||
QWORD buffer[5];
|
||||
for (BYTE i = 0; i < 5; i++)
|
||||
{
|
||||
memcpy(&buffer[i], (iid + (4 * i)), 4);
|
||||
}
|
||||
|
||||
DWORD32 v1 = (buffer[3] & 0xFFFFFFF8) | 2;
|
||||
DWORD32 v2 = ((buffer[3] & 7) << 29) | (buffer[2] >> 3);
|
||||
QWORD hardwareIDVal = ((QWORD)v1 << 32) | v2;
|
||||
for (BYTE i = 0; i < 8; ++i)
|
||||
{
|
||||
hwid[i] = (hardwareIDVal >> (8 * i)) & 0xFF;
|
||||
}
|
||||
|
||||
*version = buffer[0] & 7;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param buffer
|
||||
* @param bufSize
|
||||
* @param key
|
||||
* @param keySize
|
||||
*/
|
||||
void ConfirmationID::Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize)
|
||||
{
|
||||
BYTE sha1_input[64], sha1_result[SHA1::DIGESTSIZE];
|
||||
BYTE half = bufSize / 2;
|
||||
auto digest = SHA1();
|
||||
|
||||
// assert(half <= sizeof(sha1_result) && half + keySize <= sizeof(sha1_input) - 9);
|
||||
for (BYTE external_counter = 0; external_counter < 4; external_counter++)
|
||||
{
|
||||
memset(sha1_input, 0, sizeof(sha1_input));
|
||||
|
||||
if (isXPBrand)
|
||||
{
|
||||
memcpy(sha1_input, buffer + half, half);
|
||||
memcpy(sha1_input + half, key, keySize);
|
||||
|
||||
sha1_input[half + keySize] = 0x80;
|
||||
sha1_input[sizeof(sha1_input) - 1] = (half + keySize) * 8;
|
||||
sha1_input[sizeof(sha1_input) - 2] = (half + keySize) * 8 / 0x100;
|
||||
}
|
||||
else if (isOffice)
|
||||
{
|
||||
sha1_input[0] = 0x79;
|
||||
memcpy(sha1_input + 1, buffer + half, half);
|
||||
memcpy(sha1_input + 1 + half, key, keySize);
|
||||
|
||||
sha1_input[1 + half + keySize] = 0x80;
|
||||
sha1_input[sizeof(sha1_input) - 1] = (1 + half + keySize) * 8;
|
||||
sha1_input[sizeof(sha1_input) - 2] = (1 + half + keySize) * 8 / 0x100;
|
||||
}
|
||||
|
||||
digest.Update(sha1_input, sizeof(sha1_input));
|
||||
digest.Final(sha1_result);
|
||||
|
||||
for (BYTE i = half & ~3; i < half; i++)
|
||||
{
|
||||
sha1_result[i] = sha1_result[i + 4 - (half & 3)];
|
||||
}
|
||||
|
||||
for (BYTE i = 0; i < half; i++)
|
||||
{
|
||||
unsigned char tmp = buffer[i + half];
|
||||
buffer[i + half] = buffer[i] ^ sha1_result[i];
|
||||
buffer[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param buffer
|
||||
* @param bufSize
|
||||
* @param key
|
||||
* @param keySize
|
||||
*/
|
||||
void ConfirmationID::Unmix(BYTE *buffer, BYTE bufSize, const BYTE key[4], BYTE keySize)
|
||||
{
|
||||
BYTE sha1_input[64], sha1_result[SHA1::DIGESTSIZE];
|
||||
BYTE half = bufSize / 2;
|
||||
auto digest = SHA1();
|
||||
// assert(half <= sizeof(sha1_result) && half + keySize <= sizeof(sha1_input) - 9);
|
||||
|
||||
for (BYTE external_counter = 0; external_counter < 4; external_counter++)
|
||||
{
|
||||
memset(sha1_input, 0, sizeof(sha1_input));
|
||||
|
||||
if (isXPBrand)
|
||||
{
|
||||
memcpy(sha1_input, buffer, half);
|
||||
memcpy(sha1_input + half, key, keySize);
|
||||
sha1_input[half + keySize] = 0x80;
|
||||
sha1_input[sizeof(sha1_input) - 1] = (half + keySize) * 8;
|
||||
sha1_input[sizeof(sha1_input) - 2] = (half + keySize) * 8 / 0x100;
|
||||
}
|
||||
else if (isOffice)
|
||||
{
|
||||
sha1_input[0] = 0x79;
|
||||
memcpy(sha1_input + 1, buffer, half);
|
||||
memcpy(sha1_input + 1 + half, key, keySize);
|
||||
sha1_input[1 + half + keySize] = 0x80;
|
||||
sha1_input[sizeof(sha1_input) - 1] = (1 + half + keySize) * 8;
|
||||
sha1_input[sizeof(sha1_input) - 2] = (1 + half + keySize) * 8 / 0x100;
|
||||
}
|
||||
|
||||
digest.Update(sha1_input, sizeof(sha1_input));
|
||||
digest.Final(sha1_result);
|
||||
|
||||
for (BYTE i = half & ~3; i < half; i++)
|
||||
{
|
||||
sha1_result[i] = sha1_result[i + 4 - (half & 3)];
|
||||
}
|
||||
|
||||
for (BYTE i = 0; i < half; i++)
|
||||
{
|
||||
unsigned char tmp = buffer[i];
|
||||
buffer[i] = buffer[i + half] ^ sha1_result[i];
|
||||
buffer[i + half] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param installationIDIn
|
||||
* @param confirmationIDOut
|
||||
* @param productIDIn
|
||||
* @return
|
||||
*/
|
||||
CONFIRMATION_ID_STATUS ConfirmationID::Generate(const std::string &installationIDIn, std::string &confirmationIDOut,
|
||||
std::string &productIDIn)
|
||||
{
|
||||
DWORD32 version;
|
||||
BYTE hardwareID[8];
|
||||
BYTE installation_id[19]; // 10**45 < 256**19
|
||||
BYTE productID[4];
|
||||
|
||||
BYTE installation_id_len = 0;
|
||||
auto pid = &installationIDIn[0];
|
||||
|
||||
BYTE count = 0, totalCount = 0;
|
||||
unsigned check = 0;
|
||||
|
||||
BYTE i;
|
||||
|
||||
Q_OWORD mod_inv;
|
||||
memcpy(&mod_inv, &privateKey, sizeof(mod_inv));
|
||||
|
||||
for (; *pid; pid++)
|
||||
{
|
||||
if (*pid == ' ' || *pid == '-')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int d = *pid - '0';
|
||||
|
||||
if (d < 0 || d > 9)
|
||||
{
|
||||
return ERR_INVALID_CHARACTER;
|
||||
}
|
||||
|
||||
if (count == 5 || mod_inv.qword[0] == 0)
|
||||
{
|
||||
if (!count)
|
||||
{
|
||||
return (totalCount == 45) ? ERR_TOO_LARGE : ERR_TOO_SHORT;
|
||||
}
|
||||
|
||||
if (d != check % 7)
|
||||
{
|
||||
return (count < 5) ? ERR_TOO_SHORT : ERR_INVALID_CHECK_DIGIT;
|
||||
}
|
||||
|
||||
check = 0;
|
||||
count = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
check += (count % 2 ? d * 2 : d);
|
||||
count++;
|
||||
|
||||
totalCount++;
|
||||
if (totalCount > 45)
|
||||
{
|
||||
return ERR_TOO_LARGE;
|
||||
}
|
||||
|
||||
unsigned char carry = d;
|
||||
for (i = 0; i < installation_id_len; i++)
|
||||
{
|
||||
unsigned x = installation_id[i] * 10 + carry;
|
||||
installation_id[i] = x & 0xFF;
|
||||
carry = x >> 8;
|
||||
}
|
||||
|
||||
if (carry)
|
||||
{
|
||||
assert(installation_id_len < sizeof(installation_id));
|
||||
installation_id[installation_id_len++] = carry;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalCount != 41 && totalCount < 45)
|
||||
{
|
||||
return ERR_TOO_SHORT;
|
||||
}
|
||||
|
||||
for (; installation_id_len < sizeof(installation_id); installation_id_len++)
|
||||
{
|
||||
installation_id[installation_id_len] = 0;
|
||||
}
|
||||
|
||||
Unmix(installation_id, totalCount == 41 ? 17 : 19, iid_key, 4);
|
||||
|
||||
if (installation_id[18] >= 0x10)
|
||||
{
|
||||
return ERR_UNKNOWN_VERSION;
|
||||
}
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct
|
||||
{
|
||||
QWORD HardwareID;
|
||||
QWORD ProductIDLow;
|
||||
BYTE ProductIDHigh;
|
||||
WORD KeySHA1;
|
||||
} parsed;
|
||||
#pragma pack(pop)
|
||||
|
||||
if (isXPBrand)
|
||||
{
|
||||
memcpy(&parsed, installation_id, sizeof(parsed));
|
||||
productID[0] = parsed.ProductIDLow & ((1 << 17) - 1);
|
||||
productID[1] = (parsed.ProductIDLow >> 17) & ((1 << 10) - 1);
|
||||
productID[2] = (parsed.ProductIDLow >> 27) & ((1 << 24) - 1);
|
||||
version = (parsed.ProductIDLow >> 51) & 15;
|
||||
productID[3] = (parsed.ProductIDLow >> 55) | (parsed.ProductIDHigh << 9);
|
||||
|
||||
if (flagVersion == 0)
|
||||
{
|
||||
if (version != (totalCount == 41 ? 9 : 10))
|
||||
{
|
||||
return ERR_UNKNOWN_VERSION;
|
||||
}
|
||||
}
|
||||
else if (flagVersion != version)
|
||||
{
|
||||
return ERR_UNKNOWN_VERSION;
|
||||
}
|
||||
}
|
||||
else if (isOffice)
|
||||
{
|
||||
decode_iid_new_version(installation_id, hardwareID, &version);
|
||||
|
||||
if (flagVersion != version)
|
||||
{
|
||||
return ERR_UNKNOWN_VERSION;
|
||||
}
|
||||
|
||||
memcpy(&parsed, hardwareID, 8);
|
||||
productID[0] = stoi(productIDIn.substr(0, 5));
|
||||
|
||||
auto channelid = productIDIn.substr(6, 3);
|
||||
char *p = &channelid[0];
|
||||
for (; *p; p++)
|
||||
{
|
||||
*p = toupper((unsigned char)*p);
|
||||
}
|
||||
|
||||
if (strcmp(&channelid[0], "OEM") == 0)
|
||||
{
|
||||
productID[1] = stoi(productIDIn.substr(12, 3));
|
||||
productID[2] = (stoi(productIDIn.substr(15, 1)) * 100000) + stoi(productIDIn.substr(18, 5));
|
||||
productID[2] = calculateCheckDigit(productID[2]);
|
||||
productID[3] = ((stoi(productIDIn.substr(10, 2))) * 1000) + productID[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
productID[1] = stoi(productIDIn.substr(6, 3));
|
||||
productID[2] = stoi(productIDIn.substr(10, 7));
|
||||
productID[3] = stoi(productIDIn.substr(18, 5));
|
||||
}
|
||||
// fmt::print("ProductID: {}-{}-{}-{} \n", productID[0], productID[1], productID[2], productID[3]);
|
||||
}
|
||||
|
||||
BYTE keybuf[16];
|
||||
memcpy(keybuf, &parsed.HardwareID, 8);
|
||||
|
||||
QWORD productIdMixed =
|
||||
(QWORD)productID[0] << 41 | (QWORD)productID[1] << 58 | (QWORD)productID[2] << 17 | productID[3];
|
||||
memcpy(keybuf + 8, &productIdMixed, 8);
|
||||
|
||||
TDivisor d;
|
||||
BYTE attempt;
|
||||
|
||||
Q_OWORD ulowhi;
|
||||
memset(&ulowhi, 0, sizeof(ulowhi));
|
||||
|
||||
for (attempt = 0; attempt <= 0x80; attempt++)
|
||||
{
|
||||
if (isXPBrand)
|
||||
{
|
||||
ulowhi.byte[7] = attempt;
|
||||
}
|
||||
else if (isOffice)
|
||||
{
|
||||
ulowhi.byte[6] = attempt;
|
||||
}
|
||||
|
||||
Mix(ulowhi.byte, 14, keybuf, 16);
|
||||
QWORD x2 = residue->ui128_quotient_mod(ulowhi.qword[0], ulowhi.qword[1]);
|
||||
QWORD x1 = ulowhi.qword[0] - x2 * MOD;
|
||||
x2++;
|
||||
|
||||
d.u.qword[0] = residue->sub(residue->mul(x1, x1), residue->mul(NON_RESIDUE, residue->mul(x2, x2)));
|
||||
d.u.qword[1] = residue->add(x1, x1);
|
||||
if (divisor->find_divisor_v(&d))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (attempt > 0x80)
|
||||
{
|
||||
return ERR_UNLUCKY;
|
||||
}
|
||||
|
||||
Q_OWORD priv;
|
||||
memcpy(&priv, &privateKey, sizeof(priv));
|
||||
|
||||
divisor->mul128(&d, priv.qword[0], priv.qword[1], &d);
|
||||
|
||||
Q_OWORD e;
|
||||
memset(&e, 0, sizeof(e));
|
||||
|
||||
if (d.u.qword[0] == BAD)
|
||||
{
|
||||
// we can not get the zero divisor, actually...
|
||||
e.qword[0] = residue->__umul128(MOD + 2, MOD, &e.qword[1]);
|
||||
}
|
||||
else if (d.u.qword[1] == BAD)
|
||||
{
|
||||
// O(1/MOD) chance
|
||||
// encoded = (unsigned __int128)(MOD + 1) * d.u[0] + MOD; // * MOD + d.u[0] is fine too
|
||||
e.qword[0] = residue->__umul128(MOD + 1, d.u.qword[0], &e.qword[1]);
|
||||
e.qword[0] += MOD;
|
||||
e.qword[1] += (e.qword[0] < MOD);
|
||||
}
|
||||
else
|
||||
{
|
||||
QWORD x1 = (d.u.qword[1] % 2 ? d.u.qword[1] + MOD : d.u.qword[1]) / 2;
|
||||
QWORD x2sqr = residue->sub(residue->mul(x1, x1), d.u.qword[0]);
|
||||
QWORD x2 = residue->sqrt(x2sqr);
|
||||
|
||||
if (x2 == BAD)
|
||||
{
|
||||
x2 = residue->sqrt(residue->mul(x2sqr, residue->inv(NON_RESIDUE)));
|
||||
assert(x2 != BAD);
|
||||
e.qword[0] = residue->__umul128(MOD + 1, MOD + x2, &e.qword[1]);
|
||||
e.qword[0] += x1;
|
||||
e.qword[1] += (e.qword[0] < x1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// points (-x1+x2, v(-x1+x2)) and (-x1-x2, v(-x1-x2))
|
||||
QWORD x1a = residue->sub(x1, x2);
|
||||
QWORD y1 = residue->sub(d.v.qword[0], residue->mul(d.v.qword[1], x1a));
|
||||
QWORD x2a = residue->add(x1, x2);
|
||||
QWORD y2 = residue->sub(d.v.qword[0], residue->mul(d.v.qword[1], x2a));
|
||||
if (x1a > x2a)
|
||||
{
|
||||
QWORD tmp = x1a;
|
||||
x1a = x2a;
|
||||
x2a = tmp;
|
||||
}
|
||||
|
||||
if ((y1 ^ y2) & 1)
|
||||
{
|
||||
QWORD tmp = x1a;
|
||||
x1a = x2a;
|
||||
x2a = tmp;
|
||||
}
|
||||
|
||||
e.qword[0] = residue->__umul128(MOD + 1, x1a, &e.qword[1]);
|
||||
e.qword[0] += x2a;
|
||||
e.qword[1] += (e.qword[0] < x2a);
|
||||
}
|
||||
}
|
||||
|
||||
BYTE decimal[35];
|
||||
for (i = 0; i < 35; i++)
|
||||
{
|
||||
unsigned c = e.byte[3] % 10;
|
||||
e.byte[3] /= 10;
|
||||
|
||||
unsigned c2 = ((QWORD)c << 32 | e.byte[2]) % 10;
|
||||
e.byte[2] = ((QWORD)c << 32 | e.byte[2]) / 10;
|
||||
|
||||
unsigned c3 = ((QWORD)c2 << 32 | e.byte[1]) % 10;
|
||||
e.byte[1] = ((QWORD)c2 << 32 | e.byte[1]) / 10;
|
||||
|
||||
unsigned c4 = ((QWORD)c3 << 32 | e.byte[0]) % 10;
|
||||
e.byte[0] = ((QWORD)c3 << 32 | e.byte[0]) / 10;
|
||||
|
||||
decimal[34 - i] = c4;
|
||||
}
|
||||
|
||||
assert(e.byte[0] == 0 && e.byte[1] == 0 && e.byte[2] == 0 && e.byte[3] == 0);
|
||||
|
||||
char *q = &confirmationIDOut[0];
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
if (i)
|
||||
{
|
||||
*q++ = '-';
|
||||
}
|
||||
|
||||
unsigned char *p = decimal + i * 5;
|
||||
q[0] = p[0] + '0';
|
||||
q[1] = p[1] + '0';
|
||||
q[2] = p[2] + '0';
|
||||
q[3] = p[3] + '0';
|
||||
q[4] = p[4] + '0';
|
||||
q[5] = ((p[0] + p[1] * 2 + p[2] + p[3] * 2 + p[4]) % 7) + '0';
|
||||
q += 6;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
157
src/libumskt/confid/confid.h
Normal file
157
src/libumskt/confid/confid.h
Normal file
@ -0,0 +1,157 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_CONFID_H
|
||||
#define UMSKT_CONFID_H
|
||||
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
// Confirmation ID generator constants
|
||||
enum CONFIRMATION_ID_STATUS
|
||||
{
|
||||
SUCCESS = 0,
|
||||
ERR_TOO_SHORT = 1,
|
||||
ERR_TOO_LARGE = 2,
|
||||
ERR_INVALID_CHARACTER = 3,
|
||||
ERR_INVALID_CHECK_DIGIT = 4,
|
||||
ERR_UNKNOWN_VERSION = 5,
|
||||
ERR_UNLUCKY = 6
|
||||
};
|
||||
|
||||
#define BAD 0xFFFFFFFFFFFFFFFFull
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Q_OWORD u, v;
|
||||
} TDivisor;
|
||||
|
||||
class EXPORT ConfirmationID : public UMSKT
|
||||
{
|
||||
QWORD MOD = 0, NON_RESIDUE = 0;
|
||||
QWORD curve[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
Q_OWORD privateKey;
|
||||
|
||||
BYTE iid_key[4] = {0x0, 0x0, 0x0, 0x0};
|
||||
BOOL isOffice = false, isXPBrand = false;
|
||||
unsigned flagVersion = 0;
|
||||
|
||||
DWORD32 calculateCheckDigit(DWORD32 pid);
|
||||
void decode_iid_new_version(BYTE *iid, BYTE *hwid, DWORD32 *version);
|
||||
void Mix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize);
|
||||
void Unmix(BYTE *buffer, BYTE bufSize, const BYTE *key, BYTE keySize);
|
||||
|
||||
class Divisor
|
||||
{
|
||||
ConfirmationID *parent;
|
||||
|
||||
public:
|
||||
explicit Divisor(ConfirmationID *p)
|
||||
{
|
||||
parent = p;
|
||||
}
|
||||
|
||||
int find_divisor_v(TDivisor *d);
|
||||
void add(const TDivisor *src1, const TDivisor *src2, TDivisor *dst);
|
||||
void mul(const TDivisor *src, QWORD mult, TDivisor *dst);
|
||||
void mul128(const TDivisor *src, QWORD mult_lo, QWORD mult_hi, TDivisor *dst);
|
||||
int u2poly(const TDivisor *src, QWORD polyu[3], QWORD polyv[2]);
|
||||
};
|
||||
friend class Divisor;
|
||||
|
||||
class Residue
|
||||
{
|
||||
ConfirmationID *parent;
|
||||
|
||||
public:
|
||||
explicit Residue(ConfirmationID *p)
|
||||
{
|
||||
parent = p;
|
||||
}
|
||||
|
||||
QWORD add(QWORD x, QWORD y);
|
||||
QWORD sub(QWORD x, QWORD y);
|
||||
QWORD __umul128(QWORD a, QWORD b, QWORD *hi);
|
||||
QWORD ui128_quotient_mod(QWORD lo, QWORD hi);
|
||||
QWORD mul(QWORD x, QWORD y);
|
||||
QWORD pow(QWORD x, QWORD y);
|
||||
QWORD inverse(QWORD u, QWORD v);
|
||||
QWORD inv(QWORD x);
|
||||
QWORD sqrt(QWORD what);
|
||||
};
|
||||
friend class Residue;
|
||||
|
||||
class Polynomial
|
||||
{
|
||||
ConfirmationID *parent;
|
||||
|
||||
public:
|
||||
explicit Polynomial(ConfirmationID *p)
|
||||
{
|
||||
parent = p;
|
||||
}
|
||||
|
||||
int mul(int adeg, const QWORD a[], int bdeg, const QWORD b[], int resultprevdeg, QWORD result[]);
|
||||
int div_monic(int adeg, QWORD a[], int bdeg, const QWORD b[], QWORD *quotient);
|
||||
void xgcd(int adeg, const QWORD a[3], int bdeg, const QWORD b[3], int *pgcddeg, QWORD gcd[3], int *pmult1deg,
|
||||
QWORD mult1[3], int *pmult2deg, QWORD mult2[3]);
|
||||
};
|
||||
friend class Polynomial;
|
||||
|
||||
Residue *residue;
|
||||
Polynomial *polynomial;
|
||||
Divisor *divisor;
|
||||
|
||||
public:
|
||||
ConfirmationID()
|
||||
{
|
||||
residue = new Residue(this);
|
||||
polynomial = new Polynomial(this);
|
||||
divisor = new Divisor(this);
|
||||
}
|
||||
|
||||
BOOL LoadHyperellipticCurve(const std::string *f, const std::string &priv, const std::string &modulus,
|
||||
const std::string &nonresidue, const std::string &iidkey, BOOL isOffice, BOOL isXPBrand,
|
||||
BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(const std::string &x0, const std::string &x1, const std::string &x2,
|
||||
const std::string &x3, const std::string &x4, const std::string &x5,
|
||||
const std::string &priv, const std::string &modulus, const std::string &nonresidue,
|
||||
const std::string &iidkey, BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(QWORD x0, QWORD x1, QWORD x2, QWORD x3, QWORD x4, QWORD x5, Q_OWORD priv, QWORD modulus,
|
||||
QWORD nonresidue, DWORD32 iidkey, BOOL isOffice, BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
BOOL LoadHyperellipticCurve(QWORD *f, Q_OWORD priv, QWORD modulus, QWORD nonresidue, DWORD32 iidkey, BOOL isOffice,
|
||||
BOOL isXPBrand, BYTE flagVersion);
|
||||
|
||||
CONFIRMATION_ID_STATUS Generate(const std::string &installation_id_str, std::string &confirmation_id,
|
||||
std::string &productid);
|
||||
|
||||
~ConfirmationID()
|
||||
{
|
||||
delete residue;
|
||||
delete polynomial;
|
||||
delete divisor;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UMSKT_CONFID_H
|
55
src/libumskt/confid/confid_unittest.cpp
Normal file
55
src/libumskt/confid/confid_unittest.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/20/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* ConfirmationID must not be an abstract class.
|
||||
*/
|
||||
TEST(TestConfirmationID, InstantiateConfirmationID)
|
||||
{
|
||||
auto p3 = new ConfirmationID();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestConfirmationID : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
ConfirmationID *cid;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
cid = new ConfirmationID();
|
||||
cid->LoadHyperellipticCurve()
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (cid != nullptr)
|
||||
{
|
||||
delete cid;
|
||||
cid = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
397
src/libumskt/confid/divisor.cpp
Normal file
397
src/libumskt/confid/divisor.cpp
Normal file
@ -0,0 +1,397 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 12/05/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
int ConfirmationID::ConfirmationID::Divisor::find_divisor_v(TDivisor *d)
|
||||
{
|
||||
// u | v^2 - curve
|
||||
// u = u0 + u1*x + x^2
|
||||
// curve%u = f0 + f1*x
|
||||
QWORD v1, f2[6];
|
||||
|
||||
for (BYTE i = 0; i < 6; i++)
|
||||
{
|
||||
f2[i] = parent->curve[i];
|
||||
}
|
||||
|
||||
const QWORD u0 = d->u.qword[0], u1 = d->u.qword[1];
|
||||
for (BYTE j = 4; j--;)
|
||||
{
|
||||
f2[j] = parent->residue->sub(f2[j], parent->residue->mul(u0, f2[j + 2]));
|
||||
f2[j + 1] = parent->residue->sub(f2[j + 1], parent->residue->mul(u1, f2[j + 2]));
|
||||
f2[j + 2] = 0;
|
||||
}
|
||||
|
||||
// v = v0 + v1*x
|
||||
// u | (v0^2 - f0) + (2*v0*v1 - f1)*x + v1^2*x^2 = u0*v1^2 + u1*v1^2*x + v1^2*x^2
|
||||
// v0^2 - f0 = u0*v1^2
|
||||
// 2*v0*v1 - f1 = u1*v1^2
|
||||
// v0^2 = f0 + u0*v1^2 = (f1 + u1*v1^2)^2 / (2*v1)^2
|
||||
// (f1^2) + 2*(f1*u1-2*f0) * v1^2 + (u1^2-4*u0) * v1^4 = 0
|
||||
// v1^2 = ((2*f0-f1*u1) +- 2*sqrt(-f0*f1*u1 + f0^2 + f1^2*u0))) / (u1^2-4*u0)
|
||||
const QWORD f0 = f2[0], f1 = f2[1];
|
||||
const QWORD u0double = parent->residue->add(u0, u0);
|
||||
const QWORD coeff2 = parent->residue->sub(parent->residue->mul(u1, u1), parent->residue->add(u0double, u0double));
|
||||
const QWORD coeff1 = parent->residue->sub(parent->residue->add(f0, f0), parent->residue->mul(f1, u1));
|
||||
|
||||
if (coeff2 == 0)
|
||||
{
|
||||
if (coeff1 == 0)
|
||||
{
|
||||
if (f1 == 0)
|
||||
{
|
||||
// impossible
|
||||
// printf("bad curve(), double root detected\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
QWORD sqr = parent->residue->mul(parent->residue->mul(f1, f1),
|
||||
parent->residue->inv(parent->residue->add(coeff1, coeff1)));
|
||||
v1 = parent->residue->sqrt(sqr);
|
||||
if (v1 == BAD)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QWORD d = parent->residue->add(
|
||||
parent->residue->mul(f0, f0),
|
||||
parent->residue->mul(f1, parent->residue->sub(parent->residue->mul(f1, u0), parent->residue->mul(f0, u1))));
|
||||
d = parent->residue->sqrt(d);
|
||||
if (d == BAD)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
d = parent->residue->add(d, d);
|
||||
QWORD inv = parent->residue->inv(coeff2);
|
||||
QWORD root = parent->residue->mul(parent->residue->add(coeff1, d), inv);
|
||||
v1 = parent->residue->sqrt(root);
|
||||
if (v1 == BAD)
|
||||
{
|
||||
root = parent->residue->mul(parent->residue->sub(coeff1, d), inv);
|
||||
v1 = parent->residue->sqrt(root);
|
||||
if (v1 == BAD)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWORD v0 = parent->residue->mul(parent->residue->add(f1, parent->residue->mul(u1, parent->residue->mul(v1, v1))),
|
||||
parent->residue->inv(parent->residue->add(v1, v1)));
|
||||
d->v.qword[0] = v0;
|
||||
d->v.qword[1] = v1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param polyu
|
||||
* @param polyv
|
||||
* @return
|
||||
*/
|
||||
int ConfirmationID::ConfirmationID::Divisor::u2poly(const TDivisor *src, QWORD polyu[3], QWORD polyv[2])
|
||||
{
|
||||
if (src->u.qword[1] != BAD)
|
||||
{
|
||||
polyu[0] = src->u.qword[0];
|
||||
polyu[1] = src->u.qword[1];
|
||||
polyu[2] = 1;
|
||||
|
||||
polyv[0] = src->v.qword[0];
|
||||
polyv[1] = src->v.qword[1];
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (src->u.qword[0] != BAD)
|
||||
{
|
||||
polyu[0] = src->u.qword[0];
|
||||
polyu[1] = 1;
|
||||
|
||||
polyv[0] = src->v.qword[0];
|
||||
polyv[1] = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
polyu[0] = 1;
|
||||
polyv[0] = 0;
|
||||
polyv[1] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src1
|
||||
* @param src2
|
||||
* @param dst
|
||||
*/
|
||||
void ConfirmationID::Divisor::add(const TDivisor *src1, const TDivisor *src2, TDivisor *dst)
|
||||
{
|
||||
QWORD u1[3], u2[3], v1[2], v2[2];
|
||||
int u1deg = u2poly(src1, u1, v1);
|
||||
int u2deg = u2poly(src2, u2, v2);
|
||||
|
||||
// extended gcd: d1 = gcd(u1, u2) = e1*u1 + e2*u2
|
||||
int d1deg, e1deg, e2deg;
|
||||
QWORD d1[3], e1[3], e2[3];
|
||||
parent->polynomial->xgcd(u1deg, u1, u2deg, u2, &d1deg, d1, &e1deg, e1, &e2deg, e2);
|
||||
assert(e1deg <= 1);
|
||||
assert(e2deg <= 1);
|
||||
|
||||
// extended gcd again: d = gcd(d1, v1+v2) = c1*d1 + c2*(v1+v2)
|
||||
QWORD b[3] = {parent->residue->add(v1[0], v2[0]), parent->residue->add(v1[1], v2[1]), 0};
|
||||
int bdeg = (b[1] == 0 ? (b[0] == 0 ? -1 : 0) : 1);
|
||||
int ddeg, c1deg, c2deg;
|
||||
QWORD d[3], c1[3], c2[3];
|
||||
parent->polynomial->xgcd(d1deg, d1, bdeg, b, &ddeg, d, &c1deg, c1, &c2deg, c2);
|
||||
assert(c1deg <= 0);
|
||||
assert(c2deg <= 1);
|
||||
assert(ddeg >= 0);
|
||||
QWORD dmult = parent->residue->inv(d[ddeg]);
|
||||
int i;
|
||||
for (i = 0; i < ddeg; i++)
|
||||
{
|
||||
d[i] = parent->residue->mul(d[i], dmult);
|
||||
}
|
||||
|
||||
d[i] = 1;
|
||||
for (i = 0; i <= c1deg; i++)
|
||||
{
|
||||
c1[i] = parent->residue->mul(c1[i], dmult);
|
||||
}
|
||||
|
||||
for (i = 0; i <= c2deg; i++)
|
||||
{
|
||||
c2[i] = parent->residue->mul(c2[i], dmult);
|
||||
}
|
||||
|
||||
QWORD u[5];
|
||||
int udeg = parent->polynomial->mul(u1deg, u1, u2deg, u2, -1, u);
|
||||
// u is monic
|
||||
|
||||
QWORD v[7], tmp[7];
|
||||
int vdeg, tmpdeg;
|
||||
// c1*(e1*u1*v2 + e2*u2*v1) + c2*(v1*v2 + curve)
|
||||
// c1*(e1*u1*(v2-v1) + d1*v1) + c2*(v1*v2 + curve)
|
||||
v[0] = parent->residue->sub(v2[0], v1[0]);
|
||||
v[1] = parent->residue->sub(v2[1], v1[1]);
|
||||
tmpdeg = parent->polynomial->mul(e1deg, e1, 1, v, -1, tmp);
|
||||
vdeg = parent->polynomial->mul(u1deg, u1, tmpdeg, tmp, -1, v);
|
||||
vdeg = parent->polynomial->mul(d1deg, d1, 1, v1, vdeg, v);
|
||||
|
||||
for (i = 0; i <= vdeg; i++)
|
||||
{
|
||||
v[i] = parent->residue->mul(v[i], c1[0]);
|
||||
}
|
||||
|
||||
memcpy(tmp, parent->curve, 6 * sizeof(parent->curve[0]));
|
||||
tmpdeg = 5;
|
||||
tmpdeg = parent->polynomial->mul(1, v1, 1, v2, tmpdeg, tmp);
|
||||
vdeg = parent->polynomial->mul(c2deg, c2, tmpdeg, tmp, vdeg, v);
|
||||
|
||||
if (ddeg > 0)
|
||||
{
|
||||
assert(udeg >= 2 * ddeg);
|
||||
QWORD udiv[5];
|
||||
parent->polynomial->div_monic(udeg, u, ddeg, d, udiv);
|
||||
udeg -= ddeg;
|
||||
parent->polynomial->div_monic(udeg, udiv, ddeg, d, u);
|
||||
udeg -= ddeg;
|
||||
if (vdeg >= 0)
|
||||
{
|
||||
assert(vdeg >= ddeg);
|
||||
parent->polynomial->div_monic(vdeg, v, ddeg, d, udiv);
|
||||
vdeg -= ddeg;
|
||||
memcpy(v, udiv, (vdeg + 1) * sizeof(v[0]));
|
||||
}
|
||||
}
|
||||
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, nullptr);
|
||||
|
||||
while (udeg > 2)
|
||||
{
|
||||
assert(udeg <= 4);
|
||||
assert(vdeg <= 3);
|
||||
// u' = monic((curve-v^2)/u), v'=-v mod u'
|
||||
tmpdeg = parent->polynomial->mul(vdeg, v, vdeg, v, -1, tmp);
|
||||
for (i = 0; i <= tmpdeg && i <= 5; i++)
|
||||
{
|
||||
tmp[i] = parent->residue->sub(parent->curve[i], tmp[i]);
|
||||
}
|
||||
|
||||
for (; i <= tmpdeg; i++)
|
||||
{
|
||||
tmp[i] = parent->residue->sub(0, tmp[i]);
|
||||
}
|
||||
|
||||
for (; i <= 5; i++)
|
||||
{
|
||||
tmp[i] = parent->curve[i];
|
||||
}
|
||||
|
||||
tmpdeg = i - 1;
|
||||
QWORD udiv[5];
|
||||
parent->polynomial->div_monic(tmpdeg, tmp, udeg, u, udiv);
|
||||
|
||||
udeg = tmpdeg - udeg;
|
||||
QWORD mult = parent->residue->inv(udiv[udeg]);
|
||||
|
||||
for (i = 0; i < udeg; i++)
|
||||
{
|
||||
u[i] = parent->residue->mul(udiv[i], mult);
|
||||
}
|
||||
|
||||
u[i] = 1;
|
||||
|
||||
for (i = 0; i <= vdeg; i++)
|
||||
{
|
||||
v[i] = parent->residue->sub(0, v[i]);
|
||||
}
|
||||
|
||||
vdeg = parent->polynomial->div_monic(vdeg, v, udeg, u, nullptr);
|
||||
}
|
||||
|
||||
if (udeg == 2)
|
||||
{
|
||||
dst->u.qword[0] = u[0];
|
||||
dst->u.qword[1] = u[1];
|
||||
dst->v.qword[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v.qword[1] = (vdeg >= 1 ? v[1] : 0);
|
||||
}
|
||||
else if (udeg == 1)
|
||||
{
|
||||
dst->u.qword[0] = u[0];
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = (vdeg >= 0 ? v[0] : 0);
|
||||
dst->v.qword[1] = BAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(udeg == 0);
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
}
|
||||
}
|
||||
|
||||
#define divisor_double(src, dst) add(src, src, dst)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param mult
|
||||
* @param dst
|
||||
*/
|
||||
void ConfirmationID::Divisor::mul(const TDivisor *src, QWORD mult, TDivisor *dst)
|
||||
{
|
||||
if (mult == 0)
|
||||
{
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
return;
|
||||
}
|
||||
|
||||
TDivisor cur = *src;
|
||||
while (!(mult & 1))
|
||||
{
|
||||
divisor_double(&cur, &cur);
|
||||
mult >>= 1;
|
||||
}
|
||||
|
||||
*dst = cur;
|
||||
while ((mult >>= 1) != 0)
|
||||
{
|
||||
divisor_double(&cur, &cur);
|
||||
if (mult & 1)
|
||||
{
|
||||
add(dst, &cur, dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param mult_lo
|
||||
* @param mult_hi
|
||||
* @param dst
|
||||
*/
|
||||
void ConfirmationID::Divisor::mul128(const TDivisor *src, QWORD mult_lo, QWORD mult_hi, TDivisor *dst)
|
||||
{
|
||||
if (mult_lo == 0 && mult_hi == 0)
|
||||
{
|
||||
dst->u.qword[0] = BAD;
|
||||
dst->u.qword[1] = BAD;
|
||||
dst->v.qword[0] = BAD;
|
||||
dst->v.qword[1] = BAD;
|
||||
return;
|
||||
}
|
||||
|
||||
TDivisor cur = *src;
|
||||
while (!(mult_lo & 1))
|
||||
{
|
||||
divisor_double(&cur, &cur);
|
||||
mult_lo >>= 1;
|
||||
if (mult_hi & 1)
|
||||
{
|
||||
mult_lo |= (1ULL << 63);
|
||||
}
|
||||
mult_hi >>= 1;
|
||||
}
|
||||
|
||||
*dst = cur;
|
||||
for (;;)
|
||||
{
|
||||
mult_lo >>= 1;
|
||||
if (mult_hi & 1)
|
||||
{
|
||||
mult_lo |= (1ULL << 63);
|
||||
}
|
||||
|
||||
mult_hi >>= 1;
|
||||
if (mult_lo == 0 && mult_hi == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
divisor_double(&cur, &cur);
|
||||
if (mult_lo & 1)
|
||||
{
|
||||
add(dst, &cur, dst);
|
||||
}
|
||||
}
|
||||
}
|
261
src/libumskt/confid/polynomial.cpp
Normal file
261
src/libumskt/confid/polynomial.cpp
Normal file
@ -0,0 +1,261 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 12/05/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
|
||||
/**
|
||||
* generic short slow code
|
||||
*
|
||||
* @param adeg
|
||||
* @param a
|
||||
* @param bdeg
|
||||
* @param b
|
||||
* @param resultprevdeg
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
int ConfirmationID::Polynomial::mul(int adeg, const QWORD a[], int bdeg, const QWORD b[], int resultprevdeg,
|
||||
QWORD result[])
|
||||
{
|
||||
if (adeg < 0 || bdeg < 0)
|
||||
{
|
||||
return resultprevdeg;
|
||||
}
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = resultprevdeg + 1; i <= adeg + bdeg; i++)
|
||||
{
|
||||
result[i] = 0;
|
||||
}
|
||||
|
||||
resultprevdeg = i - 1;
|
||||
|
||||
for (i = 0; i <= adeg; i++)
|
||||
{
|
||||
for (j = 0; j <= bdeg; j++)
|
||||
{
|
||||
result[i + j] = parent->residue->add(result[i + j], parent->residue->mul(a[i], b[j]));
|
||||
}
|
||||
}
|
||||
|
||||
while (resultprevdeg >= 0 && result[resultprevdeg] == 0)
|
||||
{
|
||||
--resultprevdeg;
|
||||
}
|
||||
|
||||
return resultprevdeg;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param adeg
|
||||
* @param a
|
||||
* @param bdeg
|
||||
* @param b
|
||||
* @param quotient
|
||||
* @return
|
||||
*/
|
||||
int ConfirmationID::Polynomial::div_monic(int adeg, QWORD a[], int bdeg, const QWORD b[], QWORD *quotient)
|
||||
{
|
||||
assert(bdeg >= 0);
|
||||
assert(b[bdeg] == 1);
|
||||
int i, j;
|
||||
|
||||
for (i = adeg - bdeg; i >= 0; i--)
|
||||
{
|
||||
QWORD q = a[i + bdeg];
|
||||
if (quotient)
|
||||
{
|
||||
quotient[i] = q;
|
||||
}
|
||||
for (j = 0; j < bdeg; j++)
|
||||
{
|
||||
a[i + j] = parent->residue->sub(a[i + j], parent->residue->mul(q, b[j]));
|
||||
}
|
||||
a[i + j] = 0;
|
||||
}
|
||||
|
||||
i += bdeg;
|
||||
while (i >= 0 && a[i] == 0)
|
||||
{
|
||||
i--;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param adeg
|
||||
* @param a
|
||||
* @param bdeg
|
||||
* @param b
|
||||
* @param pgcddeg
|
||||
* @param gcd
|
||||
* @param pmult1deg
|
||||
* @param mult1
|
||||
* @param pmult2deg
|
||||
* @param mult2
|
||||
*/
|
||||
void ConfirmationID::Polynomial::xgcd(int adeg, const QWORD a[3], int bdeg, const QWORD b[3], int *pgcddeg,
|
||||
QWORD gcd[3], int *pmult1deg, QWORD mult1[3], int *pmult2deg, QWORD mult2[3])
|
||||
{
|
||||
int sdeg = -1;
|
||||
QWORD s[3] = {0, 0, 0};
|
||||
|
||||
int mult1deg = 0;
|
||||
mult1[0] = 1;
|
||||
mult1[1] = 0;
|
||||
mult1[2] = 0;
|
||||
|
||||
int tdeg = 0;
|
||||
QWORD t[3] = {1, 0, 0};
|
||||
|
||||
int mult2deg = -1;
|
||||
mult2[0] = 0;
|
||||
mult2[1] = 0;
|
||||
mult2[2] = 0;
|
||||
|
||||
int rdeg = bdeg;
|
||||
QWORD r[3] = {b[0], b[1], b[2]};
|
||||
|
||||
int gcddeg = adeg;
|
||||
gcd[0] = a[0];
|
||||
gcd[1] = a[1];
|
||||
gcd[2] = a[2];
|
||||
// s*u1 + t*u2 = r
|
||||
// mult1*u1 + mult2*u2 = gcd
|
||||
|
||||
while (rdeg >= 0)
|
||||
{
|
||||
if (rdeg > gcddeg)
|
||||
{
|
||||
unsigned tmp;
|
||||
int tmpi;
|
||||
|
||||
tmp = rdeg;
|
||||
rdeg = gcddeg;
|
||||
gcddeg = tmp;
|
||||
|
||||
tmpi = sdeg;
|
||||
sdeg = mult1deg;
|
||||
mult1deg = tmpi;
|
||||
|
||||
tmpi = tdeg;
|
||||
tdeg = mult2deg;
|
||||
mult2deg = tmpi;
|
||||
|
||||
QWORD tmp2;
|
||||
tmp2 = r[0];
|
||||
r[0] = gcd[0];
|
||||
gcd[0] = tmp2;
|
||||
|
||||
tmp2 = r[1];
|
||||
r[1] = gcd[1];
|
||||
gcd[1] = tmp2;
|
||||
|
||||
tmp2 = r[2];
|
||||
r[2] = gcd[2];
|
||||
gcd[2] = tmp2;
|
||||
|
||||
tmp2 = s[0];
|
||||
s[0] = mult1[0];
|
||||
mult1[0] = tmp2;
|
||||
|
||||
tmp2 = s[1];
|
||||
s[1] = mult1[1];
|
||||
mult1[1] = tmp2;
|
||||
|
||||
tmp2 = s[2];
|
||||
s[2] = mult1[2];
|
||||
mult1[2] = tmp2;
|
||||
|
||||
tmp2 = t[0];
|
||||
t[0] = mult2[0];
|
||||
mult2[0] = tmp2;
|
||||
|
||||
tmp2 = t[1];
|
||||
t[1] = mult2[1];
|
||||
mult2[1] = tmp2;
|
||||
|
||||
tmp2 = t[2];
|
||||
t[2] = mult2[2];
|
||||
mult2[2] = tmp2;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
int delta = gcddeg - rdeg;
|
||||
QWORD mult = parent->residue->mul(gcd[gcddeg], parent->residue->inv(r[rdeg]));
|
||||
// quotient = mult * x**delta
|
||||
|
||||
assert(rdeg + delta < 3);
|
||||
for (int i = 0; i <= rdeg; i++)
|
||||
{
|
||||
gcd[i + delta] = parent->residue->sub(gcd[i + delta], parent->residue->mul(mult, r[i]));
|
||||
}
|
||||
|
||||
while (gcddeg >= 0 && gcd[gcddeg] == 0)
|
||||
{
|
||||
gcddeg--;
|
||||
}
|
||||
assert(sdeg + delta < 3);
|
||||
|
||||
for (int i = 0; i <= sdeg; i++)
|
||||
{
|
||||
mult1[i + delta] = parent->residue->sub(mult1[i + delta], parent->residue->mul(mult, s[i]));
|
||||
}
|
||||
|
||||
if (mult1deg < sdeg + delta)
|
||||
{
|
||||
mult1deg = sdeg + delta;
|
||||
}
|
||||
|
||||
while (mult1deg >= 0 && mult1[mult1deg] == 0)
|
||||
{
|
||||
mult1deg--;
|
||||
}
|
||||
|
||||
assert(tdeg + delta < 3);
|
||||
|
||||
for (int i = 0; i <= tdeg; i++)
|
||||
{
|
||||
mult2[i + delta] = parent->residue->sub(mult2[i + delta], parent->residue->mul(mult, t[i]));
|
||||
}
|
||||
|
||||
if (mult2deg < tdeg + delta)
|
||||
{
|
||||
mult2deg = tdeg + delta;
|
||||
}
|
||||
|
||||
while (mult2deg >= 0 && mult2[mult2deg] == 0)
|
||||
{
|
||||
mult2deg--;
|
||||
}
|
||||
}
|
||||
|
||||
// d1 = gcd, e1 = mult1, e2 = mult2
|
||||
*pgcddeg = gcddeg;
|
||||
*pmult1deg = mult1deg;
|
||||
*pmult2deg = mult2deg;
|
||||
}
|
279
src/libumskt/confid/residue.cpp
Normal file
279
src/libumskt/confid/residue.cpp
Normal file
@ -0,0 +1,279 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 12/05/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "confid.h"
|
||||
|
||||
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || (defined(__arm64__) && defined(__APPLE__))
|
||||
#ifdef __GNUC__
|
||||
QWORD ConfirmationID::Residue::__umul128(QWORD multiplier, QWORD multiplicand, QWORD *product_hi)
|
||||
{
|
||||
OWORD r = (OWORD)multiplier * (OWORD)multiplicand;
|
||||
*product_hi = r >> 64;
|
||||
return (QWORD)r;
|
||||
}
|
||||
#else // basically msvc
|
||||
/**
|
||||
*
|
||||
* @param multiplier
|
||||
* @param multiplicand
|
||||
* @param product_hi
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::__umul128(QWORD multiplier, QWORD multiplicand, QWORD *product_hi)
|
||||
{
|
||||
return _umul128(multiplier, multiplicand, product_hi);
|
||||
}
|
||||
#endif
|
||||
#elif defined(__i386__) || defined(_M_IX86) || defined(__arm__) || defined(__EMSCRIPTEN__)
|
||||
QWORD ConfirmationID::Residue::__umul128(QWORD multiplier, QWORD multiplicand, QWORD *product_hi)
|
||||
{
|
||||
// multiplier = ab = a * 2^32 + b
|
||||
// multiplicand = cd = c * 2^32 + d
|
||||
// ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
|
||||
QWORD a = multiplier >> 32;
|
||||
QWORD b = multiplier & 0xFFFFFFFF;
|
||||
QWORD c = multiplicand >> 32;
|
||||
QWORD d = multiplicand & 0xFFFFFFFF;
|
||||
|
||||
// QWORD ac = a * c;
|
||||
QWORD ad = a * d;
|
||||
// QWORD bc = b * c;
|
||||
QWORD bd = b * d;
|
||||
|
||||
QWORD adbc = ad + (b * c);
|
||||
QWORD adbc_carry = adbc < ad ? 1 : 0;
|
||||
|
||||
// multiplier * multiplicand = product_hi * 2^64 + product_lo
|
||||
QWORD product_lo = bd + (adbc << 32);
|
||||
QWORD product_lo_carry = product_lo < bd ? 1 : 0;
|
||||
*product_hi = (a * c) + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
|
||||
|
||||
return product_lo;
|
||||
}
|
||||
#else
|
||||
#error Unknown architecture detected - please edit confid.cpp to tailor __umul128() your architecture
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lo
|
||||
* @param hi
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::ui128_quotient_mod(QWORD lo, QWORD hi)
|
||||
{
|
||||
// hi:lo * ceil(2**170/MOD) >> (64 + 64 + 42)
|
||||
QWORD prod1;
|
||||
__umul128(lo, parent->privateKey.qword[0], &prod1);
|
||||
|
||||
QWORD part1hi, part1lo = __umul128(lo, parent->privateKey.qword[1], &part1hi);
|
||||
QWORD part2hi, part2lo = __umul128(hi, parent->privateKey.qword[0], &part2hi);
|
||||
|
||||
QWORD sum1 = part1lo + part2lo;
|
||||
unsigned sum1carry = (sum1 < part1lo);
|
||||
sum1 += prod1;
|
||||
sum1carry += (sum1 < prod1);
|
||||
QWORD prod2 = part1hi + part2hi + sum1carry;
|
||||
|
||||
QWORD prod3hi, prod3lo = __umul128(hi, parent->privateKey.qword[1], &prod3hi);
|
||||
|
||||
prod3lo += prod2;
|
||||
prod3hi += (prod3lo < prod2);
|
||||
return (prod3lo >> 42) | (prod3hi << 22);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::mul(QWORD x, QWORD y)
|
||||
{
|
||||
// * ceil(2**170/MOD) = 0x2d351 c6d04f8b|604fa6a1 c6346a87 for (p-1)*(p-1) max
|
||||
QWORD hi, lo = __umul128(x, y, &hi);
|
||||
QWORD quotient = ui128_quotient_mod(lo, hi);
|
||||
return lo - quotient * parent->MOD;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::pow(QWORD x, QWORD y)
|
||||
{
|
||||
if (y == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QWORD cur = x;
|
||||
while (!(y & 1))
|
||||
{
|
||||
cur = mul(cur, cur);
|
||||
y >>= 1;
|
||||
}
|
||||
|
||||
QWORD res = cur;
|
||||
while ((y >>= 1) != 0)
|
||||
{
|
||||
cur = mul(cur, cur);
|
||||
if (y & 1)
|
||||
{
|
||||
res = mul(res, cur);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::add(QWORD x, QWORD y)
|
||||
{
|
||||
QWORD z = x + y;
|
||||
// z = z - (z >= MOD ? MOD : 0);
|
||||
if (z >= parent->MOD)
|
||||
{
|
||||
z -= parent->MOD;
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::sub(QWORD x, QWORD y)
|
||||
{
|
||||
QWORD z = x - y;
|
||||
// z += (x < y ? MOD : 0);
|
||||
if (x < y)
|
||||
{
|
||||
z += parent->MOD;
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param u
|
||||
* @param v
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::inverse(QWORD u, QWORD v)
|
||||
{
|
||||
// assert(u);
|
||||
int64_t tmp;
|
||||
int64_t xu = 1, xv = 0;
|
||||
QWORD v0 = v;
|
||||
while (u > 1)
|
||||
{
|
||||
QWORD d = v / u;
|
||||
QWORD remainder = v % u;
|
||||
tmp = u;
|
||||
u = remainder;
|
||||
v = tmp;
|
||||
tmp = xu;
|
||||
xu = xv - d * xu;
|
||||
xv = tmp;
|
||||
}
|
||||
xu += (xu < 0 ? v0 : 0);
|
||||
return xu;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::inv(QWORD x)
|
||||
{
|
||||
return inverse(x, parent->MOD);
|
||||
// return residue_pow(x, MOD - 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param what
|
||||
* @return
|
||||
*/
|
||||
QWORD ConfirmationID::Residue::sqrt(QWORD what)
|
||||
{
|
||||
if (!what)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QWORD g = parent->NON_RESIDUE, z, y, r, x, b, t;
|
||||
QWORD e = 0, q = parent->MOD - 1;
|
||||
|
||||
while (!(q & 1))
|
||||
{
|
||||
e++, q >>= 1;
|
||||
}
|
||||
|
||||
z = pow(g, q);
|
||||
y = z;
|
||||
r = e;
|
||||
x = pow(what, (q - 1) / 2);
|
||||
b = mul(mul(what, x), x);
|
||||
x = mul(what, x);
|
||||
|
||||
while (b != 1)
|
||||
{
|
||||
QWORD m = 0, b2 = b;
|
||||
|
||||
do
|
||||
{
|
||||
m++;
|
||||
b2 = mul(b2, b2);
|
||||
} while (b2 != 1);
|
||||
|
||||
if (m == r)
|
||||
{
|
||||
return BAD;
|
||||
}
|
||||
|
||||
t = pow(y, 1 << (r - m - 1));
|
||||
y = mul(t, t);
|
||||
r = m;
|
||||
x = mul(x, t);
|
||||
b = mul(b, y);
|
||||
}
|
||||
|
||||
if (mul(x, x) != what)
|
||||
{
|
||||
// printf("internal error in sqrt\n");
|
||||
return BAD;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
64
src/libumskt/init.cpp
Normal file
64
src/libumskt/init.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/25/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
std::FILE *UMSKT::debug;
|
||||
std::FILE *UMSKT::verbose;
|
||||
|
||||
BOOL UMSKT::IS_CONSTRUCTED = UMSKT::CONSTRUCT();
|
||||
|
||||
/**
|
||||
* a static "constructor" that does some housekeeping for certain
|
||||
* platforms, in DJGPP for instance we need to setup the interval
|
||||
* timer for RNG.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
BOOL UMSKT::CONSTRUCT()
|
||||
{
|
||||
#ifdef __DJGPP__
|
||||
// this should be set up as early as possible
|
||||
uclock();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the filestream used for debugging
|
||||
*
|
||||
* @param input std::FILE
|
||||
*/
|
||||
void UMSKT::setDebugOutput(std::FILE *input)
|
||||
{
|
||||
debug = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the filestream used for verbose messages
|
||||
*
|
||||
* @param input std::FILE
|
||||
*/
|
||||
void UMSKT::setVerboseOutput(std::FILE *input)
|
||||
{
|
||||
verbose = input;
|
||||
}
|
247
src/libumskt/libumskt.cpp
Normal file
247
src/libumskt/libumskt.cpp
Normal file
@ -0,0 +1,247 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/25/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include <libumskt/confid/confid.h>
|
||||
#include <libumskt/libumskt.h>
|
||||
#include <libumskt/pidgen2/PIDGEN2.h>
|
||||
#include <libumskt/pidgen3/BINK1998.h>
|
||||
#include <libumskt/pidgen3/BINK2002.h>
|
||||
#include <libumskt/pidgen3/PIDGEN3.h>
|
||||
|
||||
std::map<UMSKT_TAG, UMSKT_Value> UMSKT::tags;
|
||||
CryptoPP::DefaultAutoSeededRNG UMSKT::rng;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* Sets debug output to a given C++ File stream
|
||||
* if the memory allocated at filestream is "STDOUT" or "STDERR"
|
||||
* simply use the global vars allocated by *this* C++ runtime.
|
||||
* otherwise, assume that the input pointer is an ABI equivalent std::FILE
|
||||
*
|
||||
* @param char* or std::FILE "filestream"
|
||||
*/
|
||||
EXPORT BOOL UMSKT_SET_DEBUG_OUTPUT(void *filestream)
|
||||
{
|
||||
char buffer[7];
|
||||
memcpy(buffer, filestream, 6);
|
||||
buffer[6] = 0;
|
||||
auto buffstring = std::string(buffer);
|
||||
std::transform(buffstring.begin(), buffstring.end(), buffstring.begin(), ::tolower);
|
||||
|
||||
if (buffstring == "stdout")
|
||||
{
|
||||
UMSKT::debug = stdout;
|
||||
return true;
|
||||
}
|
||||
else if (buffstring == "stderr")
|
||||
{
|
||||
UMSKT::debug = stderr;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UMSKT::debug = (std::FILE *)filestream;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tag
|
||||
* @param value
|
||||
* @param valueSize
|
||||
* @return success
|
||||
*/
|
||||
EXPORT BOOL UMSKT_SET_TAG(UMSKT_TAG tag, char *value, size_t valueSize)
|
||||
{
|
||||
if (valueSize > sizeof(UMSKT_Value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// wipe/set the tag
|
||||
memset(&UMSKT::tags[tag], 0, sizeof(UMSKT_Value));
|
||||
memcpy(&UMSKT::tags[tag], value, valueSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EXPORT void UMSKT_RESET_TAGS()
|
||||
{
|
||||
UMSKT::tags.clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
EXPORT void *CONFID_INIT()
|
||||
{
|
||||
auto cid = new ConfirmationID();
|
||||
|
||||
// cid->LoadHyperellipticCurve(0, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0);
|
||||
|
||||
return cid;
|
||||
}
|
||||
|
||||
EXPORT BYTE CONFID_GENERATE(void *cidIn, const char *installation_id_str, char *&confirmation_id, char *productid)
|
||||
{
|
||||
ConfirmationID *cid;
|
||||
try
|
||||
{
|
||||
cid = static_cast<ConfirmationID *>(cidIn);
|
||||
}
|
||||
catch (const std::bad_cast &e)
|
||||
{
|
||||
fmt::print(UMSKT::debug, "{}: input is not a {} - {}", __FUNCTION__, e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (auto const i : UMSKT::tags)
|
||||
{
|
||||
switch (i.first)
|
||||
{
|
||||
case UMSKT_tag_InstallationID:
|
||||
break;
|
||||
case UMSKT_tag_ProductID:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string str, confid(confirmation_id), productids(productid);
|
||||
auto retval = cid->Generate(str, confid, productids);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
EXPORT void CONFID_END(void *cidIn)
|
||||
{
|
||||
auto *cid((ConfirmationID *)cidIn);
|
||||
delete cid;
|
||||
cid = nullptr;
|
||||
cidIn = nullptr;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
EXPORT void *PIDGEN3_INIT(const char *binkid, const char *p, const char *a, const char *b, const char *generatorX,
|
||||
const char *generatorY, const char *publicKeyX, const char *publicKeyY,
|
||||
const char *genOrder, const char *privateKey)
|
||||
{
|
||||
PIDGEN3 *p3;
|
||||
|
||||
if (PIDGEN3::checkFieldStrIsBink1998(p))
|
||||
{
|
||||
p3 = new BINK1998();
|
||||
}
|
||||
else
|
||||
{
|
||||
p3 = new BINK2002();
|
||||
}
|
||||
|
||||
p3->LoadEllipticCurve(binkid, p, a, b, generatorX, generatorY, publicKeyX, publicKeyY, genOrder, privateKey);
|
||||
|
||||
return p3;
|
||||
}
|
||||
|
||||
EXPORT BOOL PIDGEN3_Generate(void *&ptrIn, char *&pKeyOut, int pKeySizeIn)
|
||||
{
|
||||
auto *p3((PIDGEN3 *)ptrIn);
|
||||
|
||||
for (auto const i : UMSKT::tags)
|
||||
{
|
||||
switch (i.first)
|
||||
{
|
||||
case UMSKT_tag_isUpgrade:
|
||||
p3->info.isUpgrade = i.second.boolean;
|
||||
break;
|
||||
case UMSKT_tag_ChannelID:
|
||||
p3->info.setChannelID(i.second.dword);
|
||||
break;
|
||||
case UMSKT_tag_Serial:
|
||||
p3->info.setSerial(i.second.dword);
|
||||
break;
|
||||
case UMSKT_tag_AuthData:
|
||||
p3->info.setAuthInfo(i.second.dword);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string str;
|
||||
BOOL retval = p3->Generate(str);
|
||||
|
||||
assert(pKeySizeIn >= str.length() + NULL_TERMINATOR);
|
||||
|
||||
memcpy(pKeyOut, &str[0], str.length());
|
||||
pKeyOut[str.length()] = 0;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
EXPORT BOOL PIDGEN3_Validate(void *&ptrIn, char *pKeyIn)
|
||||
{
|
||||
auto *p3((PIDGEN3 *)ptrIn);
|
||||
std::string str(pKeyIn);
|
||||
|
||||
BOOL retval = p3->Validate(str);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
EXPORT void PIDGEN3_END(void *ptrIn)
|
||||
{
|
||||
auto *p3((PIDGEN3 *)ptrIn);
|
||||
delete p3;
|
||||
ptrIn = nullptr;
|
||||
p3 = nullptr;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
EXPORT void *PIDGEN2_INIT()
|
||||
{
|
||||
auto p2 = new PIDGEN2();
|
||||
return p2;
|
||||
}
|
||||
|
||||
EXPORT BOOL PIDGEN2_GENERATE(void *ptrIn, char *&keyout)
|
||||
{
|
||||
auto p2 = (PIDGEN2 *)ptrIn;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EXPORT void PIDGEN2_END(void *ptrIn)
|
||||
{
|
||||
auto p2 = (PIDGEN2 *)ptrIn;
|
||||
delete p2;
|
||||
p2 = nullptr;
|
||||
ptrIn = nullptr;
|
||||
}
|
||||
|
||||
} // extern "C"
|
309
src/libumskt/libumskt.h
Normal file
309
src/libumskt/libumskt.h
Normal file
@ -0,0 +1,309 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/24/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_LIBUMSKT_H
|
||||
#define UMSKT_LIBUMSKT_H
|
||||
|
||||
#include <typedefs.h>
|
||||
|
||||
#ifdef __DJGPP__
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <cryptopp/cryptlib.h>
|
||||
#include <cryptopp/ecp.h>
|
||||
#include <cryptopp/integer.h>
|
||||
#include <cryptopp/misc.h>
|
||||
#include <cryptopp/nbtheory.h>
|
||||
#include <cryptopp/osrng.h>
|
||||
#include <cryptopp/sha.h>
|
||||
|
||||
using ECP = CryptoPP::ECP;
|
||||
using SHA1 = CryptoPP::SHA1;
|
||||
using Integer = CryptoPP::Integer;
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
// fmt <-> CryptoPP linkage
|
||||
template <> class fmt::formatter<Integer>
|
||||
{
|
||||
char type_ = 'd';
|
||||
|
||||
public:
|
||||
constexpr auto parse(format_parse_context &ctx)
|
||||
{
|
||||
auto i = ctx.begin(), end = ctx.end();
|
||||
|
||||
if (i != end)
|
||||
{
|
||||
switch (*i)
|
||||
{
|
||||
case 'B':
|
||||
case 'b':
|
||||
case 'o':
|
||||
case 'X':
|
||||
case 'x':
|
||||
case 'd':
|
||||
type_ = *i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != end && *i != '}')
|
||||
{
|
||||
throw format_error("invalid format");
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename FmtContext> constexpr auto format(const Integer &i, FmtContext &ctx) const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case 'B':
|
||||
case 'b':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 2));
|
||||
|
||||
case 'o':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 8));
|
||||
|
||||
case 'X':
|
||||
case 'x':
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 16));
|
||||
|
||||
case 'd':
|
||||
default:
|
||||
return format_to(ctx.out(), "{}", IntToString(i, 10));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Algorithm macros
|
||||
#define PK_LENGTH 25
|
||||
#define NULL_TERMINATOR 1
|
||||
|
||||
#define NEXTSNBITS(field, n, offset) (((QWORD)(field) >> (offset)) & ((1ULL << (n)) - 1))
|
||||
#define FIRSTNBITS(field, n) NEXTSNBITS((field), (n), 0)
|
||||
|
||||
#define HIBYTES(field, bytes) NEXTSNBITS((QWORD)(field), ((bytes) * 8), ((bytes) * 8))
|
||||
#define LOBYTES(field, bytes) FIRSTNBITS((QWORD)(field), ((bytes) * 8))
|
||||
|
||||
#define BYDWORD(n) (DWORD32)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24)
|
||||
#define BITMASK(n) ((1ULL << (n)) - 1)
|
||||
|
||||
#ifndef LIBUMSKT_VERSION_STRING
|
||||
#define LIBUMSKT_VERSION_STRING "unknown version-dirty"
|
||||
#endif
|
||||
|
||||
enum ValueType
|
||||
{
|
||||
VALUE_BOOL,
|
||||
VALUE_WORD,
|
||||
VALUE_DWORD,
|
||||
VALUE_QWORD,
|
||||
VALUE_OWORD,
|
||||
VALUE_CHARPTR
|
||||
};
|
||||
|
||||
struct UMSKT_Value
|
||||
{
|
||||
ValueType type;
|
||||
union {
|
||||
BOOL boolean;
|
||||
WORD word;
|
||||
DWORD32 dword;
|
||||
QWORD qword;
|
||||
OWORD oword;
|
||||
char *chars;
|
||||
};
|
||||
};
|
||||
|
||||
enum UMSKT_TAG
|
||||
{
|
||||
UMSKT_tag_isOEM,
|
||||
UMSKT_tag_isUpgrade,
|
||||
UMSKT_tag_Year,
|
||||
UMSKT_tag_Day,
|
||||
UMSKT_tag_OEMID,
|
||||
UMSKT_tag_AuthData,
|
||||
UMSKT_tag_Serial,
|
||||
UMSKT_tag_ChannelID,
|
||||
UMSKT_tag_InstallationID,
|
||||
UMSKT_tag_ProductID
|
||||
};
|
||||
|
||||
class EXPORT UMSKT
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Convert a std::string to an Integer
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerS(const std::string &in)
|
||||
{
|
||||
return Integer(&in[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a std::string to an Integer
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerHexS(const std::string &in)
|
||||
{
|
||||
return IntegerS("0x" + in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Native byte buffer to Integer
|
||||
*
|
||||
* @param buf
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
INLINE static Integer IntegerN(BYTE *buf, size_t size)
|
||||
{
|
||||
return {buf, size, Integer::UNSIGNED, CryptoPP::LITTLE_ENDIAN_ORDER};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Native Type T to Integer, where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static Integer IntegerN(const T &in)
|
||||
{
|
||||
return IntegerN((BYTE *)&in, sizeof(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to a Native byte buffer
|
||||
*
|
||||
* @param in
|
||||
* @param buf
|
||||
* @param buflen
|
||||
* @return
|
||||
*/
|
||||
INLINE static BYTE *EncodeN(const Integer &in, BYTE *buf, size_t buflen)
|
||||
{
|
||||
in.Encode(buf, buflen);
|
||||
std::reverse(buf, buf + buflen);
|
||||
return buf + buflen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to Native type T where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static BYTE *EncodeN(const Integer &in, T &buf)
|
||||
{
|
||||
return EncodeN(in, (BYTE *)&buf, sizeof(T));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Integer to Native type T where T is a concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @param in
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
template <typename T = DWORD32> INLINE static T EncodeN(const Integer &in)
|
||||
{
|
||||
T buf;
|
||||
EncodeN(in, (BYTE *)&buf, sizeof(T));
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a random number into a Native concrete type
|
||||
*
|
||||
* @tparam T
|
||||
* @return
|
||||
*/
|
||||
template <typename T> INLINE static T getRandom()
|
||||
{
|
||||
T retval;
|
||||
rng.GenerateBlock((BYTE *)&retval, sizeof(retval));
|
||||
return retval;
|
||||
}
|
||||
|
||||
INLINE static std::string strtolower(std::string &in)
|
||||
{
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::tolower);
|
||||
return retval;
|
||||
}
|
||||
|
||||
INLINE static std::string strtoupper(const std::string &in)
|
||||
{
|
||||
auto retval = std::string(in);
|
||||
std::transform(retval.begin(), retval.end(), retval.begin(), ::toupper);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compiled-in version information
|
||||
*
|
||||
* @return Null-Terminated C-Style string pointer
|
||||
*/
|
||||
INLINE static const std::string VERSION()
|
||||
{
|
||||
return fmt::format("LIBUMSKT {} compiled on {} {}", LIBUMSKT_VERSION_STRING, __DATE__, __TIME__);
|
||||
}
|
||||
|
||||
static std::FILE *debug;
|
||||
static std::FILE *verbose;
|
||||
static BOOL IS_CONSTRUCTED;
|
||||
static std::map<UMSKT_TAG, UMSKT_Value> tags;
|
||||
static CryptoPP::DefaultAutoSeededRNG rng;
|
||||
|
||||
static BOOL CONSTRUCT();
|
||||
|
||||
static void DESTRUCT()
|
||||
{
|
||||
if (debug != nullptr && debug != stdout && debug != stderr)
|
||||
{
|
||||
std::fclose(debug);
|
||||
debug = nullptr;
|
||||
}
|
||||
if (verbose != nullptr && verbose != stdout && debug != stderr)
|
||||
{
|
||||
std::fclose(verbose);
|
||||
verbose = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void setDebugOutput(std::FILE *input);
|
||||
static void setVerboseOutput(std::FILE *input);
|
||||
};
|
||||
|
||||
#endif // UMSKT_LIBUMSKT_H
|
39
src/libumskt/libumskt_unittest.h
Normal file
39
src/libumskt/libumskt_unittest.h
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
#ifndef UMSKT_LIBUMSKT_UNITTEST_H
|
||||
#define UMSKT_LIBUMSKT_UNITTEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libumskt/libumskt.h>
|
||||
|
||||
class libumsktUnitTests : public testing::Test
|
||||
{
|
||||
public:
|
||||
libumsktUnitTests()
|
||||
{
|
||||
// UMSKT::setVerboseOutput(stderr);
|
||||
// UMSKT::setDebugOutput(stderr);
|
||||
}
|
||||
~libumsktUnitTests() override = default;
|
||||
};
|
||||
|
||||
#endif // UMSKT_LIBUMSKT_UNITTEST_H
|
76
src/libumskt/pidgen.cpp
Normal file
76
src/libumskt/pidgen.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/13/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "pidgen.h"
|
||||
|
||||
/**
|
||||
* The number 7 in an Integer for optimization
|
||||
*/
|
||||
const Integer PIDGEN::SEVEN = Integer(7);
|
||||
|
||||
/**
|
||||
* The number 10 in an Integer for optimization
|
||||
*/
|
||||
const Integer PIDGEN::TEN = Integer(10);
|
||||
|
||||
/**
|
||||
* The maximum Channel ID size (PID 2.0/3.0) in an Integer for optimization
|
||||
* 000 - 999
|
||||
*/
|
||||
const Integer PIDGEN::MaxChannelID = Integer(1'000);
|
||||
|
||||
/**
|
||||
* The maximum serial size (PID 2.0/3.0) in an Integer for optimization
|
||||
* 000000 - 999999
|
||||
*/
|
||||
const Integer PIDGEN::MaxSerial = Integer(1'000'000);
|
||||
|
||||
/**
|
||||
* Generates a Mod7 check digit for a given Integer
|
||||
*
|
||||
* @param in Integer to generate
|
||||
* @return Mod7 check digit
|
||||
*/
|
||||
Integer PIDGEN::GenerateMod7(const Integer &in)
|
||||
{
|
||||
Integer Sum = 0, CheckNum = in;
|
||||
|
||||
while (CheckNum.NotZero())
|
||||
{
|
||||
Sum += CheckNum % TEN;
|
||||
CheckNum /= TEN;
|
||||
}
|
||||
|
||||
return SEVEN - (Sum % SEVEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the last digit (one's place) of a given Integer
|
||||
* is the expected check digit.
|
||||
*
|
||||
* @param in Integer to validate
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN::isValidMod7(const Integer &in)
|
||||
{
|
||||
return GenerateMod7(in / TEN) == (in % TEN);
|
||||
}
|
72
src/libumskt/pidgen.h
Normal file
72
src/libumskt/pidgen.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/13/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "libumskt.h"
|
||||
|
||||
#ifndef UMSKT_PIDGEN_H
|
||||
#define UMSKT_PIDGEN_H
|
||||
|
||||
/**
|
||||
* PIDGEN Interface
|
||||
*
|
||||
* Defines three entry points:
|
||||
* Generate, Validate, StringifyKey
|
||||
*/
|
||||
class PIDGEN : public UMSKT
|
||||
{
|
||||
public:
|
||||
virtual ~PIDGEN() = default;
|
||||
static const Integer SEVEN;
|
||||
static const Integer TEN;
|
||||
static const Integer MaxChannelID;
|
||||
static const Integer MaxSerial;
|
||||
|
||||
virtual BOOL Generate(std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::Generate() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual BOOL Validate(const std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::Validate() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual std::string StringifyKey(const std::string &pKey)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::StringifyKey() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual std::string StringifyProductID()
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::StringifyProductID() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual BOOL ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN::ValidateKeyString() pure virtual function call");
|
||||
}
|
||||
|
||||
Integer GenerateMod7(const Integer &in);
|
||||
BOOL isValidMod7(const Integer &in);
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN_H
|
315
src/libumskt/pidgen2/PIDGEN2.cpp
Normal file
315
src/libumskt/pidgen2/PIDGEN2.cpp
Normal file
@ -0,0 +1,315 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/17/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "PIDGEN2.h"
|
||||
|
||||
const std::vector<std::string> PIDGEN2::channelIDDisallowList = {"333", "444", "555", "666", "777", "888", "999"};
|
||||
const std::vector<std::string> PIDGEN2::validYears = {"95", "96", "97", "98", "99", "00", "01", "02"};
|
||||
|
||||
/**
|
||||
* Generates a PID 2.0 key, output is placed in pKey
|
||||
*
|
||||
* @param pKey
|
||||
* @return true
|
||||
*/
|
||||
BOOL PIDGEN2::Generate(std::string &pKey)
|
||||
{
|
||||
Integer random;
|
||||
random.Randomize(rng, sizeof(DWORD32) * 8);
|
||||
|
||||
info.ChannelID = info.ChannelID % MaxChannelID;
|
||||
info.Serial = info.Serial % MaxSerial;
|
||||
|
||||
if (info.isOEM)
|
||||
{
|
||||
info.Day = info.Day % Integer(366);
|
||||
// info.Year = info.Year;
|
||||
|
||||
info.OEMID = (info.ChannelID * TEN) + (info.Serial / (MaxSerial / TEN));
|
||||
info.Serial %= (MaxSerial / TEN);
|
||||
|
||||
info.OEMID = (info.OEMID * TEN) + GenerateMod7(info.OEMID);
|
||||
|
||||
DWORD32 day = EncodeN(info.Day), year = EncodeN(info.Year), serial = EncodeN(info.Serial),
|
||||
oemid = EncodeN(info.OEMID);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n{:03d}{:02d}-OEM-{:07d}-{:05d}\n", day, year, oemid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:03d}{:02d}{:07d}{:05d}", day, year, oemid, serial);
|
||||
}
|
||||
else if (info.isOffice)
|
||||
{
|
||||
info.ChannelID = (info.ChannelID * TEN) + ((info.ChannelID % TEN) + 1);
|
||||
info.Serial = (info.Serial * TEN) + GenerateMod7(info.Serial);
|
||||
|
||||
DWORD32 channelid = EncodeN(info.ChannelID), serial = EncodeN(info.Serial);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n{:04d}-{:07d}\n", channelid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:04d}{:07d}", channelid, serial);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.Serial = (info.Serial * TEN) + GenerateMod7(info.Serial);
|
||||
|
||||
DWORD32 channelid = EncodeN(info.ChannelID), serial = EncodeN(info.Serial);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n{:03d}-{:07d}\n", channelid, serial);
|
||||
}
|
||||
|
||||
pKey = fmt::format("{:03d}{:07d}", channelid, serial);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid serial types are:
|
||||
*
|
||||
* C = Channel/Site ID (001 - 998)
|
||||
* E = Office Channel ID (+1) Check Digit
|
||||
* N = Serial
|
||||
* K = Mod7 Check Digit
|
||||
*
|
||||
* -- OEM Specific
|
||||
* D = 3 Digit day (001 - 366)
|
||||
* Y = 2 Digit year
|
||||
* O = OEM ID - typically seen as a channel ID + the first digit of the serial + mod7 check digit
|
||||
*
|
||||
* note that the N segment for OEM serials do not have a Mod7 check
|
||||
*
|
||||
* CCC-NNNNNNK
|
||||
* CCCE-NNNNNNK
|
||||
* DDDYY-ZZOOONK-NNNNN
|
||||
* DDDYY-OEM-ZZOOONK-NNNNN
|
||||
*
|
||||
* we can determine what type of key we have
|
||||
* simply by counting the numeric characters
|
||||
*
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN2::Validate(const std::string &pKey)
|
||||
{
|
||||
std::string filtered;
|
||||
ValidateKeyString(pKey, filtered);
|
||||
|
||||
bool bIsValidChannelID, bIsValidSerial, bIsValidOEMDay, bIsValidOEMYear, bIsValidOEMID;
|
||||
|
||||
switch (filtered.length())
|
||||
{
|
||||
case KeySize::FPP:
|
||||
// standard FPP/CCP has 10 digits
|
||||
info.ChannelID = IntegerS(filtered.substr(0, 3));
|
||||
info.Serial = IntegerS(filtered.substr(3, 7));
|
||||
|
||||
bIsValidChannelID = isValidChannelID();
|
||||
bIsValidSerial = isValidSerial();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidChannelID: {} isValidSerial: {}\n", bIsValidChannelID, bIsValidSerial);
|
||||
}
|
||||
|
||||
return bIsValidChannelID && bIsValidSerial;
|
||||
|
||||
case KeySize::Office:
|
||||
// so far only office 97 has been documented using this
|
||||
info.isOffice = true;
|
||||
info.ChannelID = IntegerS(filtered.substr(0, 4));
|
||||
info.Serial = IntegerS(filtered.substr(4, 7));
|
||||
|
||||
bIsValidChannelID = isValidChannelID();
|
||||
bIsValidSerial = isValidSerial();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidChannelID: {} isValidSerial: {}\n", bIsValidChannelID, bIsValidSerial);
|
||||
}
|
||||
|
||||
return bIsValidChannelID && bIsValidSerial;
|
||||
|
||||
case KeySize::OEM:
|
||||
// all OEM keys follow this pattern
|
||||
info.isOEM = true;
|
||||
info.Day = IntegerS(filtered.substr(0, 3));
|
||||
info.Year = IntegerS(filtered.substr(3, 2));
|
||||
info.OEMID = IntegerS(filtered.substr(5, 7)); // 6 + check digit
|
||||
info.Serial = IntegerS(filtered.substr(12, 5));
|
||||
|
||||
bIsValidOEMDay = isValidOEMDay();
|
||||
bIsValidOEMYear = isValidOEMYear();
|
||||
bIsValidOEMID = isValidOEMID();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print("\n\nisValidOEMDay: {} isValidOEMYear: {} isValidOEMID: {}\n", bIsValidOEMDay, bIsValidOEMYear,
|
||||
bIsValidOEMID);
|
||||
}
|
||||
|
||||
return bIsValidOEMDay && bIsValidOEMYear && bIsValidOEMID;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
std::string PIDGEN2::StringifyKey(const std::string &pKey)
|
||||
{
|
||||
switch (pKey.length())
|
||||
{
|
||||
case KeySize::FPP:
|
||||
return fmt::format("{}-{}", pKey.substr(0, 3), pKey.substr(3, 7));
|
||||
|
||||
case KeySize::Office:
|
||||
return fmt::format("{}-{}", pKey.substr(0, 4), pKey.substr(4, 7));
|
||||
|
||||
case KeySize::OEM:
|
||||
return fmt::format("{}-OEM-{}-{}", pKey.substr(0, 5), pKey.substr(5, 7), pKey.substr(12, 5));
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
std::string PIDGEN2::StringifyProductID()
|
||||
{
|
||||
if (info.isOEM)
|
||||
{
|
||||
return fmt::format("{:d}{:d}-OEM-{:d}-{:d}", info.Year, info.Day, info.OEMID, info.Serial);
|
||||
}
|
||||
|
||||
return fmt::format("{}-{}", info.ChannelID, info.Serial);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in_key
|
||||
* @param out_key
|
||||
* @return
|
||||
*/
|
||||
BOOL INLINE PIDGEN2::ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
std::copy_if(in_key.begin(), in_key.end(), std::back_inserter(out_key), [](char c) { return std::isdigit(c); });
|
||||
|
||||
return out_key.length() == KeySize::FPP || out_key.length() == KeySize::Office || out_key.length() == KeySize::OEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Serial with check digit a valid serial?
|
||||
*
|
||||
* standard Mod7 Check
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidSerial()
|
||||
{
|
||||
return isValidMod7(info.Serial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEMID a valid?
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidOEMID()
|
||||
{
|
||||
if (info.OEMID.IsZero())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return isValidMod7(info.OEMID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Channel ID a valid Channel ID?
|
||||
* also validates Channel ID check digit if applicable
|
||||
*
|
||||
* Known invalid Channel IDs are:
|
||||
* 333, 444, 555, 666, 777, 888, 999
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidChannelID() const
|
||||
{
|
||||
// if we're office, do the last digit +1 checksum
|
||||
if (info.isOffice)
|
||||
{
|
||||
Integer CheckDigit = (info.ChannelID % TEN), ChannelID = (info.ChannelID / TEN);
|
||||
|
||||
if (std::find(channelIDDisallowList.begin(), channelIDDisallowList.end(), IntToString(ChannelID)) !=
|
||||
channelIDDisallowList.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (ChannelID % TEN) + 1 == CheckDigit;
|
||||
}
|
||||
|
||||
// otherwise just make sure we're not in the disallow list
|
||||
return std::find(channelIDDisallowList.begin(), channelIDDisallowList.end(), IntToString(info.ChannelID)) ==
|
||||
channelIDDisallowList.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEM year in the allow list?
|
||||
*
|
||||
* Known allowed years are:
|
||||
* 95, 96, 97, 98, 99, 00, 01, 02
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidOEMYear() const
|
||||
{
|
||||
auto year = fmt::format("{:02d}", info.Year.ConvertToLong());
|
||||
return std::find(validYears.begin(), validYears.end(), year) != validYears.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the OEM Day an allowed day?
|
||||
*
|
||||
* Allowed days are 1 - 366 inclusive
|
||||
*
|
||||
* @return validity
|
||||
*/
|
||||
BOOL PIDGEN2::isValidOEMDay() const
|
||||
{
|
||||
return info.Day >= 0 && info.Day <= 366;
|
||||
}
|
62
src/libumskt/pidgen2/PIDGEN2.h
Normal file
62
src/libumskt/pidgen2/PIDGEN2.h
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/17/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_PIDGEN2_H
|
||||
#define UMSKT_PIDGEN2_H
|
||||
|
||||
#include <libumskt/pidgen.h>
|
||||
|
||||
class EXPORT PIDGEN2 : public PIDGEN
|
||||
{
|
||||
static const std::vector<std::string> channelIDDisallowList;
|
||||
static const std::vector<std::string> validYears;
|
||||
|
||||
enum KeySize
|
||||
{
|
||||
FPP = 10,
|
||||
Office = 11,
|
||||
OEM = 17
|
||||
};
|
||||
|
||||
public:
|
||||
~PIDGEN2() override = default;
|
||||
|
||||
struct KeyInfo
|
||||
{
|
||||
BOOL isOEM, isOffice;
|
||||
Integer Day, Year, OEMID, ChannelID, Serial;
|
||||
} info;
|
||||
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
std::string StringifyKey(const std::string &pKey) override;
|
||||
std::string StringifyProductID() override;
|
||||
BOOL ValidateKeyString(const std::string &in_key, std::string &out_key) override;
|
||||
|
||||
BOOL isValidSerial();
|
||||
BOOL isValidOEMID();
|
||||
[[nodiscard]] BOOL isValidChannelID() const;
|
||||
[[nodiscard]] BOOL isValidOEMYear() const;
|
||||
[[nodiscard]] BOOL isValidOEMDay() const;
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN2_H
|
115
src/libumskt/pidgen2/PIDGEN2_unittest.cpp
Normal file
115
src/libumskt/pidgen2/PIDGEN2_unittest.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "PIDGEN2.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* PIDGEN2 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN2, InstantiatePIDGEN2)
|
||||
{
|
||||
auto p2 = new PIDGEN2();
|
||||
ASSERT_NE(p2, nullptr);
|
||||
delete p2;
|
||||
}
|
||||
|
||||
class TestPIDGEN2 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN2 *p2;
|
||||
|
||||
PIDGEN2::KeyInfo valid_ki = {false, false, 60, 99, 0, 95, 111111};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
p2 = new PIDGEN2();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (p != nullptr)
|
||||
{
|
||||
delete p;
|
||||
p = nullptr;
|
||||
}
|
||||
if (p2 != nullptr)
|
||||
{
|
||||
delete p2;
|
||||
p2 = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyFPP)
|
||||
{
|
||||
std::string pKey = "0951111111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STRCASEEQ(&pKey[0], "095-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyOffice)
|
||||
{
|
||||
std::string pKey = "09561111111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "0956-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, TestStringifyKeyOEM)
|
||||
{
|
||||
std::string pKey = "06099000951611111";
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "06099-OEM-0009516-11111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidFPPKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "095-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidOfficeKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
p2->info.isOffice = true;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "0956-1111111");
|
||||
}
|
||||
|
||||
TEST_F(TestPIDGEN2, GenerateValidOEMKey)
|
||||
{
|
||||
p2->info = valid_ki;
|
||||
p2->info.isOEM = true;
|
||||
|
||||
std::string pKey;
|
||||
p2->Generate(pKey);
|
||||
pKey = p2->StringifyKey(pKey);
|
||||
ASSERT_STREQ(&pKey[0], "06099-OEM-0009516-11111");
|
||||
}
|
320
src/libumskt/pidgen3/BINK1998.cpp
Normal file
320
src/libumskt/pidgen3/BINK1998.cpp
Normal file
@ -0,0 +1,320 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Andrew
|
||||
*
|
||||
* @History {
|
||||
* Algorithm was initially written and open sourced by z22
|
||||
* and uploaded to GitHub by TheMCHK in August of 2019
|
||||
*
|
||||
* Endermanch (Andrew) rewrote the algorithm in May of 2023
|
||||
* Neo ported Endermanch's algorithm to CryptoPP in February of 2024
|
||||
* }
|
||||
*/
|
||||
|
||||
#include "BINK1998.h"
|
||||
|
||||
/**
|
||||
* Packs a Windows XP-like Product Key.
|
||||
*
|
||||
* @param ki
|
||||
* @return Integer representation of KeyInfo
|
||||
*/
|
||||
Integer BINK1998::Pack(const KeyInfo &ki)
|
||||
{
|
||||
// The quantity of information the key provides is 114 bits.
|
||||
// We're storing it in 2 64-bit quad-words with 14 trailing bits.
|
||||
// 64 * 2 = 128
|
||||
auto serial = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
|
||||
// Signature [114..59] <- Hash [58..31] <- Serial [30..1] <- Upgrade [0]
|
||||
Integer raw = CryptoPP::Crop(ki.Signature, 56) << 59 | CryptoPP::Crop(ki.Hash, 28) << 31 |
|
||||
CryptoPP::Crop(serial, 30) << 1 | ki.isUpgrade;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "pack: {:x}\n\n", raw);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks a Windows XP-like Product Key.
|
||||
*
|
||||
* @param raw Integer to unpack
|
||||
* @return populated PIDGEN3::KeyInfo struct
|
||||
*/
|
||||
BINK1998::KeyInfo BINK1998::Unpack(const Integer &raw)
|
||||
{
|
||||
KeyInfo ki;
|
||||
|
||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||
// log2(24^25) = 114.
|
||||
|
||||
// Upgrade = Bit 0
|
||||
ki.isUpgrade = CryptoPP::Crop(raw, 1).ConvertToLong();
|
||||
|
||||
// Serial = Bits [1..30] -> 30 bits
|
||||
auto serialPack = CryptoPP::Crop((raw >> 1), 30);
|
||||
ki.Serial = serialPack % MaxSerial;
|
||||
ki.ChannelID = ((serialPack - ki.Serial) / MaxSerial);
|
||||
|
||||
// Hash = Bits [31..58] -> 28 bits
|
||||
ki.Hash = CryptoPP::Crop((raw >> 31), 28);
|
||||
|
||||
// Signature = Bits [59..113] -> 56 bits
|
||||
ki.Signature = CryptoPP::Crop((raw >> 59), 56);
|
||||
|
||||
return ki;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Windows XP-like Product Key.
|
||||
*
|
||||
* @param pKey [out]
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
BOOL BINK1998::Generate(std::string &pKey)
|
||||
{
|
||||
Integer c, s, pRaw;
|
||||
SHA1 sha1;
|
||||
|
||||
// copy initial state from object
|
||||
auto ki = info;
|
||||
|
||||
if (!ki.Rand.IsZero())
|
||||
{
|
||||
c = ki.Rand;
|
||||
}
|
||||
|
||||
// Data segment of the RPK.
|
||||
Integer serialPack = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
Integer pData = (serialPack << 1) | ki.isUpgrade;
|
||||
|
||||
// prepare the private key for generation
|
||||
privateKey = genOrder - privateKey;
|
||||
|
||||
do
|
||||
{
|
||||
ECP::Point R;
|
||||
|
||||
if (ki.Rand.IsZero())
|
||||
{
|
||||
// Generate a random number c consisting of 384 bits without any constraints.
|
||||
c.Randomize(UMSKT::rng, FieldBits);
|
||||
}
|
||||
|
||||
// Pick a random derivative of the base point on the elliptic curve.
|
||||
// R = cG;
|
||||
R = eCurve.Multiply(c, genPoint);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "c: {:x}\n\n", c);
|
||||
fmt::print(debug, "R[x,y] [{:x},\n{:x}]\n\n", R.x, R.y);
|
||||
}
|
||||
|
||||
// Acquire its coordinates.
|
||||
// x = R.x; y = R.y;
|
||||
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the SHA message.
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(R.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(R.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// pHash = SHA1(pSerial || R.x || R.y)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, sizeof(msgBuffer));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte digest into a 32-bit integer - this is our computed pHash.
|
||||
// Truncate the pHash to 28 bits.
|
||||
|
||||
ki.Hash = IntegerN(msgDigest, 4) >> 4;
|
||||
ki.Hash = CryptoPP::Crop(ki.Hash, 28);
|
||||
|
||||
/*
|
||||
*
|
||||
* Scalars:
|
||||
* c = Random multiplier
|
||||
* e = Hash
|
||||
* s = Signature
|
||||
* n = Order of G
|
||||
* k = Private Key
|
||||
*
|
||||
* Points:
|
||||
* G(x, y) = Generator (Base Point)
|
||||
* R(x, y) = Random derivative of the generator
|
||||
* K(x, y) = Public Key
|
||||
*
|
||||
* We need to find the signature s that satisfies the equation with a given hash:
|
||||
* P = sG + eK
|
||||
* s = ek + c (mod n) <- computation optimization
|
||||
*/
|
||||
|
||||
// s = ek;
|
||||
s = privateKey * ki.Hash;
|
||||
|
||||
// s += c (mod n)
|
||||
s += c;
|
||||
s %= genOrder;
|
||||
|
||||
// Translate resulting scalar into an Integer.
|
||||
ki.Signature = s;
|
||||
|
||||
// Pack product key.
|
||||
pRaw = Pack(ki);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Generation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Sequence", ki.Serial);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
} while (ki.Signature.BitCount() > 55 && ki.Rand.IsZero());
|
||||
// ↑ ↑ ↑
|
||||
// The signature can't be longer than 55 bits, else it will
|
||||
// make the CD-key longer than 25 characters.
|
||||
|
||||
// Convert bytecode to Base24 CD-key.
|
||||
pKey = base24(pRaw);
|
||||
|
||||
info = ki;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a Windows XP-like Product Key.
|
||||
*
|
||||
* @param pKey [in]
|
||||
*
|
||||
* @return true if provided key validates against loaded curve
|
||||
*/
|
||||
BOOL BINK1998::Validate(const std::string &pKey)
|
||||
{
|
||||
if (pKey.length() != 25)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert Base24 CD-key to bytecode.
|
||||
Integer pRaw = unbase24(pKey);
|
||||
SHA1 sha1;
|
||||
|
||||
// Extract RPK, hash and signature from bytecode.
|
||||
KeyInfo ki = Unpack(pRaw);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Validation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Sequence", ki.Serial);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
Integer serialPack = (ki.ChannelID * MaxSerial) + ki.Serial;
|
||||
Integer pData = serialPack << 1 | ki.isUpgrade;
|
||||
|
||||
/*
|
||||
*
|
||||
* Scalars:
|
||||
* e = Hash
|
||||
* s = Schnorr Signature
|
||||
*
|
||||
* Points:
|
||||
* G(x, y) = Generator (Base Point)
|
||||
* K(x, y) = Public Key
|
||||
*
|
||||
* Equation:
|
||||
* P = sG + eK
|
||||
*
|
||||
*/
|
||||
|
||||
Integer e = ki.Hash, s = ki.Signature;
|
||||
|
||||
// Create 2 points on the elliptic curve.
|
||||
ECP::Point t, P;
|
||||
|
||||
// t = sG
|
||||
t = eCurve.Multiply(s, genPoint);
|
||||
|
||||
// P = eK
|
||||
P = eCurve.Multiply(e, pubPoint);
|
||||
|
||||
// P += t
|
||||
P = eCurve.Add(P, t);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "P[x,y]: [{:x},\n{:x}]\n\n", P.x, P.y);
|
||||
}
|
||||
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
|
||||
// Assemble the SHA message.
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(P.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(P.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// compHash = SHA1(pSerial || P.x || P.y)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "hash: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
info = ki;
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 28 bits.
|
||||
Integer compHash = CryptoPP::Crop(intDigest >> 4, 28);
|
||||
|
||||
// If the computed hash checks out, the key is valid.
|
||||
return compHash == ki.Hash;
|
||||
}
|
61
src/libumskt/pidgen3/BINK1998.h
Normal file
61
src/libumskt/pidgen3/BINK1998.h
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_BINK1998_H
|
||||
#define UMSKT_BINK1998_H
|
||||
|
||||
#include "PIDGEN3.h"
|
||||
|
||||
class EXPORT BINK1998 : public PIDGEN3
|
||||
{
|
||||
public:
|
||||
using PIDGEN3::PIDGEN3;
|
||||
BINK1998() = default;
|
||||
explicit BINK1998(PIDGEN3 *p3)
|
||||
{
|
||||
privateKey = p3->privateKey;
|
||||
genOrder = p3->genOrder;
|
||||
genPoint = p3->genPoint;
|
||||
pubPoint = p3->pubPoint;
|
||||
eCurve = p3->eCurve;
|
||||
}
|
||||
|
||||
~BINK1998() override = default;
|
||||
|
||||
static constexpr DWORD32 FieldBits = (48 * 8);
|
||||
static constexpr DWORD32 FieldBytes = (FieldBits / 8);
|
||||
static constexpr DWORD32 SHAMessageLength = (4 + 2 * FieldBytes);
|
||||
|
||||
using PIDGEN3::Pack;
|
||||
Integer Pack(const KeyInfo &ki) override;
|
||||
|
||||
using PIDGEN3::Unpack;
|
||||
KeyInfo Unpack(const Integer &raw) override;
|
||||
|
||||
using PIDGEN3::Generate;
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
|
||||
using PIDGEN3::Validate;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
};
|
||||
|
||||
#endif // UMSKT_BINK1998_H
|
110
src/libumskt/pidgen3/BINK1998_unittest.cpp
Normal file
110
src/libumskt/pidgen3/BINK1998_unittest.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "../libumskt_unittest.h"
|
||||
#include "BINK1998.h"
|
||||
|
||||
/**
|
||||
* BINK1998 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN3_BINK1998, InstantiateBINK1998)
|
||||
{
|
||||
auto p3 = new BINK1998();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestBINK1998 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN3 *p3;
|
||||
BINK1998 *bink1998;
|
||||
|
||||
BINK1998::KeyInfo valid_ki = {false, false, 640, 111111, 0};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
bink1998 = new BINK1998();
|
||||
bink1998->LoadEllipticCurve("0x2E",
|
||||
"2260481414313563299067995668434431120981995280321627195247220485552475627515144045"
|
||||
"6421260165232069708317717961315241",
|
||||
"1", "0",
|
||||
"1091074492220651278115691316907175015302838688467620894706280834607253141127048943"
|
||||
"2930252839559606812441712224597826",
|
||||
"1917099366991720451749161800061981867915210969017264186834961288993048036527467509"
|
||||
"6509477191800826190959228181870174",
|
||||
"1439923035396364333971294001595406158106423983592682351741971676961393703934682226"
|
||||
"9422480779920783799484349086780408",
|
||||
"5484731395987446993229594927733430043632089703338918322171291299699820472711849119"
|
||||
"800714736923107362018017833200634",
|
||||
"61760995553426173", "37454031876727861");
|
||||
bink1998->info = valid_ki;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (bink1998 != nullptr)
|
||||
{
|
||||
delete bink1998;
|
||||
bink1998 = nullptr;
|
||||
}
|
||||
if (p3 != nullptr)
|
||||
{
|
||||
delete p3;
|
||||
p3 = nullptr;
|
||||
}
|
||||
if (p != nullptr)
|
||||
{
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestBINK1998, ValidateValidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink1998->ValidateKeyString("7KWK7-9W7H4-T64D6-DB8V7-BW7MW", pKey);
|
||||
|
||||
ASSERT_TRUE(ValidateKeyString);
|
||||
ASSERT_STREQ(&pKey[0], "7KWK79W7H4T64D6DB8V7BW7MW");
|
||||
}
|
||||
|
||||
TEST_F(TestBINK1998, ValidateValidKey)
|
||||
{
|
||||
std::string pKey = "7KWK79W7H4T64D6DB8V7BW7MW";
|
||||
|
||||
auto Validate = bink1998->Validate(pKey);
|
||||
ASSERT_TRUE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK1998, GenerateValidKey)
|
||||
{
|
||||
bink1998->info.Rand = UMSKT::IntegerS("3427338792529164195109698841758932126727183763685994848291878088992924483488"
|
||||
"5768429236548372772607190036626858221847");
|
||||
|
||||
std::string pKey;
|
||||
bink1998->Generate(pKey);
|
||||
pKey = bink1998->StringifyKey(pKey);
|
||||
|
||||
ASSERT_STREQ(&pKey[0], "7KWK7-9W7H4-T64D6-DB8V7-BW7MW");
|
||||
}
|
442
src/libumskt/pidgen3/BINK2002.cpp
Normal file
442
src/libumskt/pidgen3/BINK2002.cpp
Normal file
@ -0,0 +1,442 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Andrew
|
||||
*
|
||||
* @History {
|
||||
* Algorithm was initially written and open sourced by z22
|
||||
* and uploaded to GitHub by TheMCHK in August of 2019
|
||||
*
|
||||
* Endermanch (Andrew) rewrote the algorithm in May of 2023
|
||||
* Neo ported Endermanch's algorithm to CryptoPP in February of 2024
|
||||
* }
|
||||
*/
|
||||
|
||||
#include "BINK2002.h"
|
||||
|
||||
/**
|
||||
* Packs a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param ki PIDGEN3::KeyInfo struct to pack
|
||||
* @return Integer representation of the Product Key
|
||||
*/
|
||||
Integer BINK2002::Pack(const KeyInfo &ki)
|
||||
{
|
||||
// AuthInfo [113..104] <- Signature [103..42] <- Hash [41..11] <- Channel ID [10..1] <- Upgrade [0];
|
||||
Integer raw = CryptoPP::Crop(ki.AuthInfo, 10) << 104 | CryptoPP::Crop(ki.Signature, 62) << 42 |
|
||||
CryptoPP::Crop(ki.Hash, 31) << 11 | CryptoPP::Crop(ki.ChannelID, 10) << 1 | ki.isUpgrade;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "pack: {:x}\n\n", raw);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param raw Integer representation of the product key
|
||||
* @return unpacked PIDGEN3::KeyInfo struct
|
||||
*/
|
||||
BINK2002::KeyInfo BINK2002::Unpack(const Integer &raw)
|
||||
{
|
||||
// We're assuming that the quantity of information within the product key is at most 114 bits.
|
||||
// log2(24^25) = 114.
|
||||
KeyInfo ki;
|
||||
|
||||
// Upgrade = Bit 0
|
||||
ki.isUpgrade = CryptoPP::Crop(raw, 1).ConvertToLong();
|
||||
|
||||
// Channel ID = Bits [1..10] -> 10 bits
|
||||
ki.ChannelID = CryptoPP::Crop(raw >> 1, 10);
|
||||
|
||||
// Hash = Bits [11..41] -> 30 bits
|
||||
ki.Hash = CryptoPP::Crop(raw >> 11, 31);
|
||||
|
||||
// Signature = Bits [42..103] -> 62 bits
|
||||
// The quad-word signature overlaps AuthInfo in bits 104 and 105,
|
||||
// hence Microsoft employs a secret technique called: Signature = HIDWORD(Signature) >> 2 | LODWORD(Signature)
|
||||
ki.Signature = CryptoPP::Crop(raw >> 42, 62);
|
||||
|
||||
// AuthInfo = Bits [104..113] -> 10 bits
|
||||
ki.AuthInfo = CryptoPP::Crop(raw >> 104, 10);
|
||||
|
||||
return ki;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param info
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
BOOL BINK2002::Generate(std::string &pKey)
|
||||
{
|
||||
// copy the starting state from the class
|
||||
KeyInfo ki = info;
|
||||
SHA1 sha1;
|
||||
|
||||
Integer c, e, s, pRaw;
|
||||
|
||||
if (!ki.Rand.IsZero())
|
||||
{
|
||||
c = ki.Rand;
|
||||
}
|
||||
|
||||
// Data segment of the RPK.
|
||||
Integer pData = ki.ChannelID << 1 | ki.isUpgrade;
|
||||
|
||||
BOOL noSquare;
|
||||
|
||||
do
|
||||
{
|
||||
ECP::Point R;
|
||||
|
||||
if (ki.Rand.IsZero())
|
||||
{
|
||||
// Generate a random number c consisting of 512 bits without any constraints.
|
||||
c.Randomize(UMSKT::rng, FieldBits);
|
||||
}
|
||||
|
||||
// R = cG
|
||||
R = eCurve.Multiply(c, genPoint);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "c: {:x}\n\n", c);
|
||||
fmt::print(debug, "R[x,y] [{:x},\n{:x}]\n\n", R.x, R.y);
|
||||
}
|
||||
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the first SHA message.
|
||||
*pMsgBuffer = 0x79;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
|
||||
// Convert resulting point coordinates to bytes.
|
||||
// and flip the endianness
|
||||
pMsgBuffer = EncodeN(R.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(R.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// pHash = SHA1(79 || Channel ID || R.x || R.y)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer[1]: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest[1]: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 31 bits.
|
||||
ki.Hash = CryptoPP::Crop(IntegerN(msgDigest), 31);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
BYTE buf[8];
|
||||
sha1.CalculateTruncatedDigest(buf, sizeof(buf), msgBuffer, SHAMessageLength);
|
||||
|
||||
fmt::print(verbose, "truncated buffer: ");
|
||||
for (BYTE b : buf)
|
||||
{
|
||||
fmt::print(verbose, "{:x}", b);
|
||||
}
|
||||
fmt::print(verbose, "\n\n");
|
||||
|
||||
DWORD h0 = ((DWORD)buf[0] | ((DWORD)buf[1] << 8) | ((DWORD)buf[2] << 16) | ((DWORD)buf[3] << 24));
|
||||
DWORD h1 =
|
||||
((((DWORD)buf[4]) | ((DWORD)buf[5] << 8) | ((DWORD)buf[6] << 16) | ((DWORD)buf[7] << 24)) >> (32 - 19))
|
||||
<< 1;
|
||||
|
||||
h1 |= (h0 >> 31) & 1;
|
||||
|
||||
fmt::print(verbose, "h0,1: {:x} {:x}\n\n", h0, h1);
|
||||
|
||||
ki.Serial = IntegerN(h1);
|
||||
|
||||
fmt::print(verbose, "serial: {:d}\n\n", ki.Serial);
|
||||
}
|
||||
|
||||
// Assemble the second SHA message.
|
||||
pMsgBuffer = msgBuffer;
|
||||
msgBuffer[0x00] = 0x5D;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(ki.Hash, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(ki.AuthInfo, pMsgBuffer, 2);
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
// newSignature = SHA1(5D || Channel ID || Hash || AuthInfo || 00 00)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, pMsgBuffer - msgBuffer);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "msgBuffer[2]: ");
|
||||
for (BYTE b : msgBuffer)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
|
||||
fmt::print(debug, "msgDigest[2]: ");
|
||||
for (BYTE b : msgDigest)
|
||||
{
|
||||
fmt::print(debug, "{:x}", b);
|
||||
}
|
||||
fmt::print(debug, "\n\n");
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 64-bit integer - this is our computed intermediate signature.
|
||||
// As the signature is only 62 bits long at most, we have to truncate it by shifting the high DWORD right 2
|
||||
// bits (per spec).
|
||||
QWORD iSignature = NEXTSNBITS(BYDWORD(&msgDigest[4]), 30, 2) << 32 | BYDWORD(msgDigest);
|
||||
|
||||
/*
|
||||
*
|
||||
* Scalars:
|
||||
* c = Random multiplier
|
||||
* e = Intermediate Signature
|
||||
* s = Signature
|
||||
* n = Order of G
|
||||
* k = Private Key
|
||||
*
|
||||
* Points:
|
||||
* G(x, y) = Generator (Base Point)
|
||||
* R(x, y) = Random derivative of the generator
|
||||
* K(x, y) = Public Key
|
||||
*
|
||||
* Equation:
|
||||
* s(sG + eK) = R (mod p)
|
||||
* ↓ K = kG; R = cG ↓
|
||||
*
|
||||
* s(sG + ekG) = cG (mod p)
|
||||
* s(s + ek)G = cG (mod p)
|
||||
* ↓ G cancels out, the scalar arithmetic shrinks to order n ↓
|
||||
*
|
||||
* s(s + ek) = c (mod n)
|
||||
* s² + (ek)s - c = 0 (mod n)
|
||||
* ↓ This is a quadratic equation in respect to the signature ↓
|
||||
*
|
||||
* s = (-ek ± √((ek)² + 4c)) / 2 (mod n)
|
||||
*/
|
||||
|
||||
// e = ek (mod n)
|
||||
e = CryptoPP::ModularMultiplication(IntegerN(iSignature), privateKey, genOrder);
|
||||
|
||||
// s = (ek (mod n))²
|
||||
s = CryptoPP::ModularExponentiation(e, Integer::Two(), genOrder);
|
||||
|
||||
// c *= 4 (c <<= 2)
|
||||
c *= 4;
|
||||
|
||||
// s += c
|
||||
s += c;
|
||||
|
||||
// Around half of numbers modulo a prime are not squares -> BN_sqrt_mod fails about half of the times,
|
||||
// hence if BN_sqrt_mod returns NULL, we need to restart with a different seed.
|
||||
// s = √((ek)² + 4c (mod n))
|
||||
s = CryptoPP::ModularSquareRoot(s, genOrder);
|
||||
noSquare = s.IsZero();
|
||||
|
||||
// s = -ek + √((ek)² + 4c) (mod n)
|
||||
s -= e;
|
||||
s %= genOrder;
|
||||
|
||||
// If s is odd, add order to it.
|
||||
// The order is a prime, so it can't be even.
|
||||
if (s % Integer::Two() != 0)
|
||||
{
|
||||
// s = -ek + √((ek)² + 4c) + n
|
||||
s += genOrder;
|
||||
}
|
||||
|
||||
// s /= 2 (s >>= 1)
|
||||
s /= 2;
|
||||
|
||||
// Translate resulting scalar into a 64-bit integer (the byte order is little-endian).
|
||||
ki.Signature = s;
|
||||
|
||||
// Pack product key.
|
||||
pRaw = Pack(ki);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Generation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "AuthInfo", ki.AuthInfo);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
} while ((ki.Signature.BitCount() > 62 || noSquare) && ki.Rand.IsZero());
|
||||
// ↑ ↑ ↑
|
||||
// The signature can't be longer than 62 bits, else it will
|
||||
// overlap with the AuthInfo segment next to it.
|
||||
// Convert bytecode to Base24 CD-key.
|
||||
pKey = base24(pRaw);
|
||||
|
||||
info = ki;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a Windows Server 2003-like Product Key.
|
||||
*
|
||||
* @param pKey
|
||||
**/
|
||||
BOOL BINK2002::Validate(const std::string &pKey)
|
||||
{
|
||||
Integer pRaw;
|
||||
SHA1 sha1;
|
||||
|
||||
// Convert Base24 CD-key to bytecode.
|
||||
pRaw = unbase24(pKey);
|
||||
|
||||
// Extract product key segments from bytecode.
|
||||
KeyInfo ki = Unpack(pRaw);
|
||||
|
||||
Integer pData = ki.ChannelID << 1 | ki.isUpgrade;
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
fmt::print(verbose, "Validation results:\n");
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Upgrade", (bool)ki.isUpgrade);
|
||||
fmt::print(verbose, "{:>10}: {}\n", "Channel ID", ki.ChannelID);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Hash", ki.Hash);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "Signature", ki.Signature);
|
||||
fmt::print(verbose, "{:>10}: {:x}\n", "AuthInfo", ki.AuthInfo);
|
||||
fmt::print(verbose, "\n");
|
||||
}
|
||||
|
||||
BYTE msgDigest[SHA1::DIGESTSIZE], msgBuffer[SHAMessageLength], *pMsgBuffer = msgBuffer;
|
||||
|
||||
// Assemble the first SHA message.
|
||||
msgBuffer[0x00] = 0x5D;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(ki.Hash, pMsgBuffer, 4);
|
||||
pMsgBuffer = EncodeN(ki.AuthInfo, pMsgBuffer, 2);
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
*pMsgBuffer = 0x00;
|
||||
pMsgBuffer++;
|
||||
|
||||
// newSignature = SHA1(5D || Channel ID || Hash || AuthInfo || 00 00)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, pMsgBuffer - msgBuffer);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
fmt::print(debug, "\nhash 1: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 64-bit integer - this is our computed intermediate signature.
|
||||
// As the signature is only 62 bits long at most, we have to truncate it by shifting the high DWORD right 2 bits
|
||||
// (per spec).
|
||||
QWORD iSignature = NEXTSNBITS(BYDWORD(&msgDigest[4]), 30, 2) << 32 | BYDWORD(msgDigest);
|
||||
|
||||
/*
|
||||
*
|
||||
* Scalars:
|
||||
* e = Hash
|
||||
* s = Schnorr Signature
|
||||
*
|
||||
* Points:
|
||||
* G(x, y) = Generator (Base Point)
|
||||
* K(x, y) = Public Key
|
||||
*
|
||||
* Equation:
|
||||
* P = s(sG + eK)
|
||||
*
|
||||
*/
|
||||
Integer e = IntegerN(iSignature), s = ki.Signature;
|
||||
|
||||
// Create 2 points on the elliptic curve.
|
||||
ECP::Point P, t;
|
||||
|
||||
// t = sG
|
||||
t = eCurve.Multiply(s, genPoint);
|
||||
|
||||
// P = eK
|
||||
P = eCurve.Multiply(e, pubPoint);
|
||||
|
||||
// P += t
|
||||
P = eCurve.Add(P, t);
|
||||
|
||||
// P *= s
|
||||
P = eCurve.Multiply(s, P);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "P[x,y]: [{:x},\n{:x}]\n\n", P.x, P.y);
|
||||
}
|
||||
|
||||
// Assemble the second SHA message.
|
||||
pMsgBuffer = msgBuffer;
|
||||
msgBuffer[0x00] = 0x79;
|
||||
pMsgBuffer++;
|
||||
|
||||
pMsgBuffer = EncodeN(pData, pMsgBuffer, 2);
|
||||
pMsgBuffer = EncodeN(P.x, pMsgBuffer, FieldBytes);
|
||||
EncodeN(P.y, pMsgBuffer, FieldBytes);
|
||||
|
||||
// compHash = SHA1(79 || Channel ID || P.x || P.y)
|
||||
sha1.CalculateDigest(msgDigest, msgBuffer, SHAMessageLength);
|
||||
|
||||
auto intDigest = IntegerN(msgDigest);
|
||||
if (debug)
|
||||
{
|
||||
fmt::print(debug, "hash 2: {:x}\n\n", intDigest);
|
||||
}
|
||||
|
||||
// Translate the byte sha1 into a 32-bit integer - this is our computed hash.
|
||||
// Truncate the hash to 31 bits.
|
||||
Integer compHash = CryptoPP::Crop(intDigest, 31);
|
||||
|
||||
info = ki;
|
||||
|
||||
// If the computed hash checks out, the key is valid.
|
||||
return compHash == ki.Hash;
|
||||
}
|
61
src/libumskt/pidgen3/BINK2002.h
Normal file
61
src/libumskt/pidgen3/BINK2002.h
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_BINK2002_H
|
||||
#define UMSKT_BINK2002_H
|
||||
|
||||
#include "PIDGEN3.h"
|
||||
|
||||
class EXPORT BINK2002 : public PIDGEN3
|
||||
{
|
||||
public:
|
||||
using PIDGEN3::PIDGEN3;
|
||||
BINK2002() = default;
|
||||
explicit BINK2002(PIDGEN3 *p3)
|
||||
{
|
||||
privateKey = p3->privateKey;
|
||||
genOrder = p3->genOrder;
|
||||
genPoint = p3->genPoint;
|
||||
pubPoint = p3->pubPoint;
|
||||
eCurve = p3->eCurve;
|
||||
}
|
||||
|
||||
~BINK2002() override = default;
|
||||
|
||||
static constexpr DWORD32 FieldBits = (64 * 8);
|
||||
static constexpr DWORD32 FieldBytes = (FieldBits / 8);
|
||||
static constexpr DWORD32 SHAMessageLength = (3 + 2 * FieldBytes);
|
||||
|
||||
using PIDGEN3::Pack;
|
||||
Integer Pack(const KeyInfo &ki) override;
|
||||
|
||||
using PIDGEN3::Unpack;
|
||||
KeyInfo Unpack(const Integer &raw) override;
|
||||
|
||||
using PIDGEN3::Generate;
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
|
||||
using PIDGEN3::Validate;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
};
|
||||
|
||||
#endif // UMSKT_BINK2002_H
|
121
src/libumskt/pidgen3/BINK2002_unittest.cpp
Normal file
121
src/libumskt/pidgen3/BINK2002_unittest.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 02/19/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "BINK2002.h"
|
||||
#include <libumskt/libumskt_unittest.h>
|
||||
|
||||
/**
|
||||
* BINK2002 must not be an abstract class.
|
||||
*/
|
||||
TEST(PIDGEN3_BINK2002, InstantiateBINK2002)
|
||||
{
|
||||
auto p3 = new BINK2002();
|
||||
ASSERT_NE(p3, nullptr);
|
||||
delete p3;
|
||||
}
|
||||
|
||||
class TestBINK2002 : public libumsktUnitTests
|
||||
{
|
||||
protected:
|
||||
PIDGEN *p;
|
||||
PIDGEN3 *p3;
|
||||
BINK2002 *bink2002;
|
||||
|
||||
BINK2002::KeyInfo valid_ki = {false, false, 640, 0, 701};
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
bink2002 = new BINK2002();
|
||||
bink2002->LoadEllipticCurve("0x54",
|
||||
"1250964251969733259611431105354461862074700938981465222536952118871017192617497641"
|
||||
"9995384745134703589248167610052719613586668754176591418831031596093374569",
|
||||
"1", "0",
|
||||
"8059057663701168311917532277618827622978515614146963913097592614451721430413021070"
|
||||
"395782723330339842826599481063797559797462512297834269467666807971588275",
|
||||
"1223930383017475319177970597922037862339473226753699711562597963240231208768364492"
|
||||
"7405756146495100825573682155171145924668759419114616275413724686284123408",
|
||||
"4895832170509729140211911021638266775170167022247175324972987673313207244495397975"
|
||||
"379010973250279668424167408883454560376269866102669741515127286188717976",
|
||||
"5846013328426281815512452704859777850382010968846722453046994319336479079120767834"
|
||||
"777937190955827245502389471872759584209649693396095099112777776298051208",
|
||||
"5622613991231344109", "1285511085175426271");
|
||||
bink2002->info = valid_ki;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (bink2002 != nullptr)
|
||||
{
|
||||
delete bink2002;
|
||||
bink2002 = nullptr;
|
||||
}
|
||||
if (p3 != nullptr)
|
||||
{
|
||||
delete p3;
|
||||
p3 = nullptr;
|
||||
}
|
||||
if (p != nullptr)
|
||||
{
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestBINK2002, ValidateValidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink2002->ValidateKeyString("QX7C7-6668G-RHTTC-9XXD6-4QKVM", pKey);
|
||||
ASSERT_TRUE(ValidateKeyString);
|
||||
ASSERT_STREQ(&pKey[0], "QX7C76668GRHTTC9XXD64QKVM");
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateInvalidKeyString)
|
||||
{
|
||||
std::string pKey;
|
||||
auto ValidateKeyString = bink2002->ValidateKeyString("QX7C7-6668G-RHTTC-9XXD6-4QKVM-7", pKey);
|
||||
ASSERT_FALSE(ValidateKeyString);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateValidKey)
|
||||
{
|
||||
std::string pKey = "QX7C76668GRHTTC9XXD64QKVM";
|
||||
auto Validate = bink2002->Validate(pKey);
|
||||
ASSERT_TRUE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, ValidateInvalidKey)
|
||||
{
|
||||
std::string pKey = "QX7C76668GRHTTC9XXD64QKV7";
|
||||
auto Validate = bink2002->Validate(pKey);
|
||||
ASSERT_FALSE(Validate);
|
||||
}
|
||||
|
||||
TEST_F(TestBINK2002, GenerateValidKey)
|
||||
{
|
||||
bink2002->info.Rand = UMSKT::IntegerS("2715417548459431244234182116258933974639514924173191881913315754156057922856"
|
||||
"789413383072541627152533502894944768632184791880876163762899980230935");
|
||||
std::string pKey;
|
||||
bink2002->Generate(pKey);
|
||||
pKey = bink2002->StringifyKey(pKey);
|
||||
|
||||
ASSERT_STREQ(&pKey[0], "QX7C7-6668G-RHTTC-9XXD6-4QKVM");
|
||||
}
|
316
src/libumskt/pidgen3/PIDGEN3.cpp
Normal file
316
src/libumskt/pidgen3/PIDGEN3.cpp
Normal file
@ -0,0 +1,316 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Andrew
|
||||
*/
|
||||
|
||||
#include "PIDGEN3.h"
|
||||
#include "BINK1998.h"
|
||||
#include "BINK2002.h"
|
||||
|
||||
/**
|
||||
* PID 3.0 Product Key Character Set
|
||||
*/
|
||||
const std::string PIDGEN3::pKeyCharset = "BCDFGHJKMPQRTVWXY2346789";
|
||||
|
||||
/**
|
||||
* Maximum Field size for BINK 1998
|
||||
*/
|
||||
const DWORD32 PIDGEN3::MaxSizeBINK1998 = BINK1998::FieldBits + 1;
|
||||
|
||||
/**
|
||||
* RFC 1149.5 specifies 4 as the standard IEEE-vetted random number.
|
||||
*
|
||||
* see also: https://xkcd.com/221/
|
||||
*
|
||||
* @return 4
|
||||
*/
|
||||
int getRandomNumber()
|
||||
{
|
||||
return 4; // chosen by fair dice roll
|
||||
// guaranteed to be random
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the elliptic curve
|
||||
*
|
||||
* @param pSel [in] prime
|
||||
* @param aSel [in] a
|
||||
* @param bSel [in] b
|
||||
* @param generatorXSel [in] G[x]
|
||||
* @param generatorYSel [in] G[y]
|
||||
* @param publicKeyXSel [in] pub[x]
|
||||
* @param publicKeyYSel [in] pub[y]
|
||||
* @param genOrderSel [in] computed order of G
|
||||
* @param privateKeySel [in] computed private key
|
||||
*
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
BOOL PIDGEN3::LoadEllipticCurve(const std::string &BinkIDSel, const std::string &pSel, const std::string &aSel,
|
||||
const std::string &bSel, const std::string &generatorXSel,
|
||||
const std::string &generatorYSel, const std::string &publicKeyXSel,
|
||||
const std::string &publicKeyYSel, const std::string &genOrderSel,
|
||||
const std::string &privateKeySel)
|
||||
{
|
||||
// We cannot produce a valid key without knowing the private key k. The reason for this is that
|
||||
// we need the result of the function K(x; y) = kG(x; y).
|
||||
|
||||
// We can, however, validate any given key using the available public key: {p, a, b, G, K}.
|
||||
// genOrder the order of the generator G, a value we have to reverse -> Schoof's Algorithm.
|
||||
|
||||
BINKID = IntegerHexS(BinkIDSel);
|
||||
|
||||
// We're presented with an elliptic curve, a multivariable function y(x; p; a; b), where
|
||||
// y^2 % p = x^3 + ax + b % p.
|
||||
auto p = IntegerS(pSel), a = IntegerS(aSel), b = IntegerS(bSel);
|
||||
|
||||
// Public key will consist of the resulting (x; y) values.
|
||||
auto generatorX = IntegerS(generatorXSel), generatorY = IntegerS(generatorYSel);
|
||||
|
||||
// G(x; y) is a generator function, its return value represents a point on the elliptic curve.
|
||||
auto publicKeyX = IntegerS(publicKeyXSel), publicKeyY = IntegerS(publicKeyYSel);
|
||||
|
||||
/* Computed Data */
|
||||
genOrder = IntegerS(genOrderSel);
|
||||
privateKey = IntegerS(privateKeySel);
|
||||
|
||||
/* Elliptic Curve calculations. */
|
||||
// The group is defined via Fp = all integers [0; p - 1], where p is prime.
|
||||
// The function EC_POINT_set_affine_coordinates() sets the x and y coordinates for the point p defined over the
|
||||
// curve given in group.
|
||||
eCurve = ECP(p, a, b);
|
||||
|
||||
// Create new point N for the generator on the elliptic curve and set its coordinates to (genX; genY).
|
||||
genPoint = ECP::Point(generatorX, generatorY);
|
||||
|
||||
// Create new point Q for the public key on the elliptic curve and set its coordinates to (pubX; pubY).
|
||||
pubPoint = ECP::Point(publicKeyX, publicKeyY);
|
||||
|
||||
// If generator and public key points are not on the elliptic curve, either the generator or the public key values
|
||||
// are incorrect.
|
||||
assert(eCurve.VerifyPoint(genPoint) == true);
|
||||
assert(eCurve.VerifyPoint(pubPoint) == true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a PID 3.0 generator based on a given field on the heap
|
||||
*
|
||||
* @param field
|
||||
* @return PIDGEN3 based on the field type
|
||||
*/
|
||||
PIDGEN3 *PIDGEN3::Factory(const std::string &field)
|
||||
{
|
||||
if (checkFieldStrIsBink1998(field))
|
||||
{
|
||||
return new BINK1998();
|
||||
}
|
||||
return new BINK2002();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory-style Generate function, checks the currently instantiated field
|
||||
* creates the correct PIDGEN for the field type using the copy constructor
|
||||
* and invokes its Generate()
|
||||
*
|
||||
* @param pKey
|
||||
* @return successfulness
|
||||
*/
|
||||
BOOL PIDGEN3::Generate(std::string &pKey)
|
||||
{
|
||||
if (checkFieldIsBink1998())
|
||||
{
|
||||
auto p3 = BINK1998(this);
|
||||
return p3.Generate(pKey);
|
||||
}
|
||||
|
||||
auto p3 = BINK2002(this);
|
||||
return p3.Generate(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory style Validate function, see Generate() for more info
|
||||
*
|
||||
* @param pKey
|
||||
* @return successfulness
|
||||
*/
|
||||
BOOL PIDGEN3::Validate(const std::string &pKey)
|
||||
{
|
||||
if (checkFieldIsBink1998())
|
||||
{
|
||||
auto p3 = BINK1998(this);
|
||||
return p3.Validate(pKey);
|
||||
}
|
||||
|
||||
auto p3 = BINK2002(this);
|
||||
return p3.Validate(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from byte sequence to the CD-key.
|
||||
*
|
||||
* @param seq Integer representation
|
||||
* @return std::string CDKey output
|
||||
**/
|
||||
std::string PIDGEN3::base24(Integer &seq)
|
||||
{
|
||||
std::string cdKey;
|
||||
cdKey.reserve(PK_LENGTH);
|
||||
|
||||
// Divide z by 24 and convert the remainder to a CD-key char.
|
||||
Integer r, q, a = seq;
|
||||
for (int i = PK_LENGTH - 1; i >= 0; i--)
|
||||
{
|
||||
Integer::Divide(r, q, a, (WORD)pKeyCharset.length());
|
||||
cdKey.insert(cdKey.begin(), pKeyCharset[r.ConvertToLong()]);
|
||||
a = q;
|
||||
}
|
||||
|
||||
return cdKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from CD-key to a byte sequence.
|
||||
*
|
||||
* @param cdKey std::string CDKey to convert
|
||||
* @return Integer raw representation of the CDKey
|
||||
**/
|
||||
Integer PIDGEN3::unbase24(const std::string &cdKey)
|
||||
{
|
||||
Integer result;
|
||||
|
||||
for (char ch : cdKey)
|
||||
{
|
||||
auto val = std::find(pKeyCharset.begin(), pKeyCharset.end(), ch);
|
||||
|
||||
// character is not in set, return early
|
||||
if (val == pKeyCharset.end())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// add the weighted sum to result
|
||||
result *= (int)pKeyCharset.length();
|
||||
result += (int)(val - pKeyCharset.begin());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the currently loaded Class-level KeyInfo and calculates the check digit for display.
|
||||
*
|
||||
* Algorithm directly taken from PIDGEN
|
||||
*
|
||||
* @return std::string representation of the Product ID as Displayed on the Product
|
||||
*/
|
||||
std::string PIDGEN3::StringifyProductID()
|
||||
{
|
||||
if (info.isOEM)
|
||||
{
|
||||
Integer OEMID = info.ChannelID * Integer(100);
|
||||
OEMID += ((info.Serial / (MaxSerial / TEN)) * TEN);
|
||||
OEMID += GenerateMod7(OEMID);
|
||||
|
||||
Integer Serial = info.Serial % (MaxSerial / TEN);
|
||||
|
||||
DWORD32 iOEMID = OEMID.ConvertToLong(), iSerial = Serial.ConvertToLong();
|
||||
return fmt::format("PPPPP-OEM-{:07d}-{:05d}", iOEMID, iSerial);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD32 ChannelID = info.ChannelID.ConvertToLong(),
|
||||
Serial = (info.Serial * TEN + GenerateMod7(info.Serial)).ConvertToLong(),
|
||||
BinkID = (BINKID / Integer::Two()).ConvertToLong();
|
||||
return fmt::format("PPPPP-{:03d}-{:07d}-{:d}xxx", ChannelID, Serial, BinkID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the currently instantiated PIDGEN3 object has a
|
||||
* field size greater than the maximum known BINK1998 size.
|
||||
*
|
||||
* @return boolean value
|
||||
*/
|
||||
BOOL PIDGEN3::checkFieldIsBink1998()
|
||||
{
|
||||
// is fieldSize < max?
|
||||
return (eCurve.FieldSize().BitCount() < MaxSizeBINK1998);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given field, in a std::string, is greater than
|
||||
* the maximum known BINK1998 size
|
||||
*
|
||||
* @param keyin std::string representation of a Field
|
||||
* @return boolean value
|
||||
*/
|
||||
BOOL PIDGEN3::checkFieldStrIsBink1998(std::string keyin)
|
||||
{
|
||||
auto check = IntegerS(keyin);
|
||||
|
||||
// is fieldSize < max?
|
||||
return (check.BitCount() < MaxSizeBINK1998);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a product key to stdout
|
||||
*
|
||||
* @param pk std::string to print
|
||||
*/
|
||||
std::string PIDGEN3::StringifyKey(const std::string &pKey)
|
||||
{
|
||||
assert(pKey.length() >= PK_LENGTH);
|
||||
|
||||
return fmt::format("{}-{}-{}-{}-{}", pKey.substr(0, 5), pKey.substr(5, 5), pKey.substr(10, 5), pKey.substr(15, 5),
|
||||
pKey.substr(20, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* std::BinaryOperation compatible accumulator for validating/stripping an input string against the PIDGEN3 charset
|
||||
*
|
||||
* @param accumulator
|
||||
* @param currentChar
|
||||
* @return
|
||||
*/
|
||||
std::string INLINE PIDGEN3::ValidateStringKeyInputCharset(std::string &accumulator, char currentChar)
|
||||
{
|
||||
char cchar = (char)::toupper(currentChar);
|
||||
if (std::find(pKeyCharset.begin(), pKeyCharset.end(), cchar) != pKeyCharset.end())
|
||||
{
|
||||
accumulator.push_back(cchar);
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in_key
|
||||
* @param out_key
|
||||
* @return
|
||||
*/
|
||||
BOOL PIDGEN3::ValidateKeyString(const std::string &in_key, std::string &out_key)
|
||||
{
|
||||
// copy out the product key stripping out extraneous characters
|
||||
out_key = std::accumulate(in_key.begin(), in_key.end(), std::string(), ValidateStringKeyInputCharset);
|
||||
|
||||
// only return true if we've handled exactly PK_LENGTH chars
|
||||
return (out_key.length() == PK_LENGTH);
|
||||
}
|
111
src/libumskt/pidgen3/PIDGEN3.h
Normal file
111
src/libumskt/pidgen3/PIDGEN3.h
Normal file
@ -0,0 +1,111 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/24/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_PIDGEN3_H
|
||||
#define UMSKT_PIDGEN3_H
|
||||
|
||||
#include <libumskt/pidgen.h>
|
||||
|
||||
class BINK1998;
|
||||
class BINK2002;
|
||||
|
||||
class EXPORT PIDGEN3 : public PIDGEN
|
||||
{
|
||||
friend class BINK1998;
|
||||
friend class BINK2002;
|
||||
|
||||
protected:
|
||||
Integer BINKID;
|
||||
Integer privateKey, genOrder;
|
||||
ECP::Point pubPoint, genPoint;
|
||||
ECP eCurve;
|
||||
|
||||
public:
|
||||
PIDGEN3() = default;
|
||||
|
||||
PIDGEN3(PIDGEN3 &p3)
|
||||
{
|
||||
privateKey = p3.privateKey;
|
||||
genOrder = p3.genOrder;
|
||||
pubPoint = p3.pubPoint;
|
||||
genPoint = p3.genPoint;
|
||||
eCurve = p3.eCurve;
|
||||
}
|
||||
|
||||
~PIDGEN3() override = default;
|
||||
|
||||
struct KeyInfo
|
||||
{
|
||||
BOOL isUpgrade = false, isOEM = false;
|
||||
Integer ChannelID = 0, Serial = 0, AuthInfo = 0, Rand = 0, Hash = 0, Signature = 0;
|
||||
|
||||
void setSerial(DWORD32 SerialIn)
|
||||
{
|
||||
Serial = IntegerN(SerialIn);
|
||||
}
|
||||
|
||||
void setAuthInfo(DWORD32 AuthInfoIn)
|
||||
{
|
||||
AuthInfo = IntegerN(AuthInfoIn);
|
||||
}
|
||||
|
||||
void setChannelID(DWORD32 ChannelIDIn)
|
||||
{
|
||||
ChannelID = IntegerN(ChannelIDIn);
|
||||
}
|
||||
} info;
|
||||
|
||||
static const std::string pKeyCharset;
|
||||
static const DWORD32 MaxSizeBINK1998;
|
||||
|
||||
BOOL LoadEllipticCurve(const std::string &BinkIDSel, const std::string &pSel, const std::string &aSel,
|
||||
const std::string &bSel, const std::string &generatorXSel, const std::string &generatorYSel,
|
||||
const std::string &publicKeyXSel, const std::string &publicKeyYSel,
|
||||
const std::string &genOrderSel, const std::string &privateKeySel);
|
||||
|
||||
BOOL Generate(std::string &pKey) override;
|
||||
BOOL Validate(const std::string &pKey) override;
|
||||
std::string StringifyKey(const std::string &pKey) override;
|
||||
std::string StringifyProductID() override;
|
||||
BOOL ValidateKeyString(const std::string &in_key, std::string &out_key) override;
|
||||
|
||||
virtual Integer Pack(const KeyInfo &ki)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN3::Pack() pure virtual function call");
|
||||
}
|
||||
|
||||
virtual KeyInfo Unpack(const Integer &raw)
|
||||
{
|
||||
throw std::runtime_error("PIDGEN3::Unpack() pure virtual function call");
|
||||
}
|
||||
|
||||
// PIDGEN3.cpp
|
||||
static PIDGEN3 *Factory(const std::string &field);
|
||||
static BOOL checkFieldStrIsBink1998(std::string keyin);
|
||||
static std::string ValidateStringKeyInputCharset(std::string &accumulator, char currentChar);
|
||||
static std::string base24(Integer &seq);
|
||||
static Integer unbase24(const std::string &cdKey);
|
||||
|
||||
BOOL checkFieldIsBink1998();
|
||||
};
|
||||
|
||||
#endif // UMSKT_PIDGEN3_H
|
38
src/main.cpp
Normal file
38
src/main.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Andrew on 01/06/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include <cli/cli.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int status;
|
||||
if (status = CLI::Init(argc, argv); status != 0)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
auto cli = CLI();
|
||||
status = cli.Run();
|
||||
|
||||
UMSKT::DESTRUCT();
|
||||
return status;
|
||||
}
|
40
src/rc.cpp
Normal file
40
src/rc.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 01/07/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include <cli/cli.h>
|
||||
|
||||
#include <cmrc/cmrc.hpp>
|
||||
CMRC_DECLARE(umskt);
|
||||
|
||||
/**
|
||||
* load a cmrc embedded JSON file
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::loadEmbeddedJSON()
|
||||
{
|
||||
auto fs = cmrc::umskt::get_filesystem();
|
||||
auto jsonFile = fs.open("keys.json");
|
||||
keys = json::parse(jsonFile, nullptr, false, false);
|
||||
|
||||
return true;
|
||||
}
|
104
src/typedefs.h
Normal file
104
src/typedefs.h
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/24/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#ifndef UMSKT_TYPEDEFS_H
|
||||
#define UMSKT_TYPEDEFS_H
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
// squelch the insane amount of warnings from cstdbool
|
||||
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdbool>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <stdint128>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if defined(DEBUG) || 1
|
||||
#include <cassert>
|
||||
#else
|
||||
#define assert(x) /* do nothing */
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define FNEXPORT __declspec(dllexport)
|
||||
#define FNIMPORT __declspec(dllimport)
|
||||
#define FNINLINE __forceinline
|
||||
#elif defined(__GNUC__)
|
||||
#define FNEXPORT __attribute__((visibility("default")))
|
||||
#define FNIMPORT __attribute__((visibility("default")))
|
||||
#define FNINLINE inline __attribute__((__always_inline__))
|
||||
#elif defined(__CLANG__)
|
||||
#if __has_attribute(__always_inline__)
|
||||
#define forceinline inline __attribute__((__always_inline__))
|
||||
#else
|
||||
#define forceinline inline
|
||||
#endif // __has_attribute(__always_inline__)
|
||||
#else
|
||||
#define FNEXPORT
|
||||
#define FNINLINE
|
||||
#warning "function inlining not handled"
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#define EXPORT EMSCRIPTEN_KEEPALIVE FNEXPORT
|
||||
#define INLINE FNINLINE
|
||||
#else
|
||||
#ifdef UMSKT_IMPORT_LIB
|
||||
#define EXPORT FNIMPORT
|
||||
#else
|
||||
#define EXPORT FNEXPORT
|
||||
#endif // ifdef UMSKT_IMPORT_LIB
|
||||
#define INLINE FNINLINE
|
||||
#endif // ifdef __EMSCRIPTEN__
|
||||
|
||||
// Type definitions now with more windows compatability (unfortunately)
|
||||
using BOOL = int32_t;
|
||||
using BYTE = uint8_t;
|
||||
using WORD = uint16_t;
|
||||
using DWORD = unsigned long;
|
||||
using DWORD32 = uint32_t;
|
||||
using QWORD = uint64_t;
|
||||
using OWORD = uint128_t;
|
||||
|
||||
typedef union {
|
||||
OWORD oword;
|
||||
QWORD qword[2];
|
||||
DWORD32 dword32[4];
|
||||
WORD word[8];
|
||||
BYTE byte[16];
|
||||
} Q_OWORD;
|
||||
|
||||
#endif // UMSKT_TYPEDEFS_H
|
45
src/windows/dllmain.cpp
Normal file
45
src/windows/dllmain.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/17/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "resource.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason, IN LPVOID Reserved)
|
||||
{
|
||||
|
||||
BOOLEAN bSuccess = TRUE;
|
||||
// Perform global initialization.
|
||||
switch (nReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
// For optimization.
|
||||
DisableThreadLibraryCalls(hDllHandle);
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
// end DllMain
|
BIN
src/windows/icon.ico
Normal file
BIN
src/windows/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
70
src/windows/platform.cpp
Normal file
70
src/windows/platform.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 01/07/2024
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
#include "cli/cli.h"
|
||||
#include "resource.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
BOOL CLI::loadEmbeddedJSON()
|
||||
{
|
||||
HMODULE hModule = GetModuleHandle(nullptr);
|
||||
|
||||
// Find
|
||||
HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(IDR_JSON1), "JSON");
|
||||
if (hResource == nullptr)
|
||||
{
|
||||
fmt::print("ERROR: Could not find internal JSON resource?");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load
|
||||
HGLOBAL hResourceData = LoadResource(hModule, hResource);
|
||||
if (hResourceData == nullptr)
|
||||
{
|
||||
fmt::print("ERROR: Could not load internal JSON resource?");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lock
|
||||
LPVOID pData = LockResource(hResourceData);
|
||||
if (pData == nullptr)
|
||||
{
|
||||
fmt::print("ERROR: Could not lock internal JSON resource?");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
keys = json::parse((char *)pData, nullptr, false, false);
|
||||
}
|
||||
catch (const json::exception &e)
|
||||
{
|
||||
fmt::print("ERROR: Exception occurred while parsing internal JSON file: {}\n", e.what());
|
||||
}
|
||||
|
||||
FreeResource(hResourceData);
|
||||
|
||||
return true;
|
||||
}
|
40
src/windows/resource.h
Normal file
40
src/windows/resource.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* This file is a part of the UMSKT Project
|
||||
*
|
||||
* Copyleft (C) 2019-2024 UMSKT Contributors (et.al.)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @FileCreated by Neo on 06/17/2023
|
||||
* @Maintainer Neo
|
||||
*/
|
||||
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by umskt.rc
|
||||
//
|
||||
#define IDI_ICON1 101
|
||||
#define IDR_JSON1 102
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
BIN
src/windows/umskt.rc
Normal file
BIN
src/windows/umskt.rc
Normal file
Binary file not shown.
Reference in New Issue
Block a user