1 00:00:00,570 --> 00:00:01,440 ‫Instructor: Hi. 2 00:00:01,440 --> 00:00:04,950 ‫Within this lecture we are going to see the usage 3 00:00:04,950 --> 00:00:07,920 ‫of a tool called ProGuard. 4 00:00:07,920 --> 00:00:12,920 ‫So this is a tool that enables developers to obfuscate 5 00:00:13,080 --> 00:00:17,190 ‫or encrypt their code so that when a hacker 6 00:00:17,190 --> 00:00:20,520 ‫or a security researcher decompiles it, 7 00:00:20,520 --> 00:00:22,800 ‫they won't see the source code directly 8 00:00:22,800 --> 00:00:26,760 ‫but they can see it in a concealed way. 9 00:00:26,760 --> 00:00:29,700 ‫So let me show you what I mean. 10 00:00:29,700 --> 00:00:32,790 ‫Open your My Reverse app one more time 11 00:00:32,790 --> 00:00:35,460 ‫and go under this Gradle scripts, 12 00:00:35,460 --> 00:00:40,380 ‫we have looked into this build.gradle app file before. 13 00:00:40,380 --> 00:00:44,610 ‫So we have this general settings like compiled version, 14 00:00:44,610 --> 00:00:46,650 ‫minimum SDK version, 15 00:00:46,650 --> 00:00:50,700 ‫but also we have this minify enabled 16 00:00:50,700 --> 00:00:54,480 ‫thing in the middle of the build.gradle file. 17 00:00:54,480 --> 00:00:56,940 ‫Right, we haven't seen it yet. 18 00:00:56,940 --> 00:01:01,940 ‫So this minify enabled actually is for ProGuard usage. 19 00:01:02,190 --> 00:01:04,770 ‫ProGuard doesn't only encrypt the code 20 00:01:04,770 --> 00:01:06,690 ‫but also shrinks it 21 00:01:06,690 --> 00:01:09,690 ‫in a way that it actually makes 22 00:01:09,690 --> 00:01:11,460 ‫the APK 23 00:01:11,460 --> 00:01:13,980 ‫in an efficient, smaller way. 24 00:01:13,980 --> 00:01:17,400 ‫Like, it removes the unnecessary code 25 00:01:17,400 --> 00:01:21,240 ‫and your final product, your final APK, 26 00:01:21,240 --> 00:01:24,270 ‫would be in a smaller size. 27 00:01:24,270 --> 00:01:27,780 ‫So I see many developers forgetting about this 28 00:01:27,780 --> 00:01:29,940 ‫or ignoring this at all, 29 00:01:29,940 --> 00:01:31,980 ‫but actually it's a very good idea 30 00:01:31,980 --> 00:01:36,720 ‫to use this pro tool in order to protect your code 31 00:01:36,720 --> 00:01:41,040 ‫and also in order to make your APKs in a more efficient way. 32 00:01:41,040 --> 00:01:44,940 ‫So in big projects, in big apps, most of the time 33 00:01:44,940 --> 00:01:49,515 ‫you will see this minify enabled as true or 34 00:01:49,515 --> 00:01:53,070 ‫they would be using some other tools as well. 35 00:01:53,070 --> 00:01:55,830 ‫But ProGuard is the choice of Android Studio 36 00:01:55,830 --> 00:01:58,590 ‫and it's doing a good job for this. 37 00:01:58,590 --> 00:02:00,870 ‫So if you change this to true, 38 00:02:00,870 --> 00:02:03,870 ‫then it will be enabled in your code. 39 00:02:03,870 --> 00:02:07,080 ‫So once you create a new APK, 40 00:02:07,080 --> 00:02:09,720 ‫obfuscation will be enabled, 41 00:02:09,720 --> 00:02:14,720 ‫and your code will not be decrypted as easy as it was. 42 00:02:15,420 --> 00:02:17,850 ‫So we are going to experience that as well. 43 00:02:17,850 --> 00:02:21,390 ‫So make sure you make this true, okay? 44 00:02:21,390 --> 00:02:24,450 ‫And then you have to sync everything 45 00:02:24,450 --> 00:02:29,070 ‫so that your project will be synchronized across your app. 46 00:02:29,070 --> 00:02:32,760 ‫And also, right now, we are going to see how to create 47 00:02:32,760 --> 00:02:37,760 ‫signed APKs with inside of Android studio. 48 00:02:37,920 --> 00:02:39,840 ‫So before we do that 49 00:02:39,840 --> 00:02:44,580 ‫I'm going to make this available for debug as well. 50 00:02:44,580 --> 00:02:47,490 ‫So I'm going to copy this release 51 00:02:47,490 --> 00:02:49,860 ‫with the curly braces as well. 52 00:02:49,860 --> 00:02:50,693 ‫Okay? 53 00:02:50,693 --> 00:02:54,120 ‫And paste it just below the release section 54 00:02:54,120 --> 00:02:56,250 ‫and name it debug. 55 00:02:56,250 --> 00:02:58,703 ‫So it will create two APKs, 56 00:02:58,703 --> 00:03:01,350 ‫one for release and one for debug. 57 00:03:01,350 --> 00:03:06,180 ‫Generally, we use this release thing for Google Play 58 00:03:06,180 --> 00:03:09,810 ‫and debug thing for debugging the application. 59 00:03:09,810 --> 00:03:14,810 ‫And I want the ProGuard to be enabled for both of them. 60 00:03:15,030 --> 00:03:19,323 ‫So I want to do this as release and as debug as well. 61 00:03:20,220 --> 00:03:22,230 ‫So make sure you do it. 62 00:03:22,230 --> 00:03:23,760 ‫And then after you sync, 63 00:03:23,760 --> 00:03:26,460 ‫you can come over here to build section, 64 00:03:26,460 --> 00:03:30,960 ‫and remember we build APKs like this before, 65 00:03:30,960 --> 00:03:34,500 ‫but now, we are gonna use this option to generate 66 00:03:34,500 --> 00:03:38,310 ‫signed APKs with inside of and Android studio, 67 00:03:38,310 --> 00:03:43,310 ‫just to know, just to understand how it's done as well. 68 00:03:43,770 --> 00:03:47,850 ‫And you can build the APKs, and manually sign it, 69 00:03:47,850 --> 00:03:50,310 ‫and it will produce the same result. 70 00:03:50,310 --> 00:03:52,477 ‫But this is a good skill to know. 71 00:03:52,477 --> 00:03:55,649 ‫This is a good idea to implement, 72 00:03:55,649 --> 00:03:58,320 ‫and we are going to see how it's done. 73 00:03:58,320 --> 00:04:02,880 ‫Remember we should check the APK option and hit next. 74 00:04:02,880 --> 00:04:06,660 ‫And after that it will ask for a key store path. 75 00:04:06,660 --> 00:04:10,620 ‫So we don't have the key store file, we deleted it. 76 00:04:10,620 --> 00:04:15,620 ‫Remember it was our own desktop, and then we deleted it, 77 00:04:15,750 --> 00:04:19,740 ‫and then now we're going to create it from scratch. 78 00:04:19,740 --> 00:04:23,640 ‫And we can do it by the same command with terminal. 79 00:04:23,640 --> 00:04:26,850 ‫Okay, I'm going to delete everything from here as well, 80 00:04:26,850 --> 00:04:28,080 ‫by the way. 81 00:04:28,080 --> 00:04:32,400 ‫And we can do it same command with inside of terminal. 82 00:04:32,400 --> 00:04:35,760 ‫But right now I'm just going to do it inside of 83 00:04:35,760 --> 00:04:39,600 ‫Android Studio so that you can understand how it's done. 84 00:04:39,600 --> 00:04:41,610 ‫So I'm going to say create new, 85 00:04:41,610 --> 00:04:44,910 ‫and I'm going to choose a path for my key. 86 00:04:44,910 --> 00:04:48,570 ‫So the path that I'm going to choose is the desktop itself 87 00:04:48,570 --> 00:04:50,100 ‫one more time. 88 00:04:50,100 --> 00:04:52,288 ‫And you can choose your own path, 89 00:04:52,288 --> 00:04:57,288 ‫but you have to give it a name like Key Star, okay? 90 00:04:57,390 --> 00:04:59,700 ‫So that's all you need to do. 91 00:04:59,700 --> 00:05:03,750 ‫And after that it will add, it will ask a password, 92 00:05:03,750 --> 00:05:06,510 ‫and it will edit once you type it, 93 00:05:06,510 --> 00:05:10,320 ‫just make sure you type the same password, okay? 94 00:05:10,320 --> 00:05:13,530 ‫And over here in the key section, you're more than welcome 95 00:05:13,530 --> 00:05:17,460 ‫to use the same password as this one, right, again. 96 00:05:17,460 --> 00:05:21,060 ‫Okay, make sure you don't forget it. 97 00:05:21,060 --> 00:05:24,660 ‫And in here, you choose a validity. 98 00:05:24,660 --> 00:05:27,750 ‫So it's valid for 25 years. 99 00:05:27,750 --> 00:05:28,583 ‫Okay? 100 00:05:28,583 --> 00:05:33,583 ‫And after 25 years, you can just create a new key store 101 00:05:33,660 --> 00:05:36,197 ‫and sign it with the new one. 102 00:05:36,197 --> 00:05:41,197 ‫So you can actually give the names and the organization 103 00:05:41,520 --> 00:05:45,030 ‫and the country and everything over here. 104 00:05:45,030 --> 00:05:49,320 ‫But in this Android Studio case, at least one of the 105 00:05:49,320 --> 00:05:53,468 ‫certificate details should be filled in. 106 00:05:53,468 --> 00:05:54,810 ‫Okay? 107 00:05:54,810 --> 00:05:58,740 ‫So I'm going to give it name like Atil Sam. 108 00:05:58,740 --> 00:06:02,490 ‫This should be sufficient enough for us to continue. 109 00:06:02,490 --> 00:06:06,270 ‫And if I say okay, as you can see, all the detail is 110 00:06:06,270 --> 00:06:09,780 ‫filled in right now and I can say finish. 111 00:06:09,780 --> 00:06:11,130 ‫And as you can see, 112 00:06:11,130 --> 00:06:14,760 ‫there is a debug or release selection. 113 00:06:14,760 --> 00:06:17,100 ‫Make sure you hit the shift on your keyboard 114 00:06:17,100 --> 00:06:18,660 ‫and select both of those. 115 00:06:18,660 --> 00:06:21,210 ‫And again, in the signature versions 116 00:06:21,210 --> 00:06:25,080 ‫make sure you select the V1 and V2. 117 00:06:25,080 --> 00:06:29,310 ‫And this is for jar signature and V2 is full APK signature. 118 00:06:29,310 --> 00:06:32,970 ‫Just make sure you choose both of them and say finish. 119 00:06:32,970 --> 00:06:37,970 ‫So this will generate the APK and sign it as well, 120 00:06:38,070 --> 00:06:41,220 ‫so that you won't be dealing with the signing process 121 00:06:41,220 --> 00:06:42,270 ‫after all. 122 00:06:42,270 --> 00:06:46,830 ‫And this is how developers actually create their APKs 123 00:06:46,830 --> 00:06:50,340 ‫and upload those APKs to the Google Play. 124 00:06:50,340 --> 00:06:53,460 ‫So now you know how to do this as well. 125 00:06:53,460 --> 00:06:55,050 ‫So after you are done 126 00:06:55,050 --> 00:06:59,100 ‫it will give you the location of the generated APK, 127 00:06:59,100 --> 00:07:03,840 ‫which will be most probably inside of your project folder 128 00:07:03,840 --> 00:07:05,280 ‫one more time. 129 00:07:05,280 --> 00:07:09,960 ‫So after this is done, just click on the locate button, 130 00:07:09,960 --> 00:07:14,960 ‫or you can actually open the project file as well. 131 00:07:15,420 --> 00:07:19,050 ‫And I believe we don't have the 132 00:07:19,050 --> 00:07:20,640 ‫locate button 133 00:07:20,640 --> 00:07:22,592 ‫in this section. 134 00:07:22,592 --> 00:07:24,000 ‫I dunno why not. 135 00:07:24,000 --> 00:07:27,840 ‫But we can reach it from the project folder. 136 00:07:27,840 --> 00:07:32,460 ‫So I'm gonna open my project folder, okay, from here. 137 00:07:32,460 --> 00:07:35,820 ‫So we used to go into the app, 138 00:07:35,820 --> 00:07:38,850 ‫and we are gonna do the same thing again, okay? 139 00:07:38,850 --> 00:07:41,430 ‫There is a build right now. 140 00:07:41,430 --> 00:07:44,340 ‫However, this is not the build that we are looking for. 141 00:07:44,340 --> 00:07:48,270 ‫We are looking for the build inside of the app itself. 142 00:07:48,270 --> 00:07:52,380 ‫So under the build you will see the output APK debug. 143 00:07:52,380 --> 00:07:57,060 ‫And this was the debug file that we have created before. 144 00:07:57,060 --> 00:08:01,200 ‫Right now we are not interested with this debug file 145 00:08:01,200 --> 00:08:03,870 ‫but rather we have this release 146 00:08:03,870 --> 00:08:08,670 ‫and debug folders separately under the app folder. 147 00:08:08,670 --> 00:08:09,503 ‫Okay? 148 00:08:09,503 --> 00:08:11,880 ‫So right now I'm inside of the app, 149 00:08:11,880 --> 00:08:16,800 ‫and I can reach the app debug APK that I reached before, 150 00:08:16,800 --> 00:08:18,960 ‫the same way that I reached before. 151 00:08:18,960 --> 00:08:20,790 ‫But if I go to release, 152 00:08:20,790 --> 00:08:25,560 ‫I can see the app release APK, and I can use this APK 153 00:08:25,560 --> 00:08:29,277 ‫in order to decompile it with 154 00:08:29,277 --> 00:08:30,600 ‫JDX and see 155 00:08:30,600 --> 00:08:31,433 ‫how 156 00:08:31,433 --> 00:08:32,266 ‫it's 157 00:08:32,266 --> 00:08:33,099 ‫done. 158 00:08:33,099 --> 00:08:36,930 ‫Here we go, now we see it's smaller in size than before 159 00:08:36,930 --> 00:08:39,600 ‫because we used obfuscation. 160 00:08:39,600 --> 00:08:42,480 ‫And I'm going to copy this on my desktop. 161 00:08:42,480 --> 00:08:43,380 ‫Okay? 162 00:08:43,380 --> 00:08:48,380 ‫And I'm going to use JDX to see what we get in return. 163 00:08:48,390 --> 00:08:50,460 ‫So over here I'm going to stop, 164 00:08:50,460 --> 00:08:53,040 ‫and within the next lecture we are going to decompile it 165 00:08:53,040 --> 00:08:54,693 ‫and see how it looks like.