├── .gitignore ├── .gitmodules ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-docs ├── README.md ├── README.zh-CN.md ├── build.gradle ├── checkstyle.xml ├── doc ├── architecture.png ├── capture_anr.png ├── capture_native_crash.png ├── intro.png ├── tombstone_anr_arm64-v8a.txt ├── tombstone_anr_armeabi-v7a.txt ├── tombstone_anr_x86.txt ├── tombstone_anr_x86_64.txt ├── tombstone_java.txt ├── tombstone_native_arm64-v8a.txt ├── tombstone_native_armeabi-v7a.txt ├── tombstone_native_x86.txt ├── tombstone_native_x86_64.txt ├── xcrash_logo.png ├── xcrash_logo.svg └── xcrash_logo2.png ├── gradle.properties ├── gradle ├── check.gradle ├── publish.gradle ├── sanitizer.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── xcrash_lib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── cpp │ ├── CMakeLists.txt │ ├── common │ │ ├── xcc_b64.c │ │ ├── xcc_b64.h │ │ ├── xcc_errno.h │ │ ├── xcc_fmt.c │ │ ├── xcc_fmt.h │ │ ├── xcc_libc_support.c │ │ ├── xcc_libc_support.h │ │ ├── xcc_meminfo.c │ │ ├── xcc_meminfo.h │ │ ├── xcc_signal.c │ │ ├── xcc_signal.h │ │ ├── xcc_spot.h │ │ ├── xcc_unwind.c │ │ ├── xcc_unwind.h │ │ ├── xcc_unwind_clang.c │ │ ├── xcc_unwind_clang.h │ │ ├── xcc_unwind_libcorkscrew.c │ │ ├── xcc_unwind_libcorkscrew.h │ │ ├── xcc_unwind_libunwind.c │ │ ├── xcc_unwind_libunwind.h │ │ ├── xcc_util.c │ │ ├── xcc_util.h │ │ └── xcc_version.h │ ├── xcrash.exports │ ├── xcrash │ │ ├── xc_common.c │ │ ├── xc_common.h │ │ ├── xc_crash.c │ │ ├── xc_crash.h │ │ ├── xc_fallback.c │ │ ├── xc_fallback.h │ │ ├── xc_jni.c │ │ ├── xc_jni.h │ │ ├── xc_test.c │ │ ├── xc_test.h │ │ ├── xc_trace.c │ │ ├── xc_trace.h │ │ ├── xc_util.c │ │ └── xc_util.h │ └── xcrash_dumper │ │ ├── xcd_arm_exidx.c │ │ ├── xcd_arm_exidx.h │ │ ├── xcd_core.c │ │ ├── xcd_dwarf.c │ │ ├── xcd_dwarf.h │ │ ├── xcd_elf.c │ │ ├── xcd_elf.h │ │ ├── xcd_elf_interface.c │ │ ├── xcd_elf_interface.h │ │ ├── xcd_frames.c │ │ ├── xcd_frames.h │ │ ├── xcd_log.h │ │ ├── xcd_map.c │ │ ├── xcd_map.h │ │ ├── xcd_maps.c │ │ ├── xcd_maps.h │ │ ├── xcd_md5.c │ │ ├── xcd_md5.h │ │ ├── xcd_memory.c │ │ ├── xcd_memory.h │ │ ├── xcd_memory_buf.c │ │ ├── xcd_memory_buf.h │ │ ├── xcd_memory_file.c │ │ ├── xcd_memory_file.h │ │ ├── xcd_memory_remote.c │ │ ├── xcd_memory_remote.h │ │ ├── xcd_process.c │ │ ├── xcd_process.h │ │ ├── xcd_regs.h │ │ ├── xcd_regs_arm.c │ │ ├── xcd_regs_arm64.c │ │ ├── xcd_regs_x86.c │ │ ├── xcd_regs_x86_64.c │ │ ├── xcd_sys.c │ │ ├── xcd_sys.h │ │ ├── xcd_thread.c │ │ ├── xcd_thread.h │ │ ├── xcd_util.c │ │ └── xcd_util.h │ └── java │ └── xcrash │ ├── ActivityMonitor.java │ ├── AnrHandler.java │ ├── DefaultLogger.java │ ├── Errno.java │ ├── FileManager.java │ ├── ICrashCallback.java │ ├── ILibLoader.java │ ├── ILogger.java │ ├── JavaCrashHandler.java │ ├── NativeHandler.java │ ├── TombstoneManager.java │ ├── TombstoneParser.java │ ├── Util.java │ ├── Version.java │ └── XCrash.java └── xcrash_sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── xcrash │ └── sample │ ├── MainActivity.java │ ├── MyCustomApplication.java │ ├── MyService.java │ └── SecondActivity.java └── res ├── drawable-v24 └── ic_launcher_foreground.xml ├── drawable └── ic_launcher_background.xml ├── layout ├── activity_main.xml └── activity_second.xml ├── mipmap-anydpi-v26 ├── ic_launcher.xml └── ic_launcher_round.xml ├── mipmap-hdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-mdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxxhdpi ├── ic_launcher.png └── ic_launcher_round.png └── values ├── colors.xml ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | build/ 4 | .cxx/ 5 | .gradle/ 6 | .idea/ 7 | *.iml 8 | *.log 9 | *.so 10 | wrap.sh 11 | local.properties 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/xdl"] 2 | path = external/xdl 3 | url = https://github.com/hexhacking/xDL.git 4 | [submodule "external/lzma"] 5 | path = external/lzma 6 | url = https://github.com/hexhacking/lzma.git 7 | [submodule "external/bsdsysds"] 8 | path = external/bsdsysds 9 | url = https://github.com/hexhacking/bsdsysds.git 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to xCrash 2 | 3 | Welcome to the xCrash project. Read on to learn more about our development process and how to propose bug fixes and improvements. 4 | 5 | ## Issues 6 | 7 | We use GitHub issues to track public bugs and feature requests. Before creating an issue, please note the following: 8 | 9 | 1. Please search existing issues before creating a new one. 10 | 2. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue. The more information the better. 11 | 12 | 13 | ## Branch Management 14 | 15 | There are 2 main branches: 16 | 17 | 1. `master` branch 18 | 19 | * It's the latest (pre-)release branch. We use `master` for tags. 20 | * **Please do NOT submit any PR on `master` branch.** 21 | 22 | 2. `dev` branch 23 | 24 | * It's our stable developing branch. 25 | * Once `dev` has passed our internal tests, it will be merged to `master` branch for the next release. 26 | * **Please always submit PR on `dev` branch.** 27 | 28 | 29 | ## Pull Requests 30 | 31 | Please make sure the following is done when submitting a pull request: 32 | 33 | 1. Fork the repo and create your branch from `master`. 34 | 2. Add the copyright notice to the top of any new files you've added. 35 | 3. Check your Java code lints and checkstyles. 36 | 4. Try your best to test your code. 37 | 5. Squash all of your commits into one meaningful commit. 38 | 39 | 40 | ## Code Style Guide 41 | 42 | 1. 4 spaces for indentation rather than tabs. 43 | 2. Follow this [checkstyle configuration](src/java/xcrash/checkstyle.xml) for Java code. 44 | 3. Follow the C code style already in place. 45 | 46 | 47 | ## License 48 | 49 | By contributing to xCrash, you agree that your contributions will be licensed under its [MIT LICENSE](LICENSE). 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | 4 | Most source code in xCrash are MIT licensed. Some other source code 5 | have been placed in the public domain, or have BSD-style licenses. 6 | 7 | A copy of the MIT License is included in this file. 8 | 9 | 10 | 11 | Source code have been placed in the public domain 12 | ================================================= 13 | 14 | 1. LZMA 15 | 16 | LZMA SDK is written and placed in the public domain by Igor Pavlov. 17 | 18 | Some code in LZMA SDK is based on public domain code from another developers: 19 | 1) PPMd var.H (2001): Dmitry Shkarin 20 | 2) SHA-256: Wei Dai (Crypto++ library) 21 | 22 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute the 23 | original LZMA SDK code, either in source code form or as a compiled binary, for 24 | any purpose, commercial or non-commercial, and by any means. 25 | 26 | LZMA SDK code is compatible with open source licenses, for example, you can 27 | include it to GNU GPL or GNU LGPL code. 28 | 29 | 30 | 2. MD5 31 | 32 | This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 33 | MD5 Message-Digest Algorithm (RFC 1321). 34 | 35 | Homepage: 36 | http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 37 | 38 | Author: 39 | Alexander Peslyak, better known as Solar Designer 40 | 41 | This software was written by Alexander Peslyak in 2001. No copyright is 42 | claimed, and the software is hereby placed in the public domain. 43 | In case this attempt to disclaim copyright and place the software in the 44 | public domain is deemed null and void, then the software is 45 | Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 46 | general public under the following terms: 47 | 48 | Redistribution and use in source and binary forms, with or without 49 | modification, are permitted. 50 | 51 | There's ABSOLUTELY NO WARRANTY, express or implied. 52 | 53 | See md5.c for more information. 54 | 55 | 56 | 57 | Source code Licensed under the BSD 2-Clause License 58 | =================================================== 59 | 60 | tree.h 61 | 62 | Copyright 2002 Niels Provos 63 | All rights reserved. 64 | 65 | Redistribution and use in source and binary forms, with or without 66 | modification, are permitted provided that the following conditions 67 | are met: 68 | 1. Redistributions of source code must retain the above copyright 69 | notice, this list of conditions and the following disclaimer. 70 | 2. Redistributions in binary form must reproduce the above copyright 71 | notice, this list of conditions and the following disclaimer in the 72 | documentation and/or other materials provided with the distribution. 73 | 74 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 75 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 76 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 77 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 78 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 79 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 80 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 81 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 82 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 83 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 84 | 85 | 86 | 87 | Source code Licensed under the BSD 3-Clause License 88 | =================================================== 89 | 90 | queue.h 91 | 92 | Copyright (c) 1991, 1993 The Regents of the University of California. 93 | All rights reserved. 94 | 95 | Redistribution and use in source and binary forms, with or without 96 | modification, are permitted provided that the following conditions 97 | are met: 98 | 1. Redistributions of source code must retain the above copyright 99 | notice, this list of conditions and the following disclaimer. 100 | 2. Redistributions in binary form must reproduce the above copyright 101 | notice, this list of conditions and the following disclaimer in the 102 | documentation and/or other materials provided with the distribution. 103 | 3. Neither the name of the University nor the names of its contributors 104 | may be used to endorse or promote products derived from this software 105 | without specific prior written permission. 106 | 107 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 108 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 109 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 110 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 111 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 112 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 113 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 114 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 115 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 116 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 117 | SUCH DAMAGE. 118 | 119 | 120 | 121 | Terms of the MIT License 122 | ======================== 123 | 124 | Permission is hereby granted, free of charge, to any person obtaining a copy 125 | of this software and associated documentation files (the "Software"), to deal 126 | in the Software without restriction, including without limitation the rights 127 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 128 | copies of the Software, and to permit persons to whom the Software is 129 | furnished to do so, subject to the following conditions: 130 | 131 | The above copyright notice and this permission notice shall be included in all 132 | copies or substantial portions of the Software. 133 | 134 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 135 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 136 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 137 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 138 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 139 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 140 | SOFTWARE. 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

xCrash Logo

2 | 3 | # HexHacking xCrash 4 | 5 | ![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat) 6 | ![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat) 7 | ![](https://img.shields.io/badge/release-3.0.0-red.svg?style=flat) 8 | ![](https://img.shields.io/badge/Android-4.1%20--%2011-blue.svg?style=flat) 9 | ![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat) 10 | 11 | HexHacking xCrash is a branch version of xCrash, and its version number starts from 3.0.0. Whether in terms of architecture or technical details, HexHacking xCrash will be more radical. 12 | 13 | xCrash provides the Android app with the ability to capture java crash, native crash and ANR. No root permission or any system permissions are required. 14 | 15 |

intro

