Win32 Programming Lesson 21: DLL Magic. Where are we?  We’ve looked at DLLs from a build/link/execute perspective, as well as some more advanced techniques.

Slides:



Advertisements
Similar presentations
Microsoft ® Office Outlook ® 2007 Training Retrieve, back up, or share messages Sweetwater ISD presents:
Advertisements

Data Structures Static and Dynamic.
Why Computers Are Necessary in Today’s World!
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Win32 Programming Lesson 8: Processes. Where are we?  We’re starting to have some foundational understanding of Windows  But really, we don’t know how.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Run-Time Storage Organization
1 Dynamic Memory Allocation Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
TCP/IP.
Manage your mailbox V: Retrieve, back up, or share messages Use your stored messages Whether you’re using the Personal Folders method or the Archive method.
Ceng Operating Systems
Win32 Programming Lesson 9: Jobs & Thread Basics.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
Tutorial 7 Memory Management presented by: Antonio Maiorano Paul Di Marco.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Threading Models in Visual Basic Language Student Name: Danyu Xu Student ID:98044.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Concurrency: Threads, Address Spaces, and Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
Win32 Programming Lesson 1: Why We’re All Here. Why We’re Here…  Okay, maybe that’s too grandiose  Windows – in particular Win32 Thirty-what?  What.
Sandbox Exploitations - ECE 4112 Group 12 - Gary Kao Jimmy Vuong.
Win32 Programming Lesson 10: Thread Scheduling and Priorities.
Win32 Programming Lesson 20: Advanced DLL Techniques.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Win32 Programming Lesson 22: DLL Magic Part Deux All your base are belong to us…
Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition.
How to configure DNS for a Windows 2000 domain? 1.Start the Install/Remove Programs Control Panel Applet (Start - Settings - Control Panel - Add/Remove.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Win32 Programming Lesson 18: More Memory Mapped Files and the HEAP (Finally, cool stuff!)
Games Development 2 Concurrent Programming CO3301 Week 9.
Win32 Programming Lesson 25: Unhandled Exceptions Bet you’ve never encountered one of those, eh?
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Dynamic Link Libraries: Inside Out. Dynamic Link Libraries  About Dynamic-Link Libraries  Dynamic-Link Libraries Hands On  Dynamic Link Library Reference.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Choose a folder on the remote machine. For e.g. if there is a machine named comp1 in your network, please choose a folder in that machine which you will.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 5 Page 1 CS 111 Online Processes CS 111 On-Line MS Program Operating Systems Peter Reiher.
Joe Chrzanowski. The DCI Paradigm  Created by Prof. Trygve Reenskaug  DCI is the successor to MVC  Originally intended to organize the Model part of.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
Department of Computer Science and Software Engineering
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
Win32 Programming Lesson 11: User-mode Thread Sync (aka: How to crash your machine without really trying…)
Application Remediation
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Chapter Eleven Windows XP Professional Application Support.
Win32 Programming Lesson 19: Introduction to DLLs.
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
How to fix Missing Windows Sockets Registry Entries required for Network Connectivity in Windows 10 /pages/Reimage- Repair- Tool/ /u/6/b/
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Lesson Objectives Aims Key Words Paging, Segmentation, Virtual Memory
Chapter 3: Windows7 Part 5.
Examining the Cluster Log
Lesson One – Creating a thread
CSCI206 - Computer Organization & Programming
Chapter 3: Windows7 Part 5.
Page Replacement.
Machine Independent Features
Windows CE Memory Management
Module IV Memory Organization.
System Calls David Ferry CSCI 3500 – Operating Systems
Basic Dynamic Analysis VMs and Sandboxes
CS703 – Advanced Operating Systems
Presentation transcript:

Win32 Programming Lesson 21: DLL Magic

Where are we?  We’ve looked at DLLs from a build/link/execute perspective, as well as some more advanced techniques  Today, start looking at Thread Local Storage and DLL interception >:)

Thread Local Storage (TLS)  What does the strtok function do?  How does it work?  What happens in a multithreaded environment?

TLS  Provides simple method for storing variables on a per-thread basis  Two types: dynamic and static; we’ll be looking at both.

Supporting Structures

So…  We call: DWORD TlsAlloc(); Returns TLS_OUT_OF_INDEXES if no storage is available Else, returns an index number which can be used to store a DWORD BOOL TlsSetValue( DWORD dwTlsIndex, PVOID pvTlsValue );

Cleaning Up  It’s C++, so there’s not a lot of cleaning up done for us… PVOID TlsGetValue(DWORD dwTlsIndex); BOOL TlsFree(DWORD dwTlsIndex);

Using Static TLS  Can also do this: __declspec(thread) DWORD gt_dwStartTime = 0; Creates a.tls section Allocates the necessary storage automatically

DLL Injection  So, life can be interesting  Windows provides limited process isolation  But sometimes we want to “hook” into another process  One way to do this is by leveraging DLLs

Danger, Will Robinson  Some of these techniques will make global changes to how your computer functions. You need to carefully decide whether to do this on your main machine, or if a VM is a better option. You have been warned!  (That said, I do this all on my own laptop…)

The Trick  What are we actually trying to do?

Registry  HKEY_LOCAL_MACHINE\Software\Micro soft \Windows NT\CurrentVersion\Window s\AppInit_DLLs  Hmmm. Advantages? Drawbacks?

Drawbacks…  You must restart your computer  Only mapped into processes which use User32.dll  You’re in *every* GUI app…  … for it’s entire lifetime

Better…  SetWindowsHookEx SetWindowsHookEx E.g: HHOOK hHook = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc, hinstDll, 0 ); Why hinstDll?

Walkthrough  DIPS