From 5bf5fb07a2feb21e2513d515c831526522fa68fc Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Fri, 31 Mar 2023 17:05:12 -0400 Subject: [PATCH] Move scripts away from the root directory --- .github/workflows/language_lint.yml | 6 +- .github/workflows/lint_commit.yml | 8 +- gradlew-clean.bat | 1 - gradlew-jar.bat | 2 - .../format_whitespace.py | 0 scripts/gradlew-clean.bat | 4 + scripts/gradlew-jar.bat | 4 + install.sh => scripts/install/install.sh | 0 .../install/install_without_dependencies.sh | 0 .../manage_languages.py | 0 proxy.py => scripts/proxy.py | 310 +++++++++--------- proxy_config.py => scripts/proxy_config.py | 34 +- 12 files changed, 187 insertions(+), 182 deletions(-) delete mode 100644 gradlew-clean.bat delete mode 100644 gradlew-jar.bat rename format_whitespace.py => scripts/format_whitespace.py (100%) create mode 100644 scripts/gradlew-clean.bat create mode 100644 scripts/gradlew-jar.bat rename install.sh => scripts/install/install.sh (100%) rename install_without_dependencies.sh => scripts/install/install_without_dependencies.sh (100%) rename manage_languages.py => scripts/manage_languages.py (100%) rename proxy.py => scripts/proxy.py (96%) rename proxy_config.py => scripts/proxy_config.py (96%) diff --git a/.github/workflows/language_lint.yml b/.github/workflows/language_lint.yml index 9fb7423cf..b0f176ad6 100644 --- a/.github/workflows/language_lint.yml +++ b/.github/workflows/language_lint.yml @@ -6,7 +6,7 @@ on: - ".github/workflows/**" - "src/main/**.java" - "**.json" - - "manage_languages.py" + - "scripts/manage_languages.py" branches: - "stable" - "development" @@ -15,7 +15,7 @@ on: - ".github/workflows/**" - "src/main/**.java" - "**.json" - - "manage_languages.py" + - "scripts/manage_languages.py" types: - opened - synchronize @@ -28,4 +28,4 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.10' # Version range or exact version of a Python version to use, using SemVer's version range syntax - - run: python3 manage_languages.py -l + - run: python3 scripts/manage_languages.py -l diff --git a/.github/workflows/lint_commit.yml b/.github/workflows/lint_commit.yml index 756405650..c1abd8538 100644 --- a/.github/workflows/lint_commit.yml +++ b/.github/workflows/lint_commit.yml @@ -7,8 +7,8 @@ on: - "src/main/**.java" - "**.json" - "build.gradle" - - "format_whitespace.py" - - "manage_languages.py" + - "scripts/format_whitespace.py" + - "scripts/manage_languages.py" branches: - "development" jobs: @@ -24,7 +24,7 @@ jobs: with: python-version: '3.10' - name: Run Whitespace Linter - run: python format_whitespace.py + run: python scripts/format_whitespace.py - run: git config --global user.name "github-actions" - run: git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - run: git stash @@ -37,7 +37,7 @@ jobs: run: git add -u && git commit -m 'Fix whitespace [skip actions]' || true - name: Update Languages - run: python manage_languages.py -u + run: python scripts/manage_languages.py -u - name: Commit any language changes run: git add -u && git commit -m 'Update languages [skip actions]' || true diff --git a/gradlew-clean.bat b/gradlew-clean.bat deleted file mode 100644 index df89ee3f5..000000000 --- a/gradlew-clean.bat +++ /dev/null @@ -1 +0,0 @@ -./gradlew clean \ No newline at end of file diff --git a/gradlew-jar.bat b/gradlew-jar.bat deleted file mode 100644 index d9fde181e..000000000 --- a/gradlew-jar.bat +++ /dev/null @@ -1,2 +0,0 @@ -call .\gradlew jar -pause diff --git a/format_whitespace.py b/scripts/format_whitespace.py similarity index 100% rename from format_whitespace.py rename to scripts/format_whitespace.py diff --git a/scripts/gradlew-clean.bat b/scripts/gradlew-clean.bat new file mode 100644 index 000000000..de2760893 --- /dev/null +++ b/scripts/gradlew-clean.bat @@ -0,0 +1,4 @@ +@echo off + +call ..\gradlew clean +pause diff --git a/scripts/gradlew-jar.bat b/scripts/gradlew-jar.bat new file mode 100644 index 000000000..c59598386 --- /dev/null +++ b/scripts/gradlew-jar.bat @@ -0,0 +1,4 @@ +@echo off + +call ..\gradlew jar +pause diff --git a/install.sh b/scripts/install/install.sh similarity index 100% rename from install.sh rename to scripts/install/install.sh diff --git a/install_without_dependencies.sh b/scripts/install/install_without_dependencies.sh similarity index 100% rename from install_without_dependencies.sh rename to scripts/install/install_without_dependencies.sh diff --git a/manage_languages.py b/scripts/manage_languages.py similarity index 100% rename from manage_languages.py rename to scripts/manage_languages.py diff --git a/proxy.py b/scripts/proxy.py similarity index 96% rename from proxy.py rename to scripts/proxy.py index 601877eb3..06fea5900 100644 --- a/proxy.py +++ b/scripts/proxy.py @@ -1,155 +1,155 @@ -## -# -# Copyright (C) 2002-2022 MlgmXyysd All Rights Reserved. -# -## - -## -# -# Animation Company script for mitmproxy -# -# https://github.com/MlgmXyysd/ -# -# *Original fiddler script from https://github.lunatic.moe/fiddlerscript -# -# Environment requirement: -# - mitmdump from mitmproxy -# -# @author MlgmXyysd -# @version 1.1 -# -## - -import collections -import random -from mitmproxy import http, connection, ctx, tls -from abc import ABC, abstractmethod -from enum import Enum -from mitmproxy.utils import human -from proxy_config import USE_SSL -from proxy_config import REMOTE_HOST -from proxy_config import REMOTE_PORT - -class MlgmXyysd_Animation_Company_Proxy: - - LIST_DOMAINS = [ - "api-os-takumi.mihoyo.com", - "hk4e-api-os-static.mihoyo.com", - "hk4e-sdk-os.mihoyo.com", - "dispatchosglobal.yuanshen.com", - "osusadispatch.yuanshen.com", - "account.mihoyo.com", - "log-upload-os.mihoyo.com", - "dispatchcntest.yuanshen.com", - "devlog-upload.mihoyo.com", - "webstatic.mihoyo.com", - "log-upload.mihoyo.com", - "hk4e-sdk.mihoyo.com", - "api-beta-sdk.mihoyo.com", - "api-beta-sdk-os.mihoyo.com", - "cnbeta01dispatch.yuanshen.com", - "dispatchcnglobal.yuanshen.com", - "cnbeta02dispatch.yuanshen.com", - "sdk-os-static.mihoyo.com", - "webstatic-sea.mihoyo.com", - "webstatic-sea.hoyoverse.com", - "hk4e-sdk-os-static.hoyoverse.com", - "sdk-os-static.hoyoverse.com", - "api-account-os.hoyoverse.com", - "hk4e-sdk-os.hoyoverse.com", - "overseauspider.yuanshen.com", - "gameapi-account.mihoyo.com", - "minor-api.mihoyo.com", - "public-data-api.mihoyo.com", - "uspider.yuanshen.com", - "sdk-static.mihoyo.com", - "abtest-api-data-sg.hoyoverse.com", - "log-upload-os.hoyoverse.com" - ] - - def request(self, flow: http.HTTPFlow) -> None: - if flow.request.host in self.LIST_DOMAINS: - if USE_SSL: - flow.request.scheme = "https" - else: - flow.request.scheme = "http" - flow.request.host = REMOTE_HOST - flow.request.port = REMOTE_PORT - -class InterceptionResult(Enum): - SUCCESS = 1 - FAILURE = 2 - SKIPPED = 3 - - -class TlsStrategy(ABC): - def __init__(self): - self.history = collections.defaultdict(lambda: collections.deque(maxlen=200)) - - @abstractmethod - def should_intercept(self, server_address: connection.Address) -> bool: - raise NotImplementedError() - - def record_success(self, server_address): - self.history[server_address].append(InterceptionResult.SUCCESS) - - def record_failure(self, server_address): - self.history[server_address].append(InterceptionResult.FAILURE) - - def record_skipped(self, server_address): - self.history[server_address].append(InterceptionResult.SKIPPED) - - -class ConservativeStrategy(TlsStrategy): - def should_intercept(self, server_address: connection.Address) -> bool: - return InterceptionResult.FAILURE not in self.history[server_address] - - -class ProbabilisticStrategy(TlsStrategy): - def __init__(self, p: float): - self.p = p - super().__init__() - - def should_intercept(self, server_address: connection.Address) -> bool: - return random.uniform(0, 1) < self.p - - -class MaybeTls: - strategy: TlsStrategy - - def load(self, l): - l.add_option( - "tls_strategy", int, 0, - "TLS passthrough strategy. If set to 0, connections will be passed through after the first unsuccessful " - "handshake. If set to 0 < p <= 100, connections with be passed through with probability p.", - ) - - def configure(self, updated): - if "tls_strategy" not in updated: - return - if ctx.options.tls_strategy > 0: - self.strategy = ProbabilisticStrategy(ctx.options.tls_strategy / 100) - else: - self.strategy = ConservativeStrategy() - - def tls_clienthello(self, data: tls.ClientHelloData): - server_address = data.context.server.peername - if not self.strategy.should_intercept(server_address): - ctx.log(f"TLS passthrough: {human.format_address(server_address)}.") - data.ignore_connection = True - self.strategy.record_skipped(server_address) - - def tls_established_client(self, data: tls.TlsData): - server_address = data.context.server.peername - ctx.log(f"TLS handshake successful: {human.format_address(server_address)}") - self.strategy.record_success(server_address) - - def tls_failed_client(self, data: tls.TlsData): - server_address = data.context.server.peername - ctx.log(f"TLS handshake failed: {human.format_address(server_address)}") - self.strategy.record_failure(server_address) - -addons = [ - MlgmXyysd_Animation_Company_Proxy(), - MaybeTls() -] +## +# +# Copyright (C) 2002-2022 MlgmXyysd All Rights Reserved. +# +## + +## +# +# Animation Company script for mitmproxy +# +# https://github.com/MlgmXyysd/ +# +# *Original fiddler script from https://github.lunatic.moe/fiddlerscript +# +# Environment requirement: +# - mitmdump from mitmproxy +# +# @author MlgmXyysd +# @version 1.1 +# +## + +import collections +import random +from mitmproxy import http, connection, ctx, tls +from abc import ABC, abstractmethod +from enum import Enum +from mitmproxy.utils import human +from proxy_config import USE_SSL +from proxy_config import REMOTE_HOST +from proxy_config import REMOTE_PORT + +class MlgmXyysd_Animation_Company_Proxy: + + LIST_DOMAINS = [ + "api-os-takumi.mihoyo.com", + "hk4e-api-os-static.mihoyo.com", + "hk4e-sdk-os.mihoyo.com", + "dispatchosglobal.yuanshen.com", + "osusadispatch.yuanshen.com", + "account.mihoyo.com", + "log-upload-os.mihoyo.com", + "dispatchcntest.yuanshen.com", + "devlog-upload.mihoyo.com", + "webstatic.mihoyo.com", + "log-upload.mihoyo.com", + "hk4e-sdk.mihoyo.com", + "api-beta-sdk.mihoyo.com", + "api-beta-sdk-os.mihoyo.com", + "cnbeta01dispatch.yuanshen.com", + "dispatchcnglobal.yuanshen.com", + "cnbeta02dispatch.yuanshen.com", + "sdk-os-static.mihoyo.com", + "webstatic-sea.mihoyo.com", + "webstatic-sea.hoyoverse.com", + "hk4e-sdk-os-static.hoyoverse.com", + "sdk-os-static.hoyoverse.com", + "api-account-os.hoyoverse.com", + "hk4e-sdk-os.hoyoverse.com", + "overseauspider.yuanshen.com", + "gameapi-account.mihoyo.com", + "minor-api.mihoyo.com", + "public-data-api.mihoyo.com", + "uspider.yuanshen.com", + "sdk-static.mihoyo.com", + "abtest-api-data-sg.hoyoverse.com", + "log-upload-os.hoyoverse.com" + ] + + def request(self, flow: http.HTTPFlow) -> None: + if flow.request.host in self.LIST_DOMAINS: + if USE_SSL: + flow.request.scheme = "https" + else: + flow.request.scheme = "http" + flow.request.host = REMOTE_HOST + flow.request.port = REMOTE_PORT + +class InterceptionResult(Enum): + SUCCESS = 1 + FAILURE = 2 + SKIPPED = 3 + + +class TlsStrategy(ABC): + def __init__(self): + self.history = collections.defaultdict(lambda: collections.deque(maxlen=200)) + + @abstractmethod + def should_intercept(self, server_address: connection.Address) -> bool: + raise NotImplementedError() + + def record_success(self, server_address): + self.history[server_address].append(InterceptionResult.SUCCESS) + + def record_failure(self, server_address): + self.history[server_address].append(InterceptionResult.FAILURE) + + def record_skipped(self, server_address): + self.history[server_address].append(InterceptionResult.SKIPPED) + + +class ConservativeStrategy(TlsStrategy): + def should_intercept(self, server_address: connection.Address) -> bool: + return InterceptionResult.FAILURE not in self.history[server_address] + + +class ProbabilisticStrategy(TlsStrategy): + def __init__(self, p: float): + self.p = p + super().__init__() + + def should_intercept(self, server_address: connection.Address) -> bool: + return random.uniform(0, 1) < self.p + + +class MaybeTls: + strategy: TlsStrategy + + def load(self, l): + l.add_option( + "tls_strategy", int, 0, + "TLS passthrough strategy. If set to 0, connections will be passed through after the first unsuccessful " + "handshake. If set to 0 < p <= 100, connections with be passed through with probability p.", + ) + + def configure(self, updated): + if "tls_strategy" not in updated: + return + if ctx.options.tls_strategy > 0: + self.strategy = ProbabilisticStrategy(ctx.options.tls_strategy / 100) + else: + self.strategy = ConservativeStrategy() + + def tls_clienthello(self, data: tls.ClientHelloData): + server_address = data.context.server.peername + if not self.strategy.should_intercept(server_address): + ctx.log(f"TLS passthrough: {human.format_address(server_address)}.") + data.ignore_connection = True + self.strategy.record_skipped(server_address) + + def tls_established_client(self, data: tls.TlsData): + server_address = data.context.server.peername + ctx.log(f"TLS handshake successful: {human.format_address(server_address)}") + self.strategy.record_success(server_address) + + def tls_failed_client(self, data: tls.TlsData): + server_address = data.context.server.peername + ctx.log(f"TLS handshake failed: {human.format_address(server_address)}") + self.strategy.record_failure(server_address) + +addons = [ + MlgmXyysd_Animation_Company_Proxy(), + MaybeTls() +] diff --git a/proxy_config.py b/scripts/proxy_config.py similarity index 96% rename from proxy_config.py rename to scripts/proxy_config.py index 07bac1a3a..b2d45b8bc 100644 --- a/proxy_config.py +++ b/scripts/proxy_config.py @@ -1,17 +1,17 @@ -import os - -# This can also be replaced with another IP address. -USE_SSL = True -REMOTE_HOST = "localhost" -REMOTE_PORT = 443 - -if os.getenv('MITM_REMOTE_HOST') != None: - REMOTE_HOST = os.getenv('MITM_REMOTE_HOST') -if os.getenv('MITM_REMOTE_PORT') != None: - REMOTE_PORT = int(os.getenv('MITM_REMOTE_PORT')) -if os.getenv('MITM_USE_SSL') != None: - USE_SSL = bool(os.getenv('MITM_USE_SSL')) - -print('MITM Remote Host: ' + REMOTE_HOST) -print('MITM Remote Port: ' + str(REMOTE_PORT)) -print('MITM Use SSL ' + str(USE_SSL)) +import os + +# This can also be replaced with another IP address. +USE_SSL = True +REMOTE_HOST = "localhost" +REMOTE_PORT = 443 + +if os.getenv('MITM_REMOTE_HOST') != None: + REMOTE_HOST = os.getenv('MITM_REMOTE_HOST') +if os.getenv('MITM_REMOTE_PORT') != None: + REMOTE_PORT = int(os.getenv('MITM_REMOTE_PORT')) +if os.getenv('MITM_USE_SSL') != None: + USE_SSL = bool(os.getenv('MITM_USE_SSL')) + +print('MITM Remote Host: ' + REMOTE_HOST) +print('MITM Remote Port: ' + str(REMOTE_PORT)) +print('MITM Use SSL ' + str(USE_SSL))