Making modifications & mergesmali - Nook Touch Android Development

This is a new thread on the subject of modifying the system or
applications on the Nook. I'd like to see a separate thread on
modifying the kernel, but let's keep that off this.
The Basics
A bit of the system or an app is usually written in Java. Different
tools are used to compile and process it to the final product.
The Java Runtime Environment (JRE) is what allows you to run various tools and program on your host computer.
The Java Development Kit (JDK), version 6, update 33 contains the tools you need to work with Java
javac - the Java compiler
jarsigner - a tool for signing products
Android Software Development Kit (SDK), with downloads for Level 7 API.
Android Asset Packaging Tool (AAPT) - processes resources like images and layouts
Android Debug Bridge (ADB) - allows connection and debugging to your device
The final product is either an APK file or a JAR file, both of which
are basically ZIP files. Both of these contain a file called
classes.dex which contain the executable code. An APK file also
contains resources in a directory hierarchy. Some of these items,
like regular PNG graphics are exactly as you'd find them anywhere.
Other items, like "9 patch files" (9.png), are modified and others,
like XML files, are compressed. An APK file also contains a file
called AndroidManifest.xml that describes the product. Both APK
and JAR files can also contain signatures in the META-INF
directory.
Reverse Engineering
In the best of all worlds, you would have the original Java code that
the developers used to make the product. This is seldom available.
To work around this you need to backwards step the entire
process to get back to the original Java code. There is a problem,
the backwards process is not unambiguous. Yes, you can
backtrack to some Java code, that if compiled would work the
same as the original, but it would not look the same. Often the
intent of a piece of software is apparent from its layout. Also, you
will have none of the comments in the original code.
We can easily backtrack to an intermediate place between source
Java code and the final product. This is a place that does not really
exist in the original product generation process. We can take the
raw executable code out of a product and display it in a human
readable (and editable) form. "Smali" is the name of this
representation. It is analogous to assembly code. As stated, it
really does not exist as a language in the original compilation.
There is a software tool for taking apart a product and dissecting
it into the Smali code and the resources (if any). This tool also can
be used for compiling the Smali code back into the modified
product.
apktool, a tool for reverse engineering Android files
One of the main actions of the apktool is to take apart classes.dex
and generate a whole tree of files that end in the extension ".smali".
These files will have names like:
\NeatoApp\smali\com\bigcompany\neatoapp\MainView$23.smali
Modifying a Product
So, we can take a finished product, use apktool on it to take it apart
to pieces, modify some piece, then put it back together with
apktool. Modifying a resource like a graphic is easy, just modify
it (except 9.png, more later). Changing the wording of a popup
message is also easy. Changing the language of the interface
takes a bit more care to do it correctly. Modifying the Smali code
takes a bit of knowledge and done incorrectly can even brick your
device (repairable with a backup). If you have a chunk of Smali
code that someone modified for some reason, it's not too difficult
to open up your extracted Smali file, edit in the chunk, save it and
run apktool to put everything back together.
The Problem
We see this problem with kernels all the time, that some users want
a kernel with A, B, C and others want it with C, D, E. The number
of competing configuration gets out of hand. Moreover if you
come up with feature F, then you have to find a way to package
it up with A, B, C, for the first user and D, E for the second user.
A Solution
One possible solution is to let the user decide. You can distribute
options A-F independently and let the user install them themselves.
In principle, this means the user takes whatever version of
something they have on their device, apply a specific patch, then
reinstall it on their device. This would also open things up to
modifying different versions (for example Nook Touch vs. Nook
Glow) with the same mod.
mergesmali
mergesmali is a new tool for managing modifications to Smali
code. There is no particular magic behind it. It simply can replace
sections of Smali in a text file. It is agile enough to not rely on line
numbers or exact specifics of the Smali file. Here is a simple
example how you would use it to modify something:
Code:
adb pull /system/framework/android.policy.jar
apktool d android.policy.jar \Policy
mergesmali /v \Policy\smali\com\android\internal\policy\impl\LockScreen.smali landscapemod.smali
apktool b \Policy android.policy.jar
adb push android.policy.jar /system/framework
Mod Developers
We'll get to how to make the modification files for Smali soon...

Renate,
Great post! :good:
Could you add few words on logcat/ddms to help with troubleshooting, if a mod doesn’t work as expected, please?

Yes, I'm still working on this.
I've been patching the stock reader for dictionary and other things.
I was doing the patches on the 1.1.2 Reader.apk and it worked fine.
I just switched over to the 1.1.5 Reader.apk and it patched it fine without any changes.

