Hey, guys. Thank you for coming to my talk. My name is Ryan O'Neill. My talk, Revolutionizing Elf Binary Patching with Shiva. So let me take a moment just to introduce myself. My name is Ryan O'Neill. I'm also the author of the book Learning Linux Binary Analysis, which is a book on elf hacking and related topics. I've published in a lot of journals over the years, different hacker journals, FRAC, POCR, GTFO, VX7, TempOut. And I'm also the founder of bitlackies.org, which is where I published a lot of my independent research for many years up until about 2019, still up. I'm also the founder of Arcana Research, computer security research and development. This is actually this website where you can read more about Shiva, arcanaresearch.io. And arcanatechnologies.io, which is a Linux threat detection technology for detecting various types of threats within elf artifacts. Before I get too deep into the talk, I want to take a moment to talk about the DARPA AMP program, since Shiva was in part born out of this program. This is a really unique program created by Sergey Bratis. It's the Assured Micropatching Program by DARPA. And this program is really cool. It's all about, you know, taking some brilliant, you know, creative minds who want to raise the state of the art in reverse engineering technologies and elf binary patching technologies. There's also an effort to be able to do formal verification of these patches. So after the patch is installed, can it be called safe? So there's a number of different facets to the project. And throughout the number of different performers, there's quite a number of CPU architectures that are being targeted right now. Although I'm only specifically talking about my project today. But just the AMP program as a whole is really cool. So what is Shiva? So Shiva is a state of the art binary patching solution for elf. It's essentially a custom dynamic linker that's been highly specialized to load and relocate object files and transform the program at runtime. I've written a lot of linkers and loaders over the years, from computer viruses to kernel root kits to all kinds of things, binary protectors that require different types of custom linkers and loaders. And this is definitely the pinnacle of my research after about 16 or 17 years of elf binary hacking. So what makes Shiva special? So Shiva has innovated quite a number of different new linking concepts. So the elf ABI has been extended to support more advanced linking and relocation operations that allow for program transformation at runtime. And Shiva's, you know, I'm not going to go into too much detail about Shiva, but it's a one of its primary goals is to make patching binaries approachable. Meaning you can do it in C, almost just like you'd program anything else. Trying to bridge the gap between the developer and the reverse engineer. Because patching binaries is often clunky and difficult. Shiva allows developers to write nuanced patches with quite a bit of ease. So how can Shiva help you? So if you're an organization or a company, generally speaking, there's usually legacy software that no longer has source code. And a bug that's going to be a problem is the fact that it's not going to fix it. So if a bug comes up, whether it's a security vulnerability or some kind of other bug, how does one fix that if there's no longer source code? And oftentimes, you know, a team of people might get together to try to fix a simple bug and it's clunky. And there's no, there's no, like, development workflow for that that's really been put into our industry yet. So from a hacker's perspective, Shiva can do all kinds of things as well. It's an advanced instrumentation engine. You can use it to create black box fuzzing harnesses. I used it to create black box fuzzing harnesses. I used it to fuzz the dynamic linker. One dynamic linker fuzzing another dynamic linker. But I can't really get through a lot of the stuff I want to get through today. So I'm going to blast through these slides, unfortunately, a little quicker than I might want. So the origins of Shiva. About three and a half, four years ago, I had an itch to write a custom elf interpreter. Everybody here know what an elf interpreter is? Basically, usually the dynamic linker. But writing an elf interpreter is an interesting thought because, well, there's a lot of innovative concepts that can be, you know, you can write an elf interpreter, but you can't write an elf interpreter without a dynamic linker. And so this led to a concept called interpreter chaining, where I chained two dynamic linkers together into the same process image, my custom dynamic linker, which was evil, and then the real dynamic linker. My evil dynamic linker loaded a modular relocatable object, virus, into memory. And so this was actually my first implementation of a custom dynamic linker for elf or a custom elf interpreter. And you can actually read that algorithm for interpreter chaining and the whole virus and everything is published in temp out issue two, article six there. And this, you know, modular elf virus loader interpreter ultimately loaded or ultimately morphed into the first version of Shiva, which was originally for x8664. I actually gave a talk about it a year ago, but it's a completely different beast than what I'm talking about today. But just giving you a little history there. And so the original Shiva was for loading elf micro programs. So it was a custom algorithm that allowed you to load elf micro programs to implement security features and such into the process address space, like control flow integrity hardening or whatever. You could do a lot with it. It was an instrumentation dream toy for a reverse engineer. And that's still available. I actually just open sourced that today. We're going to get into this in a moment here. But the current version of Shiva is Shiva alpha version 0.11, and it was forked off that original version. So just to clarify. And it was heavily modified to meet the requirements of the DARPA AMP program, specifically NASA. And so but with that said, it's I'm not going to get too far ahead, actually. So let me stick with the slide. So rewind 25 years. Who was originally trying to patch elf binaries? And for what purpose? And this brings us to the awesome era of early Unix virus research. And Silvio Caesar, who is a good friend of mine and mentor, is a scientist. He published this research, you know, through about 97 to 99, this very early elf research. Unix and elf parasites in 1998 and a number of other papers I could list. But you have to understand at the time this was super esoteric stuff. Nobody was doing this in 98. Who the hell knew what elf was? An elf? But I saw that paper when I was 15, and it definitely enamored me, compelled me into wanting to work on that stuff. But, yeah, just a ton of other research. It's really the same thing as elf instrumentation. Coming from somebody who has written a number of computer viruses for elf, the programmatic techniques that go into it are very much the same as instrumenting a binary with any other code. It doesn't matter if it's a parasite or if it's security code. The point is you need to make room within the elf binary to be able to use the binary. Often times the techniques aren't trivial for restructuring a binary, depending on the technique, you know, text segment padding infection, reverse text infection, so all kinds of ways. And then that code has to be relinked in some way, whether it's through PLT hooks, inline hooks, relocation poisoning or some other means. Also, we know that, of course, you know, hackers like to inject viruses into memory. So P-trace is often used. And it's often used for just instrumentation in general. You look at many different techniques, you know, you can look at technologies out there, Dynamo Rio, a bunch of them use P-trace. I've used P-trace a bunch to instrument. But on the same token, you know, security technologies use this as well for injecting patches into memory or instrumenting memory like Valgrind does. In a way, Shiva is kind of similar probably to Valgrind in how it works in terms of the just in time kind of aspect of it. Basically all the elf research was coming out of the underground scene. In the early, in the late 90s and early 2000s, there was a lot of research that was coming out of the 2000s. There were a few major players in that area. One of them was the GRUC. The GRUC designed the user land exec implementation, which is a user land function that can execute another program. So you don't have to use the exec V system call and trap into the kernel. One user land program can execute another user land program. It has all kinds of insane uses. He was using it for anti forensics. I've used it for binary protectors and now I'm using it for Shiva because it's a loader. And so very, very important research by the GRUC. And it's a very, very cool project. And he did other cool stuff, too. And of course we have Mayhem, who was the chief editor of frack around the time. And he had this incredible project, the elf reverse engineering software interface, which I really can't say enough about. Truly profound work, especially in 2002. Just the sheer level of innovation and work that went into it is impressive. And there's a number of other people that worked with Mayhem on that project, other aspects of it. But very brilliant work and very informative. And I think that's what we're going to talk about in a little bit. And then another really influential piece of work that came from the early underground, probably 99, was Silvio's he wrote a version of insmod that could install a kernel module through dev KMM by handling all the relocations and stuff manually. It was the first implementation I'd seen of a hacker writing a linker or a loader at the time. But it really seemed very profound to me. And so that's some really these are some real formative pieces of work that definitely inspired me over the years. And there's also some really interesting stuff that's come from the academic space in terms of elf binary patching. Firstly, what comes to mind is Katana, which is a DORF aware hot patching framework for elf. And it was designed by Sergey Bratis and James Oakley, I think it was about 13 years ago. And a couple of really good white papers came out of it. Pebble, I don't know as much about, but I've kind of paid attention to it over the years on GitHub. And it's an elf instrumentation framework. I think it's primarily used for software profiling, but it does some degree of function. So it's kind of a function relocation. And then we have this really great research called Weird Machines in Elf by Rebecca Shapiro and Sergey Bratis. And this was, I think there was even a talk at DEF CON maybe in 2011. But it was all about using the dynamic linkers relocation computations as a Turing complete machine. So you can program the dynamic linker to do a lot. And just through metadata, you know, relocations, whatever. And this is something Shiva does a lot. And so these are just, yeah, this is great stuff here. Yeah. So take a look at some of the research tied to it. So, you know, we could say elf binary instrumentation is a double edged sword. There's a lot to be learned from the hackers and the underground community who were first putting this information out before 25 years later rolls around and here we are needing to design advanced binary patching technologies. And Shiva has done that, but it's very much based in knowledge that I've had preexisting, you know, in the underground scene. And so we're like, okay, well, binary patching is pretty old. It goes all to the the way back to computer viruses. But really, it goes back to the beginning of Elf, which became the Unix standard in 1995 executable format for Unix, Linux. And, you know, having been somebody who's done a lot of Elf binary hacking over the years, I put a lot of thought into this project. And I started, you know, looking at Elf and saying, really, it's already equipped mostly with what it needs. It's already equipped to do a lot of patching just with its own relocation symbol information. And I started looking at, you know, say, LDLinux.so. It's already a JIT micro patching engine. It does simple patches, but it's still a hot patching system. And then we have BinLD. LD links relocatable objects into an executable using really granular Elf relocation metadata. And so just kind of looking and meditating on these things, how can I take what's already done so beautifully and well and extrapolate on that? Yeah. To make an advanced binary patching system that allows people to patch binaries in C. So I started to realize, yeah, there's a lot of power in writing an interpreter and what you can do with it. Started out as writing a modular virus just to be, you know, cool and creative. But I knew it was going to extrapolate into something a little bit more formal. And so you guys, most of you are probably familiar with Elf. The PT insert segment holds the path to LDLinux.so or the dynamic linker. That gets replaced with lib Shiva. And the interpreter generally speaking sets up the finer details of the process image. And the interpreter has instrumentation precedence because it runs before even the real dynamic linker. So another strong aspect of it is, you know, patching memory with P trace is slow because you're in another process and there's a lot of context switching and things that happen. If the patching, you know, engine is in the same address space of the program it's patching, it's much faster. And so, you know, if you're in a different place, you're going to have to do a lot of things. So this is something exploring a different time and more depth. But essentially I started thinking, well, an Elf relocatable objects have really great metadata, enough relocation information to build a process image out of. And so really Shiva is somewhat of a hybrid between LD and LDLinux.so. So it draws wisdom from both linkers. You know, it's flexible, it's modular, like the dynamic linker, LDLinux.so, but it has a nuance of LD because it uses that really granular relocation information that's in those Elf object files. So to kind of further just show how it fits into the existing Elf linking components, you've got LD, it's an Elf linker. You've got LDLinux.so, that's a linker and a loader because it loads shared libraries and knows how to load executables. And then you have LibShiva, which is an Elf linker, loader, and a transformer. And we're going to get more into transformation, transforms, how they fit on top of relocations a little bit later. But or maybe right now. So Shiva's innovation in linking concepts. Shiva, just in the research and development of it, you know, I created a number of new techniques that are necessary to kind of bring this all together. One of them I touched on briefly, interpreter chaining, Elf transforms. In fact, I'm not even going to go through the whole list right now. But each one of these is something that's either brand new or being used in a new way. Generally, this is all pretty new concepts that fit really nicely into the existing Elf ABI. We're going to talk deeper about them. Shiva's built on top of LibElf master. It's a library I wrote in like 2018. It forensically reconstructs broken binaries under the hood. So if a binary has no section headers or symbol tables, it will reconstruct those based on, you know, the EH frame, the dynamic segment, other things. It's a very, very, very well-known thing. And we create the symbol table internally. So even though Shiva's symbolically driven, it can still work on stripped binaries because of that. So I thought that might be a question that comes up. So let's take a look at Shiva's Elf linking workflow. So on the very left, we have just, you know, two object files, main.o and foo.o being linked into a program, my program. In the middle, we see that that program is now being executed and it has the LD Linux interpreter loading libc.so into memory. That's just, you know, the job. That's the general kind of linking workflow. You move over to the very far right, and there's a diagram illustrating that Shiva and LD Linux.so are cooperating together in the same address space to transform the program with both the patch and the shared libraries. So the standard Elf dynamic linking workflow essentially looks like this. You've got the kernel is trying to execute a program called test. But first it loads test interpreter, which is LD Linux.so, passes control to it. The dynamic linker loads libc or whatever it's loading, and then passes control to bin test. Actually passes control to the underscore start function. With linker chaining, where you're linking multiple dynamic linkers into the same address space, you have both lib Shiva and LD Linux.so cooperating together. The kernel loads Shiva, since that's the interpreter, passes control to it. Shiva loads, links, and transforms this patch, and then it actually user land execs, essentially, LD Linux.so and libc.so. And then it actually loads the memory, maps all the segments into memory, passes control to the real dynamic linker, just like the kernel would. The dynamic linker then loads its shared libraries, and then finally passes control to test. That's actually a simple workflow. We'll get deeper later. But I mentioned that Elf patches are compiled as just regular relocatable objects. You can use clang or gcc. In the future I plan to write a compiler wrapper. But essentially, you know, relocatable objects are great for patches. They contain rich symbolic metadata for both relocations, all the symbol names. And I have extended some of it. But generally speaking, the object files are really nice. You have to build them with a large code model. That way an internal got is used for absolute addresses so that you don't run into a situation where you're further than four gigabytes away from the executable that you need to relink with. So there's that. But I definitely recommend checking out the Shiva module loader function in Shiva underscore module dot C. It's definitely where all the, my most probably interesting code is. Also, you know, after an Elf relocatable object is, so an Elf relocatable object basically gets loaded into memory. Shiva creates a text segment, data segment, BSS for all the patch information, all the sections are put in their appropriate places. All the relocations for the patches are handled. But then the executable itself needs to be relinked to use the new patch code and data. Well, that's a little difficult because Elf executables don't have relocation data that describe how to relocate a patch. You just need to relocate their own text section. They have a little bit of dynamic linking information, but that's different. They don't have the information that was in the original Elf object files because it's not needed anymore. It would be nice. But what Shiva does is it generates a control flow graph and based off that it generates relocations on the fly for the Elf executable because there's a lot of relinking and reencoding of instructions that has to be done if you splice new code in, for instance. All the offsets change, everything changes. And so we're able to handle all that pretty easily. Pretty nicely, fluently. So I mentioned briefly Shiva's user land exec functionality. And this is just used kind of like any interpreter with Python. You can call Python directly. Same with Shiva. This is really good for testing a patch. Let's say you want to make no metadata modifications to the binary, just leave the binary completely untouched, you just specify the patch object in the Shiva module path environment variable, and then you run Shiva and the program you're trying to execute. And it will load and you can see how it works. And if you and install the patches all at run time. If you want the program to be patched every time you run it without having to execute Shiva, you have to use the Shiva pre-linker. We'll get into that in a minute. But it updates the PT interp segment with the correct interpreter and also adds a new dynamic segment, a couple of other little things. So can everybody see here the requesting program interpreter is lib Shiva in this program instead of LD Linux? So that's just kind of illustrating for you what the program looks like after it's been pre-linked. And then if the dynamic segment here, we can see the last three entries towards the bottom here, Shiva needed. And I don't know why you can't see that. Hold on here. There's like something in front of it there. But that's the base name to the patch object, Shiva needed. So the needed patch objects. The search right here is the search path to where all the object files are stored. Just like with the dynamic linker, they're usually stored in lib. And then it gives the path to the original. So that Shiva knows which path the interpreter is to load and link into memory. Because it will map the dynamic linker into memory once it's done. So I want to talk about elf symbol interposition here for a moment. So is anybody familiar with what that term means, elf symbol interposition? Okay, yeah. So essentially, though, think LD preload. It's where you can overwrite one symbol with another symbol because it has the same name based on the precedence of the object that's loaded. And Shiva, one of its really strong features is that it allows you to rewrite any code and data just by name. You know, as long as there's symbolic data attached to it, any global data, any global functions, even local functions, although it needs about two days of work to do that. But essentially, anything symbolically can be rewritten. It's actually really easy. And so instead of just rewriting functions like with LD preload, you can rewrite anything by name essentially in the executable itself. I want to give just a little example here. I'm going to give you a little example here. If you see, we're running hello. It says hello world. Can you guys see that okay? It's kind of small, but. And then I look at the symbol table and I see there's a string called hello underscore string that lives in the RO data section. And if we, let's say we want to change that program. The program's called hello. And we want to make it so that it prints hello DEFCON 31. So we literally have a very simple patch. We just redefine that constant string by name. We compile it into a L3 locatable object with a large code model. And then on this slide, we're going to show you how it works. So running hello just runs hello world. But if we set the shiva module path to the patch object, and then run shiva on hello, it installs the patch at runtime. But then if you just run it without shiva do is use the Shiva pre-linker. It's called Shiva LD. And it essentially just installs the original interpreter information, the patch metadata such as the location of the patch into the new data segment that it creates in the binary. So the executable code and data isn't changed at all. It's just metadata. So that the new binary uses the correct interpreter path and all that. So we can see we run hello directly now that we pre-linked it and it's printing hello DEFCON 31. So just a simple patch and see. So transformations. I mentioned these earlier. So this is transformations begin where relocations leave off. I think the dynamic linker is just brilliant. It's a brilliant hot patching mechanism. We can learn a lot from it. Why not take it and utilize it for micro patching binaries. Something of that nature. The same concept. Extrapolating on it. So if elf relocations are what are the metadata that describe simple patching operations, then elf transformations would be the metadata that describe complex patching operations. Such as function splicing. Things of that nature. So function splicing is the ability to splice C code into any function at any given point within the function. Fully relocatable code. Fully symbolically rich access to all the shared library symbols, functions. And this is very complicated. There's a lot of relinking. Many, many magical things have to happen under the hood. But the end result is we have these transform macros that developers can use to splice code in and out of a function. So this is just kind of a crude example here. But essentially we have on the left a program that you stir copy. And it's a function called copy string. And let's say we want to modify that function so that it uses stern copy. You know? Make sure the string, by the way, is null terminated. So on the left you can see the code that's being removed from 7BC down to 7C8. Which will make our stopping address 7CC, by the way. But we want to splice this code, which is larger, into this little area there. We want to make it look like this on the right. So how would we do that? So this is actually a transformation patch right here. I'll give you an example. So up here we have this macro. Shiva T splice function. Copy string. This is the offset, 7BC to 7CC. Now these three lines of code are pretty simple. The first line, because the argument stored in the X0 register, because it's ARM, we create a source pointer variable, because it's the argument of the function copy string. And then the destination buffer was at base pointer plus 32. So Shiva gives you macros to access live variables and registers as needed. And then it just does stern copy. This actually compiles into an object file that looks like this. And I unfortunately don't have all the time I'd like to go on that tangent. But generally speaking, in the text section here, we have this function. Shiva splice FN name copy string. That tells Shiva, okay, this function right here is actually code that's going to be spliced into a function called copy string. By the way, it won't copy the procedure prolog and epilog. That's not splice code. But ARM doesn't respect the naked attribute, apparently. So overflow crashes. So this is a program called overflow. It's the one that I showed you. It's vulnerable. It's got stir copy. We can see that when we pass it four A's, it works. When we pass it like over 16 A's, it crashes. So we prelink our patch. This one I showed you right here. We compile into a relocatable object. Prelink it to the vulnerable program overflow. And then we run overflow. And we can see that it works. It's not crashing anymore. That's because it's using stern copy and properly null terminating the string. But just showing how ‑‑ that's a very simple example. You can splice into any function. That's just to make it palatable in a talk. So spliceable code has some interesting characteristics. I kind of covered some of them. It's fully relocatable, a very rich symbolic access with natural C development. There's no limit or size to the amount of code you can splice into an existing function. And, yeah, I mean, you can ‑‑ and then, of course, there's massive amount of code that you can splice into an existing function. And then there's a lot of macros for gaining access to the live variables and registers on the stack and whatnot. So confluent linking technology. So this is a terminology I've kind of coined, which just means two dynamic linkers working together coherently within one process image to build, transform, and relink the program at run time. And there are a lot of cases ‑‑ so there's a couple new things here. Cross relocations. This is actually where one dynamic linker relies on another dynamic linker to solve its own relocations. So this is where one dynamic linker relies on another dynamic linker to solve its own relocation. And so an example of this is let's say you write a patch that has a new BSS variable. It's overwriting another BSS variable in the original program. This is the new version of the variable that should be used. Maybe you had to extend a buffer size or something. Those BSS variables are often accessed indirectly through the got. There's a relative relocation, at least in PI executables, that fixes up the got to the correct BSS address. So when she ‑‑ when somebody has a patch with a new BSS variable, for instance, they will ‑‑ sorry, I'm looking at the time here. They will ‑‑ Shiva will instruct the other dynamic linker to essentially patch it by modifying the relocation metadata in memory. So you can basically tell the dynamic linker to do whatever you want. You give it a script. The script is the ELF sections that ‑‑ and the values in the dynamic segment that are read by the dynamic linker. We also have delayed relocations, which we ‑‑ therefore we have the Shiva post linker, which actually handles some relocations after LD Linux.SO. So Shiva will load, link the patch, pass control to the dynamic linker, and then when the dynamic linker is done, oftentimes it passes control back to a function called Shiva post linker. We actually update the AT entry value in the auxiliary vector, which normally points to the start function of the program, so that it jumps back to the Shiva post linker. The Shiva post linker then finishes handling any delayed relocations and then passes control back to the dynamic linker. Shiva was just made open‑source today. I am excited, grateful to be able to share it with everybody. Please, you know, and there's a user manual. There's quite a bit of documentation. But let's see, what time is it here? So let me go into this demo real quick for you guys, okay? I want to ‑‑ all right. So let me go into this demo real quick for you guys, okay? Let's see. I hope you like Chopin. All righty. So I want to illustrate an example of symbol interposition and how it can be used to rewrite global code and data on the fly with Shiva in a way that's natural for C developers. So let's take a look at this simple program, test food. And for the sake of illustrating this scenario, I'm going to show you the original source code so we can see that main simply calls foo and then prints the return value. Foo prints I am the original foo function and then it prints the value of lucky number. Lucky number is an initialized global variable so it would live in the data section. So let's say we wanted to rewrite this function and also modify this variable. In fact, we actually want to redeclare this variable. Let's take a look over here on the right side of the screen. And this is the actual patch code itself. So as you can see, we've redeclared lucky number as an uninitialized global variable. In Shiva, we call this, you know, redefinition or redeclaration of storage type or storage type redeclaration. And then down here, we have rewritten foo. And this is showing how we can drive our patching through symbolic references. So these symbols exist. Within the target binary. And so we're able to rewrite them using symbol interposition. Now, right here, we set the value of lucky number. It's now initialized to 31337. We print I am the new function foo. We print the value of lucky number. And then right here, we're demonstrating how Shiva patches are able to resolve shared library functions that don't already have a PLT entry in the executable that we're patching. And so right here, we're calling system to cat this shiva.ancy file. And then we return dead beef. So we have rewritten foo. And we have redeclared lucky number as an uninitialized variable. So let's say we want to take this patch and we want to compile it. So we would, sorry, we would build it just like a relocatable object with a large code model. Which we have to use no pick. And then. So we have a relocatable object now. You can see the relocations in it. Symbol table. And if we want to install this patch, there's two ways to do it. So firstly, in many cases, we just want to try the patch out or just test it once without making any modification at all to the target binary. And so test first. Test foo without a patch. And now test foo with a patch. We specify the shiva module path environment variable. Export it. And then we simply invoke shiva directly. And now it runs the patch version. So it has been, the executable has been relinked in memory to use the code and data specified in our patch. Prince, I am the new function free. It then prints 31337 is the lucky number. It prints the shiva ANSI banner. And then prints the return value of dead beef. Now if we wanted to install this patch permanently, we would have to use the shiva prelinker. Which installs some metadata such as the path to shiva into the interp segment. And it updates the dynamic segment of the executable and adds a few new entries. So let's take a look at that. Let me clear the screen. Shiva LD works like this. And so give an example. Dash E is the executable which is test foo. The patch base name is foopatch.o. The interpreter path is lib shiva. And the search path is opt shiva modules. And then we will rename it the same name. So if we were to look at the program segments of test foo. We can see that lib shiva is now the interpreter. We also see there is an extra load segment. And that is to make room for the new dynamic segment. So let's take a look at the dynamic segment. How it has been modified. So the dynamic segment is actually the same. Except it has three new entries at the bottom here. Which readelf hasn't been modified to print what these are. But this is the addresses to the patch base name. The address to the patch search path. And then the address to the path of the original interpreter. Which is ldlinux.so And we also have to move the patch. Or copy the patch. Into the opt shiva modules directory. Because that is the search path that we specified. So in any case. Now when we run test foo. It is patched every single time. Because of that metadata that has been installed. The only difference between test foo now and before. Is that the dynamic segment has been updated. And the ptinterf segment has been updated. And so. Another neat little feature. Is if you call shiva directly again. With the dash u flag on test foo. It will actually run test foo. And it will run it without installing all the patches. So that is kind of a neat feature. And next we are going to look at. Transformations with function splicing. Thank you. There is more. Thank you. Okay so I am going to try to demonstrate. Elf transformations as concisely as I can. In this example. With a program called testprog. So let's take a quick look at the original source code. So we have this function foo here. Foo is called down here in main. And foo says. If this first argument num is equal to 7. Then go to done. Otherwise. Copy banner. Which is this const pointer to this string elfmaster. Over into global buff. Global buff is a bss buffer. And then it prints the value of this argument string. And so. What we want to do here is actually overwrite this function. Called printf. With some code that first checks to see if str is equal to null. And if it is not. Then it will print it. And then also. We want our code. Our patch code. To print the value of global buff. And so. Let's take a look here. There is a number of things happening in this patch. So we are actually going to start at the bottom. So firstly. Over here on the left. In the original source. We have bar. And in our patch code. We rewrite bar. As we can see. It adds the value of. Two global variables. That were added in this patch. This data val. It adds the value of. The variables together. And then prints the sum. And then up here. So bar is being completely rewritten. With symbol interposition. And then moving up here. We have the actual. Splice code. The splice patch. This is how. Transformations work. When developing shiva patches. That need to splice code. Into an existing function. And so. This macro right here is used. So we are splicing into the function foo. The. Batch code. The address to start patching at. Is 818. And the stop address. Is. 828. And so. Coming down into the actual. Splice code. Let's start right here. We have if str is not equal to null. Then print the string. And if you notice. We are using fprintf. Instead of printf. Which was in the original program. And this is again. Just illustrating. Strong global symbol resolution. And then after that. We use fprintf. To print the value. Of global variables. So we have global. Buff. Which illustrates. Our patch. Ability to. Use the extern. Keyword. So you were using the extern. Keyword. To get a hold of global. Buff. Which is. A global variable. From the program. That we are patching. And so. After that. We call. Bar. And this is illustrating. How our patch code. Will link. To the new function. Bar. Instead of the original function. Bar. And when main. Calls. Bar. It will also link to our new function. So. Back up to this. Transformation. Macro. We want to patch. 818. Let's. Take a quick look. At why. So. We'll look at the program. Assembly. Down here. At function. Foo. We're going to be patching. From here. To here. Actually. To right here. So our start address. Is 818. And the last. Address. That we patch. Is 824. Which makes our stop address. 828. And. 828. Is the. After it. Will be shifted forward. As needed. Based on the size. Of the code being spliced in. And in our case. We're splicing. A larger amount of code in. To. Let's just. Build our patch. Real quickly. And now we have a relocatable object. Called patch. O. These are the relocations. For it. And. If we look at. Use object dump. You can see. This is the splice code. This. Whole function. Right here. And. Is a special symbol name. Called Shiva splice. FN name. And then the function. That's being spliced. Is foo. This directs Shiva. To use the. Function splicing. Capabilities. And so. Shiva will. Splice. All of this. Code in. The procedure prologue. And epilogue. Won't be included. All of this code. Will be. Relocated. And. Transformed. Essentially. It will be. Inserted. And spliced. Into the function foo. Again. Into. This location. Right here. So. We're actually adding. Quite a bit of code. And. So. This will. Rewrite. The entire. Function foo. It will actually be. Rewritten. From scratch. In a different area. In memory. And the reason that. In the source code. I included this. If num. Is equal to seven. Go to. Done. Is to illustrate. How. It will have to be. The assembly code. For that. Will have to be. Relinked. In the binary. Or. In memory. Once our patch code. Is inserted. Here. Because the patch code. Is much larger. And so. For this to jump down. To done. The offsets. Will change. So this. Also. Patching this program. Also illustrates. Shiva's ability. To. Relink. The. Executable. As needed. When the patch code. Extends the size. Of the function. And. This works. By Shiva. Generating. On the fly. Relocations. For the executable. By looking. At a control. Flow graph. And so. Anyhow. Let's just try. To install. This patch. And. See how. It works. So. Again. Test. Prob. Looks. Like. This. When. We. Run. It. Now. Let's. Run. Execute. Test. Proc. Now. We. See. It's. Working. As. Expected. It. Only. Prints. The. Argument. We. Pass. It. When. We. Actually. Pass. It. In. Argument. See. And. If. We. Don't. Pass. It. In. Argument. Doesn't. And. If. We. Put. Seven. Arguments. It. Jumps. Right. Down. To. Done. And. Doesn't. Print. Doesn't. Do. Any. Of. The. Other. Stuff. That. It. Was. Doing. So. It's. Actually. Working. Exactly. How. We. Modified. The. Program. To. Behave. Now. Again. If. We. Run. Test. Prog. Without. Shiva. Still. Does. The. Same. Old. Behavior. If. Want. To. Link. The. Program. Permanently. Then. We. Use. The. Shiva. Pre. Linker. As. Demonstrated. Before. Shiva. Is. The. Interpreter. Search. Path. Is. Off. Shiva. The. Program. Directly. It. Works. Every. Time. It's. Patched. And. Again. The. Program's. Metadata. Has. Been. Modified. We. See. That. Shiva. Is. The. Interpreter. Etc. So. That. Is. What. Happened. To. Slides. There. So. Just. I. Got. A. Couple. Minutes. Left. Here. Let. Me. Pop. The. Slides. Back. Up. And. Not. Real. Familiar. With. Adobe. But. Whatever. Let's. See. Here. Sorry. I. Don't. Know. Yeah. Let. Me. Good. Idea. That's. Still. That's. Well. There. Really. Wasn't. There's. One. Last. Slide. Here. Give. Me. Just. Um. What's. Control. L. Hmm. Well. Yes. Thank. You. Look. Me. Here. I. Am. Thank. You. Okay. This. Is. Last. Slide. That. I. Would. Like. To. Just. Leave. Up. For. A. Moment. If. So. I. Guess. You. Can. Specify. The. Slide. To. I. Think. It's. Like. Slide. 51. That. I'm. Looking. For. Ah. There. You. Go. Okay. Up. Until. If. Close. Your. Eyes. I. Don't. Want. To. Close. Any. Seizures. All. Right. Thank. You. So. First. I. Just. To. Thank. You. To. My. Son. Jaden. For. Helping. Me. With. The. Video. Editing. It's. Not. My. Strong. Suit. For. The. Demo. Thank. You. Jaden. Appreciate. That. Gamer. Tries. On. YouTube. And. I. Want. To. Thank. You. To. My. Wife. Teresa. O'Neill. For. Being. Such. Powerhouse. Behind. Me. Thank. You. Honey. And. My. Mother. My. Mother. Bought. Me. Every. Book. By. What's. His. Name. Richard. Stevenson. By. The. Time. I. Was. On. It. She. Was. It. To. Help. Me. Get. Educated. On. What. I. Wanted. To. Learn. So. Thanks. Mom. Love. You. And. Thanks. To. My. Son. Mick. For. Being. Here. For. You. Any. Problems. There's. The. The. User. Manual. Still. A. In. Progress. But. It. Gets. Deeper. There's. Also. Some. Design. Specifications. That. Are. In. The. Shiva. Repository. That. They're. A. Behind. Date. But. If. You. Want. To. Learn. More. About. It. Go. To. The. Web. Site. Arcana. Research. I. O. Shiva. And. Feel. Free. To. Reach. Out. To. Me. For. Any. Questions. About. It. And. Thank. You. Grateful. For. Everybody. Being. Present. Is. There. Any. Questions. For. 30. Seconds. You. Got. Three. Seconds.