From 9d75d2eb7908f7767b820d928d0891be9098db65 Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Wed, 26 Jul 2023 12:38:25 +0700 Subject: [PATCH 1/8] ATG: synchronize every function of class ACE to make it thread safe --- .../java/com/kuhakupixel/atg/backend/ACE.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/ATG/app/src/main/java/com/kuhakupixel/atg/backend/ACE.java b/ATG/app/src/main/java/com/kuhakupixel/atg/backend/ACE.java index 6e0c521c..c7c0dfc7 100644 --- a/ATG/app/src/main/java/com/kuhakupixel/atg/backend/ACE.java +++ b/ATG/app/src/main/java/com/kuhakupixel/atg/backend/ACE.java @@ -130,7 +130,7 @@ public MatchInfo(String address, String prevValue) { // private Integer statusPublisherPort; - public Integer getStatusPublisherPort() { + public synchronized Integer getStatusPublisherPort() { return statusPublisherPort; } @@ -140,21 +140,21 @@ public ACE(Context context) throws IOException { this.availableNumTypes = GetAvailableNumTypes(); } - public Boolean IsAttached() { + public synchronized Boolean IsAttached() { return aceAttachClient != null; } - private void AssertAttached() { + private synchronized void AssertAttached() { if (!this.IsAttached()) throw new NoAttachException("Operation requires attaching to a process, but it hasn't been attached"); } - private void AssertNoAttachInARow() { + private synchronized void AssertNoAttachInARow() { if (this.IsAttached()) throw new AttachingInARowException("Cannot Attach without DeAttaching first"); } - public void ConnectToACEServer(Integer port) throws IOException, InterruptedException { + public synchronized void ConnectToACEServer(Integer port) throws IOException, InterruptedException { AssertNoAttachInARow(); this.aceAttachClient = new ACEAttachClient(port); } @@ -162,7 +162,7 @@ public void ConnectToACEServer(Integer port) throws IOException, InterruptedExce /** * this will create an ACE's server that is attached to process [pid] */ - public void Attach(Long pid) throws IOException, InterruptedException { + public synchronized void Attach(Long pid) throws IOException, InterruptedException { AssertNoAttachInARow(); // start the server List ports = Port.GetOpenPorts(2); @@ -173,7 +173,7 @@ public void Attach(Long pid) throws IOException, InterruptedException { } - public void DeAttach() throws InterruptedException { + public synchronized void DeAttach() throws InterruptedException { AssertAttached(); // tell server to die aceAttachClient.Request(new String[]{"stop"}); @@ -187,7 +187,7 @@ public void DeAttach() throws InterruptedException { } } - public Integer GetNumTypeBitSize(NumType numType) { + public synchronized Integer GetNumTypeBitSize(NumType numType) { Integer bitSize = null; for (NumTypeInfo typeInfo : this.availableNumTypes) { if (typeInfo.GetName().equals(numType.toString())) bitSize = typeInfo.GetBitSize(); @@ -196,37 +196,38 @@ public Integer GetNumTypeBitSize(NumType numType) { } - public String GetNumTypeAndBitSize(NumType numType) { + public synchronized String GetNumTypeAndBitSize(NumType numType) { Integer bitSize = this.GetNumTypeBitSize(numType); return String.format("%s (%d bit)", numType.toString(), bitSize); } // =============== this commands require attach =================== - public String CheaterCmd(String[] cmd) { + public synchronized String CheaterCmd(String[] cmd) { AssertAttached(); String out = aceAttachClient.Request(cmd); return out; } - public List CheaterCmdAsList(String[] cmd) { + public synchronized List CheaterCmdAsList(String[] cmd) { AssertAttached(); return aceAttachClient.RequestAsList(cmd); } - public Long GetAttachedPid() { + public synchronized Long GetAttachedPid() { + String pidStr = CheaterCmd(new String[]{"pid"}); return Long.parseLong(pidStr); } - public void SetNumType(NumType type) { + public synchronized void SetNumType(NumType type) { CheaterCmd(new String[]{"config", "type", type.toString()}); } /** * get current type that ACE use */ - public NumType GetNumType() { + public synchronized NumType GetNumType() { String typeStr = CheaterCmd(new String[]{"config", "type"}); return NumType.fromString(typeStr); } @@ -235,7 +236,7 @@ public NumType GetNumType() { * run code/function when type is set to [numType] * after done, the type will be set to the previous one */ - public void ActionOnType(NumType numType, IActionOnType action) { + public synchronized void ActionOnType(NumType numType, IActionOnType action) { NumType prevType = GetNumType(); // set type first before writing if (prevType != numType) @@ -245,16 +246,16 @@ public void ActionOnType(NumType numType, IActionOnType action) { SetNumType(prevType); } - public void ScanAgainstValue(Operator operator, String numValStr) { + public synchronized void ScanAgainstValue(Operator operator, String numValStr) { CheaterCmd(new String[]{"scan", operatorEnumToSymbolBiMap.get(operator), numValStr}); } - public void ScanWithoutValue(Operator operator) { + public synchronized void ScanWithoutValue(Operator operator) { CheaterCmd(new String[]{"filter", operatorEnumToSymbolBiMap.get(operator)}); } - public void WriteValueAtAddress(NumType numType, String address, String value) { + public synchronized void WriteValueAtAddress(NumType numType, String address, String value) { this.ActionOnType(numType, @@ -264,16 +265,16 @@ public void WriteValueAtAddress(NumType numType, String address, String value) { ); } - public Integer GetMatchCount() { + public synchronized Integer GetMatchCount() { return Integer.parseInt(CheaterCmd(new String[]{"matchcount"})); } - public void ResetMatches() { + public synchronized void ResetMatches() { CheaterCmd(new String[]{"reset"}); } - public List ListMatches(Integer maxCount) { + public synchronized List ListMatches(Integer maxCount) { /** * get list of matches with list command * which will return a list of [address] - [prev value] one per each line @@ -292,15 +293,15 @@ public List ListMatches(Integer maxCount) { } // =============== this commands don't require attach =================== - public List UtilCmdAsList(String[] cmd) { + public synchronized List UtilCmdAsList(String[] cmd) { return this.aceUtilClient.RequestAsList(cmd); } - public String UtilCmd(String[] cmd) { + public synchronized String UtilCmd(String[] cmd) { return this.aceUtilClient.Request(cmd); } - public List ListRunningProc() { + public synchronized List ListRunningProc() { List runningProcs = new ArrayList(); // use --reverse so newest process will be shown first List runningProcsInfoStr = UtilCmdAsList(new String[]{"ps", "ls", "--reverse"}); @@ -311,7 +312,7 @@ public List ListRunningProc() { return runningProcs; } - public boolean IsPidRunning(Long pid) { + public synchronized boolean IsPidRunning(Long pid) { String boolStr = UtilCmd(new String[]{"ps", "is_running", pid.toString()}); assert (boolStr.equals("true") || boolStr.equals("false")); return Boolean.parseBoolean(boolStr); @@ -323,7 +324,7 @@ public boolean IsPidRunning(Long pid) { * which will return list of " " * like "int 32", "short 16" and ect */ - public List GetAvailableNumTypes() { + public synchronized List GetAvailableNumTypes() { List numTypeInfos = new ArrayList(); List out = UtilCmdAsList(new String[]{"info", "type"}); for (String s : out) { @@ -337,7 +338,7 @@ public List GetAvailableNumTypes() { } - public List GetAvailableOperatorTypes() { + public synchronized List GetAvailableOperatorTypes() { // the output will be a list of supported operators like // > // < @@ -349,4 +350,4 @@ public List GetAvailableOperatorTypes() { availableOperators.add(operatorEnumToSymbolBiMap.inverse().get(s)); return availableOperators; } -} \ No newline at end of file +} From 7d1736656e6ebaf7b23e4751da01d644a7fbaf1e Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Wed, 26 Jul 2023 13:33:42 +0700 Subject: [PATCH 2/8] ATG: code cleanup for next scan callback --- .../com/kuhakupixel/atg/ui/menu/Memory.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt index 4856275d..51a11d6c 100644 --- a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt +++ b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt @@ -160,18 +160,17 @@ fun _MemoryMenu( // nextScanEnabled = isAttached && !isScanOnGoing.value, nextScanClicked = fun() { - // ====================== get scan options ======================== - val valueType: NumType = NumType.values()[valueTypeSelectedOptionIdx.value] - val scanType: Operator = Operator.values()[scanTypeSelectedOptionIdx.value] - // ================================================================ - // set the value type - if (!initialScanDone.value) ace.SetNumType(valueType) - - val statusPublisherPort = ace.getStatusPublisherPort(); // make sure to finish up the previous scan thread before continuing // with the next one, because its gonna be nasty if we don't do that currentScanThread?.join() currentScanThread = thread { + // ====================== get scan options ======================== + val valueType: NumType = NumType.values()[valueTypeSelectedOptionIdx.value] + val scanType: Operator = Operator.values()[scanTypeSelectedOptionIdx.value] + // ================================================================ + // set the value type + if (!initialScanDone.value) ace.SetNumType(valueType) + // disable next and new scan isScanOnGoing.value = true try { @@ -198,6 +197,8 @@ fun _MemoryMenu( ) } isScanOnGoing.value = false + // set initial scan to true + initialScanDone.value = true // update matches table UpdateMatches(ace = ace) } @@ -207,6 +208,7 @@ fun _MemoryMenu( * */ currentScanProgressThread?.join() currentScanProgressThread = thread { + val statusPublisherPort = ace.getStatusPublisherPort(); try { val statusSubscriber = ACEStatusSubscriber(statusPublisherPort) statusSubscriber.use { it: ACEStatusSubscriber -> @@ -227,8 +229,6 @@ fun _MemoryMenu( } - // set initial scan to true - initialScanDone.value = true }, // From 0ff52a5e61493c3f78ef86a747fe712c6301a8ab Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Wed, 26 Jul 2023 17:27:56 +0700 Subject: [PATCH 3/8] ATG: fix apk hangs when next scan is clicked more than once quickly Problem: because the need to join thread if available before continuing the operation, it will hang the gui if next scan is clicked more than once quickly Solution: remove join, because most variables used in next scan's on click are now synchronized --- .../main/java/com/kuhakupixel/atg/ui/menu/Memory.kt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt index 51a11d6c..d6eba3ad 100644 --- a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt +++ b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt @@ -71,9 +71,6 @@ private var matchesStatusText: MutableState = mutableStateOf("0 matches" private val scanProgress: MutableState = mutableStateOf(0.0f) // ================================================================ -private var currentScanThread: Thread? = null -private var currentScanProgressThread: Thread? = null - @Composable fun MemoryMenu(globalConf: GlobalConf?, overlayContext: OverlayContext?) { val snackbarHostState: SnackbarHostState = remember { SnackbarHostState() } @@ -160,10 +157,7 @@ fun _MemoryMenu( // nextScanEnabled = isAttached && !isScanOnGoing.value, nextScanClicked = fun() { - // make sure to finish up the previous scan thread before continuing - // with the next one, because its gonna be nasty if we don't do that - currentScanThread?.join() - currentScanThread = thread { + thread { // ====================== get scan options ======================== val valueType: NumType = NumType.values()[valueTypeSelectedOptionIdx.value] val scanType: Operator = Operator.values()[scanTypeSelectedOptionIdx.value] @@ -206,8 +200,7 @@ fun _MemoryMenu( * thread to update the progress as the scan goes, with a subscriber * that keeps listening to a port until the scan is done * */ - currentScanProgressThread?.join() - currentScanProgressThread = thread { + thread { val statusPublisherPort = ace.getStatusPublisherPort(); try { val statusSubscriber = ACEStatusSubscriber(statusPublisherPort) From 1135db35a95ae70dc319b3a9e40fee874288cee4 Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Wed, 26 Jul 2023 19:08:09 +0700 Subject: [PATCH 4/8] ATG: improvement to progress bar - make progress bar more responsive by calling ACE.getStatusPublisherPort outside thread to prevent waiting due to synchronization - set progress to 0 after scan is done --- .../src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt index d6eba3ad..04e61daa 100644 --- a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt +++ b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt @@ -157,6 +157,7 @@ fun _MemoryMenu( // nextScanEnabled = isAttached && !isScanOnGoing.value, nextScanClicked = fun() { + val statusPublisherPort = ace.getStatusPublisherPort(); thread { // ====================== get scan options ======================== val valueType: NumType = NumType.values()[valueTypeSelectedOptionIdx.value] @@ -201,7 +202,6 @@ fun _MemoryMenu( * that keeps listening to a port until the scan is done * */ thread { - val statusPublisherPort = ace.getStatusPublisherPort(); try { val statusSubscriber = ACEStatusSubscriber(statusPublisherPort) statusSubscriber.use { it: ACEStatusSubscriber -> @@ -211,8 +211,13 @@ fun _MemoryMenu( while (!scanProgressData.is_finished) { scanProgress.value = scanProgressData.current.toFloat() / scanProgressData.max.toFloat() + Log.d( + "ATG", + "Scan Progress: ${scanProgressData.current}/${scanProgressData.max}" + ) scanProgressData = statusSubscriber.GetScanProgress() } + scanProgress.value = 0.0f } } catch (e: Exception) { From 3034ff0dbcc97512a7d63a7f6d6dba501a682749 Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Wed, 26 Jul 2023 19:40:05 +0700 Subject: [PATCH 5/8] ATG: remove freeze checkbox because functionality is not done yet --- .../java/com/kuhakupixel/atg/ui/EditAddressOverlayDialog.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/EditAddressOverlayDialog.kt b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/EditAddressOverlayDialog.kt index 1b9f0ad1..2aa13598 100644 --- a/ATG/app/src/main/java/com/kuhakupixel/atg/ui/EditAddressOverlayDialog.kt +++ b/ATG/app/src/main/java/com/kuhakupixel/atg/ui/EditAddressOverlayDialog.kt @@ -33,12 +33,15 @@ class EditAddressOverlayDialog(overlayContext: OverlayContext, alpha: Float = 1. label = "Value Input ...", placeholder = "value ...", ) + /* TODO: implement freeze value of address Column(verticalArrangement = Arrangement.SpaceBetween) { Text("Freeze") Checkbox( checked = checked.value, onCheckedChange = { value -> checked.value = value }) } + + */ } } From 266bd209e78b14f0bc990f346e35cd32245c7aa9 Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Thu, 27 Jul 2023 11:55:53 +0700 Subject: [PATCH 6/8] ATG: fix choices dialog not scrollable Solution: update to newer version of the library --- ATG/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATG/app/build.gradle b/ATG/app/build.gradle index f3ec1a59..1b1ddb2e 100644 --- a/ATG/app/build.gradle +++ b/ATG/app/build.gradle @@ -93,7 +93,7 @@ dependencies { def nav_version = "2.5.3" implementation "androidx.navigation:navigation-compose:$nav_version" // creating overlay window - def libUberAllesVersion = '0.0.3' + def libUberAllesVersion = '0.0.4' implementation "com.github.KuhakuPixel:UberAlles:${libUberAllesVersion}" // ========================= for communication with ACE =============== // apache commons From 3bd25913763fbaf0eea29ab3186b9807810013fb Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Thu, 27 Jul 2023 16:13:19 +0700 Subject: [PATCH 7/8] ACE: downgrade cmakelist minimum required version in mock_program its a typo --- ACE/engine/mock_program/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACE/engine/mock_program/CMakeLists.txt b/ACE/engine/mock_program/CMakeLists.txt index eeab7150..644e79dc 100644 --- a/ACE/engine/mock_program/CMakeLists.txt +++ b/ACE/engine/mock_program/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.12) project(mock_program) From 38eccaaab1d86c256b70a75be4a148a500a41f33 Mon Sep 17 00:00:00 2001 From: kuhakupixel Date: Thu, 27 Jul 2023 17:27:17 +0700 Subject: [PATCH 8/8] Add Changelog --- ROADMAP.md | 4 ---- changelog.md | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 8520e069..c88842fe 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -17,10 +17,6 @@ than `=`, `<` ### Freeze value of an address -### Display progress bar on when scanning -currently in the apk, when doing scanning -the apk will freeze/wait until it finish - ### show value of an address in real time ### Undo diff --git a/changelog.md b/changelog.md index 8ec9e52a..93417510 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,19 @@ # ChangeLog +## [0.0.9] + +### Fixed +- [ATG] some of scan options not shown, because it is not scrollable +- [ATG] scanning for value may freeze the entire app due to only using one thread + +### Added +- [ATG] progress bar when scanning +- [ATG] Icon for the overlay button + +### Changed +### Removed + + ## [0.0.8] Initial Alpha release of ATG apk