QueueUserAPC VC转delphi 不成功

DJCNIAY 2008-03-17 02:58:23
delphi7 编译出来的程序 在英文OS会显示??

这个程序能够解决。有带源码是VC的。我想转成delphi不成功,谁有空帮我转转,谢谢。
http://www.cnblogs.com/hBifTs/articles/4521.html
VC的
#include "stdafx.h"

#pragma comment(linker,"/INCREMENTAL:NO")

struct apc_parameter{
TCHAR x[24];
LCID local;
BOOL (WINAPI*SetThreadLocaleA) (LCID Locale);
int (WINAPI*MessageBoxA)(HWND hWnd ,LPCSTR lpText, LPCSTR lpCaption,UINT uType);
};

void CALLBACK apc_routine(int _ap)
{
struct apc_parameter * ap = (struct apc_parameter*)_ap;

// if(!ap->SetThreadLocaleA(LOCALE_SYSTEM_DEFAULT))
if(!ap->SetThreadLocaleA(ap->local))
{
// ap->MessageBoxA(NULL,ap->x,ap->x,MB_OK);
}
}

int Reverse(LPTSTR filepath)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
PVOID codeSeg, dataSeg;
DWORD cbWritten;
struct apc_parameter ap;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);

// TCHAR appPath[] = _T("G:\\Tools\\Network\\QQ\\QQRTF\\QQRTF.exe");
/* TCHAR *fullPath = GetCommandLine();
strlwr(fullPath);
TCHAR par[] = _T("/file:");
TCHAR *appPath = strstr(fullPath,par);
if(appPath == NULL)
{
return 0;
}
appPath += strlen(par);
*/
// TCHAR appPath[] = _T("D:\\Program Files\\Bradbury\\FeedDemon\\FeedDemon.exe");

CreateProcess( 0, filepath, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &si, &pi );
if(!pi.hThread){
return -1;
}

// DWORD codeSize = (DWORD)Func_End - (DWORD)Func_Begin;

codeSeg = VirtualAllocEx(pi.hProcess,0, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
dataSeg = VirtualAllocEx(pi.hProcess,0, 1024, MEM_COMMIT, PAGE_READWRITE );

ap.local = MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC);
strcpy(ap.x,_T("Error"));

*((FARPROC*)&ap.SetThreadLocaleA) = GetProcAddress( GetModuleHandle("kernel32.dll"), "SetThreadLocale");
// *((FARPROC*)&ap.MessageBoxA) = GetProcAddress( GetModuleHandle("user32.dll"), "MessageBoxA");

WriteProcessMemory( pi.hProcess, codeSeg, apc_routine, 1024, &cbWritten );

WriteProcessMemory( pi.hProcess, dataSeg, &ap, sizeof(ap), &cbWritten );


if(!QueueUserAPC((PAPCFUNC)codeSeg, pi.hThread, (DWORD)dataSeg)){

return -1;
}
ResumeThread(pi.hThread);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}


我转的程序:
//----------------
program Project3;


uses
Windows,SysUtils;

type
apc_parameter=packed record
// x:array[0..23] of char;
local:LCID;

p: function (Locale: LCID): BOOL; stdcall;
// m: function (hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;
end;
procedure apc_routine(_ap:Integer);
begin
with apc_parameter(Pointer(_ap)^) do
begin
// m(0,x,x,0);
p(local)
end
end;

procedure temp ;
begin
;
end;
// ap.p(ap.local)
// if not ap.p(ap.local) then ap.m(0,ap.x,ap.x,0);
function PatchFile(aFilename:PChar):Boolean;
var
vStartupInfo:TStartupInfo;
vProcessInfo:TProcessInformation;
vCodeSeg,vDataSeg:Pointer;
vAp:apc_parameter;
lpNumberOfBytesWritten: DWORD;
begin
FillChar(vStartupInfo,SizeOf(vStartupInfo),#0);
vStartupInfo.cb:=SizeOf(vStartupInfo);
// vStartupInfo.dwFlags:=STARTF_USESHOWWINDOW;
// vStartupInfo.wShowWindow:=SW_SHOWNORMAL;
if not CreateProcess(nil,aFilename,nil,nil,False,CREATE_SUSPENDED,nil,nil,vStartupInfo,vProcessInfo) then
Result:=False
else
begin
vCodeSeg := VirtualAllocEx(vProcessInfo.hProcess,nil,1024,MEM_COMMIT, PAGE_EXECUTE_READWRITE );
vDataSeg := VirtualAllocEx(vProcessInfo.hProcess,nil,1024,MEM_COMMIT, PAGE_READWRITE );
with vAp do
begin
local :=$0804;
// x :='ERROR';
@p:=GetProcAddress(GetModuleHandle('kernel32.dll'),'SetThreadLocale');
// @m:=GetProcAddress(GetModuleHandle('user32.dll'),'MessageBoxA');
end;

WriteProcessMemory(vProcessInfo.hProcess,vCodeSeg,@apc_routine,Integer(@temp)-Integer(@apc_routine),lpNumberOfBytesWritten);
WriteProcessMemory(vProcessInfo.hProcess,vDataSeg,@vAp,SizeOf(vAp),lpNumberOfBytesWritten);
if not (QueueUserAPC(vCodeSeg,vProcessInfo.hThread,DWORD(vDataSeg))) then
begin
// MessageBox(0,'','',0);
// Result :=False;
end;
ResumeThread(vProcessInfo.hThread);
CloseHandle(vProcessInfo.hThread);
CloseHandle(vProcessInfo.hProcess);
Result :=True;
end;
end;
begin
PatchFile('c:\1.exe');
{ TODO -oUser -cConsole Main : Insert code here }
end.
...全文
155 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
DJCNIAY 2008-04-04
  • 打赏
  • 举报
回复
少了stdcall
DJCNIAY 2008-03-18
  • 打赏
  • 举报
回复
delphi7编译的中文程序在英文的OS,中文不会显示出来,会显示??

如果加上这个就不会
SetThreadLocale($0804);

但是有的程序已经编译好了,所以只能用上面的程序。

上面是VC的,我改成Delphi后,程序跟VC执行的不一样。
brightyang 2008-03-18
  • 打赏
  • 举报
回复
没看懂是啥意思啊
ydlchina 2008-03-17
  • 打赏
  • 举报
回复
up

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