Skip to content

Commit

Permalink
large refactoring
Browse files Browse the repository at this point in the history
- inject: fix some mutexes not unlocked
- inject: fix invalid socket selection
- inject: fix some invalid memory reads
- inject: fix memory leaks
- inject: reformat and refactor code
- inject: move inject to autopunch-inject/
- inject: better debug logs
- inject: use a relay hostname rather than IP
- loader: fix NULs in UTF16 strings
  • Loading branch information
delthas committed Apr 9, 2020
1 parent 7037868 commit 51afc8a
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 281 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
*.exe
*.dll
.vs
.idea
cmake-*
CMakeSettings.json*
*.exe
/autopunch-loader/dll*.go
/autopunch-loader/address.go
*.syso
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "detours"]
path = detours
url = https://github.com/microsoft/Detours.git
[submodule "autopunch-inject/detours"]
path = autopunch-inject/detours
url = git@github.com:microsoft/Detours.git
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
## Building

Quick overview of the components of the project:
- `inject.c`: the core autopunch DLL, that is injected into a game; has both 32 and 64 bit versions, release and debug versions;
- `inject`: the core autopunch DLL, that is injected into a game; has both 32 and 64 bit versions, release and debug versions;
- `address`: a tiny program to get the address of the `LoadLibraryW` function of the WoW `Kernel32` module; this works because ASLR is only done once per reboot;
- `packer`: a tiny program to pack a binary file as a string in a Go source file so that it can be included in an executable;
- `relay`: the STUN-like relay used by autopunch;
Expand All @@ -53,8 +53,8 @@ Preparation:
Build order:
- build `address` with CMake, compiling with `i686-w64-mingw32-gcc`, profile MinSizeRel;
- build `packer` with Go; `go install` it / add it to your PATH;
- build `inject.c` (at the root) with CMake four times: Debug and Release, for Visual C++ Build Tools x86 and x64; use the `autopunch_copy` target to put the DLLs in the right folder for next steps;
- build `inject` with CMake four times: Debug and Release, for Visual C++ Build Tools x86 and x64; use the `autopunch_copy` target to put the DLLs in the right folder for next steps;
- generate `loader` with: `go generate loader.go`;
- build `loader` twice, targeting GOARCH=amd64 then GOARCH=386, GOOS=windows, with: `go build -ldflags="-H windowsgui -s -w -X main.version=<version>" -tags walk_use_cgo`; `version` is e.g. `v0.0.1`.
- build `loader` twice, targeting GOARCH=amd64 then GOARCH=386, GOOS=windows, with: `go build -ldflags="-H windowsgui -s -w -X main.version=<version>"`; `version` is e.g. `v0.0.1`.

Building the relay (Go) is straightforward.
133 changes: 72 additions & 61 deletions .clang-format → autopunch-inject/.clang-format
Original file line number Diff line number Diff line change
@@ -1,61 +1,72 @@
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 160
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 2
UseTab: Always
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 160
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<windows\.h>'
Priority: 1
SortPriority: 1
- Regex: '^<winsock2\.h>'
Priority: 1
SortPriority: 2
- Regex: '.*'
Priority: 1
SortPriority: 3
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 2
UseTab: Always
4 changes: 2 additions & 2 deletions CMakeLists.txt → autopunch-inject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ else()
set(TARGET_FILE_BUILD rel)
endif()

add_custom_target(autopunch_copy DEPENDS autopunch COMMAND_EXPAND_LISTS VERBATIM
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:autopunch> ${CMAKE_SOURCE_DIR}/autopunch-loader/autopunch.x${TARGET_FILE_BITS}.${TARGET_FILE_BUILD}.dll)
add_custom_target(autopunch_copy ALL DEPENDS autopunch COMMAND_EXPAND_LISTS VERBATIM
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:autopunch> ${CMAKE_SOURCE_DIR}/../autopunch-loader/autopunch.x${TARGET_FILE_BITS}.${TARGET_FILE_BUILD}.dll)
1 change: 1 addition & 0 deletions autopunch-inject/detours
Submodule detours added at 64ec13
Loading

0 comments on commit 51afc8a

Please sign in to comment.