[GUIDE] Smali coding guide for beginners

Rick1684

Senior Member
Sep 25, 2012
604
469
63
37
New Carlisle
To all of you here thanks. Ive learned so much from you. Getting that volume slider taking care of means alot. @remuntada78 I really appreciate all the help. Its nice to have someone take the time to help. THATS TO ALL OF YOU. Much Love.
 
Last edited:

newbreedsoftware

Senior Member
Mar 4, 2009
73
5
0
Carson City
I'm trying to modify some smali code and I'm not exactly sure I'm doing it correctly. I am trying to bypass root detection on a game I want to play on my tablet. I found where the root detection process happens. My question is do I need to just change the const-string lines to if-nez v0, :cond_0 or do I need to edit the other files as well? Any ideas would be much appreciated, thank you. I have attached a screen shot of the smali source as well.
 

Attachments

RealWelder

Senior Member
Sep 17, 2014
692
291
93
Muncie, IN
Need some help/information. I am trying to port the 4 way reboot mod to an LG phone, with no luck. I noticed that it seems like the LG phone uses a different method for createDialog. I think that is why this mod isn't working. I guess my question is does anyone know anything about GlobalActions$GlobalActionsCreateDialog instead of Landroid/app/AlertDialog$builder?

Sent from my KYOCERA-C6745 using Tapatalk
 
Aug 28, 2016
6
0
0
Register p1 is larger than the maximum register v2 for this method

The original smali code:


# direct methods
.method public constructor <init>()V
.locals 2
.param p1, "subscription" # I

.prologue
.line 178
invoke-direct {p0}, Ljava/lang/Object;-><init>()V


The error:

out/framework/smali/android/telephony/PhoneStateListener.smali[46,1] Register p1 is larger than the maximum register v2 for this method
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file: android/telephony/PhoneStateListener.smali
at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:67)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:51)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:38)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:400)
at brut.androlib.Androlib.buildSources(Androlib.java:331)
at brut.androlib.Androlib.build(Androlib.java:287)
at brut.androlib.Androlib.build(Androlib.java:263)
at brut.apktool.Main.cmdBuild(Main.java:224)

why is this happening?
 

djdarkknight96

Recognized Themer
Nov 2, 2009
16,838
46,956
263
Springfield
www.designrifts.com
The original smali code:


# direct methods
.method public constructor <init>()V
.locals 2
.param p1, "subscription" # I

.prologue
.line 178
invoke-direct {p0}, Ljava/lang/Object;-><init>()V


The error:

out/framework/smali/android/telephony/PhoneStateListener.smali[46,1] Register p1 is larger than the maximum register v2 for this method
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file: android/telephony/PhoneStateListener.smali
at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:67)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:51)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:38)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:400)
at brut.androlib.Androlib.buildSources(Androlib.java:331)
at brut.androlib.Androlib.build(Androlib.java:287)
at brut.androlib.Androlib.build(Androlib.java:263)
at brut.apktool.Main.cmdBuild(Main.java:224)

why is this happening?
It's saying p1 is larger then v2 so look for v2 and see. Hard to help without the entire smali code.

Sent from my Nexus 6 using XDA Labs

---------- Post added at 03:13 AM ---------- Previous post was at 03:11 AM ----------

I'm trying to modify some smali code and I'm not exactly sure I'm doing it correctly. I am trying to bypass root detection on a game I want to play on my tablet. I found where the root detection process happens. My question is do I need to just change the const-string lines to if-nez v0, :cond_0 or do I need to edit the other files as well? Any ideas would be much appreciated, thank you. I have attached a screen shot of the smali source as well.
Try just deleting those lines, I mean the entire lines. I do that for Google apps so having a clear primary color doesn't crash.

Sent from my Nexus 6 using XDA Labs
 

levone1

Senior Member
Dec 28, 2014
3,745
1,451
243
BEGINNER'S GUIDE TO SMALI CODING OF SYSTEMUI
Presenting to you a beginners guide to smali coding. This thread would focus specifically on SystemUI modding. Please keep questions related to other apks out of this thread.
Thanks for this. I am still pretty much in the dark, but a little bit lighter now...
I have a general question, hopefully not too ot - let me know if so - trying to set bg of a text edit view which there is no drawable or layout xml for. I found the smali file for it, and a handful of lines indicating setBackgroundColor, with value of (I)V. I think I understand that the V is for void, and I need to change what's in the parentheses to a color value, (0xffffff, or something). I've found several examples on xda and stack overflow with 'color' and 'parse color', etc, but everything I try gets a recompile error - 'no viable alternative'. I'm sensing that I need to add something else, but not quite sure, (maybe a 'const' or 'if' line...). Any help?
Thanks
 

djdarkknight96

Recognized Themer
Nov 2, 2009
16,838
46,956
263
Springfield
www.designrifts.com
Thanks for this. I am still pretty much in the dark, but a little bit lighter now...
I have a general question, hopefully not too ot - let me know if so - trying to set bg of a text edit view which there is no drawable or layout xml for. I found the smali file for it, and a handful of lines indicating setBackgroundColor, with value of (I)V. I think I understand that the V is for void, and I need to change what's in the parentheses to a color value, (0xffffff, or something). I've found several examples on xda and stack overflow with 'color' and 'parse color', etc, but everything I try gets a recompile error - 'no viable alternative'. I'm sensing that I need to add something else, but not quite sure, (maybe a 'const' or 'if' line...). Any help?
Thanks
On the set background color there's a variable like v0 look to see if there's a definition. If not add one yourself right above it using a smali color converter. Example const v0, -0x1000000 "black" but make the v# match the set bg v#. Trial and error search it. I usually use pink to trace stuff.
 
  • Like
Reactions: levone1

levone1

Senior Member
Dec 28, 2014
3,745
1,451
243
On the set background color there's a variable like v0 look to see if there's a definition. If not add one yourself right above it using a smali color converter. Example const v0, -0x1000000 "black" but make the v# match the set bg v#. Trial and error search it. I usually use pink to trace stuff.
Just wanted to let you know that you came through for me
A little trial and error, and I figured it out. Reply so I can give you another thanks.
 

solquest3

Senior Member
Mar 27, 2013
394
34
48
Hello.
I don't know anything about smali, but I'd like to do a thing and I've been told I have to implement things at smali level.
I'd like to disable the status bar (preventing from expanding) when an app is on.
I've tried contacting that app developer, but I haven't got any reply (last update was in 2013).
I've found this post http://www.techjini.com/blog/block-n...nding-android/ where there's described how to add a transparent window for covering the status bar, so it can not get the touches, but the problem is that I have no idea on how I can add that to the app (even if I can edit apk file).
I've open the app with Virtous Ten Studios, so I can change things, but I don't know what to do.
I've added
android:name=”android.permission.SYSTEM_ALERT_WIND OW”/>
to AndroidManifest.xml, but then I have no idea on where to write the other code.
Opening the app I have these folders
- original
- res
- smali
Do you know where I should write that code? Or what I have to look for?
Thanks a lot!
Luigi.
Android 6.0.1
rooted
 

bho500

Member
Sep 28, 2017
6
1
13
20
Sicily, Italy
Premising that I am totally new to Android programming, so sorry if you don't understand what I'm saying?.
I have to change the expiration date of my app and I think I have already finded the code that would be this:

new-instance v2, Ljava/util/Date;
const-wide v0, 0x15fcd33f38fL.

Now the problem is that when I change the hex my app still tells me that it must be upgraded or that the date and time of my phone is wrong. What should I do?