- Gender
- Male
- Device
- Xiaomi Mi 9T - Android 9, Honor Magic5 Lite - Android 13
- Country
- Sbennytopia
Requirements:
- A good knowledge of smali coding;
- CatLog (or any apps to read logs)
- Apktool (or anything you prefer to decompile your app)
- Notepad++ (or whatever you use to edit smali files)
It might happen sooner or later, for a need or another, that you'd want to write something to see in your logcat (I personally use CatLog for it), such as checking why/when a game/app crashes or is detected by some protections or things like that.
Well, I soon discovered a few lines of smali code which helps achieving this:
It should be self explanatory, if you have some smali knowledge. Basically it logs your desired custom string (in this case "This is the debug line I want to write" is what I'm writing in the logs).
Example of my custom debug info written in the game. In this case, my string was "onCreate1 called", so I searched it in my CatLog app and it was actually logged as you can see:
Q: How to read that log info when I run the app?
A: You just need CatLog or any other logging apps available on Google Play. Then, just open it and search for the debug string you wrote. Assuming you're trying to see what force-closes a mod apk (or a hack you created), in order to find and bypass the protection, if you find that string in the debug logs, it means it's being called before the function you're checking, right where you pasted it. If you instead can't find the debug string in your logcats, it means that code is not being called, and the app force-closes because of another function, called BEFORE the position you pasted your debug string in.
Q: Where to place it?
A: Well, if you're asking such question, you probably don't need this tutorial or you don't know what you're reading here, but anyways, for newbies purposes, I'll still answer this question. Basically you aim to write the debug info in a specific position in your decoded smali, right where you think the app is crashing or force-closing or anything else you want to find out about your app. A basic approach would be pasting it in what's being called by your OnCreate.
Q: I added that code and the app now crashes because of it. Why?
A: In my example, I used v0 and v1, if you're pasting that AFTER some code which already used v0 and/or v1, it might happen that the app crashes because you pass a different variable, so the solution is to change number, for example you could edit .locals at the top of the method to .locals 15 or even .locals 20 and then use v19 and v20, to be safer. If that still doesn't work, you probably just need to paste those three lines elsewhere.
I might probably add some more details from time to time, whenever I get a chance, but for the moment it should be clear enough. If not, feel free to ask below
This tutorial is written by Sbenny, only for sbenny.com.
Sbenny.com® - All Rights Reserved
- A good knowledge of smali coding;
- CatLog (or any apps to read logs)
- Apktool (or anything you prefer to decompile your app)
- Notepad++ (or whatever you use to edit smali files)
It might happen sooner or later, for a need or another, that you'd want to write something to see in your logcat (I personally use CatLog for it), such as checking why/when a game/app crashes or is detected by some protections or things like that.
Well, I soon discovered a few lines of smali code which helps achieving this:
Code:
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "This is the debug line I want to write"
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
Example of my custom debug info written in the game. In this case, my string was "onCreate1 called", so I searched it in my CatLog app and it was actually logged as you can see:
Q: How to read that log info when I run the app?
A: You just need CatLog or any other logging apps available on Google Play. Then, just open it and search for the debug string you wrote. Assuming you're trying to see what force-closes a mod apk (or a hack you created), in order to find and bypass the protection, if you find that string in the debug logs, it means it's being called before the function you're checking, right where you pasted it. If you instead can't find the debug string in your logcats, it means that code is not being called, and the app force-closes because of another function, called BEFORE the position you pasted your debug string in.
Q: Where to place it?
A: Well, if you're asking such question, you probably don't need this tutorial or you don't know what you're reading here, but anyways, for newbies purposes, I'll still answer this question. Basically you aim to write the debug info in a specific position in your decoded smali, right where you think the app is crashing or force-closing or anything else you want to find out about your app. A basic approach would be pasting it in what's being called by your OnCreate.
Q: I added that code and the app now crashes because of it. Why?
A: In my example, I used v0 and v1, if you're pasting that AFTER some code which already used v0 and/or v1, it might happen that the app crashes because you pass a different variable, so the solution is to change number, for example you could edit .locals at the top of the method to .locals 15 or even .locals 20 and then use v19 and v20, to be safer. If that still doesn't work, you probably just need to paste those three lines elsewhere.
I might probably add some more details from time to time, whenever I get a chance, but for the moment it should be clear enough. If not, feel free to ask below
This tutorial is written by Sbenny, only for sbenny.com.
Sbenny.com® - All Rights Reserved