0 1 00:00:08,820 --> 00:00:13,380 Before we continue I'd like to point out that you may have noticed that we're currently working on a 1 2 00:00:13,380 --> 00:00:21,210 Windows environment whereas before we were working on a Linux environment. We're simply doing this because 2 3 00:00:21,210 --> 00:00:24,570 the windows machine is faster than the lab Linux machine. 3 4 00:00:25,380 --> 00:00:32,650 It's just a matter of convenience but the entire section is exactly the same. 4 5 00:00:32,710 --> 00:00:35,050 The only difference is the file system. 5 6 00:00:35,050 --> 00:00:39,540 So for example here the project is saved in D Drive in Linux 6 7 00:00:39,550 --> 00:00:42,910 it will be under your home directory but that is it. 7 8 00:00:44,260 --> 00:00:50,520 Whatever we're doing here in Windows it will work exactly the same in Linux if you have any issues in 8 9 00:00:50,520 --> 00:00:51,150 this regard. 9 10 00:00:51,150 --> 00:00:55,370 Just let us know and we can help you out but you shouldn't face any issues. 10 11 00:00:55,380 --> 00:00:59,700 Just follow everything we're doing OK. 11 12 00:00:59,710 --> 00:01:02,690 So right now we have three UI elements. 12 13 00:01:02,710 --> 00:01:05,560 Here's the helloworld that is included by default. 13 14 00:01:05,950 --> 00:01:09,570 And here we added a send button and an edit list. 14 15 00:01:10,580 --> 00:01:15,300 So what we're going to do now is interact with the UI elements. 15 16 00:01:15,800 --> 00:01:23,540 We're going to add text in the edit text and when you click the send button the text that's added to 16 17 00:01:23,540 --> 00:01:28,940 the edit box is going to appear on the text to view over here. 17 18 00:01:28,940 --> 00:01:34,880 So to do this we have to go on the activity that's linked to this user interface. 18 19 00:01:34,910 --> 00:01:39,410 Now there are two ways of creating event handlers. 19 20 00:01:39,410 --> 00:01:41,250 We're going to show you both ways. 20 21 00:01:42,640 --> 00:01:44,670 First let's see the more common way. 21 22 00:01:45,890 --> 00:01:49,620 We start by going to the main activity. 22 23 00:01:49,660 --> 00:01:53,270 Now this is going to involve some programming. 23 24 00:01:53,530 --> 00:01:58,480 If you don't have programming experience don't worry we'll provide all the code. 24 25 00:01:58,480 --> 00:02:01,580 It's just a matter of copying and pasting. 25 26 00:02:01,780 --> 00:02:06,180 We'll also provide the entire project that you can just import and follow what we're doing. 26 27 00:02:07,820 --> 00:02:15,910 If you prefer just follow what we're doing and try to understand which code goes where, to be a reverse 27 28 00:02:15,910 --> 00:02:20,880 engineer you don't have to be a developer OK. 28 29 00:02:20,900 --> 00:02:27,450 So here we're going to create an event handler so we're going to create what's called a method. 29 30 00:02:27,650 --> 00:02:34,140 The method is going to be called Public void and we're going to call it post item. 30 31 00:02:34,250 --> 00:02:35,610 Here we are going to write. 31 32 00:02:35,620 --> 00:02:38,170 View .OK. 32 33 00:02:38,180 --> 00:02:40,520 Don't worry too much about that red warning. 33 34 00:02:40,520 --> 00:02:44,620 We'll go over those soon. 34 35 00:02:44,790 --> 00:02:51,410 First we're going to refer to the edit text that we have in our user interface to do this we're going 35 36 00:02:51,410 --> 00:02:52,490 to use the class: 36 37 00:02:52,510 --> 00:02:58,890 EDIT text and we're going to define a variable and call it ET. 37 38 00:02:58,940 --> 00:03:03,850 This is not a programming course so we're not going to go into too much detail about these details. 38 39 00:03:05,210 --> 00:03:10,490 We mainly want to give the reverse engineer an idea of the process that the malware author goes through 39 40 00:03:10,520 --> 00:03:18,120 when developing an app so here what we have to do is find view by ID. 40 41 00:03:19,360 --> 00:03:22,810 R. ID. 41 42 00:03:23,460 --> 00:03:29,750 Edit text, so what we just did here was create a variable called ET. 42 43 00:03:29,920 --> 00:03:33,250 Edit text and we are telling it... 43 44 00:03:33,250 --> 00:03:40,530 This edit text is going to be the UI element with the following ID, so here we're linking the code 44 45 00:03:40,560 --> 00:03:52,740 to the user interface element, similarly we're going to do the text view, text to view TV equals find 45 46 00:03:52,740 --> 00:03:55,400 view by Id. 46 47 00:03:55,430 --> 00:04:01,590 Actually we need to add an ID to the text to view so let's call it textview. 47 48 00:04:02,780 --> 00:04:03,610 OK. 48 49 00:04:04,660 --> 00:04:16,020 So we go back to our find view and pass R dot Id dot text view so now we've added a reference to our 49 50 00:04:16,020 --> 00:04:18,390 edit text and a reference to our text. 50 51 00:04:18,390 --> 00:04:21,540 View what we're going to do is simple. 51 52 00:04:21,580 --> 00:04:25,270 We're just going to say TV dot settext 52 53 00:04:25,300 --> 00:04:31,880 E T dot get text. 53 54 00:04:32,000 --> 00:04:32,960 What does this mean. 54 55 00:04:34,340 --> 00:04:41,540 So we're referring to the TV text view and we're telling it to send the text of the edit text to the 55 56 00:04:41,540 --> 00:04:46,060 content of the text to view OK. 56 57 00:04:47,210 --> 00:04:49,110 So it's quite straightforward. 57 58 00:04:49,130 --> 00:04:55,040 We're just creating an event handler that's getting the text from the edit text and posting it into 58 59 00:04:55,040 --> 00:05:00,680 the textview that's literally what we just said over here. 59 60 00:05:01,550 --> 00:05:05,060 So here we see that there is an error so it won't compile. 60 61 00:05:05,120 --> 00:05:09,920 You're seeing there's that red line under here now. 61 62 00:05:09,930 --> 00:05:15,480 Android Studio has this auto complete function where it tells you when there's an error and how to fix 62 63 00:05:15,480 --> 00:05:17,030 it. 63 64 00:05:17,040 --> 00:05:22,890 So in this case here it's telling you that we were missing a class reference, we're missing the following 64 65 00:05:22,900 --> 00:05:23,610 imports 65 66 00:05:27,000 --> 00:05:31,410 so here it's actually telling you what you need to do. 66 67 00:05:31,610 --> 00:05:36,530 Do you need to add Android dot view class. 67 68 00:05:36,560 --> 00:05:43,800 If so press Alt and Enter when you press alt and enter you see that it automatically added this import 68 69 00:05:44,340 --> 00:05:45,260 in this class. 69 70 00:05:45,480 --> 00:05:46,740 And then the errors are gone. 70 71 00:05:48,520 --> 00:05:49,110 OK. 71 72 00:05:49,150 --> 00:05:52,190 So if we run this now you'll see that nothing happens. 72 73 00:05:53,010 --> 00:05:54,880 So why is this. 73 74 00:05:55,380 --> 00:06:03,000 We run the application you have your user interface and you click it. 74 75 00:06:03,870 --> 00:06:06,470 But nothing happens. 75 76 00:06:06,480 --> 00:06:12,000 The reason is that we need to attach this event handler to the button and this hasn't been done yet. 76 77 00:06:14,500 --> 00:06:23,620 So to do this we're going to use the user interface click on the button and there should be on click 77 78 00:06:25,950 --> 00:06:36,980 on click over here click and you're going to choose it automatically detects what event handlers are 78 79 00:06:36,980 --> 00:06:40,450 available for you just click on that. 79 80 00:06:40,870 --> 00:06:42,070 And now it's been attached. 80 81 00:06:43,940 --> 00:06:47,690 So what happens now when we run the application 81 82 00:06:50,240 --> 00:06:52,480 there you go. 82 83 00:06:52,560 --> 00:07:03,850 It worked so if we write test and click you see that test gets written in the text of you OK that's 83 84 00:07:03,850 --> 00:07:08,920 your first simple user interface application. 84 85 00:07:08,940 --> 00:07:15,220 Next we'll show you how to do an event handler in another way so let's go ahead and remove this event 85 86 00:07:15,220 --> 00:07:23,850 handler and let's we just detach the event handler on click from the button. 86 87 00:07:23,850 --> 00:07:31,150 So now we're back in a situation where if we click on the button in the application nothing happens. 87 88 00:07:31,180 --> 00:07:36,160 Now another way of creating an event handler is by doing everything in code. 88 89 00:07:36,190 --> 00:07:43,870 This is useful when creating UI elements and event handlers dynamically so we won't refer to the event 89 90 00:07:43,870 --> 00:07:51,860 handler within the XML but rather we'll just create it in Java programmatically so in this case for 90 91 00:07:51,860 --> 00:08:00,920 example we can go on the on create method so the UN create is what happens when the activity starts 91 92 00:08:02,670 --> 00:08:09,990 so when the activity is created for the first time this code is executed and used to be able to attach 92 93 00:08:09,990 --> 00:08:17,310 your own actions over here to run after the first execution so in this case what we're going to do is 93 94 00:08:17,310 --> 00:08:37,920 we're going to say button Btn and equals button find view by Id R dot I d dot button send. 94 95 00:08:38,000 --> 00:08:44,570 So what we're going to do here is we're going to put an event handler directly on the button so to do 95 96 00:08:44,570 --> 00:08:54,890 this we're going to say Btn and Dot set on click listener so here I'm going to show you how developers 96 97 00:08:54,890 --> 00:09:07,430 work google stack overflow button on click and usually in the first post you will find your reply copy 97 98 00:09:07,430 --> 00:09:13,470 and paste and change your ideas. 98 99 00:09:13,510 --> 00:09:16,420 This is how many developers actually work. 99 100 00:09:16,480 --> 00:09:24,270 There's no need to remember all of the details, stack overflow usually has the answer. Then in the on 100 101 00:09:24,270 --> 00:09:30,230 click function we just copy the same code as earlier fix it up a bit. 101 102 00:09:32,260 --> 00:09:40,990 What we have here is we created a button defined in an event handler telling it on click add the text 102 103 00:09:40,990 --> 00:09:45,320 from the edit text to the text to view. 103 104 00:09:45,330 --> 00:09:55,990 Now we have to run this, enter text and click and as you can see we get the same behavior without specifying 104 105 00:09:56,020 --> 00:09:59,000 anything on the user interface. 105 106 00:09:59,020 --> 00:10:07,620 We did everything programmatically, so in both scenarios you get the exact same behavior. 106 107 00:10:07,670 --> 00:10:10,730 It's just a matter of preference for whichever option you choose.