### Define Application Installation and Asset Bundling Rules Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/CMakeLists.txt This comprehensive section defines the installation process for the application. It sets up destination directories, ensures the 'install' step is default in Visual Studio, and installs the main executable, Flutter ICU data, Flutter engine library, and bundled plugins. It also includes a custom command to re-copy Flutter assets on each build, preventing stale files, and installs the AOT library for Profile and Release builds. ```CMake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Configure Application Bundle Installation and Asset Copying Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Sets up the installation process to create a relocatable application bundle in the build directory. It defines the bundle structure, ensures a clean installation, and installs the executable, ICU data, Flutter library, bundled plugins, and Flutter assets into the bundle. ```CMake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### ProxyPin Root Certificate Installation Across Platforms Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Detailed instructions for installing the ProxyPin root certificate on Windows, macOS, iOS, and Android to enable HTTPS traffic decryption. This is crucial for the proxy to function correctly with encrypted connections. ```APIDOC Purpose of Root Certificate Installation: - To decrypt HTTPS traffic, ProxyPin responds with a self-signed certificate during TLS Client Hello. - Since the self-signed certificate is not from a trusted CA, it must be installed into the system's trusted root certificates. Installation - Windows: - Method: Click "Install Certificate" or double-click the certificate file. - Location: Select "Trusted Root Certification Authorities". Installation - macOS: - Method: Click "Install Certificate" or drag the certificate file to "Keychain Access" -> "System Certificates". - Trust Setting: After installation, double-click the certificate and select "Always Trust" for this certificate. Installation - iOS: - Download: From the ProxyPin iOS app (HTTPS proxy section) or via Wi-Fi proxy connection to a computer. - Step 1: Install Profile: Go to "Settings" > "Downloaded Profile" > "Install". - Step 2: Trust Certificate: Go to "Settings" > "General" > "About" > "Certificate Trust Settings" and enable trust for ProxyPin. Installation - Android: - Android < 7: User directory certificates have same permissions as system, direct installation works. - Android >= 7: User directory certificates are no longer trusted by default. Most apps require system-level installation. - Requires ROOT access for system installation. - System version < 14: Install to /system/etc/security/cacerts. - System version >= 14: Install to /apex/com.android.conscrypt/cacerts. - ROOT Solutions: - Magisk Module: Use "Magisk ProxyPinCA" module (available on GitHub: wanghongenpin/Magisk-ProxyPinCA). Install and reboot. Verify "ProxyPinCA" certificate in system certificates. - Frida: Can be used to bypass Android SSL pinning (refer to httptoolkit.com/blog/frida-certificate-pinning/). - Non-ROOT Solutions: - Xposed Module: Can intercept native requests, but not Flutter or similar requests (refer to ProxyPin Wiki for Android non-ROOT Xposed module). ``` -------------------------------- ### Configure CMake Project and Application Metadata Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Initial CMake setup defining minimum version, project name, C++ language, application binary name, and a unique GTK application ID. It also sets the RPATH for bundled libraries and enables modern CMake policies to avoid warnings. ```CMake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "ProxyPin") set(APPLICATION_ID "com.network.proxy") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### ProxyPin Built-in File Operations API Source: https://github.com/wanghongenpin/proxypin/wiki/脚本 Provides an API for file system operations, mirroring Dart's `File` class. It supports creating file objects, asynchronous and synchronous reading/writing of string and byte content, checking file existence, getting file size, renaming, and directory creation. Asynchronous methods are recommended. ```APIDOC File(path): - Description: Creates a file object. - Parameters: - path: The file's path (String). Methods: - All methods have synchronous versions (e.g., readAsStringSync()). Asynchronous versions are recommended. readAsString(): - Description: Asynchronously reads file content and returns a string. - Returns: Promise readAsStringSync(): - Description: Synchronously reads file content and returns a string (not recommended). - Returns: String readAsBytes(): - Description: Asynchronously reads file content and returns a byte list. - Returns: Promise readAsBytesSync(): - Description: Synchronously reads file content and returns a byte list. - Returns: ArrayBuffer writeAsString(content, append): - Description: Asynchronously writes string content to file. - Parameters: - content: The string content to write. - append: Boolean, true to append, false to overwrite. - Returns: Promise writeAsBytes(bytes): - Description: Asynchronously writes byte list content to file. - Parameters: - bytes: The byte list content to write. - Returns: Promise exists(): - Description: Asynchronously checks if the file exists. - Returns: Promise length(): - Description: Asynchronously gets the file size in bytes. - Returns: Promise rename(newPath): - Description: Renames the file to the specified path. - Parameters: - newPath: The new path for the file. - Returns: Promise create(recursive: bool): - Description: Creates a directory. - Parameters: - recursive: Boolean, if true, creates parent directories as needed. - Returns: Promise ``` ```javascript //File(path):创建一个表示文件的对象,参数 path 是文件的路径。 var file = File('file.path'); //异步读取文件为字符串 var text = await file.readAsString(); //异步将字符串内容写入文件。 await file.writeAsString('text'); ``` -------------------------------- ### Include Flutter Generated Configuration Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This line includes a CMake configuration file (`generated_config.cmake`) that is dynamically created by the Flutter tool. This file provides essential build settings and variables tailored to the current Flutter project setup. ```CMake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Conditionally Install AOT Library in CMake Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt This CMake code block checks the current build type and installs the AOT (Ahead-Of-Time) compilation library if the build type is not 'Debug'. This is a common practice to include performance-critical components only in release or optimized builds, reducing debug build size and complexity. ```CMake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Set Flutter Library and Build Path Variables Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This section defines several key file paths and variables, including the main Flutter Linux GTK library (`libflutter_linux_gtk.so`), the ICU data file, the project's build directory, and the AOT (Ahead-of-Time) compiled application library. These variables are explicitly published to the parent scope for use in subsequent build and installation steps. ```CMake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Define and Link Main Application Executable Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Defines the main application executable, `ProxyPin`, from its source files. It applies standard compilation settings, links against Flutter and GTK libraries, adds a dependency on the `flutter_assemble` target, and sets output directory properties. ```CMake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### ProxyPin Scripting API: Context, Request, and Response Object Definitions Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Detailed definitions for the `context`, `request`, and `response` objects, outlining their properties and data types. These objects are passed as arguments to the `onRequest` and `onResponse` scripting functions, providing comprehensive access to the HTTP transaction details. ```APIDOC //context { "os": "macos", "scriptName": "Your Script Name", "deviceId": "Device ID", "session": {} //Runtime session object, parameters can be passed between different requests } //request { "method": " HTTP Method. Example: GET, POST, ...", "host": " *Read-only* Domain name. Ex: www.baidu.com, localhost, ...", "path": ": URL Path. Ex: /v1/api", "queries": "> JS dictionary object for URL parameters", "headers": "> JS dictionary object for all Header key-values", "body": " Request body string type. To convert JSON format to object, call JSON.parse(request.body)" } //response { "statusCode": 200, "headers": "> JS dictionary object containing all Header key-values", "body": " Request body string type. To convert JSON format to object, call JSON.parse(request.body)" } ``` -------------------------------- ### ProxyPin Scripting API Parameter Definitions Source: https://github.com/wanghongenpin/proxypin/wiki/脚本 Defines the structure and properties of the `context`, `request`, and `response` objects used in ProxyPin's scripting functions (`onRequest`, `onResponse`). These objects provide access to session data, HTTP methods, headers, queries, and body content for manipulation. ```APIDOC //context { "os": " Operating system (e.g., macos)", "scriptName": " Name of the script (e.g., Your Script Name)", "deviceId": " Device identifier", "session": " Runtime session object, allows parameter passing between different requests" } //request { "method": " HTTP Method. Example: GET, POST, ...", "host": " *Read-only* Domain name. Ex: www.baidu.com, localhost, ...", "path": " URL Path. Ex: /v1/api", "queries": "> JavaScript dictionary object for URL parameters", "headers": "> JavaScript dictionary object for all Header key-values", "body": " Request body as a string. For JSON format, use JSON.parse(request.body)" } //response { "statusCode": " HTTP Status Code. Example: 200", "headers": "> JavaScript dictionary object containing all Header key-values", "body": " Response body as a string. For JSON format, use JSON.parse(response.body)" } ``` -------------------------------- ### Define C++ Wrapper Libraries for Plugins and Applications Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/flutter/CMakeLists.txt This part organizes C++ source files for core, plugin-specific, and application-specific wrappers, prepending their full paths. It then defines two static libraries: `flutter_wrapper_plugin` for plugin development and `flutter_wrapper_app` for application runners. Both libraries apply standard settings, link against the `flutter` interface library, include necessary directories, and depend on `flutter_assemble` for their build artifacts. ```CMake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Deep Dive into HTTPS and TLS/SSL Protocols Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Provides a comprehensive explanation of HTTPS, its relationship with HTTP, the distinction between SSL and TLS, and a detailed breakdown of the TLS/SSL handshake process, highlighting the use of symmetric and asymmetric encryption. ```APIDOC HTTPS Protocol: - Definition: Secure version of HTTP, uses TLS/SSL encryption for data transfer security. - HTTP: Cleartext transmission, directly parsable. TLS vs. SSL: - SSL (Secure Socket Layer): Developed by Netscape, older, has security vulnerabilities. - TLS (Transport Layer Security): Upgrade to SSL, fixes vulnerabilities. - TLS 1.0 was initially SSL 3.1, renamed to disassociate from Netscape. - Current versions: TLS 1.2 or TLS 1.3. TLS/SSL Handshake Process (for security and efficiency): - Combines asymmetric encryption (for key exchange) and symmetric encryption (for data transfer). 1. Client Hello: - Client sends supported TLS version, cipher suites, and a "client random" (random bytes). 2. Server Hello: - Server responds with mutually supported TLS/SSL version and cipher suite. - Server sends its digital certificate (contains identity, public key). 3. Certificate Verification & Key Exchange: - Client verifies server's certificate (checks trusted CA list). - If valid, client uses server's public key to encrypt a randomly generated session key (asymmetric encryption). - Encrypted session key is sent to the server. 4. Encrypted Communication: - Server uses its private key to decrypt the session key. - Both client and server now use this session key for symmetric encryption of all subsequent data. - Symmetric encryption is faster for large data volumes. ``` -------------------------------- ### Configure Flutter Interface Library and Dependencies Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This comprehensive snippet first lists all Flutter Linux header files and then uses the custom `list_prepend` function to add their full paths. It then creates an `INTERFACE` library named `flutter`, configures its include directories, and links it against the main Flutter library and the previously found GTK, GLIB, and GIO system dependencies. Finally, it establishes a dependency on the `flutter_assemble` target to ensure all necessary artifacts are built. ```CMake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Define CMake Project and Application Binary Name Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/CMakeLists.txt This snippet initializes the CMake project, specifying the minimum required version and the project name 'network' with CXX language support. It also sets the `BINARY_NAME` variable to 'ProxyPin', which determines the executable's output name, and enables modern CMake policy for improved compatibility. ```CMake cmake_minimum_required(VERSION 3.14) project(network LANGUAGES CXX) set(BINARY_NAME "ProxyPin") cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Define Standard Compilation Settings Function for Targets Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/CMakeLists.txt This CMake function, `APPLY_STANDARD_SETTINGS`, encapsulates common compilation options to be applied to various targets. It enforces C++17 standard, sets warning level 4 with warnings as errors (except for 4100), enables structured exception handling, and defines `_HAS_EXCEPTIONS=0` and `_DEBUG` for debug builds. ```CMake add_definitions(-DUNICODE -D_UNICODE) function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Configure CMake Minimum Version and Project Paths Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/flutter/CMakeLists.txt This snippet sets the minimum required CMake version, defines ephemeral and wrapper directories, and includes a generated configuration file. It also provides a fallback mechanism for the `FLUTTER_TARGET_PLATFORM` variable, ensuring a default value if not already defined. ```CMake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Configure CMake for Flutter Desktop Application Build Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/runner/CMakeLists.txt This CMake configuration defines the build process for a Flutter desktop application. It sets up the project, defines the executable target, includes source files, applies standard build settings, injects Flutter version information as preprocessor definitions, disables the NOMINMAX macro to prevent conflicts, and links essential Flutter and Windows libraries. It also ensures the Flutter tool's build steps are executed. ```CMake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add preprocessor definitions for the build version. target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Implement Flutter Tool Backend Custom Commands and Targets Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/flutter/CMakeLists.txt This section sets up a 'phony' output file to ensure a custom command runs every time, as a workaround for incomplete dependency tracking. The custom command invokes the Flutter tool backend script (`tool_backend.bat`) to generate essential build artifacts like the Flutter library and C++ wrapper sources. Finally, a custom target `flutter_assemble` is defined, which depends on these generated artifacts, ensuring they are built as part of the project. ```CMake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### ProxyPin Scripting API Parameter Definitions Source: https://github.com/wanghongenpin/proxypin/wiki/Script This section defines the structure and properties of the 'context', 'request', and 'response' objects passed to the 'onRequest' and 'onResponse' functions. These objects provide access to various aspects of the HTTP transaction and script execution environment. ```APIDOC //context { "os": " Operating system (e.g., macos)", "scriptName": " Name of the current script", "deviceId": " Unique device identifier", "session": {} // Runtime session object for passing parameters between requests } //request { "method": " HTTP Method (e.g., GET, POST)", "host": " *read-only* Domain name (e.g., www.baidu.com)", "path": " URL Path (e.g., /v1/api)", "queries": "> JS Dictionary object for URL parameters", "headers": "> JS Dictionary object for all Header key-values", "body": " Request body string type. For JSON, call JSON.parse(request.body)" } //response { "statusCode": " HTTP Status Code (e.g., 200)", "headers": "> JS Dictionary object for all Header key-values", "body": " Response body string type. For JSON, call JSON.parse(response.body)" } ``` -------------------------------- ### ProxyPin Scripting API: File System Operations Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Offers asynchronous methods for interacting with the local file system within ProxyPin scripts. This includes creating file objects, reading content as strings, and writing string content to files. The API design is consistent with Dart's File class. ```JavaScript //File(path): Creates a file object, where path is the file's path. var file = File('file.path'); //Asynchronously reads the file as a string. var text = await file.readAsString(); //Asynchronously writes string content to the file. await file.writeAsString('text'); ``` -------------------------------- ### ProxyPin File System API Reference Source: https://github.com/wanghongenpin/proxypin/wiki/Script ProxyPin offers a JavaScript File API for interacting with the local file system, consistent with Dart's 'dart:io' File class. It supports asynchronous and synchronous operations for reading, writing, checking existence, and managing file attributes and directories. ```APIDOC File Class Constructor: File(path: String): Create an object representing a file. - path: The file system path. File Reading Methods: readAsString(): Promise - Asynchronously reads file contents as a string. readAsStringSync(): String - Synchronously reads file contents as a string (not recommended). readAsBytes(): Promise - Asynchronously reads file contents as a byte list. readAsBytesSync(): Uint8List - Synchronously reads file contents as a byte list. File Writing Methods: writeAsString(content: String, append: boolean = false): Promise - Asynchronously writes string content to a file. If 'append' is true, content is appended. writeAsBytes(bytes: Uint8List): Promise - Asynchronously writes byte list contents to a file. File Attribute Methods: exists(): Promise - Asynchronously checks whether the file exists. length(): Promise - Asynchronously retrieves file size in bytes. File Operation Methods: rename(newPath: String): Promise - Renames the file to the specified path. Directory Operation Methods (related to File API context): create(recursive: boolean = false): Promise - Creates a directory. If 'recursive' is true, multi-level directories can be created. Example Usage: var file = File('file.path'); var text = await file.readAsString(); await file.writeAsString('text'); ``` -------------------------------- ### ProxyPin Core Functionality and Traffic Interception Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Explains ProxyPin's operational mechanism as a local proxy server and its methods for intercepting network traffic on desktop and mobile platforms, including system proxy, external proxy, Wi-Fi proxy, and VPN service integration. ```APIDOC ProxyPin Operation: - Local Proxy Server: Listens on port 9099 by default. - SSL Handshake: Uses self-signed SSL certificates for client communication. - Root Certificate: Requires installation into the system for successful SSL handshake. Traffic Interception - Desktop: - System Proxy: Packet capture software sets system network proxy to ProxyPin's address/port. - External Proxy: Supports configuring external proxies (e.g., VPNs) to forward traffic to ProxyPin, resolving conflicts with other VPN software. - Note: Some applications may not read system proxy; external tools like Proxifier can redirect traffic. Traffic Interception - Mobile: - Method 1: Wi-Fi Proxy Configuration - Configure Wi-Fi proxy to ProxyPin's address/port (mobile and PC must be on the same LAN). - Note: Flutter applications may bypass this proxy. - Method 2: VPN Service - VpnService creates a virtual network card (TUN). - All data packets are forwarded to the TUN virtual network card. - ProxyPin reads IP packets from TUN, parses TCP/UDP data. - UDP: Forwards as-is to target address. - TCP (HTTP/S): Forwards to ProxyPin proxy service for interception and processing. ``` -------------------------------- ### Configure Flutter Subdirectory and GTK Dependencies Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Sets the path to the Flutter managed directory, includes it as a subdirectory, and finds the GTK 3.0 library using PkgConfig. This integrates the Flutter build system and necessary UI toolkit dependencies for the application. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### ProxyPin Scripting API: MD5 Hashing Utility Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 Provides a built-in utility function for calculating MD5 hashes of string values within the ProxyPin scripting environment. ```JavaScript var hash = md5('value') //output 2063c1608d6e0baf80249c42e2be5804 ``` -------------------------------- ### Find and Check System Dependencies with PkgConfig Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This snippet utilizes `PkgConfig` to locate and verify the presence of critical system libraries: GTK+ 3.0, GLIB 2.0, and GIO 2.0. These libraries are marked as `REQUIRED` and are essential for the Flutter Linux GTK desktop embedding to function correctly. ```CMake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Define Flutter Tool Backend Custom Build Steps Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This section defines a custom CMake command and target (`flutter_assemble`) responsible for invoking the Flutter tool's backend script (`tool_backend.sh`). This script generates and assembles the Flutter library and header files. A phony output file (`_phony_`) is used to force the command to run on every build, ensuring up-to-date artifacts. ```CMake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Integrate Flutter Libraries and Plugins into CMake Build Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/CMakeLists.txt This section integrates the Flutter framework into the CMake build system. It defines the `FLUTTER_MANAGED_DIR` variable, adds the Flutter directory and the application's runner subdirectory to the build, and includes the auto-generated `generated_plugins.cmake` file to incorporate Flutter plugins. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Flutter Core Library Interface Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/flutter/CMakeLists.txt This section defines the core Flutter library (`flutter_windows.dll`), its ICU data file, and project build directories, making them available to parent scopes. It then defines an `INTERFACE` library named `flutter`, configuring its include directories and linking it against the Flutter library's `.lib` file, and establishes a dependency on the `flutter_assemble` target. ```CMake # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Configure CMake Build Types and Profile Flags Source: https://github.com/wanghongenpin/proxypin/blob/main/windows/CMakeLists.txt This section manages CMake build configurations, detecting if the generator supports multiple configurations. It explicitly defines 'Debug', 'Profile', and 'Release' types. For the 'Profile' build, it mirrors the linker and compiler flags from the 'Release' configuration, ensuring consistent optimization settings. ```CMake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Include Generated Flutter Plugin Build Rules Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Includes the `generated_plugins.cmake` file, which contains CMake rules for building and integrating Flutter plugins into the application. This is crucial for enabling any plugin functionality used by the Flutter project. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define CMake Function for Standard Compilation Settings Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Defines a reusable CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features and options to a specified target. It enforces C++14, enables Wall and Werror, and applies -O3 and NDEBUG for non-Debug builds. ```CMake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### ProxyPin Built-in MD5 Hashing Utility Source: https://github.com/wanghongenpin/proxypin/wiki/脚本 Provides a built-in `md5` function for generating MD5 hashes of string values. This utility can be used directly within ProxyPin scripts. ```javascript var hash = md5('value') //output 2063c1608d6e0baf80249c42e2be5804 ``` -------------------------------- ### Define CMake `list_prepend` Function Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This custom CMake function `list_prepend` is defined to prepend a specified `PREFIX` to each element within a given list. It serves as a compatibility workaround for older CMake versions (like 3.10) that lack the built-in `list(TRANSFORM ... PREPEND ...)` command. ```CMake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### ProxyPin Scripting API: onRequest Function Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 The `onRequest` function is invoked before an HTTP request reaches the target server. It allows developers to inspect and modify various aspects of the request, including URL parameters, headers, and the request body. It can also be used to share data with the `onResponse` function via the `context` object or to interrupt the request by returning `null`. ```JavaScript async function onRequest(context, request) { console.log(request.url); //URL parameters request.queries["name"] = "value"; //Update or add new headers request.headers["X-New-Headers"] = "My-Value"; delete request.headers["Key-Need-Delete"]; //Update Body using fetch API, refer to online documentation for fetch API //request.body = await fetch('https://www.baidu.com/').then(response => response.text()); //Shared parameters, to be retrieved in onResponse later context["name"] = "hello"; return request; } ``` -------------------------------- ### ProxyPin Scripting API: onResponse Function Source: https://github.com/wanghongenpin/proxypin/wiki/抓包原理介绍 The `onResponse` function is executed before the HTTP response is sent back to the client. It enables developers to modify the response's status code, headers, and body. It can also access data shared from the `onRequest` function through the `context` object. ```JavaScript async function onResponse(context, request, response) { // Update or add new headers // response.headers["Name"] = context["name"]; // Update status Code response.statusCode = 500; //var body = JSON.parse(response.body); //body['key'] = "value"; //response.body = JSON.stringify(body); return response; } ``` -------------------------------- ### Set CMake Minimum Version and Ephemeral Directory Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/flutter/CMakeLists.txt This snippet sets the minimum required CMake version to 3.10 and defines the `EPHEMERAL_DIR` variable. This directory is designated for storing generated build artifacts and configurations specific to the Flutter project. ```CMake cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Configure CMake for Cross-Building with System Root Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Conditionally sets the CMake system root (CMAKE_SYSROOT) and adjusts CMAKE_FIND_ROOT_PATH_MODE variables when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. This enables proper dependency resolution for cross-compilation environments. ```CMake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Using MD5 Hashing in ProxyPin Scripts Source: https://github.com/wanghongenpin/proxypin/wiki/Script ProxyPin provides a built-in 'md5' function for generating MD5 hashes of string values. This utility can be used for data integrity checks or unique identifier generation within scripts. ```javascript var hash = md5('value') //output 2063c1608d6e0baf80249c42e2be5804 ``` -------------------------------- ### Intercepting and Modifying HTTP Requests with ProxyPin Source: https://github.com/wanghongenpin/proxypin/wiki/Script This JavaScript function is executed before an HTTP request is sent to the server. It allows modification of the request's URL parameters, headers, and body. Data can be shared with the onResponse function via the 'context' object. Returning 'None' (or implicitly 'undefined' in JS) will interrupt the request. ```javascript async function onRequest(context, request) { console.log(request.url); //URL Parameter request.queries["name"] = "value"; //Update or add Header request.headers["X-New-Headers"] = "My-Value"; delete request.headers["Key-Need-Delete"]; //Update Body Use the fetch API request interface. For specific documents, you can search for fetch API. //request.body = await fetch('https://www.baidu.com/').then(response => response.text()); //Shared parameters are taken out later during onResponse context["name"] = "hello"; return request; } ``` -------------------------------- ### Set Default CMake Build Type Source: https://github.com/wanghongenpin/proxypin/blob/main/linux/CMakeLists.txt Establishes a default build type (Debug) if CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES are not already set. This ensures a consistent build mode for the project, with predefined options for Debug, Profile, and Release. ```CMake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### ProxyPin onRequest Function for Request Modification Source: https://github.com/wanghongenpin/proxypin/wiki/脚本 This function is invoked before a request reaches the server, allowing modification of request data. It can update URL parameters, add/delete headers, and potentially modify the request body. Returning `null` from this function will interrupt the request. ```javascript async function onRequest(context, request) { console.log(request.url); //URL parameters request.queries["name"] = "value"; //Update or add new headers request.headers["X-New-Headers"] = "My-Value"; delete request.headers["Key-Need-Delete"]; //Update Body using fetch API, search fetch API documentation online //request.body = await fetch('https://www.baidu.com/').then(response => response.text()); //Share parameters, to be retrieved in onResponse later context["name"] = "hello"; return request; } ```