Skip to content

Commit

Permalink
Merge pull request #47 from KuhakuPixel/feature
Browse files Browse the repository at this point in the history
ATG: improvement to progress bar
  • Loading branch information
KuhakuPixel authored Jul 27, 2023
2 parents 0d8db3e + 38eccaa commit c767b5e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 52 deletions.
2 changes: 1 addition & 1 deletion ACE/engine/mock_program/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.12)

project(mock_program)

Expand Down
2 changes: 1 addition & 1 deletion ATG/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 29 additions & 28 deletions ATG/app/src/main/java/com/kuhakupixel/atg/backend/ACE.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public MatchInfo(String address, String prevValue) {
//
private Integer statusPublisherPort;

public Integer getStatusPublisherPort() {
public synchronized Integer getStatusPublisherPort() {
return statusPublisherPort;
}

Expand All @@ -140,29 +140,29 @@ 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);
}

/**
* 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<Integer> ports = Port.GetOpenPorts(2);
Expand All @@ -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"});
Expand All @@ -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();
Expand All @@ -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<String> CheaterCmdAsList(String[] cmd) {
public synchronized List<String> 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);
}
Expand All @@ -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)
Expand All @@ -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,

Expand All @@ -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<MatchInfo> ListMatches(Integer maxCount) {
public synchronized List<MatchInfo> ListMatches(Integer maxCount) {
/**
* get list of matches with list command
* which will return a list of [address] - [prev value] one per each line
Expand All @@ -292,15 +293,15 @@ public List<MatchInfo> ListMatches(Integer maxCount) {
}

// =============== this commands don't require attach ===================
public List<String> UtilCmdAsList(String[] cmd) {
public synchronized List<String> 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<ProcInfo> ListRunningProc() {
public synchronized List<ProcInfo> ListRunningProc() {
List<ProcInfo> runningProcs = new ArrayList<ProcInfo>();
// use --reverse so newest process will be shown first
List<String> runningProcsInfoStr = UtilCmdAsList(new String[]{"ps", "ls", "--reverse"});
Expand All @@ -311,7 +312,7 @@ public List<ProcInfo> 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);
Expand All @@ -323,7 +324,7 @@ public boolean IsPidRunning(Long pid) {
* which will return list of "<type name> <bit size>"
* like "int 32", "short 16" and ect
*/
public List<NumTypeInfo> GetAvailableNumTypes() {
public synchronized List<NumTypeInfo> GetAvailableNumTypes() {
List<NumTypeInfo> numTypeInfos = new ArrayList<NumTypeInfo>();
List<String> out = UtilCmdAsList(new String[]{"info", "type"});
for (String s : out) {
Expand All @@ -337,7 +338,7 @@ public List<NumTypeInfo> GetAvailableNumTypes() {

}

public List<Operator> GetAvailableOperatorTypes() {
public synchronized List<Operator> GetAvailableOperatorTypes() {
// the output will be a list of supported operators like
// >
// <
Expand All @@ -349,4 +350,4 @@ public List<Operator> GetAvailableOperatorTypes() {
availableOperators.add(operatorEnumToSymbolBiMap.inverse().get(s));
return availableOperators;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
*/
}

}
Expand Down
34 changes: 16 additions & 18 deletions ATG/app/src/main/java/com/kuhakupixel/atg/ui/menu/Memory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ private var matchesStatusText: MutableState<String> = mutableStateOf("0 matches"
private val scanProgress: MutableState<Float> = 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() }
Expand Down Expand Up @@ -160,18 +157,15 @@ 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 {
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 {
Expand All @@ -198,15 +192,16 @@ fun _MemoryMenu(
)
}
isScanOnGoing.value = false
// set initial scan to true
initialScanDone.value = true
// update matches table
UpdateMatches(ace = ace)
}
/**
* 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 {
try {
val statusSubscriber = ACEStatusSubscriber(statusPublisherPort)
statusSubscriber.use { it: ACEStatusSubscriber ->
Expand All @@ -216,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) {
Expand All @@ -227,8 +227,6 @@ fun _MemoryMenu(

}

// set initial scan to true
initialScanDone.value = true
},

//
Expand Down
4 changes: 0 additions & 4 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit c767b5e

Please sign in to comment.