Thank you for showing up, everybody. I appreciate this. I know that I'm on opposite of Pony Awards, so if you're here for Pony Awards, you're in the right place. So this is Reverse Engineering MicroPython Frozen Modules. My name is Wesley McGrew. I'm Senior Cyber Fellow with Martin Federal. And this talk is going to be a lot of fun for those of you who like to hack on badge life stuff. A lot of badge life badges use this Python interpreter. And we're able to pick out some things that perhaps you wouldn't have otherwise. So the agenda for the talk, we're going to be, we're going to introduce what MicroPython is. For those of you not familiar, I'm pretty sure most of you know about Python in general. We're going to look at MicroPython firmware on the Raspberry Pi Pico. So it's available for a lot of different microcontrollers, but Pico is probably the easiest for you to set up experimentation in your lab with. We're going to build a Hello World module for it, and we're going to compile it down into bytecode, and then we're going to freeze it into the MicroPython firmware itself so that it's harder for somebody to extract. We're going to talk about that freezing process and why it's there. We're going to have a hands-on example of reconstructing that module from a compiled firmware. We're going to do it with symbols and without symbols, so show you how to do it in an environment where somebody's trying to actively keep you from doing it. We're going to do some analysis of that extracted module and come to some conclusions about what this means for reverse engineering it. So MicroPython is an implementation of Python 3 for microcontrollers, and it's very interesting in that it's not a straight port of CPython. CPython is the Python you're familiar with on your desktop system where it's an interpreter running bytecode based off of the Python code that you write. And MicroPython completely just re-implements it from scratch. There's probably reasons for doing that instead of starting from CPython. Microcontrollers have limited resources and so things are optimized for that kind of environment. There's a subset of Python standard libraries in there. There's not libraries for some of the standard library stuff that doesn't make sense on a microcontroller, but there's also some additional MicroPython only libraries. They're just for working with microcontroller hardware, primarily like GPIO, like turn pin one on, pull it low, that sort of thing. There is a REPL, so a command line you're used to with Python where you can just start typing Python code and have it execute and sort of play around with the Python environment. You can do that with MicroPython if you have a serial terminal on your microcontroller like you do with a Pico. The use cases for it, you don't... I don't see it in anything that you can just like go to Lowe's and buy for home automation, but you do see it in scientific application, industrial applications. You see it in badges. And so like the last year's snacky badge at least used MicroPython. And specifically the frozen modules are used by a lot of folks to have code cooked into the firmware itself that's not in a module file on the file system. It's really nice. So what I'm presenting here is not a mistake made with MicroPython. It's just a reverse engineering talk. There's no vulnerability here as MicroPython is concerned. I like it. It's really easy to create a prototype of an embedded device with MicroPython. And so you have three choices for your code. You can have plain text that's on a small file system that's emulated in part of your flash memory. You can... and you can read and write to that file system through the REPL. You can have pre-compiled bytecode modules, and we'll talk about the structure of those. But then you can also take those pre-compiled modules and cook them into the... into the MicroPython firmware at build time. And that removes a lot of the metadata that makes it easy to find those modules and disassemble them, right? There's tools for working with the other portions of this. There's no tools for going back from a frozen module. And so in badge life, a lot of CTFs that use badges will hold secrets and keys and code that they don't want you to see as part of the CTF inside those frozen modules. The feature is there for efficiency. So the feature is there so that you're not wasting additional memory loading dot py or loading the dot mpy file into memory and doing things when it's already in memory because it's on the flash. So it saves memory. It's convenient. You don't have to do any additional loads. It's already there. But it's being abused, misused for obfuscating and hiding code and secrets inside of these binaries. And we've got some quotes here from random forums and stuff. You probably can't read them. They're small. I just grabbed a bunch of them and threw them up. But the gist of all these quotes is people are asking, well, if I've got a password for a system, how do I keep that away from my users? Or I've got a key. I've got a secret that I don't want them to read my code. Their concerns are making this obfuscated. And people were responding to them on these forums of like, you know, it's not perfect. And everybody acknowledges that this isn't perfect. And it's not perfect, but you can make it harder to get at that stuff by cooking it into a frozen module because nobody has the tools to disassemble it. And so let's make something to disassemble it. It's a layer of protection for some folks, but it's really just an obfuscation. The first thing that you have to do to get this thing working is to get a firmware image. So that's out of scope for this talk. And it's tricky depending on the module, depending on your microcontroller. You might not be able to get a flash image easy. That's a whole talk on, you know, glitching and things like that. But since we're using Pico as the, we can, we can just use the standard Pico tools for this demonstration. If you're following at home with a Pico, you use the Pico tool info and it'll tell you about the, about the firmware of a connected Pico. But it actually makes it a little too easy as you can see from the output here. From the output, you have a list of frozen modules here. And you're like, well, that's, that seems dumb. Seems like a really short talk. And what that's from is from Pico's, Pico has binary information, quote unquote, binary information in the firmware image. And it can be read with Pico tool. It can be encoded, it's encoded by MicroPython. Firmware can specify in MicroPython that it's going to include additional fields in that Pico tool or in that binary information. And MicroPython does this with simply a list of the frozen modules. And so, again, that seems real easy. You can look at how to parse that from a tool that comes with MicroPython that we're going to be using a lot here, NPY tool. This is used for freezing modules, for inspecting NPY files. There's some stuff in there for how it encodes that, that information. And so since this is too easy as a starting point, I mean, it's too easy because you can strip this out. It's not necessary for the operation of the firmware, right? So other platforms, other micro controls may not even have this sort of field, this sort of binary information in the firmware. It's not used by MicroPython itself, so we can evade this analysis by commenting out the code in the freezing tool that generates that list, right? And so to make it harder on ourselves, right? Because we imagine the next step after we start ripping this stuff out, people are going to start obfuscating this part. So we can rip this out and not have those frozen modules listed. If you can get to a serial console REPL, you can also do help modules and list them out. That is probably something that needs to be in there. I don't know if you could patch out an evasion from, or a countermeasure against that. But that's, but it's not always the case that you're going to be able to easily get the REPL on a microcontroller. So for our example, we're going to have the minimum viable Python module here, a hello world that we're going to demonstrate in plain text. We're going to demonstrate it as a compiled byte code file on the file system. And then finally as a frozen module compiled into MicroPython and look at what that looks like in the binary. Plain text is simple. You simply use the MP remote tool to upload it into the file system on the microcontroller. There's a small, very small file system that it stores those things in. You can list files on it and you import and go. You can use the MPY cross compiler to compile your hello world dot PY into an MPY into PY file and you wind up with the hex dump or you wind up with a file that has the following hex representation. And so you can kind of see in there, you see our strings, you can see some byte code in there and so you're like okay, this is a thing. Um, this immediate, doesn't immediately look to you to be very useful, but the MPY tool can work with this format very well and you can upload it into the file system and, and use it. And so if you find one on a file system, use MPY tool to uh, to tinker around with it. As a frozen module, you can take that MPY and rebuild the microcontroller or firmware from scratch. You can rebuild MicroPython from scratch including that MPY that you created. It brings it in, it kind of uh, it brings it in as a set of C structures and we'll talk about that in a little bit, but basically it's hard to go back. After you've frozen it into the firmware, it's harder to pull it back. It's not just a file on the file system anymore. But you can use it as a Python module just fine. So what can we learn from an MPY file? Because our goal eventually here is going to be to take that uh, frozen module, extract it from the firmware, recreate the MPY so that we can parse it. The MPY tool creates um, uh, uh, the frozen module from the MPY. Uh, and so the MPYtool.py code has a lot of uh, uh, algorithms and data structures in it for generating this. And so it does not generate the, binary that's going to be in the firmware directly. It generates a set of C code that's going to get statically linked into the MicroPython firmware. So um, and it's less coded and it's just like a whole lot of data structure, a whole lot of structs, right? And those structs are going to get compiled in and they're going to get arranged by the compiler into memory in various places that are not immediately obvious to you from just reading the code. Uh, the same tool can be used to dump info about an MPY file with a disassemble flag. So it does have a built in disassembler. Uh, this is the only disassembler you get with MicroPython and it's only pulling from MPY files. So if we get code out of the binary, we're going to need to disassemble it with this tool. And by the way, the bytecode for MicroPython is not the same bytecode as CPython. It's definitely not the same opcodes. It's many of the same, uh, it's many of the same opcodes with different, different values and uh, not all of the same opcodes, right? So it's a from scratch implementation. If we dump or disassemble an MPY file using the MPY tool, we get three main things out of it. We get a string table, a module, a string table, an object table, and a set of code. What you're looking at here is the string table and I'm going to talk to you about this, this, um, intern string format that they have here. For the code, there's two pieces of code. If you remember, we had a module that defined, we defined a module and then we defined a go function in it or a hello world function in it. And, um, so you're going to have two functions that have bytecode. The first one is going to be a constructor and the next one is going to be your go function that actually repeats hello world every, uh, five seconds. And you can see the, the bytecode in these and it's a stack-based language. Basically you're, you're, you're constantly loading things out of different data structures, putting them on the stack, calling other functions, pushing and popping and looping around and doing things like that. And so again, if you read up on how a Python bytecode works, it would make sense to you, but, uh, it's not exactly the same. So you can't use like the body of Python disassembly tools on this or debugging tools for this. There's a really nice colored output hex dump that you can get within PY tool that will sort of tell you what the different parts of that hex dump mean and what, what, what they are, what they have, what they're about. That'll help us when we're trying to recreate one of these. So if we can rebuild an MPY of a frozen module out of information we extract from firmware, we've got something we you can use to, to, to get some work done with it. Uh, it'll take some RE work, but it's not because it's not there in a contiguous binary blob. It's structures we've got to walk, right? We've got to find them in memory and walk them. Uh, we have to understand string interning. We need to look at the byte, byte code briefly. It's just not going to be a byte code class or anything. Um, but also another tool that we can use is we can build a version of MicroPython that's the Unix port, quote unquote Unix port. You can build it for, for Windows, Linux or whatever, but it's basically a desktop version of MicroPython, uh, that you can, that you can build and load MPY files into, run them, analyze them and do things to where you're not just restricted to working on the microcontroller itself when you're doing your reverse engineering. So first off, uh, how we're storing our string constants. We're doing what's called string interning. And so this is something that you do on very limited memory environments where you want to avoid having the same constant string in memory more than once, right? You don't want to have, uh, main or, or something like, or some other common string 50 different times in your memory if your memory is in on the order of megabytes or kilobytes or something like that, right? And so MicroPython, MicroPython calls these Q strings for unique, for unique strings. Um, and basically Q string values, the way you refer to them is, is into an index, into a linked list of pools of these strings, right? And so if you're wanting to refer to hello cruel world, or you're wanting to refer to, uh, the, the, uh, the open tag module closed tag, uh, string, you're never going to refer to it as a pointer or you'll get a pointer to it, but you're going to refer to it as, and pass it around as an index into these linked, linked pools. And so there's a link, there's a set of static ones that are in the makeQStringData.py that's used in the build process of MicroPython. Um, and those are constant across all your builds of MicroPython. And then past that in the next pool, it's going to be stuff that's, varies between each build depending on which frozen modules you include. So if you use NPY tool to create frozen code generated from your NPY file, uh, it's going to create a strings, a string data structure. And so first you've got an enum that has, uh, basically, you know, that's going to compile down to one, two, three, four, basically a indexing hello cruel world, go hello world.py, sleep time, all of those sorts of things. Then you're going to have hashes for them, like a simple one byte hash, and then a link for each of them. Those are going to be placed into pools. And so on the right hand side there, you see the frozen constant pool, uh, that, uh, has, uh, has those five strings represented in there. There's also going to be a link to the previous pool and also a previous pool size. So your QString indexes are global. They're globally unique. And so you have to look at that previous pool size to know where the indexes start for this pool. All the pools are linked together. The first constant pool starts at zero and it goes to however many constants there are. And then the frozen pool, if it's next, starts at that number plus one, plus two, plus three, plus four, plus five. So, um, and so this is another, this is the, the QString table data, uh, here. So now you've got those, uh, these defined constants for these. And so this is how you refer to the QStrings that you have. These are all your indexes defined as constants. So the question is, how do we find the compiled module in a compiled firmware? Now, if you're lucky, they built it with symbols, right? But we're not going to assume we're lucky here. We're going to assume they stripped out that binary information. We're going to assume that they stripped out the, uh, the symbols. And so for me, whatever, whenever I see somebody in compiled code that I'm reverse engineering, and they're using, uh, an open source module, like if in malware, if they're using OpenSSL or they're using, um, uh, something similar, I'll try to build a copy of that SSL library myself of almost as close of a version as I can get, and as close to the same options as I can figure for theirs, so that I can then use that as sort of a Rosetta Stone for their module that doesn't have symbols, right? Because there's data structures that I want to walk through there. And so the, one of the best things that you can do is build a debug build of MicroPython that has a frozen module in it, not necessarily, you don't have their frozen module, but it has a frozen module in it, and use that to get your bearings in the binary, right? Uh, have it load at the same address and, that sort of thing. And then you can have two copies of Ghidra up, up side by side, and use one to figure out where the data structures are in the other. And so in the debug build, it's called mpFrozenNames. The mpFrozenNames is a list of the frozen modules on the system. In your, um, in your, uh, uh, uh, debug build, you also have the frozen modules themselves, mpFrozenNpyContent. So you've got, um, there's a lot of sort of built-in frozen modules. Uh, you'll see, um, like if you have an Adafruit CircuitPython, uh, device, CircuitPython is based on MicroPython. So, uh, CircuitPython devices will have other frozen modules in them, and you may not necessarily have the source code to them, and they'll be in this list. Uh, uh, I think Lego makes a, uh, a device that has a microcontroller in it that has MicroPython or CircuitPython on it, and they also have some of their own closed source libraries that are, that are in this as well. And so this is easy mode, right? So we found the list of names of modules. We found pointers to the modules themselves, but we don't have the names of frozen names and frozen MPY content in our stripped binary. So we have a stripped binary that we copied from a microcontroller, or we got from an over-the-air update or something like that. We've got to find them in a non-debug build, right? And so the way we can find them, if we, if we can ever get to the same things, then we can start using those C data structures from the C files that these things, that from the source code of MicroPython, the source code of other frozen modules, we can start using those to sort of walk it and figure out what's different. But we've got to find those data structures first. The easiest way to find these two data structures in a non-debug build is to, is to, uh, one of the easiest ways for this is to just eyeball it. You can search for .py and just find sort of the list of constants that have .py, especially if you know the other frozen modules and the other frozen modules are consistent with the standard MicroPython ones. You can compare that list and then whatever's additional on there are other additional frozen MicroPython modules. Another, a little bit more, uh, resilient way of finding that that doesn't depend on you just sort of eyeballing a binary, which I don't mind doing all day, but y'all might, uh, is to find it as a code reference. And so there's a function that uses that list called mpfindFrozenModule and chances are it's going to build in roughly the same location in your debug build as in your, uh, right here. So you have this move, load, uh, this move, load, store combination here using this, uh, address. That address is the address to the mpFrozenNames. To find the frozen module content, there's all, there, you can't really eyeball it because it's all binary content. Uh, but there's, uh, indirect reference in, in that same mod, in that same function. So if you find those frozen names, eyeballing them, you can do a cross reference in Ghidra to walk back to where mpfindFrozenModule is and say, okay, that matches up with the debug build. Now, later on in that function, there's a bit of code that looks like this. This is a reference to the frozen MPY content. And so now we have pointers to our mod, to the, to the base data structures of our modules. So from here, it should be fairly simple work, just sort of working through those structures and pulling it out. And what we want to do is we want to recreate the hex of that original MPY file so that the rest of the work can be done with MPY tool. The header for the MPY file is, is, uh, going to be the same. Usually you can just take that from any of them and it's not super important as long as you get something that it passes the checks and it goes. It starts with magic letter M, it goes with a major micropython version. You want to have, you can have, so there's a flag in there for, or, or, and you can have it per function, whether it's native or non-native bytecode. So you can have, you can have an MPY module where the actual code of a function is native, say ARM or MIPS or whatever, or, uh, uh, byte, like not bytecode, machine code, right? Now for my money, that would be a lot easier because I can just, if I get a pointer to that, like Gaedra will, will decom, disassemble and decompile that for me. And I'm, and I'm off to the races. I don't have to interpret bytecode. So we're going with what I think is the harder example is if it's actual Python bytecode there. And then, um, there's a data type that comes up frequently in this called a variably in, a variably encoded unsigned integer, a VUINT. And this main, I don't know, maybe this is more common in microcontrollers than, than I know, but, uh, but I had to take a close look at this. And basically this is a variable length integer that for each byte, the lower seven bits is, uh, is part of the integer. And if there are more bits, then the eighth bit is set. And so if the eighth bit is set, then, you know, okay, I got to read another seven bits from the next byte and so on and so forth. And it can be arbitrarily long, right? And, and have a represent an arbitrarily large number, however much makes sense on your microcontroller. And so this is a data type that, that MicroPython uses in a lot of its data structures. And it can be a little bit of a mind bender to, to work with. So in the hello world dot mpy, we have a number of the, the intern strings that we want to have in there. Uh, and we'll see in there, we only, we only store the actual string data for strings that aren't already in the constant pool. So if something's already built into MicroPython, we don't redefine that string. We just make a reference to it. And so when we're creating our mpy file, we have to be mindful of which, which strings are new, essentially, which strings are what pool they come from. So frozen module key strings get mixed together in, um, in a, in a, in a mpy key string frozen constant pool, right? And so that's one of a few different pools in there that are all in a linked list where across the linked list, there's unique indexes for each string, right? So, um, so to find, to find that pool, the easiest thing to do is to go through, if you can find the main function, which you'd have if you're new to reverse engineering, maybe the tough part, but if you can kind of trace through the very beginnings of execution of that binary, if you can find main, there's mpy init and then key string init. And in the first four instructions in there, there is a reference to the key string frozen constant pool. Uh, you can search for a string that you know is part of that module. Like if you've just run strings on the binary, you'll have seen some of it and you can just do cross, cross references back from that if you really want to. So, so if we're going to parse these pools, we got to look at the data type for it. So a pool has a previous pointer to the previous pool in this linked list of pools. Uh, you can move backwards in the pools, but not forwards. And so, uh, that's why that first, uh, those first instructions in that key string init refer to the frozen constant pool because that's going to be the last one probably. Uh, there's a total previous length that you use to figure out where the indexes start in this pool. Uh, there's a few other fields that don't make a whole lot of difference, but at the end you have a list of hash values for the strings. Uh, you have a list of lengths for the strings, and then you have a list of the data, right? And so the string data is just going to be every string catenated together solidly with nothing in between because that lengths field in the previous, uh, the previous pointer or that, that list will tell you the lengths of each of them. And so you have to parse both of those arrays together to figure out, uh, where, what each string is. So with, uh, the previous pool is, the previous pool to the frozen pool is the npq string constant pool. The total previous length, uh, in our example is 3c2, so that's where the indexes start for the frozen modules. So any q string index, uh, greater than, so any q string greater than 962 is going to be in our frozen pool, which means that when we recreate our mpy, we're going to have to include that data into our mpy. Uh, anything less than that, we can just include the number and not re-encode the string. And so there's our list of indexes, and so there's a constant string, q string table data, uh, for hello world that you can locate through there, and that's the indexes. And so that first one, uh, uh, that first one, since it's greater than 962, we're going to have to encode that string hello world.py into our mpy file. But 7, which is just like the open tag module close tag, is already in the micropython binary, so we just include 7 and we don't re-encode it. And so this is how it looks when we re-encode it. Uh, this is, so we've already written the header, which is those first handful of bytes. The highlighted portion is the string table. Uh, there's a vunt where basically it defines whether or not it's a static entry or one that's defined in this mpy. So are we providing an index or are we providing a new string? And then the string follows. And that's why you see in that dump, you see, uh, the string data for the new strings, but not the built-in strings. So the next thing that you have to do is to, uh, build the object table. Now this is a more complex data structure, and especially as you get further from hello world, this is going to get more and more complicated. The more they're going to, the more they're using, uh, Python objects, the, the, the harder this part's going to become. But you can, like, follow through and, uh, and recreate these as well. Copy, really what you can do is you can copy these almost straight out of memory and put them into your binary and it'll just work without you necessarily having to understand them at first. Then once you get this thing fully recreated, you can load it into that Unix MicroPython interpreter and, uh, and start probing those objects from the REPL, which is much easier. And then finally, the byte code. So, oh, um, there's a format that for this code that we have to generate. If you look in mpytool.py's code, there's a function called read raw code that sort of hints to you as to how we need to build this byte code so that it can read it. Um, so the pointer to the code is the third field of that module, and so you see the frozen module, hello world there, and you see the QString table, the object table, and then you see the pointer to the first element of code, and that's for the prototype function for this object, right? And so each, each function, each, sorry, each piece of byte code can have children. So the prototype for this module is going to have a child of the go function that's inside of this module. And so it's going to contiguous, or continuously rather, or parse these elements of code, see whether they have children or not, and recursively follow down. And once you've parsed everything that doesn't have children, then you can walk back up that recursion and you've parsed all the byte code out. And so on the left there, you see the byte code for, um, for the, for the constructor, and on the right you see the byte code for the go function, which prints hello world in a loop, basically. And so one is the child of the other, essentially. So reconstructing this, uh, there are VUints for the kind, the length, and whether or not the code has children. So when we're putting this into our MPY binary, it needs to know how to reconstruct this into memory in a useful way for the interpreter. And so it's using those VUints to, uh, to do this. And so there's a kind, whether it's byte code or native code. Again, these things can be compiled down to where it's native ARM code for a function. And like I said, if that's the case, if you see something encoded like that, just, just drop your cursor and Ghidra or Idapro on that, hit disassemble, and you're off to the races, right? You can, you can read what it's doing a little bit easier. But if, if it's not, it's just, if it's byte code, Ghidra doesn't have a decoder for this, unless you want to write one. I didn't want to, uh, uh, uh, Karo back there probably will. Oh, uh, uh, and, uh, but, uh, but if you don't want to write a module to, to, to interpret this byte code, uh, you're, you're going to be left to pulling it out and dropping it in this file so the MPY tool can do this for us. Uh, the third, the third bit, is there a child for this block or not, right? And so that makes it recursively go through and read more code. So the one big problem with this, and, uh, I wanted to write a tool that would just sort of walk through a binary and do this, uh, but it's actually tricky to do because the length of the code is not referenced anywhere, right? The length of the code is defined by the fact that the code never exists, never steps outside of the bounds of its memory locations. So there's no length, it just starts execution there, and it'll just keep going as long as there's code, and as long as it doesn't return, and as long as it's looping around, it'll just sort of loop in that space. So there's no defined length for it, which, I don't know, maybe you could figure out a problem there, maybe you could exploit that in some way. But there's no length, and so it's hard in an automated fashion without parsing the byte code to know the length of it. And so you may have to eyeball that part of it. Or parse the byte code yourself, kind of trial and error. Each block of code is filed recursively by its own children. And so here you see in the first screenshot, we're encoding those integers and then plopping in the byte code for the constructor for the module. And then next, it has a child of the go function, and we go and parse that out, we put the vunts for it in there, and then we put the byte code in for the go function. Once you think you've created, and at this point, like if you take these slides and you go back, you'll see that this is bit for bit identical to the original mpy file for the hello world.mpy. We can use my Unix port to examine this. So we can load up the Unix port of MicroPython, import that mpy file, start looking at the objects, start looking at the modules, do the dict function to see what functions are available in there. We can call them. There is a tracing tool in, actually this is not, the tracing tool is in the next slide. This is another example that you can just sort of eyeball on your own of a, of a, this, this code right here will make a little light show on all the GPIO pins of a, of a, of a Pico. Basically just starts strobing all the, the, the GPIO in a pattern. If you have a dev board that has LEDs on all the pins, it'll do a little neat thing for you. That's the code that, this is the, this is the code that does this, but since it's doing GPIO, it won't work on the Unix MicroPython because it's doing like the pin function and stuff like that. You don't have GPIO on the Unix version of Micro, of MicroPython. So what you need to do is like if, if the code you pull out uses a function that's not there, you're going to have to implement some sort of stand, stand in there. And so then you can run it in the Unix port as long as you have those functions available. You can build MicroPython with SysSetTrace where you get a trace of execution. It's not quite what you'd expect. It's not a very detailed trace. It basically tells you which portion of the bytecode is executing in a very, in a very non-granular fashion. It just basically tells you which function is executing when, but you have to build, you have to define this when you're building your MicroPython binary or your MicroPython Unix port. The, the bytecode itself, this is the Hello World bytecode. Basically you're loading a global object of print, the print function. You're loading the Hello Cruel World string. You're calling the function. You pop the string off the top of the stack. You load the global time module. You load the method sleep from it. You load a constant integer of five because you want to wait for five seconds. You sleep for five seconds by calling the method. You pop the top off of that and then you jump back 17 bytes. And then you loop around and you do it again. And so that's the very basics of the language here. If you want to learn this bytecode, if you really want to take the time to step through bytecode of this and not just sort of interactively do it, you'll want to read through the MPY tool opcode class. And also, and in class in terms of like the class definition, not like a class that you sit down and learn. There's a vm.c in MicroPython that has the vm interpreter for this bytecode in there that you can read as well. This is not compatible with CPython, but familiarity with that would help. If you read through some Python bytecode tutorials, you'll understand what this is going. Conclusions on this, I'd really rather be reversing compiled C than this. Using MicroPython and creating bytecode out of your functions and stuff is probably almost a better obfuscation of your code than compiling a C firmware for your microcontroller. It's just annoying to try to read through this yourself. If you're more used to reading ARM assembly, if you're more used to reading decompiled C, it's doable though. And if you're really wanting to mess around with a device that does this, it's doable. These frozen modules are a great way to include project-specific stuff. Really the last stage of your development and deployment of a MicroPython firmware should be to put as many of your modules into this form as possible because it's just going to save memory and execution time. This is not a way to hide or obfuscate code or secrets though. Don't use it for that, especially now that this talk is out and this room of people know how to do it, right? So don't use this to go screw around with other people's CTFs in ways that ruin the fun for other people. But if you're like me and you're fun, you make your own fun, right? You don't really follow the rules on the CTF. You rather just play around with it and not even score any points. This is fun for that. It's only as well protected as access to your firmware. And so if you can dump from Flash, if you can dump from the REPL, if you can grab over the air updates for things, you can get at this stuff. So it's not a layer of protection. And you could probably automate this extraction process, but it's a bit tricky to figure out the lengths of some of those data structures too. So one thing that you should do if you are interested in this sort of stuff, if you like the idea of learning how to use Ghidra to step through all these data structures, if you want to learn how to sort of navigate around code in Ghidra, there's a great book from No Starch Press called The Ghidra Book, appropriately named, by Karen Antz and Chris Eagle. Karen Antz is in our audience here right now. She's been giving me the eye to mention this the whole time. She's actually going to be at the No Starch booth this afternoon doing a book signing. I want to say 3.30? 3.30. She's going to be at the booth over there at No Starch doing a book signing. Go buy that book and get her autograph. And she knows everything about MicroPython, frozen modules as well. Divert any questions about this, talk to her. So, no. Ask me the things. And so with that, I'm going to close this off. I appreciate y'all coming to this instead of Pawnee Awards, however poor of a choice that might have been. And I look forward to interacting with y'all. Thank you.