3-3

/*
 * TaskQueM.c
 *
 * Sample code for "Multithreading Applications in Win32"
 * This is from Chapter 3, Listing 3-3
 *
 * Call ThreadFunc NUM_TASKS times, using
 * no more than THREAD_POOL_SIZE threads.
 * This version uses WaitForMultipleObjects
 * to provide a more optimal solution.
 *
 * Build command: cl /MD TaskQueM.c
 */

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "MtVerify.h"

DWORD WINAPI ThreadFunc(LPVOID);

#define THREAD_POOL_SIZE 3
#define MAX_THREAD_INDEX THREAD_POOL_SIZE-1
#define NUM_TASKS 6

int main()
{
    HANDLE  hThrds[THREAD_POOL_SIZE];
    int     slot = 0;
    DWORD   threadId;
    int     i;
    DWORD   rc;

    for (i=1; i<=NUM_TASKS; i++)
    {
        /* Until we've used all threads in *
         * the pool, do not need to wait   *
         * for one to exit                 */
        if (i > THREAD_POOL_SIZE)
        {
            /* Wait for one thread to terminate */
            rc = WaitForMultipleObjects(
                THREAD_POOL_SIZE,
                hThrds,
                FALSE,
                INFINITE );
            slot = rc - WAIT_OBJECT_0;
            MTVERIFY( slot >= 0
                && slot < THREAD_POOL_SIZE );
            printf("Slot %d terminated\n", slot );
            MTVERIFY( CloseHandle(hThrds[slot]) );
        }
        /* Create a new thread in the given
         * available slot */
        MTVERIFY( hThrds[slot] = CreateThread(NULL,
            0,
            ThreadFunc,
            (LPVOID)slot,
            0,
            &threadId ) );
        printf("Launched thread #%d (slot %d)\n", i, slot);
        slot++;
    }

    /* Now wait for all threads to terminate */
    rc = WaitForMultipleObjects(
        THREAD_POOL_SIZE,
        hThrds,
        TRUE,
        INFINITE );
    MTVERIFY( rc >= WAIT_OBJECT_0
             && rc < WAIT_OBJECT_0+THREAD_POOL_SIZE);
    for (slot=0; slot<THREAD_POOL_SIZE; slot++)
        MTVERIFY( CloseHandle(hThrds[slot]) );
    printf("All slots terminated\n");

    return EXIT_SUCCESS;
}

/*
 * This function just calls Sleep for
 * a random amount of time, thereby
 * simulating some task that takes time.
 *
 * The param "n" is the index into
 * the handle array, kept for informational
 * purposes.
 */
DWORD WINAPI ThreadFunc(LPVOID n)
{
    srand( GetTickCount() );

    Sleep((rand()%10)*800+500);
    printf("Slot %d idle\n", n);
    return ((DWORD)n);
}

od

 

