aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/dtest
diff options
context:
space:
mode:
Diffstat (limited to 'samples/dtest')
-rw-r--r--samples/dtest/Makefile107
-rw-r--r--samples/dtest/NORMAL_IA64.TXT116
-rw-r--r--samples/dtest/NORMAL_X64.TXT116
-rw-r--r--samples/dtest/NORMAL_X86.TXT116
-rw-r--r--samples/dtest/dtarge.cpp306
-rw-r--r--samples/dtest/dtarge.h60
-rw-r--r--samples/dtest/dtarge.rc17
-rw-r--r--samples/dtest/dtest.cpp658
8 files changed, 1496 insertions, 0 deletions
diff --git a/samples/dtest/Makefile b/samples/dtest/Makefile
new file mode 100644
index 0000000..1179c19
--- /dev/null
+++ b/samples/dtest/Makefile
@@ -0,0 +1,107 @@
+##############################################################################
+##
+## Makefile for Detours Test Programs.
+##
+## Microsoft Research Detours Package
+##
+## Copyright (c) Microsoft Corporation. All rights reserved.
+##
+
+!include ..\common.mak
+
+LIBS=$(LIBS) kernel32.lib
+
+all: dirs \
+ $(BIND)\dtarge$(DETOURS_BITS).dll \
+ $(BIND)\dtest.exe \
+!IF $(DETOURS_SOURCE_BROWSING)==1
+ $(OBJD)\dtarge$(DETOURS_BITS).bsc \
+ $(OBJD)\dtest.bsc \
+!ENDIF
+ option
+
+clean:
+ -del *~ *.obj *.sbr 2> nul
+ -del $(BIND)\dtest.* $(BIND)\dtarge*.* 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)\dtarge.obj : dtarge.cpp
+
+$(OBJD)\dtarge.res : dtarge.rc
+
+$(BIND)\dtarge$(DETOURS_BITS).dll $(BIND)\dtarge$(DETOURS_BITS).lib: \
+ $(OBJD)\dtarge.obj $(OBJD)\dtarge.res $(DEPS)
+ cl /LD $(CFLAGS) \
+ /Fe$(@R).dll \
+ /Fd$(@R).pdb \
+ $(OBJD)\dtarge.obj $(OBJD)\dtarge.res \
+ /link $(LINKFLAGS) /subsystem:console \
+ /export:Target0 \
+ /export:Target1 \
+ /export:Target2 \
+ /export:Target3 \
+ /export:Target4 \
+ /export:Target5 \
+ /export:Target6 \
+ /export:Target7 \
+ /export:Target8 \
+ /export:Target9 \
+ /export:Target10 \
+ /export:Target11 \
+ /export:Target12 \
+ /export:Target13 \
+ /export:Target14 \
+ /export:Target15 \
+ /export:Target16 \
+ /export:TargetV \
+ /export:TargetR \
+ $(LIBS)
+
+$(OBJD)\dtarge$(DETOURS_BITS).bsc : $(OBJD)\dtarge.obj
+ bscmake /v /n /o $@ $(OBJD)\dtarge.sbr
+
+$(OBJD)\dtest.obj : dtest.cpp
+
+$(BIND)\dtest.exe : $(OBJD)\dtest.obj $(BIND)\dtarge$(DETOURS_BITS).lib $(DEPS)
+ cl $(CFLAGS) /Fe$@ /Fd$(@R).pdb $(OBJD)\dtest.obj \
+ /link $(LINKFLAGS) $(LIBS) $(BIND)\dtarge$(DETOURS_BITS).lib \
+ /subsystem:console /entry:WinMainCRTStartup
+
+$(OBJD)\dtest.bsc : $(OBJD)\dtest.obj
+ bscmake /v /n /o $@ $(OBJD)\dtest.sbr
+
+############################################### Install non-bit-size binaries.
+
+!IF "$(DETOURS_OPTION_PROCESSOR)" != ""
+
+$(OPTD)\dtarge$(DETOURS_OPTION_BITS).dll:
+$(OPTD)\dtarge$(DETOURS_OPTION_BITS).pdb:
+
+$(BIND)\dtarge$(DETOURS_OPTION_BITS).dll : $(OPTD)\dtarge$(DETOURS_OPTION_BITS).dll
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+$(BIND)\dtarge$(DETOURS_OPTION_BITS).pdb : $(OPTD)\dtarge$(DETOURS_OPTION_BITS).pdb
+ @if exist $? copy /y $? $(BIND) >nul && echo $@ copied from $(DETOURS_OPTION_PROCESSOR).
+
+option: \
+ $(BIND)\dtarge$(DETOURS_OPTION_BITS).dll \
+ $(BIND)\dtarge$(DETOURS_OPTION_BITS).pdb \
+
+!ELSE
+
+option:
+
+!ENDIF
+
+##############################################################################
+
+test: all
+ $(BIND)\dtest.exe
+
+################################################################# End of File.
diff --git a/samples/dtest/NORMAL_IA64.TXT b/samples/dtest/NORMAL_IA64.TXT
new file mode 100644
index 0000000..f87afa5
--- /dev/null
+++ b/samples/dtest/NORMAL_IA64.TXT
@@ -0,0 +1,116 @@
+ ..\..\bin.IA64\dtest.exe
+Calling LocalTarget1 w/o detour
+ LocalTarget1 (1)
+Calling LocalTarget1 w/ detour
+ MyLocalTarget1 (2)
+ LocalTarget1 (2)
+Calling Target0 function.
+ MyTarget0 ()
+Calling TargetN functions.
+ MyLocalTarget1 (1)
+ LocalTarget1 (1)
+ MyTarget0 ()
+ MyTarget1 (1)
+ MyTarget2 (1,2)
+ MyTarget3 (1,2,3)
+ MyTarget4 (1,2,3,4)
+ MyTarget5 (1,2,3,4,5)
+ MyTarget6 (1,2,3,4,5,6)
+ MyTarget7 (1,2,3,4,5,6,7)
+ MyTarget8 (1,2,3,4,5,6,7,8)
+ MyTarget9 (1,2,3,4,5,6,7,8,9)
+ MyTarget10(1,2,3,4,5,6,7,8,9,10)
+ MyTarget11(1,2,3,4,5,6,7,8,9,10,11)
+ MyTarget12(1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTarget13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTarget14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTarget15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTarget16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetV (0)
+ MyTargetV (0,1)
+ MyTargetV (0,1,2)
+ MyTargetV (0,1,2,3)
+ MyTargetV (0,1,2,3,4)
+ MyTargetV (0,1,2,3,4,5)
+ MyTargetV (0,1,2,3,4,5,6)
+ MyTargetV (0,1,2,3,4,5,6,7)
+ MyTargetV (0,1,2,3,4,5,6,7,8)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetR (0,1,2,3,4)
+ MyTargetR (0,1,2,3,3)
+ MyTargetR (0,1,2,3,2)
+ MyTargetR (0,1,2,3,1)
+.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... MyTargetR (0,1,2,3,4,5,6,7,8,9,10,4)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,3)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,2)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ => 3011
+Calling Target0 again with 1 detour.
+ MyTarget0 ()
+Calling Target0 again with 2 detours.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+Calling Target0 again with 3 detours.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+Calling Target0 again with 4 detours.
+ Starting Target0_3.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+ End Target0_3.
+Done.
+ Target0 ()
+ Target0 ()
+ Target1 (1)
+ Target2 (1,2)
+ Target3 (1,2,3)
+ Target4 (1,2,3,4)
+ Target5 (1,2,3,4,5)
+ Target6 (1,2,3,4,5,6)
+ Target7 (1,2,3,4,5,6,7)
+ Target8 (1,2,3,4,5,6,7,8)
+ Target9 (1,2,3,4,5,6,7,8,9)
+ Target10(1,2,3,4,5,6,7,8,9,10)
+ Target11(1,2,3,4,5,6,7,8,9,10,11)
+ Target12(1,2,3,4,5,6,7,8,9,10,11,12)
+ Target13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ Target14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ Target15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ Target16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ TargetV (0)
+ TargetV (0,1)
+ TargetV (0,1,2)
+ TargetV (0,1,2,3)
+ TargetV (0,1,2,3,4)
+ TargetV (0,1,2,3,4,5)
+ TargetV (0,1,2,3,4,5,6)
+ TargetV (0,1,2,3,4,5,6,7)
+ TargetV (0,1,2,3,4,5,6,7,8)
+ TargetV (0,1,2,3,4,5,6,7,8,9)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+::: TargetR (0,1,2,3,1)
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: TargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ Target0 ()
+ Target0 ()
+ Target0 ()
+ Target0 ()
diff --git a/samples/dtest/NORMAL_X64.TXT b/samples/dtest/NORMAL_X64.TXT
new file mode 100644
index 0000000..9758c03
--- /dev/null
+++ b/samples/dtest/NORMAL_X64.TXT
@@ -0,0 +1,116 @@
+ ..\..\bin.X64\dtest.exe
+Calling LocalTarget1 w/o detour
+ LocalTarget1 (1)
+Calling LocalTarget1 w/ detour
+ MyLocalTarget1 (2)
+ LocalTarget1 (2)
+Calling Target0 function.
+ MyTarget0 ()
+Calling TargetN functions.
+ MyLocalTarget1 (1)
+ LocalTarget1 (1)
+ MyTarget0 ()
+ MyTarget1 (1)
+ MyTarget2 (1,2)
+ MyTarget3 (1,2,3)
+ MyTarget4 (1,2,3,4)
+ MyTarget5 (1,2,3,4,5)
+ MyTarget6 (1,2,3,4,5,6)
+ MyTarget7 (1,2,3,4,5,6,7)
+ MyTarget8 (1,2,3,4,5,6,7,8)
+ MyTarget9 (1,2,3,4,5,6,7,8,9)
+ MyTarget10(1,2,3,4,5,6,7,8,9,10)
+ MyTarget11(1,2,3,4,5,6,7,8,9,10,11)
+ MyTarget12(1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTarget13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTarget14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTarget15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTarget16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetV (0)
+ MyTargetV (0,1)
+ MyTargetV (0,1,2)
+ MyTargetV (0,1,2,3)
+ MyTargetV (0,1,2,3,4)
+ MyTargetV (0,1,2,3,4,5)
+ MyTargetV (0,1,2,3,4,5,6)
+ MyTargetV (0,1,2,3,4,5,6,7)
+ MyTargetV (0,1,2,3,4,5,6,7,8)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetR (0,1,2,3,4)
+ MyTargetR (0,1,2,3,3)
+ MyTargetR (0,1,2,3,2)
+ MyTargetR (0,1,2,3,1)
+.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... MyTargetR (0,1,2,3,4,5,6,7,8,9,10,4)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,3)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,2)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ => 3011
+Calling Target0 again with 1 detour.
+ MyTarget0 ()
+Calling Target0 again with 2 detours.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+Calling Target0 again with 3 detours.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+Calling Target0 again with 4 detours.
+ Starting Target0_3.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+ End Target0_3.
+Done.
+ Target0 ()
+ Target0 ()
+ Target1 (1)
+ Target2 (1,2)
+ Target3 (1,2,3)
+ Target4 (1,2,3,4)
+ Target5 (1,2,3,4,5)
+ Target6 (1,2,3,4,5,6)
+ Target7 (1,2,3,4,5,6,7)
+ Target8 (1,2,3,4,5,6,7,8)
+ Target9 (1,2,3,4,5,6,7,8,9)
+ Target10(1,2,3,4,5,6,7,8,9,10)
+ Target11(1,2,3,4,5,6,7,8,9,10,11)
+ Target12(1,2,3,4,5,6,7,8,9,10,11,12)
+ Target13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ Target14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ Target15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ Target16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ TargetV (0)
+ TargetV (0,1)
+ TargetV (0,1,2)
+ TargetV (0,1,2,3)
+ TargetV (0,1,2,3,4)
+ TargetV (0,1,2,3,4,5)
+ TargetV (0,1,2,3,4,5,6)
+ TargetV (0,1,2,3,4,5,6,7)
+ TargetV (0,1,2,3,4,5,6,7,8)
+ TargetV (0,1,2,3,4,5,6,7,8,9)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+::: TargetR (0,1,2,3,1)
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: TargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ Target0 ()
+ Target0 ()
+ Target0 ()
+ Target0 ()
diff --git a/samples/dtest/NORMAL_X86.TXT b/samples/dtest/NORMAL_X86.TXT
new file mode 100644
index 0000000..90ab0c8
--- /dev/null
+++ b/samples/dtest/NORMAL_X86.TXT
@@ -0,0 +1,116 @@
+ ..\..\bin.X86\dtest.exe
+Calling LocalTarget1 w/o detour
+ LocalTarget1 (1)
+Calling LocalTarget1 w/ detour
+ MyLocalTarget1 (2)
+ LocalTarget1 (2)
+Calling Target0 function.
+ MyTarget0 ()
+Calling TargetN functions.
+ MyLocalTarget1 (1)
+ LocalTarget1 (1)
+ MyTarget0 ()
+ MyTarget1 (1)
+ MyTarget2 (1,2)
+ MyTarget3 (1,2,3)
+ MyTarget4 (1,2,3,4)
+ MyTarget5 (1,2,3,4,5)
+ MyTarget6 (1,2,3,4,5,6)
+ MyTarget7 (1,2,3,4,5,6,7)
+ MyTarget8 (1,2,3,4,5,6,7,8)
+ MyTarget9 (1,2,3,4,5,6,7,8,9)
+ MyTarget10(1,2,3,4,5,6,7,8,9,10)
+ MyTarget11(1,2,3,4,5,6,7,8,9,10,11)
+ MyTarget12(1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTarget13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTarget14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTarget15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTarget16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetV (0)
+ MyTargetV (0,1)
+ MyTargetV (0,1,2)
+ MyTargetV (0,1,2,3)
+ MyTargetV (0,1,2,3,4)
+ MyTargetV (0,1,2,3,4,5)
+ MyTargetV (0,1,2,3,4,5,6)
+ MyTargetV (0,1,2,3,4,5,6,7)
+ MyTargetV (0,1,2,3,4,5,6,7,8)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ MyTargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ MyTargetR (0,1,2,3,4)
+ MyTargetR (0,1,2,3,3)
+ MyTargetR (0,1,2,3,2)
+ MyTargetR (0,1,2,3,1)
+.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... MyTargetR (0,1,2,3,4,5,6,7,8,9,10,4)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,3)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,2)
+ MyTargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ => 3011
+Calling Target0 again with 1 detour.
+ MyTarget0 ()
+Calling Target0 again with 2 detours.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+Calling Target0 again with 3 detours.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+Calling Target0 again with 4 detours.
+ Starting Target0_3.
+ Starting Target0_2.
+ Starting Target0_1.
+ MyTarget0 ()
+ End Target0_1.
+ End Target0_2.
+ End Target0_3.
+Done.
+ Target0 ()
+ Target0 ()
+ Target1 (1)
+ Target2 (1,2)
+ Target3 (1,2,3)
+ Target4 (1,2,3,4)
+ Target5 (1,2,3,4,5)
+ Target6 (1,2,3,4,5,6)
+ Target7 (1,2,3,4,5,6,7)
+ Target8 (1,2,3,4,5,6,7,8)
+ Target9 (1,2,3,4,5,6,7,8,9)
+ Target10(1,2,3,4,5,6,7,8,9,10)
+ Target11(1,2,3,4,5,6,7,8,9,10,11)
+ Target12(1,2,3,4,5,6,7,8,9,10,11,12)
+ Target13(1,2,3,4,5,6,7,8,9,10,11,12,13)
+ Target14(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ Target15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ Target16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ TargetV (0)
+ TargetV (0,1)
+ TargetV (0,1,2)
+ TargetV (0,1,2,3)
+ TargetV (0,1,2,3,4)
+ TargetV (0,1,2,3,4,5)
+ TargetV (0,1,2,3,4,5,6)
+ TargetV (0,1,2,3,4,5,6,7)
+ TargetV (0,1,2,3,4,5,6,7,8)
+ TargetV (0,1,2,3,4,5,6,7,8,9)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
+ TargetV (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+::: TargetR (0,1,2,3,1)
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: TargetR (0,1,2,3,4,5,6,7,8,9,10,1)
+ Target0 ()
+ Target0 ()
+ Target0 ()
+ Target0 ()
diff --git a/samples/dtest/dtarge.cpp b/samples/dtest/dtarge.cpp
new file mode 100644
index 0000000..2cd4534
--- /dev/null
+++ b/samples/dtest/dtarge.cpp
@@ -0,0 +1,306 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (dtarge.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+#include <stdio.h>
+#include <windows.h>
+#include "dtarge.h"
+
+DWORD_PTR WINAPI Target0()
+{
+ printf(" Target0 ()\n");
+ return 1000;
+}
+
+DWORD_PTR WINAPI Target1(DWORD_PTR v1)
+{
+ printf(" Target1 (%ld)\n",
+ (DWORD)v1);
+ return 1001;
+}
+
+DWORD_PTR WINAPI Target2(DWORD_PTR v1, DWORD_PTR v2)
+{
+ printf(" Target2 (%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2);
+ return 1002;
+}
+
+DWORD_PTR WINAPI Target3(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3)
+{
+ printf(" Target3 (%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3);
+ return 1003;
+}
+
+DWORD_PTR WINAPI Target4(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4)
+{
+ printf(" Target4 (%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4);
+ return 1004;
+}
+
+DWORD_PTR WINAPI Target5(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5)
+{
+ printf(" Target5 (%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5);
+ return 1005;
+}
+
+DWORD_PTR WINAPI Target6(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6)
+{
+ printf(" Target6 (%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6);
+ return 1006;
+}
+
+DWORD_PTR WINAPI Target7(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7)
+{
+ printf(" Target7 (%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7);
+ return 1007;
+}
+
+DWORD_PTR WINAPI Target8(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8)
+{
+ printf(" Target8 (%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8);
+ return 1008;
+}
+
+DWORD_PTR WINAPI Target9(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9)
+{
+ printf(" Target9 (%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9);
+ return 1009;
+}
+
+DWORD_PTR WINAPI Target10(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10)
+{
+ printf(" Target10(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10);
+ return 1010;
+}
+
+DWORD_PTR WINAPI Target11(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11)
+{
+ printf(" Target11(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11);
+ return 1011;
+}
+
+DWORD_PTR WINAPI Target12(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12)
+{
+ printf(" Target12(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12);
+ return 1012;
+}
+
+DWORD_PTR WINAPI Target13(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13)
+{
+ printf(" Target13(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13);
+ return 1013;
+}
+
+DWORD_PTR WINAPI Target14(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14)
+{
+ printf(" Target14(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14);
+ return 1014;
+}
+
+DWORD_PTR WINAPI Target15(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15)
+{
+ printf(" Target15(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14, (DWORD)v15);
+ return 1015;
+}
+
+DWORD_PTR WINAPI Target16(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15, DWORD_PTR v16)
+{
+ printf(" Target16(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14, (DWORD)v15, (DWORD)v16);
+ return 1016;
+}
+
+DWORD_PTR WINAPI TargetV(DWORD_PTR v1, ...)
+{
+ DWORD_PTR args[32];
+
+ va_list va;
+ va_start(va, v1);
+
+ int argc = 0;
+ for (args[argc++] = v1; args[argc-1] != 0;) {
+ args[argc++] = va_arg(va, DWORD_PTR);
+ }
+ va_end(va);
+
+ printf(" TargetV (");
+ int i = argc - 1;
+ for (; i > 0; i--) {
+ printf("%ld,", (DWORD)args[i]);
+ }
+ printf("%ld)\n", (DWORD)args[0]);
+
+ return 1000 + argc;
+}
+
+DWORD_PTR WINAPI TargetR(DWORD_PTR v1, ...)
+{
+ DWORD_PTR args[32];
+
+ va_list va;
+ va_start(va, v1);
+
+ int argc = 0;
+ for (args[argc++] = v1; args[argc-1] != 0;) {
+ args[argc++] = va_arg(va, DWORD_PTR);
+ }
+ va_end(va);
+
+ if (v1 > 1) {
+ printf(":");
+ switch (argc) {
+ default:
+ return TargetR(0) + 1;
+ case 1:
+ return TargetR(args[0] - 1) + 1;
+ case 2:
+ return TargetR(args[0] - 1, args[1]) + 1;
+ case 3:
+ return TargetR(args[0] - 1, args[1], args[2]) + 1;
+ case 4:
+ return TargetR(args[0] - 1, args[1], args[2], args[3]) + 1;
+ case 5:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4]) + 1;
+ case 6:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5]) + 1;
+ case 7:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6]) + 1;
+ case 8:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7]) + 1;
+ case 9:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8]) + 1;
+ case 10:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9]) + 1;
+ case 11:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10]) + 1;
+ case 12:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11]) + 1;
+ case 13:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12]) + 1;
+ case 14:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13]) + 1;
+ case 15:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14]) + 1;
+ case 16:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15]) + 1;
+ case 17:
+ return TargetR(args[0] - 1, args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15],
+ args[16]) + 1;
+ }
+ }
+
+ printf(" TargetR (");
+ int i = argc - 1;
+ for (; i > 0; i--) {
+ printf("%ld,", (DWORD)args[i]);
+ }
+ printf("%ld)\n", (DWORD)args[0]);
+
+ return 2000 + argc;
+}
+
+
+BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
+{
+ (void)hinst;
+ (void)dwReason;
+ (void)reserved;
+
+ return TRUE;
+}
+
+//
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/dtest/dtarge.h b/samples/dtest/dtarge.h
new file mode 100644
index 0000000..7aa5cd6
--- /dev/null
+++ b/samples/dtest/dtarge.h
@@ -0,0 +1,60 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (dtarge.h of dtarge.dll)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+#pragma once
+
+#if (_MSC_VER < 1299)
+typedef DWORD DWORD_PTR;
+#endif
+
+DWORD_PTR WINAPI Target0();
+DWORD_PTR WINAPI Target1(DWORD_PTR v1);
+DWORD_PTR WINAPI Target2(DWORD_PTR v1, DWORD_PTR v2);
+DWORD_PTR WINAPI Target3(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3);
+DWORD_PTR WINAPI Target4(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4);
+DWORD_PTR WINAPI Target5(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5);
+DWORD_PTR WINAPI Target6(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6);
+DWORD_PTR WINAPI Target7(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7);
+DWORD_PTR WINAPI Target8(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8);
+DWORD_PTR WINAPI Target9(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9);
+DWORD_PTR WINAPI Target10(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10);
+DWORD_PTR WINAPI Target11(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11);
+DWORD_PTR WINAPI Target12(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12);
+DWORD_PTR WINAPI Target13(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13);
+DWORD_PTR WINAPI Target14(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14);
+DWORD_PTR WINAPI Target15(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15);
+DWORD_PTR WINAPI Target16(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15, DWORD_PTR v16);
+DWORD_PTR WINAPI TargetV(DWORD_PTR v1, ...);
+DWORD_PTR WINAPI TargetR(DWORD_PTR v1, ...);
+
+//
+///////////////////////////////////////////////////////////////// End of File.
diff --git a/samples/dtest/dtarge.rc b/samples/dtest/dtarge.rc
new file mode 100644
index 0000000..1a66b51
--- /dev/null
+++ b/samples/dtest/dtarge.rc
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Version information for dtarge.rc.
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+
+#include "detver.h"
+
+#define VER_INTERNALNAME_STR "dtarge" DETOURS_STRINGIFY(DETOURS_BITS)
+#define VER_ORIGINALFILENAME_STR "dtarge" DETOURS_STRINGIFY(DETOURS_BITS) ".dll"
+#define VER_FILEDESCRIPTION_STR "Detours Test Module"
+#define VER_COMPANYNAME_STR "Microsoft Corporation"
+
+#include "common.ver"
diff --git a/samples/dtest/dtest.cpp b/samples/dtest/dtest.cpp
new file mode 100644
index 0000000..f7de56d
--- /dev/null
+++ b/samples/dtest/dtest.cpp
@@ -0,0 +1,658 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// Detours Test Program (dtest.cpp of dtest.exe)
+//
+// Microsoft Research Detours Package
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//
+#include <stdio.h>
+#include <stdarg.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 <detours.h>
+#include "dtarge.h"
+
+DWORD_PTR WINAPI LocalTarget1(DWORD_PTR v1);
+
+////////////////////////////////////////////////////// Multi-Argument Detours.
+//
+DWORD_PTR (WINAPI * Trampoline_LocalTarget1)(DWORD_PTR v1) = LocalTarget1;
+
+DWORD_PTR (WINAPI * Trampoline_Target0)() = Target0;
+DWORD_PTR (WINAPI * Trampoline_Target1)(DWORD_PTR v1) = Target1;
+DWORD_PTR (WINAPI * Trampoline_Target2)(DWORD_PTR v1, DWORD_PTR v2) = Target2;
+DWORD_PTR (WINAPI * Trampoline_Target3)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3) = Target3;
+DWORD_PTR (WINAPI * Trampoline_Target4)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4) = Target4;
+DWORD_PTR (WINAPI * Trampoline_Target5)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5) = Target5;
+DWORD_PTR (WINAPI * Trampoline_Target6)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6) = Target6;
+DWORD_PTR (WINAPI * Trampoline_Target7)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7) = Target7;
+DWORD_PTR (WINAPI * Trampoline_Target8)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8) = Target8;
+DWORD_PTR (WINAPI * Trampoline_Target9)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9) = Target9;
+DWORD_PTR (WINAPI * Trampoline_Target10)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10) = Target10;
+DWORD_PTR (WINAPI * Trampoline_Target11)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11) = Target11;
+DWORD_PTR (WINAPI * Trampoline_Target12)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12) = Target12;
+DWORD_PTR (WINAPI * Trampoline_Target13)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13) = Target13;
+DWORD_PTR (WINAPI * Trampoline_Target14)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14) = Target14;
+DWORD_PTR (WINAPI * Trampoline_Target15)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15) = Target15;
+DWORD_PTR (WINAPI * Trampoline_Target16)
+ (DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15, DWORD_PTR v16) = Target16;
+DWORD_PTR (WINAPI * Trampoline_TargetV)(DWORD_PTR v1, ...) = TargetV;
+DWORD_PTR (WINAPI * Trampoline_TargetR)(DWORD_PTR v1, ...) = TargetR;
+
+//////////////////////////////////////////////////////////////////////////////
+//
+VOID dprintf(const char * fmt, ...)
+{
+ CHAR szBuf[1024];
+
+ va_list args;
+ va_start(args, fmt);
+ StringCchPrintfA(szBuf, sizeof(szBuf), fmt, args);
+ va_end(args);
+
+ OutputDebugStringA(szBuf);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//
+DWORD_PTR WINAPI LocalTarget1(DWORD_PTR v1)
+{
+ printf(" LocalTarget1 (%ld)\n", (DWORD)v1);
+ // dprintf("LocalTarget1\n");
+ // __debugbreak();
+ return 9000;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//
+DWORD_PTR WINAPI MyLocalTarget1(DWORD_PTR v1)
+{
+ printf(" MyLocalTarget1 (%ld)\n",
+ (DWORD)v1);
+ // dprintf("LocalTarget1, Trampoline_LocalTarget1=%p\n", Trampoline_LocalTarget1);
+ return Trampoline_LocalTarget1(v1);
+}
+
+DWORD_PTR WINAPI MyTarget0()
+{
+ printf(" MyTarget0 ()\n");
+ return Trampoline_Target0();
+}
+
+DWORD_PTR WINAPI MyTarget1(DWORD_PTR v1)
+{
+ printf(" MyTarget1 (%ld)\n",
+ (DWORD)v1);
+ return Trampoline_Target1(v1);
+}
+
+DWORD_PTR WINAPI MyTarget2(DWORD_PTR v1, DWORD_PTR v2)
+{
+ printf(" MyTarget2 (%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2);
+ return Trampoline_Target2(v1,v2);
+}
+
+DWORD_PTR WINAPI MyTarget3(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3)
+{
+ printf(" MyTarget3 (%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3);
+ return Trampoline_Target3(v1,v2,v3);
+}
+
+DWORD_PTR WINAPI MyTarget4(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4)
+{
+ printf(" MyTarget4 (%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4);
+ return Trampoline_Target4(v1,v2,v3,v4);
+}
+
+DWORD_PTR WINAPI MyTarget5(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5)
+{
+ printf(" MyTarget5 (%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5);
+ return Trampoline_Target5(v1,v2,v3,v4,v5);
+}
+
+DWORD_PTR WINAPI MyTarget6(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6)
+{
+ printf(" MyTarget6 (%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6);
+ return Trampoline_Target6(v1,v2,v3,v4,v5,v6);
+}
+
+DWORD_PTR WINAPI MyTarget7(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7)
+{
+ printf(" MyTarget7 (%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7);
+ return Trampoline_Target7(v1,v2,v3,v4,v5,v6,v7);
+}
+
+DWORD_PTR WINAPI MyTarget8(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8)
+{
+ printf(" MyTarget8 (%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8);
+ return Trampoline_Target8(v1,v2,v3,v4,v5,v6,v7,v8);
+}
+
+DWORD_PTR WINAPI MyTarget9(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9)
+{
+ printf(" MyTarget9 (%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9);
+ return Trampoline_Target9(v1,v2,v3,v4,v5,v6,v7,v8,v9);
+}
+
+DWORD_PTR WINAPI MyTarget10(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10)
+{
+ printf(" MyTarget10(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10);
+ return Trampoline_Target10(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10);
+}
+
+DWORD_PTR WINAPI MyTarget11(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11)
+{
+ printf(" MyTarget11(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11);
+ return Trampoline_Target11(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11);
+}
+
+DWORD_PTR WINAPI MyTarget12(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12)
+{
+ printf(" MyTarget12(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12);
+ return Trampoline_Target12(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12);
+}
+
+DWORD_PTR WINAPI MyTarget13(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13)
+{
+ printf(" MyTarget13(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13);
+ return Trampoline_Target13(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13);
+}
+
+DWORD_PTR WINAPI MyTarget14(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14)
+{
+ printf(" MyTarget14(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14);
+ return Trampoline_Target14(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14);
+}
+
+DWORD_PTR WINAPI MyTarget15(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15)
+{
+ printf(" MyTarget15(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14, (DWORD)v15);
+ return Trampoline_Target15(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15);
+}
+
+DWORD_PTR WINAPI MyTarget16(DWORD_PTR v1, DWORD_PTR v2, DWORD_PTR v3, DWORD_PTR v4,
+ DWORD_PTR v5, DWORD_PTR v6, DWORD_PTR v7, DWORD_PTR v8,
+ DWORD_PTR v9, DWORD_PTR v10, DWORD_PTR v11, DWORD_PTR v12,
+ DWORD_PTR v13, DWORD_PTR v14, DWORD_PTR v15, DWORD_PTR v16)
+{
+ printf(" MyTarget16(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)\n",
+ (DWORD)v1, (DWORD)v2, (DWORD)v3, (DWORD)v4,
+ (DWORD)v5, (DWORD)v6, (DWORD)v7, (DWORD)v8,
+ (DWORD)v9, (DWORD)v10, (DWORD)v11, (DWORD)v12,
+ (DWORD)v13, (DWORD)v14, (DWORD)v15, (DWORD)v16);
+ return Trampoline_Target16(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16);
+}
+
+DWORD_PTR WINAPI MyTargetV(DWORD_PTR v1, ...)
+{
+ DWORD_PTR args[32];
+
+ va_list va;
+ va_start(va, v1);
+
+ int argc = 0;
+ for (args[argc++] = v1; args[argc-1] != 0;) {
+ args[argc++] = va_arg(va, DWORD_PTR);
+ }
+ va_end(va);
+
+ printf(" MyTargetV (");
+ int i = argc - 1;
+ for (; i > 0; i--) {
+ printf("%ld,", (DWORD)args[i]);
+ }
+ printf("%ld)\n", (DWORD)args[0]);
+
+ switch (argc) {
+ default:
+ return Trampoline_TargetV(0);
+ case 1:
+ return Trampoline_TargetV(args[0]);
+ case 2:
+ return Trampoline_TargetV(args[0], args[1]);
+ case 3:
+ return Trampoline_TargetV(args[0], args[1], args[2]);
+ case 4:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3]);
+ case 5:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4]);
+ case 6:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5]);
+ case 7:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6]);
+ case 8:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7]);
+ case 9:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8]);
+ case 10:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9]);
+ case 11:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10]);
+ case 12:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11]);
+ case 13:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12]);
+ case 14:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13]);
+ case 15:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14]);
+ case 16:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15]);
+ case 17:
+ return Trampoline_TargetV(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15],
+ args[16]);
+ }
+}
+
+DWORD_PTR WINAPI MyTargetR(DWORD_PTR v1, ...)
+{
+ DWORD_PTR args[32];
+
+ va_list va;
+ va_start(va, v1);
+
+ int argc = 0;
+ for (args[argc++] = v1; args[argc-1] != 0;) {
+ args[argc++] = va_arg(va, DWORD_PTR);
+ }
+ va_end(va);
+
+ if (v1 < 5) {
+ printf(" MyTargetR (");
+ int i = argc - 1;
+ for (; i > 0; i--) {
+ printf("%ld,", (DWORD)args[i]);
+ }
+ printf("%ld)\n", (DWORD)args[0]);
+ }
+ else {
+ printf(".");
+ }
+
+ switch (argc) {
+ default:
+ return Trampoline_TargetR(0);
+ case 1:
+ return Trampoline_TargetR(args[0]);
+ case 2:
+ return Trampoline_TargetR(args[0], args[1]);
+ case 3:
+ return Trampoline_TargetR(args[0], args[1], args[2]);
+ case 4:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3]);
+ case 5:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4]);
+ case 6:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5]);
+ case 7:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6]);
+ case 8:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7]);
+ case 9:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8]);
+ case 10:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9]);
+ case 11:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10]);
+ case 12:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11]);
+ case 13:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12]);
+ case 14:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13]);
+ case 15:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14]);
+ case 16:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15]);
+ case 17:
+ return Trampoline_TargetR(args[0], args[1], args[2], args[3],
+ args[4], args[5], args[6], args[7],
+ args[8], args[9], args[10], args[11],
+ args[12], args[13], args[14], args[15],
+ args[16]);
+ }
+}
+
+/////////////////////////////////////////////////////////// Recursive Detours.
+//
+DWORD_PTR (WINAPI * Trampoline_Target0_1)() = NULL;
+DWORD_PTR (WINAPI * Trampoline_Target0_2)() = NULL;
+DWORD_PTR (WINAPI * Trampoline_Target0_3)() = NULL;
+
+static DWORD_PTR WINAPI MyTarget0_1()
+{
+ printf(" Starting Target0_1.\n");
+ DWORD_PTR rv = Trampoline_Target0_1();
+ printf(" End Target0_1.\n");
+ return rv;
+}
+
+static DWORD_PTR WINAPI MyTarget0_2()
+{
+ printf(" Starting Target0_2.\n");
+ DWORD_PTR rv = Trampoline_Target0_2();
+ printf(" End Target0_2.\n");
+ return rv;
+}
+
+static DWORD_PTR WINAPI MyTarget0_3()
+{
+ printf(" Starting Target0_3.\n");
+ DWORD_PTR rv = Trampoline_Target0_3();
+ printf(" End Target0_3.\n");
+ return rv;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//
+int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR lpszCmdLine, int nCmdShow)
+{
+ (void)hinst;
+ (void)hprev;
+ (void)lpszCmdLine;
+ (void)nCmdShow;
+
+ printf("Calling LocalTarget1 w/o detour\n");
+ LocalTarget1(1);
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_LocalTarget1, MyLocalTarget1);
+ DetourTransactionCommit();
+
+ printf("Calling LocalTarget1 w/ detour\n");
+ LocalTarget1(2);
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_Target0, MyTarget0);
+ DetourTransactionCommit();
+
+ printf("Calling Target0 function.\n");
+ //dprintf("- Trampoline_Target0:: %p\n", Trampoline_Target0);
+ //dprintf("- Target0 :: %p\n", Target0);
+ Target0();
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_Target1, MyTarget1);
+ DetourAttach(&(PVOID&)Trampoline_Target2, MyTarget2);
+ DetourAttach(&(PVOID&)Trampoline_Target3, MyTarget3);
+ DetourAttach(&(PVOID&)Trampoline_Target4, MyTarget4);
+ DetourAttach(&(PVOID&)Trampoline_Target5, MyTarget5);
+ DetourAttach(&(PVOID&)Trampoline_Target6, MyTarget6);
+ DetourAttach(&(PVOID&)Trampoline_Target7, MyTarget7);
+ DetourAttach(&(PVOID&)Trampoline_Target8, MyTarget8);
+ DetourAttach(&(PVOID&)Trampoline_Target9, MyTarget9);
+ DetourAttach(&(PVOID&)Trampoline_Target10, MyTarget10);
+ DetourAttach(&(PVOID&)Trampoline_Target11, MyTarget11);
+ DetourAttach(&(PVOID&)Trampoline_Target12, MyTarget12);
+ DetourAttach(&(PVOID&)Trampoline_Target13, MyTarget13);
+ DetourAttach(&(PVOID&)Trampoline_Target14, MyTarget14);
+ DetourAttach(&(PVOID&)Trampoline_Target15, MyTarget15);
+ DetourAttach(&(PVOID&)Trampoline_Target16, MyTarget16);
+ DetourAttach(&(PVOID&)Trampoline_TargetV, MyTargetV);
+ DetourAttach(&(PVOID&)Trampoline_TargetR, MyTargetR);
+ DetourTransactionCommit();
+
+ printf("Calling TargetN functions.\n");
+ LocalTarget1(1);
+ Target0();
+ Target1(1);
+ Target2(1,2);
+ Target3(1,2,3);
+ Target4(1,2,3,4);
+ Target5(1,2,3,4,5);
+ Target6(1,2,3,4,5,6);
+ Target7(1,2,3,4,5,6,7);
+ Target8(1,2,3,4,5,6,7,8);
+ Target9(1,2,3,4,5,6,7,8,9);
+ Target10(1,2,3,4,5,6,7,8,9,10);
+ Target11(1,2,3,4,5,6,7,8,9,10,11);
+ Target12(1,2,3,4,5,6,7,8,9,10,11,12);
+ Target13(1,2,3,4,5,6,7,8,9,10,11,12,13);
+ Target14(1,2,3,4,5,6,7,8,9,10,11,12,13,14);
+ Target15(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
+ Target16(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
+ TargetV(0);
+ TargetV(1,0);
+ TargetV(2,1,0);
+ TargetV(3,2,1,0);
+ TargetV(4,3,2,1,0);
+ TargetV(5,4,3,2,1,0);
+ TargetV(6,5,4,3,2,1,0);
+ TargetV(7,6,5,4,3,2,1,0);
+ TargetV(8,7,6,5,4,3,2,1,0);
+ TargetV(9,8,7,6,5,4,3,2,1,0);
+ TargetV(10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(12,11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(13,12,11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetV(16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
+ TargetR(4,3,2,1,0);
+ DWORD_PTR rv = TargetR(100,10,9,8,7,6,5,4,3,2,1,0);
+ printf(" => %ld\n", (DWORD)rv);
+
+ Trampoline_Target0_1 = Target0;
+ Trampoline_Target0_2 = Target0;
+ Trampoline_Target0_3 = Target0;
+
+ //dprintf("Trampoline_Target0_1 = %p\n", DetourCodeFromPointer(Trampoline_Target0_1, NULL));
+ //__debugbreak();
+
+ printf("Calling Target0 again with 1 detour.\n");
+ Target0();
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_Target0_1, MyTarget0_1);
+ DetourTransactionCommit();
+
+ //dprintf("Trampoline_Target0_2 = %p\n", DetourCodeFromPointer(Trampoline_Target0_2, NULL));
+ //__debugbreak();
+ printf("Calling Target0 again with 2 detours.\n");
+ Target0();
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_Target0_2, MyTarget0_2);
+ DetourTransactionCommit();
+
+ //dprintf("Trampoline_Target0_3 = %p\n", DetourCodeFromPointer(Trampoline_Target0_3, NULL));
+ //__debugbreak();
+ printf("Calling Target0 again with 3 detours.\n");
+ Target0();
+
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&(PVOID&)Trampoline_Target0_3, MyTarget0_3);
+ DetourTransactionCommit();
+
+ //dprintf("Trampoline_Target0_3 = %p\n", DetourCodeFromPointer(Trampoline_Target0_3, NULL));
+ //__debugbreak();
+ printf("Calling Target0 again with 4 detours.\n");
+ Target0();
+
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourDetach(&(PVOID&)Trampoline_Target0, MyTarget0);
+ DetourDetach(&(PVOID&)Trampoline_Target1, MyTarget1);
+ DetourDetach(&(PVOID&)Trampoline_Target2, MyTarget2);
+ DetourDetach(&(PVOID&)Trampoline_Target3, MyTarget3);
+ DetourDetach(&(PVOID&)Trampoline_Target4, MyTarget4);
+ DetourDetach(&(PVOID&)Trampoline_Target5, MyTarget5);
+ DetourDetach(&(PVOID&)Trampoline_Target6, MyTarget6);
+ DetourDetach(&(PVOID&)Trampoline_Target7, MyTarget7);
+ DetourDetach(&(PVOID&)Trampoline_Target8, MyTarget8);
+ DetourDetach(&(PVOID&)Trampoline_Target9, MyTarget9);
+ DetourDetach(&(PVOID&)Trampoline_Target10, MyTarget10);
+ DetourDetach(&(PVOID&)Trampoline_Target11, MyTarget11);
+ DetourDetach(&(PVOID&)Trampoline_Target12, MyTarget12);
+ DetourDetach(&(PVOID&)Trampoline_Target13, MyTarget13);
+ DetourDetach(&(PVOID&)Trampoline_Target14, MyTarget14);
+ DetourDetach(&(PVOID&)Trampoline_Target15, MyTarget15);
+ DetourDetach(&(PVOID&)Trampoline_Target16, MyTarget16);
+ DetourDetach(&(PVOID&)Trampoline_TargetV, MyTargetV);
+ DetourDetach(&(PVOID&)Trampoline_TargetR, MyTargetR);
+ DetourTransactionCommit();
+
+ printf("Done.\n");
+
+ return 0;
+}
+
+//
+///////////////////////////////////////////////////////////////// End of File.