Everyday.
jiaying (:
11:11 PM


Saturday, May 19, 2012
ahh cbox expired ._>
oh well nevermind.
hows exams man?
kinda depressed i didnt get an a+ for math.
meh shit happens.
but right now i got so many things to do i dont think i'll ever be bored haha

like modding android apk's to remove licensing
basically right apks are just the apps itself on an android phone.
installing it just copies it to a certain part of your phone.
and its actually a zip file containing program code, images and xmls

xmls - define important parameters of the program,
such as whether it should start up automatically,
or sometimes the text used like menu names etc.

images - contains all the images used by the application
comes in many types, like theres a set of images for
low resolution phones, high resolution phones, mid resolution phones etc.
some programs dont have them cause developers were lazy.

program code - this code is usually in .dex files. well it should be.
the thing about android is that apps execute in a virtual machine
sort of like a computer within a computer.
the computer within can understand .dex code really well so yeah!

so sometimes we might want to change the look of a certain app or
edit its functionality or something. One main reason for modding
apks is to remove license verification. (well who pays for software anyway)

There are many ways to modify (aka mod) an apk.
The first way is to use a .dex to .jar converter.
This converts the .dex to a .jar which is java code.
(btw java is another computing language used by computers)
(a computing language is just like languages.
you can tell the computer to do things using different languages)

so now that we have a .jar file, we can proceed to decompile it.
(decompiling is sorta like converting from computer-understandable code to human-understandable code)
In this case we use JDgui to decompile the jar, modify the necessary code,
then we recompile it using android sdk and create an apk file.
the drawback of this is that its a long-winded process, very error prone
and additionally jdgui cannot decompile all jars. sometimes it screws up
especially when there are switch statements and labels.
so you'd end up with code that doesnt make sense or work.

the second method is to decompile the apk using smali
(smali is an assembler/disassebler for Android's dex format.)
The output of it would be each individual class file, but in smali code.
We can then edit this code and recompile easily.
The drawback of this method is that smali code is really hard to understand
unless you've been working with it for a while,
or unless you have the source code (i.e human-understandable equivalent code)

That said, you should have a general idea on how to modify apks.
One thing to note is that you must re-sign your apk after you've modified it and recompiled.
This is because installing the apk on Android requires the apk to be signed.
No idea why though. Just sign it with the test key.
There's a cool app on Google Play called Signapktic that signs your apks easily.

For those wishing to remove license verification,
most applications on Google Play use the framework provided by Google
WITHOUT ANY MODIFICATIONS.
Google's framework is really simple, the app basically checks the Play for a valid license,
then issues a response to the code that requested for it.
So what if we changed the response to a constant "valid" response?
Our application would work all the time! Even without an internet connection!

Under LicenseValidator.smali (smali code from second method), we can see

.field private static final ERROR_CONTACTING_SERVER:I = 0x101
.field private static final ERROR_INVALID_PACKAGE_NAME:I = 0x102
.field private static final ERROR_NON_MATCHING_UID:I = 0x103
.field private static final ERROR_NOT_MARKET_MANAGED:I = 0x3
.field private static final ERROR_OVER_QUOTA:I = 0x5
.field private static final ERROR_SERVER_FAILURE:I = 0x4
.field private static final LICENSED:I = 0x0
.field private static final LICENSED_OLD_KEY:I = 0x2
.field private static final NOT_LICENSED:I = 0x1

This defines the variables and their associated number (0xblah is a hex number. Google "hex".)

Under LicenseValidator.smali, we also find something like

.sparse-switch
0x0 -> :sswitch_d3
0x1 -> :sswitch_de
0x2 -> :sswitch_d3
0x3 -> :sswitch_11d
0x4 -> :sswitch_f3
0x5 -> :sswitch_101
0x101 -> :sswitch_e5
0x102 -> :sswitch_10f
0x103 -> :sswitch_116
.end sparse-switch

This is the smali equivalent of a java switch.
We can see that for each response, a unique activity is triggered.
To circumvent this, one just needs to call the "verified" activity
regardless of the response.
Since 0x0 (verified) calls sswitch_d3
We can just replace all other calls to sswitch_d3!

.sparse-switch
0x0 -> :sswitch_d3
0x1 -> :sswitch_d3
0x2 -> :sswitch_d3
0x3 -> :sswitch_d3
0x4 -> :sswitch_d3
0x5 -> :sswitch_d3
0x101 -> :sswitch_d3
0x102 -> :sswitch_d3
0x103 -> :sswitch_d3
.end sparse-switch

Regardless of what the response was from Google,
our application here will think that it is valid,
and continue to let you use the application.

Unfortunately, more and more applications on Play
are modifying the framework to make it harder to crack.
One way is to spread this license verification code along many classes.
Another way is to use their own licensing system.
Also, some applications do a crc check on itself (the apk).
This is harder to bypass as you have to identify the responsible code and nullify it.
And smali code is not that understandable.

There exists an app called Lucky Patcher which allows you to remove
license verification from apks installed with a click.
I still have no idea how it works, but it manages to bypass
the CRC check (I think). It can also remove Google Ads.
So yea check it out. Its cool.

Some apps are to date uncrackable. Well sort of.
Like Poweramp. Poweramp crack works by modifying the .dex file
and forcing the system to use the modified file instead of the apk
or something like that. Hence it will have to constantly keep it
unmodified or something (i.e. not standalone).

Oh well hope you had fun reading this. Bye!

;LIGHT&
2:10:00 AM