├── .gitignore ├── 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_armeabi.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_armeabi.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 │ │ ├── queue.h │ │ ├── tree.h │ │ ├── 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 │ ├── dl │ │ ├── README.md │ │ ├── xc_dl.c │ │ └── xc_dl.h │ ├── lzma │ │ ├── 7z.h │ │ ├── 7zAlloc.c │ │ ├── 7zAlloc.h │ │ ├── 7zArcIn.c │ │ ├── 7zBuf.c │ │ ├── 7zBuf.h │ │ ├── 7zBuf2.c │ │ ├── 7zCrc.c │ │ ├── 7zCrc.h │ │ ├── 7zCrcOpt.c │ │ ├── 7zDec.c │ │ ├── 7zFile.c │ │ ├── 7zFile.h │ │ ├── 7zStream.c │ │ ├── 7zTypes.h │ │ ├── 7zVersion.h │ │ ├── 7zVersion.rc │ │ ├── Aes.c │ │ ├── Aes.h │ │ ├── AesOpt.c │ │ ├── Alloc.c │ │ ├── Alloc.h │ │ ├── Bcj2.c │ │ ├── Bcj2.h │ │ ├── Bcj2Enc.c │ │ ├── Bra.c │ │ ├── Bra.h │ │ ├── Bra86.c │ │ ├── BraIA64.c │ │ ├── Compiler.h │ │ ├── CpuArch.c │ │ ├── CpuArch.h │ │ ├── Delta.c │ │ ├── Delta.h │ │ ├── DllSecur.c │ │ ├── DllSecur.h │ │ ├── LICENSE │ │ ├── LzFind.c │ │ ├── LzFind.h │ │ ├── LzFindMt.c │ │ ├── LzFindMt.h │ │ ├── LzHash.h │ │ ├── Lzma2Dec.c │ │ ├── Lzma2Dec.h │ │ ├── Lzma2DecMt.c │ │ ├── Lzma2DecMt.h │ │ ├── Lzma2Enc.c │ │ ├── Lzma2Enc.h │ │ ├── Lzma86.h │ │ ├── Lzma86Dec.c │ │ ├── Lzma86Enc.c │ │ ├── LzmaDec.c │ │ ├── LzmaDec.h │ │ ├── LzmaEnc.c │ │ ├── LzmaEnc.h │ │ ├── LzmaLib.c │ │ ├── LzmaLib.h │ │ ├── MtCoder.c │ │ ├── MtCoder.h │ │ ├── MtDec.c │ │ ├── MtDec.h │ │ ├── Ppmd.h │ │ ├── Ppmd7.c │ │ ├── Ppmd7.h │ │ ├── Ppmd7Dec.c │ │ ├── Ppmd7Enc.c │ │ ├── Precomp.h │ │ ├── RotateDefs.h │ │ ├── Sha256.c │ │ ├── Sha256.h │ │ ├── Sort.c │ │ ├── Sort.h │ │ ├── Threads.c │ │ ├── Threads.h │ │ ├── Xz.c │ │ ├── Xz.h │ │ ├── XzCrc64.c │ │ ├── XzCrc64.h │ │ ├── XzCrc64Opt.c │ │ ├── XzDec.c │ │ ├── XzEnc.c │ │ ├── XzEnc.h │ │ └── XzIn.c │ ├── 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 | -------------------------------------------------------------------------------- /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 iQIYI's 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 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:4.1.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | // mavenLocal() 16 | mavenCentral() 17 | maven {url "https://s01.oss.sonatype.org/content/groups/public"} 18 | maven {url "https://s01.oss.sonatype.org/content/repositories/releases"} 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | 26 | ext { 27 | minSdkVersion = 16 28 | compileSdkVersion = 31 29 | targetSdkVersion = 31 30 | buildToolsVersion = '30.0.2' 31 | javaVersion = JavaVersion.VERSION_1_8 32 | ndkVersion = "21.3.6528147" 33 | cmakeVersion = "3.10.2" 34 | abiFilters = "armeabi-v7a,arm64-v8a,x86,x86_64" 35 | useASAN = false 36 | 37 | POM_GROUP_ID = "com.iqiyi.xcrash" 38 | POM_ARTIFACT_ID = "xcrash-android-lib" 39 | POM_VERSION_NAME = "3.1.0" 40 | 41 | POM_NAME = "xCrash Android Lib" 42 | POM_DESCRIPTION = "xCrash provides the Android app with the ability to capture java crash, native crash and ANR." 43 | POM_URL = "https://github.com/iqiyi/xCrash" 44 | POM_INCEPTION_YEAR = "2020" 45 | POM_PACKAGING = "aar" 46 | 47 | POM_SCM_CONNECTION = "https://github.com/iqiyi/xCrash.git" 48 | 49 | POM_ISSUE_SYSTEM = "github" 50 | POM_ISSUE_URL = "https://github.com/iqiyi/xCrash/issues" 51 | 52 | POM_LICENCE_NAME = "The MIT License" 53 | POM_LICENCE_URL = "https://opensource.org/licenses/MIT" 54 | POM_LICENCE_DIST = "repo" 55 | 56 | POM_DEVELOPER_ID = "iQIYI" 57 | POM_DEVELOPER_NAME = "iQIYI, Inc." 58 | } 59 | -------------------------------------------------------------------------------- /doc/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/doc/architecture.png -------------------------------------------------------------------------------- /doc/capture_anr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/doc/capture_anr.png -------------------------------------------------------------------------------- /doc/capture_native_crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/doc/capture_native_crash.png -------------------------------------------------------------------------------- /doc/intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/doc/intro.png -------------------------------------------------------------------------------- /doc/xcrash_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/doc/xcrash_logo.png -------------------------------------------------------------------------------- /doc/xcrash_logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | ext["signing.keyId"] = '' 5 | ext["signing.password"] = '' 6 | ext["signing.secretKeyRingFile"] = '' 7 | ext["ossrhUsername"] = '' 8 | ext["ossrhPassword"] = '' 9 | 10 | File secretPropsFile = project.rootProject.file('local.properties') 11 | if (secretPropsFile.exists()) { 12 | Properties p = new Properties() 13 | p.load(new FileInputStream(secretPropsFile)) 14 | p.each { name, value -> 15 | ext[name] = value 16 | } 17 | } else { 18 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') 19 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD') 20 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') 21 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') 22 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') 23 | } 24 | 25 | task sourcesJar(type: Jar) { 26 | archiveClassifier.set("sources") 27 | from android.sourceSets.main.java.srcDirs 28 | } 29 | 30 | task javadoc(type: Javadoc) { 31 | source = android.sourceSets.main.java.sourceFiles 32 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 33 | } 34 | 35 | task javadocJar(type: Jar, dependsOn: javadoc) { 36 | archiveClassifier.set("javadoc") 37 | from javadoc.destinationDir 38 | } 39 | 40 | project.afterEvaluate { 41 | publishing { 42 | publications { 43 | release(MavenPublication) { 44 | from components.release 45 | 46 | artifact sourcesJar 47 | artifact javadocJar 48 | 49 | artifactId POM_ARTIFACT_ID 50 | groupId POM_GROUP_ID 51 | version POM_VERSION_NAME 52 | 53 | pom { 54 | name = POM_NAME 55 | description = POM_DESCRIPTION 56 | url = POM_URL 57 | inceptionYear = POM_INCEPTION_YEAR 58 | packaging = POM_PACKAGING 59 | scm { 60 | connection = POM_SCM_CONNECTION 61 | url = POM_URL 62 | } 63 | issueManagement { 64 | system = POM_ISSUE_SYSTEM 65 | url = POM_ISSUE_URL 66 | } 67 | licenses { 68 | license { 69 | name = POM_LICENCE_NAME 70 | url = POM_LICENCE_URL 71 | distribution = POM_LICENCE_DIST 72 | } 73 | } 74 | developers { 75 | developer { 76 | id = POM_DEVELOPER_ID 77 | name = POM_DEVELOPER_NAME 78 | } 79 | } 80 | } 81 | } 82 | } 83 | repositories { 84 | maven { 85 | name = "sonatype" 86 | 87 | def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" 88 | def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" 89 | url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl 90 | 91 | credentials { 92 | username ossrhUsername 93 | password ossrhPassword 94 | } 95 | } 96 | } 97 | } 98 | } 99 | 100 | signing { 101 | sign publishing.publications 102 | } 103 | -------------------------------------------------------------------------------- /gradle/sanitizer.gradle: -------------------------------------------------------------------------------- 1 | project.afterEvaluate { 2 | 3 | preBuild.doFirst { 4 | def projectDir = project.projectDir.toString() 5 | 6 | if (rootProject.ext.useASAN) { 7 | def ndkLibDir = android.ndkDirectory.absolutePath + "/toolchains/llvm/prebuilt/" 8 | def ABIs = rootProject.ext.abiFilters.split(",") 9 | 10 | for (String abi : ABIs) { 11 | def arch = abi 12 | if (abi == 'armeabi-v7a') { 13 | arch = "arm" 14 | } else if (abi == "arm64-v8a") { 15 | arch = "aarch64" 16 | } else if (abi == "x86") { 17 | arch = "i686" 18 | } else if (abi == "x86_64") { 19 | arch = "x86_64" 20 | } 21 | 22 | // create ASAN wrap.sh 23 | def resDir = new File(projectDir + "/src/main/resources/lib/" + abi) 24 | resDir.mkdirs() 25 | def wrapFile = new File(resDir, "wrap.sh") 26 | wrapFile.withWriter { writer -> 27 | writer.write('#!/system/bin/sh\n') 28 | writer.write('HERE="$(cd "$(dirname "$0")" && pwd)"\n') 29 | 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') 30 | writer.write("ASAN_LIB=\$(ls \$HERE/libclang_rt.asan-${arch}-android.so)\n") 31 | writer.write('if [ -f "$HERE/libc++_shared.so" ]; then\n') 32 | writer.write(' export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"\n') 33 | writer.write('else\n') 34 | writer.write(' export LD_PRELOAD="$ASAN_LIB"\n') 35 | writer.write('fi\n') 36 | writer.write('"\$@"\n') 37 | } 38 | println "sanitizer: [${abi}] create wrap.sh: " + wrapFile.absolutePath 39 | 40 | // copy ASAN libs 41 | def libDir = new File(projectDir + "/src/main/jniLibs/" + abi) 42 | libDir.mkdirs() 43 | FileTree tree = fileTree(dir: ndkLibDir).include("**/libclang_rt.asan-${arch}-android.so") 44 | tree.each { File file -> 45 | copy { 46 | from file 47 | into libDir.absolutePath 48 | } 49 | println "sanitizer: [${abi}] copy lib: ${file.absolutePath} -> ${libDir.absolutePath}" 50 | } 51 | } 52 | } else { 53 | delete projectDir + '/src/main/resources/' 54 | delete projectDir + '/src/main/jniLibs/' 55 | } 56 | } 57 | } 58 | 59 | clean.doFirst { 60 | def projectDir = project.projectDir.toString() 61 | delete projectDir + '/src/main/resources/' 62 | delete projectDir + '/src/main/jniLibs/' 63 | } 64 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Oct 23 17:17:57 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.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 | void traceCallbackBeforeDump(...); 6 | } 7 | -------------------------------------------------------------------------------- /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 | # libxcrash.so 14 | ####################################### 15 | 16 | file(GLOB XCRASH_SRC 17 | xcrash/*.c 18 | common/*.c 19 | dl/*.c) 20 | 21 | add_library(xcrash SHARED 22 | ${XCRASH_SRC}) 23 | 24 | target_include_directories(xcrash PUBLIC 25 | xcrash 26 | xcrash_dumper 27 | common 28 | dl) 29 | 30 | target_link_libraries(xcrash 31 | log 32 | dl) 33 | 34 | if(USEASAN) 35 | 36 | target_compile_options(xcrash PUBLIC 37 | -fsanitize=address 38 | -fno-omit-frame-pointer) 39 | 40 | set_target_properties(xcrash PROPERTIES 41 | LINK_FLAGS " \ 42 | -fsanitize=address") 43 | 44 | else() 45 | 46 | target_compile_options(xcrash PUBLIC 47 | -Oz 48 | -flto 49 | -ffunction-sections 50 | -fdata-sections) 51 | 52 | set_target_properties(xcrash PROPERTIES 53 | LINK_FLAGS " \ 54 | -O3 \ 55 | -flto \ 56 | -Wl,--exclude-libs,ALL \ 57 | -Wl,--gc-sections \ 58 | -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/xcrash.exports") 59 | 60 | endif() 61 | 62 | ####################################### 63 | # libxcrash_dumper.so 64 | ####################################### 65 | 66 | file(GLOB XCRASH_DUMPER_SRC 67 | xcrash_dumper/*.c 68 | common/*.c) 69 | 70 | set(LZME_SRC 71 | lzma/7zCrc.c 72 | lzma/7zCrcOpt.c 73 | lzma/CpuArch.c 74 | lzma/Bra.c 75 | lzma/Bra86.c 76 | lzma/BraIA64.c 77 | lzma/Delta.c 78 | lzma/Lzma2Dec.c 79 | lzma/LzmaDec.c 80 | lzma/Sha256.c 81 | lzma/Xz.c 82 | lzma/XzCrc64.c 83 | lzma/XzCrc64Opt.c 84 | lzma/XzDec.c) 85 | 86 | set_source_files_properties(${LZME_SRC} PROPERTIES 87 | COMPILE_FLAGS " \ 88 | -D_7ZIP_ST \ 89 | -Wno-enum-conversion \ 90 | -Wno-reserved-id-macro \ 91 | -Wno-undef \ 92 | -Wno-missing-prototypes \ 93 | -Wno-missing-variable-declarations \ 94 | -Wno-cast-align \ 95 | -Wno-sign-conversion \ 96 | -Wno-assign-enum \ 97 | -Wno-unused-macros \ 98 | -Wno-padded \ 99 | -Wno-cast-qual \ 100 | -Wno-strict-prototypes \ 101 | -Wno-extra-semi-stmt") 102 | 103 | add_executable(xcrash_dumper 104 | ${XCRASH_DUMPER_SRC} 105 | ${LZME_SRC}) 106 | 107 | target_include_directories(xcrash_dumper PUBLIC 108 | xcrash_dumper 109 | common 110 | lzma) 111 | 112 | target_link_libraries(xcrash_dumper 113 | log 114 | dl) 115 | 116 | if(USEASAN) 117 | 118 | target_compile_options(xcrash_dumper PUBLIC 119 | -fsanitize=address 120 | -fno-omit-frame-pointer) 121 | 122 | set_target_properties(xcrash_dumper PROPERTIES 123 | LINK_FLAGS " \ 124 | -fsanitize=address") 125 | 126 | else() 127 | 128 | target_compile_options(xcrash_dumper PUBLIC 129 | -Oz 130 | -flto 131 | -ffunction-sections 132 | -fdata-sections) 133 | 134 | set_target_properties(xcrash_dumper PROPERTIES 135 | LINK_FLAGS " \ 136 | -O3 \ 137 | -flto \ 138 | -Wl,--exclude-libs,ALL \ 139 | -Wl,--gc-sections") 140 | 141 | endif() 142 | 143 | set_target_properties(xcrash_dumper PROPERTIES 144 | PREFIX "lib" 145 | SUFFIX ".so") 146 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_b64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-12. 23 | 24 | #ifndef XCC_B64_H 25 | #define XCC_B64_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | size_t xcc_b64_encode_max_len(size_t in_len); 35 | char *xcc_b64_encode(const uint8_t *in, size_t in_len, size_t *out_len); 36 | 37 | size_t xcc_b64_decode_max_len(size_t in_len); 38 | uint8_t *xcc_b64_decode(const char *in, size_t in_len, size_t *out_len); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_errno.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_ERRNO_H 25 | #define XCC_ERRNO_H 1 26 | 27 | #include 28 | 29 | #define XCC_ERRNO_UNKNOWN 1001 30 | #define XCC_ERRNO_INVAL 1002 31 | #define XCC_ERRNO_NOMEM 1003 32 | #define XCC_ERRNO_NOSPACE 1004 33 | #define XCC_ERRNO_RANGE 1005 34 | #define XCC_ERRNO_NOTFND 1006 35 | #define XCC_ERRNO_MISSING 1007 36 | #define XCC_ERRNO_MEM 1008 37 | #define XCC_ERRNO_DEV 1009 38 | #define XCC_ERRNO_PERM 1010 39 | #define XCC_ERRNO_FORMAT 1011 40 | #define XCC_ERRNO_ILLEGAL 1012 41 | #define XCC_ERRNO_NOTSPT 1013 42 | #define XCC_ERRNO_STATE 1014 43 | #define XCC_ERRNO_JNI 1015 44 | #define XCC_ERRNO_FD 1016 45 | 46 | #define XCC_ERRNO_SYS ((0 != errno) ? errno : XCC_ERRNO_UNKNOWN) 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_fmt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_FMT_H 25 | #define XCC_FMT_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | size_t xcc_fmt_snprintf(char *buffer, size_t buffer_size, const char *format, ...); 36 | size_t xcc_fmt_vsnprintf(char *buffer, size_t buffer_size, const char *format, va_list args); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_libc_support.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by Sim Sun on 2019-09-17. 23 | 24 | #ifndef XCC_LIBC_SUPPORT_H 25 | #define XCC_LIBC_SUPPORT_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | // memset(3) is not async-signal-safe, ref: http://boston.conman.org/2016/12/17.1 35 | void *xcc_libc_support_memset(void *s, int c, size_t n); 36 | 37 | // you need to pass timezone through gmtoff 38 | struct tm *xcc_libc_support_localtime_r(const time_t *timev, long gmtoff, struct tm *result); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_meminfo.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-22. 23 | 24 | #ifndef XCC_MEMINFO_H 25 | #define XCC_MEMINFO_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | int xcc_meminfo_record(int log_fd, pid_t pid); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_signal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_SIGNAL_CRASH_H 25 | #define XCC_SIGNAL_CRASH_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int xcc_signal_crash_register(void (*handler)(int, siginfo_t *, void *)); 36 | int xcc_signal_crash_unregister(void); 37 | int xcc_signal_crash_ignore(void); 38 | int xcc_signal_crash_queue(siginfo_t* si); 39 | 40 | int xcc_signal_trace_register(void (*handler)(int, siginfo_t *, void *)); 41 | void xcc_signal_trace_unregister(void); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_spot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_SPOT_H 25 | #define XCC_SPOT_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #pragma clang diagnostic push 37 | #pragma clang diagnostic ignored "-Wpadded" 38 | 39 | typedef struct 40 | { 41 | //set when crashed 42 | pid_t crash_tid; 43 | siginfo_t siginfo; 44 | ucontext_t ucontext; 45 | uint64_t crash_time; 46 | 47 | //set when inited 48 | int api_level; 49 | pid_t crash_pid; 50 | uint64_t start_time; 51 | long time_zone; 52 | unsigned int logcat_system_lines; 53 | unsigned int logcat_events_lines; 54 | unsigned int logcat_main_lines; 55 | int dump_elf_hash; 56 | int dump_map; 57 | int dump_fds; 58 | int dump_network_info; 59 | int dump_all_threads; 60 | unsigned int dump_all_threads_count_max; 61 | 62 | //set when crashed (content lengths after this struct) 63 | size_t log_pathname_len; 64 | 65 | //set when inited (content lengths after this struct) 66 | size_t os_version_len; 67 | size_t kernel_version_len; 68 | size_t abi_list_len; 69 | size_t manufacturer_len; 70 | size_t brand_len; 71 | size_t model_len; 72 | size_t build_fingerprint_len; 73 | size_t app_id_len; 74 | size_t app_version_len; 75 | size_t dump_all_threads_whitelist_len; 76 | } xcc_spot_t; 77 | 78 | #pragma clang diagnostic pop 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "xcc_unwind.h" 29 | #include "xcc_unwind_libcorkscrew.h" 30 | #include "xcc_unwind_libunwind.h" 31 | #include "xcc_unwind_clang.h" 32 | 33 | void xcc_unwind_init(int api_level) 34 | { 35 | #if defined(__arm__) || defined(__i386__) 36 | if(api_level >= 16 && api_level <= 20) 37 | { 38 | xcc_unwind_libcorkscrew_init(); 39 | } 40 | #endif 41 | 42 | if(api_level >= 21 && api_level <= 23) 43 | { 44 | xcc_unwind_libunwind_init(); 45 | } 46 | } 47 | 48 | size_t xcc_unwind_get(int api_level, siginfo_t *si, ucontext_t *uc, char *buf, size_t buf_len) 49 | { 50 | size_t buf_used; 51 | 52 | #if defined(__arm__) || defined(__i386__) 53 | if(api_level >= 16 && api_level <= 20) 54 | { 55 | if(0 == (buf_used = xcc_unwind_libcorkscrew_record(si, uc, buf, buf_len))) goto bottom; 56 | return buf_used; 57 | } 58 | #else 59 | (void)si; 60 | #endif 61 | 62 | if(api_level >= 21 && api_level <= 23) 63 | { 64 | if(0 == (buf_used = xcc_unwind_libunwind_record(uc, buf, buf_len))) goto bottom; 65 | return buf_used; 66 | } 67 | 68 | bottom: 69 | return xcc_unwind_clang_record(uc, buf, buf_len); 70 | } 71 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_UNWIND_H 25 | #define XCC_UNWIND_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | void xcc_unwind_init(int api_level); 36 | 37 | size_t xcc_unwind_get(int api_level, siginfo_t *si, 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_unwind_clang.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-08-02. 23 | 24 | #ifndef XCC_UNWIND_CLANG_H 25 | #define XCC_UNWIND_CLANG_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | size_t xcc_unwind_clang_record(ucontext_t *uc, char *buf, size_t buf_len); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind_libcorkscrew.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-08-02. 23 | 24 | #if defined(__arm__) || defined(__i386__) 25 | 26 | #ifndef XCC_UNWIND_LIBCORKSCREW_H 27 | #define XCC_UNWIND_LIBCORKSCREW_H 1 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | void xcc_unwind_libcorkscrew_init(void); 39 | size_t xcc_unwind_libcorkscrew_record(siginfo_t *si, ucontext_t *uc, char *buf, size_t buf_len); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/common/xcc_unwind_libunwind.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-08-02. 23 | 24 | #ifndef XCC_UNWIND_LIBUNWIND_H 25 | #define XCC_UNWIND_LIBUNWIND_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | void xcc_unwind_libunwind_init(void); 36 | size_t xcc_unwind_libunwind_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_version.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCC_VERSION_H 25 | #define XCC_VERSION_H 1 26 | 27 | #define XCC_VERSION_STR "xCrash 3.1.0" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/dl/xc_dl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-08-16. 23 | 24 | #ifndef XC_DL_H 25 | #define XC_DL_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef struct xc_dl xc_dl_t; 35 | 36 | xc_dl_t *xc_dl_create(const char *pathname); 37 | void xc_dl_destroy(xc_dl_t **self); 38 | 39 | void *xc_dl_sym(xc_dl_t *self, const char *symbol); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zAlloc.c: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.c -- Allocation functions 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zAlloc.h" 9 | 10 | /* #define _SZ_ALLOC_DEBUG */ 11 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 12 | 13 | #ifdef _SZ_ALLOC_DEBUG 14 | 15 | #ifdef _WIN32 16 | #include 17 | #endif 18 | 19 | #include 20 | int g_allocCount = 0; 21 | int g_allocCountTemp = 0; 22 | 23 | #endif 24 | 25 | void *SzAlloc(ISzAllocPtr p, size_t size) 26 | { 27 | UNUSED_VAR(p); 28 | if (size == 0) 29 | return 0; 30 | #ifdef _SZ_ALLOC_DEBUG 31 | fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount); 32 | g_allocCount++; 33 | #endif 34 | return malloc(size); 35 | } 36 | 37 | void SzFree(ISzAllocPtr p, void *address) 38 | { 39 | UNUSED_VAR(p); 40 | #ifdef _SZ_ALLOC_DEBUG 41 | if (address != 0) 42 | { 43 | g_allocCount--; 44 | fprintf(stderr, "\nFree; count = %10d", g_allocCount); 45 | } 46 | #endif 47 | free(address); 48 | } 49 | 50 | void *SzAllocTemp(ISzAllocPtr p, size_t size) 51 | { 52 | UNUSED_VAR(p); 53 | if (size == 0) 54 | return 0; 55 | #ifdef _SZ_ALLOC_DEBUG 56 | fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp); 57 | g_allocCountTemp++; 58 | #ifdef _WIN32 59 | return HeapAlloc(GetProcessHeap(), 0, size); 60 | #endif 61 | #endif 62 | return malloc(size); 63 | } 64 | 65 | void SzFreeTemp(ISzAllocPtr p, void *address) 66 | { 67 | UNUSED_VAR(p); 68 | #ifdef _SZ_ALLOC_DEBUG 69 | if (address != 0) 70 | { 71 | g_allocCountTemp--; 72 | fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); 73 | } 74 | #ifdef _WIN32 75 | HeapFree(GetProcessHeap(), 0, address); 76 | return; 77 | #endif 78 | #endif 79 | free(address); 80 | } 81 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zAlloc.h: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.h -- Allocation functions 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_ALLOC_H 5 | #define __7Z_ALLOC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void *SzAlloc(ISzAllocPtr p, size_t size); 12 | void SzFree(ISzAllocPtr p, void *address); 13 | 14 | void *SzAllocTemp(ISzAllocPtr p, size_t size); 15 | void SzFreeTemp(ISzAllocPtr p, void *address); 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zBuf.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf.c -- Byte Buffer 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zBuf.h" 7 | 8 | void Buf_Init(CBuf *p) 9 | { 10 | p->data = 0; 11 | p->size = 0; 12 | } 13 | 14 | int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc) 15 | { 16 | p->size = 0; 17 | if (size == 0) 18 | { 19 | p->data = 0; 20 | return 1; 21 | } 22 | p->data = (Byte *)ISzAlloc_Alloc(alloc, size); 23 | if (p->data) 24 | { 25 | p->size = size; 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | void Buf_Free(CBuf *p, ISzAllocPtr alloc) 32 | { 33 | ISzAlloc_Free(alloc, p->data); 34 | p->data = 0; 35 | p->size = 0; 36 | } 37 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zBuf.h: -------------------------------------------------------------------------------- 1 | /* 7zBuf.h -- Byte Buffer 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_BUF_H 5 | #define __7Z_BUF_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | Byte *data; 14 | size_t size; 15 | } CBuf; 16 | 17 | void Buf_Init(CBuf *p); 18 | int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc); 19 | void Buf_Free(CBuf *p, ISzAllocPtr alloc); 20 | 21 | typedef struct 22 | { 23 | Byte *data; 24 | size_t size; 25 | size_t pos; 26 | } CDynBuf; 27 | 28 | void DynBuf_Construct(CDynBuf *p); 29 | void DynBuf_SeekToBeg(CDynBuf *p); 30 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc); 31 | void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc); 32 | 33 | EXTERN_C_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zBuf2.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf2.c -- Byte Buffer 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zBuf.h" 9 | 10 | void DynBuf_Construct(CDynBuf *p) 11 | { 12 | p->data = 0; 13 | p->size = 0; 14 | p->pos = 0; 15 | } 16 | 17 | void DynBuf_SeekToBeg(CDynBuf *p) 18 | { 19 | p->pos = 0; 20 | } 21 | 22 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc) 23 | { 24 | if (size > p->size - p->pos) 25 | { 26 | size_t newSize = p->pos + size; 27 | Byte *data; 28 | newSize += newSize / 4; 29 | data = (Byte *)ISzAlloc_Alloc(alloc, newSize); 30 | if (!data) 31 | return 0; 32 | p->size = newSize; 33 | if (p->pos != 0) 34 | memcpy(data, p->data, p->pos); 35 | ISzAlloc_Free(alloc, p->data); 36 | p->data = data; 37 | } 38 | if (size != 0) 39 | { 40 | memcpy(p->data + p->pos, buf, size); 41 | p->pos += size; 42 | } 43 | return 1; 44 | } 45 | 46 | void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc) 47 | { 48 | ISzAlloc_Free(alloc, p->data); 49 | p->data = 0; 50 | p->size = 0; 51 | p->pos = 0; 52 | } 53 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zCrc.h: -------------------------------------------------------------------------------- 1 | /* 7zCrc.h -- CRC32 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_CRC_H 5 | #define __7Z_CRC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | extern UInt32 g_CrcTable[]; 12 | 13 | /* Call CrcGenerateTable one time before other CRC functions */ 14 | void MY_FAST_CALL CrcGenerateTable(void); 15 | 16 | #define CRC_INIT_VAL 0xFFFFFFFF 17 | #define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) 18 | #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 19 | 20 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); 21 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); 22 | 23 | EXTERN_C_END 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zFile.h: -------------------------------------------------------------------------------- 1 | /* 7zFile.h -- File IO 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_FILE_H 5 | #define __7Z_FILE_H 6 | 7 | #ifdef _WIN32 8 | #define USE_WINDOWS_FILE 9 | #endif 10 | 11 | #ifdef USE_WINDOWS_FILE 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #include "7zTypes.h" 18 | 19 | EXTERN_C_BEGIN 20 | 21 | /* ---------- File ---------- */ 22 | 23 | typedef struct 24 | { 25 | #ifdef USE_WINDOWS_FILE 26 | HANDLE handle; 27 | #else 28 | FILE *file; 29 | #endif 30 | } CSzFile; 31 | 32 | void File_Construct(CSzFile *p); 33 | #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 34 | WRes InFile_Open(CSzFile *p, const char *name); 35 | WRes OutFile_Open(CSzFile *p, const char *name); 36 | #endif 37 | #ifdef USE_WINDOWS_FILE 38 | WRes InFile_OpenW(CSzFile *p, const WCHAR *name); 39 | WRes OutFile_OpenW(CSzFile *p, const WCHAR *name); 40 | #endif 41 | WRes File_Close(CSzFile *p); 42 | 43 | /* reads max(*size, remain file's size) bytes */ 44 | WRes File_Read(CSzFile *p, void *data, size_t *size); 45 | 46 | /* writes *size bytes */ 47 | WRes File_Write(CSzFile *p, const void *data, size_t *size); 48 | 49 | WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); 50 | WRes File_GetLength(CSzFile *p, UInt64 *length); 51 | 52 | 53 | /* ---------- FileInStream ---------- */ 54 | 55 | typedef struct 56 | { 57 | ISeqInStream vt; 58 | CSzFile file; 59 | } CFileSeqInStream; 60 | 61 | void FileSeqInStream_CreateVTable(CFileSeqInStream *p); 62 | 63 | 64 | typedef struct 65 | { 66 | ISeekInStream vt; 67 | CSzFile file; 68 | } CFileInStream; 69 | 70 | void FileInStream_CreateVTable(CFileInStream *p); 71 | 72 | 73 | typedef struct 74 | { 75 | ISeqOutStream vt; 76 | CSzFile file; 77 | } CFileOutStream; 78 | 79 | void FileOutStream_CreateVTable(CFileOutStream *p); 80 | 81 | EXTERN_C_END 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 18 2 | #define MY_VER_MINOR 05 3 | #define MY_VER_BUILD 0 4 | #define MY_VERSION_NUMBERS "18.05" 5 | #define MY_VERSION MY_VERSION_NUMBERS 6 | 7 | #ifdef MY_CPU_NAME 8 | #define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")" 9 | #else 10 | #define MY_VERSION_CPU MY_VERSION 11 | #endif 12 | 13 | #define MY_DATE "2018-04-30" 14 | #undef MY_COPYRIGHT 15 | #undef MY_VERSION_COPYRIGHT_DATE 16 | #define MY_AUTHOR_NAME "Igor Pavlov" 17 | #define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" 18 | #define MY_COPYRIGHT_CR "Copyright (c) 1999-2018 Igor Pavlov" 19 | 20 | #ifdef USE_COPYRIGHT_CR 21 | #define MY_COPYRIGHT MY_COPYRIGHT_CR 22 | #else 23 | #define MY_COPYRIGHT MY_COPYRIGHT_PD 24 | #endif 25 | 26 | #define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE 27 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE 28 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/7zVersion.rc: -------------------------------------------------------------------------------- 1 | #define MY_VS_FFI_FILEFLAGSMASK 0x0000003FL 2 | #define MY_VOS_NT_WINDOWS32 0x00040004L 3 | #define MY_VOS_CE_WINDOWS32 0x00050004L 4 | 5 | #define MY_VFT_APP 0x00000001L 6 | #define MY_VFT_DLL 0x00000002L 7 | 8 | // #include 9 | 10 | #ifndef MY_VERSION 11 | #include "7zVersion.h" 12 | #endif 13 | 14 | #define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0 15 | 16 | #ifdef DEBUG 17 | #define DBG_FL VS_FF_DEBUG 18 | #else 19 | #define DBG_FL 0 20 | #endif 21 | 22 | #define MY_VERSION_INFO(fileType, descr, intName, origName) \ 23 | LANGUAGE 9, 1 \ 24 | 1 VERSIONINFO \ 25 | FILEVERSION MY_VER \ 26 | PRODUCTVERSION MY_VER \ 27 | FILEFLAGSMASK MY_VS_FFI_FILEFLAGSMASK \ 28 | FILEFLAGS DBG_FL \ 29 | FILEOS MY_VOS_NT_WINDOWS32 \ 30 | FILETYPE fileType \ 31 | FILESUBTYPE 0x0L \ 32 | BEGIN \ 33 | BLOCK "StringFileInfo" \ 34 | BEGIN \ 35 | BLOCK "040904b0" \ 36 | BEGIN \ 37 | VALUE "CompanyName", "Igor Pavlov" \ 38 | VALUE "FileDescription", descr \ 39 | VALUE "FileVersion", MY_VERSION \ 40 | VALUE "InternalName", intName \ 41 | VALUE "LegalCopyright", MY_COPYRIGHT \ 42 | VALUE "OriginalFilename", origName \ 43 | VALUE "ProductName", "7-Zip" \ 44 | VALUE "ProductVersion", MY_VERSION \ 45 | END \ 46 | END \ 47 | BLOCK "VarFileInfo" \ 48 | BEGIN \ 49 | VALUE "Translation", 0x409, 1200 \ 50 | END \ 51 | END 52 | 53 | #define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(MY_VFT_APP, descr, intName, intName ".exe") 54 | 55 | #define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(MY_VFT_DLL, descr, intName, intName ".dll") 56 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Aes.h: -------------------------------------------------------------------------------- 1 | /* Aes.h -- AES encryption / decryption 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __AES_H 5 | #define __AES_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define AES_BLOCK_SIZE 16 12 | 13 | /* Call AesGenTables one time before other AES functions */ 14 | void AesGenTables(void); 15 | 16 | /* UInt32 pointers must be 16-byte aligned */ 17 | 18 | /* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */ 19 | #define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4) 20 | 21 | /* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */ 22 | /* keySize = 16 or 24 or 32 (bytes) */ 23 | typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize); 24 | void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize); 25 | void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize); 26 | 27 | /* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */ 28 | void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ 29 | /* data - 16-byte aligned pointer to data */ 30 | /* numBlocks - the number of 16-byte blocks in data array */ 31 | typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks); 32 | extern AES_CODE_FUNC g_AesCbc_Encode; 33 | extern AES_CODE_FUNC g_AesCbc_Decode; 34 | extern AES_CODE_FUNC g_AesCtr_Code; 35 | 36 | EXTERN_C_END 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Alloc.h: -------------------------------------------------------------------------------- 1 | /* Alloc.h -- Memory allocation functions 2 | 2018-02-19 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __COMMON_ALLOC_H 5 | #define __COMMON_ALLOC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void *MyAlloc(size_t size); 12 | void MyFree(void *address); 13 | 14 | #ifdef _WIN32 15 | 16 | void SetLargePageSize(); 17 | 18 | void *MidAlloc(size_t size); 19 | void MidFree(void *address); 20 | void *BigAlloc(size_t size); 21 | void BigFree(void *address); 22 | 23 | #else 24 | 25 | #define MidAlloc(size) MyAlloc(size) 26 | #define MidFree(address) MyFree(address) 27 | #define BigAlloc(size) MyAlloc(size) 28 | #define BigFree(address) MyFree(address) 29 | 30 | #endif 31 | 32 | extern const ISzAlloc g_Alloc; 33 | extern const ISzAlloc g_BigAlloc; 34 | extern const ISzAlloc g_MidAlloc; 35 | extern const ISzAlloc g_AlignedAlloc; 36 | 37 | 38 | typedef struct 39 | { 40 | ISzAlloc vt; 41 | ISzAllocPtr baseAlloc; 42 | unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */ 43 | size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */ 44 | } CAlignOffsetAlloc; 45 | 46 | void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p); 47 | 48 | 49 | EXTERN_C_END 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Bra.h: -------------------------------------------------------------------------------- 1 | /* Bra.h -- Branch converters for executables 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BRA_H 5 | #define __BRA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | These functions convert relative addresses to absolute addresses 13 | in CALL instructions to increase the compression ratio. 14 | 15 | In: 16 | data - data buffer 17 | size - size of data 18 | ip - current virtual Instruction Pinter (IP) value 19 | state - state variable for x86 converter 20 | encoding - 0 (for decoding), 1 (for encoding) 21 | 22 | Out: 23 | state - state variable for x86 converter 24 | 25 | Returns: 26 | The number of processed bytes. If you call these functions with multiple calls, 27 | you must start next call with first byte after block of processed bytes. 28 | 29 | Type Endian Alignment LookAhead 30 | 31 | x86 little 1 4 32 | ARMT little 2 2 33 | ARM little 4 0 34 | PPC big 4 0 35 | SPARC big 4 0 36 | IA64 little 16 0 37 | 38 | size must be >= Alignment + LookAhead, if it's not last block. 39 | If (size < Alignment + LookAhead), converter returns 0. 40 | 41 | Example: 42 | 43 | UInt32 ip = 0; 44 | for () 45 | { 46 | ; size must be >= Alignment + LookAhead, if it's not last block 47 | SizeT processed = Convert(data, size, ip, 1); 48 | data += processed; 49 | size -= processed; 50 | ip += processed; 51 | } 52 | */ 53 | 54 | #define x86_Convert_Init(state) do { state = 0; } while(0) 55 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); 56 | SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 57 | SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 58 | SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 59 | SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 60 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 61 | 62 | EXTERN_C_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Bra86.c: -------------------------------------------------------------------------------- 1 | /* Bra86.c -- Converter for x86 code (BCJ) 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | #define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0) 9 | 10 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) 11 | { 12 | SizeT pos = 0; 13 | UInt32 mask = *state & 7; 14 | if (size < 5) 15 | return 0; 16 | size -= 4; 17 | ip += 5; 18 | 19 | for (;;) 20 | { 21 | Byte *p = data + pos; 22 | const Byte *limit = data + size; 23 | for (; p < limit; p++) 24 | if ((*p & 0xFE) == 0xE8) 25 | break; 26 | 27 | { 28 | SizeT d = (SizeT)(p - data - pos); 29 | pos = (SizeT)(p - data); 30 | if (p >= limit) 31 | { 32 | *state = (d > 2 ? 0 : mask >> (unsigned)d); 33 | return pos; 34 | } 35 | if (d > 2) 36 | mask = 0; 37 | else 38 | { 39 | mask >>= (unsigned)d; 40 | if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1]))) 41 | { 42 | mask = (mask >> 1) | 4; 43 | pos++; 44 | continue; 45 | } 46 | } 47 | } 48 | 49 | if (Test86MSByte(p[4])) 50 | { 51 | UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); 52 | UInt32 cur = ip + (UInt32)pos; 53 | pos += 5; 54 | if (encoding) 55 | v += cur; 56 | else 57 | v -= cur; 58 | if (mask != 0) 59 | { 60 | unsigned sh = (mask & 6) << 2; 61 | if (Test86MSByte((Byte)(v >> sh))) 62 | { 63 | v ^= (((UInt32)0x100 << sh) - 1); 64 | if (encoding) 65 | v += cur; 66 | else 67 | v -= cur; 68 | } 69 | mask = 0; 70 | } 71 | p[1] = (Byte)v; 72 | p[2] = (Byte)(v >> 8); 73 | p[3] = (Byte)(v >> 16); 74 | p[4] = (Byte)(0 - ((v >> 24) & 1)); 75 | } 76 | else 77 | { 78 | mask = (mask >> 1) | 4; 79 | pos++; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/BraIA64.c: -------------------------------------------------------------------------------- 1 | /* BraIA64.c -- Converter for IA-64 code 2 | 2017-01-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | #include "Bra.h" 8 | 9 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 10 | { 11 | SizeT i; 12 | if (size < 16) 13 | return 0; 14 | size -= 16; 15 | i = 0; 16 | do 17 | { 18 | unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3; 19 | if (m) 20 | { 21 | m++; 22 | do 23 | { 24 | Byte *p = data + (i + (size_t)m * 5 - 8); 25 | if (((p[3] >> m) & 15) == 5 26 | && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0) 27 | { 28 | unsigned raw = GetUi32(p); 29 | unsigned v = raw >> m; 30 | v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3); 31 | 32 | v <<= 4; 33 | if (encoding) 34 | v += ip + (UInt32)i; 35 | else 36 | v -= ip + (UInt32)i; 37 | v >>= 4; 38 | 39 | v &= 0x1FFFFF; 40 | v += 0x700000; 41 | v &= 0x8FFFFF; 42 | raw &= ~((UInt32)0x8FFFFF << m); 43 | raw |= (v << m); 44 | SetUi32(p, raw); 45 | } 46 | } 47 | while (++m <= 4); 48 | } 49 | i += 16; 50 | } 51 | while (i <= size); 52 | return i; 53 | } 54 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Compiler.h: -------------------------------------------------------------------------------- 1 | /* Compiler.h 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_COMPILER_H 5 | #define __7Z_COMPILER_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #ifdef UNDER_CE 10 | #define RPC_NO_WINDOWS_H 11 | /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ 12 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union 13 | #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int 14 | #endif 15 | 16 | #if _MSC_VER >= 1300 17 | #pragma warning(disable : 4996) // This function or variable may be unsafe 18 | #else 19 | #pragma warning(disable : 4511) // copy constructor could not be generated 20 | #pragma warning(disable : 4512) // assignment operator could not be generated 21 | #pragma warning(disable : 4514) // unreferenced inline function has been removed 22 | #pragma warning(disable : 4702) // unreachable code 23 | #pragma warning(disable : 4710) // not inlined 24 | #pragma warning(disable : 4714) // function marked as __forceinline not inlined 25 | #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information 26 | #endif 27 | 28 | #endif 29 | 30 | #define UNUSED_VAR(x) (void)x 31 | /* #define UNUSED_VAR(x) x=x; */ 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Delta.c: -------------------------------------------------------------------------------- 1 | /* Delta.c -- Delta converter 2 | 2009-05-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Delta.h" 7 | 8 | void Delta_Init(Byte *state) 9 | { 10 | unsigned i; 11 | for (i = 0; i < DELTA_STATE_SIZE; i++) 12 | state[i] = 0; 13 | } 14 | 15 | static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) 16 | { 17 | unsigned i; 18 | for (i = 0; i < size; i++) 19 | dest[i] = src[i]; 20 | } 21 | 22 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) 23 | { 24 | Byte buf[DELTA_STATE_SIZE]; 25 | unsigned j = 0; 26 | MyMemCpy(buf, state, delta); 27 | { 28 | SizeT i; 29 | for (i = 0; i < size;) 30 | { 31 | for (j = 0; j < delta && i < size; i++, j++) 32 | { 33 | Byte b = data[i]; 34 | data[i] = (Byte)(b - buf[j]); 35 | buf[j] = b; 36 | } 37 | } 38 | } 39 | if (j == delta) 40 | j = 0; 41 | MyMemCpy(state, buf + j, delta - j); 42 | MyMemCpy(state + delta - j, buf, j); 43 | } 44 | 45 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) 46 | { 47 | Byte buf[DELTA_STATE_SIZE]; 48 | unsigned j = 0; 49 | MyMemCpy(buf, state, delta); 50 | { 51 | SizeT i; 52 | for (i = 0; i < size;) 53 | { 54 | for (j = 0; j < delta && i < size; i++, j++) 55 | { 56 | buf[j] = data[i] = (Byte)(buf[j] + data[i]); 57 | } 58 | } 59 | } 60 | if (j == delta) 61 | j = 0; 62 | MyMemCpy(state, buf + j, delta - j); 63 | MyMemCpy(state + delta - j, buf, j); 64 | } 65 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Delta.h: -------------------------------------------------------------------------------- 1 | /* Delta.h -- Delta converter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DELTA_H 5 | #define __DELTA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define DELTA_STATE_SIZE 256 12 | 13 | void Delta_Init(Byte *state); 14 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size); 15 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size); 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/DllSecur.c: -------------------------------------------------------------------------------- 1 | /* DllSecur.c -- DLL loading security 2 | 2016-10-04 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifdef _WIN32 7 | 8 | #include 9 | 10 | #include "DllSecur.h" 11 | 12 | #ifndef UNDER_CE 13 | 14 | typedef BOOL (WINAPI *Func_SetDefaultDllDirectories)(DWORD DirectoryFlags); 15 | 16 | #define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400 17 | #define MY_LOAD_LIBRARY_SEARCH_SYSTEM32 0x800 18 | 19 | static const char * const g_Dlls = 20 | #ifndef _CONSOLE 21 | "UXTHEME\0" 22 | #endif 23 | "USERENV\0" 24 | "SETUPAPI\0" 25 | "APPHELP\0" 26 | "PROPSYS\0" 27 | "DWMAPI\0" 28 | "CRYPTBASE\0" 29 | "OLEACC\0" 30 | "CLBCATQ\0" 31 | ; 32 | 33 | #endif 34 | 35 | void LoadSecurityDlls() 36 | { 37 | #ifndef UNDER_CE 38 | 39 | wchar_t buf[MAX_PATH + 100]; 40 | 41 | { 42 | // at Vista (ver 6.0) : CoCreateInstance(CLSID_ShellLink, ...) doesn't work after SetDefaultDllDirectories() : Check it ??? 43 | OSVERSIONINFO vi; 44 | vi.dwOSVersionInfoSize = sizeof(vi); 45 | if (!GetVersionEx(&vi) || vi.dwMajorVersion != 6 || vi.dwMinorVersion != 0) 46 | { 47 | Func_SetDefaultDllDirectories setDllDirs = (Func_SetDefaultDllDirectories) 48 | GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories"); 49 | if (setDllDirs) 50 | if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS)) 51 | return; 52 | } 53 | } 54 | 55 | { 56 | unsigned len = GetSystemDirectoryW(buf, MAX_PATH + 2); 57 | if (len == 0 || len > MAX_PATH) 58 | return; 59 | } 60 | { 61 | const char *dll; 62 | unsigned pos = (unsigned)lstrlenW(buf); 63 | 64 | if (buf[pos - 1] != '\\') 65 | buf[pos++] = '\\'; 66 | 67 | for (dll = g_Dlls; dll[0] != 0;) 68 | { 69 | unsigned k = 0; 70 | for (;;) 71 | { 72 | char c = *dll++; 73 | buf[pos + k] = c; 74 | k++; 75 | if (c == 0) 76 | break; 77 | } 78 | 79 | lstrcatW(buf, L".dll"); 80 | LoadLibraryExW(buf, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 81 | } 82 | } 83 | 84 | #endif 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/DllSecur.h: -------------------------------------------------------------------------------- 1 | /* DllSecur.h -- DLL loading for security 2 | 2016-06-08 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DLL_SECUR_H 5 | #define __DLL_SECUR_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #ifdef _WIN32 12 | 13 | void LoadSecurityDlls(); 14 | 15 | #endif 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/LICENSE: -------------------------------------------------------------------------------- 1 | LZMA SDK is written and placed in the public domain by Igor Pavlov. 2 | 3 | Some code in LZMA SDK is based on public domain code from another developers: 4 | 1) PPMd var.H (2001): Dmitry Shkarin 5 | 2) SHA-256: Wei Dai (Crypto++ library) 6 | 7 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute the 8 | original LZMA SDK code, either in source code form or as a compiled binary, for 9 | any purpose, commercial or non-commercial, and by any means. 10 | 11 | LZMA SDK code is compatible with open source licenses, for example, you can 12 | include it to GNU GPL or GNU LGPL code. 13 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/LzFindMt.h: -------------------------------------------------------------------------------- 1 | /* LzFindMt.h -- multithreaded Match finder for LZ algorithms 2 | 2017-04-03 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_FIND_MT_H 5 | #define __LZ_FIND_MT_H 6 | 7 | #include "LzFind.h" 8 | #include "Threads.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #define kMtHashBlockSize (1 << 13) 13 | #define kMtHashNumBlocks (1 << 3) 14 | #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) 15 | 16 | #define kMtBtBlockSize (1 << 14) 17 | #define kMtBtNumBlocks (1 << 6) 18 | #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) 19 | 20 | typedef struct _CMtSync 21 | { 22 | Bool wasCreated; 23 | Bool needStart; 24 | Bool exit; 25 | Bool stopWriting; 26 | 27 | CThread thread; 28 | CAutoResetEvent canStart; 29 | CAutoResetEvent wasStarted; 30 | CAutoResetEvent wasStopped; 31 | CSemaphore freeSemaphore; 32 | CSemaphore filledSemaphore; 33 | Bool csWasInitialized; 34 | Bool csWasEntered; 35 | CCriticalSection cs; 36 | UInt32 numProcessedBlocks; 37 | } CMtSync; 38 | 39 | typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 40 | 41 | /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 42 | #define kMtCacheLineDummy 128 43 | 44 | typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, 45 | UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); 46 | 47 | typedef struct _CMatchFinderMt 48 | { 49 | /* LZ */ 50 | const Byte *pointerToCurPos; 51 | UInt32 *btBuf; 52 | UInt32 btBufPos; 53 | UInt32 btBufPosLimit; 54 | UInt32 lzPos; 55 | UInt32 btNumAvailBytes; 56 | 57 | UInt32 *hash; 58 | UInt32 fixedHashSize; 59 | UInt32 historySize; 60 | const UInt32 *crc; 61 | 62 | Mf_Mix_Matches MixMatchesFunc; 63 | 64 | /* LZ + BT */ 65 | CMtSync btSync; 66 | Byte btDummy[kMtCacheLineDummy]; 67 | 68 | /* BT */ 69 | UInt32 *hashBuf; 70 | UInt32 hashBufPos; 71 | UInt32 hashBufPosLimit; 72 | UInt32 hashNumAvail; 73 | 74 | CLzRef *son; 75 | UInt32 matchMaxLen; 76 | UInt32 numHashBytes; 77 | UInt32 pos; 78 | const Byte *buffer; 79 | UInt32 cyclicBufferPos; 80 | UInt32 cyclicBufferSize; /* it must be historySize + 1 */ 81 | UInt32 cutValue; 82 | 83 | /* BT + Hash */ 84 | CMtSync hashSync; 85 | /* Byte hashDummy[kMtCacheLineDummy]; */ 86 | 87 | /* Hash */ 88 | Mf_GetHeads GetHeadsFunc; 89 | CMatchFinder *MatchFinder; 90 | } CMatchFinderMt; 91 | 92 | void MatchFinderMt_Construct(CMatchFinderMt *p); 93 | void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc); 94 | SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 95 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc); 96 | void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); 97 | void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 98 | 99 | EXTERN_C_END 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/LzHash.h: -------------------------------------------------------------------------------- 1 | /* LzHash.h -- HASH functions for LZ algorithms 2 | 2015-04-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_HASH_H 5 | #define __LZ_HASH_H 6 | 7 | #define kHash2Size (1 << 10) 8 | #define kHash3Size (1 << 16) 9 | #define kHash4Size (1 << 20) 10 | 11 | #define kFix3HashSize (kHash2Size) 12 | #define kFix4HashSize (kHash2Size + kHash3Size) 13 | #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 14 | 15 | #define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8); 16 | 17 | #define HASH3_CALC { \ 18 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 19 | h2 = temp & (kHash2Size - 1); \ 20 | hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } 21 | 22 | #define HASH4_CALC { \ 23 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 24 | h2 = temp & (kHash2Size - 1); \ 25 | temp ^= ((UInt32)cur[2] << 8); \ 26 | h3 = temp & (kHash3Size - 1); \ 27 | hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; } 28 | 29 | #define HASH5_CALC { \ 30 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 31 | h2 = temp & (kHash2Size - 1); \ 32 | temp ^= ((UInt32)cur[2] << 8); \ 33 | h3 = temp & (kHash3Size - 1); \ 34 | temp ^= (p->crc[cur[3]] << 5); \ 35 | h4 = temp & (kHash4Size - 1); \ 36 | hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; } 37 | 38 | /* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ 39 | #define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; 40 | 41 | 42 | #define MT_HASH2_CALC \ 43 | h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); 44 | 45 | #define MT_HASH3_CALC { \ 46 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 47 | h2 = temp & (kHash2Size - 1); \ 48 | h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 49 | 50 | #define MT_HASH4_CALC { \ 51 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 52 | h2 = temp & (kHash2Size - 1); \ 53 | temp ^= ((UInt32)cur[2] << 8); \ 54 | h3 = temp & (kHash3Size - 1); \ 55 | h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Lzma2DecMt.h: -------------------------------------------------------------------------------- 1 | /* Lzma2DecMt.h -- LZMA2 Decoder Multi-thread 2 | 2018-02-17 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_DEC_MT_H 5 | #define __LZMA2_DEC_MT_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | size_t inBufSize_ST; 14 | size_t outStep_ST; 15 | 16 | #ifndef _7ZIP_ST 17 | unsigned numThreads; 18 | size_t inBufSize_MT; 19 | size_t outBlockMax; 20 | size_t inBlockMax; 21 | #endif 22 | } CLzma2DecMtProps; 23 | 24 | /* init to single-thread mode */ 25 | void Lzma2DecMtProps_Init(CLzma2DecMtProps *p); 26 | 27 | 28 | /* ---------- CLzma2DecMtHandle Interface ---------- */ 29 | 30 | /* Lzma2DecMt_ * functions can return the following exit codes: 31 | SRes: 32 | SZ_OK - OK 33 | SZ_ERROR_MEM - Memory allocation error 34 | SZ_ERROR_PARAM - Incorrect paramater in props 35 | SZ_ERROR_WRITE - ISeqOutStream write callback error 36 | // SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output 37 | SZ_ERROR_PROGRESS - some break from progress callback 38 | SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) 39 | */ 40 | 41 | typedef void * CLzma2DecMtHandle; 42 | 43 | CLzma2DecMtHandle Lzma2DecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid); 44 | void Lzma2DecMt_Destroy(CLzma2DecMtHandle p); 45 | 46 | SRes Lzma2DecMt_Decode(CLzma2DecMtHandle p, 47 | Byte prop, 48 | const CLzma2DecMtProps *props, 49 | ISeqOutStream *outStream, 50 | const UInt64 *outDataSize, // NULL means undefined 51 | int finishMode, // 0 - partial unpacking is allowed, 1 - if lzma2 stream must be finished 52 | // Byte *outBuf, size_t *outBufSize, 53 | ISeqInStream *inStream, 54 | // const Byte *inData, size_t inDataSize, 55 | 56 | // out variables: 57 | UInt64 *inProcessed, 58 | int *isMT, /* out: (*isMT == 0), if single thread decoding was used */ 59 | 60 | // UInt64 *outProcessed, 61 | ICompressProgress *progress); 62 | 63 | 64 | /* ---------- Read from CLzma2DecMtHandle Interface ---------- */ 65 | 66 | SRes Lzma2DecMt_Init(CLzma2DecMtHandle pp, 67 | Byte prop, 68 | const CLzma2DecMtProps *props, 69 | const UInt64 *outDataSize, int finishMode, 70 | ISeqInStream *inStream); 71 | 72 | SRes Lzma2DecMt_Read(CLzma2DecMtHandle pp, 73 | Byte *data, size_t *outSize, 74 | UInt64 *inStreamProcessed); 75 | 76 | 77 | EXTERN_C_END 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Lzma2Enc.h: -------------------------------------------------------------------------------- 1 | /* Lzma2Enc.h -- LZMA2 Encoder 2 | 2017-07-27 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_ENC_H 5 | #define __LZMA2_ENC_H 6 | 7 | #include "LzmaEnc.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO 0 12 | #define LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID ((UInt64)(Int64)-1) 13 | 14 | typedef struct 15 | { 16 | CLzmaEncProps lzmaProps; 17 | UInt64 blockSize; 18 | int numBlockThreads_Reduced; 19 | int numBlockThreads_Max; 20 | int numTotalThreads; 21 | } CLzma2EncProps; 22 | 23 | void Lzma2EncProps_Init(CLzma2EncProps *p); 24 | void Lzma2EncProps_Normalize(CLzma2EncProps *p); 25 | 26 | /* ---------- CLzmaEnc2Handle Interface ---------- */ 27 | 28 | /* Lzma2Enc_* functions can return the following exit codes: 29 | SRes: 30 | SZ_OK - OK 31 | SZ_ERROR_MEM - Memory allocation error 32 | SZ_ERROR_PARAM - Incorrect paramater in props 33 | SZ_ERROR_WRITE - ISeqOutStream write callback error 34 | SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output 35 | SZ_ERROR_PROGRESS - some break from progress callback 36 | SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) 37 | */ 38 | 39 | typedef void * CLzma2EncHandle; 40 | 41 | CLzma2EncHandle Lzma2Enc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig); 42 | void Lzma2Enc_Destroy(CLzma2EncHandle p); 43 | SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props); 44 | void Lzma2Enc_SetDataSize(CLzma2EncHandle p, UInt64 expectedDataSiize); 45 | Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p); 46 | SRes Lzma2Enc_Encode2(CLzma2EncHandle p, 47 | ISeqOutStream *outStream, 48 | Byte *outBuf, size_t *outBufSize, 49 | ISeqInStream *inStream, 50 | const Byte *inData, size_t inDataSize, 51 | ICompressProgress *progress); 52 | 53 | EXTERN_C_END 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Lzma86.h: -------------------------------------------------------------------------------- 1 | /* Lzma86.h -- LZMA + x86 (BCJ) Filter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA86_H 5 | #define __LZMA86_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA86_SIZE_OFFSET (1 + 5) 12 | #define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) 13 | 14 | /* 15 | It's an example for LZMA + x86 Filter use. 16 | You can use .lzma86 extension, if you write that stream to file. 17 | .lzma86 header adds one additional byte to standard .lzma header. 18 | .lzma86 header (14 bytes): 19 | Offset Size Description 20 | 0 1 = 0 - no filter, pure LZMA 21 | = 1 - x86 filter + LZMA 22 | 1 1 lc, lp and pb in encoded form 23 | 2 4 dictSize (little endian) 24 | 6 8 uncompressed size (little endian) 25 | 26 | 27 | Lzma86_Encode 28 | ------------- 29 | level - compression level: 0 <= level <= 9, the default value for "level" is 5. 30 | 31 | dictSize - The dictionary size in bytes. The maximum value is 32 | 128 MB = (1 << 27) bytes for 32-bit version 33 | 1 GB = (1 << 30) bytes for 64-bit version 34 | The default value is 16 MB = (1 << 24) bytes, for level = 5. 35 | It's recommended to use the dictionary that is larger than 4 KB and 36 | that can be calculated as (1 << N) or (3 << N) sizes. 37 | For better compression ratio dictSize must be >= inSize. 38 | 39 | filterMode: 40 | SZ_FILTER_NO - no Filter 41 | SZ_FILTER_YES - x86 Filter 42 | SZ_FILTER_AUTO - it tries both alternatives to select best. 43 | Encoder will use 2 or 3 passes: 44 | 2 passes when FILTER_NO provides better compression. 45 | 3 passes when FILTER_YES provides better compression. 46 | 47 | Lzma86Encode allocates Data with MyAlloc functions. 48 | RAM Requirements for compressing: 49 | RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize 50 | filterMode FilterBlockSize 51 | SZ_FILTER_NO 0 52 | SZ_FILTER_YES inSize 53 | SZ_FILTER_AUTO inSize 54 | 55 | 56 | Return code: 57 | SZ_OK - OK 58 | SZ_ERROR_MEM - Memory allocation error 59 | SZ_ERROR_PARAM - Incorrect paramater 60 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 61 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 62 | */ 63 | 64 | enum ESzFilterMode 65 | { 66 | SZ_FILTER_NO, 67 | SZ_FILTER_YES, 68 | SZ_FILTER_AUTO 69 | }; 70 | 71 | SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 72 | int level, UInt32 dictSize, int filterMode); 73 | 74 | 75 | /* 76 | Lzma86_GetUnpackSize: 77 | In: 78 | src - input data 79 | srcLen - input data size 80 | Out: 81 | unpackSize - size of uncompressed stream 82 | Return code: 83 | SZ_OK - OK 84 | SZ_ERROR_INPUT_EOF - Error in headers 85 | */ 86 | 87 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); 88 | 89 | /* 90 | Lzma86_Decode: 91 | In: 92 | dest - output data 93 | destLen - output data size 94 | src - input data 95 | srcLen - input data size 96 | Out: 97 | destLen - processed output size 98 | srcLen - processed input size 99 | Return code: 100 | SZ_OK - OK 101 | SZ_ERROR_DATA - Data error 102 | SZ_ERROR_MEM - Memory allocation error 103 | SZ_ERROR_UNSUPPORTED - unsupported file 104 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer 105 | */ 106 | 107 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); 108 | 109 | EXTERN_C_END 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Lzma86Dec.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder 2 | 2016-05-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Lzma86.h" 7 | 8 | #include "Alloc.h" 9 | #include "Bra.h" 10 | #include "LzmaDec.h" 11 | 12 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) 13 | { 14 | unsigned i; 15 | if (srcLen < LZMA86_HEADER_SIZE) 16 | return SZ_ERROR_INPUT_EOF; 17 | *unpackSize = 0; 18 | for (i = 0; i < sizeof(UInt64); i++) 19 | *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i); 20 | return SZ_OK; 21 | } 22 | 23 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen) 24 | { 25 | SRes res; 26 | int useFilter; 27 | SizeT inSizePure; 28 | ELzmaStatus status; 29 | 30 | if (*srcLen < LZMA86_HEADER_SIZE) 31 | return SZ_ERROR_INPUT_EOF; 32 | 33 | useFilter = src[0]; 34 | 35 | if (useFilter > 1) 36 | { 37 | *destLen = 0; 38 | return SZ_ERROR_UNSUPPORTED; 39 | } 40 | 41 | inSizePure = *srcLen - LZMA86_HEADER_SIZE; 42 | res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure, 43 | src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc); 44 | *srcLen = inSizePure + LZMA86_HEADER_SIZE; 45 | if (res != SZ_OK) 46 | return res; 47 | if (useFilter == 1) 48 | { 49 | UInt32 x86State; 50 | x86_Convert_Init(x86State); 51 | x86_Convert(dest, *destLen, 0, &x86State, 0); 52 | } 53 | return SZ_OK; 54 | } 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Lzma86Enc.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder 2 | 2016-05-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "Lzma86.h" 9 | 10 | #include "Alloc.h" 11 | #include "Bra.h" 12 | #include "LzmaEnc.h" 13 | 14 | #define SZE_OUT_OVERFLOW SZE_DATA_ERROR 15 | 16 | int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 17 | int level, UInt32 dictSize, int filterMode) 18 | { 19 | size_t outSize2 = *destLen; 20 | Byte *filteredStream; 21 | Bool useFilter; 22 | int mainResult = SZ_ERROR_OUTPUT_EOF; 23 | CLzmaEncProps props; 24 | LzmaEncProps_Init(&props); 25 | props.level = level; 26 | props.dictSize = dictSize; 27 | 28 | *destLen = 0; 29 | if (outSize2 < LZMA86_HEADER_SIZE) 30 | return SZ_ERROR_OUTPUT_EOF; 31 | 32 | { 33 | int i; 34 | UInt64 t = srcLen; 35 | for (i = 0; i < 8; i++, t >>= 8) 36 | dest[LZMA86_SIZE_OFFSET + i] = (Byte)t; 37 | } 38 | 39 | filteredStream = 0; 40 | useFilter = (filterMode != SZ_FILTER_NO); 41 | if (useFilter) 42 | { 43 | if (srcLen != 0) 44 | { 45 | filteredStream = (Byte *)MyAlloc(srcLen); 46 | if (filteredStream == 0) 47 | return SZ_ERROR_MEM; 48 | memcpy(filteredStream, src, srcLen); 49 | } 50 | { 51 | UInt32 x86State; 52 | x86_Convert_Init(x86State); 53 | x86_Convert(filteredStream, srcLen, 0, &x86State, 1); 54 | } 55 | } 56 | 57 | { 58 | size_t minSize = 0; 59 | Bool bestIsFiltered = False; 60 | 61 | /* passes for SZ_FILTER_AUTO: 62 | 0 - BCJ + LZMA 63 | 1 - LZMA 64 | 2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better. 65 | */ 66 | int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1; 67 | 68 | int i; 69 | for (i = 0; i < numPasses; i++) 70 | { 71 | size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE; 72 | size_t outPropsSize = 5; 73 | SRes curRes; 74 | Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); 75 | if (curModeIsFiltered && !bestIsFiltered) 76 | break; 77 | if (useFilter && i == 0) 78 | curModeIsFiltered = True; 79 | 80 | curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed, 81 | curModeIsFiltered ? filteredStream : src, srcLen, 82 | &props, dest + 1, &outPropsSize, 0, 83 | NULL, &g_Alloc, &g_Alloc); 84 | 85 | if (curRes != SZ_ERROR_OUTPUT_EOF) 86 | { 87 | if (curRes != SZ_OK) 88 | { 89 | mainResult = curRes; 90 | break; 91 | } 92 | if (outSizeProcessed <= minSize || mainResult != SZ_OK) 93 | { 94 | minSize = outSizeProcessed; 95 | bestIsFiltered = curModeIsFiltered; 96 | mainResult = SZ_OK; 97 | } 98 | } 99 | } 100 | dest[0] = (Byte)(bestIsFiltered ? 1 : 0); 101 | *destLen = LZMA86_HEADER_SIZE + minSize; 102 | } 103 | if (useFilter) 104 | MyFree(filteredStream); 105 | return mainResult; 106 | } 107 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/LzmaEnc.h: -------------------------------------------------------------------------------- 1 | /* LzmaEnc.h -- LZMA Encoder 2 | 2017-07-27 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_ENC_H 5 | #define __LZMA_ENC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA_PROPS_SIZE 5 12 | 13 | typedef struct _CLzmaEncProps 14 | { 15 | int level; /* 0 <= level <= 9 */ 16 | UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version 17 | (1 << 12) <= dictSize <= (3 << 29) for 64-bit version 18 | default = (1 << 24) */ 19 | int lc; /* 0 <= lc <= 8, default = 3 */ 20 | int lp; /* 0 <= lp <= 4, default = 0 */ 21 | int pb; /* 0 <= pb <= 4, default = 2 */ 22 | int algo; /* 0 - fast, 1 - normal, default = 1 */ 23 | int fb; /* 5 <= fb <= 273, default = 32 */ 24 | int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ 25 | int numHashBytes; /* 2, 3 or 4, default = 4 */ 26 | UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ 27 | unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ 28 | int numThreads; /* 1 or 2, default = 2 */ 29 | 30 | UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1. 31 | Encoder uses this value to reduce dictionary size */ 32 | } CLzmaEncProps; 33 | 34 | void LzmaEncProps_Init(CLzmaEncProps *p); 35 | void LzmaEncProps_Normalize(CLzmaEncProps *p); 36 | UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); 37 | 38 | 39 | /* ---------- CLzmaEncHandle Interface ---------- */ 40 | 41 | /* LzmaEnc* functions can return the following exit codes: 42 | SRes: 43 | SZ_OK - OK 44 | SZ_ERROR_MEM - Memory allocation error 45 | SZ_ERROR_PARAM - Incorrect paramater in props 46 | SZ_ERROR_WRITE - ISeqOutStream write callback error 47 | SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output 48 | SZ_ERROR_PROGRESS - some break from progress callback 49 | SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) 50 | */ 51 | 52 | typedef void * CLzmaEncHandle; 53 | 54 | CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc); 55 | void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig); 56 | 57 | SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); 58 | void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize); 59 | SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); 60 | unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p); 61 | 62 | SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, 63 | ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 64 | SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 65 | int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 66 | 67 | 68 | /* ---------- One Call Interface ---------- */ 69 | 70 | SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 71 | const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 72 | ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); 73 | 74 | EXTERN_C_END 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/LzmaLib.c: -------------------------------------------------------------------------------- 1 | /* LzmaLib.c -- LZMA library wrapper 2 | 2015-06-13 : Igor Pavlov : Public domain */ 3 | 4 | #include "Alloc.h" 5 | #include "LzmaDec.h" 6 | #include "LzmaEnc.h" 7 | #include "LzmaLib.h" 8 | 9 | MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, 10 | unsigned char *outProps, size_t *outPropsSize, 11 | int level, /* 0 <= level <= 9, default = 5 */ 12 | unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */ 13 | int lc, /* 0 <= lc <= 8, default = 3 */ 14 | int lp, /* 0 <= lp <= 4, default = 0 */ 15 | int pb, /* 0 <= pb <= 4, default = 2 */ 16 | int fb, /* 5 <= fb <= 273, default = 32 */ 17 | int numThreads /* 1 or 2, default = 2 */ 18 | ) 19 | { 20 | CLzmaEncProps props; 21 | LzmaEncProps_Init(&props); 22 | props.level = level; 23 | props.dictSize = dictSize; 24 | props.lc = lc; 25 | props.lp = lp; 26 | props.pb = pb; 27 | props.fb = fb; 28 | props.numThreads = numThreads; 29 | 30 | return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0, 31 | NULL, &g_Alloc, &g_Alloc); 32 | } 33 | 34 | 35 | MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen, 36 | const unsigned char *props, size_t propsSize) 37 | { 38 | ELzmaStatus status; 39 | return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc); 40 | } 41 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/MtCoder.h: -------------------------------------------------------------------------------- 1 | /* MtCoder.h -- Multi-thread Coder 2 | 2018-02-21 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __MT_CODER_H 5 | #define __MT_CODER_H 6 | 7 | #include "MtDec.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | if ( defined MTCODER__USE_WRITE_THREAD) : main thread writes all data blocks to output stream 13 | if (not defined MTCODER__USE_WRITE_THREAD) : any coder thread can write data blocks to output stream 14 | */ 15 | /* #define MTCODER__USE_WRITE_THREAD */ 16 | 17 | #ifndef _7ZIP_ST 18 | #define MTCODER__GET_NUM_BLOCKS_FROM_THREADS(numThreads) ((numThreads) + (numThreads) / 8 + 1) 19 | #define MTCODER__THREADS_MAX 64 20 | #define MTCODER__BLOCKS_MAX (MTCODER__GET_NUM_BLOCKS_FROM_THREADS(MTCODER__THREADS_MAX) + 3) 21 | #else 22 | #define MTCODER__THREADS_MAX 1 23 | #define MTCODER__BLOCKS_MAX 1 24 | #endif 25 | 26 | 27 | #ifndef _7ZIP_ST 28 | 29 | 30 | typedef struct 31 | { 32 | ICompressProgress vt; 33 | CMtProgress *mtProgress; 34 | UInt64 inSize; 35 | UInt64 outSize; 36 | } CMtProgressThunk; 37 | 38 | void MtProgressThunk_CreateVTable(CMtProgressThunk *p); 39 | 40 | #define MtProgressThunk_Init(p) { (p)->inSize = 0; (p)->outSize = 0; } 41 | 42 | 43 | struct _CMtCoder; 44 | 45 | 46 | typedef struct 47 | { 48 | struct _CMtCoder *mtCoder; 49 | unsigned index; 50 | int stop; 51 | Byte *inBuf; 52 | 53 | CAutoResetEvent startEvent; 54 | CThread thread; 55 | } CMtCoderThread; 56 | 57 | 58 | typedef struct 59 | { 60 | SRes (*Code)(void *p, unsigned coderIndex, unsigned outBufIndex, 61 | const Byte *src, size_t srcSize, int finished); 62 | SRes (*Write)(void *p, unsigned outBufIndex); 63 | } IMtCoderCallback2; 64 | 65 | 66 | typedef struct 67 | { 68 | SRes res; 69 | unsigned bufIndex; 70 | Bool finished; 71 | } CMtCoderBlock; 72 | 73 | 74 | typedef struct _CMtCoder 75 | { 76 | /* input variables */ 77 | 78 | size_t blockSize; /* size of input block */ 79 | unsigned numThreadsMax; 80 | UInt64 expectedDataSize; 81 | 82 | ISeqInStream *inStream; 83 | const Byte *inData; 84 | size_t inDataSize; 85 | 86 | ICompressProgress *progress; 87 | ISzAllocPtr allocBig; 88 | 89 | IMtCoderCallback2 *mtCallback; 90 | void *mtCallbackObject; 91 | 92 | 93 | /* internal variables */ 94 | 95 | size_t allocatedBufsSize; 96 | 97 | CAutoResetEvent readEvent; 98 | CSemaphore blocksSemaphore; 99 | 100 | Bool stopReading; 101 | SRes readRes; 102 | 103 | #ifdef MTCODER__USE_WRITE_THREAD 104 | CAutoResetEvent writeEvents[MTCODER__BLOCKS_MAX]; 105 | #else 106 | CAutoResetEvent finishedEvent; 107 | SRes writeRes; 108 | unsigned writeIndex; 109 | Byte ReadyBlocks[MTCODER__BLOCKS_MAX]; 110 | LONG numFinishedThreads; 111 | #endif 112 | 113 | unsigned numStartedThreadsLimit; 114 | unsigned numStartedThreads; 115 | 116 | unsigned numBlocksMax; 117 | unsigned blockIndex; 118 | UInt64 readProcessed; 119 | 120 | CCriticalSection cs; 121 | 122 | unsigned freeBlockHead; 123 | unsigned freeBlockList[MTCODER__BLOCKS_MAX]; 124 | 125 | CMtProgress mtProgress; 126 | CMtCoderBlock blocks[MTCODER__BLOCKS_MAX]; 127 | CMtCoderThread threads[MTCODER__THREADS_MAX]; 128 | } CMtCoder; 129 | 130 | 131 | void MtCoder_Construct(CMtCoder *p); 132 | void MtCoder_Destruct(CMtCoder *p); 133 | SRes MtCoder_Code(CMtCoder *p); 134 | 135 | 136 | #endif 137 | 138 | 139 | EXTERN_C_END 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Ppmd.h: -------------------------------------------------------------------------------- 1 | /* Ppmd.h -- PPMD codec common code 2 | 2017-04-03 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #ifndef __PPMD_H 6 | #define __PPMD_H 7 | 8 | #include "CpuArch.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #ifdef MY_CPU_32BIT 13 | #define PPMD_32BIT 14 | #endif 15 | 16 | #define PPMD_INT_BITS 7 17 | #define PPMD_PERIOD_BITS 7 18 | #define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) 19 | 20 | #define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) 21 | #define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) 22 | #define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) 23 | #define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) 24 | 25 | #define PPMD_N1 4 26 | #define PPMD_N2 4 27 | #define PPMD_N3 4 28 | #define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) 29 | #define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) 30 | 31 | #pragma pack(push, 1) 32 | /* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */ 33 | 34 | /* SEE-contexts for PPM-contexts with masked symbols */ 35 | typedef struct 36 | { 37 | UInt16 Summ; /* Freq */ 38 | Byte Shift; /* Speed of Freq change; low Shift is for fast change */ 39 | Byte Count; /* Count to next change of Shift */ 40 | } CPpmd_See; 41 | 42 | #define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ 43 | { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } 44 | 45 | typedef struct 46 | { 47 | Byte Symbol; 48 | Byte Freq; 49 | UInt16 SuccessorLow; 50 | UInt16 SuccessorHigh; 51 | } CPpmd_State; 52 | 53 | #pragma pack(pop) 54 | 55 | typedef 56 | #ifdef PPMD_32BIT 57 | CPpmd_State * 58 | #else 59 | UInt32 60 | #endif 61 | CPpmd_State_Ref; 62 | 63 | typedef 64 | #ifdef PPMD_32BIT 65 | void * 66 | #else 67 | UInt32 68 | #endif 69 | CPpmd_Void_Ref; 70 | 71 | typedef 72 | #ifdef PPMD_32BIT 73 | Byte * 74 | #else 75 | UInt32 76 | #endif 77 | CPpmd_Byte_Ref; 78 | 79 | #define PPMD_SetAllBitsIn256Bytes(p) \ 80 | { size_t z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \ 81 | p[z+7] = p[z+6] = p[z+5] = p[z+4] = p[z+3] = p[z+2] = p[z+1] = p[z+0] = ~(size_t)0; }} 82 | 83 | EXTERN_C_END 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Precomp.h: -------------------------------------------------------------------------------- 1 | /* Precomp.h -- StdAfx 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_PRECOMP_H 5 | #define __7Z_PRECOMP_H 6 | 7 | #include "Compiler.h" 8 | /* #include "7zTypes.h" */ 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/RotateDefs.h: -------------------------------------------------------------------------------- 1 | /* RotateDefs.h -- Rotate functions 2 | 2015-03-25 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __ROTATE_DEFS_H 5 | #define __ROTATE_DEFS_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #include 10 | 11 | /* don't use _rotl with MINGW. It can insert slow call to function. */ 12 | 13 | /* #if (_MSC_VER >= 1200) */ 14 | #pragma intrinsic(_rotl) 15 | #pragma intrinsic(_rotr) 16 | /* #endif */ 17 | 18 | #define rotlFixed(x, n) _rotl((x), (n)) 19 | #define rotrFixed(x, n) _rotr((x), (n)) 20 | 21 | #else 22 | 23 | /* new compilers can translate these macros to fast commands. */ 24 | 25 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 26 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 27 | 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Sha256.h: -------------------------------------------------------------------------------- 1 | /* Sha256.h -- SHA-256 Hash 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __CRYPTO_SHA256_H 5 | #define __CRYPTO_SHA256_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define SHA256_DIGEST_SIZE 32 12 | 13 | typedef struct 14 | { 15 | UInt32 state[8]; 16 | UInt64 count; 17 | Byte buffer[64]; 18 | } CSha256; 19 | 20 | void Sha256_Init(CSha256 *p); 21 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size); 22 | void Sha256_Final(CSha256 *p, Byte *digest); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Sort.c: -------------------------------------------------------------------------------- 1 | /* Sort.c -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Sort.h" 7 | 8 | #define HeapSortDown(p, k, size, temp) \ 9 | { for (;;) { \ 10 | size_t s = (k << 1); \ 11 | if (s > size) break; \ 12 | if (s < size && p[s + 1] > p[s]) s++; \ 13 | if (temp >= p[s]) break; \ 14 | p[k] = p[s]; k = s; \ 15 | } p[k] = temp; } 16 | 17 | void HeapSort(UInt32 *p, size_t size) 18 | { 19 | if (size <= 1) 20 | return; 21 | p--; 22 | { 23 | size_t i = size / 2; 24 | do 25 | { 26 | UInt32 temp = p[i]; 27 | size_t k = i; 28 | HeapSortDown(p, k, size, temp) 29 | } 30 | while (--i != 0); 31 | } 32 | /* 33 | do 34 | { 35 | size_t k = 1; 36 | UInt32 temp = p[size]; 37 | p[size--] = p[1]; 38 | HeapSortDown(p, k, size, temp) 39 | } 40 | while (size > 1); 41 | */ 42 | while (size > 3) 43 | { 44 | UInt32 temp = p[size]; 45 | size_t k = (p[3] > p[2]) ? 3 : 2; 46 | p[size--] = p[1]; 47 | p[1] = p[k]; 48 | HeapSortDown(p, k, size, temp) 49 | } 50 | { 51 | UInt32 temp = p[size]; 52 | p[size] = p[1]; 53 | if (size > 2 && p[2] < temp) 54 | { 55 | p[1] = p[2]; 56 | p[2] = temp; 57 | } 58 | else 59 | p[1] = temp; 60 | } 61 | } 62 | 63 | void HeapSort64(UInt64 *p, size_t size) 64 | { 65 | if (size <= 1) 66 | return; 67 | p--; 68 | { 69 | size_t i = size / 2; 70 | do 71 | { 72 | UInt64 temp = p[i]; 73 | size_t k = i; 74 | HeapSortDown(p, k, size, temp) 75 | } 76 | while (--i != 0); 77 | } 78 | /* 79 | do 80 | { 81 | size_t k = 1; 82 | UInt64 temp = p[size]; 83 | p[size--] = p[1]; 84 | HeapSortDown(p, k, size, temp) 85 | } 86 | while (size > 1); 87 | */ 88 | while (size > 3) 89 | { 90 | UInt64 temp = p[size]; 91 | size_t k = (p[3] > p[2]) ? 3 : 2; 92 | p[size--] = p[1]; 93 | p[1] = p[k]; 94 | HeapSortDown(p, k, size, temp) 95 | } 96 | { 97 | UInt64 temp = p[size]; 98 | p[size] = p[1]; 99 | if (size > 2 && p[2] < temp) 100 | { 101 | p[1] = p[2]; 102 | p[2] = temp; 103 | } 104 | else 105 | p[1] = temp; 106 | } 107 | } 108 | 109 | /* 110 | #define HeapSortRefDown(p, vals, n, size, temp) \ 111 | { size_t k = n; UInt32 val = vals[temp]; for (;;) { \ 112 | size_t s = (k << 1); \ 113 | if (s > size) break; \ 114 | if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \ 115 | if (val >= vals[p[s]]) break; \ 116 | p[k] = p[s]; k = s; \ 117 | } p[k] = temp; } 118 | 119 | void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size) 120 | { 121 | if (size <= 1) 122 | return; 123 | p--; 124 | { 125 | size_t i = size / 2; 126 | do 127 | { 128 | UInt32 temp = p[i]; 129 | HeapSortRefDown(p, vals, i, size, temp); 130 | } 131 | while (--i != 0); 132 | } 133 | do 134 | { 135 | UInt32 temp = p[size]; 136 | p[size--] = p[1]; 137 | HeapSortRefDown(p, vals, 1, size, temp); 138 | } 139 | while (size > 1); 140 | } 141 | */ 142 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Sort.h: -------------------------------------------------------------------------------- 1 | /* Sort.h -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_SORT_H 5 | #define __7Z_SORT_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void HeapSort(UInt32 *p, size_t size); 12 | void HeapSort64(UInt64 *p, size_t size); 13 | 14 | /* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */ 15 | 16 | EXTERN_C_END 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Threads.c: -------------------------------------------------------------------------------- 1 | /* Threads.c -- multithreading library 2 | 2017-06-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifndef UNDER_CE 7 | #include 8 | #endif 9 | 10 | #include "Threads.h" 11 | 12 | static WRes GetError() 13 | { 14 | DWORD res = GetLastError(); 15 | return res ? (WRes)res : 1; 16 | } 17 | 18 | static WRes HandleToWRes(HANDLE h) { return (h != NULL) ? 0 : GetError(); } 19 | static WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); } 20 | 21 | WRes HandlePtr_Close(HANDLE *p) 22 | { 23 | if (*p != NULL) 24 | { 25 | if (!CloseHandle(*p)) 26 | return GetError(); 27 | *p = NULL; 28 | } 29 | return 0; 30 | } 31 | 32 | WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); } 33 | 34 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param) 35 | { 36 | /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ 37 | 38 | #ifdef UNDER_CE 39 | 40 | DWORD threadId; 41 | *p = CreateThread(0, 0, func, param, 0, &threadId); 42 | 43 | #else 44 | 45 | unsigned threadId; 46 | *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId); 47 | 48 | #endif 49 | 50 | /* maybe we must use errno here, but probably GetLastError() is also OK. */ 51 | return HandleToWRes(*p); 52 | } 53 | 54 | static WRes Event_Create(CEvent *p, BOOL manualReset, int signaled) 55 | { 56 | *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL); 57 | return HandleToWRes(*p); 58 | } 59 | 60 | WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); } 61 | WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); } 62 | 63 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); } 64 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); } 65 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); } 66 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); } 67 | 68 | 69 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) 70 | { 71 | *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL); 72 | return HandleToWRes(*p); 73 | } 74 | 75 | static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) 76 | { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); } 77 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num) 78 | { return Semaphore_Release(p, (LONG)num, NULL); } 79 | WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); } 80 | 81 | WRes CriticalSection_Init(CCriticalSection *p) 82 | { 83 | /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ 84 | #ifdef _MSC_VER 85 | __try 86 | #endif 87 | { 88 | InitializeCriticalSection(p); 89 | /* InitializeCriticalSectionAndSpinCount(p, 0); */ 90 | } 91 | #ifdef _MSC_VER 92 | __except (EXCEPTION_EXECUTE_HANDLER) { return 1; } 93 | #endif 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Threads.h: -------------------------------------------------------------------------------- 1 | /* Threads.h -- multithreading library 2 | 2017-06-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_THREADS_H 5 | #define __7Z_THREADS_H 6 | 7 | #ifdef _WIN32 8 | #include 9 | #endif 10 | 11 | #include "7zTypes.h" 12 | 13 | EXTERN_C_BEGIN 14 | 15 | WRes HandlePtr_Close(HANDLE *h); 16 | WRes Handle_WaitObject(HANDLE h); 17 | 18 | typedef HANDLE CThread; 19 | #define Thread_Construct(p) *(p) = NULL 20 | #define Thread_WasCreated(p) (*(p) != NULL) 21 | #define Thread_Close(p) HandlePtr_Close(p) 22 | #define Thread_Wait(p) Handle_WaitObject(*(p)) 23 | 24 | typedef 25 | #ifdef UNDER_CE 26 | DWORD 27 | #else 28 | unsigned 29 | #endif 30 | THREAD_FUNC_RET_TYPE; 31 | 32 | #define THREAD_FUNC_CALL_TYPE MY_STD_CALL 33 | #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE 34 | typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *); 35 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param); 36 | 37 | typedef HANDLE CEvent; 38 | typedef CEvent CAutoResetEvent; 39 | typedef CEvent CManualResetEvent; 40 | #define Event_Construct(p) *(p) = NULL 41 | #define Event_IsCreated(p) (*(p) != NULL) 42 | #define Event_Close(p) HandlePtr_Close(p) 43 | #define Event_Wait(p) Handle_WaitObject(*(p)) 44 | WRes Event_Set(CEvent *p); 45 | WRes Event_Reset(CEvent *p); 46 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); 47 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); 48 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); 49 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); 50 | 51 | typedef HANDLE CSemaphore; 52 | #define Semaphore_Construct(p) *(p) = NULL 53 | #define Semaphore_IsCreated(p) (*(p) != NULL) 54 | #define Semaphore_Close(p) HandlePtr_Close(p) 55 | #define Semaphore_Wait(p) Handle_WaitObject(*(p)) 56 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); 57 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); 58 | WRes Semaphore_Release1(CSemaphore *p); 59 | 60 | typedef CRITICAL_SECTION CCriticalSection; 61 | WRes CriticalSection_Init(CCriticalSection *p); 62 | #define CriticalSection_Delete(p) DeleteCriticalSection(p) 63 | #define CriticalSection_Enter(p) EnterCriticalSection(p) 64 | #define CriticalSection_Leave(p) LeaveCriticalSection(p) 65 | 66 | EXTERN_C_END 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/Xz.c: -------------------------------------------------------------------------------- 1 | /* Xz.c - Xz 2 | 2017-05-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zCrc.h" 7 | #include "CpuArch.h" 8 | #include "Xz.h" 9 | #include "XzCrc64.h" 10 | 11 | const Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 }; 12 | /* const Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' }; */ 13 | 14 | unsigned Xz_WriteVarInt(Byte *buf, UInt64 v) 15 | { 16 | unsigned i = 0; 17 | do 18 | { 19 | buf[i++] = (Byte)((v & 0x7F) | 0x80); 20 | v >>= 7; 21 | } 22 | while (v != 0); 23 | buf[(size_t)i - 1] &= 0x7F; 24 | return i; 25 | } 26 | 27 | void Xz_Construct(CXzStream *p) 28 | { 29 | p->numBlocks = 0; 30 | p->blocks = NULL; 31 | p->flags = 0; 32 | } 33 | 34 | void Xz_Free(CXzStream *p, ISzAllocPtr alloc) 35 | { 36 | ISzAlloc_Free(alloc, p->blocks); 37 | p->numBlocks = 0; 38 | p->blocks = NULL; 39 | } 40 | 41 | unsigned XzFlags_GetCheckSize(CXzStreamFlags f) 42 | { 43 | unsigned t = XzFlags_GetCheckType(f); 44 | return (t == 0) ? 0 : (4 << ((t - 1) / 3)); 45 | } 46 | 47 | void XzCheck_Init(CXzCheck *p, unsigned mode) 48 | { 49 | p->mode = mode; 50 | switch (mode) 51 | { 52 | case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break; 53 | case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break; 54 | case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break; 55 | } 56 | } 57 | 58 | void XzCheck_Update(CXzCheck *p, const void *data, size_t size) 59 | { 60 | switch (p->mode) 61 | { 62 | case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break; 63 | case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break; 64 | case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break; 65 | } 66 | } 67 | 68 | int XzCheck_Final(CXzCheck *p, Byte *digest) 69 | { 70 | switch (p->mode) 71 | { 72 | case XZ_CHECK_CRC32: 73 | SetUi32(digest, CRC_GET_DIGEST(p->crc)); 74 | break; 75 | case XZ_CHECK_CRC64: 76 | { 77 | int i; 78 | UInt64 v = CRC64_GET_DIGEST(p->crc64); 79 | for (i = 0; i < 8; i++, v >>= 8) 80 | digest[i] = (Byte)(v & 0xFF); 81 | break; 82 | } 83 | case XZ_CHECK_SHA256: 84 | Sha256_Final(&p->sha, digest); 85 | break; 86 | default: 87 | return 0; 88 | } 89 | return 1; 90 | } 91 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/XzCrc64.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64.c -- CRC64 calculation 2 | 2017-05-23 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "XzCrc64.h" 7 | #include "CpuArch.h" 8 | 9 | #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42) 10 | 11 | #ifdef MY_CPU_LE 12 | #define CRC64_NUM_TABLES 4 13 | #else 14 | #define CRC64_NUM_TABLES 5 15 | #define CRC_UINT64_SWAP(v) \ 16 | ((v >> 56) \ 17 | | ((v >> 40) & ((UInt64)0xFF << 8)) \ 18 | | ((v >> 24) & ((UInt64)0xFF << 16)) \ 19 | | ((v >> 8) & ((UInt64)0xFF << 24)) \ 20 | | ((v << 8) & ((UInt64)0xFF << 32)) \ 21 | | ((v << 24) & ((UInt64)0xFF << 40)) \ 22 | | ((v << 40) & ((UInt64)0xFF << 48)) \ 23 | | ((v << 56))) 24 | 25 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 26 | #endif 27 | 28 | #ifndef MY_CPU_BE 29 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 30 | #endif 31 | 32 | typedef UInt64 (MY_FAST_CALL *CRC64_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table); 33 | 34 | static CRC64_FUNC g_Crc64Update; 35 | UInt64 g_Crc64Table[256 * CRC64_NUM_TABLES]; 36 | 37 | UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size) 38 | { 39 | return g_Crc64Update(v, data, size, g_Crc64Table); 40 | } 41 | 42 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size) 43 | { 44 | return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL; 45 | } 46 | 47 | void MY_FAST_CALL Crc64GenerateTable() 48 | { 49 | UInt32 i; 50 | for (i = 0; i < 256; i++) 51 | { 52 | UInt64 r = i; 53 | unsigned j; 54 | for (j = 0; j < 8; j++) 55 | r = (r >> 1) ^ (kCrc64Poly & ((UInt64)0 - (r & 1))); 56 | g_Crc64Table[i] = r; 57 | } 58 | for (i = 256; i < 256 * CRC64_NUM_TABLES; i++) 59 | { 60 | UInt64 r = g_Crc64Table[(size_t)i - 256]; 61 | g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); 62 | } 63 | 64 | #ifdef MY_CPU_LE 65 | 66 | g_Crc64Update = XzCrc64UpdateT4; 67 | 68 | #else 69 | { 70 | #ifndef MY_CPU_BE 71 | UInt32 k = 1; 72 | if (*(const Byte *)&k == 1) 73 | g_Crc64Update = XzCrc64UpdateT4; 74 | else 75 | #endif 76 | { 77 | for (i = 256 * CRC64_NUM_TABLES - 1; i >= 256; i--) 78 | { 79 | UInt64 x = g_Crc64Table[(size_t)i - 256]; 80 | g_Crc64Table[i] = CRC_UINT64_SWAP(x); 81 | } 82 | g_Crc64Update = XzCrc64UpdateT1_BeT4; 83 | } 84 | } 85 | #endif 86 | } 87 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/XzCrc64.h: -------------------------------------------------------------------------------- 1 | /* XzCrc64.h -- CRC64 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_CRC64_H 5 | #define __XZ_CRC64_H 6 | 7 | #include 8 | 9 | #include "7zTypes.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | extern UInt64 g_Crc64Table[]; 14 | 15 | void MY_FAST_CALL Crc64GenerateTable(void); 16 | 17 | #define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF) 18 | #define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL) 19 | #define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 20 | 21 | UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size); 22 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/XzCrc64Opt.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64Opt.c -- CRC64 calculation 2 | 2017-06-30 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifndef MY_CPU_BE 9 | 10 | #define CRC64_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 11 | 12 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 13 | { 14 | const Byte *p = (const Byte *)data; 15 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 | v = CRC64_UPDATE_BYTE_2(v, *p); 17 | for (; size >= 4; size -= 4, p += 4) 18 | { 19 | UInt32 d = (UInt32)v ^ *(const UInt32 *)p; 20 | v = (v >> 32) 21 | ^ (table + 0x300)[((d ) & 0xFF)] 22 | ^ (table + 0x200)[((d >> 8) & 0xFF)] 23 | ^ (table + 0x100)[((d >> 16) & 0xFF)] 24 | ^ (table + 0x000)[((d >> 24))]; 25 | } 26 | for (; size > 0; size--, p++) 27 | v = CRC64_UPDATE_BYTE_2(v, *p); 28 | return v; 29 | } 30 | 31 | #endif 32 | 33 | 34 | #ifndef MY_CPU_LE 35 | 36 | #define CRC_UINT64_SWAP(v) \ 37 | ((v >> 56) \ 38 | | ((v >> 40) & ((UInt64)0xFF << 8)) \ 39 | | ((v >> 24) & ((UInt64)0xFF << 16)) \ 40 | | ((v >> 8) & ((UInt64)0xFF << 24)) \ 41 | | ((v << 8) & ((UInt64)0xFF << 32)) \ 42 | | ((v << 24) & ((UInt64)0xFF << 40)) \ 43 | | ((v << 40) & ((UInt64)0xFF << 48)) \ 44 | | ((v << 56))) 45 | 46 | #define CRC64_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8)) 47 | 48 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 49 | { 50 | const Byte *p = (const Byte *)data; 51 | table += 0x100; 52 | v = CRC_UINT64_SWAP(v); 53 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 54 | v = CRC64_UPDATE_BYTE_2_BE(v, *p); 55 | for (; size >= 4; size -= 4, p += 4) 56 | { 57 | UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p; 58 | v = (v << 32) 59 | ^ (table + 0x000)[((d ) & 0xFF)] 60 | ^ (table + 0x100)[((d >> 8) & 0xFF)] 61 | ^ (table + 0x200)[((d >> 16) & 0xFF)] 62 | ^ (table + 0x300)[((d >> 24))]; 63 | } 64 | for (; size > 0; size--, p++) 65 | v = CRC64_UPDATE_BYTE_2_BE(v, *p); 66 | return CRC_UINT64_SWAP(v); 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/lzma/XzEnc.h: -------------------------------------------------------------------------------- 1 | /* XzEnc.h -- Xz Encode 2 | 2017-06-27 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_ENC_H 5 | #define __XZ_ENC_H 6 | 7 | #include "Lzma2Enc.h" 8 | 9 | #include "Xz.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | 14 | #define XZ_PROPS__BLOCK_SIZE__AUTO LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO 15 | #define XZ_PROPS__BLOCK_SIZE__SOLID LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID 16 | 17 | 18 | typedef struct 19 | { 20 | UInt32 id; 21 | UInt32 delta; 22 | UInt32 ip; 23 | int ipDefined; 24 | } CXzFilterProps; 25 | 26 | void XzFilterProps_Init(CXzFilterProps *p); 27 | 28 | 29 | typedef struct 30 | { 31 | CLzma2EncProps lzma2Props; 32 | CXzFilterProps filterProps; 33 | unsigned checkId; 34 | UInt64 blockSize; 35 | int numBlockThreads_Reduced; 36 | int numBlockThreads_Max; 37 | int numTotalThreads; 38 | int forceWriteSizesInHeader; 39 | UInt64 reduceSize; 40 | } CXzProps; 41 | 42 | void XzProps_Init(CXzProps *p); 43 | 44 | 45 | typedef void * CXzEncHandle; 46 | 47 | CXzEncHandle XzEnc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig); 48 | void XzEnc_Destroy(CXzEncHandle p); 49 | SRes XzEnc_SetProps(CXzEncHandle p, const CXzProps *props); 50 | void XzEnc_SetDataSize(CXzEncHandle p, UInt64 expectedDataSiize); 51 | SRes XzEnc_Encode(CXzEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress); 52 | 53 | SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream, 54 | const CXzProps *props, ICompressProgress *progress); 55 | 56 | SRes Xz_EncodeEmpty(ISeqOutStream *outStream); 57 | 58 | EXTERN_C_END 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /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_crash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XC_CRASH_H 25 | #define XC_CRASH_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int xc_crash_init(JNIEnv *env, 36 | int rethrow, 37 | unsigned int logcat_system_lines, 38 | unsigned int logcat_events_lines, 39 | unsigned int logcat_main_lines, 40 | int dump_elf_hash, 41 | int dump_map, 42 | int dump_fds, 43 | int dump_network_info, 44 | int dump_all_threads, 45 | unsigned int dump_all_threads_count_max, 46 | const char **dump_all_threads_whitelist, 47 | size_t dump_all_threads_whitelist_len); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_fallback.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XC_FALLBACK_H 25 | #define XC_FALLBACK_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | size_t xc_fallback_get_emergency(siginfo_t *si, 35 | ucontext_t *uc, 36 | pid_t tid, 37 | uint64_t crash_time, 38 | char *emergency, 39 | size_t emergency_len); 40 | 41 | int xc_fallback_record(int log_fd, 42 | char *emergency, 43 | unsigned int logcat_system_lines, 44 | unsigned int logcat_events_lines, 45 | unsigned int logcat_main_lines, 46 | int dump_fds, 47 | int dump_network_info); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_jni.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XC_JNI_H 25 | #define XC_JNI_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #define XC_JNI_IGNORE_PENDING_EXCEPTION() \ 36 | do { \ 37 | if((*env)->ExceptionCheck(env)) \ 38 | { \ 39 | (*env)->ExceptionClear(env); \ 40 | } \ 41 | } while(0) 42 | 43 | #define XC_JNI_CHECK_PENDING_EXCEPTION(label) \ 44 | do { \ 45 | if((*env)->ExceptionCheck(env)) \ 46 | { \ 47 | (*env)->ExceptionClear(env); \ 48 | goto label; \ 49 | } \ 50 | } while(0) 51 | 52 | #define XC_JNI_CHECK_NULL_AND_PENDING_EXCEPTION(v, label) \ 53 | do { \ 54 | XC_JNI_CHECK_PENDING_EXCEPTION(label); \ 55 | if(NULL == (v)) goto label; \ 56 | } while(0) 57 | 58 | #define XC_JNI_VERSION JNI_VERSION_1_6 59 | #define XC_JNI_CLASS_NAME "xcrash/NativeHandler" 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XC_TEST_H 25 | #define XC_TEST_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | void xc_test_crash(int run_in_new_thread); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_trace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-08-13. 23 | 24 | #ifndef XC_TRACE_H 25 | #define XC_TRACE_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef enum { 37 | XC_TRACE_DUMP_NOT_START = 0, 38 | XC_TRACE_DUMP_ON_GOING, 39 | XC_TRACE_DUMP_ART_CRASH, 40 | XC_TRACE_DUMP_END 41 | } xc_trace_dump_status_t; 42 | 43 | extern xc_trace_dump_status_t xc_trace_dump_status; 44 | extern sigjmp_buf jmpenv; 45 | 46 | int xc_trace_init(JNIEnv *env, 47 | int rethrow, 48 | unsigned int logcat_system_lines, 49 | unsigned int logcat_events_lines, 50 | unsigned int logcat_main_lines, 51 | int dump_fds, 52 | int dump_network_info); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_util.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #include 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 "xcc_errno.h" 39 | #include "xcc_fmt.h" 40 | #include "xcc_util.h" 41 | #include "xc_util.h" 42 | 43 | char *xc_util_strdupcat(const char *s1, const char *s2) 44 | { 45 | size_t s1_len, s2_len; 46 | char *s; 47 | 48 | if(NULL == s1 || NULL == s2) return NULL; 49 | 50 | s1_len = strlen(s1); 51 | s2_len = strlen(s2); 52 | 53 | if(NULL == (s = malloc(s1_len + s2_len + 1))) return NULL; 54 | memcpy(s, s1, s1_len); 55 | memcpy(s + s1_len, s2, s2_len + 1); 56 | 57 | return s; 58 | } 59 | 60 | int xc_util_mkdirs(const char *dir) 61 | { 62 | size_t len; 63 | char buf[PATH_MAX]; 64 | char *p; 65 | 66 | //check or try create dir directly 67 | errno = 0; 68 | if(0 == mkdir(dir, S_IRWXU) || EEXIST == errno) return 0; 69 | 70 | //trycreate dir recursively... 71 | 72 | len = strlen(dir); 73 | if(0 == len) return XCC_ERRNO_INVAL; 74 | if('/' != dir[0]) return XCC_ERRNO_INVAL; 75 | 76 | memcpy(buf, dir, len + 1); 77 | if(buf[len - 1] == '/') buf[len - 1] = '\0'; 78 | 79 | for(p = buf + 1; *p; p++) 80 | { 81 | if(*p == '/') 82 | { 83 | *p = '\0'; 84 | errno = 0; 85 | if(0 != mkdir(buf, S_IRWXU) && EEXIST != errno) return errno; 86 | *p = '/'; 87 | } 88 | } 89 | errno = 0; 90 | if(0 != mkdir(buf, S_IRWXU) && EEXIST != errno) return errno; 91 | return 0; 92 | } 93 | 94 | void xc_util_get_kernel_version(char *buf, size_t len) 95 | { 96 | struct utsname uts; 97 | 98 | if(0 != uname(&uts)) 99 | { 100 | strncpy(buf, "unknown", len); 101 | buf[len - 1] = '\0'; 102 | return; 103 | } 104 | 105 | snprintf(buf, len, "%s version %s %s (%s)", uts.sysname, uts.release, uts.version, uts.machine); 106 | } 107 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash/xc_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XC_UTIL_H 25 | #define XC_UTIL_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | char *xc_util_strdupcat(const char *s1, const char *s2); 35 | int xc_util_mkdirs(const char *dir); 36 | void xc_util_get_kernel_version(char *buf, size_t len); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_arm_exidx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifdef __arm__ 25 | 26 | #ifndef XCD_ARM_EXIDX_H 27 | #define XCD_ARM_EXIDX_H 1 28 | 29 | #include 30 | #include 31 | #include "xcd_regs.h" 32 | #include "xcd_memory.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | int xcd_arm_exidx_step(xcd_regs_t *regs, xcd_memory_t *memory, pid_t pid, 39 | size_t exidx_offset, size_t exidx_size, uintptr_t load_bias, 40 | uintptr_t pc, int *finished); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_dwarf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_DWARF_H 25 | #define XCD_DWARF_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_regs.h" 30 | #include "xcd_memory.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef enum 37 | { 38 | XCD_DWARF_TYPE_DEBUG_FRAME, 39 | XCD_DWARF_TYPE_EH_FRAME, 40 | XCD_DWARF_TYPE_EH_FRAME_HDR 41 | } xcd_dwarf_type_t; 42 | 43 | typedef struct xcd_dwarf xcd_dwarf_t; 44 | 45 | int xcd_dwarf_create(xcd_dwarf_t **self, xcd_memory_t *memory, pid_t pid, uintptr_t load_bias, uintptr_t hdr_load_bias, 46 | size_t offset, size_t size, xcd_dwarf_type_t type); 47 | 48 | int xcd_dwarf_step(xcd_dwarf_t *self, xcd_regs_t *regs, uintptr_t pc, int *finished); 49 | 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_elf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_ELF_H 25 | #define XCD_ELF_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_memory.h" 30 | #include "xcd_regs.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_elf xcd_elf_t; 37 | 38 | int xcd_elf_create(xcd_elf_t **self, pid_t pid, xcd_memory_t *memory); 39 | 40 | int xcd_elf_step(xcd_elf_t *self, uintptr_t rel_pc, uintptr_t step_pc, xcd_regs_t *regs, int *finished, int *sigreturn); 41 | 42 | int xcd_elf_get_function_info(xcd_elf_t *self, uintptr_t addr, char **name, size_t *name_offset); 43 | int xcd_elf_get_symbol_addr(xcd_elf_t *self, const char *name, uintptr_t *addr); 44 | 45 | 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); 46 | char *xcd_elf_get_so_name(xcd_elf_t *self); 47 | 48 | uintptr_t xcd_elf_get_load_bias(xcd_elf_t *self); 49 | xcd_memory_t *xcd_elf_get_memory(xcd_elf_t *self); 50 | 51 | int xcd_elf_is_valid(xcd_memory_t *memory); 52 | size_t xcd_elf_get_max_size(xcd_memory_t *memory); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_elf_interface.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_ELF_INTERFACE_H 25 | #define XCD_ELF_INTERFACE_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_memory.h" 30 | #include "xcd_regs.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_elf_interface xcd_elf_interface_t; 37 | 38 | int xcd_elf_interface_create(xcd_elf_interface_t **self, pid_t pid, xcd_memory_t *memory, uintptr_t *load_bias); 39 | 40 | xcd_elf_interface_t *xcd_elf_interface_gnu_create(xcd_elf_interface_t *self); 41 | 42 | int xcd_elf_interface_dwarf_step(xcd_elf_interface_t *self, uintptr_t step_pc, xcd_regs_t *regs, int *finished); 43 | #ifdef __arm__ 44 | int xcd_elf_interface_arm_exidx_step(xcd_elf_interface_t *self, uintptr_t step_pc, xcd_regs_t *regs, int *finished); 45 | #endif 46 | 47 | int xcd_elf_interface_get_function_info(xcd_elf_interface_t *self, uintptr_t addr, char **name, size_t *name_offset); 48 | int xcd_elf_interface_get_symbol_addr(xcd_elf_interface_t *self, const char *name, uintptr_t *addr); 49 | 50 | 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); 51 | char *xcd_elf_interface_get_so_name(xcd_elf_interface_t *self); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_frames.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_FRAMES_H 25 | #define XCD_FRAMES_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_regs.h" 30 | #include "xcd_maps.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_frames xcd_frames_t; 37 | 38 | int xcd_frames_create(xcd_frames_t **self, xcd_regs_t *regs, xcd_maps_t *maps, pid_t pid); 39 | void xcd_frames_destroy(xcd_frames_t **self); 40 | 41 | int xcd_frames_record_backtrace(xcd_frames_t *self, int log_fd); 42 | int xcd_frames_record_buildid(xcd_frames_t *self, int log_fd, int dump_elf_hash, uintptr_t fault_addr); 43 | int xcd_frames_record_stack(xcd_frames_t *self, int log_fd); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_log.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_LOG_H 25 | #define XCD_LOG_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define XCD_LOG_PRIO ANDROID_LOG_WARN 35 | 36 | #define XCD_LOG_TAG "xcrash_dumper" 37 | 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" 40 | #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) 41 | #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) 42 | #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) 43 | #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) 44 | #pragma clang diagnostic pop 45 | 46 | //debug-log flags for modules 47 | #define XCD_CORE_DEBUG 0 48 | #define XCD_THREAD_DEBUG 0 49 | #define XCD_ELF_DEBUG 0 50 | #define XCD_ELF_INTERFACE_DEBUG 0 51 | #define XCD_FRAMES_DEBUG 0 52 | #define XCD_DWARF_DEBUG 0 53 | #define XCD_ARM_EXIDX_DEBUG 0 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_map.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MAP_H 25 | #define XCD_MAP_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_elf.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #define XCD_MAP_PORT_DEVICE 0x8000 36 | 37 | #pragma clang diagnostic push 38 | #pragma clang diagnostic ignored "-Wpadded" 39 | typedef struct xcd_map 40 | { 41 | //base info from /proc//maps 42 | uintptr_t start; 43 | uintptr_t end; 44 | size_t offset; 45 | uint16_t flags; 46 | char *name; 47 | 48 | //ELF 49 | xcd_elf_t *elf; 50 | int elf_loaded; 51 | size_t elf_offset; 52 | size_t elf_start_offset; 53 | } xcd_map_t; 54 | #pragma clang diagnostic pop 55 | 56 | int xcd_map_init(xcd_map_t *self, uintptr_t start, uintptr_t end, size_t offset, 57 | const char * flags, const char *name); 58 | void xcd_map_uninit(xcd_map_t *self); 59 | 60 | xcd_elf_t *xcd_map_get_elf(xcd_map_t *self, pid_t pid, void *maps_obj); 61 | uintptr_t xcd_map_get_rel_pc(xcd_map_t *self, uintptr_t abs_pc, pid_t pid, void *maps_obj); 62 | uintptr_t xcd_map_get_abs_pc(xcd_map_t *self, uintptr_t rel_pc, pid_t pid, void *maps_obj); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_maps.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MAPS_H 25 | #define XCD_MAPS_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_map.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct xcd_maps xcd_maps_t; 36 | 37 | int xcd_maps_create(xcd_maps_t **self, pid_t pid); 38 | void xcd_maps_destroy(xcd_maps_t **self); 39 | 40 | xcd_map_t *xcd_maps_find_map(xcd_maps_t *self, uintptr_t pc); 41 | xcd_map_t *xcd_maps_get_prev_map(xcd_maps_t *self, xcd_map_t *cur_map); 42 | 43 | uintptr_t xcd_maps_find_abort_msg(xcd_maps_t *self); 44 | 45 | uintptr_t xcd_maps_find_pc(xcd_maps_t *self, const char *pathname, const char *symbol); 46 | 47 | int xcd_maps_record(xcd_maps_t *self, int log_fd); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /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.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MEMORY_H 25 | #define XCD_MEMORY_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef struct xcd_memory xcd_memory_t; 35 | 36 | typedef struct 37 | { 38 | void (*destroy)(void **self); 39 | size_t (*read)(void *self, uintptr_t addr, void *dst, size_t size); 40 | } xcd_memory_handlers_t; 41 | 42 | int xcd_memory_create(xcd_memory_t **self, void *map_obj, pid_t pid, void *maps_obj); 43 | int xcd_memory_create_from_buf(xcd_memory_t **self, uint8_t *buf, size_t len); 44 | void xcd_memory_destroy(xcd_memory_t **self); 45 | 46 | size_t xcd_memory_read(xcd_memory_t *self, uintptr_t addr, void *dst, size_t size); 47 | int xcd_memory_read_fully(xcd_memory_t *self, uintptr_t addr, void* dst, size_t size); 48 | int xcd_memory_read_string(xcd_memory_t *self, uintptr_t addr, char *dst, size_t size, size_t max_read); 49 | int xcd_memory_read_uleb128(xcd_memory_t *self, uintptr_t addr, uint64_t *dst, size_t *size); 50 | int xcd_memory_read_sleb128(xcd_memory_t *self, uintptr_t addr, int64_t *dst, size_t *size); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_buf.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #include 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_memory.h" 33 | #include "xcd_memory_buf.h" 34 | #include "xcd_util.h" 35 | 36 | struct xcd_memory_buf 37 | { 38 | uint8_t *buf; 39 | size_t len; 40 | }; 41 | 42 | int xcd_memory_buf_create(void **obj, uint8_t *buf, size_t len) 43 | { 44 | xcd_memory_buf_t **self = (xcd_memory_buf_t **)obj; 45 | 46 | if(NULL == (*self = malloc(sizeof(xcd_memory_buf_t)))) return XCC_ERRNO_NOMEM; 47 | (*self)->buf = buf; 48 | (*self)->len = len; 49 | 50 | return 0; 51 | } 52 | 53 | void xcd_memory_buf_destroy(void **obj) 54 | { 55 | xcd_memory_buf_t **self = (xcd_memory_buf_t **)obj; 56 | 57 | free((*self)->buf); 58 | free(*self); 59 | *self = NULL; 60 | } 61 | 62 | size_t xcd_memory_buf_read(void *obj, uintptr_t addr, void *dst, size_t size) 63 | { 64 | xcd_memory_buf_t *self = (xcd_memory_buf_t *)obj; 65 | 66 | if((size_t)addr >= self->len) return 0; 67 | 68 | #pragma clang diagnostic push 69 | #pragma clang diagnostic ignored "-Wgnu-statement-expression" 70 | size_t read_length = XCC_UTIL_MIN(size, self->len - addr); 71 | #pragma clang diagnostic pop 72 | 73 | memcpy(dst, self->buf + addr, read_length); 74 | return read_length; 75 | } 76 | 77 | #pragma clang diagnostic push 78 | #pragma clang diagnostic ignored "-Wmissing-variable-declarations" 79 | const xcd_memory_handlers_t xcd_memory_buf_handlers = { 80 | xcd_memory_buf_destroy, 81 | xcd_memory_buf_read 82 | }; 83 | #pragma clang diagnostic pop 84 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_buf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MEMORY_BUF_H 25 | #define XCD_MEMORY_BUF_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef struct xcd_memory_buf xcd_memory_buf_t; 35 | 36 | int xcd_memory_buf_create(void **obj, uint8_t *buf, size_t len); 37 | void xcd_memory_buf_destroy(void **obj); 38 | size_t xcd_memory_buf_read(void *obj, uintptr_t addr, void *dst, size_t size); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MEMORY_FILE_H 25 | #define XCD_MEMORY_FILE_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_map.h" 30 | #include "xcd_maps.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct xcd_memory_file xcd_memory_file_t; 37 | 38 | int xcd_memory_file_create(void **obj, xcd_memory_t *base, xcd_map_t *map, xcd_maps_t *maps); 39 | void xcd_memory_file_destroy(void **obj); 40 | size_t xcd_memory_file_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_memory_remote.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #include 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_memory.h" 33 | #include "xcd_memory_remote.h" 34 | #include "xcd_util.h" 35 | #include "xcd_log.h" 36 | 37 | #pragma clang diagnostic push 38 | #pragma clang diagnostic ignored "-Wpadded" 39 | struct xcd_memory_remote 40 | { 41 | pid_t pid; 42 | uintptr_t start; 43 | size_t length; 44 | }; 45 | #pragma clang diagnostic pop 46 | 47 | int xcd_memory_remote_create(void **obj, xcd_map_t *map, pid_t pid) 48 | { 49 | xcd_memory_remote_t **self = (xcd_memory_remote_t **)obj; 50 | 51 | if(NULL == (*self = malloc(sizeof(xcd_memory_remote_t)))) return XCC_ERRNO_NOMEM; 52 | (*self)->pid = pid; 53 | (*self)->start = map->start; 54 | (*self)->length = (size_t)(map->end - map->start); 55 | 56 | return 0; 57 | } 58 | 59 | void xcd_memory_remote_destroy(void **obj) 60 | { 61 | xcd_memory_remote_t **self = (xcd_memory_remote_t **)obj; 62 | 63 | free(*self); 64 | *self = NULL; 65 | } 66 | 67 | size_t xcd_memory_remote_read(void *obj, uintptr_t addr, void *dst, size_t size) 68 | { 69 | xcd_memory_remote_t *self = (xcd_memory_remote_t *)obj; 70 | 71 | if((size_t)addr >= self->length) return 0; 72 | 73 | #pragma clang diagnostic push 74 | #pragma clang diagnostic ignored "-Wgnu-statement-expression" 75 | size_t read_length = XCC_UTIL_MIN(size, self->length - addr); 76 | #pragma clang diagnostic pop 77 | 78 | uint64_t read_addr; 79 | if(__builtin_add_overflow(self->start, addr, &read_addr)) return 0; 80 | 81 | return xcd_util_ptrace_read(self->pid, (uintptr_t)read_addr, dst, read_length); 82 | } 83 | 84 | #pragma clang diagnostic push 85 | #pragma clang diagnostic ignored "-Wmissing-variable-declarations" 86 | const xcd_memory_handlers_t xcd_memory_remote_handlers = { 87 | xcd_memory_remote_destroy, 88 | xcd_memory_remote_read 89 | }; 90 | #pragma clang diagnostic pop 91 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_memory_remote.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_MEMORY_REMOTE_H 25 | #define XCD_MEMORY_REMOTE_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_map.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct xcd_memory_remote xcd_memory_remote_t; 36 | 37 | int xcd_memory_remote_create(void **obj, xcd_map_t *map, pid_t pid); 38 | void xcd_memory_remote_destroy(void **obj); 39 | size_t xcd_memory_remote_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_process.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_THREADS_H 25 | #define XCD_THREADS_H 1 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | typedef struct xcd_process xcd_process_t; 35 | 36 | int xcd_process_create(xcd_process_t **self, pid_t pid, pid_t crash_tid, siginfo_t *si, ucontext_t *uc); 37 | size_t xcd_process_get_number_of_threads(xcd_process_t *self); 38 | 39 | void xcd_process_suspend_threads(xcd_process_t *self); 40 | void xcd_process_resume_threads(xcd_process_t *self); 41 | 42 | int xcd_process_load_info(xcd_process_t *self); 43 | 44 | int xcd_process_record(xcd_process_t *self, 45 | int log_fd, 46 | unsigned int logcat_system_lines, 47 | unsigned int logcat_events_lines, 48 | unsigned int logcat_main_lines, 49 | int dump_elf_hash, 50 | int dump_map, 51 | int dump_fds, 52 | int dump_network_info, 53 | int dump_all_threads, 54 | unsigned int dump_all_threads_count_max, 55 | char *dump_all_threads_whitelist, 56 | int api_level); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_regs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_REGS_H 25 | #define XCD_REGS_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | #include "xcd_memory.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #if defined(__arm__) 37 | #define XCD_REGS_USER_NUM 18 38 | #define XCD_REGS_MACHINE_NUM 16 39 | #elif defined(__aarch64__) 40 | #define XCD_REGS_USER_NUM 34 41 | #define XCD_REGS_MACHINE_NUM 33 42 | #elif defined(__i386__) 43 | #define XCD_REGS_USER_NUM 17 44 | #define XCD_REGS_MACHINE_NUM 16 45 | #elif defined(__x86_64__) 46 | #define XCD_REGS_USER_NUM 27 47 | #define XCD_REGS_MACHINE_NUM 17 48 | #endif 49 | 50 | #pragma clang diagnostic push 51 | #pragma clang diagnostic ignored "-Wpadded" 52 | typedef struct { 53 | uintptr_t r[XCD_REGS_USER_NUM]; 54 | } xcd_regs_t; 55 | #pragma clang diagnostic pop 56 | 57 | uintptr_t xcd_regs_get_pc(xcd_regs_t *self); 58 | void xcd_regs_set_pc(xcd_regs_t *self, uintptr_t pc); 59 | 60 | uintptr_t xcd_regs_get_sp(xcd_regs_t *self); 61 | void xcd_regs_set_sp(xcd_regs_t *self, uintptr_t sp); 62 | 63 | #pragma clang diagnostic push 64 | #pragma clang diagnostic ignored "-Wpadded" 65 | typedef struct { 66 | uint8_t idx; 67 | const char *name; 68 | } xcd_regs_label_t; 69 | #pragma clang diagnostic pop 70 | 71 | void xcd_regs_get_labels(xcd_regs_label_t **labels, size_t *labels_count); 72 | 73 | void xcd_regs_load_from_ucontext(xcd_regs_t *self, ucontext_t *uc); 74 | void xcd_regs_load_from_ptregs(xcd_regs_t *self, uintptr_t *regs, size_t regs_len); 75 | 76 | int xcd_regs_record(xcd_regs_t *self, int log_fd); 77 | 78 | int xcd_regs_try_step_sigreturn(xcd_regs_t *self, uintptr_t rel_pc, xcd_memory_t *memory, pid_t pid); 79 | 80 | uintptr_t xcd_regs_get_adjust_pc(uintptr_t rel_pc, uintptr_t load_bias, xcd_memory_t *memory); 81 | 82 | int xcd_regs_set_pc_from_lr(xcd_regs_t *self, pid_t pid); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_sys.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "xcc_util.h" 29 | #include "xcd_sys.h" 30 | 31 | int xcd_sys_record(int fd, 32 | long time_zone, 33 | uint64_t start_time, 34 | uint64_t crash_time, 35 | const char *app_id, 36 | const char *app_version, 37 | int api_level, 38 | const char *os_version, 39 | const char *kernel_version, 40 | const char *abi_list, 41 | const char *manufacturer, 42 | const char *brand, 43 | const char *model, 44 | const char *build_fingerprint) 45 | { 46 | char buf[1024]; 47 | xcc_util_get_dump_header(buf, sizeof(buf), 48 | XCC_UTIL_CRASH_TYPE_NATIVE, 49 | time_zone, 50 | start_time, 51 | crash_time, 52 | app_id, 53 | app_version, 54 | api_level, 55 | os_version, 56 | kernel_version, 57 | abi_list, 58 | manufacturer, 59 | brand, 60 | model, 61 | build_fingerprint); 62 | return xcc_util_write_str(fd, buf); 63 | } 64 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_sys.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_SYS_H 25 | #define XCD_SYS_H 1 26 | 27 | #include 28 | #include 29 | #include "xcc_util.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int xcd_sys_record(int fd, 36 | long time_zone, 37 | uint64_t start_time, 38 | uint64_t crash_time, 39 | const char *app_id, 40 | const char *app_version, 41 | int api_level, 42 | const char *os_version, 43 | const char *kernel_version, 44 | const char *abi_list, 45 | const char *manufacturer, 46 | const char *brand, 47 | const char *model, 48 | const char *build_fingerprint); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_thread.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_THREAD_H 25 | #define XCD_THREAD_H 1 26 | 27 | #include 28 | #include 29 | #include "xcd_regs.h" 30 | #include "xcd_frames.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef enum 37 | { 38 | XCD_THREAD_STATUS_OK = 0, 39 | XCD_THREAD_STATUS_UNKNOWN, 40 | XCD_THREAD_STATUS_REGS, 41 | XCD_THREAD_STATUS_ATTACH, 42 | XCD_THREAD_STATUS_ATTACH_WAIT 43 | } xcd_thread_status_t; 44 | 45 | #pragma clang diagnostic push 46 | #pragma clang diagnostic ignored "-Wpadded" 47 | typedef struct xcd_thread 48 | { 49 | xcd_thread_status_t status; 50 | pid_t pid; 51 | pid_t tid; 52 | char *tname; 53 | xcd_regs_t regs; 54 | xcd_frames_t *frames; 55 | } xcd_thread_t; 56 | #pragma clang diagnostic pop 57 | 58 | void xcd_thread_init(xcd_thread_t *self, pid_t pid, pid_t tid); 59 | 60 | void xcd_thread_suspend(xcd_thread_t *self); 61 | void xcd_thread_resume(xcd_thread_t *self); 62 | 63 | void xcd_thread_load_info(xcd_thread_t *self); 64 | void xcd_thread_load_regs(xcd_thread_t *self); 65 | void xcd_thread_load_regs_from_ucontext(xcd_thread_t *self, ucontext_t *uc); 66 | int xcd_thread_load_frames(xcd_thread_t *self, xcd_maps_t *maps); 67 | 68 | int xcd_thread_record_info(xcd_thread_t *self, int log_fd, const char *pname); 69 | int xcd_thread_record_regs(xcd_thread_t *self, int log_fd); 70 | int xcd_thread_record_backtrace(xcd_thread_t *self, int log_fd); 71 | int xcd_thread_record_buildid(xcd_thread_t *self, int log_fd, int dump_elf_hash, uintptr_t fault_addr); 72 | int xcd_thread_record_stack(xcd_thread_t *self, int log_fd); 73 | int xcd_thread_record_memory(xcd_thread_t *self, int log_fd); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/cpp/xcrash_dumper/xcd_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | 24 | #ifndef XCD_UTIL_H 25 | #define XCD_UTIL_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | size_t xcd_util_ptrace_read(pid_t pid, uintptr_t addr, void *dst, size_t bytes); 36 | int xcd_util_ptrace_read_fully(pid_t pid, uintptr_t addr, void *dst, size_t bytes); 37 | int xcd_util_ptrace_read_long(pid_t pid, uintptr_t addr, long *value); 38 | 39 | int xcd_util_xz_decompress(uint8_t* src, size_t src_size, uint8_t** dst, size_t* dst_size); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/DefaultLogger.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-05-30. 23 | package xcrash; 24 | 25 | import android.util.Log; 26 | 27 | class DefaultLogger implements ILogger { 28 | @Override 29 | public void v(String tag, String msg) { 30 | Log.v(tag, msg); 31 | } 32 | 33 | @Override 34 | public void v(String tag, String msg, Throwable tr) { 35 | Log.v(tag, msg, tr); 36 | } 37 | 38 | @Override 39 | public void d(String tag, String msg) { 40 | Log.d(tag, msg); 41 | } 42 | 43 | @Override 44 | public void d(String tag, String msg, Throwable tr) { 45 | Log.d(tag, msg, tr); 46 | } 47 | 48 | @Override 49 | public void i(String tag, String msg) { 50 | Log.i(tag, msg); 51 | } 52 | 53 | @Override 54 | public void i(String tag, String msg, Throwable tr) { 55 | Log.i(tag, msg, tr); 56 | } 57 | 58 | @Override 59 | public void w(String tag, String msg) { 60 | Log.w(tag, msg); 61 | } 62 | 63 | @Override 64 | public void w(String tag, String msg, Throwable tr) { 65 | Log.w(tag, msg, tr); 66 | } 67 | 68 | @Override 69 | public void e(String tag, String msg) { 70 | Log.e(tag, msg); 71 | } 72 | 73 | @Override 74 | public void e(String tag, String msg, Throwable tr) { 75 | Log.e(tag, msg, tr); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/Errno.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | package xcrash; 24 | 25 | /** 26 | * The errno code for init() method of {@link xcrash.XCrash}. 27 | */ 28 | @SuppressWarnings("WeakerAccess") 29 | public final class Errno { 30 | 31 | /** 32 | * Initialization successful. 33 | */ 34 | public static final int OK = 0; 35 | 36 | /** 37 | * The context parameter is null. 38 | */ 39 | public static final int CONTEXT_IS_NULL = -1; 40 | 41 | /** 42 | * Load xCrash's native library failed. 43 | */ 44 | public static final int LOAD_LIBRARY_FAILED = -2; 45 | 46 | /** 47 | * Initialize xCrash's native library failed. 48 | */ 49 | public static final int INIT_LIBRARY_FAILED = -3; 50 | 51 | private Errno() { 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/ICrashCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | package xcrash; 24 | 25 | /** 26 | * Define the callback interface after the crash occurs. 27 | * 28 | *

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

In practice, older versions of Android had bugs in PackageManager 29 | * that caused installation and update of native libraries to be unreliable. 30 | */ 31 | public interface ILibLoader { 32 | 33 | /** 34 | * Loads the native library specified by the libName argument. 35 | * 36 | * @param libName the name of the library. 37 | */ 38 | void loadLibrary(String libName); 39 | } 40 | -------------------------------------------------------------------------------- /xcrash_lib/src/main/java/xcrash/Version.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | package xcrash; 24 | 25 | class Version { 26 | 27 | private Version() { 28 | } 29 | 30 | static final String version = "3.1.0"; 31 | static final String fullVersion = "xCrash " + version; 32 | } 33 | -------------------------------------------------------------------------------- /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.1' 37 | // implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.1.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 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /xcrash_sample/src/main/java/xcrash/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-present, iQIYI, Inc. All rights reserved. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | 22 | // Created by caikelun on 2019-03-07. 23 | package xcrash.sample; 24 | 25 | import android.content.Intent; 26 | import androidx.appcompat.app.AppCompatActivity; 27 | import android.os.Bundle; 28 | import android.view.View; 29 | 30 | import xcrash.XCrash; 31 | 32 | public class MainActivity extends AppCompatActivity { 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | } 39 | 40 | public void testNativeCrashInMainThread_onClick(View view) { 41 | XCrash.testNativeCrash(false); 42 | } 43 | 44 | public void testNativeCrashInAnotherJavaThread_onClick(View view) { 45 | new Thread(new Runnable() { 46 | @Override 47 | public void run() { 48 | XCrash.testNativeCrash(false); 49 | } 50 | }, "java_thread_with_a_very_long_name").start(); 51 | } 52 | 53 | public void testNativeCrashInAnotherNativeThread_onClick(View view) { 54 | XCrash.testNativeCrash(true); 55 | } 56 | 57 | public void testNativeCrashInAnotherActivity_onClick(View view) { 58 | startActivity(new Intent(this, SecondActivity.class).putExtra("type", "native")); 59 | } 60 | 61 | public void testNativeCrashInAnotherProcess_onClick(View view) { 62 | startService(new Intent(this, MyService.class).putExtra("type", "native")); 63 | } 64 | 65 | public void testJavaCrashInMainThread_onClick(View view) { 66 | XCrash.testJavaCrash(false); 67 | } 68 | 69 | public void testJavaCrashInAnotherThread_onClick(View view) { 70 | XCrash.testJavaCrash(true); 71 | } 72 | 73 | public void testJavaCrashInAnotherActivity_onClick(View view) { 74 | startActivity(new Intent(this, SecondActivity.class).putExtra("type", "java")); 75 | } 76 | 77 | public void testJavaCrashInAnotherProcess_onClick(View view) { 78 | startService(new Intent(this, MyService.class).putExtra("type", "java")); 79 | } 80 | public void testAnrInput_onClick(View view) { 81 | while (true) { 82 | try { 83 | Thread.sleep(1000); 84 | } catch (Exception ignored) { 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /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/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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/iqiyi/xCrash/457066ceb48fb84b993f1f04871d9e634d752792/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 | --------------------------------------------------------------------------------