这个c程序应该用什么编译? 是不是BCB? ( 积分: 300 )

  • 主题发起人 主题发起人 刘麻子
  • 开始时间 开始时间

刘麻子

Unregistered / Unconfirmed
GUEST, unregistred user!
http://kajaa.bbs.us/docs/Computer/System/nowcan/cb_rt98.htm
我用VC 6.0编译后,再执行就出错了,但是压缩包里面的那个Exe是可以的,另外我还试着写了个Delphi版的,也出错,不知道是哪里的问题?
 
http://kajaa.bbs.us/docs/Computer/System/nowcan/cb_rt98.htm
我用VC 6.0编译后,再执行就出错了,但是压缩包里面的那个Exe是可以的,另外我还试着写了个Delphi版的,也出错,不知道是哪里的问题?
 
VC6,新建一个Console工程。即控制台工程。
 
是不是你不是在Win98环境下编译运行的啊,因为CreateKernelThread函数是NT没有的
 
to wqyzsh: 当然在98, 要不不是扯淡吗, 呵呵..
to dengziguo: 执行VC编译出来的Exe的确出错..
//-------------------
KERNEL32 在 0084:833b6f77 的模块 <未知> 中导致无效页错误。
Registers:
EAX=8187b254 CS=0167 EIP=833b6f77 EFLGS=00010a86
EBX=8187b1f4 SS=016f ESP=0096ff9c EBP=0096ffcc
ECX=c15b3090 DS=016f ESI=00000008 FS=3bef
EDX=8187b254 ES=016f EDI=817cc2cc GS=0000
Bytes at CS:EIP:
00 89 02 00 00 16 00 00 00 ff ff ff ff 50 00 00
Stack dump:
bff8922c 833b70bc 817cc2cc 00000008 8187b1f4 00000000 0096ffa4 0096fdcc
ffffffff bffc0d90 bff79050 00000000 0096ffec bff86cd5 833b6f48 833b70bc
//-------------------
 
另外我还试着写了个Delphi版的,也出错,??????????????????????
 
我是麻子我怕谁!哈哈
 
麻子怕麻婆
 
// 此程序参考了老侃(NowCan)的Rt98.cpp, 在此表示感谢, 虽然我还不认识他, 同时也感谢东兰兄帮忙查错, :)
program KernelThread_9x;
uses Windows;
// 建立内核线程
function CreateKernelThread(
lpThreadAttributes: Pointer;
dwStackSize: DWord;
lpStartAddress: TFNThreadStartRoutine;
lpParameter: Pointer;
dwCreationFlags: DWord;
var lpThreadId: DWord): THandle;
stdcall;
external 'Kernel32.dll' Name 'CreateKernelThread';
// 分配共享内存
function SharedMemoryAlloc(dwSize: DWord): Pointer;
stdcall;
external 'ComCtl32.dll' Index 71;
// 函数调用约定
type
PfnLoadLibrary = function (lpLibFileName: PChar): HModule;
stdcall;
PfnFreeLibrary = function (hLibModule: HModule): Bool;
stdcall;
PfnGetProcAddress = function (hModule: HModule;
lpProcName: PChar): FarProc;
stdcall;
PfnGetModuleFileName = function (hModule: HModule;
lpFilename: PChar;
nSize: DWord): DWord;
stdcall;
PfnMessageBox = function (hWnd: HWnd;
lpText, lpCaption: PChar;
uType: UInt): Integer;
stdcall;
// 线程参数结构
type
PThreadParam = ^TThreadParam;
TThreadParam = record
fnLoadLibrary: PfnLoadLibrary;
fnFreeLibrary: PfnFreeLibrary;
fnGetProcAddress: PfnGetProcAddress;
fnGetModuleFileName: PfnGetModuleFileName;
szModuleName, szProcName,
szText, szCaption: array[0..MAX_PATH] of Char;
end;

// 内核线程回调
function KernelThreadPro(var Param: TThreadParam): DWord;
stdcall;
var
hUser32: HModule;
fnMessageBox: PfnMessageBox;
begin
Result := 66;
// 装载DLL
hUser32 := Param.fnLoadLibrary(@Param.szModuleName);
if (hUser32 = 0) then
Exit;
// 定位API
fnMessageBox := Param.fnGetProcAddress(hUser32, @Param.szProcName);
if (@fnMessageBox = nil) then
Exit;
// 所处进程
Param.fnGetModuleFileName(0, @Param.szText[9], MAX_PATH - 9);
// 调用API
fnMessageBox(0, @Param.szText, @Param.szCaption, MB_TOPMOST);
// 卸载DLL
Param.fnFreeLibrary(hUser32);
end;

// 帮助计算长度
procedure AfterThreadPro();
begin
end;

// 程序入口
var
ThreadCodeSize: DWord;
ThreadCodePt: Pointer;
ThreadParam: TThreadParam;
ThreadParamPt: PThreadParam;
hKernel32: HModule;
hThread: THandle;
ThreadId: DWord;
begin
// 代码长度
ThreadCodeSize := DWord(@AfterThreadPro) - DWord(@KernelThreadPro);
// 分配内存
ThreadCodePt := SharedMemoryAlloc(ThreadCodeSize + SizeOf(TThreadParam) + 3);
if (ThreadCodePt = nil) then
begin
MessageBox(0, '分配共享内存失败!!', 'Error', MB_TOPMOST);
Exit;
end;

// 拷贝代码
if (WriteProcessMemory(GetCurrentProcess(), ThreadCodePt, @KernelThreadPro, ThreadCodeSize, PDWord(nil)^) = False) then
begin
MessageBox(0, '复制线程代码失败!!', 'Error', MB_TOPMOST);
Exit;
end;

// 线程参数
hKernel32 := GetModuleHandle('Kernel32.dll');
ThreadParam.fnLoadLibrary := GetProcAddress(hKernel32, 'LoadLibraryA');
ThreadParam.fnFreeLibrary := GetProcAddress(hKernel32, 'FreeLibrary');
ThreadParam.fnGetProcAddress := GetProcAddress(hKernel32, 'GetProcAddress');
ThreadParam.fnGetModuleFileName := GetProcAddress(hKernel32, 'GetModuleFileNameA');
ThreadParam.szModuleName := 'User32.dll';
ThreadParam.szProcName := 'MessageBoxA';
ThreadParam.szText := '所处进程 ';
ThreadParam.szCaption := ' KernelThread_9x';
// 拷贝参数
ThreadParamPt := PThreadParam(DWord(ThreadCodePt) + (ThreadCodeSize + 3) and (not 3));
if (WriteProcessMemory(GetCurrentProcess(), ThreadParamPt, @ThreadParam, SizeOf(TThreadParam), PDWord(nil)^) = False) then
begin
MessageBox(0, '复制线程参数失败!!', 'Error', MB_TOPMOST);
Exit;
end;

// 建立线程
hThread := CreateKernelThread(nil, 0, ThreadCodePt, ThreadParamPt, 0, ThreadId);
if (hThread = 0) then
MessageBox(0, '建立内核线程失败!!', 'Error', MB_TOPMOST) else
CloseHandle(hThread);
end.
 
后退
顶部