Project1
标题: 请问API函数createthread怎么使用啊 [打印本页]
作者: 灰太狼与喜羊羊 时间: 2019-9-28 23:05
标题: 请问API函数createthread怎么使用啊
可以给个具体的例子吗
作者: SixRC 时间: 2019-9-28 23:50
本帖最后由 SixRC 于 2019-9-29 11:47 编辑
#include <windows.h>
#include <stdio.h>
int __stdcall hi(int i) {
Sleep(i * 80);
printf("hi %d\n", i);
return 0;
}
int main() {
for (int i = 0; i < 10; i++) {
CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)hi, i, 0, 0));
}
Sleep(1000);
getchar();
return 0;
}
#include <windows.h>
#include <stdio.h>
int __stdcall hi(int i) {
Sleep(i * 80);
printf("hi %d\n", i);
return 0;
}
int main() {
for (int i = 0; i < 10; i++) {
CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)hi, i, 0, 0));
}
Sleep(1000);
getchar();
return 0;
}
感觉已经忘记怎么写代码了..
作者: 灰太狼与喜羊羊 时间: 2019-9-29 11:27
那要是用ruby代码写呢
作者: SixRC 时间: 2019-9-29 12:08
u = Win32API.new("kernel32", "GetModuleHandleA", "p", "l").call("user32")
m = Win32API.new("kernel32", "GetProcAddress", "lp", "l").call(u, "MessageBoxA")
func = [0x8B, 0x4C, 0x24, 0x04,
0x31, 0xC0, 0x50, 0x50, 0x51, 0x50, 0xB8].pack("C*") +
[m].pack("l") +
[0xFF, 0xD0, 0xC2, 0x04, 0x00].pack("C*")
=begin
mov ecx, [esp+4] 参数 i.to_s
xor eax,eax
push eax
push eax
push ecx
push eax
mov eax,MessageBoxA
call eax 0,text,0,0
ret 4
=end
c = Win32API.new("kernel32", "CreateThread", "llppll", "v")
for i in 0...5
c.call(0, 0, func, i.to_s, 0, 0)
end
loop{Graphics.update}
u = Win32API.new("kernel32", "GetModuleHandleA", "p", "l").call("user32")
m = Win32API.new("kernel32", "GetProcAddress", "lp", "l").call(u, "MessageBoxA")
func = [0x8B, 0x4C, 0x24, 0x04,
0x31, 0xC0, 0x50, 0x50, 0x51, 0x50, 0xB8].pack("C*") +
[m].pack("l") +
[0xFF, 0xD0, 0xC2, 0x04, 0x00].pack("C*")
=begin
mov ecx, [esp+4] 参数 i.to_s
xor eax,eax
push eax
push eax
push ecx
push eax
mov eax,MessageBoxA
call eax 0,text,0,0
ret 4
=end
c = Win32API.new("kernel32", "CreateThread", "llppll", "v")
for i in 0...5
c.call(0, 0, func, i.to_s, 0, 0)
end
loop{Graphics.update}
道理还是一样的
但是新线程的函数不能是ruby函数 因为机制不一样
得先编译好
汇编毕竟麻烦
作者: 灰太狼与喜羊羊 时间: 2019-9-30 10:56
SixRC 发表于 2019-9-29 12:08
u = Win32API.new("kernel32", "GetModuleHandleA", "p", "l").call("user32")
m = Win32API.new("kernel ...
那这么说 想要在ruby中用好api函数 还得多少掌握一些汇编语言吗
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |