Black Out Guides

 

This first guide is a general tutorial on how to Invert an Android application. If you don't know what "Inverted" mean, ya might not be cut out for this.. 

 

 

To start, this is just a guide on what we need to do to successfully Invert an Android application.  

 

Tools you'll wanna have:

 

1. Note++ Link

2. Apktool 1.5.2 or newer and the newest aapt Link

3. Apkmulti tool script or Rujules22's script from his site with newest apktool.jar and aapt dropped into the others folder - Link - Link

4. Xml Marker (optional) Link

5. Photo Editor like Photoshop or Gimp2 so you can black out or pure alpha background images.

6. FastStone Photo Resizer to batch lighten images when needed - Link

7. DiffMerge by SourceGear program for merging our old code into the new app - Link

 

 

 

 

Once you have those installed and are ready to start, grab an apk like Talk.apk and decompile it. The basic inversion of this app isn't hard at all, but some of the edits B-boy makes on the BlackTalk is so that the edits are simple for Xparent Talk.

 

This guide will be a basics on how to invert in steps and we'll make another one for using Diff Merge to update an app already in our data base..

 

Decompile the app and then compile it right back up to make sure it's clean. If you build it and it errors we need to address those errors (plurals.xml and strings.xml can cause this or a bad .9 patch) By doing this you eliminate that the app itself is botched and cant' be edited. So once it builds clean, open it up and highlight in this order: Res then androidManifest and right click to open with Note+ (However you have to do this just make sure Note++ is opening the files). 

 

1. Once all res and Manifest.xml files are opened hit Control+F to find/search and type android:background in the space and hit "Find all in all opened documents".  This will pull all layout.xml and styles.xml that use that. Next, open in Xml marker or Note++ res/values/colors.xml. There is generally always at least 1 line in there that has the word background in it and 1 that has the word text. For our example we'll use background_color and text_color. Keep those 2 handy and go back to Note++ and scroll the bottom of the page where all the hits are at and which files they're in. We want to redirect ALL backgrounds and most text colors to colors.xml so that themes can work and also in case any of us make colored variations of these apps it is a simple edit in colors.xml rather than all over the place.

 

2. As an example, if you see android:background="#ff7f7f7f" you'll want to hit Control+H and copy that whole item (like what's in green text) into the top box and again in the bottom box but in the bottom box android:background="@color/backround_color" and hit "Replace all in all opened documents" and it will replace all of the hex values with an in-app redirect to colors.xml. Keep scrolling and do that same thing for every background you find. Some backgrounds point to a vague color.xml like "@color/gray55" and since that could easily be a text color, just change it to one we KNOW is a background. @*android:color/white is a famous background just like @*android:color/black is a famous text color.. Make sure you don't miss any...

 

3. You've mastered that part so do it again with android:textColor as the search/find and do the same thing but use the text_color.xml instead. If you have a layout that you know which screen it is affecting and the id's for that TextView line are something like "@id/author, @id/time, @id/content" you can redirect some of those to a different colors.xml that will be a little darker like #ffcccccc instead of #ffffffff. When using DiffMerge those types of redirects are most likely already in place for you.

 

4. All backgrounds and text colors are done! Just to make sure, do a search in Note++ for #, textColorHint, colorCacheHint and @*android. Fix anything that pulls accordingly. Once done, you can save all in Note++ and close that out.

 

5. Now, go back into the actual decompiled apk and open res and hit the search tab in windows and do a search for styles. Some apps use more than just the one in res/values so we have to make sure we edit them all accordingly. Once the search is done and 1-10 styles pull, start at the top and open the first one. This can take a little time on a new app but with DiffMerge it's quick. Since we mainly only Invert "Light" apps, you'll see a lot of @*android:style/Theme.Holo.Light or @*android:style/Theme.Light, etc.. Make sure when you edit that the only one's you change have the @*android:style in front of them.. @style is referencing an in-app style so don't mess with those. So if you see a line (example) parent="@*android:style/Theme.Light"> you will want to change it to.. Then open the Manifest and do a search for "Light" to see if any activities in there are pointing to @*android:style/Theme.Light or Theme.Holo.Light related theme styles.. If so, reverse them accordingly. Theme.Light is Theme.Black, Theme.Holo.Light is Theme.Holo, Theme.Holo.Light.DarkActionBar is Theme.Holo...Save the manifest.. 

 

6. Once you've changed ALL the necessary parents from a Theme.Light reference to a Theme.Black or Theme.Holo reference, either scroll the whole style looking for text colors or backgrounds or do searches for those and edit accordingly redirectling them back to @color/.... Once you're done with styles, save and close it..

 