This post addresses the developer side of things.
It is possible to patch Smali by hand.
For quick and dirty, this is not a bad solution.
The problem is that one must be aware of how many registers are used and for what.
In the first instance, if I need another register for my mod, that can push register references on other instructions out of the 4 bit range.
Also, if the stock code is revised later that can also change register references.
Even the simple addition of a debug print statement (Log.d) can affect things.
The solution is to always replace entire methods.
That way you are not fighting with conflicting code.
The logical place to keep your patches is in Java.
Obviously you can't have a standalone method, there has to be a class.
For instance, the stock Reader.apk has a place where it validates EAN (ISBN).
It checks for all digits, which bombs on sequences with dashes.
We want to replace that, easy enough, but we have to wrap it in the class.
Code:
package com.bn.nook.model.product;
public class Products
{
public static boolean isValidEan(String ean)
{
return(true);
}
}
Obviously this does not fully implement the class, but it has enough for our little method.
We do a normal compile of this, then apktool d it to the smali.
mergesmali can then scan through this smali and edit the stock smali from the apktool d'ed stock app.
A final apktool b, jarsigning and zipaligning puts it all back together.
But what if the method that we want to replace called some other method?
We would have to put something in our class to prevent compilation errors and to ensure that the smali code for our method did the correct invocation.
We end up writing stubs for these methods that do nothing.
If it's a void method, the body of the method is simply {}, for boolean types {return(false);}, etc.
But how do we make sure that mergesmali does not substitute these stub methods for the good methods already in stock?
Annotations.
By putting Annotations before each method, we can tell mergesmali what to do.
These annotations are preserved in the decoded smali.
They are subsequently deleted when mergesmali merges the smali.
Expanding our original example (this is just an example, not realistic):
Code:
package com.bn.nook.model.product;
import com.whoever.MergeSmali.*;
public class Products
{
@Ignore
public Products() {}
@Ignore
public static double complicatedOtherMethod(String ean, String msg)
{ return(0.0); }
@Replace
public static boolean isValidEan(String ean)
{
if (complicatedOtherMethod(ean, "Hello")<2.3) return(false);
return(true);
}
}
The @Replace tells mergesmali to replace this method.
The @Ignore tells mergesmali not to replace this method.
We need to have the stub for complicatedOtherMethod in the source.
Well, why is the constructor in there?
The compiler will generate a default constructor if we don't write one and it would have no annotation.
mergesmali prints an error if any method does not have an annotation;
There is also @Append for new methods that are not in the stock.
There is also @Delete to delete methods (that either have a super or not being used at all with the rewritten methods).
What's in com.whoever.MergeSmali.* ?
Code:
package com.whoever;
public class MergeSmali
{
public @interface Ignore {}
public @interface Replace {}
public @interface Append {}
public @interface Delete {}
}
The package is not important as long as it's an Annotation and the class/subclasses are as indicated.

collaboration?
Maybe we could start some sort of work distribution (and knowledge) towards fullfiiling some common goal for the NST.

Here's the Windows (command line) executable for mergesmali.
The basic usage is:
Code:
mergesmali /v [i]stock.smali[/i] [i]patch.smali[/i]
And here's the commands to integrate the new dictionary app to the stock Reader.
Code:
apktool.bat d Reader.apk \Reader
mergesmali /v \Reader\smali\com\bn\nook\reader\ui\ReaderMainView.smali ReaderMainView.smali
apktool.bat b \Reader NewReader.apk
It should generate the following message:
Code:
Replaced: public showLookupView()V
At this point you only have the question of how you are going to sign the modified Reader.
If you have resigned your whole system already, you can just resign with that and install.
You could also edit AndroidManifest.xml before the apktool b and delete the sharedid.
Then you could install it as a regular app after deleting the system app.

Renate NST said:
At this point you only have the question of how you are going to sign the modified Reader.
If you have resigned your whole system already
Click to expand...
Click to collapse
I guess no one did it... yet.
Renate NST said:
You could also edit AndroidManifest.xml before the apktool b and delete the sharedid.
Then you could install it as a regular app after deleting the system app.
Click to expand...
Click to collapse
I don’t understand Android security well enough.
There a discrepancy between documentation and how it works or maybe I don’t understand it at all.
Anyway – if Reader.apk is resigned, it should run under different user, thus loose access to shared databases (internal, annotations, bookmarks, etc.)
Do we need to fix permission to make them RW for everyone?
Could you check (ps) what user(s) "home", "library" and "patched reader" use on you nook now, please?

Annotations, bookmarks, last reading point are all providers implemented and used in Reader.apk.
As far as I can tell, there is no particular reason why Reader.apk uses a sharedId.
I don't have stock Home or Library running on my Nook.
I forget where I have Reader.apk installed right now.
It's been in /system/app or /data/app and worked fine in either place.
Resigning does not change user.

Renate NST said:
Annotations, bookmarks, last reading point are all providers implemented and used in Reader.apk.
Click to expand...
Click to collapse
I would expect the provider for Annotations, bookmarks is Reader.apk
They are not used anywhere else.
last reading point is used in Home.apk too.
Out of curiosity, where Annotations, bookmarks and last reading point providers are implemented?
In framework itself?
Renate NST said:
Resigning does not change user.
Click to expand...
Click to collapse
Ouch.
Stock reader runs as shared user.
If we resign it – it has to run as different one, according to security docs...
And it doesn’t matter if shared id is in manifest still or not.
I guess, I need to do some testing…

Ok, I meant resigning it with the system signature it can keep the same sharedId.
If you don't sign it with the same signature then you have to get rid of the sharedId.
It will then have a normal application user ID.
As far as I can tell, this should make no difference in anything.
But I have gutted most of the B&N stuff so I can't guarantee that in-store browsing or something else won't be affected.

Renate,
Could you answer this one:
ApokrifX said:
Out of curiosity, where Annotations, bookmarks and last reading point providers are implemented?
In framework itself?
Click to expand...
Click to collapse
And one more:
Is it difficult to mod and stock side-by-side?
Change app name + package for every class?

