1 00:00:00,380 --> 00:00:07,380 I'm going to be talking to you about Raid Air 2. It has a lot of pronunciations. People tell me 2 00:00:07,380 --> 00:00:10,640 that I'm probably saying it wrong. I'm just going to keep saying Raid Air 2. I'm sorry. That's 3 00:00:10,640 --> 00:00:14,920 what I'm going to do. It's going to be about 25 minutes. I'm talking about OpenXC, which is 4 00:00:14,920 --> 00:00:20,440 Ford's platform for moving canned messages over Bluetooth to, like, mobile apps, and it's kind of 5 00:00:20,440 --> 00:00:25,720 neat. Because OpenXC is open source, we can actually look at the firmware and kind of skip a 6 00:00:25,720 --> 00:00:28,840 lot of the discovery parts and just focus on reverse engineering with Raid Air. So it's 7 00:00:28,840 --> 00:00:34,260 really going to be a whole bunch of command line stuff. The talk is kind of in the Gen 2 8 00:00:34,260 --> 00:00:38,580 quadrant. There's going to be just a lot of commands, and, you know, I'll have the slides up. 9 00:00:38,660 --> 00:00:42,820 You can refer to the commands later. I'll try to describe what I'm doing, too. But it's not going 10 00:00:42,820 --> 00:00:46,880 to be Ubuntu style. It's going to be kind of like just fly, you know, go. So we'll see. 11 00:00:48,340 --> 00:00:53,440 First up, OpenXC. You know, this is a cool platform that kind of takes canned messages and 12 00:00:53,440 --> 00:00:58,620 translates them into message pack format, which is like JSON, and it lets you build these mobile 13 00:00:58,620 --> 00:00:58,820 apps. It lets you build these mobile apps. It lets you build these mobile apps. It lets you 14 00:00:58,840 --> 00:01:04,660 build these mobile apps. For iOS recently. For Android, it's actively developed. It's pretty 15 00:01:04,660 --> 00:01:08,580 fun. I recommend you go check it out. They give you hardware platforms and the software 16 00:01:08,580 --> 00:01:15,020 development. So you can do some cool stuff with it. Raid Air. So Raid Air 2 is like this 17 00:01:15,020 --> 00:01:19,500 reverse engineering suite of tools. There's a whole bunch of command line utilities you can 18 00:01:19,500 --> 00:01:24,920 use, like RA bin and RA hash. I'm going to be talking almost exclusively about R2, which is 19 00:01:24,920 --> 00:01:28,560 like the reverse engineering part of it. So I'll show you a little bit of Raid Air. 20 00:01:28,980 --> 00:01:34,340 I really wanted to do everything like command line style. But this is actually my backup deck 21 00:01:34,340 --> 00:01:37,900 because the command line stuff just didn't work. But I'm going to do this style of like here's a 22 00:01:37,900 --> 00:01:42,460 fake command prompt and I'm going to kind of scroll down. So a Raid Air session, you might open 23 00:01:42,460 --> 00:01:46,880 up a file. It's like an L file from binary samples. And then you want to analyze it. So AA. 24 00:01:47,140 --> 00:01:51,480 Every command in Raid Air starts with like hierarchical letters. So A is for analysis commands 25 00:01:51,480 --> 00:01:56,100 and AA is just like do the basic analysis. Okay. It says great. I looked at all the flags and I 26 00:01:56,100 --> 00:01:58,820 found some stuff. Thanks. S is for C. I'm going to look at all the flags and I found some stuff. 27 00:01:58,820 --> 00:02:04,620 So I'm going to like seek to the function called main. There I did it. And then more analysis 28 00:02:04,620 --> 00:02:09,480 commands. AX is for listing cross references. So here I'm just listing all the cross references 29 00:02:09,480 --> 00:02:13,400 that happen to be referring to main and you can see that the analysis actually completed because 30 00:02:13,400 --> 00:02:16,920 there's a whole bunch of cross references. This is great. And this is usually the experience you 31 00:02:16,920 --> 00:02:21,720 get with Raid Air, especially on like L files and PE files and stuff. It's really great at finding 32 00:02:21,720 --> 00:02:26,220 all that metadata in the symbol table and then helping you kind of walk your way through the 33 00:02:26,220 --> 00:02:26,420 binary. 34 00:02:27,180 --> 00:02:28,800 Now, when you're dealing with a raw data, you're going to want to be able to do a lot of 35 00:02:28,800 --> 00:02:32,000 things. When you're dealing with a raw firmware file, just like a bin file, you don't actually 36 00:02:32,000 --> 00:02:36,140 get all those nice symbol exports, right? So you can open it up in Raid Air. You can ask it to do 37 00:02:36,140 --> 00:02:39,800 the analysis. It will say great, I analyzed zero things for you because I don't know where main 38 00:02:39,800 --> 00:02:43,440 is, right? There's nothing there. There's no metadata. So you have to actually kind of teach 39 00:02:43,440 --> 00:02:49,640 Raid Air about where the file goes, do some searching for functions. And first Easter egg, 40 00:02:49,740 --> 00:02:54,920 Raid Air has Clippy. Clippy is installed so you can actually get Clippy to tell you things if 41 00:02:54,920 --> 00:02:58,120 you want a little bit of help. I don't know. He likes to help. 42 00:02:59,180 --> 00:03:05,120 Raid Air also does really great control flow graph visualizations in the terminal. So this is 43 00:03:05,120 --> 00:03:11,820 actually like text mode using UTF-8 lines and all the disassembly for every disassembly flavor that 44 00:03:11,820 --> 00:03:15,900 it supports, it will do this kind of control flow layout which is gorgeous. It's VV to get 45 00:03:15,900 --> 00:03:19,300 there. I'm not going to be showing you disassembly because this talk is really about 46 00:03:19,300 --> 00:03:23,780 extracting data. So we're going to be looking at how to pretty print canned signal 47 00:03:23,780 --> 00:03:28,780 information inside OpenXC. So not disassembly, more like data stuff. But if you're going to 48 00:03:28,800 --> 00:03:34,360 just have great control flow graphs for free, check out Raid Air. It's great. Okay. Going to be a 49 00:03:34,360 --> 00:03:39,140 lot of commands. I put together this summary of all the commands that I'm going to use. I will 50 00:03:39,140 --> 00:03:43,060 also show this slide at the end. So you'll have lots of time to take pictures for it. It will 51 00:03:43,060 --> 00:03:46,960 probably be in a PDF somewhere as well. You can see that the commands are all really hierarchical, 52 00:03:46,980 --> 00:03:53,000 right? All the analysis commands start with A. All the printing commands start with P. Information 53 00:03:53,000 --> 00:03:57,740 for the binary starts with I. And then there's two different things. And the most important one is 54 00:03:58,800 --> 00:04:03,720 question mark. You can use question mark as a post fix. And if you put it at the end of any letter, 55 00:04:03,820 --> 00:04:07,900 basically, it will tell you what that letter is as a command. And the help information in the 56 00:04:07,900 --> 00:04:11,940 command line for Raid Air 2 is really great. So if you know that to put question mark at the end, 57 00:04:12,000 --> 00:04:16,080 you can actually walk your way through Raid Air pretty well. The other thing is question mark first 58 00:04:16,080 --> 00:04:21,220 is more like an echo command. So you can question mark E will echo like actual echo command line, 59 00:04:21,300 --> 00:04:28,060 the normal stuff. Question mark V shows you like hexadecimal values. Question mark capital E shows 60 00:04:28,060 --> 00:04:28,560 you Clippy. 61 00:04:28,800 --> 00:04:35,080 We saw that already. So to recap, just to make sure we know what we're talking about, OpenXC takes 62 00:04:35,080 --> 00:04:41,800 these JSON files as part of its build and turns them into these CAN signal structures. Okay? And 63 00:04:41,800 --> 00:04:45,940 what we're going to do is go through the Raid Air commands necessary to actually go backwards and 64 00:04:45,940 --> 00:04:49,560 get the information out of the CAN signal structures that are in the firmware. They're going 65 00:04:49,560 --> 00:04:54,980 to kind of reverse that arrow. This is reverse engineering, right? Okay. This isn't the first 66 00:04:54,980 --> 00:04:58,780 time OpenXC has been reversed. I've given some talks about this. I've given some talks about 67 00:04:58,800 --> 00:05:03,900 doing this with IDA Pro. IDA Pro is very expensive, and this is now free. Around the same time I did 68 00:05:03,900 --> 00:05:10,280 the SANS talk, someone who had the handle BSMT put out a blog post detailing how to do the steps 69 00:05:10,280 --> 00:05:16,160 with some IDA Pro Python scripts. So BSMT's blog has like a fully automated way to do this using IDA 70 00:05:16,160 --> 00:05:20,640 Pro, which is kind of cool. Also, you know, I'm not the person who invented firmware reverse 71 00:05:20,640 --> 00:05:24,900 engineering. I'm totally standing on the shoulders of giants, and there are many. I really appreciate 72 00:05:24,900 --> 00:05:28,780 the help of Craig Hefner and his blog posts. I recommend all of his work. So I'm going to talk a 73 00:05:28,780 --> 00:05:31,680 little bit about that. And then finally, I didn't invent RAID AIR. You know, that's done by Truffet 74 00:05:31,680 --> 00:05:38,440 or Pancake, Pancake Knob Code. He actually has a talk here, this YouTube link, where he takes the 75 00:05:39,860 --> 00:05:44,920 MD380, the Tytara radios, and he reverses the ARM firmware in the Tytara radio. It's a firmware 76 00:05:44,920 --> 00:05:48,760 blob. It's using a lot of the same techniques. So I'm really building on all this previous work 77 00:05:48,760 --> 00:05:53,280 here, okay? We don't have a whole lot of time, so I'm really just going to do the yellow stuff, 78 00:05:53,480 --> 00:05:57,340 right? I'm going to assume, okay, we already know that we've got the firmware in our hand. 79 00:05:57,520 --> 00:05:58,480 You know, that's always a 80 00:05:58,780 --> 00:06:01,920 hard step with the device you just got, maybe getting the firmware. We already know the 81 00:06:01,920 --> 00:06:05,400 architecture. We already know the load address. We're just going to assume that stuff, and we're 82 00:06:05,400 --> 00:06:09,580 going to go do this yellow stuff. Load it into R2. We're going to assume that we've figured out 83 00:06:09,580 --> 00:06:13,460 where the loader loop is, you know, where the C runtime stuff does the copying, and we'll just do 84 00:06:13,460 --> 00:06:19,220 a copy for ourselves, and then we'll do the pretty printing of the structures. Okay. So first 85 00:06:19,220 --> 00:06:22,780 up, we want to load this thing. So we already know, because we're smart and we did some reverse 86 00:06:22,780 --> 00:06:28,320 engineering already, that the thing can get loaded at hex 10,000, all right? If you wanted to do this 87 00:06:28,780 --> 00:06:33,020 on off R2 command, you can do that with the dash M, as I'm showing here, M for the mapped address, 88 00:06:33,200 --> 00:06:41,680 hex 10,000. The architecture, which is A, dash A is arm. The size, like the bit width, is 16 for 89 00:06:41,680 --> 00:06:47,980 thumb, and this is a bit of a weird round hole, or a square peg in a round hole, because thumb 90 00:06:47,980 --> 00:06:51,280 isn't necessarily 60-bit addressing, and that will actually bite us when we're doing data 91 00:06:51,280 --> 00:06:56,300 printing, but you have to say B16 to get it to disassemble in thumb, and then you just give it 92 00:06:56,300 --> 00:06:58,440 the file, and this is the file that I got from the open source. 93 00:07:00,200 --> 00:07:06,420 Okay. Now, we don't necessarily want to just do the command line version of this, because we're 94 00:07:06,420 --> 00:07:09,580 going to keep adding stuff in. It's kind of like when you build a project in IDA Pro. You have, 95 00:07:09,640 --> 00:07:14,020 like, an IDB, right? Rather than work with an IDB, we're going to have this, like, config file 96 00:07:14,020 --> 00:07:18,620 for RAID Air, and we're going to keep building in little commands. So instead of that one-line 97 00:07:18,620 --> 00:07:21,880 command, we're going to start with, like, this R2 script file, and I'm going to set the 98 00:07:21,880 --> 00:07:28,220 architecture. It's ASM arc, ASM CPU, ASM bits. So this E command is setting config values. 99 00:07:28,780 --> 00:07:32,460 And under the hood, when you do those command line switches for dash A and dash B, that's really 100 00:07:32,460 --> 00:07:36,380 what's happening is just setting these config values. Okay? So then I'm going to say, okay, the 101 00:07:36,380 --> 00:07:42,320 bin address is hex 10,000. I'm going to call something flash, see F flash. So F is the flag 102 00:07:42,320 --> 00:07:48,020 command. In RAID Air, you can name any address by just calling it a flag. So F flash is hex 103 00:07:48,020 --> 00:07:55,860 10,000. And then O is for open files. So ON, I'm mapping a new file, the VI firmware file, at the 104 00:07:55,860 --> 00:07:58,400 address flash, which I just called 10,000. 105 00:07:58,780 --> 00:08:04,080 Okay? And then I'm setting this thing VA. With RAID Air, it knows the difference between file 106 00:08:04,080 --> 00:08:08,880 addresses and virtual memory addresses. And now that I've mapped the file, we need to tell RAID 107 00:08:08,880 --> 00:08:12,760 Air to switch into that virtual address space because I've just mapped it. Right? So now I'm 108 00:08:12,760 --> 00:08:17,540 going to start referring to things by hex 10,000 instead of zero. Zero would be the file offset. 109 00:08:18,120 --> 00:08:23,440 Hex 10,000 is the virtual offset. Right? So I'm going to switch to VA. And then lastly, the 110 00:08:23,440 --> 00:08:28,280 capital S, I'm adding a section. So I'm creating a section for the flash, giving it executable bits, 111 00:08:29,180 --> 00:08:34,020 and dollar S is the size of the file. And that's the kind of RAID Air magic that you just kind of 112 00:08:34,020 --> 00:08:37,000 get used to. And you write this once in the config file, and then you just kind of move on. Right? 113 00:08:37,860 --> 00:08:42,120 Okay. So what else we got to do? We know that there's a loader loop in this firmware. Loader 114 00:08:42,120 --> 00:08:47,320 loops are for C runtime. You know, it takes, like, your segment that's packed up into the binary 115 00:08:47,320 --> 00:08:51,660 file and puts it into the writable data segment, for example. That's what we're going to do here. 116 00:08:51,720 --> 00:08:58,440 We're going to emulate that. We know that it does a copy from 32EBC up to this million C8 hex address. 117 00:08:58,780 --> 00:09:05,080 And we know the length. So we're going to define data as this million C8. And then we're going to go 118 00:09:05,080 --> 00:09:09,320 and make another section. And this time you'll notice that the offset is different. Right? Because 119 00:09:09,320 --> 00:09:13,040 the sections, when you make them, they refer to the file offset. So I'm doing it, I'm making the 120 00:09:13,040 --> 00:09:19,420 section start from 22, not 32. But it'll be mapped at 32 because that's the map address. Right? 121 00:09:19,640 --> 00:09:22,800 And then the last command, now that we have everything set up, we actually know enough to 122 00:09:22,800 --> 00:09:28,600 use RAID Air's, like, search for preludes. You know, like, push, you know, every time you start a 123 00:09:28,780 --> 00:09:33,020 function, it's always the same little push and set up of the stack. And RAID Air knows how to 124 00:09:33,020 --> 00:09:37,620 search for that. So you can go AAP. It'll search through all the code sections that you define. 125 00:09:37,800 --> 00:09:41,400 It'll define functions that it recognizes as preludes. And that's a really great command for 126 00:09:41,400 --> 00:09:48,780 raw binaries. So at this point, we've mapped the code. And we have search for preludes. And 127 00:09:49,620 --> 00:09:57,580 PowerPoint crashed. I don't know. Let's try again. We might have to drink. 128 00:09:58,780 --> 00:10:17,140 Let's see. Okay. Can you see that? Oh, good. Where were we? And it crashed again. This is 129 00:10:17,140 --> 00:10:28,760 great. I should have made back up, back up strats. That's what I really needed. Okay. So 130 00:10:28,780 --> 00:10:35,020 right. So we have everything kind of mapped. I'm going to try to present. No, I'm not going to 131 00:10:35,020 --> 00:10:39,240 present this slide because it's just going to crash again. We have everything mapped. Okay. But 132 00:10:39,240 --> 00:10:44,180 you can see here what I'm showing you. When you just kind of dump the memory, you're not seeing, 133 00:10:44,280 --> 00:10:47,700 for instance, that there's a string defined here. Like, if it found the string, it would say 134 00:10:47,700 --> 00:10:52,880 str.signal1. It had identified the string. RAID Air would have. And when you do the disassembly, 135 00:10:52,880 --> 00:10:58,760 like, right here, instead of seeing disassembly, 136 00:10:58,780 --> 00:11:03,020 you'd actually see that it was data. Right? Like, if you used IDA Pro before, there's a 137 00:11:03,020 --> 00:11:07,840 difference between saying it's code or saying it's a quad D word. Right? What we want to see here 138 00:11:07,840 --> 00:11:12,040 to actually look at the data structures is turn this stuff into data. So it's not enough that 139 00:11:12,040 --> 00:11:15,240 we've mapped it. We have to actually somehow massage the information to get it together. 140 00:11:15,620 --> 00:11:23,180 So in this slide, which I'm sure won't crash PowerPoint, good. I'm showing you that you can 141 00:11:23,180 --> 00:11:28,560 ask RAID Air what it knows about strings. So here I'm saying, hey, RAID Air, IZ, what strings do 142 00:11:28,560 --> 00:11:28,760 you know about strings? I'm showing you that you can ask RAID Air what it knows about strings. 143 00:11:28,760 --> 00:11:33,220 And it says nothing, nothing at all. But you can ask RAID Air to search through the entire file and 144 00:11:33,220 --> 00:11:37,160 just do, like, a string match, just like, you know, GNU strings does. And it says, I know all 145 00:11:37,160 --> 00:11:42,820 these strings, but if you look at the addresses, they're all in 22. Right? They're not in the 146 00:11:42,820 --> 00:11:47,800 data segment that we created. They're in the wrong base offset. So the problem we have now is we 147 00:11:47,800 --> 00:11:52,420 have to actually take all those strings and map them where we want them to go. Probably with a 148 00:11:52,420 --> 00:11:56,220 patch to RAID Air, you could fix this, because IZ should do all data segments, but when you make a 149 00:11:56,220 --> 00:11:58,740 data segment, it doesn't recognize it. It only sees it when it comes from a different location. 150 00:11:58,740 --> 00:12:03,360 So this happens a lot when you're using RAID Air. And the solution is always just script it. 151 00:12:03,520 --> 00:12:07,240 Right? So I like Python. You could script it with Ruby. I know that there's, like, you know, 152 00:12:07,760 --> 00:12:14,000 choices like VI, Emacs, Ruby, Python. But R2Pipe lets you script RAID Air. Very simple Python 153 00:12:14,000 --> 00:12:19,980 script. I'm looking at the output of IIZ, and then I'm just adding that hex 10,000 to the base 154 00:12:19,980 --> 00:12:24,180 so that I can redefine all the strings. Right? So then when I'm done that, they're all redefined. 155 00:12:24,700 --> 00:12:28,720 All right. We need to groom the data, too, right? Because we know that when we look at the 156 00:12:28,740 --> 00:12:34,040 data section in memory, we saw disassembly. We didn't see quad words. Craig Heffner wrote a 157 00:12:34,040 --> 00:12:38,300 really nice script for IDA Pro called Codatify. When you're looking at firmware files, it's really 158 00:12:38,300 --> 00:12:42,740 useful to use this, because it just kind of, like, grooms the entire data segment, makes 159 00:12:42,740 --> 00:12:46,880 everything a quad word, sets everything to an offset type, and then what you get is, like, nice 160 00:12:46,880 --> 00:12:51,240 aligned data that automatically has cross-references. So when you just start looking at 161 00:12:51,240 --> 00:12:55,820 XREFs and start looking at data segments, it just starts popping out at you. With RAID Air, you 162 00:12:55,820 --> 00:12:58,660 don't get that automatically, but we can script it. Right? 163 00:12:59,020 --> 00:13:03,320 And what we're doing here is just walking the entire area of that data segment we created, 164 00:13:03,420 --> 00:13:08,360 defining everything as a quad word, and then creating a data reference of the value of that 165 00:13:08,360 --> 00:13:12,760 quad word. So you might be left with a bunch of, like, false positives, but it's better to have a 166 00:13:12,760 --> 00:13:18,000 bunch of false positives than have none of the cross-references at all. Okay. So here's a look at 167 00:13:18,000 --> 00:13:21,700 what our, like, project file is now. You can see we have the data segment. All the stuff we did 168 00:13:21,700 --> 00:13:25,800 before is in gray, and I'm highlighting in white how you actually execute those Python scripts. 169 00:13:25,960 --> 00:13:28,520 So RAID Air has this weird, has the shebang idiom. 170 00:13:28,740 --> 00:13:34,420 Right? So you go hash, bang, or exclamation point Python to run my Python script, and then I give it 171 00:13:34,420 --> 00:13:38,780 the two arguments. I'm just, all I'm doing, my project file now includes those two scripts that we 172 00:13:38,780 --> 00:13:42,800 defined. Now, I know we looked at a lot of strings and text and stuff, so I just wanted to give you 173 00:13:42,800 --> 00:13:50,060 a funny picture. Take a break. But there will be more commands. Okay. More commands. So we're 174 00:13:50,060 --> 00:13:54,960 loading stage three. Everything is all set. We know from our previous research that CAN signals, 175 00:13:55,120 --> 00:13:58,620 the whole array, starts at this particular address. Just let's assume that. You can 176 00:13:58,740 --> 00:14:04,420 figure it out by looking at the cross refs. If we go to that point and we say, hey, RAID Air, 177 00:14:04,500 --> 00:14:09,580 what cross refs are there? It says, okay, good. Now we have cross refs. See, Codatify went, set 178 00:14:09,580 --> 00:14:13,300 everything as a quad word and made data cross refs, and there's the proof. We actually have our 179 00:14:13,300 --> 00:14:18,960 data cross references. And if we disassemble at that location, we don't see disassembly. We now 180 00:14:18,960 --> 00:14:22,680 see nice quad word statements, which is kind of like what you'd see in IDA Pro after you set 181 00:14:22,680 --> 00:14:28,140 everything to the data type. Right? This helps us, like, inspect the data better. Lastly, there's 182 00:14:28,740 --> 00:14:33,620 a command called PXR. It does telescoping. So if anyone uses, like, Ponebug or any of those 183 00:14:33,620 --> 00:14:38,320 GDB add-ons, telescoping is where you take, like, the value in your stack and you just keep treating 184 00:14:38,320 --> 00:14:42,400 it like a pointer until you can't treat it like a pointer anymore. So you get this view of memory 185 00:14:42,400 --> 00:14:47,640 as it telescopes. Right? And PXR does that for you automatically. So you can see PXR is telling 186 00:14:47,640 --> 00:14:50,960 us, yep, this particular address is pointing to something in data, and that's pointing to 187 00:14:50,960 --> 00:14:55,040 something in data. Good. That's all set. And we can see that we actually are referring to a string 188 00:14:55,040 --> 00:14:58,500 signal one, and it's actually starting to map to that structure really well. 189 00:14:58,740 --> 00:15:03,200 Right? What we would really love to be able to do is say, okay, if this signal is called tire 190 00:15:03,200 --> 00:15:07,380 pressure, what can messages that in? Right? That's kind of like what we would like to know. Right? 191 00:15:07,560 --> 00:15:11,500 If you had some vehicle and you wanted to figure out where's the tire pressure signal, that's what 192 00:15:11,500 --> 00:15:16,460 you'd like to know. And this kind of telescoping isn't telling us enough. We want to go backwards 193 00:15:16,460 --> 00:15:22,540 to get all that mapping information. Okay. What we really want is types. Right? Radar actually 194 00:15:22,540 --> 00:15:28,720 knows how to parse header files and how to pretty print types. So we could eventually tell it, 195 00:15:28,740 --> 00:15:34,800 hey, you know, we know this is a pointer to can message. And we know that this is a pointer to a 196 00:15:34,800 --> 00:15:38,160 string. Can you just pretty print that for me so I can see the ID and the string right next to each 197 00:15:38,160 --> 00:15:43,340 other? The answer is yes, you can. The first problem you run into is if you load a raw binary 198 00:15:43,340 --> 00:15:48,680 file, you don't get any basic types. Right? So here I'm asking Radar, hey, I opened that raw 199 00:15:48,680 --> 00:15:53,580 binary file. What types do you know about? I'm saying T, enter. It says nothing. I don't know 200 00:15:53,580 --> 00:15:58,620 any types. Okay. So what if I ask you to give me the types and Radar commands? Because the star post fix, 201 00:15:58,740 --> 00:16:04,020 turns any output from instead just printing, like, the information in human form to printing it 202 00:16:04,020 --> 00:16:07,400 in Radar commands so you can just reuse it. It says, nope, sorry, I don't know any Radar 203 00:16:07,400 --> 00:16:13,080 transfer types either. The workaround is you just open any ELF file that's close to what you want 204 00:16:13,080 --> 00:16:18,240 to do and then use that T star command to tell that instance of Radar to dump all its type 205 00:16:18,240 --> 00:16:23,080 information to a file, which I'm doing with, like, a redirect here at the bottom. Right? And then 206 00:16:23,080 --> 00:16:28,140 when I go to the other instance of Radar, I can load that up, see the dot. I can load the types 207 00:16:28,140 --> 00:16:28,720 through to two files. So I can load that up, see the dot, I can load the types through to two files. 208 00:16:28,720 --> 00:16:32,220 So I got all the basic info and I'm like, great, I got the basic types, I'll just go and load the 209 00:16:32,220 --> 00:16:37,420 header file from OpenXC, it'll be fine, right? No, it's not fine. Seg fault. But we can fix that. 210 00:16:37,800 --> 00:16:41,420 You take the header file, you massage the header file a little bit. I won't bore you with that. 211 00:16:41,520 --> 00:16:45,100 You just kind of, like, you know, fix the types. And all of a sudden we have all the info. Okay. 212 00:16:45,160 --> 00:16:49,480 So here's our new project file. We made some more flags, see the F commands. We're saying these are 213 00:16:49,480 --> 00:16:54,380 addresses that have important names. I'm doing dot types 32 to load in that basic type 214 00:16:54,380 --> 00:16:58,700 information. And then I'm just loading a can util.h file, which I'm going to use to load the 215 00:16:58,700 --> 00:17:02,000 data, which I've massaged into something that doesn't make RAID air seg fault, which is useful. 216 00:17:02,400 --> 00:17:07,700 Now I have to set the bit width back to 32. When you're doing disassembly, it needs to be 16 to 217 00:17:07,700 --> 00:17:12,240 recognize thumb. But when you're doing the data inspection, you want the pointers to all be 32 218 00:17:12,240 --> 00:17:17,260 wide. And if you leave it at 16, it treats pointers as half words. Right? And then you just 219 00:17:17,260 --> 00:17:23,440 don't even see the data. So we set it back to 32 to continue. All right. Where are we at? We can 220 00:17:23,440 --> 00:17:28,680 go to that can signal start array. I can ask RAID air what type information do you need to 221 00:17:28,680 --> 00:17:33,680 know about this can signal type? And it prints back this PF thing. So what it's telling me is 222 00:17:33,680 --> 00:17:40,980 this is a PF, a print format command for dumping that can signal structure. Right? Now it's quite 223 00:17:40,980 --> 00:17:46,260 a long string. You know, you have this kind of PZBBFFFF and then a whole bunch of names. Okay? 224 00:17:47,480 --> 00:17:51,880 If we just do that straight up, things don't really line up properly and we don't get stuff 225 00:17:51,880 --> 00:17:55,760 like, instead of seeing the address of that can message, we really would just like to see the 226 00:17:55,760 --> 00:17:58,660 arbitration ID in that message. Right? That's the mapping we want to go for. 227 00:17:58,680 --> 00:18:02,260 And then you notice that factor doesn't even make sense. You can't have a factor of zero because 228 00:18:02,260 --> 00:18:05,300 if you take a number and you multiple that by zero, you're not going to get that number back. 229 00:18:05,420 --> 00:18:11,060 It's a useless can signal. So something has gone wrong. There's a lot of format commands. Like, 230 00:18:11,060 --> 00:18:15,240 a lot of them. Each one of them does something subtly different. If you're going to start doing 231 00:18:15,240 --> 00:18:18,600 this kind of thing, I recommend starting with that header file because then at least you don't 232 00:18:18,600 --> 00:18:22,980 have to just, like, grok the entire format. You can tweak one format at a time. And what I did 233 00:18:22,980 --> 00:18:28,660 was PF question, question to get this list. Okay? So we have that set up. We're going to go back to 234 00:18:28,680 --> 00:18:33,980 signal start. I'm going to first fix the can message type, which is the thing that the signal 235 00:18:33,980 --> 00:18:38,140 structure refers to because what I want to see is the arbitration ID. And that's really the only 236 00:18:38,140 --> 00:18:42,520 thing I care about in this message structure. See, it's got an arbitration, a bus, an ID, a 237 00:18:42,520 --> 00:18:48,020 format, frequency and stuff. I don't care about the rest. I just want that ID. So I know that 238 00:18:48,020 --> 00:18:52,060 the print format statement has PDE and all that stuff. I'm going to ignore things. And you can 239 00:18:52,060 --> 00:18:58,060 ignore stuff with colons and dots. So I'm going to change it to, you know, colon X dot colon colon, 240 00:18:58,680 --> 00:19:02,900 statement you see there with the PF. And all of a sudden, all I see is the ID. Great. That's all I 241 00:19:02,900 --> 00:19:08,880 want, right? So I'm going to make a format identifier, like a custom format identifier. I'm 242 00:19:08,880 --> 00:19:13,020 going to call it just the can message arbitration ID, please. And it'll remember that. And I can 243 00:19:13,020 --> 00:19:19,440 use that command. So now what I said is print me the current thing as a pointer to the structure. 244 00:19:19,800 --> 00:19:24,220 And I got back exactly what I wanted. I got just the arbitration ID. So I'm sitting here at the top 245 00:19:24,220 --> 00:19:28,480 of the array, sitting on a pointer to this structure that has the arbitration ID. And I asked 246 00:19:28,680 --> 00:19:33,800 print me just the ID. We're good. So now we can build up the rest. Another break. I know I'm 247 00:19:33,800 --> 00:19:42,220 doing a lot of text. Here you go. Funny picture. Okay. All right. So back to the can signal 248 00:19:42,220 --> 00:19:47,000 structure. That's a really, really big print format statement. And it misaligned. So if you 249 00:19:47,000 --> 00:19:50,660 look at the one highlighting in blue, there was an alignment problem in the can signal structure, 250 00:19:50,780 --> 00:19:55,840 and I had to add those two dots between the N1 and the F. And I've told it now, okay, I got two 251 00:19:58,680 --> 00:20:02,900 more. And then a whole bunch of floats. And the good news is when you do that, it's exactly the 252 00:20:02,900 --> 00:20:09,080 info you want. So we have our bit position. We have our bit size. We have a factor that makes 253 00:20:09,080 --> 00:20:13,700 sense. We don't have, like, a pointer to the message with the arbitration ID yet. We need to 254 00:20:13,700 --> 00:20:19,380 get that to work. The problem is you can print either a pointer to a string in a format 255 00:20:19,380 --> 00:20:24,920 specifier or a pointer to a structure in a format specifier. But you cannot print both a pointer to 256 00:20:24,920 --> 00:20:28,520 a structure and a pointer to a string in a format specifier. It just doesn't work for 257 00:20:28,680 --> 00:20:33,320 some reason. So more work arounds. We'll just print twice, right? But this gives us a chance 258 00:20:33,320 --> 00:20:40,440 to talk about macros, right? So Ray Dare has this idea of macros. See the little round brackets? 259 00:20:40,840 --> 00:20:45,040 So I define this thing called just print something, and it's, you know, doing one print 260 00:20:45,040 --> 00:20:49,520 command, comma, another print command. And then I can just call that macro by putting in a round 261 00:20:49,520 --> 00:20:57,420 brackets later. We're off to the races. Okay. So we load this thing up. I can now say invoke 262 00:20:57,420 --> 00:20:58,660 that macro. See the round brackets. I can now say invoke that macro. See the round brackets. 263 00:20:58,680 --> 00:21:04,900 And then I'm using the iterate operator. So I'm telling Ray Dare to run that command on every 264 00:21:04,900 --> 00:21:11,480 address between the steps. It's just like Python's range operator. This address to that address with 265 00:21:11,480 --> 00:21:16,700 this step. And that means I can actually print each thing in a row in that whole array, and we 266 00:21:16,700 --> 00:21:20,660 get what we're looking for, right? So you got the message structure pointer, which is just showing 267 00:21:20,660 --> 00:21:25,820 you the arbitration ID, right next to the bit position and the bit size, and the factors and 268 00:21:25,820 --> 00:21:28,500 the min and max values. And that's all the really key information that you needed. 269 00:21:28,680 --> 00:21:34,160 Right? If you compare, like, what's in the JSON from the build to what you can now pretty print with 270 00:21:34,160 --> 00:21:41,520 Ray Dare, all the info you want is right there. Right? So we're good. Now, because I like pain and 271 00:21:41,520 --> 00:21:47,980 we're not over time, let's do a live demo. What do you think? Live demo? All right. Let's do 272 00:21:47,980 --> 00:21:53,600 this. So actually I'm in the right folder. This is good. All right. We're going to invoke Ray Dare. 273 00:21:54,580 --> 00:21:58,660 I have created the final stage, final boss. Okay. So I'm going to invoke Ray Dare. I'm going to 274 00:21:58,660 --> 00:22:05,780 do this. Okay. We have our macro defined. I've also introduced a new command here with CF. CF lets 275 00:22:05,780 --> 00:22:10,400 you do like what you do in IDA where you set an address to be formatted a particular way. So you 276 00:22:10,400 --> 00:22:14,920 can tell it here's that print format statement and just make it persistent on this address. So I 277 00:22:14,920 --> 00:22:19,480 can go through all of memory and make it formatted so that when I do the disassembly, I can actually 278 00:22:19,480 --> 00:22:28,200 see the arrays. Here we go. Final boss stage. Like that. Good. We'll seek to can signals start. 279 00:22:29,200 --> 00:22:45,100 No, we won't? Why not? Come on, live demo. Ah, I did the wrong stage, guys. Here we go. Here we 280 00:22:45,100 --> 00:22:55,260 go. Final boss. Yep. All right. So we formatted memory. Sorry. For those of you who can't see my 281 00:22:55,260 --> 00:22:58,640 keyboard, I'm typing V and then I hit the letter P to go to the destination. So it's going to be a 282 00:22:58,660 --> 00:23:03,300 disassembly view. And when we're looking at disassembly, you know, we see the D words and 283 00:23:03,300 --> 00:23:08,200 when we're properly aligned in every place, we see the nice structures. And this is all the way 284 00:23:08,200 --> 00:23:18,560 through that array of CAN signals. So we did it. Are there any questions? I know that was really 285 00:23:18,560 --> 00:23:23,000 fast and a lot of commands. This is the reference for commands. Let me put it up again so you guys 286 00:23:23,000 --> 00:23:32,260 can take some pictures. I'll definitely get the slides out as well. Hey, thanks for your 287 00:23:32,260 --> 00:23:34,500 attention, guys. I'm going to have another drink.