//プロジェクト名print002 C++ソースファイルprint002.cpp #include int a1,a2,a3,a4; int pre1,pre2,pre3,pre4; DWORD oldprotect; long hdc01; typedef int (__stdcall * f_printa)(struct tagPDA *); f_printa printa; CONST DOCINFO *lpdi; int __stdcall temp01(HDC hdc,CONST DOCINFO *lpdi); int __stdcall temp02(struct tagPDA &lppd01); int __stdcall temp01(HDC hdc,CONST DOCINFO *lpdi) { hdc01=(long)hdc; VirtualProtect((LPVOID)a1,16,PAGE_EXECUTE_READWRITE,&oldprotect); __asm { mov esi,a1 mov eax,pre1 mov [esi],eax mov eax,pre2 mov [esi+4],eax } VirtualProtect((LPVOID)a1,16,PAGE_EXECUTE,&oldprotect); FlushInstructionCache((HANDLE)a1,(LPCVOID)a1,16); int n=StartDoc( hdc , lpdi); return n; } int __stdcall temp02(struct tagPDA &lppd01) { VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE_READWRITE,&oldprotect); __asm { mov esi,a3 mov eax,pre3 mov [esi],eax mov eax,pre4 mov [esi+4],eax } VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE,&oldprotect); FlushInstructionCache((HANDLE)a3,(LPCVOID)a3,16); int n; if ((lppd01.Flags & PD_RETURNDEFAULT)!=0) { n=(int)printa(&lppd01); VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE_READWRITE,&oldprotect); __asm { mov esi,a3 mov al,0xB8 mov [esi],al mov eax,a4 mov [esi+1],eax mov ax,0xC350 mov [esi+5],ax } VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE,&oldprotect); FlushInstructionCache((HANDLE)a3,(LPCVOID)a3,16); } else { // lppd01.hDevMode=0; // lppd01.hDevNames=0; // lppd01.Flags=(lppd01.Flags | PD_RETURNDEFAULT); //リターンキーを押す操作 keybd_event( VK_RETURN, 0, 0, 0 ); //リターンキーを離す操作 keybd_event( VK_RETURN, 0, KEYEVENTF_KEYUP, 0); n=(int)printa(&lppd01); } return n; } extern "C" { __declspec(dllexport) int returndefault01(void); __declspec(dllexport) int hookstartdoc01(void); __declspec(dllexport) long gethookdc01(void); __declspec(dllexport) int startdoc01(long hDC,char * string01); __declspec(dllexport) int returndefault01(void) { LPVOID hcomdlg32; hcomdlg32 = LoadLibrary("comdlg32.dll"); a3 = (int)GetProcAddress(hcomdlg32, "PrintDlgA"); printa = (int (__stdcall *)(struct tagPDA *))GetProcAddress(hcomdlg32, "PrintDlgA"); FreeLibrary(hcomdlg32); a4=(int)temp02; VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE_READWRITE,&oldprotect); __asm { mov esi,a3 mov eax,[esi] mov pre3,eax mov eax,[esi+4] mov pre4,eax mov al,0xB8 mov [esi],al mov eax,a4 mov [esi+1],eax mov ax,0xC350 mov [esi+5],ax } VirtualProtect((LPVOID)a3,16,PAGE_EXECUTE,&oldprotect); FlushInstructionCache((HANDLE)a3,(LPCVOID)a3,16); return (1); } __declspec(dllexport) int hookstartdoc01(void) { a1=(int)StartDoc; a2=(int)temp01; VirtualProtect((LPVOID)a1,16,PAGE_EXECUTE_READWRITE,&oldprotect); __asm { mov esi,a1 mov eax,[esi] mov pre1,eax mov eax,[esi+4] mov pre2,eax mov al,0xB8 mov [esi],al mov eax,a2 mov [esi+1],eax mov ax,0xC350 mov [esi+5],ax } VirtualProtect((LPVOID)a1,16,PAGE_EXECUTE,&oldprotect); FlushInstructionCache((HANDLE)a1,(LPCVOID)a1,16); return (1); } long gethookdc01(void) { return (hdc01); } int startdoc01(long hDC,char * string01) { DOCINFO info01; info01.cbSize=20; info01.lpszDocName=string01; info01.lpszOutput=0; info01.lpszDatatype=0; info01.fwType=0; StartDoc((void *)hDC,&info01); return (1); } }