In Reader.apk
com.bn.nook.reader.providers.AnnotationsProvider
com.bn.nook.reader.providers.BaseDictionaryProvider
com.bn.nook.reader.providers.BookmarksProvider
com.bn.nook.reader.providers.LastReadingPointProvider
com.bn.nook.reader.providers.ReaderLocalProvider
(I'd like to know some time why the forums breaks words up.)
On your second question, that's an interesting one.
You'd have to change the package name all over the place,
not just in the manifest, but every smali file and every function call.
But sure, it could be done.

Renate NST said:
In Reader.apk
com.bn.nook.reader.providers.AnnotationsProvider
com.bn.nook.reader.providers.BaseDictionaryProvider
com.bn.nook.reader.providers.BookmarksProvider
com.bn.nook.reader.providers.LastReadingPointProvider
com.bn.nook.reader.providers.ReaderLocalProvider
Click to expand...
Click to collapse
Thank you!
Renate NST said:
(I'd like to know some time why the forums breaks words up.)
Click to expand...
Click to collapse
No idea…
Renate NST said:
Annotations, bookmarks, last reading point are all providers implemented and used in Reader.apk.
As far as I can tell, there is no particular reason why Reader.apk uses a sharedId.
Click to expand...
Click to collapse
Looking at B&N coding style, I won’t be surprised if Home.apk uses its own provider to read the "last reading point".
If this is the case sharedId in a must.
Renate NST said:
On your second question, that's an interesting one.
You'd have to change the package name all over the place,
not just in the manifest, but every smali file and every function call.
But sure, it could be done.
Click to expand...
Click to collapse
and every function call But it can be automated easily, right?

ApokrifX said:
If this is the case sharedId in a must.
Click to expand...
Click to collapse
No.
The "Last read" icon in the upper left corner broadcasts com.bn.nook.launch.LAST_BOOK
This is usually received by Home.apk, which uses the LRP provider in Reader.apk to get the EAN of the last book.
Home.apk then sends the intent android.intent.action.VIEW to Reader.apk with the path of the book.
Reader.apk then uses it's own LRP provider to get the actual LRP in the book.
None of this requires sharedIDs.
#2 Sure, that could be automated.

Renate NST said:
No.
The "Last read" icon in the upper left corner broadcasts com.bn.nook.launch.LAST_BOOK
This is usually received by Home.apk, which uses the LRP provider in Reader.apk to get the EAN of the last book.
Home.apk then sends the intent android.intent.action.VIEW to Reader.apk with the path of the book.
Reader.apk then uses it's own LRP provider to get the actual LRP in the book.
None of this requires sharedIDs.
Click to expand...
Click to collapse
Home shows "last book thumbnail" + on page #XYZ of #ABC also.
I recall you have deleted Home.apk.
Renate NST said:
#2 Sure, that could be automated.
Click to expand...
Click to collapse
Ok. I gotta take a look.Will try to do later today.

ApokrifX said:
Home shows "last book thumbnail" + on page #XYZ of #ABC also.
I recall you have deleted Home.apk.
Click to expand...
Click to collapse
Yes, my Library.apk replacement has a receiver for the com.bn.nook.launch.LAST_BOOK intent.
Even though Home.apk uses the Reader.apk to find LB & LRP for the preview,
it only uses LB to tell the Reader.apk what to open.
Reader.apk does its own homework checking LRP for the desired book.
This can easily be verified by opening a few books with a file manager.

Renate NST said:
Yes, my Library.apk replacement has a receiver for the com.bn.nook.launch.LAST_BOOK intent.
Even though Home.apk uses the Reader.apk to find LB & LRP for the preview,
it only uses LB to tell the Reader.apk what to open.
Reader.apk does its own homework checking LRP for the desired book.
This can easily be verified by opening a few books with a file manager.
Click to expand...
Click to collapse
Ok. I.e. it shouldn't be a problem to run side-by-side readers, right?
They both modify LRP, and Home will be able to pull it via stock reader.
Same idiotic question: do we need to need to change any permissions to let both readers access media databases?

As it stands, if I understand what you want to do,
you'd have to disable the providers in one of the Readers.
You can't have two providers responding to the same intents.
Is there some overwhelming reason why you want to do all this?

Renate NST said:
As it stands, if I understand what you want to do,
you'd have to disable the providers in one of the Readers.
You can't have two providers responding to the same intents.
Click to expand...
Click to collapse
I didn't realize until now, provider responds to URI, so better have one only to avoid problems...
Renate NST said:
Is there some overwhelming reason why you want to do all this?
Click to expand...
Click to collapse
To "not break existing functionality"
I see, it'll be too difficult to have both, too many changes are needed...

Just a bump, old posts don't have signatures.
mergesmali & other stuff can be downloaded from my signature blob.

Related

Declare Function Help

Hi
I'm simply trying to use a dll written in eVC, with a small app written in vVB.
The dll has mostly been wizard generated with an extra function call testing, which returns a 4 as an int.
I've compiled the dll as 'dll_test.dll' and after much messing about i've managed to register the pvbdecl.dll file which seems to be needed. Now i get the following error. 'dll_test.dll was loaded, but the DllRegistryServer entry point was not found'
I hope this is a small common problem? thanks for any help/hints in advance
just a follow up:
i cracked it. i was using the wrong naming convention in my dll. meaning that vb couldn't find the functions in the dll. (also removed some of the c++ stuff from the dll)
now i can use my dll with vb or c (using loadlibrary etc...). next step is to use it in c with just including the h file and linking to the lib file
if anyone is interested then let me know and i'll explain more.

Ubuntu / Linux auto sign tool?

I have been toying with the idea of making a theme. Sounds like fun and the How To's here are really thorough (by the way, I appreciate that, those things must have been quite the labors of love).
As you can tell from the thread title, my OS of choice is obviously Ubuntu. The autosign tool sounds pretty convenient, but I notice it is for Windows. I've searched a bit, but honestly I am getting tired of thumbing through thread after thread looking for the answer and was hoping for a friendly nudge in the right direction.
Anyway, long way around to these questions:
1, when I re-sign an apk, do I use test-keys, do I create my own key, or do is that something JDK will create for me to use?
2, I don't want to create a theme that makes people need to wipe before switching, the template is up to date on the How To thread? Are there templates for JF ADP1.1, and maybe even RC8 as well? Or was there a thread I could read about taking the necessary parts of JF's update and building a template of mine own from that?
3, To actually resign an apk, you have to edit some hex code right? If there truly is NO tool for Linux, I could use some directions on where to find how to manually sign a file. Then hopefully I can find / convert / create a tool in Linux to handle the dirty work for me.
I guess this is what I get for coming in so late into the game.
Also, I am curious if anyone else creates themes in anything other than Windows... any *nix creators out there?
ok, first off to resign an apk or a zip you dont have to do any hex editing at all, in fact, to make a theme you dont have to do any hex editng.
2nd, use my default themes as in the stickies as a template to build your theme, it will not wipe.
3rd to resign in linux, which I haven't done, you will probably need the original signing tool which can be found in jf's recovery.img .zip[ he provided a while ago. I believe it is stickied on android development.
This is the command to resign them
java -jar testsign.jar >inputfile> <outputfile>
Hope this helps
Stericson
Thanks for the super quick reply
Ok, I'll give a search for "testsign.jar", that should get me in the right direction. Once I have that I guess it is time for some experimenting. It shouldn't be hard to develop a shell script that takes every file of xxx type, from a directory and then pass them as values to the testsign.jar app one by one. I had a shell script do something like this to rename all of my photos.
I resign the apk and zip files then.
Thanks Stericson, now I am off to find that testsign.jar, make sure I have the up-to-date default themes, and play around a bit.
EDIT:
SignApk.jar is a tool included with the Android platform source bundle.
testkey.pk8 is the private key that is compatible with the recovery image included in this zip file
testkey.x509.pem is the corresponding certificate/public key
Usage:
java -jar signapk.jar testkey.x509.pem testkey.pk8 <update.zip> <update_signed.zip>
Click to expand...
Click to collapse
This is what I need isn't it? I thought that sounded familiar, I had this downloaded from the whole "let's explore how to root my phone" process.
oh yea, ooops, that is right...sorry I have a custom version of the tool I use. Sowwy.
But that is right.
that cmd line will sign both apks and zips
Stericson

[App][WM6.5] CHome Visual Editor - compatible with all kinds of CPR

[31/08/2009] New release is avaliable, you can download the new verison from: http://cve.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32228
CHome Visual Editor is a visual CPR editor for Windows Mobile 6.5.
** You need install .net 3.5 sp1 in your computer in order to run CVE. **
With CVE, you can edit:
Titanium
LS_AlarmScene
LS_LockScene
LS_PhoneAlertScene
LS_PhoneCallScene
LS_SimplePinScene
StartMenu_GridScene
For this release, you can:
Open CPR file visually and move elements visually.
Modify all properties of the selected element by the property grid on the right side.
Change & Save (auto) the screen resolution.
Change & Save (auto) the scale rate.
Undo/Redo
Setup folder mapping between PPC and your OS.
Import registry file to load the element values (text, image source)
Save the modification.
More functions not listed.
This release only provide two language resource. The embedded language is Chinese, en-US is provided. If your OS language is not en-US, you may need to open configuration.xml and add one line to display en-US:
<language>en-us</language>
or you will get Chinese character.
wow.. looks like very good application
downloading & trying it now!!!!
Looks good indeed! Just downloaded but I can't try it now...
Got some problem here, I can't open any .cpr file to edit???
morningmoon said:
Got some problem here, I can't open any .cpr file to edit???
Click to expand...
Click to collapse
do you mean the application crash when you open *.cpr? can you upload error.log file here under CVE folder? it's all about the exceptions, none private will recorded in this file.
<?xml version="1.0"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<scale>1</scale>
<language>en-us</language>
<resolution>
<Width>240</Width>
<Height>320</Height>
</resolution>
<directory name="\Windows">
<mapping>Windows</mapping>
<mapping>E:\WindowsMobile\i780_21501_Kitchen\SYS\Lockscreen_DPI_96</mapping>
</directory>
<directory name="\Program Files">
<mapping>Program Files</mapping>
</directory>
</configuration>
Click to expand...
Click to collapse
Placed the language line in like above. But still no English.
Is there some thing we need to do more.
ebsbow said:
Placed the language line in like above. But still no English.
Is there some thing we need to do more.
Click to expand...
Click to collapse
This is strange, i copied your configuration and tested it in my comupoter, it works fine.
If you opened CVE and close it normally (the configuration will be saved again while cloing), the configuration should not not looks like your posted. the lanuguage should be the first element of configuration node. It may caused by path you placed CVE or permission issue.
JerryJiang said:
do you mean the application crash when you open *.cpr? can you upload error.log file here under CVE folder? it's all about the exceptions, none private will recorded in this file.
Click to expand...
Click to collapse
No. not crash, just can't get the Open File box to display, so I can't choose any file to open???
morningmoon said:
No. not crash, just can't get the Open File box to display, so I can't choose any file to open???
Click to expand...
Click to collapse
I never wrap the open file dialog. The open file dialog i am using is system provided, do you have any other WPF application in your computer that with a open file feature, if so, can you tested it whether it works fine?
error
Opening any CPR file the application is crashing. I am uploading the error log file. Please look and give a resolution.
Copied the "<language>en-us</language>" just below the configuration tag. But the problem is still the same.
All is in Chinees. is there anything else I need to check?
I have added the last error log.
ajeshm said:
Opening any CPR file the application is crashing. I am uploading the error log file. Please look and give a resolution.
Click to expand...
Click to collapse
The exception is caused by some color string of TextStage element in your CPR file, normally, i define the color in CPR file use the #FFxxxxxx pattern.
it seems that the color definition between WM and WPF have inconsistent rules. So can you look through the CPR file and try to find out whether there is any color definition in <TextStage/> section is not follow the rule?
I will update my code to fix the problem if you can kindlly post the inconsistant rule. Thx.
ebsbow said:
Copied the "<language>en-us</language>" just below the configuration tag. But the problem is still the same.
All is in Chinees. is there anything else I need to check?
I have added the last error log.
Click to expand...
Click to collapse
<?xml version="1.0"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<language>en-US</language>
<enable_effect>true</enable_effect>
<scale>1</scale>
<resolution>
<Width>240</Width>
<Height>320</Height>
</resolution>
<directory name="\Windows">
<mapping>Windows</mapping>
</directory>
<directory name="\Program Files">
<mapping>Program Files</mapping>
</directory>
</configuration>
karim_31 said:
<?xml version="1.0"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<language>en-US</language>
<enable_effect>true</enable_effect>
<scale>1</scale>
<resolution>
<Width>240</Width>
<Height>320</Height>
</resolution>
<directory name="\Windows">
<mapping>Windows</mapping>
</directory>
<directory name="\Program Files">
<mapping>Program Files</mapping>
</directory>
</configuration>
Click to expand...
Click to collapse
Thanks for posting your configuration. I should update my build package to include the language element instead of let the users update the xml by themselves.
ebsbow said:
Copied the "<language>en-us</language>" just below the configuration tag. But the problem is still the same.
All is in Chinees. is there anything else I need to check?
I have added the last error log.
Click to expand...
Click to collapse
Could you please try again with karim_31's configuration?
Unfortunately I don't have one. Still can't use this application
Any suggestion? What do I need to install for the open file to work?
Thanks!
JerryJiang said:
I never wrap the open file dialog. The open file dialog i am using is system provided, do you have any other WPF application in your computer that with a open file feature, if so, can you tested it whether it works fine?
Click to expand...
Click to collapse
The language works now,
Thanks, but the app seems to crash a lot when loading an cpr.
Disabling effects helps, but the apps crashes on other actions as well.
ebsbow said:
The language works now,
Thanks, but the app seems to crash a lot when loading an cpr.
Disabling effects helps, but the apps crashes on other actions as well.
Click to expand...
Click to collapse
Can you upload your error.log so that i can do some analysis to improve the quality of the application.
Sure. Here you go.
ebsbow said:
Sure. Here you go.
Click to expand...
Click to collapse
It's caused by color token:
http://forum.xda-developers.com/showpost.php?p=3952898&postcount=12
i will add more check of the token, by unless i get the inconsistant token, the color may not display correctly.
I cant even launch it
No error log... so where do i need to install all the files? it simply says that the app fails... thats all!
what im a doing wrong?
I set all in C:\ and the stwater added to windows directory

[Tutorial] How to Mod System Apps and User Interface ADDED XML/.9.png lessons

This tutorial will not include info on code, since that information is universal and there are tutorials everywhere already.
- an example of what you can do with this is here:Kronic BlueMod 4.3
- with this knowledge you can create a UI look that NOBODY else has, if you are so inclined, personally i like to share my work but i understand people who like to have unique stuff
this was done to H0!N0! v20f bell debloated/deodex rom.
- this tutorial is meant for ICS mod's but most of the concepts can be applied to other roms and android versions, however small things like file names and locations could change
requirements.
- common sense
- 7-zip installed (winrar can work too but i prefer 7-zip)
- apktool installed (which also requires jdk's etc, there is plenty of information available on how to install this already)
- here is the version of apktool i used and worked with v20f
- apktool Jar file thx to brut.alll
- paint.net (an open source paint program that can deal with transparency and .9.png files.
- working adb or some type of program to push and pull files from phone.
- windows environment (i used win8 64bit.)
Lesson 1 - setting up work environment.
the first thing you want to do when working with a new rom is install it's framework to apktool. This will help apktool know how to work with the files you are going to work with ( in lamens terms ) The command for install framework is "if".
the framework files are found in /system/framework/
- pull framework-res.apk and lge-res.apk, i also install systemui.apk too but i don't think this is needed. (systemui is found in /system/app/)
- make sure your command prompt is in the correct working directory then run the following commands
apktool if framework-res.apk
" " " lge-res.apk
" " " SystemUI.apk
it should install successfully and if you navigate to /users/yourname/framework/
you should see 1.apk 2.apk 127.apk (1 and 2 are the real framework files 127 is systemui and won't be there if you didn't bother installing it)
ok now apktool is setup.
Lesson 2 Repacking system files.
- once you have all the files for your new ****.apk system file, highlight them all, right click, go to 7-zip header, and select add to archive.
- set archive format: zip
- set compression level: store (this is 0 compression which is the best performance)
- set update mode: add and replace files
- once done, packing rename the file to the appropriate name with .apk extension.
- zipalign the file before adding it to a flashable zip or pushing to phone.
- flashable zip is recommended especially when pushing framework-res.apk to phone due to the fact you are replacing the framework app of the system it's better if the system is not running.
- always make a backup flashable with your original files in case you made a mistake.
there is a cool version of apktool that helps new users make flashable zips and zipalign files here:
Auto apktool - thanks to xavierjohn22 and brut.alll for this.
you can replace the files in a flashable zip with 7-zip on the fly by right click open archive, and drag and drop method.
lesson 3 - changing icons.
- this is the easiest part of UI moding if you know where the files are for the icons you want to change, just about anyone can do this, you don't even need to decompile.
- nitro hd uses apk/res/drawable-xhdpi/ resolution folder. so this is the folder you should edit files in, the other drawable folders don't change much.
- open the apk with 7-zip by right clicking it and using 7-zip menu, either extract the whole apk or just the res/drawable-xhdpi/ to view/edit files or you can use your decompiled folder if you are not just editing icons and are planning on rebuilding.
- as a general rule icons on the left side of the status bar are usually controlled by framework-res.apk and icons to the right side are controlled by SystemUI.apk
- for example adb status bar icon appears on left so it's found in framework-res.apk (even though the icon is also in the systemUI.apk that is not what will change the status bar icon.)
- wifi signal and battery etc, are on the right side so look in SystemUI.apk to change them.
- to edit the icons just right click the .png and open with paint.net the square checkerboard means transparent if you've never used paint.net before.
- there are multiple sets of icon styles so be sure you are editing the one your current rom is using (for example signal icons have about 5 styles) if you aren't sure which one you can change them all or do trial and error.
- when repacking the apk after icon changes, it is recommended that you repack your apk like done in lesson 2, although if you drag and drop into the archive and overwrite old files that should work too, although if you do it that way you should atleast zipalign it after.
Lesson 4 - .9.png files
- these files are used for making buttons and stretchable images, it's hard to explain and i'm by no means an expert on them, but when i edit them i only want to change color. I have had a few not work and you will get errors during compile if you mess up the formatting that's already done, this is some type of handle that tells the OS how to stretch the image i think. when i wasn't careful i got errors, when i just use the paint bucket and change the color and then save it, it usually works. if you want to change more there are lots of other guides that have better information. i recommend if you edit these you recompile your apk after every 2 or 3 files just to make sure there are no errors, this will make sure u dont edit a bunch then have trouble identifying which one caused the issue.
- some of the files on our phone that you might want to change the colors of are backgrounds, title bars, status bar pulldown menu buttons, etc. they are typically backgrounds that have different colors, sometimes it's hard to figure out which they are because their dimensions are not like how they show up on the phone, due to stretching. for instance a title bar can look like a vertical line | <--- like that because it is stretched to fill the screen horizontally, and usually it will be slightly faded and that fade will continue across which ever way it is stretched.
- you will also notice that divider bars show up as dots, in a .9.png, on these i just use a pencil and change the color of the CENTER of the dot only. if there is more than one pixel for the same color i just do it to each pixel, usually its 1 i think. (i think paint.net changed something since i updated i can use paint bucket in these and it seems to work)
some files you can look for that are useful to change are.
i will attach some example files that i blacked out like the example i linked at the beginning. if you want to see more just go to that link i posted and download the zip, extract the systemui.apk from it, unpack the apk, and you can see all the files and steal my painfully made homemade indicator that is 200+ file edits.
SystemUI.apk/res/drawable-xhdpi/
- indi_noti_btn_edit_normal.9.png
- indi_noti_btn_pressed.9.png
- indi_noti_progressbar_.normal.9.png
- indi_noti_title_list_divider.9.png
- These are just examples, there are some in framework-res too, usually the names describe what they do, you can try searching your folders for .9.png if you can't find what you are looking for, on different roms the names may be different, and it is possible for them to be in other drawable folders, but usually check xhdpi first as a general rule. you will also find statusbar backgrounds are usually not.9. files so you can put pictures and stuff in them just try to keep dimensions, it will get stretched to fit the status bar on most roms i believe.
Lesson 5 XML editing.
- install notepad++ it's free and its a must have unless you have another text editor designed to handle xml that you prefer.
- open command prompt, you can run in admin mode if you get file write errors or anything that will usually fix problems.
- navigate to folder where apktool is installed unless you have environment variables setup to handle apktool commands from other folders.
- make sure your SystemUI.apk and framework-res.apk are in the same folder, if not copy those files to that folder. for SystemUI.apk, open it with 7-zip and extract the file "classes.dex" to a folder for safe keeping, once that is done, delete it from the archive, as it will cause decompile errors. if you are running a v20c or earlier, you can try skipping this step because baksmali might work for you. if you want to edit classes.dex skip to lesson 6.
- once ready, go back to command prompt, you should still be in your apktool folder. type this.
- apktool d filename.apk
- it should decompile, if u get errors you can try another version of apktool or you can google the errors or post them here and people will try to help.
- it will create a folder named SystemUI and framework-res respectively, or the name of whatever apk you decompile. some other system files have classes.dex that has to be deleted for decompile to work. always back it up though cuz you need to add it back in later. framework-res doesn't have it on most roms i think.
- now you can open the xml's with notepad++ and edit them, save them and recompile. you can also edit images at this time if you wish in the /res/drawable-xhdpi/ folder. IF YOU MAKE MISTAKES IN THIS STEP YOU WILL GET COMPILE ERRORS, so backup original files if you are not confident in what you are doing. i can't list every xml edit here because there are millions of variations you can do, but these xml files control a number of things, from layouts to text color codes etc. variable names, calls to smali code.
- some guidelines are here.
/layout/
- status_bar.xml - edits the system status bar layout, these are fairly universal so if you want to edit this, lets say you want to move the clock to the center, just search the forums for how to center clock status_bar.xml or something, and you will find some example code's you can learn from. this goes for the others too, but here is an example.
/layout/status_bar_tracking.xml
- remove the line that starts with com.android.systemui.xxxxxxx.carrierlabel or something to that effect.
- add this line
- NOTE: for some reason the i can't make the code show up properly for the lines with textAppearance="atstyle/variablename" but that is how it should show up but replace at with the symbol for email at. xda site turns the symbol into a mention for some reason
Code:
<TextView android:textAppearance= [user=262514]@style[/user]/TextAppearance.StatusBar.Title" android:gravity="center" android:layout_gravity="bottom" android:paddingBottom="20.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ADD CUSTOM TEXT HERE" />
make sure that you don't edit anything from the other lines, save the file. This will add text to replace the old carrier label, whatever you want, you can also add other things here like time i think, but i haven't done it before. the textappearance arguement will set the textappearance so if you want to copy the color or style of something else, just read the file that it contains and call the same style as it does, for example you can open your status_bar.xml and copy the textappearance that calls the clock, if u want it to appear like the clock does (color/font etc)
- another important layout file is
/layout/status_bar_expanded.xml
- this file controls the expanded status bar, obviously.
- in notepad++ you can add stuff to the title above the notificatations, by adding it between insert your additions after the line that says
Code:
<RelativeLayout android:id="@id/setting_layout" android:tag="NO_R2L" android:background="@drawable/notification_header_bg"
...etc
- i added the clock here, after the date, so i skipped down one more line, made a new line and added this code:
Code:
<com.android.systemui.statusbar.policy.Clock android:textAppearance= [user=262514]@style[/user]/TextAppearance.StatusBar.Date" android:gravity="left|center" android:id="@id/clock" android:paddingLeft="3.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:layout_toRightOf="@id/date" />
- you also have to make sure the arguements "android:layout_toRightOf="@id/date" is the right id, you can tell which id is which because they are set in each line. you also have to check what used to be beside the date, and fix that too. so look for the text (you can use ctrl f to search) android:layout_toRightOf="@id/date" except not the one you just added, it will probably be the next line for me it's this.
Code:
<View android:id="@id/settings_divider" android:background="@drawable/ic_divider_blue_holo_dark" android:layout_width="0.6700001dip" android:layout_height="16.0dip" android:layout_marginLeft="8.0dip" android:layout_marginTop="15.0dip" android:layout_toRightOf="@id/date" />
- in this line, change "date" to "clock" without changing any other code this will make the divider appear to the right of the clock instead of ontop of it. if you make errors in this phase you can also get compile errors.
changing these layout files have endless possibilities, but this is how you do it, be careful though if you aren't confident make backups and compile often to check for errors, you can google most common errors and find help. or ask.
other things you can do in xml is change values of predefined variables, like colors, file calls, numbers for settings, boolean values, etc. for the purpose of theming focus on styles.xml and colors.xml first if you can't find what you want to change there check the same ones in framework-res/systemui or whatever you are in the corresponding app some apps call framework-res or system-UI and use the colors defined there
- to pick colors you can use Paint.net, go to more colors in color picker, find the color you want, to use it in xml put it in the following format
# aa bbbbbb aa -> transparency code 00 means transparent and ff means solid. you can lookup these codes on google for more specific values.
bbbbb-> is the code you get from Paint.net beside Hex: if it says for blue, 264AFF and i don't want it to be transparent, the color code i would use in xml is the follow "#ff264aff" where i have the letters in lower case and a # at the beginning, only have "" if they are there already, look at the preexisting code to determine, you can also change colors by changing what style something calls (change the @style) call to a style in the styles.xml that you want it to look like.
the integers.xml has some interesting things that are fairly self explanitory, or you can google them if you want to know them all i can't list everything.
- RECOMPILING ONCE YOU HAVE MADE YOUR XML EDITS.
- go back to command prompt in the correct work folder, that your SystemUI and framework-res folders are in.
type:
apktool b SystemUI.. youll see something like this. if you don't get errors.
W: could not find sources
I: checking whether resources has changed...
I: building resources...
then it will take some time to work, depending on cpu speed.
then youll see:
aapt: warning: string 'sp_dcm_gps_popup_body_NORMAL' has no default translation
or a combination of multiple errors like that about default translation, this is normal.
then youll see:
I: Building apk file...
this is good.
at this point type this line again:
apktool b SystemUI
this time it should be fast and no errors.
- YOU NOW HAVE YOUR COMPILED MODIFIED XMLS, to pack them up, navigate to apktoolfolder/SystemUI/dist/SystemUI.apk
open with 7-zip
extract the folders res, assets, and resources.arsc file to a folder called "done" or whatever name you wanna use, then add the original META-INF folder, AndroidManifest.xml file, and the classes.dex file you backed up from the original apk to the same "done" folder.
you should now have the files and folders like this
- assets
- META-INF
- res
- AndroidManifest.xml
- classes.dex
- resources.arsc
the assets, res and resources files, should be the new edited ones, and the classes meta and android files sould be originals, if u edited the smali then the classes.dex file is the edited one from that process.
if there was no classes.dex in the original file obviously you don't need it here.
at this stage, you pack your apk as per instructions in lesson 2.
Note: some SystemUI.apk files have some tricky compression (newer ones) that cause errors in apktool decompile process.
the error i kept getting was Exception in thread "main" java.lang.illegalArguementException: MALFORMED.
it's an instant error (the second you push enter) it happens, which led me to believe it's an unpacking error.
i found another clue when i tried to pull the classes.dex file out of the package with 7-zip and got a program freeze, had to end task it.
i found the solution when i downloaded the latest beta version of winrar and tried to work with the package, i was able to unpack classes.dex -----> progress.
i still got the error after deleting it and trying to decompile though. so i conlcuded that the androidmanifest.xml is also packed with strange compression (that only a very new zip utility will handle)
[fix] use winrar beta version to completely unpack every file, then repack everything except classes.dex, save that file for repacking after recompile. with 0 compression, store and replace (for this step you can go back to 7-zip) since the files are already unpack, you can let 7zip pack up the normal way, then rename the SystemUI.zip to .apk and decompile the file..... errorless =D.
this is a fix to decompile the SystemUI found in the V20F with new framework rom fond in the dev section.
lesson 6 is coming soon, smali editing.
i decided to delay smali editing, i am not good enough at it to teach, you can download jar files called smali and baksmali that you run using command lines in command prompt, such as
"java -jar baksmali.jar classes.dex" to decompile (usually goes into a folder called "out")
"java -jar smali.jar <foldername>" to recompile
omit the " " when input into command prompt.
once classes.dex is recompiled add it back into the apk, if u did your edit correctly you win, if not you will probably sit at lg screen, or the system will load and no change will occur, or some errors.
from what i understand smali code is unique but similar to closer to assembly languages like C or it's variations. i can't find alot of info on it i had done a couple small edits that i tried to copy from someone else but they partially worked because our smali's are so much differant than the people i'm trying to learn from, it was hard for me to learn anything. what little info i find would be better for you to learn from the same people i'm learning from until i have a better grasp which i can't see myself finding the time for anytime soon
i'm so close to having a full bluemod LGMms.apk 3 items i can't figure out how to change, have like 31 changed .. can't find the last 3
if anyone can figure out how to change the title bar backgrounds let me know, i tried like 5 differant ways and nothing worked i think it's set transparent in the smali and i don't know smali well enough to find it
by the way everyone i figured out how to mod lockscreen on LG stock roms, THEY ARE NOT located in framework-res like most roms, it's found in /system/app/lockscreen.apk if u need helping finding an xml for a specific lockscreen let me know
- RECOMPILING ONCE YOU HAVE MADE YOUR XML EDITS.
- go back to command prompt in the correct work folder, that your SystemUI and framework-res folders are in.
type:
apktool b SystemUI.. youll see something like this. if you don't get errors.
W: could not find sources
I: checking whether resources has changed...
I: building resources...
then it will take some time to work, depending on cpu speed.
then youll see:
aapt: warning: string 'sp_dcm_gps_popup_body_NORMAL' has no default translation
or a combination of multiple errors like that about default translation, this is normal.
then youll see:
I: Building apk file...
this is good.
at this point type this line again:
apktool b SystemUI
this time it should be fast and no errors.
Click to expand...
Click to collapse
I get to this part and all it does is create a build folder in the systemui directory.... nothing else.
mattman86 said:
I get to this part and all it does is create a build folder in the systemui directory.... nothing else.
Click to expand...
Click to collapse
interesting, i should have mentioned sometimes you don't have to build twice, but that might not have been the error anyways.
is there a dist folder after first build?
what version of apktool are you using?
i've never seen no dist folder except when the build doesn't complete.
are you sure that there wasn't an error that isn't a warning (the warning "no default translation x 2-4 is normal but if u have actual build errors that stopped the compile process there will be no dist folder, because dist is the LAST step in the process.
- if the xml you modded got compiled correctly, it's possible to impliment it by replacing the xml in the original apk with 7-zip, just check the xml in the build folder and if it's there u can try overwriting the original one in the original apk, we still need to get down to the issue with no dist though.
if you want you can try ziping the systemui directory you are trying to build, and post it here, i'll try compiling for you and see if i get errors, that way i can tell you if the problem is your apktool or an error in a mod you made.
if you do that i'll need your framework-res.apk and lge-res.apk, unless you are working on liquid nitro, i already have the framework for that rom installed if thats the case i just need the zipped systemui folder you are working on and i can see what's what.
mattman86 said:
I get to this part and all it does is create a build folder in the systemui directory.... nothing else.
Click to expand...
Click to collapse
did u figure it out?
Finally, I found this thread. This is very useful bro! Keep it up.

[Q] How to find methods and layouts to hook into without source code

I'd like to develop my first xposed module. So far I have worked through the official tutorial and compiled and read the examples. (I also made android apps before).
I want to make a module for the official Twitter app that removes certain content from the home timeline, such as "Who to follow", "While you were away" and sponsored tweets.
As a first step, I tried to change the color of these elements to red, which I didn't manage to do.
I unzipped and decompiled the app and looked for class and method names that seem helpful (most of them were obfuscated). I tried to hook into some of the methods, mostly nothing happend. I got some MedhotNotFoundExceptions and once the app crashed. I also tried to look for layouts to hook into with no success.
Do you have any hints on how to find the right point for my xposed hook?
Thank you
I also decompiled apps to hook them and it worked. You have to do so, because what's executed is the obfuscated code, and these are the names (classes, methods, variables) you need, even if you own the unobfuscated source code.
If you get MethodNotFoundExceptions, the problem must be somewhere else.
Decompile the apk with apktool. Then look throught the smali code (note that you have to know how the smali structure works, what does a method return, how are different parameters represented). For layouts I personally use DDMS' Hierarchy View. If you still have the method not found error, paste here how you are trying to hook and the original smali code.
Sent from my iPhone 6 Plus using Tapatalk
Check out this awesome tool. Converts smali back to java
https://github.com/google/enjarify
That's what i use

Categories

Resources