├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── bug_report_zh.yml │ ├── config.yml │ └── feature_request.yml └── workflows │ ├── build.yml │ ├── delete_old_workflow_runs.yml │ ├── genReleaseNote.sh │ └── release.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── README_CN.md ├── VC-LTL5.lua ├── src ├── appid.h ├── chrome++.cpp ├── chrome++.ini ├── chrome++.rc ├── config.h ├── fastsearch.h ├── green.h ├── hijack.h ├── hotkey.h ├── iaccessible.h ├── pakfile.h ├── pakpatch.h ├── patch.h ├── portable.h ├── tabbookmark.h ├── utils.h └── version.h └── xmake.lua /.clang-format: -------------------------------------------------------------------------------- 1 | # https://clang.llvm.org/docs/ClangFormatStyleOptions.html 2 | 3 | Language: Cpp 4 | BasedOnStyle: Chromium 5 | Standard: c++20 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: "Report Chrome++ Bug" 3 | title: "[Bug] " 4 | body: 5 | - type: checkboxes 6 | id: ensure 7 | attributes: 8 | label: Verify steps 9 | description: Before submitting, please check the following applicable options to prove that you have read and understood the following requirements, otherwise the issue will be closed. 10 | options: 11 | - label: I have carefully read the [INI configuration file](https://github.com/Bush2021/chrome_plus/blob/main/src/chrome%2B%2B.ini) and understand the function of each configuration item. 12 | required: true 13 | - label: I have not searched for the problem I want to raise in the [Issue Tracker](https://github.com/Bush2021/chrome_plus/issues). 14 | required: false 15 | - label: I have provided the simplest configuration that can be used to reproduce the error I reported. 16 | required: true 17 | - label: I make sure to describe the problem in English. 18 | required: true 19 | 20 | - type: textarea 21 | attributes: 22 | label: Version Information 23 | description: Please provide a screenshot of `chrome://version/`. 24 | validations: 25 | required: true 26 | - type: textarea 27 | attributes: 28 | render: yaml 29 | label: Configuration File 30 | description: Please paste the simplest `chrome++.ini` content used to reproduce the problem. 31 | validations: 32 | required: true 33 | - type: textarea 34 | attributes: 35 | label: Description 36 | description: Please provide a detailed description of the error and the steps to reproduce the error. 37 | validations: 38 | required: true 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report_zh.yml: -------------------------------------------------------------------------------- 1 | name: 错误反馈 2 | description: "提交 Chrome++ Bug" 3 | title: "[Bug] " 4 | body: 5 | - type: checkboxes 6 | id: ensure 7 | attributes: 8 | label: 验证步骤 9 | description: 在提交之前,请勾选以下适用选项以证明您已经阅读并理解了以下要求,否则该 issue 将被关闭。 10 | options: 11 | - label: 我仔细看过 [INI 配置文件](https://github.com/Bush2021/chrome_plus/blob/main/src/chrome%2B%2B.ini) 并理解了每个配置项的作用。 12 | required: true 13 | - label: 我未在 [Issue Tracker](https://github.com/Bush2021/chrome_plus/issues) 中寻找过我要提出的问题。 14 | required: false 15 | - label: 我提供了可用于重现我报告的错误的最简配置。 16 | required: true 17 | - label: 我确保使用中文描述问题。 18 | required: true 19 | 20 | - type: textarea 21 | attributes: 22 | label: 版本信息 23 | description: 请提供 `chrome://version/` 的截图。 24 | validations: 25 | required: true 26 | - type: textarea 27 | attributes: 28 | render: yaml 29 | label: 配置文件 30 | description: 请粘贴用于复现问题的最简 `chrome++.ini` 内容。 31 | validations: 32 | required: true 33 | - type: textarea 34 | attributes: 35 | label: 描述 36 | description: 请提供错误的详细描述以及重现错误的步骤 37 | validations: 38 | required: true 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Suggest improvements for this project 3 | title: "[Feature] " 4 | body: 5 | - type: checkboxes 6 | id: ensure 7 | attributes: 8 | label: Verification Steps 9 | description: Before submitting, please check the following applicable options to prove that you have read and understood the following requirements, otherwise the issue will be closed. 10 | options: 11 | - label: I have carefully read the [INI configuration file](https://github.com/Bush2021/chrome_plus/blob/main/src/chrome%2B%2B.ini) and understand the function of each configuration item. 12 | required: true 13 | - label: I have not searched for the feature request I want to propose in the [Issue Tracker](https://github.com/Bush2021/chrome_plus/issues) and did not find it. 14 | required: false 15 | - label: I am willing to create a pull request to implement the feature I proposed, otherwise I understand that the issue is likely to be closed. 16 | required: true 17 | - label: I make sure to describe the feature in English. 18 | required: true 19 | - type: textarea 20 | attributes: 21 | label: Description 22 | description: Please provide a detailed description of the feature, rather than vague statements. 23 | validations: 24 | required: true 25 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - ".clang-format" 7 | - ".gitignore" 8 | - "*.md" 9 | - "LICENSE" 10 | - "setdll/**" 11 | - "src/version.h" 12 | - ".github/ISSUE_TEMPLATE/**" 13 | - ".github/workflows/delete_old_workflow_runs.yml" 14 | - ".github/workflows/genReleaseNote.sh" 15 | workflow_dispatch: 16 | inputs: 17 | version: 18 | description: 'Release version (SemVer)' 19 | required: true 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | matrix: 25 | include: 26 | - name: build_x86 27 | arch: x86 28 | - name: build_x64 29 | arch: x64 30 | - name: build_arm64 31 | arch: arm64 32 | 33 | name: ${{ matrix.name }} 34 | runs-on: windows-latest 35 | 36 | steps: 37 | - name: Checkout Repo 38 | uses: actions/checkout@v4 39 | with: 40 | submodules: 'true' 41 | 42 | - name: Update version.h 43 | shell: bash 44 | run: | 45 | if [ "${{ github.event_name }}" == "push" ]; then 46 | COMMIT_HASH=$(git rev-parse --short HEAD) 47 | VERSION="alpha-${COMMIT_HASH}" 48 | echo "VERSION=$VERSION" >> $GITHUB_ENV 49 | sed -i '/#define RELEASE_VER_STR/,/TOSTRING(RELEASE_VER_FIX)/c\#define RELEASE_VER_STR "'"$VERSION"'"' src/version.h 50 | elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then 51 | VERSION="${{ github.event.inputs.version }}" 52 | echo "VERSION=$VERSION" >> $GITHUB_ENV 53 | IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" 54 | sed -i 's/#define RELEASE_VER_MAIN .*/#define RELEASE_VER_MAIN '"$MAJOR"'/' src/version.h 55 | sed -i 's/#define RELEASE_VER_SUB .*/#define RELEASE_VER_SUB '"$MINOR"'/' src/version.h 56 | sed -i 's/#define RELEASE_VER_FIX .*/#define RELEASE_VER_FIX '"$PATCH"'/' src/version.h 57 | fi 58 | 59 | - name: Setup VC-LTL 60 | run: nuget install VC-LTL 61 | 62 | - name: Setup Xmake 63 | uses: xmake-io/github-action-setup-xmake@v1 64 | 65 | - name: Configure Xmake 66 | run: xmake f -a ${{ matrix.arch }} 67 | 68 | - name: Build Chrome++ 69 | run: xmake 70 | 71 | - name: Upload Build Artifacts 72 | uses: actions/upload-artifact@v4 73 | with: 74 | name: version-${{ matrix.arch }}-${{ env.VERSION }} 75 | path: build/release/* 76 | 77 | create_pr: 78 | needs: build 79 | runs-on: ubuntu-latest 80 | if: github.event_name == 'workflow_dispatch' 81 | 82 | steps: 83 | - name: Checkout repository 84 | uses: actions/checkout@v4 85 | 86 | - name: Set up Git Configurations 87 | run: | 88 | git config user.name "github-actions[bot]" 89 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 90 | git checkout -b release 91 | 92 | - name: Update version.h 93 | run: | 94 | VERSION="${{ github.event.inputs.version }}" 95 | echo "VERSION=$VERSION" >> $GITHUB_ENV 96 | IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" 97 | sed -i 's/#define RELEASE_VER_MAIN .*/#define RELEASE_VER_MAIN '"$MAJOR"'/' src/version.h 98 | sed -i 's/#define RELEASE_VER_SUB .*/#define RELEASE_VER_SUB '"$MINOR"'/' src/version.h 99 | sed -i 's/#define RELEASE_VER_FIX .*/#define RELEASE_VER_FIX '"$PATCH"'/' src/version.h 100 | git add src/version.h 101 | git commit -m "build(release): bump version to $VERSION" 102 | git push origin release --force 103 | 104 | - name: Create Pull Request 105 | env: 106 | GITHUB_TOKEN: ${{ secrets.TOKEN }} 107 | run: | 108 | git push origin release 109 | gh pr create --base main --head release --title "build(release): bump version to ${{ github.event.inputs.version }}" --body "Bump version to ${{ github.event.inputs.version }}" 110 | 111 | - name: Output Run ID 112 | run: echo "RUN_ID=${{ github.run_id }}" >> $GITHUB_OUTPUT 113 | -------------------------------------------------------------------------------- /.github/workflows/delete_old_workflow_runs.yml: -------------------------------------------------------------------------------- 1 | name: Delete Old Workflow Runs 2 | on: 3 | workflow_dispatch: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | del_runs: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Delete workflow runs 12 | uses: Mattraks/delete-workflow-runs@v2 13 | with: 14 | token: ${{ github.token }} 15 | repository: ${{ github.repository }} 16 | retain_days: 90 17 | keep_minimum_runs: 0 18 | -------------------------------------------------------------------------------- /.github/workflows/genReleaseNote.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # From https://github.com/MetaCubeX/mihomo/blob/82517e6ba8059339287911af899ffdffca6a4044/.github/genReleaseNote.sh 3 | 4 | while getopts "v:" opt; do 5 | case $opt in 6 | v) 7 | version_range=$OPTARG 8 | ;; 9 | \?) 10 | echo "Invalid option: -$OPTARG" >&2 11 | exit 1 12 | ;; 13 | esac 14 | done 15 | 16 | if [ -z "$version_range" ]; then 17 | echo "Please provide the version range using -v option. Example: chmod +x genReleaseNote.sh && ./genReleaseNote.sh -v 1.0.0..HEAD" >&2 18 | exit 1 19 | fi 20 | 21 | repo_url=$(git config --get remote.origin.url) 22 | if [ -z "$repo_url" ]; then 23 | echo "Could not determine the repository URL. Please ensure you are in a git repository." >&2 24 | exit 1 25 | fi 26 | 27 | repo_url=${repo_url%.git} 28 | 29 | new_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^feat" -i $version_range | sort -f | uniq) 30 | if [ -n "$new_commits" ]; then 31 | echo "## New" >> release.md 32 | echo "$new_commits" >> release.md 33 | echo "" >> release.md 34 | fi 35 | 36 | fix_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^fix" -i $version_range | sort -f | uniq) 37 | if [ -n "$fix_commits" ]; then 38 | echo "## Fix" >> release.md 39 | echo "$fix_commits" >> release.md 40 | echo "" >> release.md 41 | fi 42 | 43 | maint_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^chore\|^docs\|^refactor" -i $version_range | sort -f | uniq) 44 | if [ -n "$maint_commits" ]; then 45 | echo "## Maintenance" >> release.md 46 | echo "$maint_commits" >> release.md 47 | echo "" >> release.md 48 | fi 49 | 50 | echo "**Full Changelog**: $repo_url/compare/$version_range" >> release.md 51 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - 'src/version.h' 9 | 10 | jobs: 11 | release: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v4 17 | with: 18 | ref: main 19 | fetch-depth: 0 20 | 21 | - name: Get Last Tag 22 | run: | 23 | LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "0.0.0") 24 | echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV 25 | 26 | - name: Get Version from version.h 27 | run: | 28 | MAJOR=$(grep '#define RELEASE_VER_MAIN' src/version.h | awk '{print $3}') 29 | MINOR=$(grep '#define RELEASE_VER_SUB' src/version.h | awk '{print $3}') 30 | PATCH=$(grep '#define RELEASE_VER_FIX' src/version.h | awk '{print $3}') 31 | VERSION="$MAJOR.$MINOR.$PATCH" 32 | echo "VERSION=$VERSION" >> $GITHUB_ENV 33 | 34 | - name: Create Tag 35 | run: | 36 | git config user.name "github-actions[bot]" 37 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 38 | git tag -a "${{ env.VERSION }}" -m "${{ env.VERSION }}" 39 | 40 | - name: Generate Release Notes 41 | run: | 42 | chmod +x .github/workflows/genReleaseNote.sh 43 | .github/workflows/genReleaseNote.sh -v ${{ env.LAST_TAG }}...${{ env.VERSION }} 44 | 45 | - name: Get Latest Workflow Run 46 | id: workflow 47 | run: | 48 | RUN_ID=$(gh api repos/${{ github.repository }}/actions/workflows/build.yml/runs \ 49 | --jq '.workflow_runs[0].id') 50 | echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | 54 | - name: Get SetDll Latest Release 55 | id: setdll 56 | run: | 57 | RELEASE_INFO=$(gh api repos/Bush2021/setdll/releases/latest) 58 | DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[0].browser_download_url') 59 | echo "download_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT 60 | env: 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | 63 | - name: Download Build Artifacts 64 | uses: actions/download-artifact@v4 65 | with: 66 | path: build_artifacts 67 | github-token: ${{ secrets.GITHUB_TOKEN }} 68 | run-id: ${{ steps.workflow.outputs.run_id }} 69 | 70 | - name: Package All Artifacts 71 | run: | 72 | mkdir -p artifacts/x86/{App,Data,Cache} 73 | mkdir -p artifacts/x64/{App,Data,Cache} 74 | mkdir -p artifacts/arm64/{App,Data,Cache} 75 | cp -r build_artifacts/version-x86-${{ env.VERSION }}/* artifacts/x86/App/ 76 | cp -r build_artifacts/version-x64-${{ env.VERSION }}/* artifacts/x64/App/ 77 | cp -r build_artifacts/version-arm64-${{ env.VERSION }}/* artifacts/arm64/App/ 78 | cp src/chrome++.ini artifacts/x86/App/ 79 | cp src/chrome++.ini artifacts/x64/App/ 80 | cp src/chrome++.ini artifacts/arm64/App/ 81 | cd artifacts 82 | 7z a -mx=9 -m0=lzma2 -mmt=on ../Chrome++_v${{ env.VERSION }}_x86_x64_arm64.7z * 83 | cd .. 84 | 85 | - name: Package SetDll 86 | run: | 87 | mkdir -p setdll_package_contents 88 | wget -O setdll_latest.7z ${{ steps.setdll.outputs.download_url }} 89 | 7z x setdll_latest.7z -o./setdll_package_contents 90 | rm setdll_latest.7z 91 | cp ./build_artifacts/version-x86-${{ env.VERSION }}/version.dll ./setdll_package_contents/version-x86.dll 92 | cp ./build_artifacts/version-x64-${{ env.VERSION }}/version.dll ./setdll_package_contents/version-x64.dll 93 | cp ./build_artifacts/version-arm64-${{ env.VERSION }}/version.dll ./setdll_package_contents/version-arm64.dll 94 | cp ./src/chrome++.ini ./setdll_package_contents/chrome++.ini 95 | cd setdll_package_contents 96 | echo "Contents of 'setdll_package_contents' directory before zipping:" 97 | ls -Al 98 | 7z a -mx=9 -ms=on -m0=lzma2 -mmt=on ../setdll.7z * 99 | cd .. 100 | 101 | - name: Create Release 102 | uses: softprops/action-gh-release@v2 103 | with: 104 | files: | 105 | Chrome++_v${{ env.VERSION }}_x86_x64_arm64.7z 106 | setdll.7z 107 | body_path: release.md 108 | tag_name: ${{ env.VERSION }} 109 | name: ${{ env.VERSION }} 110 | env: 111 | GITHUB_TOKEN: ${{ secrets.TOKEN }} 112 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .xmake/ 2 | build/ 3 | .vscode/ 4 | .idea/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "mini_gzip"] 2 | path = mini_gzip 3 | url = https://github.com/Bush2021/mini_gzip 4 | [submodule "detours"] 5 | path = detours 6 | url = https://github.com/microsoft/Detours 7 | [submodule "setdll"] 8 | path = setdll 9 | url = https://github.com/Bush2021/setdll 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chrome++ 2 | [![LICENSE](https://img.shields.io/badge/License-GPL--3.0--only-blue.svg?style=for-the-badge&logo=github "LICENSE")](https://github.com/Bush2021/chrome_plus/blob/main/LICENSE) [![LAST COMMIT](https://img.shields.io/github/last-commit/Bush2021/chrome_plus?color=blue&logo=github&style=for-the-badge "LAST COMMIT")](https://github.com/Bush2021/chrome_plus/commits/main) [![STARS](https://img.shields.io/github/stars/Bush2021/chrome_plus?color=brightgreen&logo=github&style=for-the-badge "STARS")](https://github.com/Bush2021/chrome_plus/stargazers) ![SIZES](https://img.shields.io/github/languages/code-size/Bush2021/chrome_plus?color=brightgreen&logo=github&style=for-the-badge "SIZES") 3 | 4 | 中文说明: https://github.com/Bush2021/chrome_plus/blob/main/README_CN.md 5 | 6 | ## Features 7 | * Double-click to close tab. 8 | * Right-click to close tab (hold Shift to show the original menu). 9 | * Preserve the last tab (prevent the browser from closing when the last tab is closed; clicking the close button will not work). 10 | * Use the mouse wheel to switch tabs when hovering over the tab bar. 11 | * Use the mouse wheel to switch tabs when holding the right mouse button. 12 | * Create new tab to opens the contents entered in address bar (can be configured to open in foreground or background). 13 | * Create new tab to opens bookmarks (can be configured to open in foreground or background). 14 | * Disable the above two features when the current tab is a new tab. 15 | * Customize hotkeys to quickly hide the browser window (boss key). 16 | * Customize hotkeys to translate web page. 17 | * Portable design (incompatible with the original data; you can reinstall the system or change computers without losing data). 18 | * Allow custom Chromium command line switches. 19 | * For more features, see [INI configuration file](https://github.com/Bush2021/chrome_plus/blob/main/src/chrome%2B%2B.ini). 20 | 21 | ## Download 22 | Built and released automatically using GitHub Actions. Download link: https://github.com/Bush2021/chrome_plus/releases/. 23 | 24 | ## Installation 25 | Please make sure to put `version.dll` in the same directory as `chrome.exe`. It's recommended to download the [Chrome offline installer package](https://github.com/Bush2021/chrome_installer), extract it twice to get the Chrome program files, and then place them in the [App](https://github.com/Bush2021/chrome_plus/releases/latest) folder. 26 | 27 | ## Compatibility 28 | * All browsers based on the latest stable branches of Chromium are theoretically supported. 29 | * Only the latest stable version of Chrome is tested, and maintenance is not guaranteed. 30 | * If the DLL is not properly loaded, try to [set DLL](https://github.com/Bush2021/setdll/). 31 | 32 | ## License 33 | * Versions 1.5.4 and earlier are licensed under MIT license, with all rights reserved by [Shuax](https://github.com/shuax/). 34 | * Version 1.5.5 - 1.5.9 are licensed under MIT license, with modifications made by contributors to this repository based on Shuax's version. 35 | * Versions 1.6.0 and later are licensed under GPL-3.0 license. 36 | 37 | ## Thanks 38 | * Original Author [Shuax](https://github.com/shuax/) 39 | * Revision code [provider](https://forum.ru-board.com/topic.cgi?forum=5&topic=51073&start=620&limit=1&m=1#1) for version 1.5.5 40 | * [虫子樱桃](https://github.com/czyt/) 41 | * [York Waugh](https://github.com/YorkWaugh/) 42 | * [面向大海](https://github.com/mxdh/) 43 | * [Ho Cheung](https://github.com/gz83/) 44 | * [Ritchie1108](https://github.com/Ritchie1108/) -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # Chrome++ 2 | [![LICENSE](https://img.shields.io/badge/License-GPL--3.0--only-blue.svg?style=for-the-badge&logo=github "LICENSE")](https://github.com/Bush2021/chrome_plus/blob/main/LICENSE) [![LAST COMMIT](https://img.shields.io/github/last-commit/Bush2021/chrome_plus?color=blue&logo=github&style=for-the-badge "LAST COMMIT")](https://github.com/Bush2021/chrome_plus/commits/main) [![STARS](https://img.shields.io/github/stars/Bush2021/chrome_plus?color=brightgreen&logo=github&style=for-the-badge "STARS")](https://github.com/Bush2021/chrome_plus/stargazers) ![SIZES](https://img.shields.io/github/languages/code-size/Bush2021/chrome_plus?color=brightgreen&logo=github&style=for-the-badge "SIZES") 3 | 4 | English instruction: [https://github.com/Bush2021/chrome_plus/blob/main/README.md](https://github.com/Bush2021/chrome_plus/blob/main/README.md) 5 | 6 | ## 功能 7 | - 双击关闭标签页。 8 | - 右键关闭标签页(按住 Shift 弹出原有菜单)。 9 | - 保留最后标签页(防止关闭最后一个标签页时关闭浏览器,点关闭按钮不行)。 10 | - 鼠标悬停标签栏时使用滚轮切换标签页。 11 | - 按住右键时使用滚轮切换标签页。 12 | - 新建标签页打开地址栏输入的内容(可配置前台或后台打开)。 13 | - 新建标签页打开书签(可配置前台或后台打开)。 14 | - 当前为新标签页时,可以禁用上面两个功能。 15 | - 自定义快捷键快速隐藏浏览器窗口(老板键)。 16 | - 自定义快捷键进行网页翻译。 17 | - 便携化(不兼容原版数据,可以重装系统换电脑不丢数据)。 18 | - 可以自定义 Chromium 命令行开关。 19 | - 更多功能参见 [INI 配置文件](https://github.com/Bush2021/chrome_plus/blob/main/src/chrome%2B%2B.ini)。 20 | 21 | ## 获取 22 | 采用 GitHub Actions 自动编译发布,下载地址:[https://github.com/Bush2021/chrome_plus/releases](https://github.com/Bush2021/chrome_plus/releases)。 23 | 24 | ## 安装 25 | 请确保将 `version.dll` 放入 `chrome.exe` 同一目录。建议下载 [Chrome 离线安装包](https://github.com/Bush2021/chrome_installer),解压两次得到 Chrome 程序文件,将其放入 [App](https://github.com/Bush2021/chrome_plus/releases/latest) 文件夹即可。 26 | 27 | ## 兼容性 28 | * 理论上支持所有基于 Chromium 最新稳定分支的浏览器。 29 | * 只可能针对 Chrome 最新稳定版进行测试,不保证维护。 30 | * 如果遇到 DLL 未正确加载的问题,可尝试 [强制注入 DLL](https://github.com/Bush2021/setdll/)。 31 | 32 | ## 许可证 33 | * 1.5.4 及以前的版本使用 MIT 许可证,版权所有者为 [Shuax](https://github.com/shuax/)。 34 | * 1.5.5 - 1.5.9 版本使用 MIT 许可证,由本仓库贡献者在 Shuax 版本上进行修改。 35 | * 1.6.0 以后的版本使用 GPL-3.0 许可证。 36 | 37 | ## 致谢 38 | * 原作者 [Shuax](https://github.com/shuax/) 39 | * 1.5.5 修改代码[提供者](https://forum.ru-board.com/topic.cgi?forum=5&topic=51073&start=620&limit=1&m=1#1) 40 | * [虫子樱桃](https://github.com/czyt/) 41 | * [York Waugh](https://github.com/YorkWaugh/) 42 | * [面向大海](https://github.com/mxdh/) 43 | * [Ho Cheung](https://github.com/gz83/) 44 | * [Ritchie1108](https://github.com/Ritchie1108/) -------------------------------------------------------------------------------- /VC-LTL5.lua: -------------------------------------------------------------------------------- 1 | target("VC-LTL-5") 2 | set_kind("phony") 3 | before_build("windows", function (target) 4 | local function find_in_file() 5 | for _, dir in ipairs(os.dirs("$(projectdir)/*")) do 6 | name = dir:match(".*\\(.*)") 7 | if name:find("VC%-LTL") then 8 | return dir .. [[\build\native\]] 9 | end 10 | end 11 | end 12 | local function find_in_reg() 13 | return vformat("$(reg HKEY_CURRENT_USER\\Code\\VC-LTL;Root)") 14 | end 15 | local VC_LTL_Root = find_in_file() or find_in_reg() 16 | if #VC_LTL_Root==0 then 17 | return 18 | end 19 | local WindowsTargetPlatformMinVersion = "6.0.6000.0" 20 | cprint("${color.warning}VC-LTL Path : %s", VC_LTL_Root) 21 | cprint("${color.warning}WindowsTargetPlatformMinVersion : %s", WindowsTargetPlatformMinVersion) 22 | import("core.tool.toolchain") 23 | local msvc = toolchain.load("msvc") 24 | local runenvs = msvc:runenvs() 25 | 26 | local includepath = VC_LTL_Root .. [[TargetPlatform\header;]] .. VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\header;]] 27 | 28 | runenvs.INCLUDE = includepath .. runenvs.INCLUDE 29 | 30 | local arch = target:arch() 31 | local archpath = "Win32" 32 | if arch ~= "x86" then 33 | archpath = arch 34 | end 35 | cprint("${color.warning}Platform : %s", archpath) 36 | local libpath = VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\lib\]] .. archpath .. ";" 37 | 38 | runenvs.LIB = libpath .. runenvs.LIB 39 | 40 | -- print(runenvs.INCLUDE) 41 | -- print(runenvs.LIB) 42 | end) -------------------------------------------------------------------------------- /src/appid.h: -------------------------------------------------------------------------------- 1 | #ifndef APPID_H_ 2 | #define APPID_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | auto RawPSStringFromPropertyKey = PSStringFromPropertyKey; 9 | 10 | HRESULT WINAPI MyPSStringFromPropertyKey(REFPROPERTYKEY pkey, 11 | LPWSTR psz, 12 | UINT cch) { 13 | HRESULT result = RawPSStringFromPropertyKey(pkey, psz, cch); 14 | if (SUCCEEDED(result)) { 15 | if (pkey == PKEY_AppUserModel_ID) { 16 | // DebugLog(L"MyPSStringFromPropertyKey %s", psz); 17 | return -1; 18 | } 19 | } 20 | return result; 21 | } 22 | 23 | void SetAppId() { 24 | DetourTransactionBegin(); 25 | DetourUpdateThread(GetCurrentThread()); 26 | DetourAttach((LPVOID*)&RawPSStringFromPropertyKey, MyPSStringFromPropertyKey); 27 | auto status = DetourTransactionCommit(); 28 | if (status != NO_ERROR) { 29 | DebugLog(L"SetAppId failed %d", status); 30 | } 31 | } 32 | 33 | #endif // APPID_H_ 34 | -------------------------------------------------------------------------------- /src/chrome++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | HMODULE hInstance; 6 | 7 | #define MAGIC_CODE 0x1603ABD9 8 | 9 | #include "detours.h" 10 | #include "version.h" 11 | 12 | #include "hijack.h" 13 | #include "utils.h" 14 | #include "patch.h" 15 | #include "config.h" 16 | #include "tabbookmark.h" 17 | #include "hotkey.h" 18 | #include "portable.h" 19 | #include "pakpatch.h" 20 | #include "appid.h" 21 | #include "green.h" 22 | 23 | typedef int (*Startup)(); 24 | Startup ExeMain = nullptr; 25 | 26 | void ChromePlus() { 27 | // Shortcut. 28 | SetAppId(); 29 | 30 | // Portable hajack patch. 31 | MakeGreen(); 32 | 33 | // Enhancement of the address bar, tab, and bookmark. 34 | TabBookmark(); 35 | 36 | // Patch the pak file. 37 | PakPatch(); 38 | 39 | // Process the hotkey. 40 | GetHotkey(); 41 | } 42 | 43 | void ChromePlusCommand(LPWSTR param) { 44 | if (!wcsstr(param, L"--portable")) { 45 | Portable(param); 46 | } else { 47 | ChromePlus(); 48 | } 49 | } 50 | 51 | int Loader() { 52 | // Hard patch. 53 | // MakePatch(); 54 | 55 | // Only main interface. 56 | LPWSTR param = GetCommandLineW(); 57 | // DebugLog(L"param %s", param); 58 | if (!wcsstr(param, L"-type=")) { 59 | ChromePlusCommand(param); 60 | } 61 | 62 | // Return to the main function. 63 | return ExeMain(); 64 | } 65 | 66 | void InstallLoader() { 67 | // Get the address of the original entry point of the main module. 68 | MODULEINFO mi; 69 | GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &mi, 70 | sizeof(MODULEINFO)); 71 | ExeMain = (Startup)mi.EntryPoint; 72 | 73 | DetourTransactionBegin(); 74 | DetourUpdateThread(GetCurrentThread()); 75 | DetourAttach((LPVOID*)&ExeMain, Loader); 76 | auto status = DetourTransactionCommit(); 77 | if (status != NO_ERROR) { 78 | DebugLog(L"InstallLoader failed: %d", status); 79 | } 80 | } 81 | 82 | __declspec(dllexport) void portable() {} 83 | 84 | BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) { 85 | if (dwReason == DLL_PROCESS_ATTACH) { 86 | DisableThreadLibraryCalls(hModule); 87 | hInstance = hModule; 88 | 89 | // Maintain the original function of system DLLs. 90 | LoadSysDll(hModule); 91 | 92 | InstallLoader(); 93 | } 94 | return TRUE; 95 | } 96 | -------------------------------------------------------------------------------- /src/chrome++.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bush2021/chrome_plus/d030198684e285a7fb5f83a77d3aca8d421a77ec/src/chrome++.ini -------------------------------------------------------------------------------- /src/chrome++.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bush2021/chrome_plus/d030198684e285a7fb5f83a77d3aca8d421a77ec/src/chrome++.rc -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H_ 2 | #define CONFIG_H_ 3 | 4 | std::wstring GetCrCommandLine() { 5 | auto commandLine = GetIniString(L"general", L"command_line", L""); 6 | if (!commandLine.empty()) { 7 | return commandLine; 8 | } 9 | return GetIniString(L"General", L"CommandLine", L""); // Deprecated 10 | } 11 | std::wstring GetLaunchOnStartup() { 12 | return GetIniString(L"general", L"launch_on_startup", L""); 13 | } 14 | 15 | bool IsKillLaunchOnExit() { 16 | return ::GetPrivateProfileIntW(L"general", L"kill_launch_on_exit", 0, 17 | kIniPath.c_str()) != 0; 18 | } 19 | 20 | std::wstring GetLaunchOnExit() { 21 | return GetIniString(L"general", L"launch_on_exit", L""); 22 | } 23 | 24 | std::wstring GetDirPath(const std::wstring& dir_type) { 25 | std::wstring path = CanonicalizePath(GetAppDir() + L"\\..\\" + dir_type); 26 | std::wstring dir_key = dir_type + L"_dir"; 27 | std::wstring dir_buffer = GetIniString(L"general", dir_key, path); 28 | 29 | if (dir_buffer == L"none") { 30 | return L""; 31 | } 32 | 33 | if (dir_buffer.empty()) { // Deprecated 34 | dir_key = dir_type + L"dir"; 35 | dir_buffer = GetIniString(L"general", dir_key, path); 36 | } 37 | 38 | if (dir_buffer.empty()) { 39 | dir_buffer = path; 40 | } 41 | 42 | std::wstring expanded_path = ExpandEnvironmentPath(dir_buffer); 43 | ReplaceStringInPlace(expanded_path, L"%app%", GetAppDir()); 44 | std::wstring dir = GetAbsolutePath(expanded_path); 45 | return dir; 46 | } 47 | 48 | std::wstring GetUserDataDir() { 49 | return GetDirPath(L"data"); 50 | } 51 | 52 | std::wstring GetDiskCacheDir() { 53 | return GetDirPath(L"cache"); 54 | } 55 | 56 | std::wstring GetBosskey() { 57 | auto key = GetIniString(L"general", L"boss_key", L""); 58 | if (!key.empty()) { 59 | return key; 60 | } 61 | return GetIniString(L"General", L"Bosskey", L""); // Deprecated 62 | } 63 | 64 | std::wstring GetTranslateKey() { 65 | auto key = GetIniString(L"general", L"translate_key", L""); 66 | if (!key.empty()) { 67 | return key; 68 | } 69 | return GetIniString(L"General", L"TranslateKey", L""); // Deprecated 70 | } 71 | 72 | // View password without verification 73 | bool IsShowPassword() { 74 | return ::GetPrivateProfileIntW(L"general", L"show_password", 1, 75 | kIniPath.c_str()) != 0; 76 | } 77 | 78 | // Force enable win32k 79 | bool IsWin32K() { 80 | return ::GetPrivateProfileIntW(L"general", L"win32k", 0, kIniPath.c_str()) != 81 | 0; 82 | } 83 | 84 | bool IsKeepLastTab() { 85 | return ::GetPrivateProfileIntW(L"tabs", L"keep_last_tab", 1, 86 | kIniPath.c_str()) != 0; 87 | } 88 | 89 | bool IsDoubleClickClose() { 90 | return ::GetPrivateProfileIntW(L"tabs", L"double_click_close", 1, 91 | kIniPath.c_str()) != 0; 92 | } 93 | 94 | bool IsRightClickClose() { 95 | return ::GetPrivateProfileIntW(L"tabs", L"right_click_close", 0, 96 | kIniPath.c_str()) != 0; 97 | } 98 | 99 | bool IsWheelTab() { 100 | return ::GetPrivateProfileIntW(L"tabs", L"wheel_tab", 1, kIniPath.c_str()) != 101 | 0; 102 | } 103 | 104 | bool IsWheelTabWhenPressRightButton() { 105 | return ::GetPrivateProfileIntW(L"tabs", L"wheel_tab_when_press_rbutton", 1, 106 | kIniPath.c_str()) != 0; 107 | } 108 | 109 | std::string IsOpenUrlNewTabFun() { 110 | int value = ::GetPrivateProfileIntW(L"tabs", L"open_url_new_tab", 0, 111 | kIniPath.c_str()); 112 | switch (value) { 113 | case 1: 114 | return "foreground"; 115 | case 2: 116 | return "background"; 117 | default: 118 | return "disabled"; 119 | } 120 | } 121 | 122 | std::string IsBookmarkNewTab() { 123 | int value = ::GetPrivateProfileIntW(L"tabs", L"open_bookmark_new_tab", 0, 124 | kIniPath.c_str()); 125 | switch (value) { 126 | case 1: 127 | return "foreground"; 128 | case 2: 129 | return "background"; 130 | default: 131 | return "disabled"; 132 | } 133 | } 134 | 135 | bool IsNewTabDisable() { 136 | return ::GetPrivateProfileIntW(L"tabs", L"new_tab_disable", 1, 137 | kIniPath.c_str()) != 0; 138 | } 139 | 140 | // Customize disabled tab page name 141 | std::wstring GetDisableTabName() { 142 | return GetIniString(L"tabs", L"new_tab_disable_name", L""); 143 | } 144 | 145 | #endif // CONFIG_H_ 146 | -------------------------------------------------------------------------------- /src/fastsearch.h: -------------------------------------------------------------------------------- 1 | #ifndef FASTSEARCH_H_ 2 | #define FASTSEARCH_H_ 3 | 4 | #include 5 | 6 | static const uint8_t* ForceSearch(const uint8_t* s, int n, const uint8_t* p) { 7 | int i; 8 | for (i = 0; i < n; ++i) { 9 | if (*(s + i) == *p) { 10 | return s + i; 11 | } 12 | } 13 | 14 | return nullptr; 15 | } 16 | 17 | static const uint8_t* SundaySearch(const uint8_t* s, 18 | int n, 19 | const uint8_t* p, 20 | int m) { 21 | int i, j; 22 | 23 | size_t skip[256]; 24 | 25 | for (i = 0; i < 256; ++i) { 26 | skip[i] = m + 1; 27 | } 28 | 29 | for (i = 0; i < m; ++i) { 30 | skip[p[i]] = m - i; 31 | } 32 | 33 | i = 0; 34 | while (i <= n - m) { 35 | j = 0; 36 | while (s[i + j] == p[j]) { 37 | ++j; 38 | if (j >= m) { 39 | return s + i; 40 | } 41 | } 42 | 43 | i += (int)skip[s[i + m]]; 44 | } 45 | 46 | return nullptr; 47 | } 48 | 49 | const uint8_t* FastSearch(const uint8_t* s, int n, const uint8_t* p, int m) { 50 | if (!s || !p || n < m) 51 | return nullptr; 52 | 53 | if (m == 0) { 54 | return s; 55 | } else if (m == 1) { 56 | return ForceSearch(s, n, p); 57 | } 58 | 59 | return SundaySearch(s, n, p, m); 60 | } 61 | 62 | #endif // FASTSEARCH_H_ 63 | -------------------------------------------------------------------------------- /src/green.h: -------------------------------------------------------------------------------- 1 | #ifndef GREEN_H_ 2 | #define GREEN_H_ 3 | 4 | #include 5 | 6 | auto RawUpdateProcThreadAttribute = UpdateProcThreadAttribute; 7 | auto RawCryptUnprotectData = CryptUnprotectData; 8 | auto RawLogonUserW = LogonUserW; 9 | auto RawIsOS = IsOS; 10 | auto RawNetUserGetInfo = NetUserGetInfo; 11 | auto RawGetVolumeInformationW = GetVolumeInformationW; 12 | 13 | BOOL WINAPI FakeGetComputerName(_Out_ LPTSTR lpBuffer, 14 | _Inout_ LPDWORD lpnSize) { 15 | return false; 16 | } 17 | 18 | // This function checks if the lpVolumeSerialNumber parameter is provided. 19 | // If lpVolumeSerialNumber is not null, the function returns false. This 20 | // behavior is implemented for portability reasons, as seen in the following 21 | // reference: 22 | // https://source.chromium.org/chromium/chromium/src/+/main:rlz/win/lib/machine_id_win.cc;l=41;drc=3dd5eb19b88fb0246061e21fc6098830bead0edb 23 | // 24 | // If lpVolumeSerialNumber is null, the function calls RawGetVolumeInformationW 25 | // and returns its result. This is necessary because other parts of the codebase 26 | // may require the actual volume information, such as the 27 | // lpMaximumComponentLength parameter, as seen in the following reference: 28 | // https://source.chromium.org/chromium/chromium/src/+/main:base/files/file_util_win.cc;drc=5b01e9f5bff328ba66e415103ca50ae940328fde;l=1071 29 | // 30 | // Returns: 31 | // - FALSE if lpVolumeSerialNumber is not null. 32 | // - The result of RawGetVolumeInformationW otherwise. 33 | BOOL WINAPI FakeGetVolumeInformation(_In_opt_ LPCTSTR lpRootPathName, 34 | _Out_opt_ LPTSTR lpVolumeNameBuffer, 35 | _In_ DWORD nVolumeNameSize, 36 | _Out_opt_ LPDWORD lpVolumeSerialNumber, 37 | _Out_opt_ LPDWORD lpMaximumComponentLength, 38 | _Out_opt_ LPDWORD lpFileSystemFlags, 39 | _Out_opt_ LPTSTR lpFileSystemNameBuffer, 40 | _In_ DWORD nFileSystemNameSize) { 41 | if (lpVolumeSerialNumber != nullptr) { 42 | return false; 43 | } else { 44 | return RawGetVolumeInformationW( 45 | lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, 46 | lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, 47 | lpFileSystemNameBuffer, nFileSystemNameSize); 48 | } 49 | } 50 | 51 | enum ProcessCreationMitigationPolicy : DWORD64 { 52 | BlockNonMicrosoftBinariesAlwaysOn = 0x00000001ui64 << 44, 53 | Win32kSystemCallDisableAlwaysOn = 0x00000001ui64 << 28 54 | }; 55 | 56 | BOOL WINAPI MyUpdateProcThreadAttribute( 57 | __inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, 58 | __in DWORD dwFlags, 59 | __in DWORD_PTR Attribute, 60 | __in_bcount_opt(cbSize) PVOID lpValue, 61 | __in SIZE_T cbSize, 62 | __out_bcount_opt(cbSize) PVOID lpPreviousValue, 63 | __in_opt PSIZE_T lpReturnSize) { 64 | if (Attribute == PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY && 65 | cbSize >= sizeof(DWORD64)) { 66 | // https://source.chromium.org/chromium/chromium/src/+/main:sandbox/win/src/process_mitigations.cc;l=362;drc=4c2fec5f6699ffeefd93137d2bf8c03504c6664c 67 | PDWORD64 policy_value_1 = &((PDWORD64)lpValue)[0]; 68 | *policy_value_1 &= ~static_cast( 69 | ProcessCreationMitigationPolicy::BlockNonMicrosoftBinariesAlwaysOn); 70 | if (IsWin32K()) { 71 | *policy_value_1 &= static_cast( 72 | ProcessCreationMitigationPolicy::Win32kSystemCallDisableAlwaysOn); 73 | } 74 | } 75 | return RawUpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, 76 | lpValue, cbSize, lpPreviousValue, 77 | lpReturnSize); 78 | } 79 | 80 | BOOL WINAPI 81 | MyCryptProtectData(_In_ DATA_BLOB* pDataIn, 82 | _In_opt_ LPCWSTR szDataDescr, 83 | _In_opt_ DATA_BLOB* pOptionalEntropy, 84 | _Reserved_ PVOID pvReserved, 85 | _In_opt_ CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, 86 | _In_ DWORD dwFlags, 87 | _Out_ DATA_BLOB* pDataOut) { 88 | pDataOut->cbData = pDataIn->cbData; 89 | pDataOut->pbData = (BYTE*)LocalAlloc(LMEM_FIXED, pDataOut->cbData); 90 | memcpy(pDataOut->pbData, pDataIn->pbData, pDataOut->cbData); 91 | return true; 92 | } 93 | 94 | BOOL WINAPI 95 | MyCryptUnprotectData(_In_ DATA_BLOB* pDataIn, 96 | _Out_opt_ LPWSTR* ppszDataDescr, 97 | _In_opt_ DATA_BLOB* pOptionalEntropy, 98 | _Reserved_ PVOID pvReserved, 99 | _In_opt_ CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, 100 | _In_ DWORD dwFlags, 101 | _Out_ DATA_BLOB* pDataOut) { 102 | if (RawCryptUnprotectData(pDataIn, ppszDataDescr, pOptionalEntropy, 103 | pvReserved, pPromptStruct, dwFlags, pDataOut)) { 104 | return true; 105 | } 106 | 107 | pDataOut->cbData = pDataIn->cbData; 108 | pDataOut->pbData = (BYTE*)LocalAlloc(LMEM_FIXED, pDataOut->cbData); 109 | memcpy(pDataOut->pbData, pDataIn->pbData, pDataOut->cbData); 110 | return true; 111 | } 112 | 113 | DWORD WINAPI MyLogonUserW(LPCWSTR lpszUsername, 114 | LPCWSTR lpszDomain, 115 | LPCWSTR lpszPassword, 116 | DWORD dwLogonType, 117 | DWORD dwLogonProvider, 118 | PHANDLE phToken) { 119 | DWORD ret = RawLogonUserW(lpszUsername, lpszDomain, lpszPassword, dwLogonType, 120 | dwLogonProvider, phToken); 121 | 122 | SetLastError(ERROR_ACCOUNT_RESTRICTION); 123 | return ret; 124 | } 125 | 126 | BOOL WINAPI MyIsOS(DWORD dwOS) { 127 | DWORD ret = RawIsOS(dwOS); 128 | if (dwOS == OS_DOMAINMEMBER) { 129 | return false; 130 | } 131 | 132 | return ret; 133 | } 134 | 135 | NET_API_STATUS WINAPI MyNetUserGetInfo(LPCWSTR servername, 136 | LPCWSTR username, 137 | DWORD level, 138 | LPBYTE* bufptr) { 139 | NET_API_STATUS ret = RawNetUserGetInfo(servername, username, level, bufptr); 140 | if (level == 1 && ret == 0) { 141 | LPUSER_INFO_1 user_info = (LPUSER_INFO_1)*bufptr; 142 | user_info->usri1_password_age = 0; 143 | } 144 | 145 | return ret; 146 | } 147 | 148 | void MakeGreen() { 149 | auto RawGetComputerNameW = GetComputerNameW; 150 | auto RawCryptProtectData = CryptProtectData; 151 | 152 | DetourTransactionBegin(); 153 | DetourUpdateThread(GetCurrentThread()); 154 | 155 | // kernel32.dll 156 | DetourAttach((LPVOID*)&RawGetComputerNameW, FakeGetComputerName); 157 | DetourAttach((LPVOID*)&RawGetVolumeInformationW, FakeGetVolumeInformation); 158 | DetourAttach((LPVOID*)&RawUpdateProcThreadAttribute, 159 | MyUpdateProcThreadAttribute); 160 | 161 | // components/os_crypt/os_crypt_win.cc 162 | // crypt32.dll 163 | DetourAttach((LPVOID*)&RawCryptProtectData, MyCryptProtectData); 164 | DetourAttach((LPVOID*)&RawCryptUnprotectData, MyCryptUnprotectData); 165 | 166 | if (IsShowPassword()) { 167 | // advapi32.dll 168 | DetourAttach((LPVOID*)&RawLogonUserW, MyLogonUserW); 169 | 170 | // shlwapi.dll 171 | DetourAttach((LPVOID*)&RawIsOS, MyIsOS); 172 | 173 | // netapi32.dll 174 | DetourAttach((LPVOID*)&RawNetUserGetInfo, MyNetUserGetInfo); 175 | } 176 | 177 | auto status = DetourTransactionCommit(); 178 | if (status != NO_ERROR) { 179 | DebugLog(L"MakeGreen failed: %d", status); 180 | } 181 | } 182 | 183 | #endif // GREEN_H_ 184 | -------------------------------------------------------------------------------- /src/hijack.h: -------------------------------------------------------------------------------- 1 | #ifndef HIJACK_H_ 2 | #define HIJACK_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace hijack { 9 | 10 | #define NOP_FUNC \ 11 | { \ 12 | __nop(); \ 13 | __nop(); \ 14 | __nop(); \ 15 | __nop(); \ 16 | __nop(); \ 17 | __nop(); \ 18 | __nop(); \ 19 | __nop(); \ 20 | __nop(); \ 21 | __nop(); \ 22 | __nop(); \ 23 | __nop(); \ 24 | return __COUNTER__; \ 25 | } 26 | // Use __COUNTER__ to generate slightly different code to avoid 27 | // being automatically merged with the same functions by VS. 28 | 29 | #define EXPORT(api) int __cdecl api() NOP_FUNC 30 | 31 | #pragma region Declare the exported functions 32 | // Declare the exported functions. 33 | #pragma comment( \ 34 | linker, \ 35 | "/export:GetFileVersionInfoA=?GetFileVersionInfoA@hijack@@YAHXZ,@1") 36 | #pragma comment( \ 37 | linker, \ 38 | "/export:GetFileVersionInfoByHandle=?GetFileVersionInfoByHandle@hijack@@YAHXZ,@2") 39 | #pragma comment( \ 40 | linker, \ 41 | "/export:GetFileVersionInfoExA=?GetFileVersionInfoExA@hijack@@YAHXZ,@3") 42 | #pragma comment( \ 43 | linker, \ 44 | "/export:GetFileVersionInfoExW=?GetFileVersionInfoExW@hijack@@YAHXZ,@4") 45 | #pragma comment( \ 46 | linker, \ 47 | "/export:GetFileVersionInfoSizeA=?GetFileVersionInfoSizeA@hijack@@YAHXZ,@5") 48 | #pragma comment( \ 49 | linker, \ 50 | "/export:GetFileVersionInfoSizeExA=?GetFileVersionInfoSizeExA@hijack@@YAHXZ,@6") 51 | #pragma comment( \ 52 | linker, \ 53 | "/export:GetFileVersionInfoSizeExW=?GetFileVersionInfoSizeExW@hijack@@YAHXZ,@7") 54 | #pragma comment( \ 55 | linker, \ 56 | "/export:GetFileVersionInfoSizeW=?GetFileVersionInfoSizeW@hijack@@YAHXZ,@8") 57 | #pragma comment( \ 58 | linker, \ 59 | "/export:GetFileVersionInfoW=?GetFileVersionInfoW@hijack@@YAHXZ,@9") 60 | #pragma comment(linker, "/export:VerFindFileA=?VerFindFileA@hijack@@YAHXZ,@10") 61 | #pragma comment(linker, "/export:VerFindFileW=?VerFindFileW@hijack@@YAHXZ,@11") 62 | #pragma comment(linker, \ 63 | "/export:VerInstallFileA=?VerInstallFileA@hijack@@YAHXZ,@12") 64 | #pragma comment(linker, \ 65 | "/export:VerInstallFileW=?VerInstallFileW@hijack@@YAHXZ,@13") 66 | #pragma comment( \ 67 | linker, "/export:VerLanguageNameA=?VerLanguageNameA@hijack@@YAHXZ,@14") 68 | #pragma comment( \ 69 | linker, "/export:VerLanguageNameW=?VerLanguageNameW@hijack@@YAHXZ,@15") 70 | #pragma comment(linker, \ 71 | "/export:VerQueryValueA=?VerQueryValueA@hijack@@YAHXZ,@16") 72 | #pragma comment(linker, \ 73 | "/export:VerQueryValueW=?VerQueryValueW@hijack@@YAHXZ,@17") 74 | 75 | EXPORT(GetFileVersionInfoA) 76 | EXPORT(GetFileVersionInfoByHandle) 77 | EXPORT(GetFileVersionInfoExA) 78 | EXPORT(GetFileVersionInfoExW) 79 | EXPORT(GetFileVersionInfoSizeA) 80 | EXPORT(GetFileVersionInfoSizeExA) 81 | EXPORT(GetFileVersionInfoSizeExW) 82 | EXPORT(GetFileVersionInfoSizeW) 83 | EXPORT(GetFileVersionInfoW) 84 | EXPORT(VerFindFileA) 85 | EXPORT(VerFindFileW) 86 | EXPORT(VerInstallFileA) 87 | EXPORT(VerInstallFileW) 88 | EXPORT(VerLanguageNameA) 89 | EXPORT(VerLanguageNameW) 90 | EXPORT(VerQueryValueA) 91 | EXPORT(VerQueryValueW) 92 | } // namespace hijack 93 | #pragma endregion 94 | 95 | void InstallDetours(PBYTE pTarget, PBYTE pDetour) { 96 | DetourTransactionBegin(); 97 | DetourUpdateThread(GetCurrentThread()); 98 | DetourAttach(&(PVOID&)pTarget, pDetour); 99 | DetourTransactionCommit(); 100 | } 101 | 102 | #pragma region Load system dll 103 | void LoadVersion(HINSTANCE hModule) { 104 | PBYTE pImageBase = (PBYTE)hModule; 105 | PIMAGE_DOS_HEADER pimDH = (PIMAGE_DOS_HEADER)pImageBase; 106 | if (pimDH->e_magic == IMAGE_DOS_SIGNATURE) { 107 | PIMAGE_NT_HEADERS pimNH = (PIMAGE_NT_HEADERS)(pImageBase + pimDH->e_lfanew); 108 | if (pimNH->Signature == IMAGE_NT_SIGNATURE) { 109 | PIMAGE_EXPORT_DIRECTORY pimExD = 110 | (PIMAGE_EXPORT_DIRECTORY)(pImageBase + 111 | pimNH->OptionalHeader 112 | .DataDirectory 113 | [IMAGE_DIRECTORY_ENTRY_EXPORT] 114 | .VirtualAddress); 115 | DWORD* pName = (DWORD*)(pImageBase + pimExD->AddressOfNames); 116 | DWORD* pFunction = (DWORD*)(pImageBase + pimExD->AddressOfFunctions); 117 | WORD* pNameOrdinals = (WORD*)(pImageBase + pimExD->AddressOfNameOrdinals); 118 | 119 | wchar_t szSysDirectory[MAX_PATH + 1]; 120 | GetSystemDirectory(szSysDirectory, MAX_PATH); 121 | 122 | wchar_t szDLLPath[MAX_PATH + 1]; 123 | lstrcpy(szDLLPath, szSysDirectory); 124 | lstrcat(szDLLPath, TEXT("\\version.dll")); 125 | 126 | HINSTANCE module = LoadLibrary(szDLLPath); 127 | for (size_t i = 0; i < pimExD->NumberOfNames; ++i) { 128 | PBYTE Original = 129 | (PBYTE)GetProcAddress(module, (char*)(pImageBase + pName[i])); 130 | if (Original) { 131 | InstallDetours(pImageBase + pFunction[pNameOrdinals[i]], Original); 132 | } 133 | } 134 | } 135 | } 136 | } 137 | #pragma endregion 138 | 139 | void LoadSysDll(HINSTANCE hModule) { 140 | LoadVersion(hModule); 141 | } 142 | 143 | #endif // HIJACK_H_ -------------------------------------------------------------------------------- /src/hotkey.h: -------------------------------------------------------------------------------- 1 | #ifndef HOTKEY_H_ 2 | #define HOTKEY_H_ 3 | 4 | #include 5 | 6 | UINT ParseHotkeys(const wchar_t* keys) { 7 | UINT mo = 0; 8 | UINT vk = 0; 9 | 10 | std::wstring temp = keys; 11 | std::vector key_parts = StringSplit(temp, L'+', L""); 12 | 13 | std::unordered_map keyMap = { 14 | {L"shift", MOD_SHIFT}, {L"ctrl", MOD_CONTROL}, {L"alt", MOD_ALT}, 15 | {L"win", MOD_WIN}, {L"left", VK_LEFT}, {L"right", VK_RIGHT}, 16 | {L"up", VK_UP}, {L"down", VK_DOWN}, {L"←", VK_LEFT}, 17 | {L"→", VK_RIGHT}, {L"↑", VK_UP}, {L"↓", VK_DOWN}, 18 | {L"esc", VK_ESCAPE}, {L"tab", VK_TAB}, {L"backspace", VK_BACK}, 19 | {L"enter", VK_RETURN}, {L"space", VK_SPACE}, {L"prtsc", VK_SNAPSHOT}, 20 | {L"scroll", VK_SCROLL}, {L"pause", VK_PAUSE}, {L"insert", VK_INSERT}, 21 | {L"delete", VK_DELETE}, {L"end", VK_END}, {L"home", VK_HOME}, 22 | {L"pageup", VK_PRIOR}, {L"pagedown", VK_NEXT}, 23 | }; 24 | 25 | for (auto& key : key_parts) { 26 | std::wstring lowerKey; 27 | std::transform(key.begin(), key.end(), std::back_inserter(lowerKey), 28 | ::tolower); 29 | 30 | if (keyMap.count(lowerKey)) { 31 | if (lowerKey == L"shift" || lowerKey == L"ctrl" || lowerKey == L"alt" || 32 | lowerKey == L"win") { 33 | mo |= keyMap[lowerKey]; 34 | } else { 35 | vk = keyMap[lowerKey]; 36 | } 37 | } else { 38 | TCHAR wch = key[0]; 39 | if (key.length() == 1) // Parse single characters A-Z, 0-9, etc. 40 | { 41 | if (isalnum(wch)) 42 | vk = toupper(wch); 43 | else 44 | vk = LOWORD(VkKeyScan(wch)); 45 | } else if (wch == 'F' || wch == 'f') // Parse the F1-F24 function keys. 46 | { 47 | if (isdigit(key[1])) { 48 | int FX = _wtoi(&key[1]); 49 | if (FX >= 1 && FX <= 24) 50 | vk = VK_F1 + FX - 1; 51 | } 52 | } 53 | } 54 | } 55 | 56 | #define MOD_NOREPEAT 0x4000 57 | mo |= MOD_NOREPEAT; 58 | 59 | return MAKELPARAM(mo, vk); 60 | } 61 | 62 | static bool is_hide = false; 63 | 64 | static std::vector hwnd_list; 65 | 66 | BOOL CALLBACK SearchChromeWindow(HWND hWnd, LPARAM lParam) { 67 | if (IsWindowVisible(hWnd)) { 68 | wchar_t buff[256]; 69 | GetClassNameW(hWnd, buff, 255); 70 | if (wcscmp(buff, L"Chrome_WidgetWin_1") == 71 | 0) // || wcscmp(buff, L"Chrome_WidgetWin_2")==0 || wcscmp(buff, 72 | // L"SysShadow")==0 ) 73 | { 74 | DWORD pid; 75 | GetWindowThreadProcessId(hWnd, &pid); 76 | if (pid == GetCurrentProcessId()) { 77 | ShowWindow(hWnd, SW_HIDE); 78 | hwnd_list.push_back(hWnd); 79 | } 80 | } 81 | } 82 | return true; 83 | } 84 | 85 | void HideAndShow() { 86 | if (!is_hide) { 87 | EnumWindows(SearchChromeWindow, 0); 88 | } else { 89 | for (auto r_iter = hwnd_list.rbegin(); r_iter != hwnd_list.rend(); 90 | ++r_iter) { 91 | ShowWindow(*r_iter, SW_SHOW); 92 | } 93 | hwnd_list.clear(); 94 | } 95 | is_hide = !is_hide; 96 | } 97 | 98 | void Translate() { 99 | ExecuteCommand(IDC_SHOW_TRANSLATE); 100 | keybd_event(VK_RIGHT, 0, 0, 0); 101 | keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0); 102 | } 103 | 104 | typedef void (*HotkeyAction)(); 105 | 106 | void OnHotkey(HotkeyAction action) { 107 | action(); 108 | } 109 | 110 | void Hotkey(const std::wstring& keys, HotkeyAction action) { 111 | if (keys.empty()) { 112 | return; 113 | } else { 114 | UINT flag = ParseHotkeys(keys.c_str()); 115 | 116 | std::thread th([flag, action]() { 117 | RegisterHotKey(nullptr, 0, LOWORD(flag), HIWORD(flag)); 118 | 119 | MSG msg; 120 | while (GetMessage(&msg, nullptr, 0, 0)) { 121 | if (msg.message == WM_HOTKEY) { 122 | OnHotkey(action); 123 | } 124 | TranslateMessage(&msg); 125 | DispatchMessage(&msg); 126 | } 127 | }); 128 | th.detach(); 129 | } 130 | } 131 | 132 | void GetHotkey() { 133 | std::wstring bossKey = GetBosskey(); 134 | if (!bossKey.empty()) { 135 | Hotkey(bossKey, HideAndShow); 136 | } 137 | 138 | std::wstring translateKey = GetTranslateKey(); 139 | if (!translateKey.empty()) { 140 | Hotkey(translateKey, Translate); 141 | } 142 | } 143 | 144 | #endif // HOTKEY_H_ 145 | -------------------------------------------------------------------------------- /src/iaccessible.h: -------------------------------------------------------------------------------- 1 | #ifndef IACCESSIBLE_H_ 2 | #define IACCESSIBLE_H_ 3 | 4 | #include 5 | #pragma comment(lib, "oleacc.lib") 6 | 7 | #include 8 | #include 9 | 10 | using NodePtr = Microsoft::WRL::ComPtr; 11 | 12 | template 13 | void GetAccessibleName(NodePtr node, Function f) { 14 | VARIANT self; 15 | self.vt = VT_I4; 16 | self.lVal = CHILDID_SELF; 17 | 18 | BSTR bstr = nullptr; 19 | if (S_OK == node->get_accName(self, &bstr)) { 20 | f(bstr); 21 | SysFreeString(bstr); 22 | } 23 | } 24 | 25 | template 26 | void GetAccessibleDescription(NodePtr node, Function f) { 27 | VARIANT self; 28 | self.vt = VT_I4; 29 | self.lVal = CHILDID_SELF; 30 | 31 | BSTR bstr = nullptr; 32 | if (S_OK == node->get_accDescription(self, &bstr)) { 33 | f(bstr); 34 | SysFreeString(bstr); 35 | } 36 | } 37 | 38 | template 39 | void GetAccessibleValue(NodePtr node, Function f) { 40 | VARIANT self; 41 | self.vt = VT_I4; 42 | self.lVal = CHILDID_SELF; 43 | 44 | BSTR bstr = nullptr; 45 | if (S_OK == node->get_accValue(self, &bstr)) { 46 | f(bstr); 47 | SysFreeString(bstr); 48 | } 49 | } 50 | 51 | template 52 | void GetAccessibleSize(NodePtr node, Function f) { 53 | VARIANT self; 54 | self.vt = VT_I4; 55 | self.lVal = CHILDID_SELF; 56 | 57 | RECT rect; 58 | if (S_OK == node->accLocation(&rect.left, &rect.top, &rect.right, 59 | &rect.bottom, self)) { 60 | auto [left, top, right, bottom] = rect; 61 | f({left, top, right + left, bottom + top}); 62 | } 63 | } 64 | 65 | long GetAccessibleRole(NodePtr node) { 66 | VARIANT self; 67 | self.vt = VT_I4; 68 | self.lVal = CHILDID_SELF; 69 | 70 | VARIANT role; 71 | if (S_OK == node->get_accRole(self, &role)) { 72 | if (role.vt == VT_I4) { 73 | return role.lVal; 74 | } 75 | } 76 | return 0; 77 | } 78 | 79 | long GetAccessibleState(NodePtr node) { 80 | VARIANT self; 81 | self.vt = VT_I4; 82 | self.lVal = CHILDID_SELF; 83 | 84 | VARIANT state; 85 | if (S_OK == node->get_accState(self, &state)) { 86 | if (state.vt == VT_I4) { 87 | return state.lVal; 88 | } 89 | } 90 | return 0; 91 | } 92 | 93 | template 94 | void TraversalAccessible(NodePtr node, Function f, bool raw_traversal = false) { 95 | if (!node) { 96 | return; 97 | } 98 | 99 | long child_count = 0; 100 | if (S_OK != node->get_accChildCount(&child_count) || child_count == 0) { 101 | return; 102 | } 103 | 104 | auto step = child_count < 20 ? child_count : 20; 105 | for (auto i = 0; i < child_count;) { 106 | auto arrChildren = std::make_unique(step); 107 | 108 | long get_count = 0; 109 | if (S_OK != AccessibleChildren(node.Get(), i, step, arrChildren.get(), 110 | &get_count)) { 111 | return; 112 | } 113 | 114 | bool is_task_completed = false; 115 | for (int j = 0; j < get_count; ++j) { 116 | if (arrChildren[j].vt != VT_DISPATCH) { 117 | continue; 118 | } 119 | 120 | if (is_task_completed) { 121 | arrChildren[j] 122 | .pdispVal->Release(); // Release immediately to avoid memory leaks. 123 | continue; 124 | } 125 | 126 | Microsoft::WRL::ComPtr dispatch_interface = 127 | arrChildren[j].pdispVal; 128 | NodePtr child_node = nullptr; 129 | if (S_OK != dispatch_interface->QueryInterface(IID_IAccessible, 130 | (void**)&child_node)) { 131 | continue; 132 | } 133 | 134 | if (raw_traversal) { 135 | TraversalAccessible(child_node, f, true); 136 | if (f(child_node)) { 137 | is_task_completed = true; 138 | } 139 | } else { 140 | if ((GetAccessibleState(child_node) & STATE_SYSTEM_INVISIBLE) == 0) { 141 | if (f(child_node)) { 142 | is_task_completed = true; 143 | } 144 | } 145 | } 146 | } 147 | 148 | if (is_task_completed) { 149 | return; 150 | } 151 | 152 | i += step; 153 | 154 | if (i + step >= child_count) { 155 | step = child_count - i; 156 | } 157 | } 158 | } 159 | 160 | NodePtr FindElementWithRole(NodePtr node, long role) { 161 | NodePtr element = nullptr; 162 | if (node) { 163 | TraversalAccessible(node, [&](NodePtr child) { 164 | if (auto childRole = GetAccessibleRole(child); childRole == role) { 165 | element = child; 166 | } else { 167 | element = FindElementWithRole(child, role); 168 | } 169 | return element != nullptr; 170 | }); 171 | } 172 | return element; 173 | } 174 | 175 | NodePtr FindPageTabList(NodePtr node) { 176 | NodePtr page_tab_list = nullptr; 177 | if (node) { 178 | TraversalAccessible(node, [&](NodePtr child) { 179 | if (auto role = GetAccessibleRole(child); 180 | role == ROLE_SYSTEM_PAGETABLIST) { 181 | page_tab_list = child; 182 | } else if (role == ROLE_SYSTEM_PANE || role == ROLE_SYSTEM_TOOLBAR) { 183 | // These two judgments must be retained, otherwise it will crash (#56) 184 | page_tab_list = FindPageTabList(child); 185 | } 186 | return page_tab_list; 187 | }); 188 | } 189 | return page_tab_list; 190 | } 191 | 192 | NodePtr GetParentElement(NodePtr child) { 193 | NodePtr element = nullptr; 194 | Microsoft::WRL::ComPtr dispatch = nullptr; 195 | if (S_OK == child->get_accParent(&dispatch) && dispatch) { 196 | NodePtr parent = nullptr; 197 | if (S_OK == dispatch->QueryInterface(IID_IAccessible, (void**)&parent)) { 198 | element = parent; 199 | } 200 | } 201 | return element; 202 | } 203 | 204 | NodePtr GetChromeWidgetWin(HWND hwnd) { 205 | NodePtr pacc_main_window = nullptr; 206 | wchar_t name[MAX_PATH]; 207 | if (GetClassName(hwnd, name, MAX_PATH) && 208 | wcsstr(name, L"Chrome_WidgetWin_") == name) { 209 | NodePtr pacc_main_window = nullptr; 210 | if (S_OK == AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, 211 | IID_PPV_ARGS(&pacc_main_window))) { 212 | return pacc_main_window; 213 | } 214 | } 215 | DebugLog(L"GetChromeWidgetWin failed"); 216 | return nullptr; 217 | } 218 | 219 | NodePtr GetTopContainerView(HWND hwnd) { 220 | NodePtr top_container_view = nullptr; 221 | NodePtr page_tab_list = FindPageTabList(GetChromeWidgetWin(hwnd)); 222 | if (page_tab_list) { 223 | top_container_view = GetParentElement(page_tab_list); 224 | } 225 | if (!top_container_view) { 226 | DebugLog(L"GetTopContainerView failed"); 227 | } 228 | return top_container_view; 229 | } 230 | 231 | // Gets the current number of tabs. 232 | int GetTabCount(NodePtr top) { 233 | NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); 234 | if (!page_tab_list) { 235 | return 0; 236 | } 237 | NodePtr page_tab = FindElementWithRole(page_tab_list, ROLE_SYSTEM_PAGETAB); 238 | if (!page_tab) { 239 | return 0; 240 | } 241 | NodePtr page_tab_pane = GetParentElement(page_tab); 242 | if (!page_tab_pane) { 243 | return 0; 244 | } 245 | std::vector children; 246 | TraversalAccessible(page_tab_pane, [&children](NodePtr child) { 247 | children.push_back(child); 248 | return false; 249 | }); 250 | 251 | int tab_count = 0; 252 | for (const auto& child : children) { 253 | auto role = GetAccessibleRole(child); 254 | auto state = GetAccessibleState(child); 255 | if (role == ROLE_SYSTEM_PAGETAB || 256 | // Grouped and collapsed tabs are counted as one tab. 257 | (role == ROLE_SYSTEM_PAGETABLIST && (state & STATE_SYSTEM_COLLAPSED))) { 258 | ++tab_count; 259 | } 260 | } 261 | return tab_count; 262 | } 263 | 264 | NodePtr FindChildElement(NodePtr parent, long role, int skipcount = 0) { 265 | NodePtr element = nullptr; 266 | if (parent) { 267 | int i = 0; 268 | TraversalAccessible(parent, 269 | [&element, &role, &i, &skipcount](NodePtr child) { 270 | // DebugLog(L"当前 %d,%d", i, skipcount); 271 | if (GetAccessibleRole(child) == role) { 272 | if (i == skipcount) { 273 | element = child; 274 | } 275 | ++i; 276 | } 277 | return element != nullptr; 278 | }); 279 | } 280 | return element; 281 | } 282 | 283 | // Whether the mouse is on a tab 284 | bool IsOnOneTab(NodePtr top, POINT pt) { 285 | NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); 286 | if (!page_tab_list) { 287 | return false; 288 | } 289 | NodePtr page_tab = FindElementWithRole(page_tab_list, ROLE_SYSTEM_PAGETAB); 290 | if (!page_tab) { 291 | return false; 292 | } 293 | NodePtr page_tab_pane = GetParentElement(page_tab); 294 | if (!page_tab_pane) { 295 | return false; 296 | } 297 | 298 | bool flag = false; 299 | TraversalAccessible(page_tab_pane, [&flag, &pt](NodePtr child) { 300 | if (GetAccessibleRole(child) != ROLE_SYSTEM_PAGETAB) { 301 | return false; 302 | } 303 | GetAccessibleSize(child, [&flag, &pt](RECT rect) { 304 | if (PtInRect(&rect, pt)) { 305 | flag = true; 306 | } 307 | }); 308 | return flag; 309 | }); 310 | return flag; 311 | } 312 | 313 | bool IsOnlyOneTab(NodePtr top) { 314 | if (!IsKeepLastTab()) { 315 | return false; 316 | } 317 | auto tab_count = GetTabCount(top); 318 | return tab_count <= 1; 319 | } 320 | 321 | // Whether the mouse is on the tab bar 322 | bool IsOnTheTabBar(NodePtr top, POINT pt) { 323 | bool flag = false; 324 | NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); 325 | if (page_tab_list) { 326 | GetAccessibleSize(page_tab_list, [&flag, &pt](RECT rect) { 327 | if (PtInRect(&rect, pt)) { 328 | flag = true; 329 | } 330 | }); 331 | } 332 | return flag; 333 | } 334 | 335 | // Determine whether it is a new tab page from the name of the current tab page. 336 | bool IsNameNewTab(NodePtr top) { 337 | bool flag = false; 338 | std::unique_ptr new_tab_name(nullptr, free); 339 | NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); 340 | if (!page_tab_list) { 341 | return false; 342 | } 343 | TraversalAccessible(page_tab_list, [&new_tab_name](NodePtr child) { 344 | if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) { 345 | GetAccessibleName(child, [&new_tab_name](BSTR bstr) { 346 | new_tab_name.reset( 347 | _wcsdup(bstr)); // Save the name obtained from the new tab button. 348 | }); 349 | } 350 | return false; 351 | }); 352 | NodePtr page_tab = FindElementWithRole(page_tab_list, ROLE_SYSTEM_PAGETAB); 353 | if (!page_tab) { 354 | return false; 355 | } 356 | NodePtr page_tab_pane = GetParentElement(page_tab); 357 | if (!page_tab_pane) { 358 | return false; 359 | } 360 | 361 | std::vector disable_tab_names = 362 | StringSplit(GetDisableTabName(), L',', L"\""); 363 | TraversalAccessible( 364 | page_tab_pane, [&flag, &new_tab_name, &disable_tab_names](NodePtr child) { 365 | if (GetAccessibleState(child) & STATE_SYSTEM_SELECTED) { 366 | GetAccessibleName( 367 | child, [&flag, &new_tab_name, &disable_tab_names](BSTR bstr) { 368 | std::wstring_view bstr_view(bstr); 369 | std::wstring_view new_tab_view(new_tab_name.get()); 370 | flag = (bstr_view.find(new_tab_view) != std::wstring::npos); 371 | for (const auto& tab_name : disable_tab_names) { 372 | if (bstr_view.find(tab_name) != std::wstring::npos) { 373 | flag = true; 374 | break; 375 | } 376 | } 377 | }); 378 | } 379 | return false; 380 | }); 381 | return flag; 382 | } 383 | 384 | // Determine whether it is a new tab page from the document value of the tab 385 | // page. 386 | bool IsDocNewTab() { 387 | auto cr_command_line = GetCrCommandLine(); 388 | if (cr_command_line.find(L"--force-renderer-accessibility") == 389 | std::wstring::npos) { 390 | return false; 391 | } 392 | 393 | bool flag = false; 394 | HWND hwnd = FindWindowEx(GetForegroundWindow(), nullptr, 395 | L"Chrome_RenderWidgetHostHWND", nullptr); 396 | NodePtr pacc_main_window = nullptr; 397 | if (S_OK == AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, 398 | IID_PPV_ARGS(&pacc_main_window))) { 399 | NodePtr document = 400 | FindElementWithRole(pacc_main_window, ROLE_SYSTEM_DOCUMENT); 401 | if (document) { 402 | // The accValue of document needs to be obtained by adding the startup 403 | // parameter --force-renderer-accessibility. However, this parameter will 404 | // slightly affect the performance of the browser when loading pages with 405 | // a large number of elements. Therefore, it is not enabled by default. 406 | // If users need to use this feature, they may add the parameter manually. 407 | GetAccessibleValue(document, [&flag](BSTR bstr) { 408 | std::wstring_view bstr_view(bstr); 409 | flag = bstr_view.find(L"://newtab") != std::wstring_view::npos || 410 | bstr_view.find(L"://new-tab-page") != std::wstring_view::npos; 411 | }); 412 | } 413 | } 414 | return flag; 415 | } 416 | 417 | bool IsOnNewTab(NodePtr top) { 418 | if (!IsNewTabDisable()) { 419 | return false; 420 | } 421 | return IsNameNewTab(top) || IsDocNewTab(); 422 | } 423 | 424 | // Whether the mouse is on a bookmark. 425 | bool IsOnBookmark(HWND hwnd, POINT pt) { 426 | bool flag = false; 427 | std::function LambdaEnumChild = 428 | [&pt, &flag, &LambdaEnumChild](NodePtr child) -> bool { 429 | auto role = GetAccessibleRole(child); 430 | if (role == ROLE_SYSTEM_PUSHBUTTON || role == ROLE_SYSTEM_MENUITEM) { 431 | bool is_in_rect = false; 432 | GetAccessibleSize(child, [&is_in_rect, &pt](const RECT& rect) { 433 | if (PtInRect(&rect, pt)) { 434 | is_in_rect = true; 435 | } 436 | }); 437 | if (is_in_rect) { 438 | GetAccessibleDescription(child, [&flag](BSTR bstr) { 439 | std::wstring_view bstr_view(bstr); 440 | flag = (bstr_view.find_first_of(L".:") != std::wstring_view::npos) && 441 | (bstr_view.substr(0, 11) != L"javascript:"); 442 | }); 443 | if (flag) { 444 | return true; // Stop traversing if found. 445 | } 446 | } 447 | } 448 | // traverse the child nodes. 449 | TraversalAccessible(child, LambdaEnumChild); 450 | return flag; 451 | }; 452 | // Start traversing. 453 | TraversalAccessible(GetChromeWidgetWin(hwnd), LambdaEnumChild); 454 | return flag; 455 | } 456 | 457 | // Whether the omnibox is focused. 458 | bool IsOmniboxFocus(NodePtr top) { 459 | NodePtr tool_bar = FindElementWithRole(top, ROLE_SYSTEM_TOOLBAR); 460 | if (!tool_bar) { 461 | return false; 462 | } 463 | NodePtr omnibox = FindElementWithRole(tool_bar, ROLE_SYSTEM_TEXT); 464 | if (!omnibox) { 465 | return false; 466 | } 467 | NodePtr tool_bar_group = GetParentElement(omnibox); 468 | if (!tool_bar_group) { 469 | return false; 470 | } 471 | 472 | bool flag = false; 473 | TraversalAccessible(tool_bar_group, [&flag](NodePtr child) { 474 | if (GetAccessibleRole(child) != ROLE_SYSTEM_TEXT) { 475 | return false; 476 | } 477 | if (GetAccessibleState(child) & STATE_SYSTEM_FOCUSED) { 478 | flag = true; 479 | } 480 | return flag; 481 | }); 482 | return flag; 483 | } 484 | 485 | // Whether the mouse is on the dialog box. 486 | bool IsOnDialog(HWND hwnd, POINT pt) { 487 | bool flag = false; 488 | TraversalAccessible( 489 | GetChromeWidgetWin(hwnd), 490 | [&pt, &flag](NodePtr child) { 491 | if (GetAccessibleRole(child) == ROLE_SYSTEM_DIALOG) { 492 | GetAccessibleSize(child, [&pt, &flag](RECT rect) { 493 | if (PtInRect(&rect, pt)) { 494 | flag = true; 495 | } 496 | }); 497 | } 498 | return flag; 499 | }, 500 | true); // raw_traversal 501 | return flag; 502 | } 503 | 504 | // Whether the mouse is on the close button of a tab. 505 | // Should be used together with `IsOnOneTab` to search the close button. 506 | bool IsOnCloseButton(NodePtr top, POINT pt) { 507 | bool flag = false; 508 | TraversalAccessible( 509 | top, 510 | [&pt, &flag](NodePtr child) { 511 | if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) { 512 | GetAccessibleSize(child, [&pt, &flag](RECT rect) { 513 | if (PtInRect(&rect, pt)) { 514 | flag = true; 515 | } 516 | }); 517 | } 518 | return flag; 519 | }, 520 | true); // raw_traversal 521 | return flag; 522 | } 523 | 524 | #endif // IACCESSIBLE_H_ 525 | -------------------------------------------------------------------------------- /src/pakfile.h: -------------------------------------------------------------------------------- 1 | #ifndef PAKFILE_H_ 2 | #define PAKFILE_H_ 3 | 4 | #pragma warning(disable : 4334) 5 | #pragma warning(disable : 4267) 6 | 7 | extern "C" 8 | { 9 | #include "..\mini_gzip\miniz.c" 10 | #include "..\mini_gzip\mini_gzip.h" 11 | #include "..\mini_gzip\mini_gzip.c" 12 | } 13 | 14 | #pragma pack(push) 15 | #pragma pack(1) 16 | 17 | #define PACK4_FILE_VERSION (4) 18 | #define PACK5_FILE_VERSION (5) 19 | 20 | struct PAK4_HEADER { 21 | uint32_t num_entries; 22 | uint8_t encodeing; 23 | }; 24 | 25 | struct PAK5_HEADER { 26 | uint32_t encodeing; 27 | uint16_t resource_count; 28 | uint16_t alias_count; 29 | }; 30 | 31 | struct PAK_ENTRY { 32 | uint16_t resource_id; 33 | uint32_t file_offset; 34 | }; 35 | 36 | struct PAK_ALIAS { 37 | uint16_t resource_id; 38 | uint16_t entry_index; 39 | }; 40 | #pragma pack(pop) 41 | 42 | bool CheckHeader(uint8_t* buffer, 43 | PAK_ENTRY*& pak_entry, 44 | PAK_ENTRY*& end_entry) { 45 | uint32_t version = *(uint32_t*)buffer; 46 | 47 | if (version != PACK4_FILE_VERSION && version != PACK5_FILE_VERSION) 48 | return false; 49 | 50 | if (version == PACK4_FILE_VERSION) { 51 | PAK4_HEADER* pak_header = (PAK4_HEADER*)(buffer + sizeof(uint32_t)); 52 | if (pak_header->encodeing != 1) 53 | return false; 54 | 55 | pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK4_HEADER)); 56 | end_entry = pak_entry + pak_header->num_entries; 57 | } 58 | 59 | if (version == PACK5_FILE_VERSION) { 60 | PAK5_HEADER* pak_header = (PAK5_HEADER*)(buffer + sizeof(uint32_t)); 61 | if (pak_header->encodeing != 1) 62 | return false; 63 | 64 | pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK5_HEADER)); 65 | end_entry = pak_entry + pak_header->resource_count; 66 | } 67 | 68 | // In order to save the "next item" of the last item, 69 | // the id of this special item must be 0 70 | if (!end_entry || end_entry->resource_id != 0) 71 | return false; 72 | 73 | return true; 74 | } 75 | 76 | template 77 | void PakFind(uint8_t* buffer, uint8_t* pos, Function f) { 78 | PAK_ENTRY* pak_entry = nullptr; 79 | PAK_ENTRY* end_entry = nullptr; 80 | 81 | // Check the file header. 82 | if (!CheckHeader(buffer, pak_entry, end_entry)) 83 | return; 84 | 85 | do { 86 | PAK_ENTRY* next_entry = pak_entry + 1; 87 | if (pos >= buffer + pak_entry->file_offset && 88 | pos <= buffer + next_entry->file_offset) { 89 | f(buffer + pak_entry->file_offset, 90 | next_entry->file_offset - pak_entry->file_offset); 91 | break; 92 | } 93 | 94 | pak_entry = next_entry; 95 | } while (pak_entry->resource_id != 0); 96 | } 97 | 98 | template 99 | void TraversalGZIPFile(uint8_t* buffer, Function f) { 100 | PAK_ENTRY* pak_entry = NULL; 101 | PAK_ENTRY* end_entry = NULL; 102 | 103 | // Check the file header. 104 | if (!CheckHeader(buffer, pak_entry, end_entry)) 105 | return; 106 | 107 | do { 108 | PAK_ENTRY* next_entry = pak_entry + 1; 109 | uint32_t old_size = next_entry->file_offset - pak_entry->file_offset; 110 | 111 | if (old_size < 10 * 1024) { 112 | // Files smaller than 10 kb are skipped. 113 | pak_entry = next_entry; 114 | continue; 115 | } 116 | 117 | BYTE gzip[] = {0x1F, 0x8B, 0x08}; 118 | size_t gzip_len = sizeof(gzip); 119 | if (memcmp(buffer + pak_entry->file_offset, gzip, gzip_len) != 0) { 120 | // Files that are not gzip format are skipped. 121 | pak_entry = next_entry; 122 | continue; 123 | } 124 | 125 | uint32_t original_size = *(uint32_t*)(buffer + next_entry->file_offset - 4); 126 | uint8_t* unpack_buffer = (uint8_t*)malloc(original_size); 127 | if (!unpack_buffer) 128 | return; 129 | 130 | struct mini_gzip gz; 131 | mini_gz_start(&gz, buffer + pak_entry->file_offset, old_size); 132 | int unpack_len = mini_gz_unpack(&gz, unpack_buffer, original_size); 133 | 134 | if (original_size == unpack_len) { 135 | uint32_t new_len = old_size; 136 | bool changed = f(unpack_buffer, unpack_len, new_len); 137 | if (changed) { 138 | // If the file is changed. 139 | size_t compress_size = 0; 140 | uint8_t* compress_buffer = 141 | (uint8_t*)gzip_compress(unpack_buffer, new_len, &compress_size); 142 | if (compress_buffer && compress_size < old_size) { 143 | /*FILE *fp = fopen("test.gz", "wb"); 144 | fwrite(compress_buffer, compress_size, 1, fp); 145 | fclose(fp);*/ 146 | 147 | // gzip header 148 | memcpy(buffer + pak_entry->file_offset, compress_buffer, 10); 149 | 150 | // extra 151 | buffer[pak_entry->file_offset + 3] = 0x04; 152 | uint16_t extra_length = old_size - compress_size - 2; 153 | memcpy(buffer + pak_entry->file_offset + 10, &extra_length, 154 | sizeof(extra_length)); 155 | memset(buffer + pak_entry->file_offset + 12, '\0', extra_length); 156 | 157 | // compress 158 | memcpy(buffer + pak_entry->file_offset + 12 + extra_length, 159 | compress_buffer + 10, compress_size - 10); 160 | 161 | /*fp = fopen("test2.gz", "wb"); 162 | fwrite(buffer + pak_entry->file_offset, old_size, 1, fp); 163 | fclose(fp);*/ 164 | } else { 165 | DebugLog(L"gzip compress error %d %d", compress_size, old_size); 166 | } 167 | 168 | if (compress_buffer) 169 | free(compress_buffer); 170 | } 171 | } 172 | 173 | free(unpack_buffer); 174 | pak_entry = next_entry; 175 | } while (pak_entry->resource_id != 0); 176 | } 177 | 178 | #endif // PAKFILE_H_ 179 | -------------------------------------------------------------------------------- /src/pakpatch.h: -------------------------------------------------------------------------------- 1 | #ifndef PAKPATCH_H_ 2 | #define PAKPATCH_H_ 3 | 4 | #include "pakfile.h" 5 | 6 | DWORD resources_pak_size = 0; 7 | HANDLE resources_pak_map = nullptr; 8 | HANDLE resources_pak_file = nullptr; 9 | 10 | auto RawCreateFile = CreateFileW; 11 | auto RawCreateFileMapping = CreateFileMappingW; 12 | auto RawMapViewOfFile = MapViewOfFile; 13 | 14 | HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject, 15 | _In_ DWORD dwDesiredAccess, 16 | _In_ DWORD dwFileOffsetHigh, 17 | _In_ DWORD dwFileOffsetLow, 18 | _In_ SIZE_T dwNumberOfBytesToMap) { 19 | if (hFileMappingObject == resources_pak_map) { 20 | // Modify it to be modifiable. 21 | LPVOID buffer = 22 | RawMapViewOfFile(hFileMappingObject, FILE_MAP_COPY, dwFileOffsetHigh, 23 | dwFileOffsetLow, dwNumberOfBytesToMap); 24 | 25 | // No more hook needed. 26 | resources_pak_map = nullptr; 27 | DetourTransactionBegin(); 28 | DetourUpdateThread(GetCurrentThread()); 29 | DetourDetach((LPVOID*)&RawMapViewOfFile, MyMapViewOfFile); 30 | auto status = DetourTransactionCommit(); 31 | if (status != NO_ERROR) { 32 | DebugLog(L"Unhook RawMapViewOfFile failed %d", status); 33 | } 34 | 35 | if (buffer) { 36 | // Traverse the gzip file. 37 | TraversalGZIPFile((BYTE*)buffer, [=](uint8_t* begin, uint32_t size, 38 | uint32_t& new_len) { 39 | bool changed = false; 40 | 41 | BYTE search_start[] = R"()"; 42 | uint8_t* pos = 43 | memmem(begin, size, search_start, sizeof(search_start) - 1); 44 | if (pos) { 45 | // Compress the HTML for writing patch information. 46 | std::string html((char*)begin, size); 47 | compression_html(html); 48 | 49 | // RemoveUpdateError 50 | // if (IsNeedPortable()) 51 | { 52 | ReplaceStringInPlace(html, R"(hidden="[[!showUpdateStatus_]]")", 53 | R"(hidden="true")"); 54 | ReplaceStringInPlace( 55 | html, R"(hidden="[[!shouldShowIcons_(showUpdateStatus_)]]")", 56 | R"(hidden="true")"); 57 | } 58 | 59 | const char prouct_title[] = u8R"({aboutBrowserVersion}
Chrome++ )" RELEASE_VER_STR u8R"( modified version
)"; 60 | ReplaceStringInPlace(html, R"({aboutBrowserVersion})", 61 | prouct_title); 62 | 63 | if (html.length() <= size) { 64 | // Write modifications. 65 | memcpy(begin, html.c_str(), html.length()); 66 | 67 | // Modify length. 68 | new_len = html.length(); 69 | changed = true; 70 | } 71 | } 72 | 73 | return changed; 74 | }); 75 | } 76 | 77 | return buffer; 78 | } 79 | 80 | return RawMapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, 81 | dwFileOffsetLow, dwNumberOfBytesToMap); 82 | } 83 | 84 | HANDLE WINAPI MyCreateFileMapping(_In_ HANDLE hFile, 85 | _In_opt_ LPSECURITY_ATTRIBUTES lpAttributes, 86 | _In_ DWORD flProtect, 87 | _In_ DWORD dwMaximumSizeHigh, 88 | _In_ DWORD dwMaximumSizeLow, 89 | _In_opt_ LPCTSTR lpName) { 90 | if (hFile == resources_pak_file) { 91 | // Modify it to be modifiable. 92 | resources_pak_map = 93 | RawCreateFileMapping(hFile, lpAttributes, PAGE_WRITECOPY, 94 | dwMaximumSizeHigh, dwMaximumSizeLow, lpName); 95 | 96 | // No more hook needed. 97 | resources_pak_file = nullptr; 98 | DetourTransactionBegin(); 99 | DetourUpdateThread(GetCurrentThread()); 100 | DetourDetach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping); 101 | auto status = DetourTransactionCommit(); 102 | if (status != NO_ERROR) { 103 | DebugLog(L"Unhook RawCreateFileMapping failed %d", status); 104 | } 105 | 106 | DetourTransactionBegin(); 107 | DetourUpdateThread(GetCurrentThread()); 108 | DetourAttach((LPVOID*)&RawMapViewOfFile, MyMapViewOfFile); 109 | status = DetourTransactionCommit(); 110 | if (status != NO_ERROR) { 111 | DebugLog(L"Hook RawMapViewOfFile failed %d", status); 112 | } 113 | 114 | return resources_pak_map; 115 | } 116 | return RawCreateFileMapping(hFile, lpAttributes, flProtect, dwMaximumSizeHigh, 117 | dwMaximumSizeLow, lpName); 118 | } 119 | 120 | HANDLE WINAPI MyCreateFile(_In_ LPCTSTR lpFileName, 121 | _In_ DWORD dwDesiredAccess, 122 | _In_ DWORD dwShareMode, 123 | _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, 124 | _In_ DWORD dwCreationDisposition, 125 | _In_ DWORD dwFlagsAndAttributes, 126 | _In_opt_ HANDLE hTemplateFile) { 127 | HANDLE file = RawCreateFile(lpFileName, dwDesiredAccess, dwShareMode, 128 | lpSecurityAttributes, dwCreationDisposition, 129 | dwFlagsAndAttributes, hTemplateFile); 130 | 131 | if (isEndWith(lpFileName, L"resources.pak")) { 132 | resources_pak_file = file; 133 | resources_pak_size = GetFileSize(resources_pak_file, nullptr); 134 | 135 | DetourTransactionBegin(); 136 | DetourUpdateThread(GetCurrentThread()); 137 | DetourAttach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping); 138 | auto status = DetourTransactionCommit(); 139 | if (status != NO_ERROR) { 140 | DebugLog(L"Hook RawCreateFileMapping failed %d", status); 141 | } 142 | 143 | // No more hook needed. 144 | DetourTransactionBegin(); 145 | DetourUpdateThread(GetCurrentThread()); 146 | DetourDetach((LPVOID*)&RawCreateFile, MyCreateFile); 147 | status = DetourTransactionCommit(); 148 | if (status != NO_ERROR) { 149 | DebugLog(L"Unhook RawCreateFile failed %d", status); 150 | } 151 | } 152 | 153 | return file; 154 | } 155 | 156 | void PakPatch() { 157 | DetourTransactionBegin(); 158 | DetourUpdateThread(GetCurrentThread()); 159 | DetourAttach((LPVOID*)&RawCreateFile, MyCreateFile); 160 | auto status = DetourTransactionCommit(); 161 | if (status != NO_ERROR) { 162 | DebugLog(L"Hook RawCreateFile failed %d", status); 163 | } 164 | } 165 | 166 | #endif // PAKPATCH_H_ 167 | -------------------------------------------------------------------------------- /src/patch.h: -------------------------------------------------------------------------------- 1 | #ifndef PATCH_H_ 2 | #define PATCH_H_ 3 | 4 | typedef LONG NTSTATUS, *PNTSTATUS; 5 | 6 | #ifndef NT_SUCCESS 7 | #define NT_SUCCESS(x) ((x) >= 0) 8 | #define STATUS_SUCCESS ((NTSTATUS)0) 9 | #endif 10 | 11 | typedef struct _UNICODE_STRING { 12 | USHORT Length; 13 | USHORT MaximumLength; 14 | PWSTR Buffer; 15 | } UNICODE_STRING, *PUNICODE_STRING; 16 | 17 | typedef NTSTATUS(WINAPI* pLdrLoadDll)(IN PWCHAR PathToFile OPTIONAL, 18 | IN ULONG Flags OPTIONAL, 19 | IN PUNICODE_STRING ModuleFileName, 20 | OUT PHANDLE ModuleHandle); 21 | 22 | pLdrLoadDll RawLdrLoadDll = nullptr; 23 | 24 | // https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/dialogs/outdated_upgrade_bubble.cc?q=outdated_upgrade_bubble&ss=chromium%2Fchromium%2Fsrc 25 | // This function is invalid and needs to be modified. 26 | // void Outdated(HMODULE module) { 27 | // // "OutdatedUpgradeBubble.Show" 28 | // #ifdef _WIN64 29 | // BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80, 30 | // 0x3D}; uint8_t* match = SearchModuleRaw(module, search, sizeof(search)); 31 | // #else 32 | // BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80, 33 | // 0x3D}; uint8_t* match = SearchModuleRaw(module, search, sizeof(search)); 34 | // #endif 35 | // if (match) { 36 | // if (*(match + 0xF) == 0x74) { 37 | // BYTE patch[] = {0x90, 0x90}; 38 | // WriteMemory(match + 0xF, patch, sizeof(patch)); 39 | // } 40 | // } else { 41 | // DebugLog(L"patch Outdated failed %p", module); 42 | // } 43 | // } 44 | 45 | void DevWarning(HMODULE module) { 46 | // "enable-automation" 47 | } 48 | 49 | NTSTATUS WINAPI MyLdrLoadDll(IN PWCHAR PathToFile OPTIONAL, 50 | IN ULONG Flags OPTIONAL, 51 | IN PUNICODE_STRING ModuleFileName, 52 | OUT PHANDLE ModuleHandle) { 53 | static bool chrome_loaded = false; 54 | 55 | NTSTATUS ntstatus = 56 | RawLdrLoadDll(PathToFile, Flags, ModuleFileName, ModuleHandle); 57 | if (NT_SUCCESS(ntstatus)) { 58 | if (wcsstr(ModuleFileName->Buffer, L"chrome.dll") != 0 && !chrome_loaded) { 59 | chrome_loaded = true; 60 | // Outdated((HMODULE)*ModuleHandle); 61 | DevWarning((HMODULE)*ModuleHandle); 62 | } 63 | } 64 | return ntstatus; 65 | }; 66 | 67 | void MakePatch() { 68 | // HMODULE chrome = GetModuleHandle(L"chrome.dll"); 69 | // if (chrome) 70 | // { 71 | // Outdated(chrome); 72 | // DevWarning(chrome); 73 | // return; 74 | // } 75 | HMODULE ntdll = GetModuleHandle(L"ntdll.dll"); 76 | if (ntdll) { 77 | RawLdrLoadDll = (pLdrLoadDll)GetProcAddress(ntdll, "LdrLoadDll"); 78 | if (RawLdrLoadDll) { 79 | DetourTransactionBegin(); 80 | DetourUpdateThread(GetCurrentThread()); 81 | DetourAttach((LPVOID*)&RawLdrLoadDll, MyLdrLoadDll); 82 | auto status = DetourTransactionCommit(); 83 | if (status != NO_ERROR) { 84 | DebugLog(L"Hook LdrLoadDll failed %d", status); 85 | } 86 | } 87 | } 88 | } 89 | 90 | #endif // PATCH_H_ 91 | -------------------------------------------------------------------------------- /src/portable.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLE_H_ 2 | #define PORTABLE_H_ 3 | 4 | // Construct new command line with portable mode. 5 | std::wstring GetCommand(LPWSTR param) { 6 | std::vector args; 7 | 8 | int argc; 9 | LPWSTR* argv = CommandLineToArgvW(param, &argc); 10 | 11 | int insert_pos = 0; 12 | for (int i = 0; i < argc; ++i) { 13 | if (std::wstring(argv[i]).find(L"--") != std::wstring::npos || 14 | std::wstring(argv[i]).find(L"--single-argument") != 15 | std::wstring::npos) { 16 | break; 17 | } 18 | insert_pos = i; 19 | } 20 | for (int i = 0; i < argc; ++i) { 21 | // Preserve former arguments. 22 | if (i) 23 | args.push_back(argv[i]); 24 | 25 | // Append new arguments. 26 | if (i == insert_pos) { 27 | args.push_back(L"--portable"); 28 | 29 | args.push_back(L"--disable-features=WinSboxNoFakeGdiInit"); 30 | 31 | auto userdata = GetUserDataDir(); 32 | if (!userdata.empty()) { 33 | args.push_back(L"--user-data-dir=" + userdata); 34 | } 35 | 36 | auto diskcache = GetDiskCacheDir(); 37 | if (!diskcache.empty()) { 38 | args.push_back(L"--disk-cache-dir=" + diskcache); 39 | } 40 | 41 | // Get the command line and append parameters 42 | // Intercept and split the parameters starting with each --, 43 | // and then args.push_back multiple times 44 | // Repeat the above process until the -- sign no longer exists in the 45 | // string 46 | { 47 | auto cr_command_line = GetCrCommandLine(); 48 | std::wstring temp = cr_command_line; 49 | while (true) { 50 | auto pos = temp.find(L"--"); 51 | if (pos == std::wstring::npos) { 52 | break; 53 | } else { 54 | auto pos2 = temp.find(L" --", pos); 55 | if (pos2 == std::wstring::npos) { 56 | args.push_back(temp); 57 | break; 58 | } else { 59 | args.push_back(temp.substr(pos, pos2 - pos)); 60 | temp = temp.substr(0, pos) + temp.substr(pos2 + 1); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } 67 | LocalFree(argv); 68 | 69 | return JoinArgsString(args, L" "); 70 | } 71 | 72 | HANDLE hMutex = nullptr; 73 | bool IsFirstRun() { 74 | DWORD pid = GetCurrentProcessId(); 75 | std::wstring mutex_name = 76 | L"Global\\ChromePlusFirstRunMutex" + std::to_wstring(pid); 77 | hMutex = CreateMutexW(nullptr, TRUE, mutex_name.c_str()); 78 | if (hMutex == nullptr || GetLastError() == ERROR_ALREADY_EXISTS) { 79 | return false; 80 | } 81 | return true; 82 | } 83 | 84 | void LaunchCommands(const std::wstring& get_commands, 85 | int show_command, 86 | std::vector* program_handles) { 87 | auto commands = StringSplit( 88 | get_commands, L';', 89 | L""); // Quotes should not be used as they can cause errors with paths 90 | // that contain spaces. Since semicolons rarely appear in names and 91 | // commands, they are used as delimiters. 92 | if (commands.empty()) { 93 | return; 94 | } 95 | for (const auto& command : commands) { 96 | std::wstring expanded_path = ExpandEnvironmentPath(command); 97 | ReplaceStringInPlace(expanded_path, L"%app%", GetAppDir()); 98 | HANDLE handle = RunExecute(expanded_path.c_str(), show_command); 99 | if (program_handles != nullptr && handle != nullptr) { 100 | program_handles->push_back(handle); 101 | } 102 | } 103 | } 104 | 105 | void KillLaunchOnExit(std::vector* program_handles) { 106 | if (IsKillLaunchOnExit() && program_handles != nullptr) { 107 | for (auto handle : *program_handles) { 108 | TerminateProcess(handle, 0); 109 | } 110 | } 111 | } 112 | 113 | void Portable(LPWSTR param) { 114 | bool first_run = IsFirstRun(); 115 | auto launch_on_startup = GetLaunchOnStartup(); 116 | auto launch_on_exit = GetLaunchOnExit(); 117 | std::vector program_handles = {nullptr}; 118 | 119 | if (first_run && !launch_on_startup.empty()) { 120 | LaunchCommands(launch_on_startup, SW_SHOW, &program_handles); 121 | } 122 | 123 | wchar_t path[MAX_PATH]; 124 | ::GetModuleFileName(nullptr, path, MAX_PATH); 125 | std::wstring args = GetCommand(param); 126 | 127 | SHELLEXECUTEINFO sei = {0}; 128 | sei.cbSize = sizeof(SHELLEXECUTEINFO); 129 | sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; 130 | sei.lpVerb = L"open"; 131 | sei.lpFile = path; 132 | sei.nShow = SW_SHOWNORMAL; 133 | sei.lpParameters = args.c_str(); 134 | 135 | if (ShellExecuteEx(&sei)) { 136 | if (first_run && !launch_on_exit.empty()) { 137 | // `WaitForSingleObject` causes IDM floating bar not to be displayed. 138 | // Hence, end users should be reminded to avoid using this feature until a 139 | // better method is implemented. See: 140 | // https://github.com/Bush2021/chrome_plus/issues/130 141 | WaitForSingleObject(sei.hProcess, INFINITE); 142 | CloseHandle(hMutex); 143 | KillLaunchOnExit(&program_handles); 144 | LaunchCommands(launch_on_exit, SW_HIDE, nullptr); 145 | } 146 | ExitProcess(0); 147 | } 148 | } 149 | 150 | #endif // PORTABLE_H_ 151 | -------------------------------------------------------------------------------- /src/tabbookmark.h: -------------------------------------------------------------------------------- 1 | #ifndef TABBOOKMARK_H_ 2 | #define TABBOOKMARK_H_ 3 | 4 | #include "iaccessible.h" 5 | 6 | HHOOK mouse_hook = nullptr; 7 | static POINT kLButtonDownPoint = {-1, -1}; 8 | 9 | #define KEY_PRESSED 0x8000 10 | bool IsPressed(int key) { 11 | return key && (::GetKeyState(key) & KEY_PRESSED) != 0; 12 | } 13 | 14 | // Compared with `IsOnlyOneTab`, this function additionally implements tick 15 | // fault tolerance to prevent users from directly closing the window when 16 | // they click too fast. 17 | bool IsNeedKeep(NodePtr top_container_view) { 18 | if (!IsKeepLastTab()) { 19 | return false; 20 | } 21 | 22 | auto tab_count = GetTabCount(top_container_view); 23 | bool keep_tab = (tab_count == 1); 24 | 25 | static auto last_closing_tab_tick = GetTickCount64(); 26 | auto tick = GetTickCount64() - last_closing_tab_tick; 27 | last_closing_tab_tick = GetTickCount64(); 28 | 29 | if (tick > 50 && tick <= 250 && tab_count == 2) { 30 | keep_tab = true; 31 | } 32 | 33 | return keep_tab; 34 | } 35 | 36 | // If the top_container_view is not found at the first time, try to close the 37 | // find-in-page bar and find the top_container_view again. 38 | NodePtr HandleFindBar(HWND hwnd, POINT pt) { 39 | // If the mouse is clicked directly on the find-in-page bar, follow Chrome's 40 | // original logic. Otherwise, clicking the button on the find-in-page bar may 41 | // directly close the find-in-page bar. 42 | if (IsOnDialog(hwnd, pt)) { 43 | return nullptr; 44 | } 45 | NodePtr top_container_view = GetTopContainerView(hwnd); 46 | if (!top_container_view) { 47 | ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd); 48 | top_container_view = GetTopContainerView(hwnd); 49 | if (!top_container_view) { 50 | return nullptr; 51 | } 52 | } 53 | return top_container_view; 54 | } 55 | 56 | class IniConfig { 57 | public: 58 | IniConfig() 59 | : is_double_click_close(IsDoubleClickClose()), 60 | is_right_click_close(IsRightClickClose()), 61 | is_wheel_tab(IsWheelTab()), 62 | is_wheel_tab_when_press_right_button(IsWheelTabWhenPressRightButton()), 63 | is_bookmark_new_tab(IsBookmarkNewTab()), 64 | is_open_url_new_tab(IsOpenUrlNewTabFun()) {} 65 | 66 | bool is_double_click_close; 67 | bool is_right_click_close; 68 | bool is_wheel_tab; 69 | bool is_wheel_tab_when_press_right_button; 70 | std::string is_bookmark_new_tab; 71 | std::string is_open_url_new_tab; 72 | }; 73 | 74 | IniConfig config; 75 | 76 | // Use the mouse wheel to switch tabs 77 | bool HandleMouseWheel(WPARAM wParam, LPARAM lParam, PMOUSEHOOKSTRUCT pmouse) { 78 | if (wParam != WM_MOUSEWHEEL || 79 | (!config.is_wheel_tab && !config.is_wheel_tab_when_press_right_button)) { 80 | return false; 81 | } 82 | 83 | HWND hwnd = GetFocus(); 84 | NodePtr top_container_view = GetTopContainerView(hwnd); 85 | 86 | PMOUSEHOOKSTRUCTEX pwheel = (PMOUSEHOOKSTRUCTEX)lParam; 87 | int zDelta = GET_WHEEL_DELTA_WPARAM(pwheel->mouseData); 88 | 89 | // If the mouse wheel is used to switch tabs when the mouse is on the tab bar. 90 | if (config.is_wheel_tab && IsOnTheTabBar(top_container_view, pmouse->pt)) { 91 | hwnd = GetTopWnd(hwnd); 92 | if (zDelta > 0) { 93 | ExecuteCommand(IDC_SELECT_PREVIOUS_TAB, hwnd); 94 | } else { 95 | ExecuteCommand(IDC_SELECT_NEXT_TAB, hwnd); 96 | } 97 | return true; 98 | } 99 | 100 | // If it is used to switch tabs when the right button is held. 101 | if (config.is_wheel_tab_when_press_right_button && IsPressed(VK_RBUTTON)) { 102 | hwnd = GetTopWnd(hwnd); 103 | if (zDelta > 0) { 104 | ExecuteCommand(IDC_SELECT_PREVIOUS_TAB, hwnd); 105 | } else { 106 | ExecuteCommand(IDC_SELECT_NEXT_TAB, hwnd); 107 | } 108 | return true; 109 | } 110 | 111 | return false; 112 | } 113 | 114 | // Double-click to close tab. 115 | int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { 116 | if (wParam != WM_LBUTTONDBLCLK || !config.is_double_click_close) { 117 | return 0; 118 | } 119 | 120 | POINT pt = pmouse->pt; 121 | HWND hwnd = WindowFromPoint(pt); 122 | NodePtr top_container_view = HandleFindBar(hwnd, pt); 123 | if (!top_container_view) { 124 | return 0; 125 | } 126 | 127 | bool is_on_one_tab = IsOnOneTab(top_container_view, pt); 128 | bool is_on_close_button = IsOnCloseButton(top_container_view, pt); 129 | bool is_only_one_tab = IsOnlyOneTab(top_container_view); 130 | if (!is_on_one_tab || is_on_close_button) { 131 | return 0; 132 | } 133 | if (is_only_one_tab) { 134 | ExecuteCommand(IDC_NEW_TAB, hwnd); 135 | ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); 136 | } else { 137 | ExecuteCommand(IDC_CLOSE_TAB, hwnd); 138 | } 139 | return 1; 140 | } 141 | 142 | // Right-click to close tab (Hold Shift to show the original menu). 143 | int HandleRightClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { 144 | if (wParam != WM_RBUTTONUP || IsPressed(VK_SHIFT) || 145 | !config.is_right_click_close) { 146 | return 0; 147 | } 148 | 149 | POINT pt = pmouse->pt; 150 | HWND hwnd = WindowFromPoint(pt); 151 | NodePtr top_container_view = HandleFindBar(hwnd, pt); 152 | if (!top_container_view) { 153 | return 0; 154 | } 155 | 156 | bool is_on_one_tab = IsOnOneTab(top_container_view, pt); 157 | bool keep_tab = IsNeedKeep(top_container_view); 158 | 159 | if (is_on_one_tab) { 160 | if (keep_tab) { 161 | ExecuteCommand(IDC_NEW_TAB, hwnd); 162 | ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); 163 | } else { 164 | // Attempt new SendKey function which includes a `dwExtraInfo` 165 | // value (MAGIC_CODE). 166 | SendKey(VK_MBUTTON); 167 | } 168 | return 1; 169 | } 170 | return 0; 171 | } 172 | 173 | // Preserve the last tab when the middle button is clicked on the tab. 174 | int HandleMiddleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { 175 | if (wParam != WM_MBUTTONUP) { 176 | return 0; 177 | } 178 | 179 | POINT pt = pmouse->pt; 180 | HWND hwnd = WindowFromPoint(pt); 181 | NodePtr top_container_view = HandleFindBar(hwnd, pt); 182 | if (!top_container_view) { 183 | return 0; 184 | } 185 | 186 | bool is_on_one_tab = IsOnOneTab(top_container_view, pt); 187 | bool keep_tab = IsNeedKeep(top_container_view); 188 | 189 | if (is_on_one_tab && keep_tab) { 190 | ExecuteCommand(IDC_NEW_TAB, hwnd); 191 | ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); 192 | return 1; 193 | } 194 | 195 | return 0; 196 | } 197 | 198 | // Open bookmarks in a new tab. 199 | bool HandleBookmark(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { 200 | if (wParam != WM_LBUTTONUP || IsPressed(VK_CONTROL) || IsPressed(VK_SHIFT) || 201 | config.is_bookmark_new_tab == "disabled") { 202 | return false; 203 | } 204 | 205 | // Add drag detection logic for 206 | // https://github.com/Bush2021/chrome_plus/issues/152 207 | int dragThresholdX = GetSystemMetrics(SM_CXDRAG); 208 | int dragThresholdY = GetSystemMetrics(SM_CYDRAG); 209 | int dx = pmouse->pt.x - kLButtonDownPoint.x; 210 | int dy = pmouse->pt.y - kLButtonDownPoint.y; 211 | if (abs(dx) > dragThresholdX || abs(dy) > dragThresholdY) { 212 | return false; 213 | } 214 | 215 | POINT pt = pmouse->pt; 216 | HWND hwnd = WindowFromPoint(pt); 217 | NodePtr top_container_view = GetTopContainerView( 218 | GetFocus()); // Must use `GetFocus()`, otherwise when opening bookmarks 219 | // in a bookmark folder (and similar expanded menus), 220 | // `top_container_view` cannot be obtained, making it 221 | // impossible to correctly determine `is_on_new_tab`. See 222 | // #98. 223 | 224 | bool is_on_bookmark = IsOnBookmark(hwnd, pt); 225 | bool is_on_new_tab = IsOnNewTab(top_container_view); 226 | 227 | if (is_on_bookmark && !is_on_new_tab) { 228 | if (config.is_bookmark_new_tab == "foreground") { 229 | SendKey(VK_MBUTTON, VK_SHIFT); 230 | } else if (config.is_bookmark_new_tab == "background") { 231 | SendKey(VK_MBUTTON); 232 | } 233 | return true; 234 | } 235 | 236 | return false; 237 | } 238 | 239 | LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) { 240 | if (nCode != HC_ACTION) { 241 | return CallNextHookEx(mouse_hook, nCode, wParam, lParam); 242 | } 243 | 244 | do { 245 | if (wParam == WM_MOUSEMOVE || wParam == WM_NCMOUSEMOVE) { 246 | break; 247 | } 248 | PMOUSEHOOKSTRUCT pmouse = (PMOUSEHOOKSTRUCT)lParam; 249 | 250 | // Defining a `dwExtraInfo` value to prevent hook the message sent by 251 | // Chrome++ itself. 252 | if (pmouse->dwExtraInfo == MAGIC_CODE) { 253 | break; 254 | } 255 | 256 | // Record LBUTTONDOWN position 257 | if (wParam == WM_LBUTTONDOWN) { 258 | kLButtonDownPoint = pmouse->pt; 259 | break; 260 | } 261 | 262 | if (HandleMouseWheel(wParam, lParam, pmouse)) { 263 | return 1; 264 | } 265 | 266 | if (HandleDoubleClick(wParam, pmouse) != 0) { 267 | // Do not return 1. Returning 1 could cause the keep_tab to fail 268 | // or trigger double-click operations consecutively when the user 269 | // double-clicks on the tab page rapidly and repeatedly. 270 | } 271 | 272 | if (HandleRightClick(wParam, pmouse) != 0) { 273 | return 1; 274 | } 275 | 276 | if (HandleMiddleClick(wParam, pmouse) != 0) { 277 | return 1; 278 | } 279 | 280 | if (HandleBookmark(wParam, pmouse)) { 281 | return 1; 282 | } 283 | } while (0); 284 | return CallNextHookEx(mouse_hook, nCode, wParam, lParam); 285 | } 286 | 287 | int HandleKeepTab(WPARAM wParam) { 288 | if (!(wParam == 'W' && IsPressed(VK_CONTROL) && !IsPressed(VK_SHIFT)) && 289 | !(wParam == VK_F4 && IsPressed(VK_CONTROL))) { 290 | return 0; 291 | } 292 | 293 | HWND hwnd = GetFocus(); 294 | wchar_t name[256] = {0}; 295 | GetClassName(hwnd, name, 255); 296 | if (wcsstr(name, L"Chrome_WidgetWin_") == nullptr) { 297 | return 0; 298 | } 299 | 300 | if (IsFullScreen(hwnd)) { 301 | // Have to exit full screen to find the tab. 302 | ExecuteCommand(IDC_FULLSCREEN, hwnd); 303 | } 304 | 305 | HWND tmp_hwnd = hwnd; 306 | hwnd = GetAncestor(tmp_hwnd, GA_ROOTOWNER); 307 | ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, tmp_hwnd); 308 | 309 | NodePtr top_container_view = GetTopContainerView(hwnd); 310 | if (!IsNeedKeep(top_container_view)) { 311 | return 0; 312 | } 313 | 314 | ExecuteCommand(IDC_NEW_TAB, hwnd); 315 | ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); 316 | return 1; 317 | } 318 | 319 | int HandleOpenUrlNewTab(WPARAM wParam) { 320 | if (!(config.is_open_url_new_tab != "disabled" && wParam == VK_RETURN && 321 | !IsPressed(VK_MENU))) { 322 | return 0; 323 | } 324 | 325 | NodePtr top_container_view = GetTopContainerView(GetForegroundWindow()); 326 | if (IsOmniboxFocus(top_container_view) && !IsOnNewTab(top_container_view)) { 327 | if (config.is_open_url_new_tab == "foreground") { 328 | SendKey(VK_MENU, VK_RETURN); 329 | } else if (config.is_open_url_new_tab == "background") { 330 | SendKey(VK_SHIFT, VK_MENU, VK_RETURN); 331 | } 332 | return 1; 333 | } 334 | return 0; 335 | } 336 | 337 | HHOOK keyboard_hook = nullptr; 338 | LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { 339 | if (nCode == HC_ACTION && !(lParam & 0x80000000)) // pressed 340 | { 341 | if (HandleKeepTab(wParam) != 0) { 342 | return 1; 343 | } 344 | 345 | if (HandleOpenUrlNewTab(wParam) != 0) { 346 | return 1; 347 | } 348 | } 349 | return CallNextHookEx(keyboard_hook, nCode, wParam, lParam); 350 | } 351 | 352 | void TabBookmark() { 353 | mouse_hook = 354 | SetWindowsHookEx(WH_MOUSE, MouseProc, hInstance, GetCurrentThreadId()); 355 | keyboard_hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInstance, 356 | GetCurrentThreadId()); 357 | } 358 | 359 | #endif // TABBOOKMARK_H_ 360 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H_ 2 | #define UTILS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #pragma comment(lib, "Shlwapi.lib") 14 | 15 | #include "FastSearch.h" 16 | 17 | // https://source.chromium.org/chromium/chromium/src/+/main:chrome/app/chrome_command_ids.h?q=chrome_command_ids.h&ss=chromium%2Fchromium%2Fsrc 18 | #define IDC_NEW_TAB 34014 19 | #define IDC_CLOSE_TAB 34015 20 | #define IDC_SELECT_NEXT_TAB 34016 21 | #define IDC_SELECT_PREVIOUS_TAB 34017 22 | #define IDC_SELECT_TAB_0 34018 23 | #define IDC_SELECT_TAB_1 34019 24 | #define IDC_SELECT_TAB_2 34020 25 | #define IDC_SELECT_TAB_3 34021 26 | #define IDC_SELECT_TAB_4 34022 27 | #define IDC_SELECT_TAB_5 34023 28 | #define IDC_SELECT_TAB_6 34024 29 | #define IDC_SELECT_TAB_7 34025 30 | #define IDC_SELECT_LAST_TAB 34026 31 | #define IDC_SHOW_TRANSLATE 35009 32 | #define IDC_UPGRADE_DIALOG 40024 33 | #define IDC_FULLSCREEN 34030 34 | #define IDC_CLOSE_FIND_OR_STOP 37003 35 | #define IDC_WINDOW_CLOSE_OTHER_TABS 35023 36 | 37 | // String manipulation function. 38 | std::wstring Format(const wchar_t* format, va_list args) { 39 | std::vector buffer; 40 | 41 | size_t length = _vscwprintf(format, args); 42 | 43 | buffer.resize((length + 1) * sizeof(wchar_t)); 44 | 45 | _vsnwprintf_s(&buffer[0], length + 1, length, format, args); 46 | 47 | return std::wstring(&buffer[0]); 48 | } 49 | 50 | std::wstring Format(const wchar_t* format, ...) { 51 | va_list args; 52 | 53 | va_start(args, format); 54 | auto str = Format(format, args); 55 | va_end(args); 56 | 57 | return str; 58 | } 59 | 60 | std::string wstring_to_string(const std::wstring& wstr) { 61 | std::string strTo; 62 | auto szTo = new char[wstr.length() + 1]; 63 | szTo[wstr.size()] = '\0'; 64 | WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, szTo, 65 | static_cast(wstr.length()), nullptr, nullptr); 66 | strTo = szTo; 67 | delete[] szTo; 68 | return strTo; 69 | } 70 | 71 | // Specify the delimiter and wrapper to split the string. 72 | std::vector StringSplit(const std::wstring& str, 73 | const wchar_t delim, 74 | const std::wstring& enclosure) { 75 | std::vector result; 76 | std::wstring::size_type start = 0; 77 | std::wstring::size_type end = str.find(delim); 78 | while (end != std::wstring::npos) { 79 | std::wstring name = str.substr(start, end - start); 80 | if (!enclosure.empty() && !name.empty() && 81 | name.front() == enclosure.front()) { 82 | name.erase(0, 1); 83 | } 84 | if (!enclosure.empty() && !name.empty() && 85 | name.back() == enclosure.back()) { 86 | name.erase(name.size() - 1); 87 | } 88 | result.push_back(name); 89 | start = end + 1; 90 | end = str.find(delim, start); 91 | } 92 | if (start < str.length()) { 93 | std::wstring name = str.substr(start); 94 | if (!enclosure.empty() && !name.empty() && 95 | name.front() == enclosure.front()) { 96 | name.erase(0, 1); 97 | } 98 | if (!enclosure.empty() && !name.empty() && 99 | name.back() == enclosure.back()) { 100 | name.erase(name.size() - 1); 101 | } 102 | result.push_back(name); 103 | } 104 | return result; 105 | } 106 | 107 | // Compression html. 108 | std::string& ltrim(std::string& s) { 109 | s.erase(s.begin(), std::find_if(s.begin(), s.end(), 110 | [](int ch) { return !std::isspace(ch); })); 111 | return s; 112 | } 113 | std::string& rtrim(std::string& s) { 114 | s.erase(std::find_if(s.rbegin(), s.rend(), 115 | [](int ch) { return !std::isspace(ch); }) 116 | .base(), 117 | s.end()); 118 | return s; 119 | } 120 | 121 | std::string& trim(std::string& s) { 122 | return ltrim(rtrim(s)); 123 | } 124 | 125 | std::vector split(const std::string& text, char sep) { 126 | std::vector tokens; 127 | std::size_t start = 0, end = 0; 128 | while ((end = text.find(sep, start)) != std::string::npos) { 129 | std::string temp = text.substr(start, end - start); 130 | tokens.push_back(temp); 131 | start = end + 1; 132 | } 133 | std::string temp = text.substr(start); 134 | tokens.push_back(temp); 135 | return tokens; 136 | } 137 | 138 | void compression_html(std::string& html) { 139 | auto lines = split(html, '\n'); 140 | html.clear(); 141 | for (auto& line : lines) { 142 | html += "\n"; 143 | html += trim(line); 144 | } 145 | } 146 | 147 | bool ReplaceStringInPlace(std::string& subject, 148 | const std::string& search, 149 | const std::string& replace) { 150 | bool find = false; 151 | size_t pos = 0; 152 | while ((pos = subject.find(search, pos)) != std::string::npos) { 153 | subject.replace(pos, search.length(), replace); 154 | pos += replace.length(); 155 | find = true; 156 | } 157 | return find; 158 | } 159 | 160 | bool ReplaceStringInPlace(std::wstring& subject, 161 | const std::wstring& search, 162 | const std::wstring& replace) { 163 | bool find = false; 164 | size_t pos = 0; 165 | while ((pos = subject.find(search, pos)) != std::wstring::npos) { 166 | subject.replace(pos, search.length(), replace); 167 | pos += replace.length(); 168 | find = true; 169 | } 170 | return find; 171 | } 172 | 173 | std::wstring QuoteSpaceIfNeeded(const std::wstring& str) { 174 | if (str.find(L' ') == std::wstring::npos) 175 | return std::move(str); 176 | 177 | std::wstring escaped(L"\""); 178 | for (auto c : str) { 179 | if (c == L'"') 180 | escaped += L'"'; 181 | escaped += c; 182 | } 183 | escaped += L'"'; 184 | return std::move(escaped); 185 | } 186 | 187 | std::wstring JoinArgsString(std::vector lines, 188 | const std::wstring& delimiter) { 189 | std::wstring text; 190 | bool first = true; 191 | for (auto& line : lines) { 192 | if (!first) 193 | text += delimiter; 194 | else 195 | first = false; 196 | text += QuoteSpaceIfNeeded(line); 197 | } 198 | return text; 199 | } 200 | 201 | // Memory and module search functions. 202 | // Search memory. 203 | uint8_t* memmem(uint8_t* src, int n, const uint8_t* sub, int m) { 204 | return (uint8_t*)FastSearch(src, n, sub, m); 205 | } 206 | 207 | uint8_t* SearchModuleRaw(HMODULE module, const uint8_t* sub, int m) { 208 | uint8_t* buffer = (uint8_t*)module; 209 | 210 | PIMAGE_NT_HEADERS nt_header = 211 | (PIMAGE_NT_HEADERS)(buffer + ((PIMAGE_DOS_HEADER)buffer)->e_lfanew); 212 | PIMAGE_SECTION_HEADER section = 213 | (PIMAGE_SECTION_HEADER)((char*)nt_header + sizeof(DWORD) + 214 | sizeof(IMAGE_FILE_HEADER) + 215 | nt_header->FileHeader.SizeOfOptionalHeader); 216 | 217 | for (int i = 0; i < nt_header->FileHeader.NumberOfSections; ++i) { 218 | if (strcmp((const char*)section[i].Name, ".text") == 0) { 219 | return memmem(buffer + section[i].PointerToRawData, 220 | section[i].SizeOfRawData, sub, m); 221 | break; 222 | } 223 | } 224 | return nullptr; 225 | } 226 | 227 | uint8_t* SearchModuleRaw2(HMODULE module, const uint8_t* sub, int m) { 228 | uint8_t* buffer = (uint8_t*)module; 229 | 230 | PIMAGE_NT_HEADERS nt_header = 231 | (PIMAGE_NT_HEADERS)(buffer + ((PIMAGE_DOS_HEADER)buffer)->e_lfanew); 232 | PIMAGE_SECTION_HEADER section = 233 | (PIMAGE_SECTION_HEADER)((char*)nt_header + sizeof(DWORD) + 234 | sizeof(IMAGE_FILE_HEADER) + 235 | nt_header->FileHeader.SizeOfOptionalHeader); 236 | 237 | for (int i = 0; i < nt_header->FileHeader.NumberOfSections; ++i) { 238 | if (strcmp((const char*)section[i].Name, ".rdata") == 0) { 239 | return memmem(buffer + section[i].PointerToRawData, 240 | section[i].SizeOfRawData, sub, m); 241 | break; 242 | } 243 | } 244 | return nullptr; 245 | } 246 | 247 | // bool WriteMemory(PBYTE BaseAddress, PBYTE Buffer, DWORD nSize) { 248 | // DWORD ProtectFlag = 0; 249 | // if (VirtualProtectEx(GetCurrentProcess(), BaseAddress, nSize, 250 | // PAGE_EXECUTE_READWRITE, &ProtectFlag)) { 251 | // memcpy(BaseAddress, Buffer, nSize); 252 | // FlushInstructionCache(GetCurrentProcess(), BaseAddress, nSize); 253 | // VirtualProtectEx(GetCurrentProcess(), BaseAddress, nSize, ProtectFlag, 254 | // &ProtectFlag); 255 | // return true; 256 | // } 257 | // return false; 258 | // } 259 | 260 | // Path and file manipulation functions. 261 | // Get the directory where the application is located. 262 | std::wstring GetAppDir() { 263 | wchar_t path[MAX_PATH]; 264 | ::GetModuleFileName(nullptr, path, MAX_PATH); 265 | ::PathRemoveFileSpec(path); 266 | return path; 267 | } 268 | 269 | bool isEndWith(const wchar_t* s, const wchar_t* sub) { 270 | if (!s || !sub) 271 | return false; 272 | size_t len1 = wcslen(s); 273 | size_t len2 = wcslen(sub); 274 | if (len2 > len1) 275 | return false; 276 | return !_memicmp(s + len1 - len2, sub, len2 * sizeof(wchar_t)); 277 | } 278 | 279 | const std::wstring kIniPath = GetAppDir() + L"\\chrome++.ini"; 280 | 281 | // Prase the INI file. 282 | std::wstring GetIniString(const std::wstring& section, 283 | const std::wstring& key, 284 | const std::wstring& default_value) { 285 | std::vector buffer(100); 286 | DWORD bytesread = 0; 287 | do { 288 | bytesread = ::GetPrivateProfileStringW( 289 | section.c_str(), key.c_str(), default_value.c_str(), buffer.data(), 290 | (DWORD)buffer.size(), kIniPath.c_str()); 291 | if (bytesread >= buffer.size() - 1) { 292 | buffer.resize(buffer.size() * 2); 293 | } else { 294 | break; 295 | } 296 | } while (true); 297 | 298 | return std::wstring(buffer.data()); 299 | } 300 | 301 | // Canonicalize the path. 302 | std::wstring CanonicalizePath(const std::wstring& path) { 303 | TCHAR temp[MAX_PATH]; 304 | ::PathCanonicalize(temp, path.data()); 305 | return std::wstring(temp); 306 | } 307 | 308 | // Get the absolute path. 309 | std::wstring GetAbsolutePath(const std::wstring& path) { 310 | wchar_t buffer[MAX_PATH]; 311 | ::GetFullPathNameW(path.c_str(), MAX_PATH, buffer, nullptr); 312 | return buffer; 313 | } 314 | 315 | // Expand environment variables in the path. 316 | std::wstring ExpandEnvironmentPath(const std::wstring& path) { 317 | std::vector buffer(MAX_PATH); 318 | size_t ExpandedLength = ::ExpandEnvironmentStrings(path.c_str(), &buffer[0], 319 | (DWORD)buffer.size()); 320 | if (ExpandedLength > buffer.size()) { 321 | buffer.resize(ExpandedLength); 322 | ExpandedLength = ::ExpandEnvironmentStrings(path.c_str(), &buffer[0], 323 | (DWORD)buffer.size()); 324 | } 325 | return std::wstring(&buffer[0], 0, ExpandedLength); 326 | } 327 | 328 | // Debug log function. 329 | void DebugLog(const wchar_t* format, ...) { 330 | // va_list args; 331 | 332 | // va_start(args, format); 333 | // auto str = Format(format, args); 334 | // va_end(args); 335 | 336 | // str = Format(L"[chrome++] %s\n", str.c_str()); 337 | 338 | // std::string nstr = wstring_to_string(str); 339 | // const char* cstr = nstr.c_str(); 340 | 341 | // FILE* fp = nullptr; 342 | // std::wstring logPath = GetAppDir() + L"\\Chrome++_Debug.log"; 343 | // _wfopen_s(&fp, logPath.c_str(), L"a+"); 344 | // if (fp) { 345 | // fwrite(cstr, strlen(cstr), 1, fp); 346 | // fclose(fp); 347 | // } 348 | } 349 | 350 | // Window and message processing functions. 351 | HWND GetTopWnd(HWND hwnd) { 352 | while (::GetParent(hwnd) && ::IsWindowVisible(::GetParent(hwnd))) { 353 | hwnd = ::GetParent(hwnd); 354 | } 355 | return hwnd; 356 | } 357 | 358 | void ExecuteCommand(int id, HWND hwnd = 0) { 359 | if (hwnd == 0) 360 | hwnd = GetForegroundWindow(); 361 | // hwnd = GetTopWnd(hwnd); 362 | // hwnd = GetForegroundWindow(); 363 | // PostMessage(hwnd, WM_SYSCOMMAND, id, 0); 364 | ::SendMessageTimeoutW(hwnd, WM_SYSCOMMAND, id, 0, 0, 1000, 0); 365 | } 366 | 367 | HANDLE RunExecute(const wchar_t* command, WORD show = SW_SHOW) { 368 | int nArgs = 0; 369 | std::vector command_line; 370 | LPWSTR* szArglist = CommandLineToArgvW(command, &nArgs); 371 | for (int i = 0; i < nArgs; ++i) { 372 | command_line.push_back(QuoteSpaceIfNeeded(szArglist[i])); 373 | } 374 | LocalFree(szArglist); 375 | 376 | SHELLEXECUTEINFO ShExecInfo = {0}; 377 | ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); 378 | ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; 379 | ShExecInfo.lpFile = command_line[0].c_str(); 380 | ShExecInfo.nShow = show; 381 | 382 | std::wstring parameter; 383 | for (size_t i = 1; i < command_line.size(); ++i) { 384 | parameter += command_line[i]; 385 | parameter += L" "; 386 | } 387 | if (command_line.size() > 1) { 388 | ShExecInfo.lpParameters = parameter.c_str(); 389 | } 390 | if (ShellExecuteEx(&ShExecInfo)) { 391 | return ShExecInfo.hProcess; 392 | } 393 | return nullptr; 394 | } 395 | 396 | bool IsFullScreen(HWND hwnd) { 397 | RECT windowRect; 398 | return (GetWindowRect(hwnd, &windowRect) && 399 | (windowRect.left == 0 && windowRect.top == 0 && 400 | windowRect.right == GetSystemMetrics(SM_CXSCREEN) && 401 | windowRect.bottom == GetSystemMetrics(SM_CYSCREEN))); 402 | } 403 | 404 | // Keyboard and mouse input functions. 405 | // Send the combined key operation. 406 | // class SendKeys { 407 | // public: 408 | // template 409 | // SendKeys(T... keys) { 410 | // std::vector keys_ = {keys...}; 411 | // for (auto& key : keys_) { 412 | // INPUT input = {0}; 413 | // input.type = INPUT_KEYBOARD; 414 | // input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; 415 | // input.ki.wVk = key; 416 | 417 | // // Correct the mouse message 418 | // switch (key) { 419 | // case VK_MBUTTON: 420 | // input.type = INPUT_MOUSE; 421 | // input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; 422 | // break; 423 | // } 424 | 425 | // inputs_.push_back(input); 426 | // } 427 | 428 | // SendInput((UINT)inputs_.size(), &inputs_[0], sizeof(INPUT)); 429 | // } 430 | // ~SendKeys() { 431 | // for (auto& input : inputs_) { 432 | // input.ki.dwFlags |= KEYEVENTF_KEYUP; 433 | 434 | // // Correct the mouse message 435 | // switch (input.ki.wVk) { 436 | // case VK_MBUTTON: 437 | // input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; 438 | // break; 439 | // } 440 | // } 441 | 442 | // SendInput((UINT)inputs_.size(), &inputs_[0], sizeof(INPUT)); 443 | // } 444 | 445 | // private: 446 | // std::vector inputs_; 447 | // }; 448 | 449 | template 450 | void SendKey(T&&... keys) { 451 | std::vector::type> keys_ = { 452 | std::forward(keys)...}; 453 | std::vector inputs{}; 454 | inputs.reserve(keys_.size() * 2); 455 | for (auto& key : keys_) { 456 | INPUT input = {0}; 457 | // Adjust mouse messages 458 | switch (key) { 459 | case VK_RBUTTON: 460 | input.type = INPUT_MOUSE; 461 | input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE 462 | ? MOUSEEVENTF_LEFTDOWN 463 | : MOUSEEVENTF_RIGHTDOWN; 464 | input.mi.dwExtraInfo = MAGIC_CODE; 465 | break; 466 | case VK_LBUTTON: 467 | input.type = INPUT_MOUSE; 468 | input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE 469 | ? MOUSEEVENTF_RIGHTDOWN 470 | : MOUSEEVENTF_LEFTDOWN; 471 | input.mi.dwExtraInfo = MAGIC_CODE; 472 | break; 473 | case VK_MBUTTON: 474 | input.type = INPUT_MOUSE; 475 | input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; 476 | input.mi.dwExtraInfo = MAGIC_CODE; 477 | break; 478 | default: 479 | input.type = INPUT_KEYBOARD; 480 | input.ki.wVk = (WORD)key; 481 | input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; 482 | input.ki.dwExtraInfo = MAGIC_CODE; 483 | break; 484 | } 485 | inputs.emplace_back(std::move(input)); 486 | } 487 | for (auto& key : keys_) { 488 | INPUT input = {0}; 489 | // Adjust mouse messages 490 | switch (key) { 491 | case VK_RBUTTON: 492 | input.type = INPUT_MOUSE; 493 | input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE 494 | ? MOUSEEVENTF_LEFTUP 495 | : MOUSEEVENTF_RIGHTUP; 496 | input.mi.dwExtraInfo = MAGIC_CODE; 497 | break; 498 | case VK_LBUTTON: 499 | input.type = INPUT_MOUSE; 500 | input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE 501 | ? MOUSEEVENTF_RIGHTUP 502 | : MOUSEEVENTF_LEFTUP; 503 | input.mi.dwExtraInfo = MAGIC_CODE; 504 | break; 505 | case VK_MBUTTON: 506 | input.type = INPUT_MOUSE; 507 | input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP; 508 | input.mi.dwExtraInfo = MAGIC_CODE; 509 | break; 510 | default: 511 | input.type = INPUT_KEYBOARD; 512 | input.ki.dwFlags = KEYEVENTF_KEYUP; 513 | input.ki.wVk = (WORD)key; 514 | input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; 515 | input.ki.dwExtraInfo = MAGIC_CODE; 516 | break; 517 | } 518 | inputs.emplace_back(std::move(input)); 519 | } 520 | SendInput((UINT)inputs.size(), &inputs[0], sizeof(INPUT)); 521 | } 522 | 523 | // Send a single key operation. 524 | void SendOneMouse(int mouse) { 525 | // Swap the left and right mouse buttons (if defined). 526 | if (::GetSystemMetrics(SM_SWAPBUTTON) == TRUE) { 527 | if (mouse == MOUSEEVENTF_RIGHTDOWN) 528 | mouse = MOUSEEVENTF_LEFTDOWN; 529 | else if (mouse == MOUSEEVENTF_RIGHTUP) 530 | mouse = MOUSEEVENTF_LEFTUP; 531 | } 532 | 533 | INPUT input[1]; 534 | memset(input, 0, sizeof(input)); 535 | 536 | input[0].type = INPUT_MOUSE; 537 | 538 | input[0].mi.dwFlags = mouse; 539 | input[0].mi.dwExtraInfo = MAGIC_CODE; 540 | ::SendInput(1, input, sizeof(INPUT)); 541 | } 542 | 543 | #endif // UTILS_H_ 544 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H_ 2 | #define VERSION_H_ 3 | 4 | #define RELEASE_VER_MAIN 1 5 | #define RELEASE_VER_SUB 11 6 | #define RELEASE_VER_FIX 1 7 | 8 | #define TOSTRING2(arg) #arg 9 | #define TOSTRING(arg) TOSTRING2(arg) 10 | 11 | #define RELEASE_VER_STR \ 12 | TOSTRING(RELEASE_VER_MAIN) \ 13 | "." TOSTRING(RELEASE_VER_SUB) "." TOSTRING(RELEASE_VER_FIX) 14 | 15 | #endif // VERSION_H_ 16 | -------------------------------------------------------------------------------- /xmake.lua: -------------------------------------------------------------------------------- 1 | includes("VC-LTL5.lua") 2 | 3 | add_rules("mode.debug", "mode.release") 4 | 5 | set_warnings("more") 6 | 7 | add_defines("WIN32", "_WIN32") 8 | add_defines("UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_DEPRECATE") 9 | 10 | if is_mode("release") then 11 | add_defines("NDEBUG") 12 | add_cxflags("/O2", "/Os", "/Gy", "/MT", "/EHsc", "/fp:precise") 13 | add_ldflags("/DYNAMICBASE", "/LTCG") 14 | end 15 | 16 | add_cxflags("/utf-8") 17 | 18 | -- add_links("gdiplus", "kernel32", "user32", "gdi32", "winspool", "comdlg32") 19 | -- add_links("advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32") 20 | add_links("kernel32", "user32", "shell32", "oleaut32", "propsys", "shlwapi", "crypt32", "advapi32", "netapi32") 21 | 22 | target("detours") 23 | set_kind("static") 24 | add_files("detours/src/*.cpp|uimports.cpp") 25 | add_includedirs("detours/src", {public=true}) 26 | 27 | target("chrome_plus") 28 | set_kind("shared") 29 | set_targetdir("$(buildir)/release") 30 | set_basename("version") 31 | add_deps("detours") 32 | add_links("detours") 33 | add_files("src/*.cpp") 34 | add_files("src/*.rc") 35 | add_links("user32") 36 | add_cxflags("/std:c++17") 37 | after_build(function (target) 38 | os.rm("$(buildir)/release/version.exp") 39 | os.rm("$(buildir)/release/version.lib") 40 | end) --------------------------------------------------------------------------------