回复 25楼 hahayezhe
我把那段创建和打开互斥对象的汇编代码转换为pascal假代码, 我汇编学得不乍地,帮个眼看看有错不
程序代码:
0043245A /$ 807C24 04 00 cmp byte ptr [esp+4], 0
0043245F |. 53 push ebx
00432460 |. 55 push ebp
00432461 |. 56 push esi
00432462 |. 57 push edi
00432463 |. 8BF1 mov esi, ecx
00432465 |. BD 88835100 mov ebp, 00518388
0043246A |. BB 94835100 mov ebx, 00518394
0043246F |. 74 1E je short 0043248F
00432471 |. 8BFD mov edi, ebp
00432473 |> FF37 /push dword ptr [edi] ; /MutexName
00432475 |. 6A 00 |push 0 ; |Inheritable = FALSE
00432477 |. 68 01001F00 |push 1F0001 ; |Access = 1F0001
0043247C |. FF15 50514D00 |call dword ptr [<&KERNEL32.OpenMutex>; \OpenMutexW
00432482 |. 85C0 |test eax, eax
00432484 |. 8906 |mov dword ptr [esi], eax
00432486 |. 75 3F |jnz short 004324C7
00432488 |. 83C7 04 |add edi, 4
0043248B |. 3BFB |cmp edi, ebx
0043248D |.^ 7C E4 \jl short 00432473
0043248F |> 8BFD mov edi, ebp
00432491 |> FF37 /push dword ptr [edi] ; /MutexName
00432493 |. 6A 00 |push 0 ; |InitialOwner = FALSE
00432495 |. 6A 00 |push 0 ; |pSecurity = NULL
00432497 |. FF15 4C514D00 |call dword ptr [<&KERNEL32.CreateMut>; \CreateMutexW
0043249D |. 85C0 |test eax, eax
0043249F |. 8906 |mov dword ptr [esi], eax
004324A1 |. 74 14 |je short 004324B7
004324A3 |. FF15 48514D00 |call dword ptr [<&KERNEL32.GetLastEr>; [GetLastError
004324A9 >|. 3D B7000000 |cmp eax, 0B7 ; 0B7错误号:当文件已存在时,无法创建该文件。
004324AE >|. 75 20 |jnz short 004324D0 ; 创建互斥对象成功,跳转
004324B0 |. 8BCE |mov ecx, esi
004324B2 |. E8 A4010500 |call 0048265B
004324B7 |> 83C7 04 |add edi, 4
004324BA |. 3BFB |cmp edi, ebx
004324BC |.^ 7C D3 \jl short 00432491 ; 继续创建互斥对象
004324BE |> 32C0 xor al, al
004324C0 |> 5F pop edi
004324C1 |. 5E pop esi
004324C2 |. 5D pop ebp
004324C3 |. 5B pop ebx
004324C4 |. C2 0400 retn 4
004324C7 |> 8BCE mov ecx, esi
004324C9 |. E8 8D010500 call 0048265B
004324CE |.^ EB EE jmp short 004324BE
004324D0 |> B0 01 mov al, 1
004324D2 \.^ EB EC jmp short 004324C0
程序代码:
function CreateOrOpenMutex(i:Integer):Integer;
begin
esi:=ecx;
ebp:=$00518388;
ebx:=$00518394;
if i<>0 then begin
edi:=ebp;
L2:
eax:=OpenMutex($1F0001,0,dword ptr[edi]);
if eax<>0 then begin
ecx:=esi;
call $0048265B;
al:=0;
end else begin
edi:=edi+4;
if edi<ebx then goto L2;
goto L1;
end;
end else begin
L1:
edi:=ebp;
eax:=CreateMutex(0,false,dword ptr[edi]);
dword ptr [esi]:=eax;
if eax<>0 then begin
eax:=GetLastError();
if eax<>$0B7 then begin //0B7错误号:当文件已存在时,无法创建该文件。
al:=1;
end else begin
ecx:=esi;
call $0048265B;
edi:=edi+4;
if edi<ebx then goto L1;
al:=0;
end;
end;
end;
result:=al;
end;