Tutorial Code Injection (FileWritter)

Theeundertakeer

Platinian
Original poster
Jan 8, 2021
32
78
18
32
Armenia
Hello. I'm posting a small helper class to write some data into the file. There are cases when we want to know the content of the data and the data might be too long to show it via Toast. I've created a small utility class FileWritter which you can inject and write any String representation of an object into the file.

The file will be located in /data/data/com.yourGameYouWantToMode/files/game-data.txt (You can customize the name of the TXT to whatever you want).

The file is smali ready.

Pre-requests :

  1. Be aware that writing anything to a file requires a CONTEXT so you need either call it from any sort of Activity or pass context around and later pass it to the function. If you find yourself too hard to do it, just drop a message I will create another utility which will make that hassle a little easier.
  2. Permission checking is available, for the first time if you are trying on the actual physical device with Android version 6.0 and higher, the very first time you will be asked to allow Write permission, just hit allow and redo the action to write to the file
  3. The method is static, so you can inject (hook it up) in any place as long as you can pass Context to the method.

Sample example of usage :

Let's say we have Decompiled some game called com.awesomegame.shooter


The steps we need to do for FileWritter :

  1. Unzip the content
  2. Go to com/writter
  3. Drag the content of "writter" folder to "com " folder of your decompiled game - so the decompiled tree of the game shall look like this :
com/writter/...
com/awesomegame/..


Now we can access the writter.

The simple example to invoke a function in activity will look like this :

Code:
conts/4 v1, "Some information to Print"

invoke-static {v1, p0}, Lcom/writer/FileWriter;->writeToFile(Ljava/lang/String;Landroid/app/Activity;)V
Where "v1" will be your actual data representation in STRING and p0 will be the CONTEXT (Activity)

You will get a Toast in both cases : Success of writing to a file or in a failure.


Comment if you have any questions.
 

Attachments