16 | 17 | xCrash can generate a tombstone file (similar format as Android system's tombstone file) in the directory you specified when the app process crashes or ANRs. 18 | 19 | [README 中文版](README.zh-CN.md) 20 | 21 | 22 | ## Features 23 | 24 | * Support Android 4.1 - 11 (API level 16 - 30). 25 | * Support armeabi-v7a, arm64-v8a, x86 and x86_64. 26 | * Capturing java crash, native crash and ANR. 27 | * Dumping detailed statistics about process, threads, memory, FD and network. 28 | * Setting which thread's info should be dumped via regular expressions. 29 | * Do not require root permission or any system permissions. 30 | 31 | 32 | ## Tombstone File Previews 33 | 34 | * [java crash](doc/tombstone_java.txt) 35 | * [native crash (armeabi-v7a)](doc/tombstone_native_armeabi-v7a.txt) 36 | * [native crash (arm64-v8a)](doc/tombstone_native_arm64-v8a.txt) 37 | * [native crash (x86)](doc/tombstone_native_x86.txt) 38 | * [native crash (x86_64)](doc/tombstone_native_x86_64.txt) 39 | * [ANR (armeabi-v7a)](doc/tombstone_anr_armeabi-v7a.txt) 40 | * [ANR (arm64-v8a)](doc/tombstone_anr_arm64-v8a.txt) 41 | * [ANR (x86)](doc/tombstone_anr_x86.txt) 42 | * [ANR (x86_64)](doc/tombstone_anr_x86_64.txt) 43 | 44 | 45 | ## Overview Maps 46 | 47 | ### Architecture 48 | 49 |

architecture

50 | 51 | ### Capture Native Crash 52 | 53 |

capture native crash

54 | 55 | ### Capture ANR 56 | 57 |

capture anr

58 | 59 | ## Usage 60 | 61 | #### 1. Add dependency. 62 | 63 | ```Gradle 64 | dependencies { 65 | implementation 'io.hexhacking.xcrash:xcrash-android-lib:3.0.0' 66 | } 67 | ``` 68 | 69 | #### 2. Specify one or more ABI(s) you need. 70 | 71 | ```Gradle 72 | android { 73 | defaultConfig { 74 | ndk { 75 | abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 76 | } 77 | } 78 | } 79 | ``` 80 | 81 | #### 3. Initialize xCrash. 82 | 83 | > Java 84 | 85 | ```Java 86 | public class MyCustomApplication extends Application { 87 | 88 | @Override 89 | protected void attachBaseContext(Context base) { 90 | super.attachBaseContext(base); 91 | 92 | xcrash.XCrash.init(this); 93 | } 94 | } 95 | ``` 96 | 97 | > Kotlin 98 | 99 | ```Kotlin 100 | class MyCustomApplication : Application() { 101 | 102 | override fun attachBaseContext(base: Context) { 103 | super.attachBaseContext(base) 104 | 105 | xcrash.XCrash.init(this) 106 | } 107 | } 108 | ``` 109 | 110 | Tombstone files will be written to `Context#getFilesDir() + "/tombstones"` directory by default. (usually in: `/data/data/PACKAGE_NAME/files/tombstones`) 111 | 112 | There is a more practical and complex sample app in the [xcrash_sample](xcrash_sample) folder. 113 | 114 | 115 | ## Support 116 | 117 | * [GitHub Issues](https://github.com/hexhacking/xCrash/issues) 118 | * [GitHub Discussions](https://github.com/hexhacking/xCrash/discussions) 119 | * [Telegram Public Group](https://t.me/android_native_geeks) 120 | 121 | 122 | ## Contributing 123 | 124 | [xCrash Contributing Guide](CONTRIBUTING.md). 125 | 126 | 127 | ## License 128 | 129 | xCrash is MIT licensed, as found in the [LICENSE](LICENSE) file. 130 | 131 | xCrash documentation is Creative Commons licensed, as found in the [LICENSE-docs](LICENSE-docs) file. 132 | -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 |

xCrash Logo

2 | 3 | # HexHacking xCrash 4 | 5 | ![](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat) 6 | ![](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat) 7 | ![](https://img.shields.io/badge/release-3.0.0-red.svg?style=flat) 8 | ![](https://img.shields.io/badge/Android-4.1%20--%2011-blue.svg?style=flat) 9 | ![](https://img.shields.io/badge/arch-armeabi--v7a%20%7C%20arm64--v8a%20%7C%20x86%20%7C%20x86__64-blue.svg?style=flat) 10 | 11 | HexHacking xCrash 是 xCrash 的一个分支版本,它的版本号从 3.0.0 开始。无论是在架构还是技术细节上,HexHacking xCrash 将会更加的激进。 12 | 13 | xCrash 能为安卓 app 提供捕获 java 崩溃,native 崩溃和 ANR 的能力。不需要 root 权限或任何系统权限。 14 | 15 |

intro

16 | 17 | xCrash 能在 app 进程崩溃或 ANR 时,在你指定的目录中生成一个 tombstone 文件(格式与安卓系统的 tombstone 文件类似)。 18 | 19 | [README English Version](README.md) 20 | 21 | 22 | ## 特征 23 | 24 | * 支持 Android 4.1 - 11(API level 16 - 30)。 25 | * 支持 armeabi-v7a,arm64-v8a,x86 和 x86_64。 26 | * 捕获 java 崩溃,native 崩溃和 ANR。 27 | * 获取详细的进程、线程、内存、FD、网络统计信息。 28 | * 通过正则表达式设置需要获取哪些线程的信息。 29 | * 不需要 root 权限或任何系统权限。 30 | 31 | 32 | ## Tombstone 文件预览 33 | 34 | * [java 崩溃](doc/tombstone_java.txt) 35 | * [native 崩溃 (armeabi-v7a)](doc/tombstone_native_armeabi-v7a.txt) 36 | * [native 崩溃 (arm64-v8a)](doc/tombstone_native_arm64-v8a.txt) 37 | * [native 崩溃 (x86)](doc/tombstone_native_x86.txt) 38 | * [native 崩溃 (x86_64)](doc/tombstone_native_x86_64.txt) 39 | * [ANR (armeabi-v7a)](doc/tombstone_anr_armeabi-v7a.txt) 40 | * [ANR (arm64-v8a)](doc/tombstone_anr_arm64-v8a.txt) 41 | * [ANR (x86)](doc/tombstone_anr_x86.txt) 42 | * [ANR (x86_64)](doc/tombstone_anr_x86_64.txt) 43 | 44 | 45 | ## 概览图 46 | 47 | ### 架构 48 | 49 |

architecture

50 | 51 | ### 捕获 native 崩溃 52 | 53 |

capture native crash

54 | 55 | ### 捕获 ANR 56 | 57 |

capture anr

58 | 59 | ## 使用 60 | 61 | #### 1. 增加依赖。 62 | 63 | ```Gradle 64 | dependencies { 65 | implementation 'io.hexhacking.xcrash:xcrash-android-lib:3.0.0' 66 | } 67 | ``` 68 | 69 | #### 2. 指定一个或多个你需要的 ABI。 70 | 71 | ```Gradle 72 | android { 73 | defaultConfig { 74 | ndk { 75 | abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 76 | } 77 | } 78 | } 79 | ``` 80 | 81 | #### 3. 初始化 xCrash。 82 | 83 | > Java 84 | 85 | ```Java 86 | public class MyCustomApplication extends Application { 87 | 88 | @Override 89 | protected void attachBaseContext(Context base) { 90 | super.attachBaseContext(base); 91 | 92 | xcrash.XCrash.init(this); 93 | } 94 | } 95 | ``` 96 | 97 | > Kotlin 98 | 99 | ```Kotlin 100 | class MyCustomApplication : Application() { 101 | 102 | override fun attachBaseContext(base: Context) { 103 | super.attachBaseContext(base) 104 | 105 | xcrash.XCrash.init(this) 106 | } 107 | } 108 | ``` 109 | 110 | Tombstone 文件默认将被写入到 `Context#getFilesDir() + "/tombstones"` 目录。(通常在: `/data/data/PACKAGE_NAME/files/tombstones`) 111 | 112 | 在 [xcrash_sample](xcrash_sample) 文件夹中,有一个更实际和复杂的示例 app。 113 | 114 | 115 | ## 技术支持 116 | 117 | * [GitHub Issues](https://github.com/hexhacking/xCrash/issues) 118 | * [GitHub Discussions](https://github.com/hexhacking/xCrash/discussions) 119 | * [Telegram Public Group](https://t.me/android_native_geeks) 120 | 121 | 122 | ## 贡献 123 | 124 | [xCrash Contributing Guide](CONTRIBUTING.md) 125 | 126 | 127 | ## 许可证 128 | 129 | xCrash 使用 [MIT 许可证](LICENSE)。 130 | 131 | xCrash 的文档使用 [Creative Commons 许可证](LICENSE-docs)。 132 | 133 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:4.1.1' 8 | classpath 'digital.wup:android-maven-publish:3.6.2' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' 10 | } 11 | } 12 | 13 | allprojects { 14 | repositories { 15 | google() 16 | jcenter() 17 | } 18 | } 19 | 20 | task clean(type: Delete) { 21 | delete rootProject.buildDir 22 | } 23 | 24 | ext { 25 | minSdkVersion = 16 26 | compileSdkVersion = 30 27 | targetSdkVersion = 30 28 | buildToolsVersion = '30.0.2' 29 | javaVersion = JavaVersion.VERSION_1_6 30 | ndkVersion = "21.3.6528147" 31 | cmakeVersion = "3.10.2" 32 | abiFilters = "armeabi-v7a,arm64-v8a,x86,x86_64" 33 | //abiFilters = "armeabi-v7a" 34 | useASAN = false 35 | 36 | POM_GROUP_ID = "io.hexhacking.xcrash" 37 | POM_ARTIFACT_ID = "xcrash-android-lib" 38 | POM_VERSION_NAME = "3.0.0" 39 | 40 | POM_NAME = "xCrash Android Lib" 41 | POM_DESCRIPTION = "xCrash provides the Android app with the ability to capture java crash, native crash and ANR." 42 | POM_URL = "https://github.com/hexhacking/xCrash" 43 | POM_INCEPTION_YEAR = "2019" 44 | POM_PACKAGING = "aar" 45 | 46 | POM_SCM_CONNECTION = "https://github.com/hexhacking/xCrash.git" 47 | 48 | POM_ISSUE_SYSTEM = "github" 49 | POM_ISSUE_URL = "https://github.com/hexhacking/xCrash/issues" 50 | 51 | POM_LICENCE_NAME = "The MIT License" 52 | POM_LICENCE_URL = "https://opensource.org/licenses/MIT" 53 | POM_LICENCE_DIST = "repo" 54 | 55 | POM_DEVELOPER_ID = "HexHacking" 56 | POM_DEVELOPER_NAME = "HexHacking Team" 57 | 58 | BINTRAY_REPO = "maven" 59 | BINTRAY_ORGANIZATION = "hexhacking" 60 | BINTRAY_LICENCE = ['MIT'] 61 | } 62 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /doc/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/architecture.png -------------------------------------------------------------------------------- /doc/capture_anr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/capture_anr.png -------------------------------------------------------------------------------- /doc/capture_native_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/capture_native_crash.png -------------------------------------------------------------------------------- /doc/intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/intro.png -------------------------------------------------------------------------------- /doc/xcrash_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/xcrash_logo.png -------------------------------------------------------------------------------- /doc/xcrash_logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/doc/xcrash_logo2.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | -------------------------------------------------------------------------------- /gradle/check.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'checkstyle' 2 | 3 | checkstyle { 4 | configFile rootProject.file('checkstyle.xml') 5 | toolVersion '8.18' 6 | ignoreFailures false 7 | showViolations true 8 | } 9 | 10 | task('checkstyle', type: Checkstyle) { 11 | source 'src/main/java' 12 | include '**/*.java' 13 | classpath = files() 14 | } 15 | 16 | check.dependsOn('checkstyle') 17 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'digital.wup.android-maven-publish' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | def readPropertyFromLocalProperties(String key) { 5 | Properties properties = new Properties() 6 | try { 7 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 8 | } catch (Exception e) { 9 | println("load local.properties failed. msg: ${e.message}") 10 | } 11 | return properties.getProperty(key) 12 | } 13 | 14 | def getCustomMavenRepo() { 15 | return readPropertyFromLocalProperties('CUSTOM_MAVEN_REPO') 16 | } 17 | 18 | def getCustomMavenUsername() { 19 | return readPropertyFromLocalProperties('CUSTOM_MAVEN_USERNAME') 20 | } 21 | 22 | def getCustomMavenPassword() { 23 | return readPropertyFromLocalProperties('CUSTOM_MAVEN_PASSWORD') 24 | } 25 | 26 | def getBintrayUser() { 27 | return readPropertyFromLocalProperties('BINTRAY_USER') 28 | } 29 | 30 | def getBintrayApikey() { 31 | return readPropertyFromLocalProperties('BINTRAY_APIKEY') 32 | } 33 | 34 | task sourcesJar(type: Jar) { 35 | classifier = 'sources' 36 | from android.sourceSets.main.java.srcDirs 37 | } 38 | 39 | task javadoc(type: Javadoc) { 40 | source = android.sourceSets.main.java.sourceFiles 41 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 42 | } 43 | 44 | task javadocJar(type: Jar, dependsOn: javadoc) { 45 | classifier = 'javadoc' 46 | from javadoc.destinationDir 47 | } 48 | 49 | publishing.publications { 50 | mavenAar(MavenPublication) { 51 | from components.android 52 | 53 | artifact sourcesJar 54 | artifact javadocJar 55 | 56 | artifactId POM_ARTIFACT_ID 57 | groupId POM_GROUP_ID 58 | version POM_VERSION_NAME 59 | 60 | pom { 61 | name = POM_NAME 62 | description = POM_DESCRIPTION 63 | url = POM_URL 64 | inceptionYear = POM_INCEPTION_YEAR 65 | packaging = POM_PACKAGING 66 | scm { 67 | connection = POM_SCM_CONNECTION 68 | url = POM_URL 69 | } 70 | issueManagement { 71 | system = POM_ISSUE_SYSTEM 72 | url = POM_ISSUE_URL 73 | } 74 | licenses { 75 | license { 76 | name = POM_LICENCE_NAME 77 | url = POM_LICENCE_URL 78 | distribution = POM_LICENCE_DIST 79 | } 80 | } 81 | developers { 82 | developer { 83 | id = POM_DEVELOPER_ID 84 | name = POM_DEVELOPER_NAME 85 | } 86 | } 87 | } 88 | } 89 | } 90 | 91 | // custom maven repo 92 | publishing.repositories { 93 | maven { 94 | url getCustomMavenRepo() 95 | credentials { 96 | username getCustomMavenUsername() 97 | password getCustomMavenPassword() 98 | } 99 | } 100 | } 101 | 102 | // bintray maven repo 103 | bintray { 104 | user = getBintrayUser() 105 | key = getBintrayApikey() 106 | publications = ['mavenAar'] 107 | pkg { 108 | repo = BINTRAY_REPO 109 | name = "${POM_GROUP_ID}:${POM_ARTIFACT_ID}" 110 | userOrg = BINTRAY_ORGANIZATION 111 | desc = POM_DESCRIPTION 112 | websiteUrl = POM_URL 113 | issueTrackerUrl = POM_ISSUE_URL 114 | vcsUrl = POM_SCM_CONNECTION 115 | licenses = BINTRAY_LICENCE 116 | publicDownloadNumbers = true 117 | publish = true 118 | dryRun = false 119 | 120 | version { 121 | name = POM_VERSION_NAME 122 | released = new Date() 123 | vcsTag = POM_VERSION_NAME 124 | gpg { 125 | sign = true 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /gradle/sanitizer.gradle: -------------------------------------------------------------------------------- 1 | project.afterEvaluate { 2 | 3 | preBuild.doFirst { 4 | if (rootProject.ext.useASAN) { 5 | def ndkLibDir = android.ndkDirectory.absolutePath + "/toolchains/llvm/prebuilt/" 6 | def ABIs = rootProject.ext.abiFilters.split(",") 7 | 8 | for (String abi : ABIs) { 9 | def arch = abi 10 | if (abi == 'armeabi-v7a') { 11 | arch = "arm" 12 | } else if (abi == "arm64-v8a") { 13 | arch = "aarch64" 14 | } else if (abi == "x86") { 15 | arch = "i686" 16 | } else if (abi == "x86_64") { 17 | arch = "x86_64" 18 | } 19 | 20 | // create ASAN wrap.sh 21 | def resDir = new File("src/main/resources/lib/" + abi) 22 | resDir.mkdirs() 23 | def wrapFile = new File(resDir, "wrap.sh") 24 | wrapFile.withWriter { writer -> 25 | writer.write('#!/system/bin/sh\n') 26 | writer.write('HERE="$(cd "$(dirname "$0")" && pwd)"\n') 27 | writer.write('export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1,detect_stack_use_after_return=1,check_initialization_order=true,quarantine_size_mb=64,color=never,new_delete_type_mismatch=0,sleep_before_dying=5,use_sigaltstack=0\n') 28 | writer.write("ASAN_LIB=\$(ls \$HERE/libclang_rt.asan-${arch}-android.so)\n") 29 | writer.write('if [ -f "$HERE/libc++_shared.so" ]; then\n') 30 | writer.write(' export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"\n') 31 | writer.write('else\n') 32 | writer.write(' export LD_PRELOAD="$ASAN_LIB"\n') 33 | writer.write('fi\n') 34 | writer.write('"\$@"\n') 35 | } 36 | println "sanitizer: [${abi}] create wrap.sh: " + wrapFile.absolutePath 37 | 38 | // copy ASAN libs 39 | def libDir = new File("src/main/jniLibs/" + abi) 40 | libDir.mkdirs() 41 | FileTree tree = fileTree(dir: ndkLibDir).include("**/libclang_rt.asan-${arch}-android.so") 42 | tree.each { File file -> 43 | copy { 44 | from file 45 | into libDir.absolutePath 46 | } 47 | println "sanitizer: [${abi}] copy lib: ${file.absolutePath} -> ${libDir.absolutePath}" 48 | } 49 | } 50 | } else { 51 | delete 'src/main/resources/' 52 | delete 'src/main/jniLibs/' 53 | } 54 | } 55 | } 56 | 57 | clean.doFirst { 58 | delete 'src/main/resources/' 59 | delete 'src/main/jniLibs/' 60 | } 61 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 13 11:21:54 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':xcrash_lib', ':xcrash_sample' 2 | -------------------------------------------------------------------------------- /xcrash_lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /xcrash_lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | buildToolsVersion rootProject.ext.buildToolsVersion 6 | ndkVersion rootProject.ext.ndkVersion 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.minSdkVersion 9 | targetSdkVersion rootProject.ext.targetSdkVersion 10 | consumerProguardFiles 'proguard-rules.pro' 11 | externalNativeBuild { 12 | cmake { 13 | abiFilters rootProject.ext.abiFilters.split(",") 14 | if(rootProject.ext.useASAN) { 15 | arguments "-DANDROID_ARM_MODE=arm" 16 | arguments "-DUSEASAN=ON" 17 | } 18 | } 19 | } 20 | } 21 | externalNativeBuild { 22 | cmake { 23 | path "src/main/cpp/CMakeLists.txt" 24 | version rootProject.ext.cmakeVersion 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility rootProject.ext.javaVersion 29 | targetCompatibility rootProject.ext.javaVersion 30 | } 31 | buildTypes { 32 | debug { 33 | minifyEnabled false 34 | } 35 | release { 36 | minifyEnabled false 37 | } 38 | } 39 | } 40 | 41 | apply from: rootProject.file('gradle/check.gradle') 42 | apply from: rootProject.file('gradle/publish.gradle') 43 | -------------------------------------------------------------------------------- /xcrash_lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -keep class xcrash.NativeHandler { 2 | native ; 3 | void crashCallback(...); 4 | void traceCallback(...); 5 | } 6 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | ####################################### 4 | # global 5 | ####################################### 6 | 7 | add_compile_options( 8 | -std=c11 9 | -Weverything 10 | -Werror) 11 | 12 | ####################################### 13 | # external 14 | ####################################### 15 | 16 | set(BSDSYSDS_PATH ../../../../external/bsdsysds) 17 | set(LZMA_PATH ../../../../external/lzma/C) 18 | set(XDL_PATH ../../../../external/xdl/xdl_lib/src/main/cpp) 19 | 20 | ####################################### 21 | # libxcrash.so 22 | ####################################### 23 | 24 | file(GLOB XCRASH_SRC 25 | xcrash/*.c 26 | common/*.c 27 | ${XDL_PATH}/*.c) 28 | 29 | add_library(xcrash SHARED 30 | ${XCRASH_SRC}) 31 | 32 | target_include_directories(xcrash PUBLIC 33 | xcrash 34 | common 35 | ${BSDSYSDS_PATH} 36 | ${XDL_PATH}) 37 | 38 | target_link_libraries(xcrash 39 | log 40 | dl) 41 | 42 | if(USEASAN) 43 | 44 | target_compile_options(xcrash PUBLIC 45 | -fsanitize=address 46 | -fno-omit-frame-pointer) 47 | 48 | set_target_properties(xcrash PROPERTIES 49 | LINK_FLAGS " \ 50 | -fsanitize=address") 51 | 52 | else() 53 | 54 | target_compile_options(xcrash PUBLIC 55 | -Oz 56 | -flto 57 | -ffunction-sections 58 | -fdata-sections) 59 | 60 | set_target_properties(xcrash PROPERTIES 61 | LINK_FLAGS " \ 62 | -O3 \ 63 | -flto \ 64 | -Wl,--exclude-libs,ALL \ 65 | -Wl,--gc-sections \ 66 | -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/xcrash.exports") 67 | 68 | endif() 69 | 70 | ####################################### 71 | # libxcrash_dumper.so 72 | ####################################### 73 | 74 | file(GLOB XCRASH_DUMPER_SRC 75 | xcrash_dumper/*.c 76 | common/*.c) 77 | 78 | set(LZME_SRC 79 | ${LZMA_PATH}/7zCrc.c 80 | ${LZMA_PATH}/7zCrcOpt.c 81 | ${LZMA_PATH}/CpuArch.c 82 | ${LZMA_PATH}/Bra.c 83 | ${LZMA_PATH}/Bra86.c 84 | ${LZMA_PATH}/BraIA64.c 85 | ${LZMA_PATH}/Delta.c 86 | ${LZMA_PATH}/Lzma2Dec.c 87 | ${LZMA_PATH}/LzmaDec.c 88 | ${LZMA_PATH}/Sha256.c 89 | ${LZMA_PATH}/Xz.c 90 | ${LZMA_PATH}/XzCrc64.c 91 | ${LZMA_PATH}/XzCrc64Opt.c 92 | ${LZMA_PATH}/XzDec.c) 93 | 94 | set_source_files_properties(${LZME_SRC} PROPERTIES 95 | COMPILE_FLAGS " \ 96 | -D_7ZIP_ST \ 97 | -Wno-enum-conversion \ 98 | -Wno-reserved-id-macro \ 99 | -Wno-undef \ 100 | -Wno-missing-prototypes \ 101 | -Wno-missing-variable-declarations \ 102 | -Wno-cast-align \ 103 | -Wno-sign-conversion \ 104 | -Wno-assign-enum \ 105 | -Wno-unused-macros \ 106 | -Wno-padded \ 107 | -Wno-cast-qual \ 108 | -Wno-strict-prototypes \ 109 | -Wno-extra-semi-stmt") 110 | 111 | add_executable(xcrash_dumper 112 | ${XCRASH_DUMPER_SRC} 113 | ${LZME_SRC}) 114 | 115 | target_include_directories(xcrash_dumper PUBLIC 116 | xcrash_dumper 117 | common 118 | ${BSDSYSDS_PATH} 119 | ${LZMA_PATH}) 120 | 121 | target_link_libraries(xcrash_dumper 122 | log 123 | dl) 124 | 125 | if(USEASAN) 126 | 127 | target_compile_options(xcrash_dumper PUBLIC 128 | -fsanitize=address 129 | -fno-omit-frame-pointer) 130 | 131 | set_target_properties(xcrash_dumper PROPERTIES 132 | LINK_FLAGS " \ 133 | -fsanitize=address") 134 | 135 | else() 136 | 137 | target_compile_options(xcrash_dumper PUBLIC 138 | -Oz 139 | -flto 140 | -ffunction-sections 141 | -fdata-sections) 142 | 143 | set_target_properties(xcrash_dumper PROPERTIES 144 | LINK_FLAGS " \ 145 | -O3 \ 146 | -flto \ 147 | -Wl,--exclude-libs,ALL \ 148 | -Wl,--gc-sections") 149 | 150 | endif() 151 | 152 | set_target_properties(xcrash_dumper PROPERTIES 153 | PREFIX "lib" 154 | SUFFIX ".so") 155 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_b64.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-12. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "xcc_b64.h" 30 | 31 | static const char xcc_b64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 32 | 33 | size_t xcc_b64_encode_max_len(size_t in_len) 34 | { 35 | return in_len * 4 / 3 + 4 + 1; 36 | } 37 | 38 | char *xcc_b64_encode(const uint8_t *in, size_t in_len, size_t *out_len) 39 | { 40 | const uint8_t *start, *end; 41 | char *out, *p; 42 | size_t olen; 43 | 44 | olen = in_len * 4 / 3 + 4 + 1; 45 | if(olen < in_len) return NULL; 46 | if(NULL == (out = malloc(olen))) return NULL; 47 | 48 | start = in; 49 | end = in + in_len; 50 | p = out; 51 | while (end - start >= 3) 52 | { 53 | *p++ = xcc_b64_table[start[0] >> 2]; 54 | *p++ = xcc_b64_table[((start[0] & 0x03) << 4) | (start[1] >> 4)]; 55 | *p++ = xcc_b64_table[((start[1] & 0x0f) << 2) | (start[2] >> 6)]; 56 | *p++ = xcc_b64_table[start[2] & 0x3f]; 57 | start += 3; 58 | } 59 | 60 | if (end - start > 0) 61 | { 62 | *p++ = xcc_b64_table[start[0] >> 2]; 63 | if(end - start == 1) 64 | { 65 | *p++ = xcc_b64_table[(start[0] & 0x03) << 4]; 66 | *p++ = '='; 67 | } 68 | else //end - start == 2 69 | { 70 | *p++ = xcc_b64_table[((start[0] & 0x03) << 4) | (start[1] >> 4)]; 71 | *p++ = xcc_b64_table[(start[1] & 0x0f) << 2]; 72 | } 73 | *p++ = '='; 74 | } 75 | 76 | *p = '\0'; 77 | 78 | if(NULL != out_len) *out_len = (size_t)(p - out); 79 | 80 | return out; 81 | } 82 | 83 | size_t xcc_b64_decode_max_len(size_t in_len) 84 | { 85 | return in_len / 4 * 3 + 1; 86 | } 87 | 88 | uint8_t *xcc_b64_decode(const char *in, size_t in_len, size_t *out_len) 89 | { 90 | uint8_t dtable[256], *out, *p, block[4], tmp; 91 | size_t i, count, olen, pad = 0; 92 | 93 | //build decode table 94 | memset(dtable, 0x80, 256); 95 | for(i = 0; i < sizeof(xcc_b64_table) - 1; i++) 96 | dtable[(size_t)(xcc_b64_table[i])] = (uint8_t)i; 97 | dtable['='] = 0; 98 | 99 | //get & check valid count of char at the "in" buffer 100 | count = 0; 101 | for (i = 0; i < in_len; i++) { 102 | if (dtable[(size_t)(in[i])] != 0x80) 103 | count++; 104 | } 105 | if(0 == count || 0 != count % 4) return NULL; 106 | 107 | //"out" buffer 108 | olen = count / 4 * 3 + 1; 109 | if(NULL == (out = malloc(olen))) return NULL; 110 | 111 | p = out; 112 | count = 0; 113 | for (i = 0; i < in_len; i++) 114 | { 115 | tmp = dtable[(size_t)(in[i])]; 116 | if(0x80 == tmp) continue; //invalid char 117 | 118 | if('=' == in[i]) pad++; //meet padding 119 | 120 | block[count] = tmp; 121 | count++; 122 | if (count == 4) 123 | { 124 | *p++ = (uint8_t)((block[0] << 2) | (block[1] >> 4)); 125 | *p++ = (uint8_t)((block[1] << 4) | (block[2] >> 2)); 126 | *p++ = (uint8_t)((block[2] << 6) | block[3]); 127 | count = 0; 128 | if (pad) 129 | { 130 | if (pad == 1) 131 | p--; 132 | else if (pad == 2) 133 | p -= 2; 134 | else { 135 | free(out); 136 | return NULL; 137 | } 138 | break; 139 | } 140 | } 141 | } 142 | 143 | *p = 0; 144 | 145 | if(NULL != out_len) *out_len = (size_t)(p - out); 146 | return out; 147 | } 148 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_b64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-12. 24 | 25 | #ifndef XCC_B64_H 26 | #define XCC_B64_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | size_t xcc_b64_encode_max_len(size_t in_len); 36 | char *xcc_b64_encode(const uint8_t *in, size_t in_len, size_t *out_len); 37 | 38 | size_t xcc_b64_decode_max_len(size_t in_len); 39 | uint8_t *xcc_b64_decode(const char *in, size_t in_len, size_t *out_len); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_errno.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_ERRNO_H 26 | #define XCC_ERRNO_H 1 27 | 28 | #include 29 | 30 | #define XCC_ERRNO_UNKNOWN 1001 31 | #define XCC_ERRNO_INVAL 1002 32 | #define XCC_ERRNO_NOMEM 1003 33 | #define XCC_ERRNO_NOSPACE 1004 34 | #define XCC_ERRNO_RANGE 1005 35 | #define XCC_ERRNO_NOTFND 1006 36 | #define XCC_ERRNO_MISSING 1007 37 | #define XCC_ERRNO_MEM 1008 38 | #define XCC_ERRNO_DEV 1009 39 | #define XCC_ERRNO_PERM 1010 40 | #define XCC_ERRNO_FORMAT 1011 41 | #define XCC_ERRNO_ILLEGAL 1012 42 | #define XCC_ERRNO_NOTSPT 1013 43 | #define XCC_ERRNO_STATE 1014 44 | #define XCC_ERRNO_JNI 1015 45 | #define XCC_ERRNO_FD 1016 46 | 47 | #define XCC_ERRNO_SYS ((0 != errno) ? errno : XCC_ERRNO_UNKNOWN) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_fmt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_FMT_H 26 | #define XCC_FMT_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | size_t xcc_fmt_snprintf(char *buffer, size_t buffer_size, const char *format, ...); 37 | size_t xcc_fmt_vsnprintf(char *buffer, size_t buffer_size, const char *format, va_list args); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_libc_support.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by Sim Sun on 2019-09-17. 24 | 25 | #include 26 | #include "xcc_libc_support.h" 27 | #include "xcc_errno.h" 28 | 29 | void *xcc_libc_support_memset(void *s, int c, size_t n) 30 | { 31 | char *p = (char *)s; 32 | 33 | while(n--) 34 | *p++ = (char)c; 35 | 36 | return s; 37 | } 38 | 39 | /* Nonzero if YEAR is a leap year (every 4 years, 40 | except every 100th isn't, and every 400th is). */ 41 | #define XCC_LIC_SUPPORT_ISLEAP(year) ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) 42 | 43 | #define XCC_LIC_SUPPORT_SECS_PER_HOUR (60 * 60) 44 | #define XCC_LIC_SUPPORT_SECS_PER_DAY (XCC_LIC_SUPPORT_SECS_PER_HOUR * 24) 45 | #define XCC_LIC_SUPPORT_DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) 46 | #define XCC_LIC_SUPPORT_LEAPS_THRU_END_OF(y) (XCC_LIC_SUPPORT_DIV(y, 4) - XCC_LIC_SUPPORT_DIV(y, 100) + XCC_LIC_SUPPORT_DIV(y, 400)) 47 | 48 | static const unsigned short int xcc_libc_support_mon_yday[2][13] = 49 | { 50 | /* Normal years. */ 51 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, 52 | /* Leap years. */ 53 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 54 | }; 55 | 56 | /* Compute the `struct tm' representation of *T, 57 | offset GMTOFF seconds east of UTC, 58 | and store year, yday, mon, mday, wday, hour, min, sec into *RESULT. 59 | Return RESULT if successful. */ 60 | struct tm *xcc_libc_support_localtime_r(const time_t *timep, long gmtoff, struct tm *result) 61 | { 62 | time_t days, rem, y; 63 | const unsigned short int *ip; 64 | 65 | if(NULL == result) return NULL; 66 | 67 | result->tm_gmtoff = gmtoff; 68 | 69 | days = ((*timep) / XCC_LIC_SUPPORT_SECS_PER_DAY); 70 | rem = ((*timep) % XCC_LIC_SUPPORT_SECS_PER_DAY); 71 | rem += gmtoff; 72 | while (rem < 0) 73 | { 74 | rem += XCC_LIC_SUPPORT_SECS_PER_DAY; 75 | --days; 76 | } 77 | while (rem >= XCC_LIC_SUPPORT_SECS_PER_DAY) 78 | { 79 | rem -= XCC_LIC_SUPPORT_SECS_PER_DAY; 80 | ++days; 81 | } 82 | result->tm_hour = (int)(rem / XCC_LIC_SUPPORT_SECS_PER_HOUR); 83 | rem %= XCC_LIC_SUPPORT_SECS_PER_HOUR; 84 | result->tm_min = (int)(rem / 60); 85 | result->tm_sec = rem % 60; 86 | /* January 1, 1970 was a Thursday. */ 87 | result->tm_wday = (4 + days) % 7; 88 | if (result->tm_wday < 0) 89 | result->tm_wday += 7; 90 | y = 1970; 91 | 92 | while (days < 0 || days >= (XCC_LIC_SUPPORT_ISLEAP(y) ? 366 : 365)) 93 | { 94 | /* Guess a corrected year, assuming 365 days per year. */ 95 | time_t yg = y + days / 365 - (days % 365 < 0); 96 | 97 | /* Adjust DAYS and Y to match the guessed year. */ 98 | days -= ((yg - y) * 365 99 | + XCC_LIC_SUPPORT_LEAPS_THRU_END_OF (yg - 1) 100 | - XCC_LIC_SUPPORT_LEAPS_THRU_END_OF (y - 1)); 101 | 102 | y = yg; 103 | } 104 | result->tm_year = (int)(y - 1900); 105 | if (result->tm_year != y - 1900) 106 | { 107 | /* The year cannot be represented due to overflow. */ 108 | errno = EOVERFLOW; 109 | return NULL; 110 | } 111 | result->tm_yday = (int)days; 112 | ip = xcc_libc_support_mon_yday[XCC_LIC_SUPPORT_ISLEAP(y)]; 113 | for (y = 11; days < (long int) ip[y]; --y) 114 | continue; 115 | days -= ip[y]; 116 | result->tm_mon = (int)y; 117 | result->tm_mday = (int)(days + 1); 118 | return result; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_libc_support.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by Sim Sun on 2019-09-17. 24 | 25 | #ifndef XCC_LIBC_SUPPORT_H 26 | #define XCC_LIBC_SUPPORT_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | // memset(3) is not async-signal-safe, ref: http://boston.conman.org/2016/12/17.1 36 | void *xcc_libc_support_memset(void *s, int c, size_t n); 37 | 38 | // you need to pass timezone through gmtoff 39 | struct tm *xcc_libc_support_localtime_r(const time_t *timev, long gmtoff, struct tm *result); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_meminfo.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-22. 24 | 25 | #ifndef XCC_MEMINFO_H 26 | #define XCC_MEMINFO_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int xcc_meminfo_record(int log_fd, pid_t pid); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_signal.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "xcc_signal.h" 35 | #include "xcc_errno.h" 36 | #include "xcc_libc_support.h" 37 | 38 | #define XCC_SIGNAL_CRASH_STACK_SIZE (1024 * 128) 39 | 40 | #pragma clang diagnostic push 41 | #pragma clang diagnostic ignored "-Wpadded" 42 | typedef struct 43 | { 44 | int signum; 45 | struct sigaction oldact; 46 | } xcc_signal_crash_info_t; 47 | #pragma clang diagnostic pop 48 | 49 | static xcc_signal_crash_info_t xcc_signal_crash_info[] = 50 | { 51 | {.signum = SIGABRT}, 52 | {.signum = SIGBUS}, 53 | {.signum = SIGFPE}, 54 | {.signum = SIGILL}, 55 | {.signum = SIGSEGV}, 56 | {.signum = SIGTRAP}, 57 | {.signum = SIGSYS}, 58 | {.signum = SIGSTKFLT} 59 | }; 60 | 61 | int xcc_signal_crash_register(void (*handler)(int, siginfo_t *, void *)) 62 | { 63 | stack_t ss; 64 | if(NULL == (ss.ss_sp = calloc(1, XCC_SIGNAL_CRASH_STACK_SIZE))) return XCC_ERRNO_NOMEM; 65 | ss.ss_size = XCC_SIGNAL_CRASH_STACK_SIZE; 66 | ss.ss_flags = 0; 67 | if(0 != sigaltstack(&ss, NULL)) return XCC_ERRNO_SYS; 68 | 69 | struct sigaction act; 70 | memset(&act, 0, sizeof(act)); 71 | sigfillset(&act.sa_mask); 72 | act.sa_sigaction = handler; 73 | act.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; 74 | 75 | size_t i; 76 | for(i = 0; i < sizeof(xcc_signal_crash_info) / sizeof(xcc_signal_crash_info[0]); i++) 77 | if(0 != sigaction(xcc_signal_crash_info[i].signum, &act, &(xcc_signal_crash_info[i].oldact))) 78 | return XCC_ERRNO_SYS; 79 | 80 | return 0; 81 | } 82 | 83 | int xcc_signal_crash_unregister(void) 84 | { 85 | int r = 0; 86 | size_t i; 87 | for(i = 0; i < sizeof(xcc_signal_crash_info) / sizeof(xcc_signal_crash_info[0]); i++) 88 | if(0 != sigaction(xcc_signal_crash_info[i].signum, &(xcc_signal_crash_info[i].oldact), NULL)) 89 | r = XCC_ERRNO_SYS; 90 | 91 | return r; 92 | } 93 | 94 | int xcc_signal_crash_ignore(void) 95 | { 96 | struct sigaction act; 97 | xcc_libc_support_memset(&act, 0, sizeof(act)); 98 | sigemptyset(&act.sa_mask); 99 | act.sa_handler = SIG_DFL; 100 | act.sa_flags = SA_RESTART; 101 | 102 | int r = 0; 103 | size_t i; 104 | for(i = 0; i < sizeof(xcc_signal_crash_info) / sizeof(xcc_signal_crash_info[0]); i++) 105 | if(0 != sigaction(xcc_signal_crash_info[i].signum, &act, NULL)) 106 | r = XCC_ERRNO_SYS; 107 | 108 | return r; 109 | } 110 | 111 | int xcc_signal_crash_queue(siginfo_t* si) 112 | { 113 | if(SIGABRT == si->si_signo || SI_FROMUSER(si)) 114 | { 115 | if(0 != syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), si->si_signo, si)) 116 | return XCC_ERRNO_SYS; 117 | } 118 | 119 | return 0; 120 | } 121 | 122 | static sigset_t xcc_signal_trace_oldset; 123 | static struct sigaction xcc_signal_trace_oldact; 124 | 125 | int xcc_signal_trace_register(void (*handler)(int, siginfo_t *, void *)) 126 | { 127 | int r; 128 | sigset_t set; 129 | struct sigaction act; 130 | 131 | //un-block the SIGQUIT mask for current thread, hope this is the main thread 132 | sigemptyset(&set); 133 | sigaddset(&set, SIGQUIT); 134 | if(0 != (r = pthread_sigmask(SIG_UNBLOCK, &set, &xcc_signal_trace_oldset))) return r; 135 | 136 | //register new signal handler for SIGQUIT 137 | memset(&act, 0, sizeof(act)); 138 | sigfillset(&act.sa_mask); 139 | act.sa_sigaction = handler; 140 | act.sa_flags = SA_RESTART | SA_SIGINFO; 141 | if(0 != sigaction(SIGQUIT, &act, &xcc_signal_trace_oldact)) 142 | { 143 | pthread_sigmask(SIG_SETMASK, &xcc_signal_trace_oldset, NULL); 144 | return XCC_ERRNO_SYS; 145 | } 146 | 147 | return 0; 148 | } 149 | 150 | void xcc_signal_trace_unregister(void) 151 | { 152 | pthread_sigmask(SIG_SETMASK, &xcc_signal_trace_oldset, NULL); 153 | sigaction(SIGQUIT, &xcc_signal_trace_oldact, NULL); 154 | } 155 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_signal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_SIGNAL_CRASH_H 26 | #define XCC_SIGNAL_CRASH_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | int xcc_signal_crash_register(void (*handler)(int, siginfo_t *, void *)); 37 | int xcc_signal_crash_unregister(void); 38 | int xcc_signal_crash_ignore(void); 39 | int xcc_signal_crash_queue(siginfo_t* si); 40 | 41 | int xcc_signal_trace_register(void (*handler)(int, siginfo_t *, void *)); 42 | void xcc_signal_trace_unregister(void); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_spot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_SPOT_H 26 | #define XCC_SPOT_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #pragma clang diagnostic push 38 | #pragma clang diagnostic ignored "-Wpadded" 39 | 40 | typedef struct 41 | { 42 | //set when crashed 43 | pid_t crash_tid; 44 | siginfo_t siginfo; 45 | ucontext_t ucontext; 46 | uint64_t crash_time; 47 | 48 | //set when inited 49 | int api_level; 50 | pid_t crash_pid; 51 | uint64_t start_time; 52 | long time_zone; 53 | unsigned int logcat_system_lines; 54 | unsigned int logcat_events_lines; 55 | unsigned int logcat_main_lines; 56 | int dump_elf_hash; 57 | int dump_map; 58 | int dump_fds; 59 | int dump_network_info; 60 | int dump_all_threads; 61 | unsigned int dump_all_threads_count_max; 62 | 63 | //set when crashed (content lenghts after this struct) 64 | size_t log_pathname_len; 65 | 66 | //set when inited (content lenghts after this struct) 67 | size_t os_version_len; 68 | size_t kernel_version_len; 69 | size_t abi_list_len; 70 | size_t manufacturer_len; 71 | size_t brand_len; 72 | size_t model_len; 73 | size_t build_fingerprint_len; 74 | size_t app_id_len; 75 | size_t app_version_len; 76 | size_t dump_all_threads_allowlist_len; 77 | } xcc_spot_t; 78 | 79 | #pragma clang diagnostic pop 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "xcc_unwind.h" 30 | #include "xcc_unwind_libcorkscrew.h" 31 | #include "xcc_unwind_libunwind.h" 32 | #include "xcc_unwind_clang.h" 33 | 34 | void xcc_unwind_init(int api_level) 35 | { 36 | #if defined(__arm__) || defined(__i386__) 37 | if(api_level >= 16 && api_level <= 20) 38 | { 39 | xcc_unwind_libcorkscrew_init(); 40 | } 41 | #endif 42 | 43 | if(api_level >= 21 && api_level <= 23) 44 | { 45 | xcc_unwind_libunwind_init(); 46 | } 47 | } 48 | 49 | size_t xcc_unwind_get(int api_level, siginfo_t *si, ucontext_t *uc, char *buf, size_t buf_len) 50 | { 51 | size_t buf_used; 52 | 53 | #if defined(__arm__) || defined(__i386__) 54 | if(api_level >= 16 && api_level <= 20) 55 | { 56 | if(0 == (buf_used = xcc_unwind_libcorkscrew_record(si, uc, buf, buf_len))) goto bottom; 57 | return buf_used; 58 | } 59 | #else 60 | (void)si; 61 | #endif 62 | 63 | if(api_level >= 21 && api_level <= 23) 64 | { 65 | if(0 == (buf_used = xcc_unwind_libunwind_record(uc, buf, buf_len))) goto bottom; 66 | return buf_used; 67 | } 68 | 69 | bottom: 70 | return xcc_unwind_clang_record(uc, buf, buf_len); 71 | } 72 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_UNWIND_H 26 | #define XCC_UNWIND_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | void xcc_unwind_init(int api_level); 37 | 38 | size_t xcc_unwind_get(int api_level, siginfo_t *si, ucontext_t *uc, char *buf, size_t buf_len); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind_clang.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-08-02. 24 | 25 | #ifndef XCC_UNWIND_CLANG_H 26 | #define XCC_UNWIND_CLANG_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | size_t xcc_unwind_clang_record(ucontext_t *uc, char *buf, size_t buf_len); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind_libcorkscrew.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-08-02. 24 | 25 | #if defined(__arm__) || defined(__i386__) 26 | 27 | #ifndef XCC_UNWIND_LIBCORKSCREW_H 28 | #define XCC_UNWIND_LIBCORKSCREW_H 1 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | void xcc_unwind_libcorkscrew_init(void); 40 | size_t xcc_unwind_libcorkscrew_record(siginfo_t *si, ucontext_t *uc, char *buf, size_t buf_len); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind_libunwind.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-08-02. 24 | 25 | #ifndef XCC_UNWIND_LIBUNWIND_H 26 | #define XCC_UNWIND_LIBUNWIND_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | void xcc_unwind_libunwind_init(void); 37 | size_t xcc_unwind_libunwind_record(ucontext_t *uc, char *buf, size_t buf_len); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_version.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCC_VERSION_H 26 | #define XCC_VERSION_H 1 27 | 28 | #define XCC_VERSION_STR "xCrash 3.0.0" 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash.exports: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | JNI_OnLoad; 4 | xc_test_crash; 5 | xc_test_call_1; 6 | xc_test_call_2; 7 | xc_test_call_3; 8 | xc_test_call_4; 9 | 10 | local: 11 | *; 12 | }; 13 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_common.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-08-20. 24 | 25 | #ifndef XC_COMMON_H 26 | #define XC_COMMON_H 1 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | // log filename format: 37 | // tombstone_01234567890123456789_appversion__processname.native.xcrash 38 | // tombstone_01234567890123456789_appversion__processname.trace.xcrash 39 | // placeholder_01234567890123456789.clean.xcrash 40 | #define XC_COMMON_LOG_PREFIX "tombstone" 41 | #define XC_COMMON_LOG_PREFIX_LEN 9 42 | #define XC_COMMON_LOG_SUFFIX_CRASH ".native.xcrash" 43 | #define XC_COMMON_LOG_SUFFIX_TRACE ".trace.xcrash" 44 | #define XC_COMMON_LOG_SUFFIX_TRACE_LEN 13 45 | #define XC_COMMON_LOG_NAME_MIN_TRACE (9 + 1 + 20 + 1 + 2 + 13) 46 | #define XC_COMMON_PLACEHOLDER_PREFIX "placeholder" 47 | #define XC_COMMON_PLACEHOLDER_SUFFIX ".clean.xcrash" 48 | 49 | //system info 50 | extern int xc_common_api_level; 51 | extern char *xc_common_os_version; 52 | extern char *xc_common_abi_list; 53 | extern char *xc_common_manufacturer; 54 | extern char *xc_common_brand; 55 | extern char *xc_common_model; 56 | extern char *xc_common_build_fingerprint; 57 | extern char *xc_common_kernel_version; 58 | extern long xc_common_time_zone; 59 | 60 | //app info 61 | extern char *xc_common_app_id; 62 | extern char *xc_common_app_version; 63 | extern char *xc_common_app_lib_dir; 64 | extern char *xc_common_log_dir; 65 | 66 | //process info 67 | extern pid_t xc_common_process_id; 68 | extern char *xc_common_process_name; 69 | extern uint64_t xc_common_start_time; 70 | extern JavaVM *xc_common_vm; 71 | extern jclass xc_common_cb_class; 72 | extern int xc_common_fd_null; 73 | 74 | //process statue 75 | extern sig_atomic_t xc_common_native_crashed; 76 | extern sig_atomic_t xc_common_java_crashed; 77 | 78 | void xc_common_set_vm(JavaVM *vm, JNIEnv *env, jclass cls); 79 | 80 | int xc_common_init(int api_level, 81 | const char *os_version, 82 | const char *abi_list, 83 | const char *manufacturer, 84 | const char *brand, 85 | const char *model, 86 | const char *build_fingerprint, 87 | const char *app_id, 88 | const char *app_version, 89 | const char *app_lib_dir, 90 | const char *log_dir); 91 | 92 | int xc_common_open_crash_log(char *pathname, size_t pathname_len, int *from_placeholder); 93 | int xc_common_open_trace_log(char *pathname, size_t pathname_len, uint64_t trace_time); 94 | void xc_common_close_crash_log(int fd); 95 | void xc_common_close_trace_log(int fd); 96 | int xc_common_seek_to_content_end(int fd); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_crash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XC_CRASH_H 26 | #define XC_CRASH_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | int xc_crash_init(JNIEnv *env, 37 | int rethrow, 38 | unsigned int logcat_system_lines, 39 | unsigned int logcat_events_lines, 40 | unsigned int logcat_main_lines, 41 | int dump_elf_hash, 42 | int dump_map, 43 | int dump_fds, 44 | int dump_network_info, 45 | int dump_all_threads, 46 | unsigned int dump_all_threads_count_max, 47 | const char **dump_all_threads_allowlist, 48 | size_t dump_all_threads_allowlist_len); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_fallback.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XC_FALLBACK_H 26 | #define XC_FALLBACK_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | size_t xc_fallback_get_emergency(siginfo_t *si, 36 | ucontext_t *uc, 37 | pid_t tid, 38 | uint64_t crash_time, 39 | char *emergency, 40 | size_t emergency_len); 41 | 42 | int xc_fallback_record(int log_fd, 43 | char *emergency, 44 | unsigned int logcat_system_lines, 45 | unsigned int logcat_events_lines, 46 | unsigned int logcat_main_lines, 47 | int dump_fds, 48 | int dump_network_info); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_jni.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XC_JNI_H 26 | #define XC_JNI_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define XC_JNI_IGNORE_PENDING_EXCEPTION() \ 37 | do { \ 38 | if((*env)->ExceptionCheck(env)) \ 39 | { \ 40 | (*env)->ExceptionClear(env); \ 41 | } \ 42 | } while(0) 43 | 44 | #define XC_JNI_CHECK_PENDING_EXCEPTION(label) \ 45 | do { \ 46 | if((*env)->ExceptionCheck(env)) \ 47 | { \ 48 | (*env)->ExceptionClear(env); \ 49 | goto label; \ 50 | } \ 51 | } while(0) 52 | 53 | #define XC_JNI_CHECK_NULL_AND_PENDING_EXCEPTION(v, label) \ 54 | do { \ 55 | XC_JNI_CHECK_PENDING_EXCEPTION(label); \ 56 | if(NULL == (v)) goto label; \ 57 | } while(0) 58 | 59 | #define XC_JNI_VERSION JNI_VERSION_1_6 60 | #define XC_JNI_CLASS_NAME "xcrash/NativeHandler" 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_test.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "xdl.h" 33 | #include "xcc_util.h" 34 | #include "xc_test.h" 35 | #include "xc_common.h" 36 | 37 | #pragma clang diagnostic push 38 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 39 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 40 | 41 | #define XC_TEST_LOG(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, "xcrash", fmt, ##__VA_ARGS__) 42 | #define XC_TEST_ABORT_MSG "abort message for xCrash internal testing" 43 | 44 | static void xc_test_set_abort_msg() 45 | { 46 | void *libc = NULL; 47 | xcc_util_libc_set_abort_message_t set_abort_msg = NULL; 48 | 49 | if(xc_common_api_level >= 29) libc = xdl_open(XCC_UTIL_LIBC_Q); 50 | if(NULL == libc && NULL == (libc = xdl_open(XCC_UTIL_LIBC))) goto end; 51 | if(NULL == (set_abort_msg = (xcc_util_libc_set_abort_message_t)xdl_sym(libc, XCC_UTIL_LIBC_SET_ABORT_MSG))) goto end; 52 | 53 | set_abort_msg(XC_TEST_ABORT_MSG); 54 | 55 | end: 56 | if(NULL != libc) xdl_close(libc); 57 | } 58 | 59 | #pragma clang optimize off 60 | 61 | int xc_test_call_4(int v) 62 | { 63 | int *a = NULL; 64 | 65 | xc_test_set_abort_msg(); 66 | 67 | *a = v; // crash! 68 | (*a)++; 69 | v = *a; 70 | 71 | return v; 72 | } 73 | 74 | int xc_test_call_3(int v) 75 | { 76 | int r = xc_test_call_4(v + 1); 77 | return r; 78 | } 79 | 80 | int xc_test_call_2(int v) 81 | { 82 | int r = xc_test_call_3(v + 1); 83 | return r; 84 | } 85 | 86 | void xc_test_call_1(void) 87 | { 88 | int r = xc_test_call_2(1); 89 | r = 0; 90 | } 91 | 92 | static void *xc_test_new_thread(void *arg) 93 | { 94 | (void)arg; 95 | pthread_detach(pthread_self()); 96 | pthread_setname_np(pthread_self(), "xcrash_test_cal"); 97 | 98 | xc_test_call_1(); 99 | 100 | return NULL; 101 | } 102 | 103 | static void *xc_test_keep_logging(void *arg) 104 | { 105 | (void)arg; 106 | pthread_detach(pthread_self()); 107 | pthread_setname_np(pthread_self(), "xcrash_test_log"); 108 | 109 | int i = 0; 110 | while(++i < 600) 111 | { 112 | XC_TEST_LOG("crashed APP's thread is running ...... %d", i); 113 | usleep(1000 * 100); 114 | } 115 | 116 | return NULL; 117 | } 118 | 119 | void xc_test_crash(int run_in_new_thread) 120 | { 121 | pthread_t tid; 122 | 123 | pthread_create(&tid, NULL, &xc_test_keep_logging, NULL); 124 | usleep(1000 * 10); 125 | 126 | if(run_in_new_thread) 127 | pthread_create(&tid, NULL, &xc_test_new_thread, NULL); 128 | else 129 | xc_test_call_1(); 130 | } 131 | 132 | #pragma clang optimize on 133 | 134 | #pragma clang diagnostic pop 135 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XC_TEST_H 26 | #define XC_TEST_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | void xc_test_crash(int run_in_new_thread); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_trace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-08-13. 24 | 25 | #ifndef XC_TRACE_H 26 | #define XC_TRACE_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | int xc_trace_init(JNIEnv *env, 37 | int rethrow, 38 | unsigned int logcat_system_lines, 39 | unsigned int logcat_events_lines, 40 | unsigned int logcat_main_lines, 41 | int dump_fds, 42 | int dump_network_info); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_util.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "xcc_errno.h" 40 | #include "xcc_fmt.h" 41 | #include "xcc_util.h" 42 | #include "xc_util.h" 43 | 44 | char *xc_util_strdupcat(const char *s1, const char *s2) 45 | { 46 | size_t s1_len, s2_len; 47 | char *s; 48 | 49 | if(NULL == s1 || NULL == s2) return NULL; 50 | 51 | s1_len = strlen(s1); 52 | s2_len = strlen(s2); 53 | 54 | if(NULL == (s = malloc(s1_len + s2_len + 1))) return NULL; 55 | memcpy(s, s1, s1_len); 56 | memcpy(s + s1_len, s2, s2_len + 1); 57 | 58 | return s; 59 | } 60 | 61 | int xc_util_mkdirs(const char *dir) 62 | { 63 | size_t len; 64 | char buf[PATH_MAX]; 65 | char *p; 66 | 67 | //check or try create dir directly 68 | errno = 0; 69 | if(0 == mkdir(dir, S_IRWXU) || EEXIST == errno) return 0; 70 | 71 | //trycreate dir recursively... 72 | 73 | len = strlen(dir); 74 | if(0 == len) return XCC_ERRNO_INVAL; 75 | if('/' != dir[0]) return XCC_ERRNO_INVAL; 76 | 77 | memcpy(buf, dir, len + 1); 78 | if(buf[len - 1] == '/') buf[len - 1] = '\0'; 79 | 80 | for(p = buf + 1; *p; p++) 81 | { 82 | if(*p == '/') 83 | { 84 | *p = '\0'; 85 | errno = 0; 86 | if(0 != mkdir(buf, S_IRWXU) && EEXIST != errno) return errno; 87 | *p = '/'; 88 | } 89 | } 90 | errno = 0; 91 | if(0 != mkdir(buf, S_IRWXU) && EEXIST != errno) return errno; 92 | return 0; 93 | } 94 | 95 | void xc_util_get_kernel_version(char *buf, size_t len) 96 | { 97 | struct utsname uts; 98 | 99 | if(0 != uname(&uts)) 100 | { 101 | strncpy(buf, "unknown", len); 102 | buf[len - 1] = '\0'; 103 | return; 104 | } 105 | 106 | snprintf(buf, len, "%s version %s %s (%s)", uts.sysname, uts.release, uts.version, uts.machine); 107 | } 108 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XC_UTIL_H 26 | #define XC_UTIL_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | char *xc_util_strdupcat(const char *s1, const char *s2); 36 | int xc_util_mkdirs(const char *dir); 37 | void xc_util_get_kernel_version(char *buf, size_t len); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_arm_exidx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifdef __arm__ 26 | 27 | #ifndef XCD_ARM_EXIDX_H 28 | #define XCD_ARM_EXIDX_H 1 29 | 30 | #include 31 | #include 32 | #include "xcd_regs.h" 33 | #include "xcd_memory.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | int xcd_arm_exidx_step(xcd_regs_t *regs, xcd_memory_t *memory, pid_t pid, 40 | size_t exidx_offset, size_t exidx_size, uintptr_t load_bias, 41 | uintptr_t pc, int *finished); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_dwarf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_DWARF_H 26 | #define XCD_DWARF_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_regs.h" 31 | #include "xcd_memory.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef enum 38 | { 39 | XCD_DWARF_TYPE_DEBUG_FRAME, 40 | XCD_DWARF_TYPE_EH_FRAME, 41 | XCD_DWARF_TYPE_EH_FRAME_HDR 42 | } xcd_dwarf_type_t; 43 | 44 | typedef struct xcd_dwarf xcd_dwarf_t; 45 | 46 | int xcd_dwarf_create(xcd_dwarf_t **self, xcd_memory_t *memory, pid_t pid, uintptr_t load_bias, uintptr_t hdr_load_bias, 47 | size_t offset, size_t size, xcd_dwarf_type_t type); 48 | 49 | int xcd_dwarf_step(xcd_dwarf_t *self, xcd_regs_t *regs, uintptr_t pc, int *finished); 50 | 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_elf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_ELF_H 26 | #define XCD_ELF_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_memory.h" 31 | #include "xcd_regs.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef struct xcd_elf xcd_elf_t; 38 | 39 | int xcd_elf_create(xcd_elf_t **self, pid_t pid, xcd_memory_t *memory); 40 | 41 | int xcd_elf_step(xcd_elf_t *self, uintptr_t rel_pc, uintptr_t step_pc, xcd_regs_t *regs, int *finished, int *sigreturn); 42 | 43 | int xcd_elf_get_function_info(xcd_elf_t *self, uintptr_t addr, char **name, size_t *name_offset); 44 | int xcd_elf_get_symbol_addr(xcd_elf_t *self, const char *name, uintptr_t *addr); 45 | 46 | int xcd_elf_get_build_id(xcd_elf_t *self, uint8_t *build_id, size_t build_id_len, size_t *build_id_len_ret); 47 | char *xcd_elf_get_so_name(xcd_elf_t *self); 48 | 49 | uintptr_t xcd_elf_get_load_bias(xcd_elf_t *self); 50 | xcd_memory_t *xcd_elf_get_memory(xcd_elf_t *self); 51 | 52 | int xcd_elf_is_valid(xcd_memory_t *memory); 53 | size_t xcd_elf_get_max_size(xcd_memory_t *memory); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_elf_interface.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_ELF_INTERFACE_H 26 | #define XCD_ELF_INTERFACE_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_memory.h" 31 | #include "xcd_regs.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef struct xcd_elf_interface xcd_elf_interface_t; 38 | 39 | int xcd_elf_interface_create(xcd_elf_interface_t **self, pid_t pid, xcd_memory_t *memory, uintptr_t *load_bias); 40 | 41 | xcd_elf_interface_t *xcd_elf_interface_gnu_create(xcd_elf_interface_t *self); 42 | 43 | int xcd_elf_interface_dwarf_step(xcd_elf_interface_t *self, uintptr_t step_pc, xcd_regs_t *regs, int *finished); 44 | #ifdef __arm__ 45 | int xcd_elf_interface_arm_exidx_step(xcd_elf_interface_t *self, uintptr_t step_pc, xcd_regs_t *regs, int *finished); 46 | #endif 47 | 48 | int xcd_elf_interface_get_function_info(xcd_elf_interface_t *self, uintptr_t addr, char **name, size_t *name_offset); 49 | int xcd_elf_interface_get_symbol_addr(xcd_elf_interface_t *self, const char *name, uintptr_t *addr); 50 | 51 | int xcd_elf_interface_get_build_id(xcd_elf_interface_t *self, uint8_t *build_id, size_t build_id_len, size_t *build_id_len_ret); 52 | char *xcd_elf_interface_get_so_name(xcd_elf_interface_t *self); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_frames.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_FRAMES_H 26 | #define XCD_FRAMES_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_regs.h" 31 | #include "xcd_maps.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef struct xcd_frames xcd_frames_t; 38 | 39 | int xcd_frames_create(xcd_frames_t **self, xcd_regs_t *regs, xcd_maps_t *maps, pid_t pid); 40 | void xcd_frames_destroy(xcd_frames_t **self); 41 | 42 | int xcd_frames_record_backtrace(xcd_frames_t *self, int log_fd); 43 | int xcd_frames_record_buildid(xcd_frames_t *self, int log_fd, int dump_elf_hash, uintptr_t fault_addr); 44 | int xcd_frames_record_stack(xcd_frames_t *self, int log_fd); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_LOG_H 26 | #define XCD_LOG_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #define XCD_LOG_PRIO ANDROID_LOG_WARN 36 | 37 | #define XCD_LOG_TAG "xcrash_dumper" 38 | 39 | #pragma clang diagnostic push 40 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 41 | #define XCD_LOG_DEBUG(fmt, ...) do{if(XCD_LOG_PRIO <= ANDROID_LOG_DEBUG) __android_log_print(ANDROID_LOG_DEBUG, XCD_LOG_TAG, fmt, ##__VA_ARGS__);}while(0) 42 | #define XCD_LOG_INFO(fmt, ...) do{if(XCD_LOG_PRIO <= ANDROID_LOG_INFO) __android_log_print(ANDROID_LOG_INFO, XCD_LOG_TAG, fmt, ##__VA_ARGS__);}while(0) 43 | #define XCD_LOG_WARN(fmt, ...) do{if(XCD_LOG_PRIO <= ANDROID_LOG_WARN) __android_log_print(ANDROID_LOG_WARN, XCD_LOG_TAG, fmt, ##__VA_ARGS__);}while(0) 44 | #define XCD_LOG_ERROR(fmt, ...) do{if(XCD_LOG_PRIO <= ANDROID_LOG_ERROR) __android_log_print(ANDROID_LOG_ERROR, XCD_LOG_TAG, fmt, ##__VA_ARGS__);}while(0) 45 | #pragma clang diagnostic pop 46 | 47 | //debug-log flags for modules 48 | #define XCD_CORE_DEBUG 0 49 | #define XCD_THREAD_DEBUG 0 50 | #define XCD_ELF_DEBUG 0 51 | #define XCD_ELF_INTERFACE_DEBUG 0 52 | #define XCD_FRAMES_DEBUG 0 53 | #define XCD_DWARF_DEBUG 0 54 | #define XCD_ARM_EXIDX_DEBUG 0 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_map.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "xcc_errno.h" 30 | #include "xcc_util.h" 31 | #include "xcd_map.h" 32 | #include "xcd_util.h" 33 | #include "xcd_log.h" 34 | 35 | int xcd_map_init(xcd_map_t *self, uintptr_t start, uintptr_t end, size_t offset, 36 | const char * flags, const char *name) 37 | { 38 | self->start = start; 39 | self->end = end; 40 | self->offset = offset; 41 | 42 | self->flags = PROT_NONE; 43 | if(flags[0] == 'r') self->flags |= PROT_READ; 44 | if(flags[1] == 'w') self->flags |= PROT_WRITE; 45 | if(flags[2] == 'x') self->flags |= PROT_EXEC; 46 | 47 | if(NULL == name || '\0' == name[0]) 48 | { 49 | self->name = NULL; 50 | } 51 | else 52 | { 53 | if(0 == strncmp(name, "/dev/", 5) && 0 != strncmp(name + 5, "ashmem/", 7)) 54 | self->flags |= XCD_MAP_PORT_DEVICE; 55 | 56 | if(NULL == (self->name = strdup(name))) return XCC_ERRNO_NOMEM; 57 | } 58 | 59 | self->elf = NULL; 60 | self->elf_loaded = 0; 61 | self->elf_offset = 0; 62 | self->elf_start_offset = 0; 63 | 64 | return 0; 65 | } 66 | 67 | void xcd_map_uninit(xcd_map_t *self) 68 | { 69 | free(self->name); 70 | self->name = NULL; 71 | } 72 | 73 | xcd_elf_t *xcd_map_get_elf(xcd_map_t *self, pid_t pid, void *maps_obj) 74 | { 75 | xcd_memory_t *memory = NULL; 76 | xcd_elf_t *elf = NULL; 77 | 78 | if(NULL == self->elf && 0 == self->elf_loaded) 79 | { 80 | self->elf_loaded = 1; 81 | 82 | if(0 != xcd_memory_create(&memory, self, pid, maps_obj)) return NULL; 83 | 84 | if(0 != xcd_elf_create(&elf, pid, memory)) return NULL; 85 | 86 | self->elf = elf; 87 | } 88 | 89 | return self->elf; 90 | } 91 | 92 | uintptr_t xcd_map_get_rel_pc(xcd_map_t *self, uintptr_t abs_pc, pid_t pid, void *maps_obj) 93 | { 94 | xcd_elf_t *elf = xcd_map_get_elf(self, pid, maps_obj); 95 | uintptr_t load_bias = (NULL == elf ? 0 : xcd_elf_get_load_bias(elf)); 96 | 97 | return abs_pc - (self->start - self->elf_offset - load_bias); 98 | } 99 | 100 | uintptr_t xcd_map_get_abs_pc(xcd_map_t *self, uintptr_t rel_pc, pid_t pid, void *maps_obj) 101 | { 102 | xcd_elf_t *elf = xcd_map_get_elf(self, pid, maps_obj); 103 | uintptr_t load_bias = (NULL == elf ? 0 : xcd_elf_get_load_bias(elf)); 104 | 105 | return (self->start - self->elf_offset - load_bias) + rel_pc; 106 | } 107 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_map.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MAP_H 26 | #define XCD_MAP_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_elf.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define XCD_MAP_PORT_DEVICE 0x8000 37 | 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wpadded" 40 | typedef struct xcd_map 41 | { 42 | //base info from /proc//maps 43 | uintptr_t start; 44 | uintptr_t end; 45 | size_t offset; 46 | uint16_t flags; 47 | char *name; 48 | 49 | //ELF 50 | xcd_elf_t *elf; 51 | int elf_loaded; 52 | size_t elf_offset; 53 | size_t elf_start_offset; 54 | } xcd_map_t; 55 | #pragma clang diagnostic pop 56 | 57 | int xcd_map_init(xcd_map_t *self, uintptr_t start, uintptr_t end, size_t offset, 58 | const char * flags, const char *name); 59 | void xcd_map_uninit(xcd_map_t *self); 60 | 61 | xcd_elf_t *xcd_map_get_elf(xcd_map_t *self, pid_t pid, void *maps_obj); 62 | uintptr_t xcd_map_get_rel_pc(xcd_map_t *self, uintptr_t abs_pc, pid_t pid, void *maps_obj); 63 | uintptr_t xcd_map_get_abs_pc(xcd_map_t *self, uintptr_t rel_pc, pid_t pid, void *maps_obj); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_maps.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MAPS_H 26 | #define XCD_MAPS_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_map.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_maps xcd_maps_t; 37 | 38 | int xcd_maps_create(xcd_maps_t **self, pid_t pid); 39 | void xcd_maps_destroy(xcd_maps_t **self); 40 | 41 | xcd_map_t *xcd_maps_find_map(xcd_maps_t *self, uintptr_t pc); 42 | xcd_map_t *xcd_maps_get_prev_map(xcd_maps_t *self, xcd_map_t *cur_map); 43 | 44 | uintptr_t xcd_maps_find_abort_msg(xcd_maps_t *self); 45 | 46 | uintptr_t xcd_maps_find_pc(xcd_maps_t *self, const char *pathname, const char *symbol); 47 | 48 | int xcd_maps_record(xcd_maps_t *self, int log_fd); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | //#ifdef HAVE_OPENSSL 27 | //#include 28 | //#elif !defined(_MD5_H) 29 | //#define _MD5_H 30 | 31 | #ifndef XCD_MD5_H 32 | #define XCD_MD5_H 1 33 | 34 | /* Any 32-bit or wider unsigned integer data type will do */ 35 | typedef unsigned int xcd_MD5_u32plus; 36 | 37 | typedef struct { 38 | xcd_MD5_u32plus lo, hi; 39 | xcd_MD5_u32plus a, b, c, d; 40 | unsigned char buffer[64]; 41 | xcd_MD5_u32plus block[16]; 42 | } xcd_MD5_CTX; 43 | 44 | void xcd_MD5_Init(xcd_MD5_CTX *ctx); 45 | void xcd_MD5_Update(xcd_MD5_CTX *ctx, const void *data, unsigned long size); 46 | void xcd_MD5_Final(unsigned char *result, xcd_MD5_CTX *ctx); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include "xcc_errno.h" 29 | #include "xcd_map.h" 30 | #include "xcd_memory.h" 31 | #include "xcd_memory_file.h" 32 | #include "xcd_memory_buf.h" 33 | #include "xcd_memory_remote.h" 34 | 35 | extern const xcd_memory_handlers_t xcd_memory_buf_handlers; 36 | extern const xcd_memory_handlers_t xcd_memory_file_handlers; 37 | extern const xcd_memory_handlers_t xcd_memory_remote_handlers; 38 | 39 | struct xcd_memory 40 | { 41 | void *obj; 42 | const xcd_memory_handlers_t *handlers; 43 | }; 44 | 45 | int xcd_memory_create(xcd_memory_t **self, void *map_obj, pid_t pid, void *maps_obj) 46 | { 47 | xcd_map_t *map = (xcd_map_t *)map_obj; 48 | xcd_maps_t *maps = (xcd_maps_t *)maps_obj; 49 | 50 | if(map->end <= map->start) return XCC_ERRNO_INVAL; 51 | if(map->flags & XCD_MAP_PORT_DEVICE) return XCC_ERRNO_DEV; 52 | 53 | if(NULL == (*self = malloc(sizeof(xcd_memory_t)))) return XCC_ERRNO_NOMEM; 54 | 55 | //try memory from file 56 | (*self)->handlers = &xcd_memory_file_handlers; 57 | if(0 == xcd_memory_file_create(&((*self)->obj), *self, map, maps)) return 0; 58 | 59 | //try memory from remote ptrace 60 | //Sometimes, data only exists in the remote process's memory such as vdso data on x86. 61 | if(!(map->flags & PROT_READ)) return XCC_ERRNO_PERM; 62 | (*self)->handlers = &xcd_memory_remote_handlers; 63 | if(0 == xcd_memory_remote_create(&((*self)->obj), map, pid)) return 0; 64 | (void)pid; 65 | 66 | free(*self); 67 | return XCC_ERRNO_MEM; 68 | } 69 | 70 | //for ELF header info unzipped from .gnu_debugdata in the local memory 71 | int xcd_memory_create_from_buf(xcd_memory_t **self, uint8_t *buf, size_t len) 72 | { 73 | if(NULL == (*self = malloc(sizeof(xcd_memory_t)))) return XCC_ERRNO_NOMEM; 74 | (*self)->handlers = &xcd_memory_buf_handlers; 75 | if(0 == xcd_memory_buf_create(&((*self)->obj), buf, len)) return 0; 76 | 77 | free(*self); 78 | return XCC_ERRNO_MEM; 79 | } 80 | 81 | void xcd_memory_destroy(xcd_memory_t **self) 82 | { 83 | (*self)->handlers->destroy(&((*self)->obj)); 84 | free(*self); 85 | *self = NULL; 86 | } 87 | 88 | size_t xcd_memory_read(xcd_memory_t *self, uintptr_t addr, void *dst, size_t size) 89 | { 90 | return self->handlers->read(self->obj, addr, dst, size); 91 | } 92 | 93 | int xcd_memory_read_fully(xcd_memory_t *self, uintptr_t addr, void* dst, size_t size) 94 | { 95 | size_t rc = self->handlers->read(self->obj, addr, dst, size); 96 | return rc == size ? 0 : XCC_ERRNO_MISSING; 97 | } 98 | 99 | int xcd_memory_read_string(xcd_memory_t *self, uintptr_t addr, char *dst, size_t size, size_t max_read) 100 | { 101 | char value; 102 | size_t i = 0; 103 | int r; 104 | 105 | while(i < size && i < max_read) 106 | { 107 | if(0 != (r = xcd_memory_read_fully(self, addr, &value, sizeof(value)))) return r; 108 | dst[i] = value; 109 | if('\0' == value) return 0; 110 | addr++; 111 | i++; 112 | } 113 | return XCC_ERRNO_NOSPACE; 114 | } 115 | 116 | int xcd_memory_read_uleb128(xcd_memory_t *self, uintptr_t addr, uint64_t *dst, size_t *size) 117 | { 118 | uint64_t cur_value = 0; 119 | uint64_t shift = 0; 120 | uint8_t byte; 121 | int r; 122 | 123 | if(NULL != size) *size = 0; 124 | 125 | do 126 | { 127 | if(0 != (r = xcd_memory_read_fully(self, addr, &byte, 1))) return r; 128 | addr += 1; 129 | if(NULL != size) *size += 1; 130 | cur_value += ((uint64_t)(byte & 0x7f) << shift); 131 | shift += 7; 132 | }while(byte & 0x80); 133 | 134 | *dst = cur_value; 135 | return 0; 136 | } 137 | 138 | int xcd_memory_read_sleb128(xcd_memory_t *self, uintptr_t addr, int64_t *dst, size_t *size) 139 | { 140 | uint64_t cur_value = 0; 141 | uint64_t shift = 0; 142 | uint8_t byte; 143 | int r; 144 | 145 | if(NULL != size) *size = 0; 146 | 147 | do 148 | { 149 | if(0 != (r = xcd_memory_read_fully(self, addr, &byte, 1))) return r; 150 | addr += 1; 151 | if(NULL != size) *size += 1; 152 | cur_value += ((uint64_t)(byte & 0x7f) << shift); 153 | shift += 7; 154 | }while(byte & 0x80); 155 | 156 | if(byte & 0x40) 157 | cur_value |= ((uint64_t)(-1) << shift); 158 | 159 | *dst = (int64_t)cur_value; 160 | return 0; 161 | } 162 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MEMORY_H 26 | #define XCD_MEMORY_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct xcd_memory xcd_memory_t; 36 | 37 | typedef struct 38 | { 39 | void (*destroy)(void **self); 40 | size_t (*read)(void *self, uintptr_t addr, void *dst, size_t size); 41 | } xcd_memory_handlers_t; 42 | 43 | int xcd_memory_create(xcd_memory_t **self, void *map_obj, pid_t pid, void *maps_obj); 44 | int xcd_memory_create_from_buf(xcd_memory_t **self, uint8_t *buf, size_t len); 45 | void xcd_memory_destroy(xcd_memory_t **self); 46 | 47 | size_t xcd_memory_read(xcd_memory_t *self, uintptr_t addr, void *dst, size_t size); 48 | int xcd_memory_read_fully(xcd_memory_t *self, uintptr_t addr, void* dst, size_t size); 49 | int xcd_memory_read_string(xcd_memory_t *self, uintptr_t addr, char *dst, size_t size, size_t max_read); 50 | int xcd_memory_read_uleb128(xcd_memory_t *self, uintptr_t addr, uint64_t *dst, size_t *size); 51 | int xcd_memory_read_sleb128(xcd_memory_t *self, uintptr_t addr, int64_t *dst, size_t *size); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_buf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "xcc_errno.h" 31 | #include "xcc_util.h" 32 | #include "xcd_map.h" 33 | #include "xcd_memory.h" 34 | #include "xcd_memory_buf.h" 35 | #include "xcd_util.h" 36 | 37 | struct xcd_memory_buf 38 | { 39 | uint8_t *buf; 40 | size_t len; 41 | }; 42 | 43 | int xcd_memory_buf_create(void **obj, uint8_t *buf, size_t len) 44 | { 45 | xcd_memory_buf_t **self = (xcd_memory_buf_t **)obj; 46 | 47 | if(NULL == (*self = malloc(sizeof(xcd_memory_buf_t)))) return XCC_ERRNO_NOMEM; 48 | (*self)->buf = buf; 49 | (*self)->len = len; 50 | 51 | return 0; 52 | } 53 | 54 | void xcd_memory_buf_destroy(void **obj) 55 | { 56 | xcd_memory_buf_t **self = (xcd_memory_buf_t **)obj; 57 | 58 | free((*self)->buf); 59 | free(*self); 60 | *self = NULL; 61 | } 62 | 63 | size_t xcd_memory_buf_read(void *obj, uintptr_t addr, void *dst, size_t size) 64 | { 65 | xcd_memory_buf_t *self = (xcd_memory_buf_t *)obj; 66 | 67 | if((size_t)addr >= self->len) return 0; 68 | 69 | #pragma clang diagnostic push 70 | #pragma clang diagnostic ignored "-Wgnu-statement-expression" 71 | size_t read_length = XCC_UTIL_MIN(size, self->len - addr); 72 | #pragma clang diagnostic pop 73 | 74 | memcpy(dst, self->buf + addr, read_length); 75 | return read_length; 76 | } 77 | 78 | #pragma clang diagnostic push 79 | #pragma clang diagnostic ignored "-Wmissing-variable-declarations" 80 | const xcd_memory_handlers_t xcd_memory_buf_handlers = { 81 | xcd_memory_buf_destroy, 82 | xcd_memory_buf_read 83 | }; 84 | #pragma clang diagnostic pop 85 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_buf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MEMORY_BUF_H 26 | #define XCD_MEMORY_BUF_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct xcd_memory_buf xcd_memory_buf_t; 36 | 37 | int xcd_memory_buf_create(void **obj, uint8_t *buf, size_t len); 38 | void xcd_memory_buf_destroy(void **obj); 39 | size_t xcd_memory_buf_read(void *obj, uintptr_t addr, void *dst, size_t size); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MEMORY_FILE_H 26 | #define XCD_MEMORY_FILE_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_map.h" 31 | #include "xcd_maps.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef struct xcd_memory_file xcd_memory_file_t; 38 | 39 | int xcd_memory_file_create(void **obj, xcd_memory_t *base, xcd_map_t *map, xcd_maps_t *maps); 40 | void xcd_memory_file_destroy(void **obj); 41 | size_t xcd_memory_file_read(void *obj, uintptr_t addr, void *dst, size_t size); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_remote.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "xcc_errno.h" 31 | #include "xcc_util.h" 32 | #include "xcd_map.h" 33 | #include "xcd_memory.h" 34 | #include "xcd_memory_remote.h" 35 | #include "xcd_util.h" 36 | #include "xcd_log.h" 37 | 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wpadded" 40 | struct xcd_memory_remote 41 | { 42 | pid_t pid; 43 | uintptr_t start; 44 | size_t length; 45 | }; 46 | #pragma clang diagnostic pop 47 | 48 | int xcd_memory_remote_create(void **obj, xcd_map_t *map, pid_t pid) 49 | { 50 | xcd_memory_remote_t **self = (xcd_memory_remote_t **)obj; 51 | 52 | if(NULL == (*self = malloc(sizeof(xcd_memory_remote_t)))) return XCC_ERRNO_NOMEM; 53 | (*self)->pid = pid; 54 | (*self)->start = map->start; 55 | (*self)->length = (size_t)(map->end - map->start); 56 | 57 | return 0; 58 | } 59 | 60 | void xcd_memory_remote_destroy(void **obj) 61 | { 62 | xcd_memory_remote_t **self = (xcd_memory_remote_t **)obj; 63 | 64 | free(*self); 65 | *self = NULL; 66 | } 67 | 68 | size_t xcd_memory_remote_read(void *obj, uintptr_t addr, void *dst, size_t size) 69 | { 70 | xcd_memory_remote_t *self = (xcd_memory_remote_t *)obj; 71 | 72 | if((size_t)addr >= self->length) return 0; 73 | 74 | #pragma clang diagnostic push 75 | #pragma clang diagnostic ignored "-Wgnu-statement-expression" 76 | size_t read_length = XCC_UTIL_MIN(size, self->length - addr); 77 | #pragma clang diagnostic pop 78 | 79 | uint64_t read_addr; 80 | if(__builtin_add_overflow(self->start, addr, &read_addr)) return 0; 81 | 82 | return xcd_util_ptrace_read(self->pid, (uintptr_t)read_addr, dst, read_length); 83 | } 84 | 85 | #pragma clang diagnostic push 86 | #pragma clang diagnostic ignored "-Wmissing-variable-declarations" 87 | const xcd_memory_handlers_t xcd_memory_remote_handlers = { 88 | xcd_memory_remote_destroy, 89 | xcd_memory_remote_read 90 | }; 91 | #pragma clang diagnostic pop 92 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_remote.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_MEMORY_REMOTE_H 26 | #define XCD_MEMORY_REMOTE_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_map.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_memory_remote xcd_memory_remote_t; 37 | 38 | int xcd_memory_remote_create(void **obj, xcd_map_t *map, pid_t pid); 39 | void xcd_memory_remote_destroy(void **obj); 40 | size_t xcd_memory_remote_read(void *obj, uintptr_t addr, void *dst, size_t size); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_process.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_THREADS_H 26 | #define XCD_THREADS_H 1 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct xcd_process xcd_process_t; 36 | 37 | int xcd_process_create(xcd_process_t **self, pid_t pid, pid_t crash_tid, siginfo_t *si, ucontext_t *uc); 38 | size_t xcd_process_get_number_of_threads(xcd_process_t *self); 39 | 40 | void xcd_process_suspend_threads(xcd_process_t *self); 41 | void xcd_process_resume_threads(xcd_process_t *self); 42 | 43 | int xcd_process_load_info(xcd_process_t *self); 44 | 45 | int xcd_process_record(xcd_process_t *self, 46 | int log_fd, 47 | unsigned int logcat_system_lines, 48 | unsigned int logcat_events_lines, 49 | unsigned int logcat_main_lines, 50 | int dump_elf_hash, 51 | int dump_map, 52 | int dump_fds, 53 | int dump_network_info, 54 | int dump_all_threads, 55 | unsigned int dump_all_threads_count_max, 56 | char *dump_all_threads_allowlist, 57 | int api_level); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_regs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_REGS_H 26 | #define XCD_REGS_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | #include "xcd_memory.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #if defined(__arm__) 38 | #define XCD_REGS_USER_NUM 18 39 | #define XCD_REGS_MACHINE_NUM 16 40 | #elif defined(__aarch64__) 41 | #define XCD_REGS_USER_NUM 34 42 | #define XCD_REGS_MACHINE_NUM 33 43 | #elif defined(__i386__) 44 | #define XCD_REGS_USER_NUM 17 45 | #define XCD_REGS_MACHINE_NUM 16 46 | #elif defined(__x86_64__) 47 | #define XCD_REGS_USER_NUM 27 48 | #define XCD_REGS_MACHINE_NUM 17 49 | #endif 50 | 51 | #pragma clang diagnostic push 52 | #pragma clang diagnostic ignored "-Wpadded" 53 | typedef struct { 54 | uintptr_t r[XCD_REGS_USER_NUM]; 55 | } xcd_regs_t; 56 | #pragma clang diagnostic pop 57 | 58 | uintptr_t xcd_regs_get_pc(xcd_regs_t *self); 59 | void xcd_regs_set_pc(xcd_regs_t *self, uintptr_t pc); 60 | 61 | uintptr_t xcd_regs_get_sp(xcd_regs_t *self); 62 | void xcd_regs_set_sp(xcd_regs_t *self, uintptr_t sp); 63 | 64 | #pragma clang diagnostic push 65 | #pragma clang diagnostic ignored "-Wpadded" 66 | typedef struct { 67 | uint8_t idx; 68 | const char *name; 69 | } xcd_regs_label_t; 70 | #pragma clang diagnostic pop 71 | 72 | void xcd_regs_get_labels(xcd_regs_label_t **labels, size_t *labels_count); 73 | 74 | void xcd_regs_load_from_ucontext(xcd_regs_t *self, ucontext_t *uc); 75 | void xcd_regs_load_from_ptregs(xcd_regs_t *self, uintptr_t *regs, size_t regs_len); 76 | 77 | int xcd_regs_record(xcd_regs_t *self, int log_fd); 78 | 79 | int xcd_regs_try_step_sigreturn(xcd_regs_t *self, uintptr_t rel_pc, xcd_memory_t *memory, pid_t pid); 80 | 81 | uintptr_t xcd_regs_get_adjust_pc(uintptr_t rel_pc, uintptr_t load_bias, xcd_memory_t *memory); 82 | 83 | int xcd_regs_set_pc_from_lr(xcd_regs_t *self, pid_t pid); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_sys.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "xcc_util.h" 30 | #include "xcd_sys.h" 31 | 32 | int xcd_sys_record(int fd, 33 | long time_zone, 34 | uint64_t start_time, 35 | uint64_t crash_time, 36 | const char *app_id, 37 | const char *app_version, 38 | int api_level, 39 | const char *os_version, 40 | const char *kernel_version, 41 | const char *abi_list, 42 | const char *manufacturer, 43 | const char *brand, 44 | const char *model, 45 | const char *build_fingerprint) 46 | { 47 | char buf[1024]; 48 | xcc_util_get_dump_header(buf, sizeof(buf), 49 | XCC_UTIL_CRASH_TYPE_NATIVE, 50 | time_zone, 51 | start_time, 52 | crash_time, 53 | app_id, 54 | app_version, 55 | api_level, 56 | os_version, 57 | kernel_version, 58 | abi_list, 59 | manufacturer, 60 | brand, 61 | model, 62 | build_fingerprint); 63 | return xcc_util_write_str(fd, buf); 64 | } 65 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_sys.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_SYS_H 26 | #define XCD_SYS_H 1 27 | 28 | #include 29 | #include 30 | #include "xcc_util.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | int xcd_sys_record(int fd, 37 | long time_zone, 38 | uint64_t start_time, 39 | uint64_t crash_time, 40 | const char *app_id, 41 | const char *app_version, 42 | int api_level, 43 | const char *os_version, 44 | const char *kernel_version, 45 | const char *abi_list, 46 | const char *manufacturer, 47 | const char *brand, 48 | const char *model, 49 | const char *build_fingerprint); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_thread.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_THREAD_H 26 | #define XCD_THREAD_H 1 27 | 28 | #include 29 | #include 30 | #include "xcd_regs.h" 31 | #include "xcd_frames.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef enum 38 | { 39 | XCD_THREAD_STATUS_OK = 0, 40 | XCD_THREAD_STATUS_UNKNOWN, 41 | XCD_THREAD_STATUS_REGS, 42 | XCD_THREAD_STATUS_ATTACH, 43 | XCD_THREAD_STATUS_ATTACH_WAIT 44 | } xcd_thread_status_t; 45 | 46 | #pragma clang diagnostic push 47 | #pragma clang diagnostic ignored "-Wpadded" 48 | typedef struct xcd_thread 49 | { 50 | xcd_thread_status_t status; 51 | pid_t pid; 52 | pid_t tid; 53 | char *tname; 54 | xcd_regs_t regs; 55 | xcd_frames_t *frames; 56 | } xcd_thread_t; 57 | #pragma clang diagnostic pop 58 | 59 | void xcd_thread_init(xcd_thread_t *self, pid_t pid, pid_t tid); 60 | 61 | void xcd_thread_suspend(xcd_thread_t *self); 62 | void xcd_thread_resume(xcd_thread_t *self); 63 | 64 | void xcd_thread_load_info(xcd_thread_t *self); 65 | void xcd_thread_load_regs(xcd_thread_t *self); 66 | void xcd_thread_load_regs_from_ucontext(xcd_thread_t *self, ucontext_t *uc); 67 | int xcd_thread_load_frames(xcd_thread_t *self, xcd_maps_t *maps); 68 | 69 | int xcd_thread_record_info(xcd_thread_t *self, int log_fd, const char *pname); 70 | int xcd_thread_record_regs(xcd_thread_t *self, int log_fd); 71 | int xcd_thread_record_backtrace(xcd_thread_t *self, int log_fd); 72 | int xcd_thread_record_buildid(xcd_thread_t *self, int log_fd, int dump_elf_hash, uintptr_t fault_addr); 73 | int xcd_thread_record_stack(xcd_thread_t *self, int log_fd); 74 | int xcd_thread_record_memory(xcd_thread_t *self, int log_fd); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | 25 | #ifndef XCD_UTIL_H 26 | #define XCD_UTIL_H 1 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | size_t xcd_util_ptrace_read(pid_t pid, uintptr_t addr, void *dst, size_t bytes); 37 | int xcd_util_ptrace_read_fully(pid_t pid, uintptr_t addr, void *dst, size_t bytes); 38 | int xcd_util_ptrace_read_long(pid_t pid, uintptr_t addr, long *value); 39 | 40 | int xcd_util_xz_decompress(uint8_t* src, size_t src_size, uint8_t** dst, size_t* dst_size); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/ActivityMonitor.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-09-25. 24 | package xcrash; 25 | 26 | import android.app.Activity; 27 | import android.app.Application; 28 | import android.os.Bundle; 29 | 30 | import java.util.LinkedList; 31 | 32 | class ActivityMonitor { 33 | 34 | private static final ActivityMonitor instance = new ActivityMonitor(); 35 | 36 | private LinkedList activities = null; 37 | private boolean isAppForeground = false; 38 | 39 | private static final int MAX_ACTIVITY_NUM = 100; 40 | 41 | private ActivityMonitor() { 42 | } 43 | 44 | static ActivityMonitor getInstance() { 45 | return instance; 46 | } 47 | 48 | void initialize(Application application) { 49 | activities = new LinkedList(); 50 | 51 | application.registerActivityLifecycleCallbacks( 52 | new Application.ActivityLifecycleCallbacks() { 53 | 54 | private int activityReferences = 0; 55 | private boolean isActivityChangingConfigurations = false; 56 | 57 | @Override 58 | public void onActivityCreated(Activity activity, Bundle savedInstanceState) { 59 | activities.addFirst(activity); 60 | if (activities.size() > MAX_ACTIVITY_NUM) { 61 | activities.removeLast(); 62 | } 63 | } 64 | 65 | @Override 66 | public void onActivityStarted(Activity activity) { 67 | if (++activityReferences == 1 && !isActivityChangingConfigurations) { 68 | isAppForeground = true; 69 | } 70 | } 71 | 72 | @Override 73 | public void onActivityResumed(Activity activity) { 74 | } 75 | 76 | @Override 77 | public void onActivityPaused(Activity activity) { 78 | } 79 | 80 | @Override 81 | public void onActivityStopped(Activity activity) { 82 | isActivityChangingConfigurations = activity.isChangingConfigurations(); 83 | if (--activityReferences == 0 && !isActivityChangingConfigurations) { 84 | isAppForeground = false; 85 | } 86 | } 87 | 88 | @Override 89 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) { 90 | } 91 | 92 | @Override 93 | public void onActivityDestroyed(Activity activity) { 94 | activities.remove(activity); 95 | } 96 | } 97 | ); 98 | } 99 | 100 | void finishAllActivities() { 101 | if (activities != null) { 102 | for (Activity activity : activities) { 103 | activity.finish(); 104 | } 105 | activities.clear(); 106 | } 107 | } 108 | 109 | boolean isApplicationForeground() { 110 | return this.isAppForeground; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/DefaultLogger.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-05-30. 24 | package xcrash; 25 | 26 | import android.util.Log; 27 | 28 | class DefaultLogger implements ILogger { 29 | @Override 30 | public void v(String tag, String msg) { 31 | Log.v(tag, msg); 32 | } 33 | 34 | @Override 35 | public void v(String tag, String msg, Throwable tr) { 36 | Log.v(tag, msg, tr); 37 | } 38 | 39 | @Override 40 | public void d(String tag, String msg) { 41 | Log.d(tag, msg); 42 | } 43 | 44 | @Override 45 | public void d(String tag, String msg, Throwable tr) { 46 | Log.d(tag, msg, tr); 47 | } 48 | 49 | @Override 50 | public void i(String tag, String msg) { 51 | Log.i(tag, msg); 52 | } 53 | 54 | @Override 55 | public void i(String tag, String msg, Throwable tr) { 56 | Log.i(tag, msg, tr); 57 | } 58 | 59 | @Override 60 | public void w(String tag, String msg) { 61 | Log.w(tag, msg); 62 | } 63 | 64 | @Override 65 | public void w(String tag, String msg, Throwable tr) { 66 | Log.w(tag, msg, tr); 67 | } 68 | 69 | @Override 70 | public void e(String tag, String msg) { 71 | Log.e(tag, msg); 72 | } 73 | 74 | @Override 75 | public void e(String tag, String msg, Throwable tr) { 76 | Log.e(tag, msg, tr); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/Errno.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | package xcrash; 25 | 26 | /** 27 | * The errno code for init() method of {@link xcrash.XCrash}. 28 | */ 29 | @SuppressWarnings("WeakerAccess") 30 | public final class Errno { 31 | 32 | /** 33 | * Initialization successful. 34 | */ 35 | public static final int OK = 0; 36 | 37 | /** 38 | * The context parameter is null. 39 | */ 40 | public static final int CONTEXT_IS_NULL = -1; 41 | 42 | /** 43 | * Load xCrash's native library failed. 44 | */ 45 | public static final int LOAD_LIBRARY_FAILED = -2; 46 | 47 | /** 48 | * Initialize xCrash's native library failed. 49 | */ 50 | public static final int INIT_LIBRARY_FAILED = -3; 51 | 52 | private Errno() { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/ICrashCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | package xcrash; 25 | 26 | /** 27 | * Define the callback interface after the crash occurs. 28 | * 29 | *

Note: Strictly speaking, this interface should always be implemented. 30 | * When disk is exhausted, the crash information cannot be saved to a crash log file. 31 | * The only way you can get the crash information is through the second parameter of onCrash() method. 32 | * Then you should parse and post the information immediately, because the APP process is crashing, 33 | * it will be killed by the system at any time. 34 | */ 35 | public interface ICrashCallback { 36 | 37 | /** 38 | * When a Java exception or native crash occurs, xCrash first captures and logs 39 | * the crash information to a crash log file and then calls this method. 40 | * 41 | * @param logPath Absolute path to the crash log file. 42 | * @param emergency A buffer that holds basic crash information when disk exhausted. 43 | * @throws Exception xCrash will catch and ignore any exception throw by this method. 44 | */ 45 | @SuppressWarnings("unused") 46 | void onCrash(String logPath, String emergency) throws Exception; 47 | } 48 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/ILibLoader.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-07-15. 24 | package xcrash; 25 | 26 | /** 27 | * Define the native library loader. 28 | * 29 | *

In practice, older versions of Android had bugs in PackageManager 30 | * that caused installation and update of native libraries to be unreliable. 31 | */ 32 | public interface ILibLoader { 33 | 34 | /** 35 | * Loads the native library specified by the libName argument. 36 | * 37 | * @param libName the name of the library. 38 | */ 39 | void loadLibrary(String libName); 40 | } 41 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/ILogger.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-05-30. 24 | package xcrash; 25 | 26 | /** 27 | * Define the logger interface used by xCrash. 28 | */ 29 | public interface ILogger { 30 | 31 | /** 32 | * Log a VERBOSE message. 33 | * 34 | * @param tag Used to identify the source of a log message. 35 | * @param msg The message you would like logged. 36 | */ 37 | @SuppressWarnings("unused") 38 | void v(String tag, String msg); 39 | 40 | /** 41 | * Log a VERBOSE message and the exception. 42 | * 43 | * @param tag Used to identify the source of a log message. 44 | * @param msg The message you would like logged. 45 | * @param tr An exception to log. 46 | */ 47 | @SuppressWarnings("unused") 48 | void v(String tag, String msg, Throwable tr); 49 | 50 | /** 51 | * Log a DEBUG message. 52 | * 53 | * @param tag Used to identify the source of a log message. 54 | * @param msg The message you would like logged. 55 | */ 56 | @SuppressWarnings("unused") 57 | void d(String tag, String msg); 58 | 59 | /** 60 | * Log a DEBUG message and the exception. 61 | * 62 | * @param tag Used to identify the source of a log message. 63 | * @param msg The message you would like logged. 64 | * @param tr An exception to log. 65 | */ 66 | @SuppressWarnings("unused") 67 | void d(String tag, String msg, Throwable tr); 68 | 69 | /** 70 | * Log a INFO message. 71 | * 72 | * @param tag Used to identify the source of a log message. 73 | * @param msg The message you would like logged. 74 | */ 75 | @SuppressWarnings("unused") 76 | void i(String tag, String msg); 77 | 78 | /** 79 | * Log a INFO message and the exception. 80 | * 81 | * @param tag Used to identify the source of a log message. 82 | * @param msg The message you would like logged. 83 | * @param tr An exception to log. 84 | */ 85 | @SuppressWarnings("unused") 86 | void i(String tag, String msg, Throwable tr); 87 | 88 | /** 89 | * Log a WARN message. 90 | * 91 | * @param tag Used to identify the source of a log message. 92 | * @param msg The message you would like logged. 93 | */ 94 | @SuppressWarnings("unused") 95 | void w(String tag, String msg); 96 | 97 | /** 98 | * Log a WARN message and the exception. 99 | * 100 | * @param tag Used to identify the source of a log message. 101 | * @param msg The message you would like logged. 102 | * @param tr An exception to log. 103 | */ 104 | @SuppressWarnings("unused") 105 | void w(String tag, String msg, Throwable tr); 106 | 107 | /** 108 | * Log a ERROR message. 109 | * 110 | * @param tag Used to identify the source of a log message. 111 | * @param msg The message you would like logged. 112 | */ 113 | @SuppressWarnings("unused") 114 | void e(String tag, String msg); 115 | 116 | /** 117 | * Log a ERROR message and the exception. 118 | * 119 | * @param tag Used to identify the source of a log message. 120 | * @param msg The message you would like logged. 121 | * @param tr An exception to log. 122 | */ 123 | @SuppressWarnings("unused") 124 | void e(String tag, String msg, Throwable tr); 125 | } 126 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/Version.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | package xcrash; 25 | 26 | class Version { 27 | 28 | private Version() { 29 | } 30 | 31 | static final String version = "3.0.0"; 32 | static final String fullVersion = "xCrash " + version; 33 | } 34 | -------------------------------------------------------------------------------- /xcrash_sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /xcrash_sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | buildToolsVersion rootProject.ext.buildToolsVersion 6 | ndkVersion rootProject.ext.ndkVersion 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.minSdkVersion 9 | targetSdkVersion rootProject.ext.targetSdkVersion 10 | applicationId "xcrash.sample" 11 | versionCode 1 12 | versionName "1.0" 13 | ndk { 14 | abiFilters rootProject.ext.abiFilters.split(",") 15 | } 16 | } 17 | compileOptions { 18 | sourceCompatibility rootProject.ext.javaVersion 19 | targetCompatibility rootProject.ext.javaVersion 20 | } 21 | buildTypes { 22 | debug { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | release { 27 | minifyEnabled true 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | implementation 'androidx.appcompat:appcompat:1.2.0' 36 | implementation 'androidx.constraintlayout:constraintlayout:2.0.2' 37 | //implementation 'io.hexhacking.xcrash:xcrash-android-lib:3.0.0' 38 | implementation project(':xcrash_lib') 39 | } 40 | 41 | apply from: rootProject.file('gradle/sanitizer.gradle') 42 | -------------------------------------------------------------------------------- /xcrash_sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/java/xcrash/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | package xcrash.sample; 25 | 26 | import android.content.Intent; 27 | import androidx.appcompat.app.AppCompatActivity; 28 | import android.os.Bundle; 29 | import android.view.View; 30 | 31 | import xcrash.XCrash; 32 | 33 | public class MainActivity extends AppCompatActivity { 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_main); 39 | } 40 | 41 | public void testNativeCrashInMainThread_onClick(View view) { 42 | XCrash.testNativeCrash(false); 43 | } 44 | 45 | public void testNativeCrashInAnotherJavaThread_onClick(View view) { 46 | new Thread(new Runnable() { 47 | @Override 48 | public void run() { 49 | XCrash.testNativeCrash(false); 50 | } 51 | }, "java_thread_with_a_very_long_name").start(); 52 | } 53 | 54 | public void testNativeCrashInAnotherNativeThread_onClick(View view) { 55 | XCrash.testNativeCrash(true); 56 | } 57 | 58 | public void testNativeCrashInAnotherActivity_onClick(View view) { 59 | startActivity(new Intent(this, SecondActivity.class).putExtra("type", "native")); 60 | } 61 | 62 | public void testNativeCrashInAnotherProcess_onClick(View view) { 63 | startService(new Intent(this, MyService.class).putExtra("type", "native")); 64 | } 65 | 66 | public void testJavaCrashInMainThread_onClick(View view) { 67 | XCrash.testJavaCrash(false); 68 | } 69 | 70 | public void testJavaCrashInAnotherThread_onClick(View view) { 71 | XCrash.testJavaCrash(true); 72 | } 73 | 74 | public void testJavaCrashInAnotherActivity_onClick(View view) { 75 | startActivity(new Intent(this, SecondActivity.class).putExtra("type", "java")); 76 | } 77 | 78 | public void testJavaCrashInAnotherProcess_onClick(View view) { 79 | startService(new Intent(this, MyService.class).putExtra("type", "java")); 80 | } 81 | public void testAnrInput_onClick(View view) { 82 | while (true) { 83 | try { 84 | Thread.sleep(1000); 85 | } catch (Exception ignored) { 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/java/xcrash/sample/MyCustomApplication.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020-present, HexHacking Team. All rights reserved. 2 | // Copyright (c) 2019, iQIYI, Inc. All rights reserved. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | // 22 | 23 | // Created by caikelun on 2019-03-07. 24 | package xcrash.sample; 25 | 26 | import android.app.Application; 27 | import android.content.Context; 28 | import android.util.Log; 29 | 30 | import org.json.JSONObject; 31 | 32 | import java.io.File; 33 | import java.io.FileWriter; 34 | 35 | import xcrash.TombstoneManager; 36 | import xcrash.TombstoneParser; 37 | import xcrash.XCrash; 38 | import xcrash.ICrashCallback; 39 | 40 | public class MyCustomApplication extends Application { 41 | private final String TAG = "xcrash_sample"; 42 | 43 | @Override 44 | protected void attachBaseContext(Context base) { 45 | super.attachBaseContext(base); 46 | 47 | // callback for java crash, native crash and ANR 48 | ICrashCallback callback = new ICrashCallback() { 49 | @Override 50 | public void onCrash(String logPath, String emergency) { 51 | Log.d(TAG, "log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)")); 52 | 53 | if (emergency != null) { 54 | debug(logPath, emergency); 55 | 56 | // Disk is exhausted, send crash report immediately. 57 | sendThenDeleteCrashLog(logPath, emergency); 58 | } else { 59 | // Add some expanded sections. Send crash report at the next time APP startup. 60 | 61 | // OK 62 | TombstoneManager.appendSection(logPath, "expanded_key_1", "expanded_content"); 63 | TombstoneManager.appendSection(logPath, "expanded_key_2", "expanded_content_row_1\nexpanded_content_row_2"); 64 | 65 | // Invalid. (Do NOT include multiple consecutive newline characters ("\n\n") in the content string.) 66 | // TombstoneManager.appendSection(logPath, "expanded_key_3", "expanded_content_row_1\n\nexpanded_content_row_2"); 67 | 68 | debug(logPath, null); 69 | } 70 | } 71 | }; 72 | 73 | Log.d(TAG, "xCrash SDK init: start"); 74 | 75 | // Initialize xCrash. 76 | XCrash.init(this, new XCrash.InitParameters() 77 | .setAppVersion("1.2.3-beta456-patch789") 78 | .setJavaRethrow(true) 79 | .setJavaLogCountMax(10) 80 | //.setJavaDumpAllThreadsAllowList(new String[]{"^main$", "^Binder:.*", ".*Finalizer.*"}) 81 | //.setJavaDumpAllThreadsCountMax(10) 82 | .setJavaCallback(callback) 83 | .setNativeRethrow(true) 84 | .setNativeLogCountMax(10) 85 | .setNativeDumpAllThreads(true) 86 | //.setNativeDumpAllThreadsAllowList(new String[]{"^xcrash\\.sample$", "^Signal Catcher$", "^Jit thread pool$", ".*(R|r)ender.*", ".*Chrome.*"}) 87 | //.setNativeDumpAllThreadsCountMax(10) 88 | .setNativeCallback(callback) 89 | .setAnrRethrow(true) 90 | .setAnrLogCountMax(10) 91 | .setAnrCallback(callback) 92 | .setPlaceholderCountMax(3) 93 | .setPlaceholderSizeKb(512) 94 | .setLogFileMaintainDelayMs(1000)); 95 | 96 | Log.d(TAG, "xCrash SDK init: end"); 97 | 98 | // Send all pending crash log files. 99 | new Thread(new Runnable() { 100 | @Override 101 | public void run() { 102 | for(File file : TombstoneManager.getAllTombstones()) { 103 | sendThenDeleteCrashLog(file.getAbsolutePath(), null); 104 | } 105 | } 106 | }).start(); 107 | } 108 | 109 | private void sendThenDeleteCrashLog(String logPath, String emergency) { 110 | // Parse 111 | //Map map = TombstoneParser.parse(logPath, emergency); 112 | //String crashReport = new JSONObject(map).toString(); 113 | 114 | // Send the crash report to server-side. 115 | // ...... 116 | 117 | // If the server-side receives successfully, delete the log file. 118 | // 119 | // Note: When you use the placeholder file feature, 120 | // please always use this method to delete tombstone files. 121 | // 122 | //TombstoneManager.deleteTombstone(logPath); 123 | } 124 | 125 | private void debug(String logPath, String emergency) { 126 | // Parse and save the crash info to a JSON file for debugging. 127 | FileWriter writer = null; 128 | try { 129 | File debug = new File(getApplicationContext().getFilesDir() + "/tombstones/debug.json"); 130 | debug.createNewFile(); 131 | writer = new FileWriter(debug, false); 132 | writer.write(new JSONObject(TombstoneParser.parse(logPath, emergency)).toString()); 133 | } catch (Exception e) { 134 | Log.d(TAG, "debug failed", e); 135 | } finally { 136 | if (writer != null) { 137 | try { 138 | writer.close(); 139 | } catch (Exception ignored) { 140 | } 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/java/xcrash/sample/MyService.java: -------------------------------------------------------------------------------- 1 | package xcrash.sample; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | 7 | import xcrash.XCrash; 8 | 9 | public class MyService extends Service { 10 | public MyService() { 11 | } 12 | 13 | @Override 14 | public void onCreate() { 15 | } 16 | 17 | @Override 18 | public int onStartCommand(Intent intent, int flags, int startId) { 19 | String type = intent.getStringExtra("type"); 20 | if (type != null) { 21 | if (type.equals("native")) { 22 | XCrash.testNativeCrash(false); 23 | } else if (type.equals("java")) { 24 | XCrash.testJavaCrash(false); 25 | } 26 | } 27 | return START_NOT_STICKY; 28 | } 29 | 30 | @Override 31 | public IBinder onBind(Intent intent) { 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/java/xcrash/sample/SecondActivity.java: -------------------------------------------------------------------------------- 1 | package xcrash.sample; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | 8 | import xcrash.XCrash; 9 | 10 | public class SecondActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_second); 16 | 17 | Intent intent = getIntent(); 18 | String type = intent.getStringExtra("type"); 19 | if (type != null) { 20 | if (type.equals("native")) { 21 | XCrash.testNativeCrash(false); 22 | } else if (type.equals("java")) { 23 | XCrash.testJavaCrash(false); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/layout/activity_second.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hexhacking/xCrash/656b0bc6992ff51fd365ba5a7a750530981cdd5c/xcrash_sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | xcrash_sample 3 | 4 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | --------------------------------------------------------------------------------