1 00:00:00,270 --> 00:00:03,510 ‫-: Hi. Within this lecture, we are going to see how 2 00:00:03,510 --> 00:00:08,100 ‫we can create an APK, a final product out of this app 3 00:00:08,100 --> 00:00:10,740 ‫that we have developed in the previous lecture. 4 00:00:10,740 --> 00:00:14,370 ‫And now we are going to see how we can use that APK 5 00:00:14,370 --> 00:00:18,720 ‫in our emulator or in our Android devices. 6 00:00:18,720 --> 00:00:21,870 ‫So over here right now, if I run this app 7 00:00:21,870 --> 00:00:24,330 ‫it'll run on my emulator, 8 00:00:24,330 --> 00:00:26,820 ‫but most of the time 9 00:00:26,820 --> 00:00:29,220 ‫when you commit a reverse engineering 10 00:00:29,220 --> 00:00:30,630 ‫when you try to do 11 00:00:30,630 --> 00:00:33,930 ‫a reverse engineering for some kind of an app, 12 00:00:33,930 --> 00:00:36,810 ‫you won't get the source codes, okay? 13 00:00:36,810 --> 00:00:39,057 ‫You will only get apk, 14 00:00:39,057 --> 00:00:43,980 ‫and you will try to actually de-compile it 15 00:00:43,980 --> 00:00:48,750 ‫and get the source codes or dalvik bytecodes out of it. 16 00:00:48,750 --> 00:00:52,260 ‫So you have to know, how to create an APK 17 00:00:52,260 --> 00:00:55,170 ‫and how to work with APKs in general. 18 00:00:55,170 --> 00:00:58,080 ‫So if you come over here to your build menu, 19 00:00:58,080 --> 00:01:03,080 ‫you will see a menu like this, build bundles and APKs. 20 00:01:03,570 --> 00:01:08,520 ‫So also you will see a generate signed bundle APK 21 00:01:08,520 --> 00:01:10,710 ‫option as well. 22 00:01:10,710 --> 00:01:12,690 ‫We're going to see both of those 23 00:01:12,690 --> 00:01:15,570 ‫and we're going to work with both of those. 24 00:01:15,570 --> 00:01:20,100 ‫And the second one is to create a signed APK, 25 00:01:20,100 --> 00:01:24,480 ‫a signed apk means that you sign it as a developer, 26 00:01:24,480 --> 00:01:26,910 ‫it identifies you as a developer 27 00:01:26,910 --> 00:01:30,180 ‫of this Android application. 28 00:01:30,180 --> 00:01:33,210 ‫So for example, if you want to put your app 29 00:01:33,210 --> 00:01:37,980 ‫on the app store, I mean Google Play in Android, of course, 30 00:01:37,980 --> 00:01:41,400 ‫you have to sign it, so that Google Play 31 00:01:41,400 --> 00:01:44,520 ‫will know that you are the developer. 32 00:01:44,520 --> 00:01:46,440 ‫However, in this case, 33 00:01:46,440 --> 00:01:50,100 ‫when you try and when you do some tests, 34 00:01:50,100 --> 00:01:52,380 ‫it's perfectly okay to come over here 35 00:01:52,380 --> 00:01:57,380 ‫to build bundle or APK's and choose build APK's. 36 00:01:57,450 --> 00:02:00,420 ‫So this will create the apk in the same way. 37 00:02:00,420 --> 00:02:03,270 ‫You will get the latest product, a final product 38 00:02:03,270 --> 00:02:06,813 ‫of this development, but it won't be signed. 39 00:02:07,707 --> 00:02:11,580 ‫And in fact, we will see how to sign it manually 40 00:02:11,580 --> 00:02:15,783 ‫like we did in the backdoor section as well. 41 00:02:16,650 --> 00:02:19,410 ‫Just let me show you this as an example. 42 00:02:19,410 --> 00:02:22,920 ‫If I come over here to generate signed APK, 43 00:02:22,920 --> 00:02:24,390 ‫it'll ask me for, 44 00:02:24,390 --> 00:02:28,950 ‫if I want to create a bundle or APK, I'm gonna go for APK. 45 00:02:28,950 --> 00:02:33,330 ‫And once I do that, it'll ask me for a key store path. 46 00:02:33,330 --> 00:02:38,040 ‫So remember, a key store that we have created using terminal 47 00:02:38,040 --> 00:02:39,780 ‫in the backdoor section. 48 00:02:39,780 --> 00:02:41,430 ‫So this is the same thing. 49 00:02:41,430 --> 00:02:44,940 ‫It asks for a key store, and if you don't have 50 00:02:44,940 --> 00:02:49,020 ‫a pre-created key store, you can create a new one, 51 00:02:49,020 --> 00:02:51,180 ‫from here, from this menu. 52 00:02:51,180 --> 00:02:55,140 ‫And then you can use it to sign your APK 53 00:02:55,140 --> 00:02:58,620 ‫so that you can actually use it in any device 54 00:02:58,620 --> 00:03:02,010 ‫or in Google Play as well. 55 00:03:02,010 --> 00:03:05,760 ‫So if you come over here, if you hit, create new, 56 00:03:05,760 --> 00:03:08,220 ‫you will see that it will ask for a path 57 00:03:08,220 --> 00:03:11,580 ‫and it'll ask for your name and organization, 58 00:03:11,580 --> 00:03:14,850 ‫city and some stuff like that. 59 00:03:14,850 --> 00:03:16,650 ‫And of course, we've done this before. 60 00:03:16,650 --> 00:03:18,780 ‫We are gonna do it again, later on. 61 00:03:18,780 --> 00:03:21,600 ‫But again, for tests and other things, 62 00:03:21,600 --> 00:03:24,570 ‫you can actually use this Build APKs 63 00:03:24,570 --> 00:03:28,020 ‫and once you click on it, it'll just generate the APK. 64 00:03:28,020 --> 00:03:32,280 ‫Create the apk, and put that in a folder like this. 65 00:03:32,280 --> 00:03:33,840 ‫So it's very simple. 66 00:03:33,840 --> 00:03:36,000 ‫Now, if you click on Locate, 67 00:03:36,000 --> 00:03:39,060 ‫over here or if you open your, 68 00:03:39,060 --> 00:03:40,800 ‫your own project file, 69 00:03:40,800 --> 00:03:43,920 ‫like, this is inside of my project right now, 70 00:03:43,920 --> 00:03:48,920 ‫my reverse app, as you can see, my reverse app, and then app 71 00:03:50,100 --> 00:03:54,540 ‫you can actually find it from here and then build 72 00:03:54,540 --> 00:03:58,620 ‫and then outputs, and then APK, and then debug. 73 00:03:58,620 --> 00:04:02,040 ‫And then here you go, app debug APK. 74 00:04:02,040 --> 00:04:05,640 ‫So this is the apk generated for us. 75 00:04:05,640 --> 00:04:07,410 ‫And it's very simple as you can see. 76 00:04:07,410 --> 00:04:09,000 ‫You can just click on the menu 77 00:04:09,000 --> 00:04:11,670 ‫and it'll generate an apk for you. 78 00:04:11,670 --> 00:04:15,423 ‫Now we can use this apk to reverse engineer. 79 00:04:16,380 --> 00:04:19,380 ‫Now, if you have skipped the previous lectures 80 00:04:19,380 --> 00:04:21,030 ‫for some reason, 81 00:04:21,030 --> 00:04:25,350 ‫I'm going to explain how to use apk in an emulator 82 00:04:25,350 --> 00:04:27,870 ‫or in any android device, one more time. 83 00:04:27,870 --> 00:04:29,850 ‫So if you already watched this, 84 00:04:29,850 --> 00:04:33,450 ‫if you already can start APKs, 85 00:04:33,450 --> 00:04:37,200 ‫if you already can use APKs in your emulator, 86 00:04:37,200 --> 00:04:40,590 ‫you may as well as skip this lecture 87 00:04:40,590 --> 00:04:43,080 ‫and continue with the next one. 88 00:04:43,080 --> 00:04:46,500 ‫So right now, I'm going to stop my emulator. 89 00:04:46,500 --> 00:04:47,940 ‫Okay, here you go. 90 00:04:47,940 --> 00:04:50,880 ‫I'm actually going to stop every app 91 00:04:50,880 --> 00:04:53,760 ‫that I have on my emulator running right now, 92 00:04:53,760 --> 00:04:56,250 ‫so that we will have a clear system 93 00:04:56,250 --> 00:04:59,130 ‫and we will start from scratch. 94 00:04:59,130 --> 00:05:03,120 ‫Now, if I come over here to my emulator, I suppose 95 00:05:03,120 --> 00:05:07,500 ‫that I want to use my app debug apk in this emulator 96 00:05:07,500 --> 00:05:10,110 ‫and I don't know how it's done. 97 00:05:10,110 --> 00:05:15,110 ‫So first thing to do is to actually uninstall my reverse app 98 00:05:15,270 --> 00:05:18,360 ‫in this case, because we already have it installed. 99 00:05:18,360 --> 00:05:20,940 ‫So let me uninstall this first of all. 100 00:05:20,940 --> 00:05:21,900 ‫Okay, here we go. 101 00:05:21,900 --> 00:05:24,390 ‫We got rid of the my reverse app. 102 00:05:24,390 --> 00:05:27,780 ‫So next thing to do is to make sure that 103 00:05:27,780 --> 00:05:32,780 ‫we can actually install APKs from other sources 104 00:05:33,270 --> 00:05:37,590 ‫rather than Google play in this phone, in this emulator. 105 00:05:37,590 --> 00:05:39,570 ‫It doesn't matter if it's an emulator 106 00:05:39,570 --> 00:05:42,390 ‫or if it's a real Android device, 107 00:05:42,390 --> 00:05:44,820 ‫you can actually change the setting 108 00:05:44,820 --> 00:05:48,210 ‫whenever or wherever you want. Okay? 109 00:05:48,210 --> 00:05:51,090 ‫So this will enable us to download 110 00:05:51,090 --> 00:05:55,650 ‫and use APKs other than Google Play. 111 00:05:55,650 --> 00:05:59,790 ‫So if you come over here to settings, and you, 112 00:05:59,790 --> 00:06:02,310 ‫you can actually search for this setting 113 00:06:02,310 --> 00:06:05,310 ‫because there are so many versions of Android 114 00:06:05,310 --> 00:06:09,090 ‫and so many versions of other phones and devices. 115 00:06:09,090 --> 00:06:13,530 ‫So it's a little bit hard to find it through the menus 116 00:06:13,530 --> 00:06:18,530 ‫that if you search for install, okay, unknown, 117 00:06:18,660 --> 00:06:22,350 ‫you will actually see this install unknown apps. 118 00:06:22,350 --> 00:06:24,300 ‫So make sure you click on that 119 00:06:24,300 --> 00:06:28,650 ‫and find install unknown apps one more time, like this. 120 00:06:28,650 --> 00:06:33,180 ‫And allow Chrome or other applications over here 121 00:06:33,180 --> 00:06:36,510 ‫to download APKs and install it. 122 00:06:36,510 --> 00:06:39,360 ‫So in our case, I'm going to allow Chrome 123 00:06:39,360 --> 00:06:43,470 ‫so that I can actually download whatever I want 124 00:06:43,470 --> 00:06:48,470 ‫from a website or a cloud source that I put my APKs on. 125 00:06:49,260 --> 00:06:52,470 ‫Okay? So make sure you do that. 126 00:06:52,470 --> 00:06:57,270 ‫And in fact, in our case, it, it won't be even necessary 127 00:06:57,270 --> 00:07:00,240 ‫to download something from the internet. 128 00:07:00,240 --> 00:07:02,207 ‫We're just gonna drag and drop this APK 129 00:07:02,207 --> 00:07:04,800 ‫and it will work most of the time. 130 00:07:04,800 --> 00:07:08,490 ‫But it's essential that you know how to work with this stuff 131 00:07:08,490 --> 00:07:13,020 ‫because in a real device, in a real Android device 132 00:07:13,020 --> 00:07:15,810 ‫all you have to do is just download this APK 133 00:07:15,810 --> 00:07:19,620 ‫and make sure you installed it on your phone 134 00:07:19,620 --> 00:07:22,560 ‫or device or tablet so that it will run. 135 00:07:22,560 --> 00:07:25,320 ‫For example, in emulator, you can just drag and drop 136 00:07:25,320 --> 00:07:29,070 ‫like this, as I said before, and it will be installed. 137 00:07:29,070 --> 00:07:32,640 ‫Here you go. Now I can actually run this 138 00:07:32,640 --> 00:07:36,570 ‫and play with this, okay? 139 00:07:36,570 --> 00:07:40,380 ‫And it's not the case in a real Android device. 140 00:07:40,380 --> 00:07:43,650 ‫In that case, you have to upload this apk to a file 141 00:07:43,650 --> 00:07:46,590 ‫or a file upload your website 142 00:07:46,590 --> 00:07:51,590 ‫and then download it to your Android device and then run it. 143 00:07:51,750 --> 00:07:54,750 ‫So that's why we have learned about this 144 00:07:54,750 --> 00:07:58,020 ‫unknown sources in Chrome and everything. 145 00:07:58,020 --> 00:08:00,090 ‫So in order to upload your app 146 00:08:00,090 --> 00:08:03,690 ‫you can use any platform you want. 147 00:08:03,690 --> 00:08:06,360 ‫I generally use this files fm. 148 00:08:06,360 --> 00:08:11,360 ‫This is kind of weupload or transfer upload website, okay? 149 00:08:12,150 --> 00:08:15,630 ‫But it allows us to upload APKs as well. 150 00:08:15,630 --> 00:08:19,830 ‫So some of the platforms actually block this 151 00:08:19,830 --> 00:08:24,240 ‫and files fm do not, does not block APK. 152 00:08:24,240 --> 00:08:28,590 ‫So you can actually upload them whenever you want from here. 153 00:08:28,590 --> 00:08:30,810 ‫Okay? For example, I'm gonna do that. 154 00:08:30,810 --> 00:08:33,690 ‫I'm just going to say, start file upload. 155 00:08:33,690 --> 00:08:36,870 ‫And as you can see, it gives me a link. 156 00:08:36,870 --> 00:08:38,550 ‫Now, if I go to that link 157 00:08:38,550 --> 00:08:42,796 ‫from my device or from my emulator or from my phone, 158 00:08:42,796 --> 00:08:47,796 ‫I can actually download it and install it on my device. 159 00:08:48,930 --> 00:08:51,210 ‫So this is another alternative 160 00:08:51,210 --> 00:08:55,080 ‫rather than dragging and dropping the APK. Okay? 161 00:08:55,080 --> 00:08:58,950 ‫And the third alternative may be just 162 00:08:58,950 --> 00:09:03,630 ‫using the terminal or Android debug bridge 163 00:09:03,630 --> 00:09:07,920 ‫in order to use, in order to install APKs. 164 00:09:07,920 --> 00:09:11,580 ‫But make sure you remember this files fm 165 00:09:11,580 --> 00:09:16,230 ‫because we are going to use this a lot during this course, 166 00:09:16,230 --> 00:09:18,270 ‫as well as during your, 167 00:09:18,270 --> 00:09:21,900 ‫most probably in your real life as well. 168 00:09:21,900 --> 00:09:25,860 ‫So over here I have my emulator working 169 00:09:25,860 --> 00:09:30,330 ‫and I can actually reach that emulator by Android, 170 00:09:30,330 --> 00:09:33,540 ‫calling Android debug bridge, which is ADB. 171 00:09:33,540 --> 00:09:36,540 ‫And in order to do that, I'm gonna open terminal 172 00:09:36,540 --> 00:09:41,540 ‫in my Android studio and I will run some commands. 173 00:09:42,030 --> 00:09:44,250 ‫So this is the same thing basically 174 00:09:44,250 --> 00:09:48,030 ‫by opening your command prompt or terminal, 175 00:09:48,030 --> 00:09:53,030 ‫but you can actually do this inside of your Android studio. 176 00:09:53,040 --> 00:09:55,410 ‫So in Windows, you can call cls 177 00:09:55,410 --> 00:09:57,870 ‫in order to clear the screen. 178 00:09:57,870 --> 00:10:02,430 ‫And in Mac, of course, you can call clear 179 00:10:02,430 --> 00:10:07,050 ‫and then we are going to use adb. Okay? 180 00:10:07,050 --> 00:10:09,600 ‫But as you can see, I, 181 00:10:09,600 --> 00:10:12,000 ‫I have typed, adb install 182 00:10:12,000 --> 00:10:14,700 ‫and it says that command not found. 183 00:10:14,700 --> 00:10:18,300 ‫Actually, we have seen how to deal with this problem before 184 00:10:18,300 --> 00:10:20,190 ‫but in case you missed it, 185 00:10:20,190 --> 00:10:22,290 ‫I'm just going to show you one more time. 186 00:10:22,290 --> 00:10:25,200 ‫And in fact, I'm just going to show you another 187 00:10:25,200 --> 00:10:26,910 ‫solution this time. 188 00:10:26,910 --> 00:10:30,480 ‫So this generally becomes a problem 189 00:10:30,480 --> 00:10:33,750 ‫in MAC operating systems. Okay? 190 00:10:33,750 --> 00:10:35,790 ‫So I'm gonna search for this. 191 00:10:35,790 --> 00:10:38,880 ‫I'm gonna search for, adb command not found. 192 00:10:38,880 --> 00:10:40,230 ‫So I'm getting an error 193 00:10:40,230 --> 00:10:42,030 ‫and I just want to know how to solve it. 194 00:10:42,030 --> 00:10:45,720 ‫So I'm searching it in Google, okay? 195 00:10:45,720 --> 00:10:50,720 ‫And let me go to Google and say, adb not found, 196 00:10:50,850 --> 00:10:53,520 ‫maybe adb command not found. 197 00:10:53,520 --> 00:10:57,960 ‫And most probably I will see a lot of results like this. 198 00:10:57,960 --> 00:10:59,943 ‫Okay? Millions of results. 199 00:11:00,840 --> 00:11:05,280 ‫Then I'm gonna go into stackoverflow.com, 200 00:11:05,280 --> 00:11:06,780 ‫which is my favorite website 201 00:11:06,780 --> 00:11:10,920 ‫as well as, its favorite websites for every developer 202 00:11:10,920 --> 00:11:12,690 ‫in the world as well. 203 00:11:12,690 --> 00:11:15,630 ‫As you can see, there are a lot of solutions 204 00:11:15,630 --> 00:11:19,860 ‫for, adb command not found problem. 205 00:11:19,860 --> 00:11:23,040 ‫So if you are on Mac, and if you're getting this error 206 00:11:23,040 --> 00:11:25,650 ‫you can use the previous solution 207 00:11:25,650 --> 00:11:27,720 ‫that I have offered you in this course, 208 00:11:27,720 --> 00:11:31,500 ‫or you can try to export the paths like this, okay? 209 00:11:31,500 --> 00:11:35,040 ‫And it will add the paths to your platform 210 00:11:35,040 --> 00:11:38,643 ‫and you can use adb without having a problem. 211 00:11:39,570 --> 00:11:44,570 ‫And I suggest you use this code, echo export path, okay? 212 00:11:47,130 --> 00:11:50,130 ‫You can actually find this code from this website 213 00:11:50,130 --> 00:11:54,060 ‫or I can share this on my resources as well. 214 00:11:54,060 --> 00:11:57,930 ‫But once you do that, it'll add this path 215 00:11:57,930 --> 00:12:01,503 ‫to your profile so that you can use it whenever you want. 216 00:12:02,520 --> 00:12:04,800 ‫And in order to make this work, 217 00:12:04,800 --> 00:12:07,350 ‫I'm going to paste this over here 218 00:12:07,350 --> 00:12:09,090 ‫and it'll be run for me. 219 00:12:09,090 --> 00:12:12,300 ‫Now if I run adb install, let's see. 220 00:12:12,300 --> 00:12:15,210 ‫Yeah, it says that, command not found, 221 00:12:15,210 --> 00:12:17,490 ‫but over here it says that 222 00:12:17,490 --> 00:12:19,890 ‫you have to restart android studio. 223 00:12:19,890 --> 00:12:20,970 ‫So let's do that. 224 00:12:20,970 --> 00:12:23,970 ‫Let's close down and open one more time 225 00:12:23,970 --> 00:12:28,200 ‫and let's see if this works this time. 226 00:12:28,200 --> 00:12:32,550 ‫And I'm doing all of this, in order to make sure, 227 00:12:32,550 --> 00:12:37,550 ‫you know how to use APKs in emulators or in devices. 228 00:12:37,680 --> 00:12:40,500 ‫As you can see now, adb works. 229 00:12:40,500 --> 00:12:44,940 ‫Now if I say, adb install, it will ask for a requirement, 230 00:12:44,940 --> 00:12:46,590 ‫it will ask for a parameter. 231 00:12:46,590 --> 00:12:49,920 ‫It's asking for the apk itself. 232 00:12:49,920 --> 00:12:51,900 ‫So I'm gonna go over to my desktop 233 00:12:51,900 --> 00:12:56,070 ‫which I can go by saying, cd desktop. 234 00:12:56,070 --> 00:12:59,550 ‫However, apparently, I'm not inside of my home folder, 235 00:12:59,550 --> 00:13:02,700 ‫so I'm gonna say cd.. cd.., 236 00:13:02,700 --> 00:13:05,850 ‫then I can go to cd desktop, and here you go. 237 00:13:05,850 --> 00:13:08,610 ‫Now we can see pp debug apk. 238 00:13:08,610 --> 00:13:12,270 ‫Now I'm gonna run adb install app debug apk. 239 00:13:12,270 --> 00:13:16,110 ‫And now, yeah, it says that it's already over there 240 00:13:16,110 --> 00:13:18,480 ‫so you don't need to do this one more time. 241 00:13:18,480 --> 00:13:21,030 ‫But as you can see, we found the third way 242 00:13:21,030 --> 00:13:24,900 ‫of installing an apk into an emulator. 243 00:13:24,900 --> 00:13:28,200 ‫So you know how to work with this, 244 00:13:28,200 --> 00:13:31,350 ‫with three various ways right now. 245 00:13:31,350 --> 00:13:35,550 ‫So if one of them fails, just make sure you try another one 246 00:13:35,550 --> 00:13:40,550 ‫and make sure you follow the stackoverflow or googling 247 00:13:41,040 --> 00:13:44,340 ‫in order to solve your problems in real life as well, 248 00:13:44,340 --> 00:13:46,980 ‫like we did in this lecture. 249 00:13:46,980 --> 00:13:49,500 ‫So now we have our apk 250 00:13:49,500 --> 00:13:53,670 ‫and we know how to work with APKs in emulators. 251 00:13:53,670 --> 00:13:58,080 ‫Now it's really the time to decompile this 252 00:13:58,080 --> 00:14:01,080 ‫and manipulate it in a way that we want. 253 00:14:01,080 --> 00:14:03,873 ‫Let's do that in the next lecture.