From 14fd474982f3535d6fda53c0aa362747bd420f4b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:29:02 +0100 Subject: [PATCH 01/10] Reflect emulation status in exit code --- src/analyzer/main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index e4468096..b26b85a8 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -44,7 +44,7 @@ namespace #endif } - void run_emulation(windows_emulator& win_emu, const analysis_options& options) + bool run_emulation(windows_emulator& win_emu, const analysis_options& options) { try { @@ -78,10 +78,12 @@ namespace if (exit_status.has_value()) { win_emu.log.print(color::red, "Emulation terminated with status: %X\n", *exit_status); + return false; } else { - win_emu.log.print(color::red, "Emulation terminated without status!\n"); + win_emu.log.print(color::green, "Emulation terminated without status!\n"); + return true; } } @@ -99,11 +101,11 @@ namespace return wide_args; } - void run(const analysis_options& options, const std::span args) + bool run(const analysis_options& options, const std::span args) { if (args.empty()) { - return; + return false; } emulator_settings settings{ @@ -175,7 +177,7 @@ namespace win_emu.emu().hook_memory_write(section.region.start, section.region.length, std::move(write_handler)); } - run_emulation(win_emu, options); + return run_emulation(win_emu, options); } std::vector bundle_arguments(const int argc, char** argv) @@ -253,12 +255,14 @@ int main(const int argc, char** argv) throw std::runtime_error("Application not specified!"); } + bool result{}; + do { - run(options, args); + result = run(options, args); } while (options.use_gdb); - return 0; + return result ? 0 : 1; } catch (std::exception& e) { From 7ad0e83bbd5795b74c35b9d80ca16e8e64e2646a Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:32:03 +0100 Subject: [PATCH 02/10] More emulation root renaming --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3eeac6d3..3a7ec6a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: name: Windows Release Artifacts path: build/release/artifacts - - name: Dump Root FS + - name: Create Emulation Root run: src/tools/create-root.bat - name: Dump API Set @@ -75,7 +75,7 @@ jobs: - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 with: - name: ${{ matrix.platform }} Root FS + name: ${{ matrix.platform }} Emulation Root path: "*" working-directory: root retention-days: 1 @@ -185,7 +185,7 @@ jobs: strategy: fail-fast: false matrix: - filesystem: + emulation-root: - Windows 2025 - Windows 2022 - Windows 2019 @@ -233,10 +233,10 @@ jobs: name: Windows ${{matrix.configuration}} Artifacts path: build/${{matrix.preset}}/artifacts - - name: Download Root FS + - name: Download Emulation Root uses: pyTooling/download-artifact@v4 with: - name: ${{ matrix.filesystem }} Root FS + name: ${{ matrix.emulation-root }} Emulation Root path: build/${{matrix.preset}}/artifacts/root - name: Copy Test Sample From 35dd452840776ec013be8a44089cee6e7cc7893d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:32:16 +0100 Subject: [PATCH 03/10] Add android x86_64 smoke test --- .github/workflows/build.yml | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3a7ec6a5..5d9e47b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -247,10 +247,63 @@ jobs: env: EMULATOR_ROOT: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/root + smoke-test-android-x64: + name: Smoke Test Android x86_64 + runs-on: ubuntu-24.04 + needs: [create-emulation-root, build] + strategy: + fail-fast: false + matrix: + emulation-root: + - Windows 2025 + - Windows 2022 + - Windows 2019 + configuration: + - Debug + - Release + include: + - configuration: Debug + preset: debug + - configuration: Release + preset: release + steps: + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Download Artifacts + uses: pyTooling/download-artifact@v4 + with: + name: Android x86_64 ${{matrix.configuration}} Artifacts + path: build/${{matrix.preset}}/artifacts + + - name: Download Windows Artifacts + uses: pyTooling/download-artifact@v4 + with: + name: Windows ${{matrix.configuration}} Artifacts + path: build/${{matrix.preset}}/artifacts + + - name: Download Emulation Root + uses: pyTooling/download-artifact@v4 + with: + name: ${{ matrix.emulation-root }} Emulation Root + path: build/${{matrix.preset}}/artifacts/root + + - name: Copy Test Sample + run: cp build/${{matrix.preset}}/artifacts/test-sample.exe build/${{matrix.preset}}/artifacts/root/filesys/c/ + + - name: Run Test + uses: reactivecircus/android-emulator-runner@v2.33.0 + with: + api-level: 29 + script: adb push build/${{matrix.preset}}/artifacts/* /data/local/tmp && adb shell \"cd /data/local/tmp && export LD_LIBRARY_PATH=. && chmod +x ./analyzer && ./analyzer -e ./root c:/test-sample.exe\" + summary: name: Pipeline Summary runs-on: ubuntu-24.04 - needs: [create-emulation-root, build, test, verify-formatting] + needs: [smoke-test-android-x64, create-emulation-root, build, test, verify-formatting] if: always() steps: - uses: geekyeggo/delete-artifact@v5 From d9a2a99132a54576434ba39b3a36d7d06cf6936e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:35:19 +0100 Subject: [PATCH 04/10] Add autoretries to curl --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d9e47b8..0509882c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: uses: actions/checkout@v4 - name: Download DirectX Runtime - run: curl -L -o directx_Jun2010_redist.exe https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe + run: curl --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 40 -L -o directx_Jun2010_redist.exe https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe - name: Extract DirectX Runtime run: ./directx_Jun2010_redist.exe /Q /T:"${{github.workspace}}/dxrt" From 84f429e128fd3c9af829d06f3501f01cfa6084a9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:44:44 +0100 Subject: [PATCH 05/10] Fix android test --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0509882c..ecc01187 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -298,7 +298,7 @@ jobs: uses: reactivecircus/android-emulator-runner@v2.33.0 with: api-level: 29 - script: adb push build/${{matrix.preset}}/artifacts/* /data/local/tmp && adb shell \"cd /data/local/tmp && export LD_LIBRARY_PATH=. && chmod +x ./analyzer && ./analyzer -e ./root c:/test-sample.exe\" + script: "adb push build/${{matrix.preset}}/artifacts/* /data/local/tmp && adb shell \"cd /data/local/tmp && export LD_LIBRARY_PATH=. && chmod +x ./analyzer && ./analyzer -e ./root c:/test-sample.exe\"" summary: name: Pipeline Summary From 631386ebbf02e25f59ac5ce34c926bfea63c97e1 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:46:32 +0100 Subject: [PATCH 06/10] More gitignore --- src/tools/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/.gitignore b/src/tools/.gitignore index d484f3b3..54781cee 100644 --- a/src/tools/.gitignore +++ b/src/tools/.gitignore @@ -1,2 +1,3 @@ root +root*/ registry \ No newline at end of file From f7620750e701122483416b11e389045f14cd12a9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 09:55:47 +0100 Subject: [PATCH 07/10] Use correct android architectures --- .github/workflows/build.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecc01187..faa5df8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -247,8 +247,8 @@ jobs: env: EMULATOR_ROOT: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/root - smoke-test-android-x64: - name: Smoke Test Android x86_64 + smoke-test-android: + name: Smoke Test Android runs-on: ubuntu-24.04 needs: [create-emulation-root, build] strategy: @@ -258,6 +258,9 @@ jobs: - Windows 2025 - Windows 2022 - Windows 2019 + architecture: + - x86_64 + - arm64-v8a configuration: - Debug - Release @@ -276,7 +279,7 @@ jobs: - name: Download Artifacts uses: pyTooling/download-artifact@v4 with: - name: Android x86_64 ${{matrix.configuration}} Artifacts + name: Android ${{matrix.architecture}} ${{matrix.configuration}} Artifacts path: build/${{matrix.preset}}/artifacts - name: Download Windows Artifacts @@ -298,12 +301,13 @@ jobs: uses: reactivecircus/android-emulator-runner@v2.33.0 with: api-level: 29 + arch: ${{matrix.architecture}} script: "adb push build/${{matrix.preset}}/artifacts/* /data/local/tmp && adb shell \"cd /data/local/tmp && export LD_LIBRARY_PATH=. && chmod +x ./analyzer && ./analyzer -e ./root c:/test-sample.exe\"" summary: name: Pipeline Summary runs-on: ubuntu-24.04 - needs: [smoke-test-android-x64, create-emulation-root, build, test, verify-formatting] + needs: [smoke-test-android, create-emulation-root, build, test, verify-formatting] if: always() steps: - uses: geekyeggo/delete-artifact@v5 From a76c7f41c02d67602468416d29bde7f1c6d1e0b2 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 10:19:16 +0100 Subject: [PATCH 08/10] Fix android arm64 test --- .github/workflows/build.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index faa5df8d..e9a1d27d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -185,16 +185,16 @@ jobs: strategy: fail-fast: false matrix: - emulation-root: - - Windows 2025 - - Windows 2022 - - Windows 2019 platform: - Windows - Linux GCC - Linux Clang - macOS arm64 - macOS x86_64 + emulation-root: + - Windows 2025 + - Windows 2022 + - Windows 2019 configuration: - Debug - Release @@ -249,18 +249,18 @@ jobs: smoke-test-android: name: Smoke Test Android - runs-on: ubuntu-24.04 + runs-on: ${{ matrix.runner }} needs: [create-emulation-root, build] strategy: fail-fast: false matrix: + architecture: + - x86_64 + - arm64-v8a emulation-root: - Windows 2025 - Windows 2022 - Windows 2019 - architecture: - - x86_64 - - arm64-v8a configuration: - Debug - Release @@ -269,8 +269,13 @@ jobs: preset: debug - configuration: Release preset: release + - architecture: x86_64 + runner: ubuntu-24.04 + - architecture: arm64-v8a + runner: macos-latest steps: - name: Enable KVM + if: ${{ startsWith(matrix.runner, 'ubuntu') }} run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules From ddbe94e1051fd794e7eaadda4c43fad47f5e3d10 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 10:26:33 +0100 Subject: [PATCH 09/10] Disable android arm test for now --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9a1d27d..2436de95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -256,7 +256,7 @@ jobs: matrix: architecture: - x86_64 - - arm64-v8a + #- arm64-v8a emulation-root: - Windows 2025 - Windows 2022 @@ -271,8 +271,8 @@ jobs: preset: release - architecture: x86_64 runner: ubuntu-24.04 - - architecture: arm64-v8a - runner: macos-latest + #- architecture: arm64-v8a + # runner: macos-latest steps: - name: Enable KVM if: ${{ startsWith(matrix.runner, 'ubuntu') }} From 617a68eb21b32ebc72e511ee3b8ca5eaf8c41209 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 10:31:13 +0100 Subject: [PATCH 10/10] Fix exit status --- src/analyzer/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index b26b85a8..19d366a2 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -75,16 +75,14 @@ namespace } const auto exit_status = win_emu.process().exit_status; - if (exit_status.has_value()) - { - win_emu.log.print(color::red, "Emulation terminated with status: %X\n", *exit_status); - return false; - } - else + if (!exit_status.has_value()) { win_emu.log.print(color::green, "Emulation terminated without status!\n"); - return true; + return false; } + + win_emu.log.print(color::red, "Emulation terminated with status: %X\n", *exit_status); + return *exit_status == STATUS_SUCCESS; } std::vector parse_arguments(const std::span args)