From 3b0ae35d3b82bb80ada4cdab12dbd7e1b55ee44d Mon Sep 17 00:00:00 2001 From: Duy Truong Date: Mon, 27 Feb 2023 15:47:58 -0800 Subject: Add Bitness enum to NativePoc. This allows shorter, more readable code when poc bitness is set at runtime. This is generally called as: NativePoc.builder() .pocName(....) .bitness(is64bit ? ONLY64 : ONLY32) .build() .run(this); Bug: 267681397 Test: run test for CVE_2022_20416 modified with this API. Change-Id: If081e2202dbcaf2a43926f96575d8dfd84e9903f Merged-In: If081e2202dbcaf2a43926f96575d8dfd84e9903f --- .../host-side/src/com/android/sts/common/NativePoc.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libraries/sts-common-util/host-side/src/com/android/sts/common/NativePoc.java b/libraries/sts-common-util/host-side/src/com/android/sts/common/NativePoc.java index 221c1f7ad..90acdecdf 100644 --- a/libraries/sts-common-util/host-side/src/com/android/sts/common/NativePoc.java +++ b/libraries/sts-common-util/host-side/src/com/android/sts/common/NativePoc.java @@ -196,6 +196,12 @@ public class NativePoc { .assumePocExitSuccess(true); } + public static enum Bitness { + AUTO, // push 32 or 64 bit version of PoC depending on device arch + ONLY32, // push only 32bit version of PoC + ONLY64 // push only 64bit version of PoC; raises error when running on 32bit-only device + } + public static class Builder { private String pocName; private ImmutableList args; @@ -305,6 +311,17 @@ public class NativePoc { return this; } + /** Force using 32bit or 64bit version of the native poc */ + public Builder bitness(Bitness bitness) { + if (bitness == Bitness.ONLY32) { + return only32(true).only64(false); + } + if (bitness == Bitness.ONLY64) { + return only32(false).only64(true); + } + return only32(false).only64(false); + } + public Builder assumePocExitSuccess(boolean assumePocExitSuccess) { this.assumePocExitSuccess = assumePocExitSuccess; return this; -- cgit v1.2.3