Z
zanpen2001
Unregistered / Unconfirmed
GUEST, unregistred user!
最近在学习createRemoteThread函数下面是我的一个例程,可以顺利编译和运行,但是无法用MESSAGEBOX弹出文本读取的内容下面是我的代码,可能我的问题比较低级,大家别笑我,帮帮忙<code>program inj;{$IMAGEBASE $11110000}{$APPTYPE CONSOLE}uses windows;procedure testfunc;stdcall;var content: pchar; FileHandle: THandle; TxtFileSize: dword; BytesReads: Cardinal;begin FileHandle := CreateFile(PCHAR('test.txt'), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if FileHandle <> INVALID_HANDLE_VALUE then begin TxtFileSize := GetFileSize(FileHandle, nil); GetMem(content, TxtFileSize); ReadFile(FileHandle, content^, TxtFileSize, BytesReads, nil); CloseHandle(FileHandle); end; Messagebox(0,content,'',mb_ok);end;procedure Inject(ProcessHandle: longword; EntryPoint: pointer);var Module, NewModule: Pointer; Size, BytesWritten, TID: longword;begin Module := Pointer(GetModuleHandle(nil)); Size := PImageOptionalHeader(Pointer(integer(Module) + PImageDosHeader(Module)._lfanew + SizeOf(dword) + SizeOf(TImageFileHeader))).SizeOfImage; VirtualFreeEx(ProcessHandle, Module, 0, MEM_RELEASE); NewModule := VirtualAllocEx(ProcessHandle, Module, Size, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE); WriteProcessMemory(ProcessHandle, NewModule, Module, Size, BytesWritten); CreateRemoteThread(ProcessHandle, nil, 0, EntryPoint, Module, 0, TID);end;var ProcessHandle, Pid: longword;begin GetWindowThreadProcessId(FindWindow('WMPlayerApp', nil), @PID); ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, PID); Inject(ProcessHandle, @testfunc); CloseHandle(ProcessHandle);end.</code>content中的应该就是注入函数读取的txt文本的内容了,可在messagebox中显示为空白我曾用非注入的方式测试过testfunc,是可以成功运行的我想用纯api来解决我的问题,pascal的内容不想涉及