Latest / CyberCode Academy / Course 33 - Static Analysis for Reverse Engineering | Episode 2: Tool Setup, xAnalyzer Integration, and Database Maintenance
Transcript
- 0:00Speaker 1: Welcome to the deep dive. You know, usually when we
- 0:04Speaker 1: interact with a piece of software, there's this expectation of
- 0:07Speaker 1: a smooth, polished surface.
- 0:10Speaker 2: Right like a sealed black box.
- 0:12Speaker 1: Exactly, you double click an icon and app opens and
- 0:15Speaker 1: it just works. It's clean, it's user friendly, and all
- 0:19Speaker 1: the messy logic is completely hidden away from us, which.
- 0:23Speaker 2: I mean for most of our daily tasks, is exactly
- 0:25Speaker 2: what we want. We need our tools to be predictable.
- 0:28Speaker 2: We want the complexity abstracted away so we can just
- 0:30Speaker 2: you know, write an email or play a game.
- 0:33Speaker 1: Yeah, we don't want to think about the silagon. But
- 0:35Speaker 1: today we are shattering that polished surface. We're going to
- 0:38Speaker 1: figure out how analysts and security researchers actually crack open
- 0:42Speaker 1: compiled software to see how it ticks.
- 0:44Speaker 2: It's a completely different mindset, it really is.
- 0:47Speaker 1: Our mission today is to build a personal software analysis laboratory,
- 0:51Speaker 1: entirely from scratch, right in your mind. We're going to
- 0:53Speaker 1: set up the ultimate digital workbench to analyze code, function
- 0:57Speaker 1: by function and.
- 0:58Speaker 2: All without even needing to look at a screen.
- 1:00Speaker 1: Okay, let's unpack this. If I want to look under
- 1:02Speaker 1: the hood of an application, what exactly do I need
- 1:05Speaker 1: on my workbench.
- 1:06Speaker 2: Well, to truly dissect software, you need two very distinct perspectives.
- 1:11Speaker 2: You need the macro view and the microview.
- 1:14Speaker 1: So big picture in nuts and bolts exactly.
- 1:17Speaker 2: The macroview is handled by something called a portable executable
- 1:21Speaker 2: analyzer or a PE analyzer for sure.
- 1:24Speaker 1: Okay, and what does that actually do? Does it run
- 1:26Speaker 1: the code?
- 1:27Speaker 2: No, it doesn't run the code at all. Instead, it
- 1:29Speaker 2: scans the file and gives you the overarching blueprint. It
- 1:32Speaker 2: tells you what programming language the application was written in,
- 1:36Speaker 2: what compiler translated it, and crucially, if there are any
- 1:39Speaker 2: obvious protections or packers wrapping the code.
- 1:42Speaker 1: Wait, I'm stuck in that last term. What do you
- 1:44Speaker 1: mean by a packer? Is that like a digital shrink wrap?
- 1:47Speaker 2: That is actually a great way to picture it. Imagine
- 1:50Speaker 2: you write a letter, but before you send it, you
- 1:51Speaker 2: can press it, encrypt it, and lock it inside a
- 1:54Speaker 2: heavy metal briefcase. Okay, the post office can't read the letter.
- 1:57Speaker 2: The recipient actually has to use a key to unpack
- 2:00Speaker 2: it into their own memory before they can read it.
- 2:02Speaker 1: Oh. I see, So it's an obfuscation.
- 2:04Speaker 2: Thing, right. Software developers use packers to protect their intellectual
- 2:08Speaker 2: property from piracy, but malur authors use them constantly to
- 2:12Speaker 2: hide malicious code from your antivirus software.
- 2:15Speaker 1: Sneaky.
- 2:16Speaker 2: Yeah, so a PE analyzer spots that briefcase and warns you, hey,
- 2:20Speaker 2: this file is packed.
- 2:21Speaker 1: Okay, So that's the macro view. It's kind of like
- 2:23Speaker 1: inspecting the outside of a lock safe to see who
- 2:26Speaker 1: manufactured it before you, you know, try to crack.
- 2:29Speaker 2: It precisely, but eventually you do have to look inside.
- 2:32Speaker 2: And for the microview, you need a disassembler and a debugger.
- 2:36Speaker 2: This is the tool that actually opens the engine block.
- 2:38Speaker 1: Let's break those down. Disassembler first, sure.
- 2:41Speaker 2: A disassembler translates the raw machine code, literally the ones
- 2:44Speaker 2: and zeros that the processor reads back into assembly language.
- 2:47Speaker 1: Which is the absolute lowest level of human readable code.
- 2:51Speaker 2: Right exactly. And then the debugger part is what gives
- 2:54Speaker 2: you godlike control over the software. Let's you freeze time.
- 2:57Speaker 1: Freeze time.
- 2:58Speaker 2: Yeah, you can pause the execution of the application right
- 3:01Speaker 2: in the middle of a process, step through it one
- 3:04Speaker 2: single instruction at a time, and read the values changing
- 3:08Speaker 2: inside the computer's memory in real time.
- 3:11Speaker 1: Let's pause on that because the concept of freezing time
- 3:13Speaker 1: and running application sounds like absolute science fiction. What is
- 3:17Speaker 1: actually happening to the silicon when I hit pause on
- 3:19Speaker 1: a piece of code.
- 3:20Speaker 2: Well, at a physical level, your CPU is basically a
- 3:24Speaker 2: microscopic clock ticking billions of times a second, blindly executing
- 3:28Speaker 2: whatever instruction is next.
- 3:29Speaker 1: In line, just churning through commands.
- 3:31Speaker 2: Right, So, when you set a break point in a debugger,
- 3:34Speaker 2: the tool secretly swaps out the real instruction at that
- 3:37Speaker 2: specific memory address with a special interrupt code. It's usually
- 3:40Speaker 2: referred to as an i int.
- 3:42Speaker 1: Three instruction an IONT three.
- 3:44Speaker 2: Okay, yeah, And when the CPU hits that interrupt, it
- 3:46Speaker 2: stops what it's doing and essentially says, I need a
- 3:49Speaker 2: human to tell me what to do next. Everything hangs
- 3:52Speaker 2: in suspended animation.
- 3:53Speaker 1: That is incredible, it is.
- 3:55Speaker 2: And while it's paused, you get to inspect the CPU's
- 3:58Speaker 2: internal short term memory slots, which are called registers, to
- 4:02Speaker 2: see exactly what data it was holding at that exact millisecond.
- 4:06Speaker 1: Okay, So before we can start injecting interrupt codes in
- 4:09Speaker 1: freezing time, we have to construct our base camp.
- 4:11Speaker 2: We need our tools, right.
- 4:13Speaker 1: The foundational tool we need for this is a popular
- 4:16Speaker 1: open source disassembler and debugger called by sixty four DBG. Now,
- 4:22Speaker 1: getting this setup relies on portable software, meaning there's no
- 4:25Speaker 1: bloated installer.
- 4:26Speaker 2: You just download a zip file.
- 4:28Speaker 1: Yeah, lightweight zip file. But there's this one thing. The
- 4:30Speaker 1: instructions are incredibly specific about where you put this extracted folder.
- 4:35Speaker 1: They insist you must place it directly in the root
- 4:37Speaker 1: of your sea drive. That's very important, But hold on,
- 4:40Speaker 1: why can't I just leave it in my downloads folder
- 4:42Speaker 1: or I don't know, on my desktop. That seems incredibly nitpicky.
- 4:46Speaker 2: It sounds nitpicky, yeah, but it's actually about how processors
- 4:49Speaker 2: handle map lookups. Moving it to the root of the
- 4:52Speaker 2: sea drive is like dramatically shortening the address on a
- 4:55Speaker 2: piece of mail. Well, if your tool is buried in
- 4:58Speaker 2: say se uses your name downloads extracted folder sixty four dbg,
- 5:04Speaker 2: that's a mouthful exactly. The operating system has to read
- 5:07Speaker 2: and parse that entire complex string of text every single
- 5:11Speaker 2: time it wants to fetch a resource.
- 5:13Speaker 1: And let me guess, these low level tools don't like
- 5:15Speaker 1: long addresses.
- 5:16Speaker 2: They hate them. Deep reverse engineering tools interact directly with
- 5:20Speaker 2: the operating system's kernel long file paths, or even worse
- 5:24Speaker 2: paths with weird spaces and special characters in the folder names. Oh,
- 5:28Speaker 2: like a space in your username right, That can cause
- 5:31Speaker 2: unexpected bugs or permission errors during a really delicate debugging session.
- 5:35Speaker 2: By placing the folder directly at C sixty four dbg,
- 5:38Speaker 2: you give the CPU a clean, one step look up.
- 5:41Speaker 1: You are creating a stable, dedicated operating environment. I like
- 5:45Speaker 1: that analogy. It's like preparing a physical garage. Moving the
- 5:48Speaker 1: folders to the seed drive is like bolting your heavy
- 5:50Speaker 1: machinery to the floor.
- 5:51Speaker 2: That's a great way to put it. You're creating a
- 5:53Speaker 2: permanent home for your tools before bringing in an engine
- 5:55Speaker 2: to dismantle.
- 5:56Speaker 1: Makes total sense. So we've got our by sixty four
- 5:59Speaker 1: dbg sitting cleanly on the sea drive. Inside there's an
- 6:03Speaker 1: executable file. I'd probably just drag a shortcut to the
- 6:06Speaker 1: desktop to keep things accessible definitely. But when you launch it,
- 6:09Speaker 1: the software immediately forces you to make a choice. It
- 6:12Speaker 1: asks if you want to run the thirty two bit
- 6:14Speaker 1: version or the sixty four bit version. Why do we
- 6:16Speaker 1: need two entirely separate versions of the same tool.
- 6:19Speaker 2: Because you have to match your debugger to the architecture
- 6:22Speaker 2: of the software you're trying to analyze a thirty two
- 6:25Speaker 2: bit application and a sixty four bit application speak well
- 6:29Speaker 2: slightly different dialects of machine.
- 6:31Speaker 1: Code, mostly because of memory.
- 6:32Speaker 2: Right, primarily, yeah, because of how they address memory. Think
- 6:36Speaker 2: of memory addresses like physical street addresses. Okay, a thirty
- 6:39Speaker 2: two bit program only has enough address space to comprehend
- 6:42Speaker 2: about four gigabytes of memory. It's internal registers, those short
- 6:47Speaker 2: term memory slots we talked about are physically.
- 6:49Speaker 1: Smaller, whereas a sixty four bit program.
- 6:52Speaker 2: Has vastly larger registers and an address space that is
- 6:55Speaker 2: practically infinite for our current needs.
- 6:57Speaker 1: So they just don't mix.
- 6:58Speaker 2: Right. If you try to force a thirty two bit
- 7:00Speaker 2: debugger to analyze sixty four bit memory addresses, it simply
- 7:04Speaker 2: can't comprehend the numbers. They're too large. So the tool
- 7:07Speaker 2: provides both environments.
- 7:08Speaker 1: Got it. You need the right size wrench for the
- 7:10Speaker 1: right size bolt.
- 7:11Speaker 2: Yep.
- 7:12Speaker 1: So that is our microview tool, our heavy machinery for
- 7:15Speaker 1: the macroview, the PE analyzer. The tool is called Detected
- 7:19Speaker 1: Easy or die.
- 7:20Speaker 2: E, and the setup is nearly identical.
- 7:22Speaker 1: Yeah. You download the portables at file, extract it and
- 7:25Speaker 1: place it right next to your debugger in the root
- 7:27Speaker 1: of the sea drive again, keeping the file paths as
- 7:30Speaker 1: short as possible, and make a desktop shortcut exactly.
- 7:33Speaker 2: Now we have both tools ready on the workbench, but
- 7:36Speaker 2: we have a problem.
- 7:37Speaker 1: We do.
- 7:37Speaker 2: Yeah. If you are to take a target application right now,
- 7:41Speaker 2: say a piece of suspicious malware, and drop it into
- 7:44Speaker 2: the guy's sixty four Dbdreed disassembler, you would hit a massive.
- 7:48Speaker 1: Wall, oh, because of the code.
- 7:49Speaker 2: The screen would fill up with raw assembly code and
- 7:52Speaker 2: it looks like absolute gibberish, right, It's just.
- 7:55Speaker 1: A terrifying wall of cryptic letters and numbers. It'll say
- 7:58Speaker 1: things like PUSA, h EBPMV e b p ESP, JMP
- 8:03Speaker 1: zero X whatever. I know you mentioned assembly is human
- 8:06Speaker 1: readable earlier, but that doesn't look very readable to me.
- 8:09Speaker 1: What do those letters actually mean?
- 8:11Speaker 2: So those letters are called mnemonics. They are three or
- 8:15Speaker 2: four letter abbreviations that represent fundamental actions for the processor commands. Basically,
- 8:20Speaker 2: MV stands for it tells the CPU to move data
- 8:24Speaker 2: from one location to another, POSH tells the CPU to
- 8:28Speaker 2: place data onto a temporary storage area.
- 8:30Speaker 1: Called the stack, and JMP.
- 8:32Speaker 2: JMP stands for jump. It tells the processor to stop
- 8:35Speaker 2: reading straight down the list and leap to a completely
- 8:37Speaker 2: different memory address.
- 8:39Speaker 1: So it does tell you exactly what the CPU is
- 8:41Speaker 1: physically doing.
- 8:42Speaker 2: Yes, but it provides absolutely no context about why it's
- 8:44Speaker 2: doing it. Without context, analyzing a large program is like
- 8:48Speaker 2: trying to read a massive novel where all the character
- 8:50Speaker 2: names and locations have been replaced by random serial numbers.
- 8:53Speaker 1: That sounds miserable.
- 8:55Speaker 2: It is. You might know that serial number four moved
- 8:58Speaker 2: to location B, but we don't know that Alice went
- 9:01Speaker 2: to the bank to figure that out. We desperately need
- 9:04Speaker 2: a translator, which.
- 9:05Speaker 1: Brings us to the most vital addition to our workbench,
- 9:08Speaker 1: a plugin called Analyzer. This is an absolute game changer.
- 9:12Speaker 2: It truly is. Xanalyzer is a specialized plugin for by
- 9:16Speaker 2: sixty four dB driz that perform static code analysis. It
- 9:20Speaker 2: scans that terrifying wall of mnemonics and transforms it. It
- 9:25Speaker 2: cross references the code with known Windows functions and actually
- 9:28Speaker 2: attaches human readable labels to the parameters.
- 9:31Speaker 1: So instead of just seeing a random number being pushed
- 9:33Speaker 1: into memory, you actually see a label pop up that says, oh,
- 9:36Speaker 1: this is a call to create a message box yea,
- 9:38Speaker 1: and here is the exact text it's preparing to.
- 9:40Speaker 2: Display exactly But beyond the text labels. The most powerful
- 9:44Speaker 2: thing x analyzer does.
- 9:45Speaker 1: Is visual right the blocks.
- 9:46Speaker 2: Yeah, when you look at raw assembly, it's just a
- 9:49Speaker 2: flat wall of text. Xanalyzer scans the logic and draws
- 9:52Speaker 2: clear mental boundaries. It groups related lines of code into
- 9:56Speaker 2: distinct visual blocks, and even better, it draws vertical indentation
- 10:00Speaker 2: arrows alongside the text.
- 10:02Speaker 1: Why are those arrows so important? I mean it sounds.
- 10:04Speaker 2: Simple because in assembly, code almost never flows in a
- 10:08Speaker 2: straight line. It constantly evaluates conditions like if the user
- 10:13Speaker 2: entered the correct password, jump to the success memory address.
- 10:16Speaker 2: If not, jump to the error memory address.
- 10:18Speaker 1: Oh okay.
- 10:19Speaker 2: Those visual arrows map out exactly where a jump originates
- 10:22Speaker 2: and exactly where it lands.
- 10:23Speaker 1: It's like having a GPS overlay for the code. Instead
- 10:27Speaker 1: of manually scrolling through thousands of lines trying to find
- 10:30Speaker 1: where a jump took you, you can just follow the
- 10:32Speaker 1: visual arrow I can see how that saves hours of
- 10:35Speaker 1: manual tracing.
- 10:36Speaker 2: If we connect this to the bigger picture, it lets
- 10:38Speaker 2: you see the flow of the program's logic like a
- 10:41Speaker 2: map of a city's one way streets.
- 10:43Speaker 1: So how do we get this brilliant translator into our debugger?
- 10:47Speaker 1: Because we have both a thirty two bit and a
- 10:49Speaker 1: sixty four bit environment. The installation requires a little manual labor.
- 10:53Speaker 2: You have to do it twice.
- 10:54Speaker 1: Right, you download these analyzer plugin files, then you have
- 10:58Speaker 1: to physically place them into the plug folder inside your
- 11:01Speaker 1: by thirty two directory, and then you have to back
- 11:03Speaker 1: out and copy the sixty four bit versions of the
- 11:06Speaker 1: plug in into the plugins folder of the by sixty
- 11:08Speaker 1: four directory.
- 11:09Speaker 2: Which reinforces the concept that you are dealing with two
- 11:12Speaker 2: completely separate machines under the hood.
- 11:14Speaker 1: Exactly. But now that we have our translator installed, we
- 11:17Speaker 1: run into a major problem. If we push this plug
- 11:20Speaker 1: in too hard, it.
- 11:21Speaker 2: Breaks, yes, the secret configuration trap.
- 11:24Speaker 1: Right when you open the settings menu for x Analyzer,
- 11:27Speaker 1: human nature kicks in. You see a list of checkboxes
- 11:30Speaker 1: for automatic analysis, and naturally you think, I want this
- 11:34Speaker 1: smart tool to do all the work for me. Check
- 11:36Speaker 1: all the boxes.
- 11:37Speaker 2: The very common mistake, but analysts worn against this.
- 11:41Speaker 1: Wait, why wouldn't we want the tool to do everything automatically?
- 11:45Speaker 1: Why limit a smart tool? Why would my powerful modern
- 11:48Speaker 1: computer crash?
- 11:50Speaker 2: This is a fantastic lesson in the difference between static
- 11:53Speaker 2: and dynamic analysis. When you leave those automatic analysis boxes checked.
- 11:58Speaker 2: You are demanding that x analyzer perform heavy static analysis
- 12:01Speaker 2: on the entire executable file the instant you load it,
- 12:05Speaker 2: meaning it tries to read the whole book before I
- 12:07Speaker 2: even press play. Exactly, it attempts to trace every possible jump,
- 12:11Speaker 2: every possible function, and every possible variable without actually running
- 12:14Speaker 2: the code. Think of it like trying to perfectly map
- 12:17Speaker 2: every single branch and twig of a giant oak tree
- 12:20Speaker 2: in your head all at once. I get a headache,
- 12:22Speaker 2: and so does the CPU. For a tiny, simple program,
- 12:26Speaker 2: your computer can handle it. But if you load a
- 12:29Speaker 2: massive complex piece of commercial software or a heavily obfuscated
- 12:34Speaker 2: piece of malware.
- 12:35Speaker 1: The ones of the heavy metal briefcases.
- 12:37Speaker 2: Exactly, the complexity is exponential. The CPU exhausts its memory
- 12:42Speaker 2: trying to hold the entire map in its head, and
- 12:44Speaker 2: the debugger simply collapses. Your workbench crashes.
- 12:48Speaker 1: So trying to translate the entire dictionary at once just
- 12:51Speaker 1: breaks the system. What is the consensus on how to
- 12:54Speaker 1: fix this?
- 12:55Speaker 2: The golden rule for stability is to aggressively limit the automation.
- 12:59Speaker 2: You go in to those settings and you uncheck the
- 13:01Speaker 2: first two options related to automatic analysis.
- 13:04Speaker 1: The buggy ones right.
- 13:05Speaker 2: You leave only the third and fourth options checked, which
- 13:08Speaker 2: handle more passive things like formatting.
- 13:10Speaker 1: But if it's not analyzing the code automatically, how do
- 13:13Speaker 1: we actually get our translated labels and visual arrows.
- 13:16Speaker 2: We use the manual method. You load your software, and
- 13:20Speaker 2: because it's not autoanalyzing, the debugger opens instantly. It stays
- 13:24Speaker 2: fast and lightweight.
- 13:25Speaker 1: Okay, that's a plus.
- 13:26Speaker 2: You step through the code, freezing time as we discussed,
- 13:29Speaker 2: until you find a specific sception that looks interesting. Then
- 13:33Speaker 2: you use your mouse to highlight just that specific block
- 13:36Speaker 2: of code, write, click select analyzer, and click analyze selection.
- 13:40Speaker 1: Oh, I see, you are retaining total control. You are
- 13:43Speaker 1: only asking the plug in to translate the one specific
- 13:46Speaker 1: paragraph you are currently reading, rather than the entire book exactly.
- 13:50Speaker 2: You get all the benefits of the human readable labels
- 13:53Speaker 2: without risking a catastrophic crash. It is a much more
- 13:56Speaker 2: elegant surgical approach to reverse engineering.
- 13:59Speaker 1: Okay, let's pivot for a second to lab maintenance. Say
- 14:02Speaker 1: you've been surgically dissecting a piece of software for hours
- 14:06Speaker 1: your frozen time in a dozen different places. You've analyzed
- 14:09Speaker 1: various blocks of code. You've got notes everywhere it gets messy.
- 14:12Speaker 1: It gets very messy. We need to start fresh for
- 14:14Speaker 1: new experiments. But how do we clean up If I
- 14:17Speaker 1: just want to wipe the slate clean and delete all
- 14:20Speaker 1: my break points, do I just hunt them down in
- 14:22Speaker 1: software menus?
- 14:23Speaker 2: I mean you could, but doing that manually through the
- 14:26Speaker 2: software interface is incredibly tedious, and sometimes the internal databases
- 14:30Speaker 2: get corrupted.
- 14:31Speaker 1: Anyway, Because debuggers are stubbornly designed to remember your state.
- 14:34Speaker 2: Right exactly, they save all your breakpoints and notes so
- 14:37Speaker 2: you can pick up where.
- 14:37Speaker 1: You left off earlier. You mentioned that setting a breakpoint
- 14:40Speaker 1: actually modifies the code in memory by swapping in an
- 14:44Speaker 1: interrupt instruction. I imagine the debugger has to keep a
- 14:47Speaker 1: very meticulous record of every change it made so it
- 14:50Speaker 1: can revert them.
- 14:51Speaker 2: Later precisely, and it stores all those meticulous records in
- 14:54Speaker 2: a hidden folder. This is another major benefit of having
- 14:58Speaker 2: our tools sitting right on the root of the seat.
- 15:00Speaker 2: We can easily access the back end if you navigate
- 15:03Speaker 2: into your by sixty four DBG folder. Inside both the
- 15:06Speaker 2: buy Come two and by sixty four directories, there is
- 15:08Speaker 2: a folder named dB short for database.
- 15:11Speaker 1: This is where all the ghosts of your past debugging
- 15:13Speaker 1: sessions live.
- 15:14Speaker 2: Delete the ghosts. When you want a perfect clean reset,
- 15:19Speaker 2: you bypass the software interface entirely. You simply open that
- 15:22Speaker 2: dB folder, highlight every single file inside it, and hit delete.
- 15:27Speaker 1: Just wipe it out.
- 15:28Speaker 2: It completely purges the saved state. The next time you
- 15:31Speaker 2: open the debugger, it's like a brand new installation.
- 15:33Speaker 1: Okay, here's where it gets really interesting. Let's say we
- 15:36Speaker 1: have our clean environment. We've carefully analyzed a single block
- 15:40Speaker 1: of code, and xanalyzer has successfully translated a nummonic for us. Okay,
- 15:46Speaker 1: it proudly labels a function call as message box. Great.
- 15:49Speaker 1: We know the code is trying to pop up a
- 15:51Speaker 1: message box on the screen, but how do we know
- 15:53Speaker 1: what information that message box needs to actually function?
- 15:56Speaker 2: This is where every reverse engineer relies on external documentation,
- 16:00Speaker 2: specifically the ultimate Rosetta stone for Windows programming, the Microsoft
- 16:04Speaker 2: Developer Network or MSDN library official docs. Right when you
- 16:08Speaker 2: see a standard Windows API function like message box in
- 16:11Speaker 2: your debugger, you go to a web browser and search
- 16:14Speaker 2: for that exact function name in the official MSDN documentation.
- 16:18Speaker 1: So I just type MSDN message box A into a
- 16:21Speaker 1: search engine, because Analyzer always seems to stick an A
- 16:24Speaker 1: or A W at the end of the function.
- 16:26Speaker 2: Names actually pro tip from the programming world. Drop the
- 16:29Speaker 2: AORW when you search.
- 16:31Speaker 1: Oh really, why?
- 16:32Speaker 2: Those letters just tell the operating system what type of
- 16:35Speaker 2: text formatting to expect. A stands for ASCA, which is
- 16:38Speaker 2: standard text, and W stands for wide, which means Unicode
- 16:42Speaker 2: text for international characters. H Okay, But the underlying function
- 16:46Speaker 2: mechanics are the same. Just search MSDN message box.
- 16:49Speaker 1: Okay, So I drop the letter. I search the official
- 16:52Speaker 1: Microsoft documentation and it gives me a clear list of
- 16:55Speaker 1: the parameters the function requires. What does it say for
- 16:58Speaker 1: a message box? The manual says its four specific things
- 17:01Speaker 1: to work, a handle to owner window, the text inside
- 17:04Speaker 1: the box, the title of the box, and the style
- 17:07Speaker 1: of the buttons. Right, and they are listed in a
- 17:09Speaker 1: very specific logical order. Parameter one, parameter two, perimeter three,
- 17:13Speaker 1: perimeter four.
- 17:14Speaker 2: But here's the massive twist. When you look back at
- 17:17Speaker 2: your debugger, when you look at the raw machine code
- 17:20Speaker 2: that X analyzer just translated for you, those parameters are
- 17:23Speaker 2: absolutely not being fed into the function in that order, right.
- 17:27Speaker 1: The raw code pushes them in backwards.
- 17:29Speaker 2: Why, Because of how the by eighty six processor architecture
- 17:33Speaker 2: handles memory During function calls, it uses that temporary storage
- 17:38Speaker 2: area we mentioned earlier, called the stack.
- 17:40Speaker 1: Okay, the stack, and the.
- 17:41Speaker 2: Stack operates on a strict last in first out principle
- 17:45Speaker 2: or LIFOFO.
- 17:46Speaker 1: Last in first out. Can you visualize that for me?
- 17:49Speaker 2: Think of it like a spring loaded stack of plates
- 17:52Speaker 2: at a buffet restaurant. You push a plate down onto
- 17:55Speaker 2: the stack, then you push another plate on top of it.
- 17:57Speaker 2: Right when a customer comes along to grab a plate,
- 18:00Speaker 2: which one did they take?
- 18:01Speaker 1: They take the one on the very top exactly.
- 18:02Speaker 2: The last plate you pushed onto the pile is the
- 18:05Speaker 2: first plate someone picks up.
- 18:06Speaker 1: Okay, so how does the buffet plate analogy apply to
- 18:09Speaker 1: our assembly code?
- 18:10Speaker 2: When a program wants to call the message box function,
- 18:13Speaker 2: it has to push the four required parameters onto that
- 18:16Speaker 2: memory stack so the function can read them. But because
- 18:19Speaker 2: the function is designed to read the stack from the
- 18:21Speaker 2: top down, grabbing the top plate first, the program actually
- 18:25Speaker 2: has to push the parameters in reverse order.
- 18:28Speaker 1: Oh wow. So if the human readable Microsoft documentation says
- 18:31Speaker 1: parameter one is the window handle, parameter two is the text,
- 18:34Speaker 1: parameter three is the title, and parameter four is the button.
- 18:37Speaker 2: Style, then the assembly code will push parameter four onto
- 18:40Speaker 2: the stack first unbelievable. Then it pushes parameter three, then
- 18:43Speaker 2: parameter two, and finally parameter one is pushed last. That
- 18:47Speaker 2: leaves parameter one sitting right on top of the stack,
- 18:50Speaker 2: ready to be the very first thing the function reads.
- 18:53Speaker 1: That is mind bending. The very first parameter listed in
- 18:56Speaker 1: the official human documentation is the very last parameter pushed
- 19:00Speaker 1: in the actual machine code. Yep, you are literally watching
- 19:03Speaker 1: the machine execute logic backward compared to how the human
- 19:07Speaker 1: programmer conceptualized and wrote it.
- 19:10Speaker 2: It really is an incredible realization, and it's a perfect
- 19:12Speaker 2: example of why analysts need to understand not just what
- 19:15Speaker 2: the code is doing, but why the underlying hardware forces
- 19:19Speaker 2: it to be structured that.
- 19:20Speaker 1: Way, because the tools can only take you so far exactly.
- 19:24Speaker 2: This analyzer plug in is fantastic for labeling the text,
- 19:27Speaker 2: but the human analyst still has to understand the lifomechanics
- 19:30Speaker 2: of the stack to interpret that text correctly.
- 19:32Speaker 1: This has been a phenomenal build. We took raw, confusing
- 19:35Speaker 1: concepts and built a fully functioning, highly stable software analysis
- 19:40Speaker 1: laboratory right.
- 19:41Speaker 2: In our minds, a very powerful lab.
- 19:43Speaker 1: Let's do a quick mental review exercise to lock these
- 19:46Speaker 1: concepts in. If you're listening, visualize that seed drive you
- 19:49Speaker 1: just downloaded the Z analyzer plug in files. You need
- 19:52Speaker 1: to install them. Where exactly do they go?
- 19:54Speaker 2: Remember you are dealing with two distinct architectures. The files
- 19:57Speaker 2: go into the plugins directory inside the BY thirty T
- 20:00Speaker 2: two folder A and D. You must repeat the exact
- 20:02Speaker 2: same process putting the sixty four bit files inside the
- 20:06Speaker 2: BY sixty four folders plug in directory.
- 20:08Speaker 1: Nailed it, Okay. Second mental map, You freeze time in
- 20:11Speaker 1: the debugger. You find a function call, You look it
- 20:13Speaker 1: up on the MSDN library and Microsoft's documentation lists four parameters.
- 20:18Speaker 1: Which of those four parameters is pushed onto the stack
- 20:20Speaker 1: first in your assembly code?
- 20:21Speaker 2: Because the hardware stack operates on a last in, first
- 20:24Speaker 2: out principle, the machine pushes them in reverse order, So
- 20:28Speaker 2: the fourth parameter on the ms dandlist is the very
- 20:31Speaker 2: first one pushed onto the stack in the code.
- 20:34Speaker 1: Perfect. You now have a working mental model of how
- 20:37Speaker 1: software actually interacts with a processor at the lowest levels,
- 20:42Speaker 1: Which brings me to a final thought for you to
- 20:44Speaker 1: chew on today.
- 20:44Speaker 2: Let's hear it.
- 20:45Speaker 1: We just spent this entire deep dive learning how to
- 20:48Speaker 1: look at machine logic. We discovered that at the silicon level,
- 20:52Speaker 1: the machine organizes instructions in reverse to how a human
- 20:56Speaker 1: naturally reads them. If our deepest system tools require us
- 20:59Speaker 1: to interpret logic backward just to understand a simple message box,
- 21:04Speaker 1: what does that reveal about the massive hidden gap of
- 21:07Speaker 1: translation happening every single second between the high level software
- 21:10Speaker 1: we rely on every day and the cold, hard, physical
- 21:13Speaker 1: hardware it actually runs on.
- 21:14Speaker 2: It's a gap of abstraction that most people never even
- 21:17Speaker 2: realize exists, and now you
- 21:18Speaker 1: Have the tools to explore it yourself.