QueueUserAPC VC转delphi 不成功(200分)

  • 主题发起人 主题发起人 djcniay
  • 开始时间 开始时间
D

djcniay

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi7 编译出来的程序 在英文OS会显示??<br><br>这个程序能够解决。有带源码是VC的。我想转成delphi不成功,谁有空帮我转转,谢谢。<br>http://www.cnblogs.com/hBifTs/articles/4521.html<br>VC的<br>#include "stdafx.h"<br><br>#pragma comment(linker,"/INCREMENTAL:NO")<br><br>struct apc_parameter{<br> TCHAR x[24];<br> LCID local;<br> BOOL (WINAPI*SetThreadLocaleA) (LCID Locale);<br> int &nbsp;(WINAPI*MessageBoxA)(HWND hWnd ,LPCSTR lpText, LPCSTR lpCaption,UINT uType);<br>};<br><br>void CALLBACK apc_routine(int _ap)<br>{<br> struct apc_parameter * ap = (struct apc_parameter*)_ap;<br><br> // if(!ap-&gt;SetThreadLocaleA(LOCALE_SYSTEM_DEFAULT))<br> if(!ap-&gt;SetThreadLocaleA(ap-&gt;local))<br> {<br> // ap-&gt;MessageBoxA(NULL,ap-&gt;x,ap-&gt;x,MB_OK);<br> }<br>}<br><br>int Reverse(LPTSTR filepath)<br>{<br> STARTUPINFO si;<br> PROCESS_INFORMATION pi;<br> PVOID &nbsp; codeSeg, dataSeg;<br> DWORD &nbsp; cbWritten;<br> struct apc_parameter ap;<br><br> ZeroMemory(&amp;si, sizeof(si));<br> si.cb = sizeof(si);<br><br> // TCHAR appPath[] = _T("G://Tools//Network//QQ//QQRTF//QQRTF.exe");<br>/* TCHAR *fullPath = GetCommandLine();<br> strlwr(fullPath);<br> TCHAR par[] = _T("/file:");<br> TCHAR *appPath = strstr(fullPath,par);<br> if(appPath == NULL)<br> {<br> return 0;<br> }<br> appPath += strlen(par);<br>*/<br>// TCHAR appPath[] = _T("D://Program Files//Bradbury//FeedDemon//FeedDemon.exe");<br> <br> CreateProcess( 0, filepath, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &amp;si, &amp;pi );<br> if(!pi.hThread){<br> return -1;<br> }<br><br> // DWORD codeSize = (DWORD)Func_End - (DWORD)Func_Begin;<br><br> codeSeg = VirtualAllocEx(pi.hProcess,0, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE );<br> dataSeg = VirtualAllocEx(pi.hProcess,0, 1024, MEM_COMMIT, PAGE_READWRITE );<br><br> ap.local = MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC);<br> strcpy(ap.x,_T("Error"));<br><br> *((FARPROC*)&amp;ap.SetThreadLocaleA) = GetProcAddress( GetModuleHandle("kernel32.dll"), "SetThreadLocale");<br>// *((FARPROC*)&amp;ap.MessageBoxA) = GetProcAddress( GetModuleHandle("user32.dll"), "MessageBoxA");<br><br> WriteProcessMemory( pi.hProcess, codeSeg, apc_routine, 1024, &amp;cbWritten );<br><br> WriteProcessMemory( pi.hProcess, dataSeg, &amp;ap, sizeof(ap), &amp;cbWritten );<br><br><br> if(!QueueUserAPC((PAPCFUNC)codeSeg, pi.hThread, (DWORD)dataSeg)){<br><br> return -1;<br> }<br> ResumeThread(pi.hThread);<br> CloseHandle(pi.hThread);<br> CloseHandle(pi.hProcess);<br> return 0;<br>}<br><br><br>我转的程序:<br>//----------------<br>program Project3;<br><br><br>uses<br>&nbsp; Windows,SysUtils;<br><br>type<br>&nbsp; apc_parameter=packed record<br>// &nbsp; &nbsp;x:array[0..23] of char;<br>&nbsp; &nbsp; local:LCID;<br><br>&nbsp; &nbsp; p: function (Locale: LCID): BOOL; stdcall;<br>// &nbsp; &nbsp;m: function (hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;<br>&nbsp; end;<br>&nbsp;procedure apc_routine(_ap:Integer);<br>&nbsp;begin<br>&nbsp; &nbsp;with apc_parameter(Pointer(_ap)^) do<br>&nbsp; &nbsp;begin<br>// &nbsp; &nbsp; m(0,x,x,0);<br>&nbsp; &nbsp; &nbsp;p(local)<br>&nbsp; &nbsp;end<br>&nbsp;end;<br><br>&nbsp;procedure temp ;<br>&nbsp;begin<br>&nbsp; &nbsp;;<br>&nbsp;end;<br>// &nbsp; &nbsp; ap.p(ap.local)<br>// &nbsp; if not ap.p(ap.local) then ap.m(0,ap.x,ap.x,0);<br>&nbsp; function PatchFile(aFilename:PChar):Boolean;<br>&nbsp; var<br>&nbsp; &nbsp; vStartupInfo:TStartupInfo;<br>&nbsp; &nbsp; vProcessInfo:TProcessInformation;<br>&nbsp; &nbsp; vCodeSeg,vDataSeg:Pointer;<br>&nbsp; &nbsp; vAp:apc_parameter;<br>&nbsp; &nbsp; lpNumberOfBytesWritten: DWORD;<br>&nbsp; begin<br>&nbsp; &nbsp; FillChar(vStartupInfo,SizeOf(vStartupInfo),#0);<br>&nbsp; &nbsp; vStartupInfo.cb:=SizeOf(vStartupInfo);<br>// &nbsp; &nbsp;vStartupInfo.dwFlags:=STARTF_USESHOWWINDOW;<br>// &nbsp; &nbsp;vStartupInfo.wShowWindow:=SW_SHOWNORMAL;<br>&nbsp; &nbsp; if not CreateProcess(nil,aFilename,nil,nil,False,CREATE_SUSPENDED,nil,nil,vStartupInfo,vProcessInfo) then<br>&nbsp; &nbsp; &nbsp; Result:=False<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; vCodeSeg := VirtualAllocEx(vProcessInfo.hProcess,nil,1024,MEM_COMMIT, PAGE_EXECUTE_READWRITE );<br>&nbsp; &nbsp; &nbsp; vDataSeg := VirtualAllocEx(vProcessInfo.hProcess,nil,1024,MEM_COMMIT, PAGE_READWRITE );<br>&nbsp; &nbsp; &nbsp; with vAp do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; local :=$0804;<br>// &nbsp; &nbsp; &nbsp; &nbsp;x :='ERROR';<br>&nbsp; &nbsp; &nbsp; &nbsp; @p:=GetProcAddress(GetModuleHandle('kernel32.dll'),'SetThreadLocale');<br>// &nbsp; &nbsp; &nbsp; &nbsp;@m:=GetProcAddress(GetModuleHandle('user32.dll'),'MessageBoxA');<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; WriteProcessMemory(vProcessInfo.hProcess,vCodeSeg,@apc_routine,Integer(@temp)-Integer(@apc_routine),lpNumberOfBytesWritten);<br>&nbsp; &nbsp; WriteProcessMemory(vProcessInfo.hProcess,vDataSeg,@vAp,SizeOf(vAp),lpNumberOfBytesWritten);<br>&nbsp; &nbsp; if not (QueueUserAPC(vCodeSeg,vProcessInfo.hThread,DWORD(vDataSeg))) then<br>&nbsp; &nbsp; &nbsp; begin<br>// &nbsp; &nbsp; &nbsp; &nbsp;MessageBox(0,'','',0);<br>// &nbsp; &nbsp; &nbsp; &nbsp;Result :=False;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; ResumeThread(vProcessInfo.hThread);<br>&nbsp; &nbsp; &nbsp; CloseHandle(vProcessInfo.hThread);<br>&nbsp; &nbsp; &nbsp; CloseHandle(vProcessInfo.hProcess);<br>&nbsp; &nbsp; &nbsp; Result :=True;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>begin<br>&nbsp; PatchFile('c:/1.exe');<br>&nbsp; { TODO -oUser -cConsole Main : Insert code here }<br>end.
 
搞定.少stdcall;
 
怎么结束贴子
 
后退
顶部