aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/talloc
diff options
context:
space:
mode:
Diffstat (limited to 'samples/talloc')
-rw-r--r--samples/talloc/Makefile332
-rw-r--r--samples/talloc/NORMAL_IA64.TXT70
-rw-r--r--samples/talloc/NORMAL_X64.TXT66
-rw-r--r--samples/talloc/talloc.cpp541
-rw-r--r--samples/talloc/tdll1x.cpp17
-rw-r--r--samples/talloc/tdll2x.cpp17
-rw-r--r--samples/talloc/tdll3x.cpp17
-rw-r--r--samples/talloc/tdll4x.cpp17
-rw-r--r--samples/talloc/tdll5x.cpp17
-rw-r--r--samples/talloc/tdll6x.cpp17
-rw-r--r--samples/talloc/tdll7x.cpp17
-rw-r--r--samples/talloc/tdll8x.cpp17
-rw-r--r--samples/talloc/tdll9x.cpp17
13 files changed, 1162 insertions, 0 deletions
diff --git a/samples/talloc/Makefile b/samples/talloc/Makefile
new file mode 100644
index 0000000..9e561c4
--- /dev/null
+++ b/samples/talloc/Makefile
@@ -0,0 +1,332 @@
+##############################################################################
+##
+## Makefile for Detours Test Programs.
+##
+## Microsoft Research Detours Package
+##
+## Copyright (c) Microsoft Corporation. All rights reserved.
+##
+
+!include ..\common.mak
+
+# This test tests the allocation algorithm. .dlls are carefully placed
+# immediately adjacent to each other to force the algorithm to look more places.
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+
+!if "$(DETOURS_TARGET_PROCESSOR:64=)" == "$(DETOURS_TARGET_PROCESSOR)"
+# 32bit bases
+DETOURS_TALLOC1=0x28000000
+DETOURS_TALLOC2=0x38000000
+DETOURS_TALLOC3=0x48050000
+DETOURS_TALLOC4=0x58000000
+DETOURS_TALLOC5=0x68000000
+DETOURS_TALLOC6=0x68010000
+DETOURS_TALLOC7=0x68020000
+DETOURS_TALLOC8=0x68030000
+DETOURS_TALLOC9=0x68040000
+!else
+# 64bit bases
+DETOURS_TALLOC1=0x280000000
+DETOURS_TALLOC2=0x380000000
+DETOURS_TALLOC3=0x480050000
+DETOURS_TALLOC4=0x580000000
+DETOURS_TALLOC5=0x680000000
+DETOURS_TALLOC6=0x680010000
+DETOURS_TALLOC7=0x680020000
+DETOURS_TALLOC8=0x680030000
+DETOURS_TALLOC9=0x680040000
+!endif
+
+LIBS=$(LIBS) kernel32.lib psapi.lib
+
+all: dirs \
+ $(BIND)\tdll1x$(DETOURS_BITS).dll \
+ $(BIND)\tdll2x$(DETOURS_BITS).dll \
+ $(BIND)\tdll3x$(DETOURS_BITS).dll \
+ $(BIND)\tdll4x$(DETOURS_BITS).dll \
+ $(BIND)\tdll5x$(DETOURS_BITS).dll \
+ $(BIND)\tdll6x$(DETOURS_BITS).dll \
+ $(BIND)\tdll7x$(DETOURS_BITS).dll \
+ $(BIND)\tdll8x$(DETOURS_BITS).dll \
+ $(BIND)\tdll9x$(DETOURS_BITS).dll \
+ $(BIND)\talloc.exe \
+ \
+!IF $(DETOURS_SOURCE_BROWSING)==1
+ $(OBJD)\tdll1x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll2x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll3x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll4x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll5x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll6x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll7x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll8x$(DETOURS_BITS).bsc \
+ $(OBJD)\tdll9x$(DETOURS_BITS).bsc \
+ $(OBJD)\talloc.bsc \
+!ENDIF
+ option
+
+clean:
+ -del *~ 2>nul
+ -del $(BIND)\tdll1x* 2>nul
+ -del $(BIND)\tdll2x* 2>nul
+ -del $(BIND)\tdll3x* 2>nul
+ -del $(BIND)\tdll4x* 2>nul
+ -del $(BIND)\tdll5x* 2>nul
+ -del $(BIND)\tdll6x* 2>nul
+ -del $(BIND)\tdll7x* 2>nul
+ -del $(BIND)\tdll8x* 2>nul
+ -del $(BIND)\tdll9x* 2>nul
+ -del $(BIND)\talloc* 2>nul
+ -rmdir /q /s $(OBJD) 2>nul
+
+realclean: clean
+ -rmdir /q /s $(OBJDS) 2>nul
+
+dirs:
+ @if not exist $(BIND) mkdir $(BIND) && echo. Created $(BIND)
+ @if not exist $(OBJD) mkdir $(OBJD) && echo. Created $(OBJD)
+
+##############################################################################
+
+$(OBJD)\talloc.obj : talloc.cpp
+
+$(BIND)\talloc.exe : $(OBJD)\talloc.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb $(OBJD)\talloc.obj \
+ /link $(LINKFLAGS) $(LIBS) \
+ $(BIND)\tdll1x$(DETOURS_BITS).lib \
+ $(BIND)\tdll2x$(DETOURS_BITS).lib \
+ $(BIND)\tdll3x$(DETOURS_BITS).lib \
+ $(BIND)\tdll4x$(DETOURS_BITS).lib \
+ $(BIND)\tdll5x$(DETOURS_BITS).lib \
+ $(BIND)\tdll6x$(DETOURS_BITS).lib \
+ $(BIND)\tdll7x$(DETOURS_BITS).lib \
+ $(BIND)\tdll8x$(DETOURS_BITS).lib \
+ $(BIND)\tdll9x$(DETOURS_BITS).lib \
+ /subsystem:console /entry:WinMainCRTStartup
+
+$(OBJD)\talloc.bsc : $(OBJD)\talloc.obj
+ bscmake /v /n /o $@ $(OBJD)\talloc.sbr
+
+$(OBJD)\tdll1x.obj : tdll1x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll1x$(DETOURS_BITS).dll : $(OBJD)\tdll1x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll1x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:windows \
+ /noentry \
+ /base:$(DETOURS_TALLOC1)
+
+$(OBJD)\tdll1x$(DETOURS_BITS).bsc : $(OBJD)\tdll1x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll1x.sbr
+
+$(OBJD)\tdll2x.obj : tdll2x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll2x$(DETOURS_BITS).dll : $(OBJD)\tdll2x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll2x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC2)
+
+$(OBJD)\tdll2x$(DETOURS_BITS).bsc : $(OBJD)\tdll2x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll2x.sbr
+
+$(OBJD)\tdll3x.obj : tdll3x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll3x$(DETOURS_BITS).dll : $(OBJD)\tdll3x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll3x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC3)
+
+$(OBJD)\tdll3x$(DETOURS_BITS).bsc : $(OBJD)\tdll3x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll3x.sbr
+
+$(OBJD)\tdll4x.obj : tdll4x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll4x$(DETOURS_BITS).dll : $(OBJD)\tdll4x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll4x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC4)
+
+$(OBJD)\tdll4x$(DETOURS_BITS).bsc : $(OBJD)\tdll4x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll4x.sbr
+
+
+$(OBJD)\tdll5x.obj : tdll5x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll5x$(DETOURS_BITS).dll : $(OBJD)\tdll5x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll5x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC5)
+
+$(OBJD)\tdll5x$(DETOURS_BITS).bsc : $(OBJD)\tdll5x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll5x.sbr
+
+$(OBJD)\tdll6x.obj : tdll6x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll6x$(DETOURS_BITS).dll : $(OBJD)\tdll6x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll6x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC6)
+
+$(OBJD)\tdll6x$(DETOURS_BITS).bsc : $(OBJD)\tdll6x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll6x.sbr
+
+
+$(OBJD)\tdll7x.obj : tdll7x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll7x$(DETOURS_BITS).dll : $(OBJD)\tdll7x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll7x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC7)
+
+$(OBJD)\tdll7x$(DETOURS_BITS).bsc : $(OBJD)\tdll7x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll7x.sbr
+
+
+$(OBJD)\tdll8x.obj : tdll8x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll8x$(DETOURS_BITS).dll : $(OBJD)\tdll8x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll8x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC8)
+
+$(OBJD)\tdll8x$(DETOURS_BITS).bsc : $(OBJD)\tdll8x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll8x.sbr
+
+
+$(OBJD)\tdll9x.obj : tdll9x.cpp
+
+# /noentry keeps the .dlls small, so they all fit at their bases
+$(BIND)\tdll9x$(DETOURS_BITS).dll : $(OBJD)\tdll9x.obj $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb \
+ $(OBJD)\tdll9x.obj /LD \
+ /link $(LINKFLAGS:/profile=/fixed) $(LIBS) \
+ /subsystem:console \
+ /noentry \
+ /base:$(DETOURS_TALLOC9)
+
+$(OBJD)\tdll9x$(DETOURS_BITS).bsc : $(OBJD)\tdll9x.obj
+ bscmake /v /n /o $@ $(OBJD)\tdll9x.sbr
+
+############################################### Install non-bit-size binaries.
+
+!IF "$(DETOURS_OPTION_PROCESSOR)" != ""
+
+$(OPTD)\tdll1x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll1x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll2x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll2x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll3x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll3x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll4x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll4x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll5x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll5x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll6x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll6x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll7x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll7x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll8x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll8x$(DETOURS_OPTION_BITS).pdb:
+$(OPTD)\tdll9x$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\tdll9x$(DETOURS_OPTION_BITS).pdb:
+
+$(BIND)\tdll1x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll1x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll1x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll1x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll2x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll2x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll2x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll2x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll3x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll3x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll3x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll3x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll4x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll4x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll4x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll4x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll5x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll5x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll5x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll5x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll6x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll6x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll6x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll6x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll7x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll7x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll7x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll7x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll8x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll8x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll8x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll8x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll9x$(DETOURS_OPTION_BITS).dll : $(OPTD)\tdll9x$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\tdll9x$(DETOURS_OPTION_BITS).pdb : $(OPTD)\tdll9x$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+
+option: \
+ $(BIND)\tdll1x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll1x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll2x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll2x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll3x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll3x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll4x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll4x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll5x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll5x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll6x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll6x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll7x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll7x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll8x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll8x$(DETOURS_OPTION_BITS).pdb \
+ $(BIND)\tdll9x$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\tdll9x$(DETOURS_OPTION_BITS).pdb \
+
+!ELSE
+
+option:
+
+!ENDIF
+
+##############################################################################
+
+test: all
+ $(BIND)\talloc.exe
+
+################################################################# End of File.
diff --git a/samples/talloc/NORMAL_IA64.TXT b/samples/talloc/NORMAL_IA64.TXT
new file mode 100644
index 0000000..e04a1c9
--- /dev/null
+++ b/samples/talloc/NORMAL_IA64.TXT
@@ -0,0 +1,70 @@
+talloc.exe: Detoured functions.
+
+ Address Size: Typ Sta Prot Ini : Contents
+ ------------ ------------: --- --- ---- --- : -----------------
+Exe: 13f660000
+ 100000000 3f660000: fre --- :
+ 13f660000 2000: img com r-- rcx : TALLOC.EXE
+ 13f6ce000 100802000: fre --- :
+Dll1: 280000000
+ 200000000 3fed0000: fre --- :
+ 23fed0000 10000: pri com r-x rwx :
+ 23fee0000 2000: pri res --- :
+ 23fee2000 e000: fre --- :
+ 23fef0000 10000: pri res --- :
+ 23ff00000 100000: pri res --- :
+ 240000000 40000000: pri res --- :
+ 280000000 2000: img com r-- rcx : TDLL1X64.DLL
+ 280028000 8000: fre --- :
+ 280030000 7ffd0000: pri res --- :
+Dll2: 380000000
+ 300000000 80000000: pri res --- :
+ 380000000 2000: img com r-- rcx : TDLL2X64.DLL
+ 380028000 8000: fre --- :
+ 380030000 40000000: pri res --- :
+ 3c0030000 100000: pri res --- :
+ 3c0130000 10000: pri res --- :
+ 3c0140000 2000: pri res --- :
+ 3c0142000 e000: fre --- :
+ 3c0150000 10000: pri com r-x rwx :
+ 3c0160000 3fea0000: fre --- :
+Dll3: 480000000
+ 400000000 40000000: pri res --- :
+ 440000000 100000: pri res --- :
+ 440100000 10000: pri res --- :
+ 440110000 2000: pri res --- :
+ 440112000 e000: fre --- :
+ 440120000 10000: pri com r-x rwx :
+ 440130000 3fed0000: fre --- :
+ 480000000 2000: img com r-- rcx : TDLL3X64.DLL
+ 480028000 8000: fre --- :
+ 480030000 7ffd0000: pri res --- :
+Dll4: 580000000
+ 500000000 80000000: pri res --- :
+ 580000000 2000: img com r-- rcx : TDLL4X64.DLL
+ 580028000 3fea8000: fre --- :
+ 5bfed0000 10000: pri com r-x rwx :
+ 5bfee0000 2000: pri res --- :
+ 5bfee2000 e000: fre --- :
+ 5bfef0000 10000: pri res --- :
+ 5bff00000 100000: pri res --- :
+ 5c0000000 40000000: pri res --- :
+Dll5: 680000000
+ 600000000 f0000: fre --- :
+ 6000f0000 10000: pri com r-x rwx :
+ 600100000 7ff00000: pri res --- :
+ 680000000 2000: img com r-- rcx : TDLL5X64.DLL
+ 680028000 18000: fre --- :
+ 680040000 2000: img com r-- rcx : TDLL6X64.DLL
+ 680068000 18000: fre --- :
+ 680080000 2000: img com r-- rcx : TDLL7X64.DLL
+ 6800a8000 18000: fre --- :
+ 6800c0000 2000: img com r-- rcx : TDLL8X64.DLL
+ 6800e8000 18000: fre --- :
+ 680100000 2000: img com r-- rcx : TDLL9X64.DLL
+ 680128000 8000: fre --- :
+ 680130000 7fe00000: pri res --- :
+ 6fff30000 10000: pri com r-x rwx :
+ 6fff40000 6f3fbdd0000: fre --- :
+
+talloc.exe: 1 calls to Dll1Function
diff --git a/samples/talloc/NORMAL_X64.TXT b/samples/talloc/NORMAL_X64.TXT
new file mode 100644
index 0000000..650d09a
--- /dev/null
+++ b/samples/talloc/NORMAL_X64.TXT
@@ -0,0 +1,66 @@
+talloc.exe: Detoured functions.
+
+ Address Size: Typ Sta Prot Ini : Contents
+ ------------ ------------: --- --- ---- --- : -----------------
+Exe: 13f7f0000
+ 100000000 3f7f0000: fre --- :
+ 13f7f0000 1000: img com r-- rcx : TALLOC.EXE
+ 13f81e000 1006b2000: fre --- :
+Dll1: 280000000
+ 200000000 3fed0000: fre --- :
+ 23fed0000 10000: pri com r-x rwx :
+ 23fee0000 1000: pri res --- :
+ 23fee1000 f000: fre --- :
+ 23fef0000 10000: pri res --- :
+ 23ff00000 100000: pri res --- :
+ 240000000 40000000: pri res --- :
+ 280000000 1000: img com r-- rcx : TDLL1X64.DLL
+ 280010000 7fff0000: pri res --- :
+Dll2: 380000000
+ 300000000 80000000: pri res --- :
+ 380000000 1000: img com r-- rcx : TDLL2X64.DLL
+ 380010000 40000000: pri res --- :
+ 3c0010000 100000: pri res --- :
+ 3c0110000 10000: pri res --- :
+ 3c0120000 1000: pri res --- :
+ 3c0121000 f000: fre --- :
+ 3c0130000 10000: pri com r-x rwx :
+ 3c0140000 3fec0000: fre --- :
+Dll3: 480000000
+ 400000000 40000000: pri res --- :
+ 440000000 100000: pri res --- :
+ 440100000 10000: pri res --- :
+ 440110000 1000: pri res --- :
+ 440111000 f000: fre --- :
+ 440120000 10000: pri com r-x rwx :
+ 440130000 3fed0000: fre --- :
+ 480000000 1000: img com r-- rcx : TDLL3X64.DLL
+ 480010000 7fff0000: pri res --- :
+Dll4: 580000000
+ 500000000 80000000: pri res --- :
+ 580000000 1000: img com r-- rcx : TDLL4X64.DLL
+ 580010000 3fec0000: fre --- :
+ 5bfed0000 10000: pri com r-x rwx :
+ 5bfee0000 1000: pri res --- :
+ 5bfee1000 f000: fre --- :
+ 5bfef0000 10000: pri res --- :
+ 5bff00000 100000: pri res --- :
+ 5c0000000 40000000: pri res --- :
+Dll5: 680000000
+ 600000000 f0000: fre --- :
+ 6000f0000 10000: pri com r-x rwx :
+ 600100000 7ff00000: pri res --- :
+ 680000000 1000: img com r-- rcx : TDLL5X64.DLL
+ 680010000 30000: fre --- :
+ 680040000 1000: img com r-- rcx : TDLL6X64.DLL
+ 680050000 30000: fre --- :
+ 680080000 1000: img com r-- rcx : TDLL7X64.DLL
+ 680090000 30000: fre --- :
+ 6800c0000 1000: img com r-- rcx : TDLL8X64.DLL
+ 6800d0000 30000: fre --- :
+ 680100000 1000: img com r-- rcx : TDLL9X64.DLL
+ 680110000 7fe00000: pri res --- :
+ 6fff10000 10000: pri com r-x rwx :
+ 6fff20000 7f7fdf70000: fre --- :
+
+talloc.exe: 1 calls to Dll1Function
diff --git a/samples/talloc/talloc.cpp b/samples/talloc/talloc.cpp
new file mode 100644
index 0000000..85eb6b3
--- /dev/null
+++ b/samples/talloc/talloc.cpp
@@ -0,0 +1,541 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (talloc.cpp of talloc.exe)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+#define PSAPI_VERSION 2
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+#pragma warning(push)
+#if _MSC_VER > 1400
+#pragma warning(disable:6102 6103) // /analyze warnings
+#endif
+#include <strsafe.h>
+#pragma warning(pop)
+#include <psapi.h>
+#include <detours.h>
+
+//////////////////////////////////////////////////////////////////////////////
+
+void TypeToString(DWORD Type, char *pszBuffer, size_t cBuffer)
+{
+ if (Type == MEM_IMAGE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "img");
+ }
+ else if (Type == MEM_MAPPED) {
+ StringCchPrintfA(pszBuffer, cBuffer, "map");
+ }
+ else if (Type == MEM_PRIVATE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "pri");
+ }
+ else if (Type == 0) {
+ StringCchPrintfA(pszBuffer, cBuffer, " ");
+ }
+ else {
+ StringCchPrintfA(pszBuffer, cBuffer, "%x", Type);
+ }
+}
+
+void StateToString(DWORD State, char *pszBuffer, size_t cBuffer)
+{
+ if (State == MEM_COMMIT) {
+ StringCchPrintfA(pszBuffer, cBuffer, "com");
+ }
+ else if (State == MEM_FREE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "fre");
+ }
+ else if (State == MEM_RESERVE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "res");
+ }
+ else {
+ StringCchPrintfA(pszBuffer, cBuffer, "%x", State);
+ }
+}
+
+void ProtectToString(DWORD Protect, char *pszBuffer, size_t cBuffer)
+{
+ if (Protect == 0) {
+ StringCchPrintfA(pszBuffer, cBuffer, "");
+ }
+ else if (Protect == PAGE_EXECUTE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "--x");
+ }
+ else if (Protect == PAGE_EXECUTE_READ) {
+ StringCchPrintfA(pszBuffer, cBuffer, "r-x");
+ }
+ else if (Protect == PAGE_EXECUTE_READWRITE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "rwx");
+ }
+ else if (Protect == PAGE_EXECUTE_WRITECOPY) {
+ StringCchPrintfA(pszBuffer, cBuffer, "rcx");
+ }
+ else if (Protect == PAGE_NOACCESS) {
+ StringCchPrintfA(pszBuffer, cBuffer, "---");
+ }
+ else if (Protect == PAGE_READONLY) {
+ StringCchPrintfA(pszBuffer, cBuffer, "r--");
+ }
+ else if (Protect == PAGE_READWRITE) {
+ StringCchPrintfA(pszBuffer, cBuffer, "rw-");
+ }
+ else if (Protect == PAGE_WRITECOPY) {
+ StringCchPrintfA(pszBuffer, cBuffer, "rc-");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_EXECUTE)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "g--x");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_EXECUTE_READ)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "gr-x");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_EXECUTE_READWRITE)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "grwx");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_EXECUTE_WRITECOPY)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "grcx");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_NOACCESS)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "g---");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_READONLY)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "gr--");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_READWRITE)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "grw-");
+ }
+ else if (Protect == (PAGE_GUARD | PAGE_WRITECOPY)) {
+ StringCchPrintfA(pszBuffer, cBuffer, "grc-");
+ }
+ else {
+ StringCchPrintfA(pszBuffer, cBuffer, "%x", Protect);
+ }
+}
+
+ULONG PadToPage(ULONG Size)
+{
+ return (Size & 0xfff)
+ ? Size + 0x1000 - (Size & 0xfff)
+ : Size;
+}
+
+size_t NextAt(size_t start)
+{
+ size_t next = start;
+
+ for (;;) {
+ MEMORY_BASIC_INFORMATION mbi;
+
+ ZeroMemory(&mbi, sizeof(mbi));
+ if (VirtualQuery((PVOID)next, &mbi, sizeof(mbi)) == 0) {
+ break;
+ }
+ if ((mbi.RegionSize & 0xfff) == 0xfff) {
+ break;
+ }
+
+ if ((size_t)mbi.AllocationBase != start) {
+ break;
+ }
+
+ next = (size_t)mbi.BaseAddress + mbi.RegionSize;
+ }
+ return next;
+}
+
+size_t RoundUpRegion(size_t value)
+{
+ size_t diff = value & 0xffff;
+ return (diff != 0) ? value + 0x10000 - diff : value;
+}
+
+VOID DumpProcessHeaders()
+{
+ printf(" %12s %12s: %3s %3s %4s %3s : %8s\n",
+ "Address", "Size", "Typ", "Sta", "Prot", "Ini", "Contents");
+ printf(" %12s %12s: %3s %3s %4s %3s : %8s\n",
+ "------------", "------------", "---", "---", "----", "---", "-----------------");
+}
+
+BOOL DumpProcess(UINT64 lo64, UINT64 hi64)
+{
+#ifdef _WIN64
+ ULONG_PTR lo = lo64;
+ ULONG_PTR hi = hi64;
+#else
+ ULONG_PTR lo = (size_t)(lo64 >> 4);
+ ULONG_PTR hi = (size_t)(hi64 >> 4);
+#endif
+
+ size_t base;
+ size_t next;
+
+ MEMORY_BASIC_INFORMATION mbi;
+
+ for (next = lo; next < hi;) {
+ base = next;
+ ZeroMemory(&mbi, sizeof(mbi));
+ if (VirtualQuery((PVOID)base, &mbi, sizeof(mbi)) == 0) {
+ break;
+ }
+ if ((mbi.RegionSize & 0xfff) == 0xfff) {
+ break;
+ }
+
+ if ((size_t)mbi.BaseAddress < lo) {
+ base = (size_t)mbi.BaseAddress;
+ }
+
+ size_t size = ((size_t)mbi.BaseAddress + mbi.RegionSize) - base;
+ next = (size_t)mbi.BaseAddress + mbi.RegionSize;
+
+ CHAR szType[16];
+ TypeToString(mbi.Type, szType, ARRAYSIZE(szType));
+ CHAR szState[16];
+ StateToString(mbi.State, szState, ARRAYSIZE(szState));
+ CHAR szProtect[16];
+ ProtectToString(mbi.Protect, szProtect, ARRAYSIZE(szProtect));
+ CHAR szAllocProtect[16];
+ ProtectToString(mbi.AllocationProtect, szAllocProtect, ARRAYSIZE(szAllocProtect));
+
+ CHAR szFile[MAX_PATH];
+ szFile[0] = '\0';
+ DWORD cb = 0;
+ PCHAR pszFile = szFile;
+
+ if (base == (size_t)mbi.AllocationBase) {
+ next = NextAt(base);
+
+ cb = GetMappedFileNameA(GetCurrentProcess(),
+ mbi.AllocationBase, szFile, ARRAYSIZE(szFile));
+ if (cb > 0) {
+ for (DWORD c = 0; c < cb; c++) {
+ szFile[c] = (char)toupper(szFile[c]);
+ }
+ szFile[cb] = '\0';
+ }
+ else {
+ szFile[0] = '\0';
+ }
+ if ((pszFile = strrchr(szFile, '\\')) == NULL) {
+ pszFile = szFile;
+ }
+ else {
+ pszFile++;
+ }
+ }
+
+ printf("%c %12zx %12zx: %3s %3s %4s %3s : %s\n",
+ " *"[base == (size_t)mbi.AllocationBase],
+ base,
+ size,
+ szType,
+ szState,
+ szProtect,
+ szAllocProtect,
+ pszFile);
+ }
+ return TRUE;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+__declspec(dllimport) DWORD WINAPI Dll1Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll2Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll3Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll4Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll5Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll6Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll7Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll8Function(DWORD Value);
+__declspec(dllimport) DWORD WINAPI Dll9Function(DWORD Value);
+
+static LONG dwCountDll1 = 0;
+static LONG dwCountDll2 = 0;
+static LONG dwCountDll3 = 0;
+static LONG dwCountDll4 = 0;
+static LONG dwCountDll5 = 0;
+static LONG dwCountDll6 = 0;
+static LONG dwCountDll7 = 0;
+static LONG dwCountDll8 = 0;
+static LONG dwCountDll9 = 0;
+
+static DWORD (WINAPI * TrueDll1Function)(DWORD Value) = Dll1Function;
+static DWORD (WINAPI * TrueDll2Function)(DWORD Value) = Dll2Function;
+static DWORD (WINAPI * TrueDll3Function)(DWORD Value) = Dll3Function;
+static DWORD (WINAPI * TrueDll4Function)(DWORD Value) = Dll4Function;
+static DWORD (WINAPI * TrueDll5Function)(DWORD Value) = Dll5Function;
+static DWORD (WINAPI * TrueDll6Function)(DWORD Value) = Dll6Function;
+static DWORD (WINAPI * TrueDll7Function)(DWORD Value) = Dll7Function;
+static DWORD (WINAPI * TrueDll8Function)(DWORD Value) = Dll8Function;
+static DWORD (WINAPI * TrueDll9Function)(DWORD Value) = Dll9Function;
+
+DWORD WINAPI MineDll1Function(DWORD Value)
+{
+ Value = TrueDll1Function(Value);
+ InterlockedIncrement(&dwCountDll1);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll2Function(DWORD Value)
+{
+ Value = TrueDll2Function(Value);
+ InterlockedIncrement(&dwCountDll2);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll3Function(DWORD Value)
+{
+ Value = TrueDll3Function(Value);
+ InterlockedIncrement(&dwCountDll3);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll4Function(DWORD Value)
+{
+ Value = TrueDll4Function(Value);
+ InterlockedIncrement(&dwCountDll4);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll5Function(DWORD Value)
+{
+ Value = TrueDll5Function(Value);
+ InterlockedIncrement(&dwCountDll5);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll6Function(DWORD Value)
+{
+ Value = TrueDll6Function(Value);
+ InterlockedIncrement(&dwCountDll6);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll7Function(DWORD Value)
+{
+ Value = TrueDll7Function(Value);
+ InterlockedIncrement(&dwCountDll7);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll8Function(DWORD Value)
+{
+ Value = TrueDll8Function(Value);
+ InterlockedIncrement(&dwCountDll8);
+
+ return Value;
+}
+
+DWORD WINAPI MineDll9Function(DWORD Value)
+{
+ Value = TrueDll9Function(Value);
+ InterlockedIncrement(&dwCountDll9);
+
+ return Value;
+}
+
+void Reserve(ULONG_PTR addr, ULONG_PTR size)
+{
+ PVOID mem = VirtualAlloc((PVOID)addr, size, MEM_RESERVE, PAGE_NOACCESS);
+ if (mem != (PVOID)addr) {
+ printf("*** Reservation failed: %p != %p\n", mem, (PVOID)addr);
+ }
+}
+
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR lpszCmdLine, int nCmdShow)
+{
+ (void)hinst;
+ (void)hprev;
+ (void)lpszCmdLine;
+ (void)nCmdShow;
+ DWORD error = NO_ERROR;
+
+ size_t Dll1 = (size_t)LoadLibraryA("tdll1x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll2 = (size_t)LoadLibraryA("tdll2x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll3 = (size_t)LoadLibraryA("tdll3x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll4 = (size_t)LoadLibraryA("tdll4x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll5 = (size_t)LoadLibraryA("tdll5x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll6 = (size_t)LoadLibraryA("tdll6x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll7 = (size_t)LoadLibraryA("tdll7x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll8 = (size_t)LoadLibraryA("tdll8x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+ size_t Dll9 = (size_t)LoadLibraryA("tdll9x" DETOURS_STRINGIFY(DETOURS_BITS) ".dll");
+
+ size_t DllEnd = RoundUpRegion(NextAt(Dll1));
+ ULONG_PTR DllSize = (DllEnd - Dll1);
+
+ (void)Dll6;
+ (void)Dll7;
+ (void)Dll8;
+
+ // Force allocation below moving lower.
+ Reserve(Dll1 - 0x40000000, 0x40000000);
+ Reserve(Dll1 - 0x40100000, 0x00100000);
+ Reserve(Dll1 - 0x40110000, 0x00010000);
+ Reserve(Dll1 - 0x40120000, 0x00001000);
+ Reserve(Dll1 + DllSize, 0x80000000 - DllSize);
+
+ // Force allocation above moving higher.
+ Reserve(Dll2 - 0x80000000, 0x80000000);
+ Reserve(Dll2 + DllSize, 0x40000000);
+ Reserve(Dll2 + 0x40000000 + DllSize, 0x00100000);
+ Reserve(Dll2 + 0x40100000 + DllSize, 0x00010000);
+ Reserve(Dll2 + 0x40110000 + DllSize, 0x00001000);
+
+ // Force allocation below moving higher.
+ Reserve(Dll3 - 0x80000000, 0x40000000);
+ Reserve(Dll3 - 0x40000000, 0x00100000);
+ Reserve(Dll3 - 0x3ff00000, 0x00010000);
+ Reserve(Dll3 - 0x3fef0000, 0x00001000);
+ Reserve(Dll3 + DllSize, 0x80000000 - DllSize);
+
+ // Force allocation above moving lower.
+ Reserve(Dll4 - 0x80000000, 0x80000000);
+ Reserve(Dll4 + 0x40000000, 0x40000000);
+ Reserve(Dll4 + 0x3ff00000, 0x00100000);
+ Reserve(Dll4 + 0x3fef0000, 0x00010000);
+ Reserve(Dll4 + 0x3fee0000, 0x00001000);
+
+ // Force allocation above and below.
+ Reserve(Dll5 - 0x7ff00000, 0x7ff00000);
+ Reserve(Dll9 + DllSize, 0x7fe00000);
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll1Function, MineDll1Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ failed:
+ printf("talloc.exe: Error detouring functions: %ld\n", error);
+ exit(1);
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll2Function, MineDll2Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll3Function, MineDll3Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll4Function, MineDll4Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll5Function, MineDll5Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll6Function, MineDll6Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll7Function, MineDll7Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll8Function, MineDll8Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)TrueDll9Function, MineDll9Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ printf("talloc.exe: Detoured functions.\n");
+ printf("\n");
+
+ DumpProcessHeaders();
+ printf("%-47s %17zx\n", "Exe:", (size_t)GetModuleHandleW(NULL));
+ DumpProcess(0x100000000, 0x200000000);
+ printf("%-47s %17zx\n", "Dll1:", Dll1);
+ DumpProcess(0x200000000, 0x300000000);
+ printf("%-47s %17zx\n", "Dll2:", Dll2);
+ DumpProcess(0x300000000, 0x400000000);
+ printf("%-47s %17zx\n", "Dll3:", Dll3);
+ DumpProcess(0x400000000, 0x500000000);
+ printf("%-47s %17zx\n", "Dll4:", Dll4);
+ DumpProcess(0x500000000, 0x600000000);
+ printf("%-47s %17zx\n", "Dll5:", Dll5);
+ DumpProcess(0x600000000, 0x700000000);
+ fflush(stdout);
+
+ Dll1Function(1);
+ Dll2Function(2);
+ Dll2Function(3);
+ Dll3Function(4);
+ Dll3Function(5);
+ Dll3Function(6);
+ Dll4Function(7);
+ Dll5Function(8);
+ Dll6Function(9);
+ Dll7Function(10);
+ Dll8Function(10);
+ Dll9Function(10);
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourDetach(&(PVOID&)TrueDll1Function, MineDll1Function);
+ DetourDetach(&(PVOID&)TrueDll2Function, MineDll2Function);
+ DetourDetach(&(PVOID&)TrueDll3Function, MineDll3Function);
+ DetourDetach(&(PVOID&)TrueDll4Function, MineDll4Function);
+ DetourDetach(&(PVOID&)TrueDll5Function, MineDll5Function);
+ DetourDetach(&(PVOID&)TrueDll6Function, MineDll6Function);
+ DetourDetach(&(PVOID&)TrueDll7Function, MineDll7Function);
+ DetourDetach(&(PVOID&)TrueDll8Function, MineDll8Function);
+ DetourDetach(&(PVOID&)TrueDll9Function, MineDll9Function);
+ error = DetourTransactionCommit();
+ if (error != NO_ERROR) {
+ goto failed;
+ }
+
+ printf("\n");
+ printf("talloc.exe: %ld calls to Dll1Function\n", dwCountDll1);
+ fflush(stdout);
+
+ return 0;
+}
+
+//
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll1x.cpp b/samples/talloc/tdll1x.cpp
new file mode 100644
index 0000000..8edbadc
--- /dev/null
+++ b/samples/talloc/tdll1x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll1x.cpp of talloc.exe/tdll1x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll1Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll2x.cpp b/samples/talloc/tdll2x.cpp
new file mode 100644
index 0000000..c7e394f
--- /dev/null
+++ b/samples/talloc/tdll2x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll2x.cpp of talloc.exe/tdll2x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll2Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll3x.cpp b/samples/talloc/tdll3x.cpp
new file mode 100644
index 0000000..d3610e2
--- /dev/null
+++ b/samples/talloc/tdll3x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll3x.cpp of talloc.exe/tdll3x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll3Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll4x.cpp b/samples/talloc/tdll4x.cpp
new file mode 100644
index 0000000..eb3ab1e
--- /dev/null
+++ b/samples/talloc/tdll4x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll4x.cpp of talloc.exe/tdll4x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll4Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll5x.cpp b/samples/talloc/tdll5x.cpp
new file mode 100644
index 0000000..681ce41
--- /dev/null
+++ b/samples/talloc/tdll5x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll5x.cpp of talloc.exe/tdll5x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll5Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll6x.cpp b/samples/talloc/tdll6x.cpp
new file mode 100644
index 0000000..da2a306
--- /dev/null
+++ b/samples/talloc/tdll6x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll6x.cpp of talloc.exe/tdll6x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll6Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll7x.cpp b/samples/talloc/tdll7x.cpp
new file mode 100644
index 0000000..bcc9927
--- /dev/null
+++ b/samples/talloc/tdll7x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll7x.cpp of talloc.exe/tdll7x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll7Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll8x.cpp b/samples/talloc/tdll8x.cpp
new file mode 100644
index 0000000..2c899e4
--- /dev/null
+++ b/samples/talloc/tdll8x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll8x.cpp of talloc.exe/tdll8x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll8Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/talloc/tdll9x.cpp b/samples/talloc/tdll9x.cpp
new file mode 100644
index 0000000..b8d5c08
--- /dev/null
+++ b/samples/talloc/tdll9x.cpp
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (tdll9x.cpp of talloc.exe/tdll9x.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+//////////////////////////////////////////////////////////////////// DLL Stuff
+//
+__declspec(dllexport) unsigned long __stdcall Dll9Function(unsigned long Value)
+{
+ return Value + 1;
+}
+
+///////////////////////////////////////////////////////////////// End of File.