Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Getting started & Tutorials
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4android Getting started & Tutorials Android development starts here. Please do not post questions in this sub-forum.

Android Code Obfuscation

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-06-2012, 04:55 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default Android Code Obfuscation

Basic4android v1.8 includes a new code obfuscation feature.
During compilation Basic4android generates Java code which is then compiled with the Java compiler and converted to Dalvik (Android byte code format).
There are tools that allow decompilation of Dalvik byte code into Java code.

The purpose of obfuscation is to make the decompiled code less readable, harder to understand and make it more difficult to extract strings like developer account keys.

It is important to understand how the obfuscator works.
The obfuscator does two things:

Strings obfuscation
Any string written in Process_Globals sub (and only in this sub) will be obfuscated, making it much harder to extract important keys. The strings are defuscated at runtime.
Note that several keys are used during obfuscation including the package name, version name and version code. Modifying these values with the manifest editor will break the defuscation process.

Variables renaming
The names of global variables and subs are converted to meaningless strings. Local variables are not affected as their names are lost anyway during the compilation.
The following identifiers are not renamed:
- Identifiers that contain an underscore (requires for the events handlers).
- Subs that appear in CallSub statements. Only if the sub name appears as a static string then the identifier will be kept as is.
- Designer views names.

Tip: If, for some reason, you need to prevent the obfuscator to rename an identifier you should add an underscore in the identifier name.

A file named ObfuscatorMap.txt will be created under the Objects folder. This file maps the original identifiers names to the obfuscated names. This mapping can be helpful to analyze crash reports.

Activating the obfuscator
Basic4android version 1.8 makes it simpler to choose the compilation mode.

There are three modes:
- Debug - in this mode the IDE debugger will connect to the running application (same as the previous Attach debugger option).
- Release - compiles the application without any debugging information.
- Release (obfuscation) - compiles the application and activates the obfuscator.


Pitfalls
Using CallSub with a non-static string.
The following code demonstrates this issue:
Code:
Sub Activity_Resume
    
CallSub("Main""Test1"'Works because it is a static string (Test sub will not be renamed)
    Dim subName As String
    subName = 
"Test2"
    
CallSub("Main", subName) 'Skipped at runtime because Test2 sub is renamed
    subName = "Test_3"
    
CallSub("Main", subName) 'Works because Test_3 includes an underscore and it will not be renamed.
End Sub
Sub Test1
    
Log("a")
End Sub
Sub Test2
    
Log("b")
End Sub
Sub Test_3
    
Log("c")
End Sub
- LicenseChecker.SetVariableAndValue
This method references a variable using a string. This method will fail if the variable name doesn't include an underscore.

Known issues (version 1.80)
The string obfuscation fails with empty strings. This is only relevant to empty strings in Process_Globals as other strings are not obfuscated.
This will be fixed in the next update. Note that by default strings are set to the empty string, therefore you can just remove the empty string assignment.
Reply With Quote
  #2 (permalink)  
Old 01-06-2012, 05:04 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Italy
Posts: 599
Awards Showcase
Beta Tester 
Total Awards: 1
Default

wow !!

you're a genius!
__________________
rgds,
moster67
Reply With Quote
  #3 (permalink)  
Old 01-06-2012, 06:55 PM
Knows the basics
 
Join Date: Aug 2011
Posts: 86
Default

We cant wait more until release!!

Reply With Quote
  #4 (permalink)  
Old 01-06-2012, 07:00 PM
nad nad is offline
Knows the basics
 
Join Date: Jun 2011
Posts: 81
Default

Awesome Erel, really useful.
Bless the day i got B4A
Reply With Quote
  #5 (permalink)  
Old 01-06-2012, 07:21 PM
worm's Avatar
Newbie
 
Join Date: Sep 2011
Location: Lugano, Switzerland
Posts: 4
Default

Thank you for your hard work!
__________________
Basic4Android addicted
http://www.mushiware.ch
Reply With Quote
  #6 (permalink)  
Old 01-06-2012, 09:07 PM
clx clx is offline
Junior Member
 
Join Date: Oct 2011
Posts: 29
Default

Amazing!!

Thanks!
Reply With Quote
  #7 (permalink)  
Old 01-06-2012, 09:28 PM
Fox Fox is offline
Senior Member
 
Join Date: Mar 2011
Posts: 138
Default

Amazing

looking forward to this version

Thanks erel for this nice feature
Reply With Quote
  #8 (permalink)  
Old 01-07-2012, 03:05 AM
Basic4ppc Veteran
 
Join Date: Aug 2011
Posts: 348
Default

Would using this have any impact on app performance?

Sent from my DROIDX
__________________
B4A Chatroom
Reply With Quote
  #9 (permalink)  
Old 01-07-2012, 03:14 AM
Basic4ppc Expert
 
Join Date: Apr 2009
Posts: 503
Default

Simply Marvellous
Reply With Quote
  #10 (permalink)  
Old 01-07-2012, 07:08 AM
Senior Member
 
Join Date: Jul 2011
Posts: 118
Default

Great!!!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Obfuscation in source file WZSun Basic4android Updates and Questions 2 01-10-2012 09:08 PM
Java code does not work on Android device Amalkotey Libraries developers questions 3 06-06-2011 09:12 AM
Android Setting with Code or Script jnbarban Basic4android Updates and Questions 3 05-20-2011 07:42 AM
b4ppc code vs b4a code jschuchert Basic4android Updates and Questions 6 04-23-2011 06:32 PM
Obfuscation during compilation WZSun Bugs & wishlist 4 12-19-2010 02:19 PM


All times are GMT. The time now is 10:04 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0