Hard coding Issues
Description :
This is Security of Android Application
that Developer forget used sensitive information into code of application
in application development procress.
How to fix :
Not should push sensitive information into Code of Application
or Protected by use Obfuscation code
Obfuscation is an encoding, class name or variable.
Strength
- when Decompile Application will see encoded text instead of plain-text
- Size of Apk file is smaller
Step 1 - Config (build.gradle) "minifyEnabled" == true
android {
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project’s release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile(
‘proguard-android-optimize.txt’),
‘proguard-rules.pro’
}
}
…
}
Step 2 - Create Empty Activity
[ MainActivity.kt ]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setName(User(“antdroid”, “1”))
}
private fun setName(user : User) {
tvName.text = user.name
}
}
[ User Model ]
data class User (
val name : String,
val age : String
)
Step 3 - Rebuild Project or Build apk file.
( There may be Eror let click "Scan" in build tab below )
Step 4 - go to : app/build/outputs/apk/debug/app-debug.apk.
- double click : classes.dex
- model User : to see age , name variable.
- right click : User File to Ganerate Progroud keep rule.
Result will avaliable to use can select you might use to all
-keep class com.example.trymyobfuscationcode.model.User { *; }
Or specific variable
-keep class com.example.trymyobfuscationcode.model.User { java.lang.String name; }
-keep class com.example.trymyobfuscationcode.model.User { java.lang.String age; }
Step 5 - Copy to : proguard-rules.pro.
- Build Apk file.
- New Apk File Path : app/build/outputs/apk/debug/app-release-unsigned.apk.
- Double Click : classes.dex and See : package name is obfuscated.
Tips : Library that has in Github have ProGuard rules
for you can use for work same.
Such as : : GitHub - bumptech/glide: An image loading and caching library for Android focused on smooth scrolling
ความคิดเห็น
แสดงความคิดเห็น