Skip to content

Instantly share code, notes, and snippets.

@en9inerd
Last active August 29, 2024 23:20
Show Gist options
  • Save en9inerd/b4f185d6d3f5e51257d6e4051c619e1d to your computer and use it in GitHub Desktop.
Save en9inerd/b4f185d6d3f5e51257d6e4051c619e1d to your computer and use it in GitHub Desktop.
Memory Address Manipulator
// This script prompts the user to enter a memory address and either increments or decrements it, maintaining the format.
// It also saves the new address to a file for use in subsequent runs.
// Define the file path
const filePath = FileManager.local().documentsDirectory() + "/memory_address.txt";
// Read the last saved address or use a default address
let lastAddress;
if (FileManager.local().fileExists(filePath)) {
lastAddress = FileManager.local().readString(filePath);
} else {
lastAddress = "0x00000000";
}
let alert = new Alert();
alert.title = "Memory Address Increment/Decrement";
alert.addTextField("Enter memory address (e.g., 0x0000001B)", lastAddress);
alert.addAction("Increment");
alert.addAction("Decrement");
let response = await alert.presentAlert();
let inputAddress = alert.textFieldValue(0);
// Validate the input address
if (!/^0x[0-9A-Fa-f]+$/.test(inputAddress)) {
let errorAlert = new Alert();
errorAlert.title = "Invalid Input";
errorAlert.message = "Please enter a valid hexadecimal memory address.";
errorAlert.addAction("OK");
await errorAlert.presentAlert();
return;
}
// Convert the input address to a number
let addressNumber = parseInt(inputAddress, 16);
// Determine the length of the original address for formatting
let originalLength = inputAddress.length - 2; // Subtract 2 for "0x"
if (response == 0) {
// Increment the address
addressNumber++;
} else if (response == 1) {
// Decrement the address
addressNumber--;
}
// Convert the number back to a hexadecimal string with padding to match original length
let newAddress = "0x" + addressNumber.toString(16).toUpperCase().padStart(originalLength, '0');
// Save the new address to the file
FileManager.local().writeString(filePath, newAddress);
// Copy the new address to the clipboard
Pasteboard.copyString(newAddress);
// Display the result
let resultAlert = new Alert();
resultAlert.title = "New Memory Address";
resultAlert.message = `The new memory address is ${newAddress}.\n\nIt has been copied to the clipboard.`;
resultAlert.addAction("OK");
await resultAlert.presentAlert();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment