Skip to content

Commit bdab6d8

Browse files
Update 0.5
Added CLI and bug fixing
1 parent 3e34b80 commit bdab6d8

18 files changed

+2283
-668
lines changed

README.md

Lines changed: 207 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ AndroidMemoryTool
1818
.This Tool is written in python using ctypes not affective as c.
1919
If you find any bug or not working function you can contact me.
2020

21-
* Date : 2022/03/23
21+
* Date : 2023/07/11
2222
* Author : **__Abdul Moez__**
23-
* Version : 0.4
23+
* Version : 0.5
2424
* Study : UnderGraduate in GCU Lahore, Pakistan
2525
* Repository : https://github.com/Anonym0usWork1221/android-memorytool
2626
* Documentation: https://github.com/Anonym0usWork1221/android-memorytool/tree/main/Documentation
@@ -30,31 +30,39 @@ If you find any bug or not working function you can contact me.
3030

3131
Copyright (c) 2022 AbdulMoez
3232

33+
-----------
34+
3335
# Note
34-
1. This documentation is for 0.4 version (UPDATED)
36+
1. This documentation is for 0.5 version (UPDATED)
3537
2. You can find old version on pypi if you want to use them
3638

37-
# Version 0.4
38-
-> Optimized the code
39-
-> Increase Stability
40-
-> Fixed Known bugs:
41-
-> Fixed Simple Text search returning same values as previous search problem
42-
-> Fixed Increasing Values/address problem in Fast search algorithms
43-
-> Fixed output pattern in raw dump
44-
45-
-> Added Reset function for queue
46-
-> Added Hex Pattern Finder 87 ?? BB
47-
-> Added Hex search for (Float, Dword, Double)
48-
-> Added support for fork() process (by default takes first pid as parent)
49-
-> Added Manually PID entering support either in int or string (pid=714 or pid="714")
50-
-> Can raw dump from Custom start_address-end_address ("4754D6E6-5754D6E6" or "client.so")
51-
-> Added Known error files and its fixes in (ERRORS.md) file
52-
-> Added Support to dump map file
53-
-> Added UTF-8 and UTF-16E support for lib read/write
54-
-> Added a Detailed Documentation File
55-
-> Added Documentation string stub in AndroidMemoryTool class
39+
-----------
5640

41+
# Version 0.5
42+
-> ----------------------------------------MOD-LOGS-------------------------------------------------- <-
43+
44+
-> Fixed the invalid output of hex address in reading process
45+
-> Fixed the read_lib and write_lib hex issue the now pass the hex as a
46+
string in old method the calculation was generating errors due to hex value passed as integer
47+
-> Optimize the code of DataClass.py
48+
-> Fixed Initializers of some classes (e.g: ThreadingController and DataClasses)
49+
-> Added Complete self explaining doc strings to all the classes and functions
50+
-> Rewrite the Mapping class inorder to reduce junk size and correct the mapping of anonymous range.
51+
-> Added new function of find_and_replace_hex_pattern() for search wild card and replace that in hex form
52+
e.g: find_and_replace_hex_pattern(search_pattern='2D??3D', replace_pattern='1D4D2D')
53+
-> Added CLI for command line interface
54+
55+
-> ----------------------------------------TO-DO---------------------------------------------------- <-
56+
57+
-> TODO: Add Reverse engineering Support for offline binaries using known disassemblers (capstone, keystone, r2pipe)
58+
-> TODO: Add Assembly support for reading and writing memory at runtime
59+
60+
-> ----------------------------------------SUGGESTIONS---------------------------------------------- <-
5761

62+
-> SUGGESTIONS: You can leave your suggestions either on my mailbox or discord server.
63+
64+
65+
-----------
5866

5967
Requirements
6068
-----------
@@ -63,21 +71,30 @@ Requirements
6371

6472
* Android Requirements -> Rooted Device Needed
6573

74+
-----------
75+
6676
Installation
6777
----------------------------------------
6878
1. **Simply install it by pip and use it in your project**
69-
``pip install androidMemoryTool==0.4``
79+
``pip install androidMemoryTool==0.5``
7080

7181
2. **Or by cloning and then run command**
7282
``pip install .``
7383

