mirror of
https://gitea.tendokyu.moe/self/even
synced 2024-12-18 10:35:57 +01:00
repo: initial commit
This commit is contained in:
commit
b94cd28371
246
.clang-format
Normal file
246
.clang-format
Normal file
@ -0,0 +1,246 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Microsoft
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseColons: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterExternBlock: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: false
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Leave
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
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
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: false
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigits: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigits: 0
|
||||
Hex: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
KeepEmptyLinesAtEOF: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PackConstructorInitializers: BinPack
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
...
|
||||
|
63
.gitignore
vendored
Normal file
63
.gitignore
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/c
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=c
|
||||
|
||||
### C ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c
|
||||
|
||||
*.sys
|
||||
*.base
|
||||
compile_commands.json
|
||||
*.zip
|
340
COPYING
Normal file
340
COPYING
Normal file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
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
|
||||
this service 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.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
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
|
||||
convey 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 General Public License as published by
|
||||
the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
80
Makefile
Normal file
80
Makefile
Normal file
@ -0,0 +1,80 @@
|
||||
#
|
||||
# by Frank Rysanek <rysanek@fccps.cz>
|
||||
#
|
||||
# Based on the source code of ioperm.c by Marcel Telka <marcel@telka.sk>
|
||||
# - thanks a million :-)
|
||||
#
|
||||
|
||||
# See also my_names.h
|
||||
# Note that after changing the driver name, you also have
|
||||
# to rename $(DRVNAME).c manually in this directory :-)
|
||||
DRVNAME = even
|
||||
|
||||
INCLUDES = -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/ddk
|
||||
INCLUDES +=
|
||||
|
||||
# We could in fact just add -DEVEN_DRIVER_NAME=\"$(DRVNAME)\" to CFLAGS,
|
||||
# but we'd have to be careful to "make clean" after changing
|
||||
# the driver name here in the makefile...
|
||||
#CFLAGS = -Wall $(INCLUDES) -DEVEN_DRIVER_NAME=\"$(DRVNAME)\"
|
||||
CFLAGS = -Wall $(INCLUDES)
|
||||
|
||||
# Kernel-mode libs:
|
||||
# libntoskrnl = basic kernel-mode environment
|
||||
# libhal = WRITE_PORT_UCHAR et al.
|
||||
#KRNLIBS = -lntoskrnl -lhal
|
||||
KRNLIBS = -lntoskrnl
|
||||
|
||||
CC = x86_64-w64-mingw32-gcc
|
||||
DLLTOOL = x86_64-w64-mingw32-dlltool
|
||||
STRIP = x86_64-w64-mingw32-strip
|
||||
|
||||
all: $(DRVNAME).sys
|
||||
|
||||
# Dependencies on header files:
|
||||
$(DRVNAME).sys: even_names.h
|
||||
$(DRVNAME).sys: even_ioctl.h
|
||||
|
||||
# This shall get appended to the built-in set of suffixes supported:
|
||||
.SUFFIXES: .sys .exe
|
||||
# Otherwise the custom inference rules below wouldn't ever kick in.
|
||||
|
||||
# This is implicit, no need to define this explicitly:
|
||||
#.c.o:
|
||||
# $(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
# This inference rule allows us to turn an .o into a .sys without
|
||||
# much hassle, implicitly.
|
||||
# The downside is, that you cannot potentially add further object files
|
||||
# to get linked into the .sys driver (such as, some custom ASM routines).
|
||||
# Oh wait, maybe you can... try adding your .o after the last $(CC) in the rule...
|
||||
.o.sys:
|
||||
$(CC) -Wl,--base-file,$*.base \
|
||||
-Wl,--entry,DriverEntry@8 \
|
||||
-nostartfiles -nostdlib \
|
||||
-o junk.tmp \
|
||||
$*.o \
|
||||
$(KRNLIBS)
|
||||
-rm -f junk.tmp
|
||||
$(DLLTOOL) --dllname $*.sys \
|
||||
--base-file $*.base --output-exp $*.exp
|
||||
$(CC) -Wl,--subsystem,native \
|
||||
-Wl,--image-base,0x10000 \
|
||||
-Wl,--file-alignment,0x1000 \
|
||||
-Wl,--section-alignment,0x1000 \
|
||||
-Wl,--entry,DriverEntry@8 \
|
||||
-Wl,$*.exp \
|
||||
-mdll -nostartfiles -nostdlib \
|
||||
-o $*.sys \
|
||||
$*.o \
|
||||
$(KRNLIBS)
|
||||
$(STRIP) $*.sys
|
||||
|
||||
JUNK = *.base *.exp *.o *~ junk.tmp
|
||||
|
||||
clean:
|
||||
rm -f $(JUNK) *.sys
|
||||
|
||||
semiclean:
|
||||
rm -f $(JUNK)
|
||||
|
438
even.c
Normal file
438
even.c
Normal file
@ -0,0 +1,438 @@
|
||||
/*
|
||||
* even.sys - a stub for Htsysm7679
|
||||
* Copyright (C) 2024 Zephyr Lykos <self@mochaa.ws>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include "even_ioctl.h"
|
||||
#include "even_names.h"
|
||||
|
||||
#define uthash_nonfatal_oom(obj) do {return STATUS_INTERNAL_ERROR;} while (0)
|
||||
|
||||
#include "even_peb.h"
|
||||
#include "uthash.h"
|
||||
|
||||
/*
|
||||
* Htsysm7679 constatns
|
||||
*/
|
||||
|
||||
USE_EVEN_IOCTL_OUT_DATA(1);
|
||||
USE_EVEN_IOCTL_OUT_DATA(2);
|
||||
|
||||
const struct even_ioctl_out_data1 htsysm_check_1 = {.result = 1, .data = {0x64, 0xBC, 0xD4, 0x56}};
|
||||
const struct even_ioctl_out_data2 htsysm_check_2 = {
|
||||
.result = 1,
|
||||
.data = {0x00, 0x00, 0x59, 0x26, 0x04, 0xF8, 0xFF, 0xFF},
|
||||
};
|
||||
const struct even_ioctl_out_data1 htsysm_check_3 = {.result = 1, .data = {0x48, 0xB3, 0xF7, 0x97}};
|
||||
|
||||
static VOID __stdcall even_unload(IN PDRIVER_OBJECT DriverObject)
|
||||
{
|
||||
ANSI_STRING SymbolicLinkNameA;
|
||||
UNICODE_STRING SymbolicLinkNameW;
|
||||
|
||||
DbgPrint("Even Htsysm7679: DriverUnload called\r\n"); // catch this using DBGVIEW from www.sysinternals.com
|
||||
|
||||
/*RtlInitUnicodeString( &SymbolicLinkName, EVEN_DOSDEVICE_NAME );*/
|
||||
/* If I want to use normal string combining logic in my_names.h, I need to mess with ANSI vs. Unicode */
|
||||
RtlInitString(&SymbolicLinkNameA, EVEN_DOSDEVICE_NAME);
|
||||
RtlAnsiStringToUnicodeString(&SymbolicLinkNameW, &SymbolicLinkNameA,
|
||||
TRUE); /* Init from an ANSI string, and do allocate target buffer */
|
||||
|
||||
IoDeleteSymbolicLink(&SymbolicLinkNameW);
|
||||
IoDeleteDevice(DriverObject->DeviceObject);
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall even_dispatch_create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
struct even_peb *fake_peb = NULL;
|
||||
|
||||
static NTSTATUS __stdcall even_create_peb(HANDLE pid)
|
||||
{
|
||||
struct even_peb *s;
|
||||
|
||||
HASH_FIND_INT(fake_peb, &pid, s);
|
||||
if (s == NULL) {
|
||||
s = ExAllocatePool(PagedPool, sizeof(*s));
|
||||
s->pid = pid;
|
||||
|
||||
PROCESS_BASIC_INFORMATION ProcessInformation;
|
||||
NtQueryInformationProcess(
|
||||
pid,
|
||||
ProcessBasicInformation,
|
||||
&ProcessInformation,
|
||||
sizeof(ProcessInformation),
|
||||
NULL
|
||||
);
|
||||
|
||||
RtlCopyMemory(&s->fake_peb, ProcessInformation.PebBaseAddress, sizeof(*ProcessInformation.PebBaseAddress));
|
||||
|
||||
HASH_ADD_INT(fake_peb, pid, s);
|
||||
}
|
||||
|
||||
s->refcnt += 1;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall even_delete_peb(struct even_peb* peb)
|
||||
{
|
||||
DbgPrint("Even Htsysm7679: PEB Refcnt for PID %d: %d\r\n", peb->pid, peb->refcnt);
|
||||
if (peb->refcnt <= 0) {
|
||||
DbgPrint("Even Htsysm7679: PEB Refcnt <= 0, deleting\r\n");
|
||||
HASH_DEL(fake_peb, peb);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
peb->refcnt -= 1;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall *even_find_peb(IN HANDLE pid, OUT struct even_peb *s)
|
||||
{
|
||||
HASH_FIND_INT(fake_peb, &pid, s);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall even_open_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(DeviceObject);
|
||||
|
||||
PIO_STACK_LOCATION io_stack;
|
||||
io_stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
if (!(io_stack)) /* do we have a valid io_stack? */
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
switch (io_stack->MajorFunction)
|
||||
{
|
||||
case IRP_MJ_CREATE:
|
||||
if (pid == 0) goto err_out;
|
||||
DbgPrint("Even Htsysm7679: Handle to symbolink link opened by PID %d\r\n", pid);
|
||||
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Status = even_create_peb(pid);
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
case IRP_MJ_CLOSE:
|
||||
if (pid == 0) goto err_out;
|
||||
DbgPrint("Even Htsysm7679: Handle to symbolink link closed by PID %d\r\n", pid);
|
||||
|
||||
struct even_peb s;
|
||||
even_find_peb(pid, &s);
|
||||
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Status = even_delete_peb(&s);
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
err_out:
|
||||
|
||||
/* complete IRP request */
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
static NTSTATUS __stdcall even_dispatch_device_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(DeviceObject);
|
||||
|
||||
PIO_STACK_LOCATION io_stack;
|
||||
|
||||
/* default return values */
|
||||
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
/* get current I/O stack location */
|
||||
io_stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
if (!(io_stack)) /* do we have a valid io_stack? */
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
/* if this fires, we've hooked up the ioctl() handler to the wrong callback slot */
|
||||
if (io_stack->MajorFunction != IRP_MJ_DEVICE_CONTROL)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
switch (io_stack->Parameters.DeviceIoControl.IoControlCode)
|
||||
{
|
||||
case IOCTL_CHECK_1: {
|
||||
if (io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(htsysm_check_1))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
RtlCopyBytes(Irp->AssociatedIrp.SystemBuffer, &htsysm_check_1, sizeof(htsysm_check_1));
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(htsysm_check_1);
|
||||
DbgPrint("Even Htsysm7679: Check 1\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_CHECK_2: {
|
||||
if (io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(htsysm_check_2))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
RtlCopyBytes(Irp->AssociatedIrp.SystemBuffer, &htsysm_check_2, sizeof(htsysm_check_2));
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(htsysm_check_2);
|
||||
DbgPrint("Even Htsysm7679: Check 2\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_CHECK_3: {
|
||||
if (io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(htsysm_check_3))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
RtlCopyBytes(Irp->AssociatedIrp.SystemBuffer, &htsysm_check_3, sizeof(htsysm_check_3));
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(htsysm_check_3);
|
||||
DbgPrint("Even Htsysm7679: Check 3\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_WRITE_PEB_1: {
|
||||
struct even_ioctl_in_data *even_in_data = (struct even_ioctl_in_data *)Irp->AssociatedIrp.SystemBuffer;
|
||||
struct even_ioctl_out_data *even_out_data = (struct even_ioctl_out_data *)Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
if ((io_stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct even_ioctl_in_data)) ||
|
||||
(!even_in_data) ||
|
||||
(io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(struct even_ioctl_out_data1)) ||
|
||||
(!even_out_data))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
struct even_peb s;
|
||||
|
||||
if ((even_in_data->offset + 4) > sizeof(s.fake_peb))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
};
|
||||
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
if (even_find_peb(pid, &s) != STATUS_SUCCESS) {
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
void* fake_peb;
|
||||
fake_peb = &s.fake_peb;
|
||||
|
||||
int value;
|
||||
RtlCopyBytes(&value, even_in_data->value, sizeof(value));
|
||||
value = ~value;
|
||||
|
||||
DbgPrint("Even Htsysm7679: Write PEB 1\r\n");
|
||||
DbgPrint("Even Htsysm7679: Offset = %0x, Value = %0x\r\n", even_in_data->offset, value);
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
((char *)fake_peb)[even_in_data->offset + i] = ((char *)&value)[i];
|
||||
}
|
||||
|
||||
even_out_data->result = 1;
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(*even_out_data);
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_WRITE_PEB_2: {
|
||||
struct even_ioctl_in_data *even_in_data = (struct even_ioctl_in_data *)Irp->AssociatedIrp.SystemBuffer;
|
||||
struct even_ioctl_out_data *even_out_data = (struct even_ioctl_out_data *)Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
if ((io_stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct even_ioctl_in_data)) ||
|
||||
(!even_in_data) ||
|
||||
(io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(struct even_ioctl_out_data1)) ||
|
||||
(!even_out_data))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
struct even_peb s;
|
||||
|
||||
if ((even_in_data->offset + 4) > sizeof(s.fake_peb))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
};
|
||||
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
if (even_find_peb(pid, &s) != STATUS_SUCCESS) {
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
void* fake_peb;
|
||||
fake_peb = &s.fake_peb;
|
||||
|
||||
int value;
|
||||
RtlCopyBytes(&value, even_in_data->value, sizeof(value));
|
||||
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
((char *)fake_peb)[even_in_data->offset + i] = ((char *)&value)[i];
|
||||
}
|
||||
|
||||
even_out_data->result = 1;
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(*even_out_data);
|
||||
DbgPrint("Even Htsysm7679: Write PEB 2\r\n");
|
||||
DbgPrint("Even Htsysm7679: Offset = %0x, Value = %0x\r\n", even_in_data->offset, value);
|
||||
}
|
||||
break;
|
||||
|
||||
case IOCTL_READ_PEB: {
|
||||
struct even_ioctl_in_data *even_in_data = (struct even_ioctl_in_data *)Irp->AssociatedIrp.SystemBuffer;
|
||||
struct even_ioctl_out_data1 *even_out_data = (struct even_ioctl_out_data1 *)Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
if ((io_stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(struct even_ioctl_in_data)) ||
|
||||
(!even_in_data) ||
|
||||
(io_stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(struct even_ioctl_out_data1)) ||
|
||||
(!even_out_data))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
struct even_peb s;
|
||||
|
||||
if ((even_in_data->offset + 4) > sizeof(s.fake_peb))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
|
||||
goto err_out;
|
||||
};
|
||||
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
if (even_find_peb(pid, &s) != STATUS_SUCCESS) {
|
||||
Irp->IoStatus.Status = STATUS_INTERNAL_ERROR;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
|
||||
void* fake_peb;
|
||||
fake_peb = &s.fake_peb;
|
||||
|
||||
char value[4];
|
||||
RtlCopyBytes(&value, fake_peb + (even_in_data->offset), sizeof(value));
|
||||
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
value[i] &= value[i];
|
||||
}
|
||||
|
||||
even_out_data->result = 1;
|
||||
RtlCopyMemory(even_out_data->data, value, sizeof(value));
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = sizeof(*even_out_data);
|
||||
DbgPrint("Even Htsysm7679: Read PEB\r\n");
|
||||
DbgPrint("Even Htsysm7679: Offset = %0x, Value = %0x\r\n", even_in_data->offset, *(int *)even_in_data->value);
|
||||
DbgPrint("Even Htsysm7679: Return = %0x\r\n", *(int *)value);
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* STATUS_NOT_IMPLEMENTED takes action */
|
||||
break;
|
||||
}
|
||||
|
||||
err_out:
|
||||
|
||||
/* complete IRP request */
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
NTSTATUS __stdcall
|
||||
DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
|
||||
{
|
||||
NTSTATUS status;
|
||||
/* a particular Device Instance, theoretically one of many,
|
||||
managed by this driver : */
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
UNICODE_STRING DeviceNameW;
|
||||
UNICODE_STRING SymbolicLinkNameW;
|
||||
ANSI_STRING DeviceNameA;
|
||||
ANSI_STRING SymbolicLinkNameA;
|
||||
|
||||
DbgPrint("Even Htsysm7679: DriverEntry Called\r\n"); // catch this using DBGVIEW from www.sysinternals.com
|
||||
|
||||
/* support for service stopping */
|
||||
DriverObject->DriverUnload = even_unload;
|
||||
/* create support */
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = even_dispatch_create;
|
||||
/* IOCTL support */
|
||||
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = even_dispatch_device_control;
|
||||
/* Open/close support */
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = even_open_close;
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = even_open_close;
|
||||
|
||||
/* initialize counted unicode strings */
|
||||
RtlInitString(&DeviceNameA, EVEN_DEVICE_NAME);
|
||||
RtlAnsiStringToUnicodeString(&DeviceNameW, &DeviceNameA,
|
||||
TRUE); /* Init from an ANSI string, and do allocate target buffer */
|
||||
RtlInitString(&SymbolicLinkNameA, EVEN_DOSDEVICE_NAME);
|
||||
RtlAnsiStringToUnicodeString(&SymbolicLinkNameW, &SymbolicLinkNameA,
|
||||
TRUE); /* Init from an ANSI string, and do allocate target buffer */
|
||||
|
||||
/* create device object */
|
||||
status = IoCreateDevice(DriverObject, 0, &DeviceNameW, 0xaa01, 0, FALSE, &DeviceObject);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||
|
||||
/* create user-visible name for the device */
|
||||
status = IoCreateSymbolicLink(&SymbolicLinkNameW, &DeviceNameW);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// vim: sw=4 et
|
46
even_ioctl.h
Normal file
46
even_ioctl.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef _MY_IOCTL_H_
|
||||
#define _MY_IOCTL_H_ 1
|
||||
|
||||
/*
|
||||
METHOD_BUFFERED handles the copy_to_user/copy_from_user automagically for us, at the cost of some overhead
|
||||
METHOD_OUT_DIRECT = no automagical copy, MDL set up for "Kernel_driver -> User_mode_app" direction
|
||||
METHOD_IN_DIRECT = no automagical copy, MDL set up for "User_mode_app -> Kernel_driver" direction
|
||||
METHOD_NEITHER = no automagical copy, no automagical MDL setup. Driver (ioctl code) must be guaranteed
|
||||
to run in the context of the calling user-space thread and ask for the user->system
|
||||
mapping itself, and its access to the buffer should be wrapped in a try/catch to handle
|
||||
potential exceptions...
|
||||
|
||||
That's right, DIRECT IN/OUT are from the driver's point of view, relative to the user-space app!!!
|
||||
Both the MSDN and the Coreproject.com article say so, the CodeProject article with added emphasis.
|
||||
*/
|
||||
|
||||
/* CTL Codes above 0x800 are free for your custom use
|
||||
Note: using METHOD_BUFFERED = we're lazy and we don't care about a bit of overhead */
|
||||
|
||||
#define IOCTL_CHECK_1 CTL_CODE(0xaa01, 0xe10, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_CHECK_2 CTL_CODE(0xaa01, 0xe30, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_CHECK_3 CTL_CODE(0xaa01, 0xe31, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_WRITE_PEB_1 CTL_CODE(0xaa01, 0xe20, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_WRITE_PEB_2 CTL_CODE(0xaa01, 0xe21, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_READ_PEB CTL_CODE(0xaa01, 0xe22, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
struct even_ioctl_in_data
|
||||
{
|
||||
unsigned int offset;
|
||||
char value[4];
|
||||
};
|
||||
|
||||
struct even_ioctl_out_data
|
||||
{
|
||||
int result;
|
||||
};
|
||||
|
||||
#define USE_EVEN_IOCTL_OUT_DATA(x) \
|
||||
struct even_ioctl_out_data##x \
|
||||
{ \
|
||||
unsigned int result; \
|
||||
char data[x * 4]; \
|
||||
};
|
||||
|
||||
#endif /* _MY_IOCTL_H_ */
|
||||
// vim: sw=4 et
|
15
even_names.h
Normal file
15
even_names.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _EVEN_NAMES_H_
|
||||
#define _EVEN_NAMES_H_ 1
|
||||
|
||||
/* Remember: two "string literals" "will get concatenated into one"
|
||||
if there's no punctuation between them:
|
||||
"hello" "world" => "hello world"
|
||||
*/
|
||||
#ifndef EVEN_DRIVER_NAME
|
||||
#define EVEN_DRIVER_NAME "Htsysm7679" /* not used itself outside of this header file */
|
||||
#endif
|
||||
/* for the driver */
|
||||
#define EVEN_DEVICE_NAME "\\Device\\" EVEN_DRIVER_NAME
|
||||
#define EVEN_DOSDEVICE_NAME "\\DosDevices\\" EVEN_DRIVER_NAME /* AKA symlink name */
|
||||
|
||||
#endif /* _EVEN_NAMES_H_ */
|
55
even_peb.h
Normal file
55
even_peb.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef _EVEN_PEB_H_
|
||||
#define _EVEN_PEB_H_ 1
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <minwindef.h>
|
||||
#include "uthash.h"
|
||||
|
||||
typedef struct _PEB_LDR_DATA {
|
||||
BYTE Reserved1[8];
|
||||
PVOID Reserved2[3];
|
||||
LIST_ENTRY InMemoryOrderModuleList;
|
||||
} PEB_LDR_DATA,*PPEB_LDR_DATA;
|
||||
|
||||
typedef struct _RTL_USER_PROCESS_PARAMETERS {
|
||||
BYTE Reserved1[16];
|
||||
PVOID Reserved2[10];
|
||||
UNICODE_STRING ImagePathName;
|
||||
UNICODE_STRING CommandLine;
|
||||
} RTL_USER_PROCESS_PARAMETERS,*PRTL_USER_PROCESS_PARAMETERS;
|
||||
|
||||
/* This function pointer is undocumented and just valid for windows 2000.
|
||||
Therefore I guess. */
|
||||
typedef VOID (NTAPI *PPS_POST_PROCESS_INIT_ROUTINE)(VOID);
|
||||
|
||||
typedef struct _PEB {
|
||||
BYTE Reserved1[2];
|
||||
BYTE BeingDebugged;
|
||||
BYTE Reserved2[1];
|
||||
PVOID Reserved3[2];
|
||||
PPEB_LDR_DATA Ldr;
|
||||
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
|
||||
PVOID Reserved4[3];
|
||||
PVOID AtlThunkSListPtr;
|
||||
PVOID Reserved5;
|
||||
ULONG Reserved6;
|
||||
PVOID Reserved7;
|
||||
ULONG Reserved8;
|
||||
ULONG AtlThunkSListPtr32;
|
||||
PVOID Reserved9[45];
|
||||
BYTE Reserved10[96];
|
||||
PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
|
||||
BYTE Reserved11[128];
|
||||
PVOID Reserved12[1];
|
||||
ULONG SessionId;
|
||||
} PEB,*PPEB;
|
||||
|
||||
struct even_peb {
|
||||
HANDLE pid;
|
||||
int refcnt;
|
||||
PEB fake_peb;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
#endif
|
||||
// vim: sw=4 et
|
Loading…
Reference in New Issue
Block a user