00401000  /$  81EC 18010000 sub     esp, 118
00401006  |.  53            push    ebx
00401007  |.  8B1D 1C204000 mov     ebx, dword ptr [<&KERNEL32.WaitF>;  kernel32.WaitForMultipleObjects
0040100D  |.  55            push    ebp
0040100E  |.  8B2D 30204000 mov     ebp, dword ptr [<&MSVCRTD.printf>;  MSVCRTD.printf
00401014  |.  56            push    esi
00401015  |.  57            push    edi
00401016  |.  33F6          xor     esi, esi
00401018  |.  BF 01000000   mov     edi, 1
0040101D  |>  83FF 03       /cmp     edi, 3
00401020  |.  7E 3A         |jle     short 0040105C
00401022  |.  6A FF         |push    -1
00401024  |.  8D4424 1C     |lea     eax, dword ptr [esp+1C]
00401028  |.  6A 00         |push    0
0040102A  |.  50            |push    eax
0040102B  |.  6A 03         |push    3
0040102D  |.  FFD3          |call    ebx                             ;  kernel32.waitformultipleobjects
0040102F  |.  8BF0          |mov     esi, eax
00401031  |.  85F6          |test    esi, esi
00401033  |.  0F8C 14010000 |jl      0040114D
00401039  |.  83FE 03       |cmp     esi, 3
0040103C  |.  0F8D 0B010000 |jge     0040114D
00401042  |.  56            |push    esi
00401043  |.  68 68314000   |push    00403168                        ;  ASCII "Slot %d terminated",LF
00401048  |.  FFD5          |call    ebp                             ;  printf
0040104A  |.  8B4CB4 20     |mov     ecx, dword ptr [esp+esi*4+20]
0040104E  |.  83C4 08       |add     esp, 8
00401051  |.  51            |push    ecx                             ; /hObject
00401052  |.  FF15 18204000 |call    dword ptr [<&KERNEL32.CloseHand>; \CloseHandle
00401058  |.  85C0          |test    eax, eax
0040105A  |.  74 71         |je      short 004010CD
0040105C  |>  8D5424 24     |lea     edx, dword ptr [esp+24]
00401060  |.  52            |push    edx                             ; /pThreadId
00401061  |.  6A 00         |push    0                               ; |CreationFlags = 0
00401063  |.  56            |push    esi                             ; |pThreadParm
00401064  |.  68 70134000   |push    00401370                        ; |ThreadFunction = TaskQueM.00401370
00401069  |.  6A 00         |push    0                               ; |StackSize = 0
0040106B  |.  6A 00         |push    0                               ; |pSecurity = NULL
0040106D  |.  FF15 14204000 |call    dword ptr [<&KERNEL32.CreateThr>; \CreateThread
00401073  |.  85C0          |test    eax, eax
00401075  |.  8944B4 18     |mov     dword ptr [esp+esi*4+18], eax
00401079  |.  0F84 4E010000 |je      004011CD
0040107F  |.  56            |push    esi
00401080  |.  57            |push    edi
00401081  |.  68 48314000   |push    00403148                        ;  ASCII "Launched thread #%d (slot %d)",LF
00401086  |.  FFD5          |call    ebp                             ;  printf
00401088  |.  83C4 0C       |add     esp, 0C
0040108B  |.  46            |inc     esi
0040108C  |.  47            |inc     edi
0040108D  |.  83FF 06       |cmp     edi, 6
00401090  |.^ 7E 8B         \jle     short 0040101D
00401092  |.  6A FF         push    -1
00401094  |.  8D4424 1C     lea     eax, dword ptr [esp+1C]
00401098  |.  6A 01         push    1
0040109A  |.  50            push    eax
0040109B  |.  6A 03         push    3
0040109D  |.  FFD3          call    ebx                              ;  kernel32.waitformultipleobjects
0040109F  |.  83F8 03       cmp     eax, 3
004010A2  |.  0F83 3C020000 jnb     004012E4
004010A8  |.  33F6          xor     esi, esi
004010AA  |.  8D7C24 18     lea     edi, dword ptr [esp+18]
004010AE  |>  8B0F          /mov     ecx, dword ptr [edi]
004010B0  |.  51            |push    ecx                             ; /hObject
004010B1  |.  FF15 18204000 |call    dword ptr [<&KERNEL32.CloseHand>; \CloseHandle
004010B7  |.  85C0          |test    eax, eax
004010B9  |.  0F84 8E010000 |je      0040124D
004010BF  |.  46            |inc     esi
004010C0  |.  83C7 04       |add     edi, 4
004010C3  |.  83FE 03       |cmp     esi, 3
004010C6  |.^ 7C E6         \jl      short 004010AE
004010C8  |.  E9 00020000   jmp     004012CD
004010CD  |>  FF15 10204000 call    dword ptr [<&KERNEL32.GetLastErr>; [GetLastError
004010D3  |.  6A 00         push    0                                ; /Arguments = NULL
004010D5  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]          ; |
004010D9  |.  6A 00         push    0                                ; |BufSize = 0
004010DB  |.  51            push    ecx                              ; |Buffer
004010DC  |.  6A 00         push    0                                ; |LanguageId = 0 (LANG_NEUTRAL)
004010DE  |.  50            push    eax                              ; |MessageId
004010DF  |.  6A 00         push    0                                ; |pSource = NULL
004010E1  |.  68 00110000   push    1100                             ; |Flags = ALLOCATE_BUFFER|FROM_SYSTEM|0
004010E6  |.  FF15 0C204000 call    dword ptr [<&KERNEL32.FormatMess>; \FormatMessageA
004010EC  |.  8B5424 10     mov     edx, dword ptr [esp+10]
004010F0  |.  8D4424 28     lea     eax, dword ptr [esp+28]
004010F4  |.  52            push    edx                              ; /<%s>
004010F5  |.  68 2C314000   push    0040312C                         ; |<%s> = "CloseHandle(hThrds[slot])"
004010FA  |.  68 20314000   push    00403120                         ; |<%s> = "TaskQueM.c"
004010FF  |.  6A 34         push    34                               ; |<%d> = 34 (52.)
00401101  |.  68 DC304000   push    004030DC                         ; |Format = LF,"The following call failed at line %d in %s:",LF,LF,"    %s",LF,LF,"Reason: %s",LF,""
00401106  |.  50            push    eax                              ; |s
00401107  |.  FF15 6C204000 call    dword ptr [<&USER32.wsprintfA>]  ; \wsprintfA
0040110D  |.  83C4 18       add     esp, 18
00401110  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]
00401114  |.  8D7C24 28     lea     edi, dword ptr [esp+28]
00401118  |.  33C0          xor     eax, eax
0040111A  |.  6A 00         push    0                                ; /pOverlapped = NULL
0040111C  |.  51            push    ecx                              ; |pBytesWritten
0040111D  |.  83C9 FF       or      ecx, FFFFFFFF                    ; |
00401120  |.  8D5424 30     lea     edx, dword ptr [esp+30]          ; |
00401124  |.  F2:AE         repne   scas byte ptr es:[edi]           ; |
00401126  |.  F7D1          not     ecx                              ; |
00401128  |.  49            dec     ecx                              ; |
00401129  |.  51            push    ecx                              ; |nBytesToWrite
0040112A  |.  52            push    edx                              ; |Buffer
0040112B  |.  6A F4         push    -0C                              ; |/DevType = STD_ERROR_HANDLE
0040112D  |.  FF15 08204000 call    dword ptr [<&KERNEL32.GetStdHand>; |\GetStdHandle
00401133  |.  50            push    eax                              ; |hFile
00401134  |.  FF15 04204000 call    dword ptr [<&KERNEL32.WriteFile>>; \WriteFile
0040113A  |.  68 B80B0000   push    0BB8                             ; /Timeout = 3000. ms
0040113F  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
00401145  |.  6A 01         push    1                                ; /status = 1
00401147  |.  FF15 2C204000 call    dword ptr [<&MSVCRTD.exit>]      ; \exit
0040114D  |>  FF15 10204000 call    dword ptr [<&KERNEL32.GetLastErr>; [GetLastError
00401153  |.  6A 00         push    0                                ; /Arguments = NULL
00401155  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]          ; |
00401159  |.  6A 00         push    0                                ; |BufSize = 0
0040115B  |.  51            push    ecx                              ; |Buffer
0040115C  |.  6A 00         push    0                                ; |LanguageId = 0 (LANG_NEUTRAL)
0040115E  |.  50            push    eax                              ; |MessageId
0040115F  |.  6A 00         push    0                                ; |pSource = NULL
00401161  |.  68 00110000   push    1100                             ; |Flags = ALLOCATE_BUFFER|FROM_SYSTEM|0
00401166  |.  FF15 0C204000 call    dword ptr [<&KERNEL32.FormatMess>; \FormatMessageA
0040116C  |.  8B5424 10     mov     edx, dword ptr [esp+10]
00401170  |.  8D4424 28     lea     eax, dword ptr [esp+28]
00401174  |.  52            push    edx                              ; /<%s>
00401175  |.  68 B4304000   push    004030B4                         ; |<%s> = "slot >= 0 && slot < THREAD_POOL_SIZE"
0040117A  |.  68 20314000   push    00403120                         ; |<%s> = "TaskQueM.c"
0040117F  |.  6A 32         push    32                               ; |<%d> = 32 (50.)
00401181  |.  68 DC304000   push    004030DC                         ; |Format = LF,"The following call failed at line %d in %s:",LF,LF,"    %s",LF,LF,"Reason: %s",LF,""
00401186  |.  50            push    eax                              ; |s
00401187  |.  FF15 6C204000 call    dword ptr [<&USER32.wsprintfA>]  ; \wsprintfA
0040118D  |.  83C4 18       add     esp, 18
00401190  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]
00401194  |.  8D7C24 28     lea     edi, dword ptr [esp+28]
00401198  |.  33C0          xor     eax, eax
0040119A  |.  6A 00         push    0                                ; /pOverlapped = NULL
0040119C  |.  51            push    ecx                              ; |pBytesWritten
0040119D  |.  83C9 FF       or      ecx, FFFFFFFF                    ; |
004011A0  |.  8D5424 30     lea     edx, dword ptr [esp+30]          ; |
004011A4  |.  F2:AE         repne   scas byte ptr es:[edi]           ; |
004011A6  |.  F7D1          not     ecx                              ; |
004011A8  |.  49            dec     ecx                              ; |
004011A9  |.  51            push    ecx                              ; |nBytesToWrite
004011AA  |.  52            push    edx                              ; |Buffer
004011AB  |.  6A F4         push    -0C                              ; |/DevType = STD_ERROR_HANDLE
004011AD  |.  FF15 08204000 call    dword ptr [<&KERNEL32.GetStdHand>; |\GetStdHandle
004011B3  |.  50            push    eax                              ; |hFile
004011B4  |.  FF15 04204000 call    dword ptr [<&KERNEL32.WriteFile>>; \WriteFile
004011BA  |.  68 B80B0000   push    0BB8                             ; /Timeout = 3000. ms
004011BF  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
004011C5  |.  6A 01         push    1                                ; /status = 1
004011C7  |.  FF15 2C204000 call    dword ptr [<&MSVCRTD.exit>]      ; \exit
004011CD  |>  FF15 10204000 call    dword ptr [<&KERNEL32.GetLastErr>; [GetLastError
004011D3  |.  6A 00         push    0                                ; /Arguments = NULL
004011D5  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]          ; |
004011D9  |.  6A 00         push    0                                ; |BufSize = 0
004011DB  |.  51            push    ecx                              ; |Buffer
004011DC  |.  6A 00         push    0                                ; |LanguageId = 0 (LANG_NEUTRAL)
004011DE  |.  50            push    eax                              ; |MessageId
004011DF  |.  6A 00         push    0                                ; |pSource = NULL
004011E1  |.  68 00110000   push    1100                             ; |Flags = ALLOCATE_BUFFER|FROM_SYSTEM|0
004011E6  |.  FF15 0C204000 call    dword ptr [<&KERNEL32.FormatMess>; \FormatMessageA
004011EC  |.  8B5424 10     mov     edx, dword ptr [esp+10]
004011F0  |.  8D4424 28     lea     eax, dword ptr [esp+28]
004011F4  |.  52            push    edx                              ; /<%s>
004011F5  |.  68 64304000   push    00403064                         ; |<%s> = "hThrds[slot] = CreateThread(NULL, 0, ThreadFunc, (LPVOID)slot, 0, &threadId )"
004011FA  |.  68 20314000   push    00403120                         ; |<%s> = "TaskQueM.c"
004011FF  |.  6A 3D         push    3D                               ; |<%d> = 3D (61.)
00401201  |.  68 DC304000   push    004030DC                         ; |Format = LF,"The following call failed at line %d in %s:",LF,LF,"    %s",LF,LF,"Reason: %s",LF,""
00401206  |.  50            push    eax                              ; |s
00401207  |.  FF15 6C204000 call    dword ptr [<&USER32.wsprintfA>]  ; \wsprintfA
0040120D  |.  83C4 18       add     esp, 18
00401210  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]
00401214  |.  8D7C24 28     lea     edi, dword ptr [esp+28]
00401218  |.  33C0          xor     eax, eax
0040121A  |.  6A 00         push    0                                ; /pOverlapped = NULL
0040121C  |.  51            push    ecx                              ; |pBytesWritten
0040121D  |.  83C9 FF       or      ecx, FFFFFFFF                    ; |
00401220  |.  8D5424 30     lea     edx, dword ptr [esp+30]          ; |
00401224  |.  F2:AE         repne   scas byte ptr es:[edi]           ; |
00401226  |.  F7D1          not     ecx                              ; |
00401228  |.  49            dec     ecx                              ; |
00401229  |.  51            push    ecx                              ; |nBytesToWrite
0040122A  |.  52            push    edx                              ; |Buffer
0040122B  |.  6A F4         push    -0C                              ; |/DevType = STD_ERROR_HANDLE
0040122D  |.  FF15 08204000 call    dword ptr [<&KERNEL32.GetStdHand>; |\GetStdHandle
00401233  |.  50            push    eax                              ; |hFile
00401234  |.  FF15 04204000 call    dword ptr [<&KERNEL32.WriteFile>>; \WriteFile
0040123A  |.  68 B80B0000   push    0BB8                             ; /Timeout = 3000. ms
0040123F  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
00401245  |.  6A 01         push    1                                ; /status = 1
00401247  |.  FF15 2C204000 call    dword ptr [<&MSVCRTD.exit>]      ; \exit
0040124D  |>  FF15 10204000 call    dword ptr [<&KERNEL32.GetLastErr>; [GetLastError
00401253  |.  6A 00         push    0                                ; /Arguments = NULL
00401255  |.  8D5424 14     lea     edx, dword ptr [esp+14]          ; |
00401259  |.  6A 00         push    0                                ; |BufSize = 0
0040125B  |.  52            push    edx                              ; |Buffer
0040125C  |.  6A 00         push    0                                ; |LanguageId = 0 (LANG_NEUTRAL)
0040125E  |.  50            push    eax                              ; |MessageId
0040125F  |.  6A 00         push    0                                ; |pSource = NULL
00401261  |.  68 00110000   push    1100                             ; |Flags = ALLOCATE_BUFFER|FROM_SYSTEM|0
00401266  |.  FF15 0C204000 call    dword ptr [<&KERNEL32.FormatMess>; \FormatMessageA
0040126C  |.  8B4424 10     mov     eax, dword ptr [esp+10]
00401270  |.  8D4C24 28     lea     ecx, dword ptr [esp+28]
00401274  |.  50            push    eax                              ; /<%s>
00401275  |.  68 2C314000   push    0040312C                         ; |<%s> = "CloseHandle(hThrds[slot])"
0040127A  |.  68 20314000   push    00403120                         ; |<%s> = "TaskQueM.c"
0040127F  |.  6A 4B         push    4B                               ; |<%d> = 4B (75.)
00401281  |.  68 DC304000   push    004030DC                         ; |Format = LF,"The following call failed at line %d in %s:",LF,LF,"    %s",LF,LF,"Reason: %s",LF,""
00401286  |.  51            push    ecx                              ; |s
00401287  |.  FF15 6C204000 call    dword ptr [<&USER32.wsprintfA>]  ; \wsprintfA
0040128D  |.  8D7C24 40     lea     edi, dword ptr [esp+40]
00401291  |.  83C9 FF       or      ecx, FFFFFFFF
00401294  |.  33C0          xor     eax, eax
00401296  |.  83C4 18       add     esp, 18
00401299  |.  F2:AE         repne   scas byte ptr es:[edi]
0040129B  |.  F7D1          not     ecx
0040129D  |.  8D5424 14     lea     edx, dword ptr [esp+14]
004012A1  |.  6A 00         push    0                                ; /pOverlapped = NULL
004012A3  |.  49            dec     ecx                              ; |
004012A4  |.  52            push    edx                              ; |pBytesWritten
004012A5  |.  8D4424 30     lea     eax, dword ptr [esp+30]          ; |
004012A9  |.  51            push    ecx                              ; |nBytesToWrite
004012AA  |.  50            push    eax                              ; |Buffer
004012AB  |.  6A F4         push    -0C                              ; |/DevType = STD_ERROR_HANDLE
004012AD  |.  FF15 08204000 call    dword ptr [<&KERNEL32.GetStdHand>; |\GetStdHandle
004012B3  |.  50            push    eax                              ; |hFile
004012B4  |.  FF15 04204000 call    dword ptr [<&KERNEL32.WriteFile>>; \WriteFile
004012BA  |.  68 B80B0000   push    0BB8                             ; /Timeout = 3000. ms
004012BF  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
004012C5  |.  6A 01         push    1                                ; /status = 1
004012C7  |.  FF15 2C204000 call    dword ptr [<&MSVCRTD.exit>]      ; \exit
004012CD  |>  68 4C304000   push    0040304C                         ;  ASCII "All slots terminated",LF
004012D2  |.  FFD5          call    ebp
004012D4  |.  83C4 04       add     esp, 4
004012D7  |.  33C0          xor     eax, eax
004012D9  |.  5F            pop     edi
004012DA  |.  5E            pop     esi
004012DB  |.  5D            pop     ebp
004012DC  |.  5B            pop     ebx
004012DD  |.  81C4 18010000 add     esp, 118
004012E3  |.  C3            retn
004012E4  |>  FF15 10204000 call    dword ptr [<&KERNEL32.GetLastErr>; [GetLastError
004012EA  |.  6A 00         push    0                                ; /Arguments = NULL
004012EC  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]          ; |
004012F0  |.  6A 00         push    0                                ; |BufSize = 0
004012F2  |.  51            push    ecx                              ; |Buffer
004012F3  |.  6A 00         push    0                                ; |LanguageId = 0 (LANG_NEUTRAL)
004012F5  |.  50            push    eax                              ; |MessageId
004012F6  |.  6A 00         push    0                                ; |pSource = NULL
004012F8  |.  68 00110000   push    1100                             ; |Flags = ALLOCATE_BUFFER|FROM_SYSTEM|0
004012FD  |.  FF15 0C204000 call    dword ptr [<&KERNEL32.FormatMess>; \FormatMessageA
00401303  |.  8B5424 10     mov     edx, dword ptr [esp+10]
00401307  |.  8D4424 28     lea     eax, dword ptr [esp+28]
0040130B  |.  52            push    edx                              ; /<%s>
0040130C  |.  68 10304000   push    00403010                         ; |<%s> = "rc >= WAIT_OBJECT_0 && rc < WAIT_OBJECT_0+THREAD_POOL_SIZE"
00401311  |.  68 20314000   push    00403120                         ; |<%s> = "TaskQueM.c"
00401316  |.  6A 49         push    49                               ; |<%d> = 49 (73.)
00401318  |.  68 DC304000   push    004030DC                         ; |Format = LF,"The following call failed at line %d in %s:",LF,LF,"    %s",LF,LF,"Reason: %s",LF,""
0040131D  |.  50            push    eax                              ; |s
0040131E  |.  FF15 6C204000 call    dword ptr [<&USER32.wsprintfA>]  ; \wsprintfA
00401324  |.  83C4 18       add     esp, 18
00401327  |.  8D4C24 14     lea     ecx, dword ptr [esp+14]
0040132B  |.  8D7C24 28     lea     edi, dword ptr [esp+28]
0040132F  |.  33C0          xor     eax, eax
00401331  |.  6A 00         push    0                                ; /pOverlapped = NULL
00401333  |.  51            push    ecx                              ; |pBytesWritten
00401334  |.  83C9 FF       or      ecx, FFFFFFFF                    ; |
00401337  |.  8D5424 30     lea     edx, dword ptr [esp+30]          ; |
0040133B  |.  F2:AE         repne   scas byte ptr es:[edi]           ; |
0040133D  |.  F7D1          not     ecx                              ; |
0040133F  |.  49            dec     ecx                              ; |
00401340  |.  51            push    ecx                              ; |nBytesToWrite
00401341  |.  52            push    edx                              ; |Buffer
00401342  |.  6A F4         push    -0C                              ; |/DevType = STD_ERROR_HANDLE
00401344  |.  FF15 08204000 call    dword ptr [<&KERNEL32.GetStdHand>; |\GetStdHandle
0040134A  |.  50            push    eax                              ; |hFile
0040134B  |.  FF15 04204000 call    dword ptr [<&KERNEL32.WriteFile>>; \WriteFile
00401351  |.  68 B80B0000   push    0BB8                             ; /Timeout = 3000. ms
00401356  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
0040135C  |.  6A 01         push    1                                ; /status = 1
0040135E  |.  FF15 2C204000 call    dword ptr [<&MSVCRTD.exit>]      ; \exit
00401364  |.  90            nop
00401365  |.  90            nop
00401366  |.  90            nop
00401367  |.  90            nop
00401368  |.  90            nop
00401369  |.  90            nop
0040136A  |.  90            nop
0040136B  |.  90            nop
0040136C  |.  90            nop
0040136D  |.  90            nop
0040136E  |.  90            nop
0040136F  |.  90            nop
00401370  |.  56            push    esi
00401371  |.  FF15 20204000 call    dword ptr [<&KERNEL32.GetTickCou>; [GetTickCount
00401377  |.  50            push    eax                              ; /seed
00401378  |.  FF15 38204000 call    dword ptr [<&MSVCRTD.srand>]     ; \srand
0040137E  |.  83C4 04       add     esp, 4
00401381  |.  FF15 34204000 call    dword ptr [<&MSVCRTD.rand>]      ; [rand
00401387  |.  99            cdq
00401388  |.  B9 0A000000   mov     ecx, 0A
0040138D  |.  F7F9          idiv    ecx
0040138F  |.  8D0492        lea     eax, dword ptr [edx+edx*4]
00401392  |.  8D1480        lea     edx, dword ptr [eax+eax*4]
00401395  |.  C1E2 05       shl     edx, 5
00401398  |.  81C2 F4010000 add     edx, 1F4
0040139E  |.  52            push    edx                              ; /Timeout
0040139F  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
004013A5  |.  8B7424 08     mov     esi, dword ptr [esp+8]
004013A9  |.  56            push    esi                              ; /<%d>
004013AA  |.  68 7C314000   push    0040317C                         ; |format = "Slot %d idle",LF,""
004013AF  |.  FF15 30204000 call    dword ptr [<&MSVCRTD.printf>]    ; \printf
004013B5  |.  83C4 08       add     esp, 8
004013B8  |.  8BC6          mov     eax, esi
004013BA  |.  5E            pop     esi
004013BB  \.  C2 0400       retn    4

 

 

thread

 

00401370  |.  56            push    esi
00401371  |.  FF15 20204000 call    dword ptr [<&KERNEL32.GetTickCou>; [GetTickCount
00401377  |.  50            push    eax                              ; /seed
00401378  |.  FF15 38204000 call    dword ptr [<&MSVCRTD.srand>]     ; \srand
0040137E  |.  83C4 04       add     esp, 4
00401381  |.  FF15 34204000 call    dword ptr [<&MSVCRTD.rand>]      ; [rand
00401387  |.  99            cdq
00401388  |.  B9 0A000000   mov     ecx, 0A
0040138D  |.  F7F9          idiv    ecx
0040138F  |.  8D0492        lea     eax, dword ptr [edx+edx*4]
00401392  |.  8D1480        lea     edx, dword ptr [eax+eax*4]
00401395  |.  C1E2 05       shl     edx, 5
00401398  |.  81C2 F4010000 add     edx, 1F4
0040139E  |.  52            push    edx                              ; /Timeout
0040139F  |.  FF15 00204000 call    dword ptr [<&KERNEL32.Sleep>]    ; \Sleep
004013A5  |.  8B7424 08     mov     esi, dword ptr [esp+8]
004013A9  |.  56            push    esi                              ; /<%d>
004013AA  |.  68 7C314000   push    0040317C                         ; |format = "Slot %d idle",LF,""
004013AF  |.  FF15 30204000 call    dword ptr [<&MSVCRTD.printf>]    ; \printf
004013B5  |.  83C4 08       add     esp, 8
004013B8  |.  8BC6          mov     eax, esi
004013BA  |.  5E            pop     esi
004013BB  \.  C2 0400       retn    4

 ida

 

 

posted @ 2010-07-08 14:23  南守拥  阅读(348)  评论(0编辑  收藏  举报