00:00:00.000 --> 00:00:04.705 All right. So this is put on your ten foT hat. I'm Miaubiz 00:00:04.705 --> 00:00:10.711 and this talk is going to be about templates and scripting et 00:00:16.383 --> 00:00:22.389 por or IDA as we call it. They look like this, basically they 00:00:25.092 --> 00:00:31.231 solve the problem that we have this function max and the code 00:00:31.231 --> 00:00:37.704 is equally have lid for cars and valid 32 bits signs in so we 00:00:37.704 --> 00:00:43.911 don't want to write the code over and over so we have this 00:00:43.911 --> 00:00:48.782 expression and then type and there is a place by the compiler 00:00:48.782 --> 00:00:54.154 whatever type you're using and then bindery you will end up 00:00:54.154 --> 00:01:00.827 with this. And this for whatever types are actually use. And then 00:01:00.827 --> 00:01:06.833 eventually your C plus templates look like this but is fine when 00:01:16.910 --> 00:01:22.916 you're programming C plus then you have some binary. You can 00:01:28.422 --> 00:01:33.894 put what's in there and there is bad decoration and says near 00:01:33.894 --> 00:01:41.835 something or where the problem is where you have that angle 00:01:41.835 --> 00:01:47.841 bract. I didn't get too far. So when you have seize C plus 00:01:49.977 --> 00:01:56.083 templates. Which are character that IDA doesn't accept so we 00:01:56.083 --> 00:02:02.022 still want to get them in there so there is 3 ways we can do it 00:02:05.826 --> 00:02:13.500 and we're going to use python. That's a Texas or raddle snake. 00:02:13.500 --> 00:02:19.506 So the -- the first one is typical version and we're going 00:02:34.054 --> 00:02:38.492 to look at -- 10 foes and then we give it -- it works out. And 00:02:38.492 --> 00:02:42.396 this is the type part of it. So the first the stuff in black 00:02:42.396 --> 00:02:47.901 we're going to focus on the red and green part. And so they both 00:02:47.901 --> 00:02:55.108 start the same slash end or the ten. And there is the pointer at 00:02:55.108 --> 00:03:00.247 the star. Can you have several in a roll. Then you have the 00:03:00.247 --> 00:03:06.253 length and then have you the pound sign which means -- there 00:03:15.529 --> 00:03:20.801 is two different 0 -- when you go to local types. You see the 00:03:20.801 --> 00:03:24.337 -- and then you decode them there is math involved. Somewhat 00:03:24.337 --> 00:03:28.942 and then we figure out that is 1645 and 1398. That was the 00:03:28.942 --> 00:03:33.013 types. You can do the reverse operation and then you can 00:03:33.013 --> 00:03:37.484 replace then those in that string you have and then apply 00:03:37.484 --> 00:03:43.490 type and now it works again. So if say for PDB into your local 00:03:45.959 --> 00:03:51.164 types you gotten already types that have templates in them, now 00:03:51.164 --> 00:03:56.937 you can just replace the O and O in that in that string you got 00:03:56.937 --> 00:04:04.211 from ADA and it still works you magically get the proper types 00:04:04.211 --> 00:04:09.282 in there. And then that's one way of doing it. Sometimes 00:04:09.282 --> 00:04:15.288 that's a good way. Meeting this actually classes and types of 00:04:18.458 --> 00:04:24.464 whatever and they are generated into the binary. The whole thing 00:04:29.436 --> 00:04:36.977 is just a string. Is just like type with a weird name. That 00:04:36.977 --> 00:04:42.983 happens to have those symbols in them. So you can actually rename 00:04:49.956 --> 00:04:56.563 types to anything and so one way to get around the problem. So 00:04:56.563 --> 00:05:03.703 basically when you go to venue try to enter a type and when you 00:05:03.703 --> 00:05:09.709 try to apply a type to a function it pauses the -- poises 00:05:12.379 --> 00:05:17.984 your type declaration and also any type declaration that has 00:05:17.984 --> 00:05:23.990 been reference by that type and so if anywhere in that type that 00:05:26.092 --> 00:05:33.033 -- these bad character then it will fail. So you can just -- 00:05:33.033 --> 00:05:39.372 whatever types are in there you rename them to something like 00:05:39.372 --> 00:05:45.378 temp 1 or 2. Whatever. And then we name to them back and achieve 00:05:47.480 --> 00:05:54.421 the same result. And APA that's call rename maim the type. And 00:05:54.421 --> 00:06:01.294 unlike IDIPI this one actually does what it says. So then you 00:06:01.294 --> 00:06:07.934 call it original name and then you do the opposite operation 00:06:07.934 --> 00:06:13.940 after the setting the type. Okay. So then the T foe TIPI. So 00:06:31.157 --> 00:06:38.565 you create a 10 foe T. So 10 foe is type in foe underscore B is 00:06:38.565 --> 00:06:43.069 just something that's on all of those types. And then you can 00:06:43.069 --> 00:06:49.743 call, get name type on that 10 toe T and where it says some 00:06:49.743 --> 00:06:53.747 crazy name you can actually put any string and it will create a 00:06:53.747 --> 00:06:59.753 10 foe T that has that name. A name with that I mean -- the 00:07:04.758 --> 00:07:10.931 local type with that name then when you apply the 10 foe you 00:07:10.931 --> 00:07:16.936 get different results. But then so the VDUI is because much of 00:07:22.542 --> 00:07:28.548 this scripping for x-rays is intended so that when are you 00:07:31.451 --> 00:07:35.221 decompiler window and user interface you can use what's 00:07:35.221 --> 00:07:42.429 visible in the window. So you have to then jump to the screen 00:07:42.429 --> 00:07:49.636 EA and open or whatever and then you're able to get this IU 00:07:49.636 --> 00:07:55.709 object. And then change the type of your function argument then 00:07:55.709 --> 00:08:02.282 you actually change the types L bar here is local variable so 00:08:02.282 --> 00:08:08.955 the you change the type of local variable that are in arguments 00:08:08.955 --> 00:08:16.129 and when you do that it then changes the type of the function 00:08:16.129 --> 00:08:23.136 itself. And there is a the L bar object itself has also a set 00:08:23.136 --> 00:08:29.476 type method which would seem to be the same operation as going 00:08:29.476 --> 00:08:34.347 through the UI and then changes the L bar type but that other 00:08:34.347 --> 00:08:39.018 set type actually that's a different thing or nothing and 00:08:39.018 --> 00:08:45.025 that's why you need to go through this DUI. So here's the 00:08:47.193 --> 00:08:54.801 whole thing. You have to decompile it and there is just 00:08:54.801 --> 00:09:00.740 to get it to open decompile window for you otherwise you 00:09:02.842 --> 00:09:10.817 can't get the DBUI. And wow so then there is the return type of 00:09:10.817 --> 00:09:17.891 the function and so right there I was all I was changing the 00:09:17.891 --> 00:09:24.397 arguments the local variable that are the arguments of the 00:09:24.397 --> 00:09:28.835 function. The return type doesn't have. Even though there 00:09:28.835 --> 00:09:34.841 is a return. There is a local variable for the return. 00:09:34.841 --> 00:09:41.848 Variable or whatever, but if it changes that type it won't 00:09:41.848 --> 00:09:47.854 actually let you do it. The return type of the function and 00:09:52.092 --> 00:09:55.462 also when are you exchanging the when you're doing this calling 00:09:55.462 --> 00:10:00.700 set L bar type. You can actually add or remove argument. 00:10:00.700 --> 00:10:05.205 Something you might be interested in. So then to create 00:10:05.205 --> 00:10:10.243 a complete arbitrary type. But also the number of arguments you 00:10:10.243 --> 00:10:16.249 can do that all in. So has it has these simple types. And 00:10:29.362 --> 00:10:35.368 order type and maybe some other types and simple types there is 00:10:37.637 --> 00:10:43.643 like one byte numeration and 80% of them are weird stuff that you 00:10:48.715 --> 00:10:54.888 will never use like the static pillar or this other one which 00:10:54.888 --> 00:10:59.025 obviously is not actually a type -- double that's on. And so then 00:10:59.025 --> 00:11:04.964 you can create this your string that where you place this place 00:11:09.636 --> 00:11:15.608 holder into your string or the return type and then for 00:11:15.608 --> 00:11:21.214 argument types how many you want and you give them different 00:11:21.214 --> 00:11:27.220 simple types and then make put in as many pointers as you want. 00:11:34.227 --> 00:11:41.568 Eventually and then you actually so your first type returns the 00:11:41.568 --> 00:11:48.608 same type of the magic string that was on solution 1. So then 00:11:48.608 --> 00:11:54.614 you can then do the replace thing you can replace the 00:11:57.116 --> 00:12:04.190 however is encoded by -- into the string. The simple types 00:12:04.190 --> 00:12:08.661 then you can replace them how the O -- are encode and had the 00:12:08.661 --> 00:12:14.667 early example I showed -- it was always 2 bytes for the length 00:12:17.036 --> 00:12:24.744 for like the first 1 thousand order -- will it actually be 00:12:24.744 --> 00:12:30.750 like 3 bytes so the -- beyond 4 thousand or 8 thousand the 00:12:33.419 --> 00:12:39.425 ordinal when it goes above that is slightly different but you 00:12:42.328 --> 00:12:48.334 can bend. Put in whatever you want and then so these you can 00:12:53.206 --> 00:12:59.212 get create a T 4 T and when you call -- on it and give it 00:13:04.350 --> 00:13:10.356 whatever the IDC -- so is another way creating a 104 that 00:13:12.759 --> 00:13:19.065 certain type. Because there is several functions in there. 00:13:19.065 --> 00:13:24.971 Create function type and is like 40 of them and if you look into 00:13:24.971 --> 00:13:28.207 them there is isn't any -- only -- mirrors of the header file so 00:13:28.207 --> 00:13:31.110 there is no public usage of these -- actually that's what 00:13:31.110 --> 00:13:37.116 you want on if you have that type of string that you get from 00:13:42.422 --> 00:13:48.428 get 10 foe or type from IDC. So then there is a function call 00:13:53.733 --> 00:13:59.739 applying 10 foes 2. Because apply 10 foe was taken so 00:14:02.575 --> 00:14:08.581 applies 10 foe and now it does the same as -- whatever I did. 00:14:13.886 --> 00:14:19.892 First one let me see where it was. Apply type from IDC. Okay. 00:14:26.299 --> 00:14:32.305 The whole thing. And then I don't know what I have to say 00:14:35.541 --> 00:14:41.547 about this topic. And wow. I went fast for 20 minutes. [ 00:14:54.427 --> 00:15:00.566 APPLAUSE ] >> Any questions? You. So the question is like 00:15:00.566 --> 00:15:06.572 when you would end up with these types that can now be partner. 00:15:14.380 --> 00:15:22.054 So basically let say you have binary and that includes -- C 00:15:22.054 --> 00:15:28.060 plus and then you built plus and then with symbol then you will 00:15:34.834 --> 00:15:38.204 have those symbols in there and you want to transfer those 00:15:38.204 --> 00:15:44.210 symbols into your unknown binary because these are normal. That's 00:15:49.482 --> 00:15:55.488 the common situation you'll end up with this. You know something 00:16:00.259 --> 00:16:03.329 about the types that's not in the binary and is C plus 00:16:03.329 --> 00:16:09.335 templates. Yeah. Ask basically for IDA as I mention somewhere 00:16:12.305 --> 00:16:19.078 in there. All though they're template types. IDA doesn't 00:16:19.078 --> 00:16:26.285 really care what the members of the templates are or how is 00:16:26.285 --> 00:16:32.592 structure. >> If you have more questions I have an mic that 00:16:32.592 --> 00:16:35.728 makes it easier for you to hear. So you have more questions? 00:16:35.728 --> 00:16:41.734 Anybody did it go over your head? Only 2 smart guys in the 00:16:45.938 --> 00:16:47.940 room. >> All right, thank you, guys.