├── .github └── workflows │ └── main.yml ├── .gitignore ├── Changelog.md ├── DebugEnhancer.xcodeproj └── project.pbxproj ├── DebugEnhancer ├── Info.plist ├── kern_dbgenhancer.cpp ├── kern_dbgenhancer.hpp └── kern_start.cpp ├── LICENSE.txt └── README.md /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | release: 8 | types: [published] 9 | 10 | env: 11 | PROJECT_TYPE: KEXT 12 | 13 | jobs: 14 | build: 15 | name: Build 16 | runs-on: macos-latest 17 | env: 18 | JOB_TYPE: BUILD 19 | steps: 20 | - uses: actions/checkout@v4 21 | - uses: actions/checkout@v4 22 | with: 23 | repository: acidanthera/MacKernelSDK 24 | path: MacKernelSDK 25 | - name: CI Bootstrap 26 | run: | 27 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/ci-bootstrap.sh) && eval "$src" || exit 1 28 | - name: Lilu Bootstrap 29 | run: | 30 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/Lilu/master/Lilu/Scripts/bootstrap.sh) && eval "$src" || exit 1 31 | 32 | - run: xcodebuild -jobs 1 -configuration Debug 33 | - run: xcodebuild -jobs 1 -configuration Release 34 | 35 | - name: Upload to Artifacts 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: Artifacts 39 | path: build/*/*.zip 40 | - name: Upload to Release 41 | if: github.event_name == 'release' 42 | uses: svenstaro/upload-release-action@v2 43 | with: 44 | repo_token: ${{ secrets.GITHUB_TOKEN }} 45 | file: build/*/*.zip 46 | tag: ${{ github.ref }} 47 | file_glob: true 48 | 49 | analyze-clang: 50 | name: Analyze Clang 51 | runs-on: macos-latest 52 | env: 53 | JOB_TYPE: ANALYZE 54 | steps: 55 | - uses: actions/checkout@v4 56 | - uses: actions/checkout@v4 57 | with: 58 | repository: acidanthera/MacKernelSDK 59 | path: MacKernelSDK 60 | - name: CI Bootstrap 61 | run: | 62 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/ci-bootstrap.sh) && eval "$src" || exit 1 63 | - name: Lilu Bootstrap 64 | run: | 65 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/Lilu/master/Lilu/Scripts/bootstrap.sh) && eval "$src" || exit 1 66 | 67 | - run: xcodebuild analyze -quiet -scheme DebugEnhancer -configuration Debug CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang-analyze" && [ "$(find clang-analyze -name "*.html")" = "" ] 68 | - run: xcodebuild analyze -quiet -scheme DebugEnhancer -configuration Release CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang-analyze" && [ "$(find clang-analyze -name "*.html")" = "" ] 69 | 70 | analyze-coverity: 71 | name: Analyze Coverity 72 | runs-on: macos-latest 73 | env: 74 | JOB_TYPE: COVERITY 75 | if: github.repository_owner == 'acidanthera' && github.event_name != 'pull_request' 76 | steps: 77 | - uses: actions/checkout@v4 78 | - uses: actions/checkout@v4 79 | with: 80 | repository: acidanthera/MacKernelSDK 81 | path: MacKernelSDK 82 | - name: CI Bootstrap 83 | run: | 84 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/ci-bootstrap.sh) && eval "$src" || exit 1 85 | - name: Lilu Bootstrap 86 | run: | 87 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/Lilu/master/Lilu/Scripts/bootstrap.sh) && eval "$src" || exit 1 88 | 89 | - name: Run Coverity 90 | run: | 91 | src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/acidanthera/ocbuild/master/coverity/covstrap.sh) && eval "$src" || exit 1 92 | env: 93 | COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} 94 | COVERITY_SCAN_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }} 95 | COVERITY_BUILD_COMMAND: xcodebuild -configuration Release 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | DerivedData 3 | Lilu.kext 4 | xcuserdata 5 | xcshareddata 6 | project.xcworkspace 7 | /MacKernelSDK 8 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | DebugEnhancer Changelog 2 | ============================ 3 | #### v1.1.0 4 | - Fixed loading on macOS 10.10 and older due to a MacKernelSDK regression 5 | 6 | #### v1.0.9 7 | - Added constants for macOS 15 support 8 | 9 | #### v1.0.8 10 | - Added constants for macOS 14 support 11 | 12 | #### v1.0.7 13 | - Added constants for macOS 13 support 14 | 15 | #### v1.0.6 16 | - Workaround for macos 12 (Monterey) and higher: do not use log_setsize 17 | 18 | #### v1.0.5 19 | - Support boot-arg `-dbgenhiolog` to redirect IOLog output to kernel vprintf 20 | 21 | #### v1.0.4 22 | - Use method routeMultipleLong instead of routeMultiple in order to avoid conflict with HibernationFixup 23 | 24 | #### v1.0.3 25 | - Added constants for macOS 12 support 26 | 27 | #### v1.0.2 28 | - Added MacKernelSDK with Xcode 12 compatibility 29 | 30 | #### v1.0.1 31 | - Added constants for 11.0 support 32 | 33 | #### v1.0.0 34 | - Initial release 35 | -------------------------------------------------------------------------------- /DebugEnhancer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CE405ED91E4A080700AA0B3D /* plugin_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE405ED81E4A080700AA0B3D /* plugin_start.cpp */; }; 11 | CE8DA0DA2517E21D008C44E8 /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE8DA0D92517E21D008C44E8 /* libkmod.a */; }; 12 | F654D35E1F6DA4FF00D29D64 /* kern_dbgenhancer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F654D35C1F6DA4FF00D29D64 /* kern_dbgenhancer.cpp */; }; 13 | F654D35F1F6DA4FF00D29D64 /* kern_dbgenhancer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F654D35D1F6DA4FF00D29D64 /* kern_dbgenhancer.hpp */; }; 14 | F6769743238FCF8000FDA3EE /* kern_start.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6769742238FCF8000FDA3EE /* kern_start.cpp */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXCopyFilesBuildPhase section */ 18 | 1C642F521C8F157A006B4C51 /* CopyFiles */ = { 19 | isa = PBXCopyFilesBuildPhase; 20 | buildActionMask = 2147483647; 21 | dstPath = ""; 22 | dstSubfolderSpec = 13; 23 | files = ( 24 | ); 25 | runOnlyForDeploymentPostprocessing = 0; 26 | }; 27 | /* End PBXCopyFilesBuildPhase section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 1C748C271C21952C0024EED2 /* DebugEnhancer.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DebugEnhancer.kext; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 1C748C2E1C21952C0024EED2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 1CF01C901C8CF97F002DCEA3 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 33 | 1CF01C921C8CF997002DCEA3 /* Changelog.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Changelog.md; sourceTree = ""; }; 34 | 1CF01C931C8DF02E002DCEA3 /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = ""; }; 35 | CE405EBA1E49DD7100AA0B3D /* kern_compression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_compression.hpp; sourceTree = ""; }; 36 | CE405EBB1E49DD7100AA0B3D /* kern_disasm.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_disasm.hpp; sourceTree = ""; }; 37 | CE405EBC1E49DD7100AA0B3D /* kern_file.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_file.hpp; sourceTree = ""; }; 38 | CE405EBD1E49DD7100AA0B3D /* kern_iokit.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_iokit.hpp; sourceTree = ""; }; 39 | CE405EBE1E49DD7100AA0B3D /* kern_mach.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_mach.hpp; sourceTree = ""; }; 40 | CE405EBF1E49DD7100AA0B3D /* kern_patcher.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_patcher.hpp; sourceTree = ""; }; 41 | CE405EC01E49DD7100AA0B3D /* kern_policy.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_policy.hpp; sourceTree = ""; }; 42 | CE405EC31E49DD7100AA0B3D /* kern_user.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_user.hpp; sourceTree = ""; }; 43 | CE405EC41E49DD7100AA0B3D /* kern_util.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_util.hpp; sourceTree = ""; }; 44 | CE405EC61E49DD7100AA0B3D /* LegacyIOService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LegacyIOService.h; sourceTree = ""; }; 45 | CE405EC71E49DD7100AA0B3D /* libkmod.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libkmod.a; sourceTree = ""; }; 46 | CE405ECF1E49EC9100AA0B3D /* kern_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_config.hpp; sourceTree = ""; }; 47 | CE405ED21E49F9FC00AA0B3D /* kern_api.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_api.hpp; sourceTree = ""; }; 48 | CE405ED81E4A080700AA0B3D /* plugin_start.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_start.cpp; sourceTree = ""; }; 49 | CE405EDA1E4A080F00AA0B3D /* plugin_start.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = plugin_start.hpp; sourceTree = ""; }; 50 | CE8DA0D92517E21D008C44E8 /* libkmod.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libkmod.a; path = ../Lilu/MacKernelSDK/Library/x86_64/libkmod.a; sourceTree = ""; }; 51 | F654D35C1F6DA4FF00D29D64 /* kern_dbgenhancer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kern_dbgenhancer.cpp; sourceTree = ""; }; 52 | F654D35D1F6DA4FF00D29D64 /* kern_dbgenhancer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = kern_dbgenhancer.hpp; sourceTree = ""; }; 53 | F6769742238FCF8000FDA3EE /* kern_start.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = kern_start.cpp; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 1C748C231C21952C0024EED2 /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | CE8DA0DA2517E21D008C44E8 /* libkmod.a in Frameworks */, 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | 1C748C1D1C21952C0024EED2 = { 69 | isa = PBXGroup; 70 | children = ( 71 | 1CF01C911C8CF982002DCEA3 /* Docs */, 72 | 1C748C291C21952C0024EED2 /* DebugEnhancer */, 73 | CE405EC81E49DD7B00AA0B3D /* SDK */, 74 | 1C748C281C21952C0024EED2 /* Products */, 75 | CE8DA0D82517E21D008C44E8 /* Frameworks */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 1C748C281C21952C0024EED2 /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 1C748C271C21952C0024EED2 /* DebugEnhancer.kext */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | 1C748C291C21952C0024EED2 /* DebugEnhancer */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | F654D35C1F6DA4FF00D29D64 /* kern_dbgenhancer.cpp */, 91 | F654D35D1F6DA4FF00D29D64 /* kern_dbgenhancer.hpp */, 92 | F6769742238FCF8000FDA3EE /* kern_start.cpp */, 93 | 1C748C2E1C21952C0024EED2 /* Info.plist */, 94 | ); 95 | path = DebugEnhancer; 96 | sourceTree = ""; 97 | }; 98 | 1CF01C911C8CF982002DCEA3 /* Docs */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 1CF01C901C8CF97F002DCEA3 /* README.md */, 102 | 1CF01C931C8DF02E002DCEA3 /* LICENSE.txt */, 103 | 1CF01C921C8CF997002DCEA3 /* Changelog.md */, 104 | ); 105 | name = Docs; 106 | sourceTree = ""; 107 | }; 108 | CE405EB91E49DD7100AA0B3D /* Headers */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | CE405ED21E49F9FC00AA0B3D /* kern_api.hpp */, 112 | CE405ECF1E49EC9100AA0B3D /* kern_config.hpp */, 113 | CE405EBA1E49DD7100AA0B3D /* kern_compression.hpp */, 114 | CE405EBB1E49DD7100AA0B3D /* kern_disasm.hpp */, 115 | CE405EBC1E49DD7100AA0B3D /* kern_file.hpp */, 116 | CE405EBD1E49DD7100AA0B3D /* kern_iokit.hpp */, 117 | CE405EBE1E49DD7100AA0B3D /* kern_mach.hpp */, 118 | CE405EBF1E49DD7100AA0B3D /* kern_patcher.hpp */, 119 | CE405EC01E49DD7100AA0B3D /* kern_policy.hpp */, 120 | CE405EC31E49DD7100AA0B3D /* kern_user.hpp */, 121 | CE405EC41E49DD7100AA0B3D /* kern_util.hpp */, 122 | CE405EDA1E4A080F00AA0B3D /* plugin_start.hpp */, 123 | ); 124 | name = Headers; 125 | path = Lilu.kext/Contents/Resources/Headers; 126 | sourceTree = SOURCE_ROOT; 127 | }; 128 | CE405EC51E49DD7100AA0B3D /* Library */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | CE405EC61E49DD7100AA0B3D /* LegacyIOService.h */, 132 | CE405EC71E49DD7100AA0B3D /* libkmod.a */, 133 | CE405ED81E4A080700AA0B3D /* plugin_start.cpp */, 134 | ); 135 | name = Library; 136 | path = Lilu.kext/Contents/Resources/Library; 137 | sourceTree = SOURCE_ROOT; 138 | }; 139 | CE405EC81E49DD7B00AA0B3D /* SDK */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | CE405EB91E49DD7100AA0B3D /* Headers */, 143 | CE405EC51E49DD7100AA0B3D /* Library */, 144 | ); 145 | name = SDK; 146 | sourceTree = ""; 147 | }; 148 | CE8DA0D82517E21D008C44E8 /* Frameworks */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | CE8DA0D92517E21D008C44E8 /* libkmod.a */, 152 | ); 153 | name = Frameworks; 154 | sourceTree = ""; 155 | }; 156 | /* End PBXGroup section */ 157 | 158 | /* Begin PBXHeadersBuildPhase section */ 159 | 1C748C241C21952C0024EED2 /* Headers */ = { 160 | isa = PBXHeadersBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | F654D35F1F6DA4FF00D29D64 /* kern_dbgenhancer.hpp in Headers */, 164 | ); 165 | runOnlyForDeploymentPostprocessing = 0; 166 | }; 167 | /* End PBXHeadersBuildPhase section */ 168 | 169 | /* Begin PBXNativeTarget section */ 170 | 1C748C261C21952C0024EED2 /* DebugEnhancer */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = 1C748C311C21952C0024EED2 /* Build configuration list for PBXNativeTarget "DebugEnhancer" */; 173 | buildPhases = ( 174 | 1C748C221C21952C0024EED2 /* Sources */, 175 | 1C748C231C21952C0024EED2 /* Frameworks */, 176 | 1C748C241C21952C0024EED2 /* Headers */, 177 | 1C748C251C21952C0024EED2 /* Resources */, 178 | 1C642F521C8F157A006B4C51 /* CopyFiles */, 179 | CEC51E902121A15900F1F49A /* Archive */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | ); 185 | name = DebugEnhancer; 186 | productName = DebugEnhancerDebugEnhancer; 187 | productReference = 1C748C271C21952C0024EED2 /* DebugEnhancer.kext */; 188 | productType = "com.apple.product-type.kernel-extension"; 189 | }; 190 | /* End PBXNativeTarget section */ 191 | 192 | /* Begin PBXProject section */ 193 | 1C748C1E1C21952C0024EED2 /* Project object */ = { 194 | isa = PBXProject; 195 | attributes = { 196 | LastUpgradeCheck = 1200; 197 | ORGANIZATIONNAME = vit9696; 198 | TargetAttributes = { 199 | 1C748C261C21952C0024EED2 = { 200 | CreatedOnToolsVersion = 7.2; 201 | }; 202 | }; 203 | }; 204 | buildConfigurationList = 1C748C211C21952C0024EED2 /* Build configuration list for PBXProject "DebugEnhancer" */; 205 | compatibilityVersion = "Xcode 3.2"; 206 | developmentRegion = en; 207 | hasScannedForEncodings = 0; 208 | knownRegions = ( 209 | en, 210 | Base, 211 | ); 212 | mainGroup = 1C748C1D1C21952C0024EED2; 213 | productRefGroup = 1C748C281C21952C0024EED2 /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | 1C748C261C21952C0024EED2 /* DebugEnhancer */, 218 | ); 219 | }; 220 | /* End PBXProject section */ 221 | 222 | /* Begin PBXResourcesBuildPhase section */ 223 | 1C748C251C21952C0024EED2 /* Resources */ = { 224 | isa = PBXResourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | /* End PBXResourcesBuildPhase section */ 231 | 232 | /* Begin PBXShellScriptBuildPhase section */ 233 | CEC51E902121A15900F1F49A /* Archive */ = { 234 | isa = PBXShellScriptBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | inputPaths = ( 239 | ); 240 | name = Archive; 241 | outputPaths = ( 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | shellPath = /bin/sh; 245 | shellScript = "cd \"${TARGET_BUILD_DIR}\"\n\ndist=(\"$FULL_PRODUCT_NAME\")\nif [ -d \"$DWARF_DSYM_FILE_NAME\" ]; then dist+=(\"$DWARF_DSYM_FILE_NAME\"); fi\n\narchive=\"${PRODUCT_NAME}-${MODULE_VERSION}-$(echo $CONFIGURATION | tr /a-z/ /A-Z/).zip\"\nrm -rf *.zip\nzip -qry -FS \"${archive}\" \"${dist[@]}\"\n"; 246 | }; 247 | /* End PBXShellScriptBuildPhase section */ 248 | 249 | /* Begin PBXSourcesBuildPhase section */ 250 | 1C748C221C21952C0024EED2 /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | F6769743238FCF8000FDA3EE /* kern_start.cpp in Sources */, 255 | F654D35E1F6DA4FF00D29D64 /* kern_dbgenhancer.cpp in Sources */, 256 | CE405ED91E4A080700AA0B3D /* plugin_start.cpp in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | /* End PBXSourcesBuildPhase section */ 261 | 262 | /* Begin XCBuildConfiguration section */ 263 | 1C748C2F1C21952C0024EED2 /* Debug */ = { 264 | isa = XCBuildConfiguration; 265 | buildSettings = { 266 | ALWAYS_SEARCH_USER_PATHS = NO; 267 | ARCHS = x86_64; 268 | CLANG_CXX_LANGUAGE_STANDARD = "c++1y"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 271 | CLANG_WARN_BOOL_CONVERSION = YES; 272 | CLANG_WARN_COMMA = YES; 273 | CLANG_WARN_CONSTANT_CONVERSION = YES; 274 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INFINITE_RECURSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 281 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 282 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 283 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 285 | CLANG_WARN_STRICT_PROTOTYPES = YES; 286 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | DEBUG_INFORMATION_FORMAT = dwarf; 290 | ENABLE_STRICT_OBJC_MSGSEND = YES; 291 | ENABLE_TESTABILITY = YES; 292 | GCC_C_LANGUAGE_STANDARD = c11; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_SYMBOLS_PRIVATE_EXTERN = YES; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | KERNEL_EXTENSION_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; 307 | KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = macosx; 310 | }; 311 | name = Debug; 312 | }; 313 | 1C748C301C21952C0024EED2 /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ALWAYS_SEARCH_USER_PATHS = NO; 317 | ARCHS = x86_64; 318 | CLANG_CXX_LANGUAGE_STANDARD = "c++1y"; 319 | CLANG_CXX_LIBRARY = "libc++"; 320 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 321 | CLANG_WARN_BOOL_CONVERSION = YES; 322 | CLANG_WARN_COMMA = YES; 323 | CLANG_WARN_CONSTANT_CONVERSION = YES; 324 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INFINITE_RECURSION = YES; 329 | CLANG_WARN_INT_CONVERSION = YES; 330 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 331 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 332 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 333 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 334 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 335 | CLANG_WARN_STRICT_PROTOTYPES = YES; 336 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 337 | CLANG_WARN_UNREACHABLE_CODE = YES; 338 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 339 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 340 | ENABLE_STRICT_OBJC_MSGSEND = YES; 341 | GCC_C_LANGUAGE_STANDARD = c11; 342 | GCC_NO_COMMON_BLOCKS = YES; 343 | GCC_OPTIMIZATION_LEVEL = 3; 344 | GCC_SYMBOLS_PRIVATE_EXTERN = YES; 345 | GCC_UNROLL_LOOPS = YES; 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | KERNEL_EXTENSION_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; 353 | KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; 354 | SDKROOT = macosx; 355 | }; 356 | name = Release; 357 | }; 358 | 1C748C321C21952C0024EED2 /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | CLANG_ENABLE_OBJC_WEAK = YES; 362 | COPY_PHASE_STRIP = NO; 363 | CURRENT_PROJECT_VERSION = "$(MODULE_VERSION)"; 364 | DEPLOYMENT_POSTPROCESSING = YES; 365 | GCC_ENABLE_FLOATING_POINT_LIBRARY_CALLS = NO; 366 | GCC_ENABLE_KERNEL_DEVELOPMENT = NO; 367 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO; 368 | GCC_PREPROCESSOR_DEFINITIONS = ( 369 | "MODULE_VERSION=$(MODULE_VERSION)", 370 | "PRODUCT_NAME=$(PRODUCT_NAME)", 371 | "$(inherited)", 372 | ); 373 | HEADER_SEARCH_PATHS = "${PROJECT_DIR}/Lilu.kext/Contents/Resources"; 374 | INFOPLIST_FILE = DebugEnhancer/Info.plist; 375 | LIBRARY_SEARCH_PATHS = ( 376 | "$(inherited)", 377 | "$(PROJECT_DIR)/MacKernelSDK/Library/x86_64", 378 | ); 379 | MACOSX_DEPLOYMENT_TARGET = 10.8; 380 | MODULE_NAME = as.lvs1974.DebugEnhancer; 381 | MODULE_START = "$(PRODUCT_NAME)_kern_start"; 382 | MODULE_STOP = "$(PRODUCT_NAME)_kern_stop"; 383 | MODULE_VERSION = 1.1.1; 384 | OTHER_CFLAGS = ( 385 | "-mmmx", 386 | "-msse", 387 | "-msse2", 388 | "-msse3", 389 | "-mfpmath=sse", 390 | "-mssse3", 391 | "-ftree-vectorize", 392 | "-fno-non-call-exceptions", 393 | "-fno-builtin", 394 | "-fno-asynchronous-unwind-tables", 395 | "-Wno-unknown-warning-option", 396 | "-Wno-ossharedptr-misuse", 397 | "-Wno-vla", 398 | ); 399 | OTHER_LDFLAGS = "-static"; 400 | PRODUCT_BUNDLE_IDENTIFIER = as.lvs1974.DebugEnhancer; 401 | PRODUCT_NAME = "$(TARGET_NAME)"; 402 | WRAPPER_EXTENSION = kext; 403 | }; 404 | name = Debug; 405 | }; 406 | 1C748C331C21952C0024EED2 /* Release */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | CLANG_ENABLE_OBJC_WEAK = YES; 410 | CURRENT_PROJECT_VERSION = "$(MODULE_VERSION)"; 411 | DEAD_CODE_STRIPPING = YES; 412 | DEPLOYMENT_POSTPROCESSING = YES; 413 | GCC_ENABLE_FLOATING_POINT_LIBRARY_CALLS = NO; 414 | GCC_ENABLE_KERNEL_DEVELOPMENT = NO; 415 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES; 416 | GCC_PREPROCESSOR_DEFINITIONS = ( 417 | "MODULE_VERSION=$(MODULE_VERSION)", 418 | "PRODUCT_NAME=$(PRODUCT_NAME)", 419 | ); 420 | HEADER_SEARCH_PATHS = "${PROJECT_DIR}/Lilu.kext/Contents/Resources"; 421 | INFOPLIST_FILE = DebugEnhancer/Info.plist; 422 | LIBRARY_SEARCH_PATHS = ( 423 | "$(inherited)", 424 | "$(PROJECT_DIR)/MacKernelSDK/Library/x86_64", 425 | ); 426 | LLVM_LTO = YES; 427 | MACOSX_DEPLOYMENT_TARGET = 10.8; 428 | MODULE_NAME = as.lvs1974.DebugEnhancer; 429 | MODULE_START = "$(PRODUCT_NAME)_kern_start"; 430 | MODULE_STOP = "$(PRODUCT_NAME)_kern_stop"; 431 | MODULE_VERSION = 1.1.1; 432 | OTHER_CFLAGS = ( 433 | "-mmmx", 434 | "-msse", 435 | "-msse2", 436 | "-msse3", 437 | "-mfpmath=sse", 438 | "-mssse3", 439 | "-ftree-vectorize", 440 | "-fno-non-call-exceptions", 441 | "-fno-builtin", 442 | "-fno-asynchronous-unwind-tables", 443 | "-Wno-unknown-warning-option", 444 | "-Wno-ossharedptr-misuse", 445 | "-Wno-vla", 446 | ); 447 | OTHER_LDFLAGS = "-static"; 448 | PRODUCT_BUNDLE_IDENTIFIER = as.lvs1974.DebugEnhancer; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | STRIP_STYLE = "non-global"; 451 | WRAPPER_EXTENSION = kext; 452 | }; 453 | name = Release; 454 | }; 455 | /* End XCBuildConfiguration section */ 456 | 457 | /* Begin XCConfigurationList section */ 458 | 1C748C211C21952C0024EED2 /* Build configuration list for PBXProject "DebugEnhancer" */ = { 459 | isa = XCConfigurationList; 460 | buildConfigurations = ( 461 | 1C748C2F1C21952C0024EED2 /* Debug */, 462 | 1C748C301C21952C0024EED2 /* Release */, 463 | ); 464 | defaultConfigurationIsVisible = 0; 465 | defaultConfigurationName = Release; 466 | }; 467 | 1C748C311C21952C0024EED2 /* Build configuration list for PBXNativeTarget "DebugEnhancer" */ = { 468 | isa = XCConfigurationList; 469 | buildConfigurations = ( 470 | 1C748C321C21952C0024EED2 /* Debug */, 471 | 1C748C331C21952C0024EED2 /* Release */, 472 | ); 473 | defaultConfigurationIsVisible = 0; 474 | defaultConfigurationName = Release; 475 | }; 476 | /* End XCConfigurationList section */ 477 | }; 478 | rootObject = 1C748C1E1C21952C0024EED2 /* Project object */; 479 | } 480 | -------------------------------------------------------------------------------- /DebugEnhancer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | KEXT 17 | CFBundleShortVersionString 18 | $(MODULE_VERSION) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(MODULE_VERSION) 23 | IOKitPersonalities 24 | 25 | as.lvs1974.DebugEnhancer 26 | 27 | CFBundleIdentifier 28 | $(PRODUCT_BUNDLE_IDENTIFIER) 29 | IOClass 30 | $(PRODUCT_NAME:rfc1034identifier) 31 | IOMatchCategory 32 | $(PRODUCT_NAME:rfc1034identifier) 33 | IOProviderClass 34 | IOResources 35 | IOResourceMatch 36 | IOKit 37 | 38 | 39 | NSHumanReadableCopyright 40 | Copyright © 2019 lvs1974. All rights reserved. 41 | OSBundleCompatibleVersion 42 | 1.0 43 | OSBundleLibraries 44 | 45 | as.vit9696.Lilu 46 | 1.2.6 47 | com.apple.kpi.bsd 48 | 12.0.0 49 | com.apple.kpi.dsep 50 | 12.0.0 51 | com.apple.kpi.iokit 52 | 12.0.0 53 | com.apple.kpi.libkern 54 | 12.0.0 55 | com.apple.kpi.mach 56 | 12.0.0 57 | com.apple.kpi.unsupported 58 | 12.0.0 59 | 60 | OSBundleRequired 61 | Root 62 | 63 | 64 | -------------------------------------------------------------------------------- /DebugEnhancer/kern_dbgenhancer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_dbgenhancer.cpp 3 | // DebugEnhancer 4 | // 5 | // Copyright © 2019 lvs1974. All rights reserved. 6 | // 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "kern_dbgenhancer.hpp" 14 | 15 | static DBGENH *callbackDBGENH = nullptr; 16 | 17 | bool DBGENH::init() 18 | { 19 | callbackDBGENH = this; 20 | 21 | lilu.onPatcherLoadForce( 22 | [](void *user, KernelPatcher &patcher) { 23 | callbackDBGENH->processKernel(patcher); 24 | }, this); 25 | 26 | return true; 27 | } 28 | 29 | void DBGENH::deinit() 30 | { 31 | } 32 | 33 | //============================================================================== 34 | 35 | int DBGENH::kdb_printf(const char *fmt, ...) 36 | { 37 | va_list ap; 38 | va_start(ap, fmt); 39 | callbackDBGENH->kern_vprintf(fmt, ap); 40 | va_end(ap); 41 | return 0; 42 | } 43 | 44 | //============================================================================== 45 | 46 | void DBGENH::kprintf(const char *fmt, ...) 47 | { 48 | va_list ap; 49 | va_start(ap, fmt); 50 | callbackDBGENH->kern_vprintf(fmt, ap); 51 | va_end(ap); 52 | } 53 | 54 | //============================================================================== 55 | 56 | IOReturn DBGENH::IOHibernateSystemSleep(void) 57 | { 58 | unsigned int value = 0; 59 | if (callbackDBGENH->kernel_debug_entry_count) { 60 | value = *callbackDBGENH->kernel_debug_entry_count; 61 | *callbackDBGENH->kernel_debug_entry_count = 1; 62 | } 63 | 64 | IOReturn result = FunctionCast(IOHibernateSystemSleep, callbackDBGENH->orgIOHibernateSystemSleep)(); 65 | SYSLOG("DBGENH", "IOHibernateSystemSleep is called, result is: %x", result); 66 | 67 | if (callbackDBGENH->kernel_debug_entry_count) 68 | *callbackDBGENH->kernel_debug_entry_count = value; 69 | return result; 70 | } 71 | 72 | //============================================================================== 73 | 74 | uint32_t DBGENH::hibernate_write_image(void) 75 | { 76 | unsigned int value = 0; 77 | if (callbackDBGENH->kernel_debug_entry_count) { 78 | value = *callbackDBGENH->kernel_debug_entry_count; 79 | *callbackDBGENH->kernel_debug_entry_count = 1; 80 | } 81 | printf("DBGENH @ hibernate_write_image is called\n"); 82 | uint32_t result = FunctionCast(hibernate_write_image, callbackDBGENH->org_hibernate_write_image)(); 83 | printf("DBGENH @ hibernate_write_image result is: %x\n", result); 84 | 85 | if (callbackDBGENH->kernel_debug_entry_count) 86 | *callbackDBGENH->kernel_debug_entry_count = value; 87 | return result; 88 | } 89 | 90 | //============================================================================== 91 | 92 | void DBGENH::IOLog(const char *fmt, ...) 93 | { 94 | va_list ap; 95 | va_start(ap, fmt); 96 | callbackDBGENH->kern_vprintf(fmt, ap); 97 | va_end(ap); 98 | } 99 | 100 | //============================================================================== 101 | 102 | void DBGENH::processKernel(KernelPatcher &patcher) 103 | { 104 | if (!(progressState & ProcessingState::KernelRouted)) 105 | { 106 | kernel_debug_entry_count = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_kernel_debugger_entry_count")); 107 | if (!kernel_debug_entry_count) 108 | SYSLOG("DBGENH", "Symbol _kernel_debugger_entry_count cannot be resolved with error %d", patcher.getError()); 109 | patcher.clearError(); 110 | 111 | gIOKitDebug = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_gIOKitDebug")); 112 | if (gIOKitDebug) { 113 | *gIOKitDebug |= kIOLogPMRootDomain | kIOLogHibernate; 114 | } 115 | else 116 | SYSLOG("DBGENH", "Symbol _gIOKitDebug cannot be resolved with error %d", patcher.getError()); 117 | patcher.clearError(); 118 | 119 | kern_vprintf = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_vprintf")); 120 | if (kern_vprintf) { 121 | KernelPatcher::RouteRequest requests[] = { 122 | {"_kdb_printf", kdb_printf}, 123 | {"_kprintf", kprintf}, 124 | {"_hibernate_write_image", hibernate_write_image, org_hibernate_write_image}, 125 | {"_IOHibernateSystemSleep", IOHibernateSystemSleep, orgIOHibernateSystemSleep}, 126 | {"_IOLog", IOLog, orgIOLog} 127 | }; 128 | 129 | bool route_iolog = checkKernelArgument("-dbgenhiolog"); 130 | size_t size = arrsize(requests) - (route_iolog ? 0 : 1); 131 | if (!patcher.routeMultipleLong(KernelPatcher::KernelID, requests, size)) 132 | SYSLOG("DBGENH", "patcher.routeMultiple for %s is failed with error %d", requests[0].symbol, patcher.getError()); 133 | } else 134 | SYSLOG("DBGENH", "Symbol _vprintf cannot be resolved with error %d", patcher.getError()); 135 | 136 | log_setsize = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_log_setsize")); 137 | if (log_setsize) { 138 | const uint8_t find[] = {0x3D, 0xFF, 0xFF, 0x0F, 0x00, 0x0F}; 139 | const uint8_t replace[] = {0x3D, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F}; 140 | KernelPatcher::LookupPatch patch = {nullptr, find, replace, sizeof(find), 1}; 141 | DBGLOG("DBGENH", "applying kernel patch"); 142 | patcher.clearError(); 143 | patcher.applyLookupPatch(&patch, reinterpret_cast(log_setsize), 50); 144 | int new_logsize = MAX_MSG_BSIZE; 145 | if (patcher.getError() == KernelPatcher::Error::NoError) 146 | new_logsize = MAX_MSG_BSIZE*10; // 10 MBytes 147 | else 148 | SYSLOG("DBGENH", "applyLookupPatch failed with error %d", patcher.getError()); 149 | 150 | int error = 0; 151 | if ((error = log_setsize(new_logsize))) 152 | SYSLOG("DBGENH", "log_setsize could not change dmesg buffer size to %d, error: %d", new_logsize, error); 153 | } 154 | else 155 | { 156 | patcher.clearError(); 157 | kalloc_data = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_kalloc_data")); 158 | bsd_log_lock_safe = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_bsd_log_lock_safe")); 159 | bsd_log_unlock = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_bsd_log_unlock")); 160 | struct msgbuf *msgbufp = reinterpret_cast(patcher.solveSymbol(KernelPatcher::KernelID, "_msgbuf")); 161 | if (kalloc_data && bsd_log_lock_safe && bsd_log_unlock && msgbufp) 162 | { 163 | int new_logsize = MAX_MSG_BSIZE*10; // 10 MBytes 164 | char *new_logdata = kalloc_data(new_logsize, Z_WAITOK | Z_ZERO); 165 | if (new_logdata != nullptr) 166 | { 167 | int i = 0, count = 0; 168 | char *p = nullptr; 169 | 170 | bsd_log_lock_safe(); 171 | 172 | PANIC_COND(msgbufp->msg_magic != MSG_MAGIC, "DBGENH", "msgbufp->msg_magic has a wrong magic value"); 173 | 174 | char *old_logdata = msgbufp->msg_bufc; 175 | int old_logsize = msgbufp->msg_size; 176 | int old_bufr = msgbufp->msg_bufr; 177 | int old_bufx = msgbufp->msg_bufx; 178 | 179 | // start "new_logsize" bytes before the write pointer 180 | if (new_logsize <= old_bufx) { 181 | count = new_logsize; 182 | p = old_logdata + old_bufx - count; 183 | } else { 184 | // if new buffer is bigger, copy what we have and let the bzero above handle the difference 185 | count = MIN(new_logsize, old_logsize); 186 | p = old_logdata + old_logsize - (count - old_bufx); 187 | } 188 | 189 | for (i = 0; i < count; i++) { 190 | if (p >= old_logdata + old_logsize) 191 | p = old_logdata; 192 | new_logdata[i] = *p++; 193 | } 194 | 195 | int new_bufx = i; 196 | if (new_bufx >= new_logsize) 197 | new_bufx = 0; 198 | msgbufp->msg_bufx = new_bufx; 199 | 200 | int new_bufr = old_bufx - old_bufr; // how much were we trailing bufx by? 201 | if (new_bufr < 0) 202 | new_bufr += old_logsize; 203 | 204 | new_bufr = new_bufx - new_bufr; // now relative to oldest data in new buffer 205 | if (new_bufr < 0) 206 | new_bufr += new_logsize; 207 | 208 | msgbufp->msg_bufr = new_bufr; 209 | msgbufp->msg_size = new_logsize; 210 | msgbufp->msg_bufc = new_logdata; 211 | 212 | bsd_log_unlock(); 213 | 214 | // This memory is now dead - clear it so that it compresses better 215 | // in case of suspend to disk etc. 216 | bzero(old_logdata, old_logsize); 217 | } 218 | else 219 | SYSLOG("DBGENH", "kalloc_data could not allocate memory"); 220 | } 221 | else 222 | { 223 | SYSLOG("DBGENH", "Symbol _log_setsize/_kalloc_data/_bsd_log_lock_safe/_bsd_log_unlock/_msgbuf cannot be resolved with error %d", patcher.getError()); 224 | } 225 | } 226 | 227 | progressState |= ProcessingState::KernelRouted; 228 | } 229 | 230 | // Ignore all the errors for other processors 231 | patcher.clearError(); 232 | } 233 | -------------------------------------------------------------------------------- /DebugEnhancer/kern_dbgenhancer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_dbgenhancer.hpp 3 | // DebugEnhancer 4 | // 5 | // Copyright © 2019 lvs1974. All rights reserved. 6 | // 7 | 8 | #ifndef kern_dbgenhancer_hpp 9 | #define kern_dbgenhancer_hpp 10 | 11 | #include 12 | 13 | #define MAX_MSG_BSIZE (1*1024*1024) 14 | 15 | enum zalloc_flags_t { 16 | Z_WAITOK = 0x0000, 17 | Z_NOWAIT = 0x0001, 18 | Z_NOPAGEWAIT = 0x0002, 19 | Z_ZERO = 0x0004, 20 | Z_NOFAIL = 0x8000 21 | }; 22 | 23 | #pragma pack(push,1) 24 | 25 | struct msgbuf { 26 | #define MSG_MAGIC 0x063061 27 | int msg_magic; 28 | int msg_size; 29 | int msg_bufx; /* write pointer */ 30 | int msg_bufr; /* read pointer */ 31 | char *msg_bufc; /* buffer */ 32 | }; 33 | 34 | #pragma pack(pop) 35 | 36 | class DBGENH { 37 | public: 38 | bool init(); 39 | void deinit(); 40 | 41 | private: 42 | /** 43 | * Patch kernel 44 | * 45 | * @param patcher KernelPatcher instance 46 | */ 47 | void processKernel(KernelPatcher &patcher); 48 | 49 | /** 50 | * Hooked methods / callbacks 51 | */ 52 | static int kdb_printf(const char *fmt, ...); 53 | static void kprintf(const char *fmt, ...); 54 | static IOReturn IOHibernateSystemSleep(void); 55 | static uint32_t hibernate_write_image(void); 56 | static void IOLog(const char *fmt, ...); 57 | 58 | /** 59 | * Trampolines for original method invocations 60 | */ 61 | 62 | mach_vm_address_t orgIOHibernateSystemSleep {}; 63 | mach_vm_address_t org_hibernate_write_image {}; 64 | mach_vm_address_t orgIOLog {}; 65 | 66 | /** 67 | * Original method 68 | */ 69 | using t_kern_vprintf = int (*) (const char *fmt, va_list ap); 70 | t_kern_vprintf kern_vprintf {nullptr}; 71 | 72 | unsigned int *kernel_debug_entry_count {nullptr}; 73 | SInt64 *gIOKitDebug {nullptr}; 74 | 75 | using t_log_setsize = int (*) (int); 76 | t_log_setsize log_setsize {nullptr}; 77 | 78 | using t_kalloc_data = char * (*)(vm_size_t size, uint32_t flags); 79 | t_kalloc_data kalloc_data {nullptr}; 80 | 81 | using t_bsd_log_lock_safe = void (*) (); 82 | t_bsd_log_lock_safe bsd_log_lock_safe {nullptr}; 83 | 84 | using t_bsd_log_unlock = void (*) (); 85 | t_bsd_log_unlock bsd_log_unlock {nullptr}; 86 | 87 | using t_kernel_sysctlbyname = int (*)(const char *, void *, size_t *, void *, size_t); 88 | t_kernel_sysctlbyname kernel_sysctlbyname {nullptr}; 89 | 90 | /** 91 | * Current progress mask 92 | */ 93 | struct ProcessingState { 94 | enum { 95 | NothingReady = 0, 96 | KernelRouted = 1, 97 | EverythingDone = KernelRouted, 98 | }; 99 | }; 100 | int progressState {ProcessingState::NothingReady}; 101 | }; 102 | 103 | #endif /* kern_dbgenhancer_hpp */ 104 | -------------------------------------------------------------------------------- /DebugEnhancer/kern_start.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // kern_start.cpp 3 | // DebugEnhancer 4 | // 5 | // Copyright © 2019 lvs1974. All rights reserved. 6 | // 7 | 8 | #include 9 | #include 10 | 11 | #include "kern_dbgenhancer.hpp" 12 | 13 | static DBGENH dbgenh; 14 | 15 | static const char *bootargOff[] { 16 | "-dbgenhoff" 17 | }; 18 | 19 | static const char *bootargDebug[] { 20 | "-dbgenhdbg" 21 | }; 22 | 23 | static const char *bootargBeta[] { 24 | "-dbgenhbeta" 25 | }; 26 | 27 | PluginConfiguration ADDPR(config) { 28 | xStringify(PRODUCT_NAME), 29 | parseModuleVersion(xStringify(MODULE_VERSION)), 30 | LiluAPI::AllowNormal | LiluAPI::AllowInstallerRecovery | LiluAPI::AllowSafeMode, 31 | bootargOff, 32 | arrsize(bootargOff), 33 | bootargDebug, 34 | arrsize(bootargDebug), 35 | bootargBeta, 36 | arrsize(bootargBeta), 37 | KernelVersion::MountainLion, 38 | KernelVersion::Sequoia, 39 | []() { 40 | dbgenh.init(); 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, lvs1974 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DebugEnhancer 2 | ============= 3 | 4 | [![Build Status](https://github.com/acidanthera/DebugEnhancer/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/acidanthera/DebugEnhancer/actions) [![Scan Status](https://scan.coverity.com/projects/22205/badge.svg?flat=1)](https://scan.coverity.com/projects/22205) 5 | 6 | A Lilu plugin intended to enable debug output in the macOS kernel, 7 | the original idea belongs to Piker-Alpha, see https://github.com/Piker-Alpha/debugMachKernel.sh for more details. 8 | 9 | #### Boot-args 10 | - `-dbgenhdbg` turns on debugging output 11 | - `-dbgenhbeta` enables loading on unsupported osx 12 | - `-dbgenhoff` disables kext loading 13 | - `-dbgenhiolog` redirect IOLog output to kernel vprintf (the same as for kdb_printf and kprintf) 14 | --------------------------------------------------------------------------------