7484
3. **Project live at**
75-
https://pypi.org/project/androidMemoryTool/0.4/
85+
https://pypi.org/project/androidMemoryTool/0.5/
7686

7787

7888
Memory Tool with example which can be found in the
7989
`Android-Py-Cheats-Script @ 9d2520e`.
8090

91+
-----------
92+
Video Demo
93+
-----------
94+
[![Video Demo](https://img.youtube.com/vi/Ivyy6GQzm3w/0.jpg)](https://www.youtube.com/watch?v=Ivyy6GQzm3w)
95+
96+
-----------
97+
8198
## Documentation
8299

83100
* Getting Process ID
@@ -173,6 +190,19 @@ for index in range(0, len(found_pattern[0])):
173190
print(f"{found_pattern[0][index]}: {found_pattern[2][index]}")
174191
print(f"Total Pattern found: {found_pattern[1]}")
175192
```
193+
194+
* Find and replace hex Patterns
195+
```python
196+
from androidMemoryTool import AndroidMemoryTool
197+
tool = AndroidMemoryTool(PKG=662, SPEED_MODE=True, WORKERS=55,
198+
pMAP=AndroidMemoryTool.PMAP(ALL=True))
199+
found_pattern = tool.find_and_replace_hex_pattern("87 ?? 2B", "87 1D 2B")
200+
for index in range(0, len(found_pattern[0])):
201+
# address hex value
202+
print(f"{found_pattern[0][index]}: {found_pattern[2][index]}")
203+
print(f"Total Pattern found and replaced: {found_pattern[1]}") # returns number
204+
```
205+
176206
* Dump Maps
177207
```python
178208
from androidMemoryTool import AndroidMemoryTool
@@ -181,12 +211,160 @@ is_dumped = tool.dump_maps(path="./")
181211
print(is_dumped)
182212
```
183213

214+
-----------
215+
216+
## Android Memory Tool CLI Documentation
217+
```
218+
-> This Version is come with an exciting feature called CLI (command line interface) means you dont need to execute the code everytime just use the tools cli to do short work.
219+
```
220+
221+
The Android Memory Tool CLI is a command-line interface for the Android Memory Tool. It provides various commands to interact with memory in Android applications.
222+
223+
### Usage
224+
* For Linux:
225+
```
226+
python3 -m androidMemoryTool <command> [options]
227+
```
228+
* For Android:
229+
Execute the tool with root privileges using `sudo`:
230+
```
231+
sudo python3 -m androidMemoryTool <command> [options]
232+
```
233+
234+
* If you added the bin path of python libraries to environment variable then you can execute it directly
235+
````
236+
amt <command> [options]
237+
````
238+
**and use sudo for android**
239+
240+
### Available Commands
241+
* `read_value`: Read a value from memory.
242+
* `read_write_value`: Read and write a value in memory.
243+
* `write_lib`: Write a value to a library.
244+
* `read_lib`: Read a value from a library.
245+
* `refiner_address`: Refine a list of addresses.
246+
* `get_module_base_address`: Get the base address of a module.
247+
* `raw_dump`: Dump a library as raw binary.
248+
* `find_hex_pattern`: Find a hexadecimal pattern in memory.
249+
* `find_and_replace_hex_pattern`: Find and replace a hexadecimal pattern in memory.
250+
* `dump_maps`: Dump memory maps.
251+
* `get_pid`: Return the PID of a process.
252+
* `help`: Display help information.
253+
254+
### Command-line Data Types
255+
Pass them with just name as given below
256+
* `DWORD`
257+
* `FLOAT`
258+
* `DOUBLE`
259+
* `WORD`
260+
* `BYTE`
261+
* `QWORD`
262+
* `XOR`
263+
* `UTF_8`
264+
* `UTF_16LE`
265+
266+
### Command Details
267+
You can get detailed information about each command and its usage by running:
268+
```
269+
python3 -m androidMemoryTool help <command>
270+
```
271+
For example, to get help for the read_value command, run:
272+
```
273+
python3 -m androidMemoryTool help read_value
274+
```
275+
276+
### Examples
277+
* Read a value from memory:
278+
````
279+
python3 -m androidMemoryTool read_value <pkg> <type> <speed_mode> <workers> <read>
280+
````
281+
Replace <pkg>, <type>, <speed_mode>, <workers>, and <read> with the appropriate values.
282+
283+
* Read and write a value in memory:
284+
````
285+
python3 -m androidMemoryTool read_write_value <pkg> <type> <speed_mode> <workers> <read> <write>
286+
````
287+
Replace <pkg>, <type>, <speed_mode>, <workers>, <read>, and <write> with the appropriate values.
288+
289+
* Write a value to a library:
290+
````
291+
python3 -m androidMemoryTool write_lib <pkg> <type> <base_address> <offset> <write_value>
292+
````
293+
Replace <pkg>, <type>, <base_address>, <offset>, and <write_value> with the appropriate values.
294+
295+
* Read a value from a library:
296+
````
297+
python3 -m androidMemoryTool read_lib <pkg> <type> <base_address> <offset> [--value <value>]
298+
````
299+
Replace <pkg>, <type>, <base_address>, <offset>, and <value> with the appropriate values.
300+
301+
* Refine a list of addresses:
302+
````
303+
python3 -m androidMemoryTool refiner_address <pkg> <type> <speed_mode> <workers> <list_address> <value_to_refine>
304+
````
305+
Replace <pkg>, <type>, <speed_mode>, <workers>, <list_address>, and <value_to_refine> with the appropriate values.
306+
307+
* Get the base address of a module:
308+
````
309+
python3 -m androidMemoryTool get_module_base_address <pid> <module_name>
310+
````
311+
Replace <pid> and <module_name> with the appropriate values.
312+
313+
* Dump a library as raw binary:
314+
````
315+
python3 -m androidMemoryTool raw_dump <pkg> <lib_name> [<path>]
316+
````
317+
Replace <pkg>, <lib_name>, and <path> with the appropriate values. The <path> argument is optional and defaults to the current directory.
318+
319+
* Find a hexadecimal pattern in memory:
320+
````
321+
python3 -m androidMemoryTool find_hex_pattern <pkg> <type> <speed_mode> <workers> <hex_pattern>
322+
````
323+
Replace <pkg>, <type>, <speed_mode>, <workers>, and <hex_pattern> with the appropriate values.
324+
325+
* Find and replace a hexadecimal pattern in memory:
326+
````
327+
python3 -m androidMemoryTool find_and_replace_hex_pattern <pkg> <type> <speed_mode> <workers> <search_pattern> <replace_pattern>
328+
````
329+
Replace <pkg>, <type>, <speed_mode>, <workers>, <search_pattern>, and <replace_pattern> with the appropriate values.
330+
331+
* Dump memory maps:
332+
````
333+
python3 -m androidMemoryTool dump_maps <pkg> [--path <path>]
334+
````
335+
Replace <pkg> and <path> with the appropriate values. The <path> argument is optional and defaults to the current directory.
336+
337+
* Return the PID of a process:
338+
````
339+
python3 -m androidMemoryTool get_pid <pkg>
340+
````
341+
Replace <pkg> with the appropriate package name.
342+
343+
### Version
344+
To get the version of the Android Memory Tool, use the following command:
345+
````
346+
python3 -m androidMemoryTool -v
347+
````
348+
### Help
349+
To display general help information or help for a specific command, use the help command:
350+
````
351+
python3 -m androidMemoryTool help [command]
352+
````
353+
Replace [command] with the desired command to get help for that command. If no command is provided, general help information will be displayed.
354+
355+
356+
-----------
357+
184358
# Detailed Documentation
185-
You can found detailed documentation [here](https://github.com/Anonym0usWork1221/android-memorytool/tree/main/Documentation)
359+
You can find detailed documentation [here](https://github.com/Anonym0usWork1221/android-memorytool/tree/main/Documentation)
360+
361+
-----------
186362

187363
# Errors
188364
Some known errors and their solutions can be found [here](https://github.com/Anonym0usWork1221/android-memorytool/blob/main/ERRORS.md)
189365

366+
-----------
367+
190368
Supported Data Types
191369
-------------------
192370

@@ -225,12 +403,15 @@ Supported Map Ranges
225403
| B_Bad | Bad | Bad Memory (dangerous) |
226404
| CODE_SYSTEM | Code system | Code system memory (dangerous) |
227405

406+
-----------
407+
228408
# Contributor
229409

230410
<a href = "https://github.com/Anonym0usWork1221/android-memorytool/graphs/contributors">
231411
<img src = "https://contrib.rocks/image?repo=Anonym0usWork1221/android-memorytool"/>
232412
</a>
233413

414+
-----------
234415

235416
Assistance
236417
----------
@@ -242,6 +423,7 @@ I also created a Discord group:
242423

243424
* Server : https://discord.gg/RMNcqzmt9f
244425

426+
-----------
245427

246428
Buy Me a coffee
247429
--------------

Tests/AndroidMemoryTool-Tests.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# from androidMemoryTool import AndroidMemoryTool
2+
3+
# initialize tool.
4+
# tool = AndroidMemoryTool(PKG="ac_client", TYPE=AndroidMemoryTool.DataTypes.DWORD, SPEED_MODE=True, WORKERS=55,
5+
# pMAP=AndroidMemoryTool.PMAP(ALL=True))
6+
# print(tool.get_pid("ac_client"))
7+
# values = tool.read_value(100)
8+
# founded_offsets = values[0]
9+
#
10+
# refined_address = tool.refiner_address(list_address=founded_offsets, value_to_refine=50)
11+
# tool.read_lib('0x0', '0x100')
12+
# tool.write_lib('0x0', '0x0', 10)
13+
14+
# pid = AndroidMemoryTool.get_pid("714")
15+
# print(pid)
16+
17+
# if you are reading you will get tuple of two values offset list and total values found
18+
19+
# values = tool.read_value(100)
20+
# founded_offsets = values[0]
21+
# founded_values = values[1]
22+
# print(founded_values)
23+
# print(founded_offsets)
24+
25+
26+
# if you are writing only return total value wrote
27+
# values1 = tool.read_write_value(100, 10)
28+
# print(values1)
29+
30+
31+
# if you are reading lib offset only get the value at that place
32+
# values1 = tool.read_lib(0x0, 0x100)
33+
# print(values1)
34+
35+
36+
# if you are writing lib offset only get the true/false at that place
37+
# values1 = tool.write_lib(0x0, 0x100, 20)
38+
# print(values1)
39+
40+
# dump = tool.raw_dump('client.so', '/home/kali/Documents/')
41+
# print(dump)
42+
43+
# print(tool.read_value("19h"))
44+
45+
# Manually entered pid
46+
# tool = AndroidMemoryTool(PKG=714, TYPE=AndroidMemoryTool.DataTypes.DWORD, SPEED_MODE=True, WORKERS=55,
47+
# pMAP=AndroidMemoryTool.PMAP(ALL=True))
48+
# test_value = tool.read_value(42)
49+
# print(test_value)
50+
51+
# to dump maps
52+
# is_dumped = tool.dump_maps(path="./")
53+
# print(is_dumped)
54+
55+
# utf8 lib tests
56+
# tool = AndroidMemoryTool(PKG=662, TYPE=AndroidMemoryTool.DataTypes.UTF_8, SPEED_MODE=True, WORKERS=55,
57+
# pMAP=AndroidMemoryTool.PMAP(ALL=True))
58+
# off = tool.read_value("hi")
59+
# print(off)
60+
61+
# off = tool.read_lib(0x5590fb61d8e2, 0x0, "hi")
62+
# print(off)
63+
64+
# Hex pattern
65+
# found_pattern = tool.find_hex_pattern("87 ?? 2B")
66+
# for index in range(0, len(found_pattern[0])):
67+
# print(f"{found_pattern[0][index]}: {found_pattern[2][index]}")
68+
# print(f"Total Pattern found: {found_pattern[1]}")
69+
70+
# Read Write Hex pattern
71+
# found_pattern = tool.find_and_replace_hex_pattern("87 ?? 2B", "87 1D 2D")
72+
# for index in range(0, len(found_pattern[0])):
73+
# print(f"{found_pattern[0][index]}: {found_pattern[2][index]}")
74+
# print(f"Total Pattern found and replaced: {found_pattern[1]}")

0 commit comments

Comments
 (0)