7. Styles are all done! Now do a windows search in the apk for colors.. Not many apps have more than 1 but some do so make sure you always plan for the worst so we don't miss something. Open colors.xml up and take a few deep breaths cause this is where all our hard work earlier is counting on us to make the right edits. Some items are name very obvious as to what it affects, i.e. backgrounds, text colors, shadows, pressed bg, etc. Go through and make ALL backgrounds #444444(dark-med gray) and all text #00ff00(green). This is for the initial testing. Now, go through and make the edits on the one's that are a little iffy as to what they do and I always make them #ff00ff (pink) or I open all of res with Note++ and do a search for that colors name and see if something pulls letting me know if it's a text color or background. Once you've gotten all colors.xml finished, save and close it..

 

8. This will be a good time to compile/build the apk and run the first test.. Depending on the apk, you can build it as a non system app and sign it or build it as a system app and flash it.. Your call on that for you own testing but for official releases we want to try and offer both install methods..

 

9. Hopefully ya didn't get any errors cause if ya did, and ya compiled the app right after ya decompiled it, it's your edits.. read the log and make needed changes. If it built and installed run tests looking for any black text (that's why the backgrounds are #444444 for now) or any pink backgrounds or text.. If you find issues, like black text or pink backgrounds track them down. Make sure you didn't miss any text colors in layouts and check res/colors or res/drawable for anything since sometimes they do have that stuff. If ya find some pink stuff, start narrowing it down by changing each of those #ff00ff in colors to a different color like #00ffff for cyan or #ffff00 for yellow and compile it and see what changed to what. Then go back in and you can start changing some of those colors to our background color or text color since you'll know what the affect now.. In some instances you'll have 1 item in colors set to #ff00ff (Pink) and in the app you have a text color AND a background using pink. This can be fixed by either doing a search in note++ for those item names in colors to see if you missed something or by opening res/values/public.xml where all the ID's for everyting is. Find the ID for the pink text and then for the pink background and open smali + Manifest in Note++ and do a search for those 2 ID's.. Depending on how many pull (shouldn't be more than 1 or 2) you can see the names of the smali, and they usually tell the location so if the name of the smali sounds like it is obvious, go into the decompiled apk and into smali and navigate to that smali file, open it and go to the line that has that ID from the Note++ search. Look above it a few lines and below it, see if there is a setTextColor, setBackgroundColor, or maybe below it will be SetColor but above it you will see where it might reference that text color or background color. If so, open the public.xml from the app again and if the smali you have opened is affecting the text color, change just that ID # like 7fe0010 to a different public ID for another text color that you know will be white. Do the same thing for the background. This part can get tricky an luckily not a ton of apps will have that issue.

 

10. Build it agan and install it again. Run the tests and do the same thing for any text color issues or colored backgrounds. Any white backgrounds will more than likely be a drawable image in the res folder so as long as most backgrounds are dark-med gray and all text is green, you're ready for drawable images. Not gonna get into .9's cause I'll assume you already know how to outling the existing .9.png image and fill it with a solid color. So go throught all the drawable folders in res and change all backgrounds or images that appear to be backgrounds to black and make sure any icon image like for settings or compose text are light now if they were dark in the stock app. 

 

11. Finally, open colors.xml again and hit control+H and put 444444 in the top box and 000000 in the bottom box.. replace all.. Then hit Control+H again and put 00ff00 in the top box and ffffff in the bottom one... Build and thoroughly test again.. Hopefully you did some deep testing when our backgrounds were dark-med gray so you could still see any black text at that time.. If you've changed every drawable image in those folders and have ran tests throughout layouts, drawable,colors, etc and still have a white background or black text, open smali in Note++ and do a search for BackgroundColor if it's a background issue. See how many smali files pull. Read through the list of the files at the bottom of Note++ and see if any seem obvious. If so, via the decompiled apk, navigate to that smali and open it in Note++ and do a search for -0x1 just in it. If anything pulls looking similar to this const/4 v2, -0x1 then that could be the white background. Look above and below again but also if the v2(variable) is also a v2 on that SetBackground line, then there's even more of a chance that's it.. You can change it to const v2, -0x100 for black. Save that smali but don't close out of Note++ and build the app and install it. If it quickly errors on classes, open Note++ again and make that line const/high16 v2, -0x100 and save and build again..

 

12. These aren't fool proof methods and learning takes time but it helps to guide you as to how to invert an app. Something I do in most apps is a smali search for the beginning of the framework-res public ID's for Theme.Styles and colors.. System styles start with 0x103 so if anything pulls and has 5 more characters then go check the public.xml in framework-res to see if it's something you might wanna change. Then colors are 0x0106***** so I do a search for 0x106 and see what pulls and do the same as with styles id's... Little tricks we've learned along the way... 

 

13. Hopefully this guide is helpful and I'll edit it more or someone else will...