Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Can we declare a variable as 'int' in the driver ???

OSR_Community_UserOSR_Community_User Member Posts: 110,217
Hi,

I have declared a variable as 'int' in my driver. This variable is used
as an index inside a for loop. something like this:-

int iCount;

for(iCount = 3; iCount >= 0; iCount--)
{

blah.. blah..

}

This is a part of DriverEntry....

Now this driver is working very fine if built as a checked build. But it
wont get loaded if it is built as a free build. Because iCount is
behaving as ULONG. and therefore it is in an infinite loop and so the
driver is not getting loaded at all.

[I know that I can change the for loop to serve my purpose, but ...
why...]. I declared iCount as LONG. But still the same behavior !!!!!
[LONG is supposed to be signed long right ????] What is happening ?

My build.log shows these flags....



Compiling e:\wfckrnl\nbt directory ********************
'nmake.exe /c BUILDMSG=Stop. -i NTTEST= UMTEST= NOLINK=1 NOPASS0=1
386=1'
cl -nologo -Ii386\ -I. -I..\Include -I..\NicIface -I..\smb -I..\nbt
-Id:\ddk\inc -Id:\ddk\inc -Id:\ddk\inc -D_X86_=1 -Di386=1 -DSTD_CALL
-DCONDITION_HANDLING=1 -DNT_UP=1 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100
-DWINNT=1 -D_WIN32_WINNT=0x0400 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1
-DFPO=1 -DNDEBUG -D_IDWBUILD /c /Zel /Zp8 /Gy -cbstring /W3 /Gz
/QIfdiv- /QIf /Gi- /Gm- /GX- /GR- /GF /Oxs /Oy
-FId:\ddk\inc\warning.h .\wfcnbt.c
wfcnbt.c
lib -out:d:\ddk\lib\i386\free\WfcNbt.lib -debugtype:cv
-IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096 -nodefaultlib
-machine:i386 @D:\TEMP\nma00229.
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

obj\i386\wfcnbt.obj



Linking e:\wfckrnl\sys directory ********************
'nmake.exe /c BUILDMSG=Stop. -i LINKONLY=1 NOPASS0=1 NTTEST= UMTEST=
386=1'
link -out:d:\ddk\lib\i386\free\wfcsrv.sys -machine:i386
@D:\TEMP\nma00185.
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

-MERGE:_PAGE=PAGE
-MERGE:_TEXT=.text
-SECTION:INIT,d
-OPT:REF
-INCREMENTAL:NO
-FORCE:MULTIPLE
-RELEASE
-FULLBUILD
-IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096
-NODEFAULTLIB
-debug:notmapped,MINIMAL
-debugtype:coff
-version:4.00
-osversion:4.00
-PDB:NONE
-MERGE:.rdata=.text
-optidata
-driver
-align:0x20
-subsystem:native,4.00
-base:0x10000
-entry:DriverEntry@8
-out:d:\ddk\lib\i386\free\wfcsrv.sys
d:\ddk\lib\i386\free\wfcNbt.lib
Stop.

Comments

  • Paul_BunnPaul_Bunn Member Posts: 251
    I don't see what difference iCount being signed or not would make to the for
    loop.
    int normally is equivalent to LONG. You should be able to define iCount as
    LONG or ULONG and it shouldn't make any difference to that particular loop.
    The only difference I can think of is that in the free build it is likely
    that iCount may not be assigned storage at all, but may just live as a
    register value (depending on what you're doing with it). It's also possible
    that it's a compiler bug, though that is rare these days. I would tend to
    recommend debugging the free build and looking at the disassembly.

    Regards,

    Paul Bunn, UltraBac.com, 425-644-6000
    Microsoft MVP - WindowsNT/2000
    http://www.ultrabac.com


    -----Original Message-----
    From: Eshanye [mailto:[email protected]]
    Sent: Wednesday, June 21, 2000 7:27 AM
    To: NT Developers Interest List
    Subject: [ntdev] Can we declare a variable as 'int' in the driver ???


    Hi,

    I have declared a variable as 'int' in my driver. This variable is used
    as an index inside a for loop. something like this:-

    int iCount;

    for(iCount = 3; iCount >= 0; iCount--)
    {

    blah.. blah..

    }

    This is a part of DriverEntry....

    Now this driver is working very fine if built as a checked build. But it
    wont get loaded if it is built as a free build. Because iCount is
    behaving as ULONG. and therefore it is in an infinite loop and so the
    driver is not getting loaded at all.

    [I know that I can change the for loop to serve my purpose, but ...
    why...]. I declared iCount as LONG. But still the same behavior !!!!!
    [LONG is supposed to be signed long right ????] What is happening ?
  • Gregory_G._DyessGregory_G._Dyess Member - All Emails Posts: 386
    Paul,
    Since the boundary condition is >= 0 (as opposed to just >0), it will
    make a difference whether the variable is signed or unsigned.

    You may want to explicitly declare your variable as "signed long" instead of
    long or LONG. I personally despise using the M$-supplied typedefs for
    standard types unless it's something specifically required to be so.

    Greg

    > -----Original Message-----
    > From: [email protected]
    > [mailto:[email protected]]On Behalf Of Paul Bunn
    > Sent: Wednesday, June 21, 2000 10:17 AM
    > To: NT Developers Interest List
    > Subject: [ntdev] RE: Can we declare a variable as 'int' in the driver
    > ???
    >
    >
    > I don't see what difference iCount being signed or not would make
    > to the for
    > loop.
    > int normally is equivalent to LONG. You should be able to define
    > iCount as
    > LONG or ULONG and it shouldn't make any difference to that
    > particular loop.
    > The only difference I can think of is that in the free build it is likely
    > that iCount may not be assigned storage at all, but may just live as a
    > register value (depending on what you're doing with it). It's
    > also possible
    > that it's a compiler bug, though that is rare these days. I would tend to
    > recommend debugging the free build and looking at the disassembly.
    >
    > Regards,
    >
    > Paul Bunn, UltraBac.com, 425-644-6000
    > Microsoft MVP - WindowsNT/2000
    > http://www.ultrabac.com
    >
    >
    > -----Original Message-----
    > From: Eshanye [mailto:[email protected]]
    > Sent: Wednesday, June 21, 2000 7:27 AM
    > To: NT Developers Interest List
    > Subject: [ntdev] Can we declare a variable as 'int' in the driver ???
    >
    >
    > Hi,
    >
    > I have declared a variable as 'int' in my driver. This variable is used
    > as an index inside a for loop. something like this:-
    >
    > int iCount;
    >
    > for(iCount = 3; iCount >= 0; iCount--)
    > {
    >
    > blah.. blah..
    >
    > }
    >
    > This is a part of DriverEntry....
    >
    > Now this driver is working very fine if built as a checked build. But it
    > wont get loaded if it is built as a free build. Because iCount is
    > behaving as ULONG. and therefore it is in an infinite loop and so the
    > driver is not getting loaded at all.
    >
    > [I know that I can change the for loop to serve my purpose, but ...
    > why...]. I declared iCount as LONG. But still the same behavior !!!!!
    > [LONG is supposed to be signed long right ????] What is happening ?
    >
    >
    > ---
    > You are currently subscribed to ntdev as: [email protected]
    > To unsubscribe send a blank email to $subst('Email.Unsub')
    >
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    >I don't see what difference iCount being signed or not
    When a I used to be a pupil I was given a task by my teacher to find a bug in this code:

    ULONG uCount;
    for(uCount = 10; uCount >= 0; uCount--)
    {
    // ...
    }

    And I've found it then :) This loop is infinite, 'cause uCount is always >= 0.

    ----------
    ??: Paul Bunn[SMTP:[email protected]]
    ?????: NT Developers Interest List
    ??????????: 21 ???? 2000 ?. 19:16
    ????: NT Developers Interest List
    ????: [ntdev] RE: Can we declare a variable as 'int' in the driver ???

    I don't see what difference iCount being signed or not would make to the for
    loop.
    int normally is equivalent to LONG. You should be able to define iCount as
    LONG or ULONG and it shouldn't make any difference to that particular loop.
    The only difference I can think of is that in the free build it is likely
    that iCount may not be assigned storage at all, but may just live as a
    register value (depending on what you're doing with it). It's also possible
    that it's a compiler bug, though that is rare these days. I would tend to
    recommend debugging the free build and looking at the disassembly.

    Regards,

    Paul Bunn, UltraBac.com, 425-644-6000
    Microsoft MVP - WindowsNT/2000
    http://www.ultrabac.com


    -----Original Message-----
    From: Eshanye [mailto:[email protected]]
    Sent: Wednesday, June 21, 2000 7:27 AM
    To: NT Developers Interest List
    Subject: [ntdev] Can we declare a variable as 'int' in the driver ???


    Hi,

    I have declared a variable as 'int' in my driver. This variable is used
    as an index inside a for loop. something like this:-

    int iCount;

    for(iCount = 3; iCount >= 0; iCount--)
    {

    blah.. blah..

    }

    This is a part of DriverEntry....

    Now this driver is working very fine if built as a checked build. But it
    wont get loaded if it is built as a free build. Because iCount is
    behaving as ULONG. and therefore it is in an infinite loop and so the
    driver is not getting loaded at all.

    [I know that I can change the for loop to serve my purpose, but ...
    why...]. I declared iCount as LONG. But still the same behavior !!!!!
    [LONG is supposed to be signed long right ????] What is happening ?


    ---
    You are currently subscribed to ntdev as: [email protected]
    To unsubscribe send a blank email to $subst('Email.Unsub')
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    ----- Original Message -----
    From: "Paul Bunn" <[email protected]>
    To: "NT Developers Interest List" <[email protected]>
    Sent: Wednesday, June 21, 2000 11:16 AM
    Subject: [ntdev] RE: Can we declare a variable as 'int' in the driver ???


    > I don't see what difference iCount being signed or not would make to the for
    > loop.
    > int normally is equivalent to LONG. You should be able to define iCount as
    > LONG or ULONG and it shouldn't make any difference to that particular loop.
    Huh? The value of ( (unsigned)x >= 0) is always TRUE.

    > The only difference I can think of is that in the free build it is likely
    > that iCount may not be assigned storage at all, but may just live as a
    > register value (depending on what you're doing with it). It's also possible
    > that it's a compiler bug, though that is rare these days. I would tend to
    > recommend debugging the free build and looking at the disassembly.

    The more likely thing is that the free build is failing due to some other
    unrelated problem, though perhaps you are stepping on the storage for
    this particular variable. In the debugger, disassemble this piece of code
    to validate it is using the correct comparison.
    -DH

    >
    > Regards,
    >
    > Paul Bunn, UltraBac.com, 425-644-6000
    > Microsoft MVP - WindowsNT/2000
    > http://www.ultrabac.com
    >
    >
    > -----Original Message-----
    > From: Eshanye [mailto:[email protected]]
    > Sent: Wednesday, June 21, 2000 7:27 AM
    > To: NT Developers Interest List
    > Subject: [ntdev] Can we declare a variable as 'int' in the driver ???
    >
    >
    > Hi,
    >
    > I have declared a variable as 'int' in my driver. This variable is used
    > as an index inside a for loop. something like this:-
    >
    > int iCount;
    >
    > for(iCount = 3; iCount >= 0; iCount--)
    > {
    >
    > blah.. blah..
    >
    > }
    >
    > This is a part of DriverEntry....
    >
    > Now this driver is working very fine if built as a checked build. But it
    > wont get loaded if it is built as a free build. Because iCount is
    > behaving as ULONG. and therefore it is in an infinite loop and so the
    > driver is not getting loaded at all.
    >
    > [I know that I can change the for loop to serve my purpose, but ...
    > why...]. I declared iCount as LONG. But still the same behavior !!!!!
    > [LONG is supposed to be signed long right ????] What is happening ?
    >
    >
    > ---
    > You are currently subscribed to ntdev as: [email protected]
    > To unsubscribe send a blank email to $subst('Email.Unsub')
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    >And I've found it then :) This loop is infinite, 'cause uCount is always >=
    0.

    :-)))))
    Surely, it will be 0 - and will overflow to 0xffffffff (which is MAX_ULONG
    which is > 0) on next iteration.

    Max
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Actually if the condition of the foor loop in the free build is iCount >= 0
    then in the m/c code there is no comparision at all there will be a
    unconditional jump to the beginig of the foor loop like this

    000b9 83 ef 08 sub edi, 8
    000bc eb ce jmp SHORT $L13115

    - so it goes to infinite loop. Where are in the condition of for loop in the
    free build is iCount > -1 thne in the machine code there is a comparision and
    then this a "ja" [jump if above ?? ] to the begining of the for loop...
    like this

    000ba 83 ef 08 sub edi, 8
    000bd 83 ff f8 cmp edi, -8 ; fffffff8H
    000c0 77 cb ja SHORT $L13115

    so this wont be an infinite loop !!!!! [This is the optimisation of the
    compiler ??]

    I've given the code and the generated m/c code for that.....


    Here are the two, genetated m/c codes...
    The original source code was :-
    BOOLEAN WfcInetNtoA(in_addr dwIpAddr, char * cBufPtr)
    {

    ULONG dwTempIpAddr;
    ULONG iTotalLength=0;
    ANSI_STRING DestinationString;
    UNICODE_STRING OutPutString;
    UNICODE_STRING UniCodeString;
    UNICODE_STRING DotUniString;
    CHAR OutputCharString[] = "000.000.000.000";
    WCHAR WideStr[100];
    WCHAR TempIntStr[20];
    int iCount;


    RtlInitAnsiString(
    (PANSI_STRING)&DestinationString,(PCSZ)OutputCharString);
    RtlInitUnicodeString((PUNICODE_STRING)&UniCodeString,
    (PCWSTR)WideStr);
    *(UniCodeString.Buffer) = 0;
    UniCodeString.Length =0;
    UniCodeString.MaximumLength = 100;


    RtlInitUnicodeString((PUNICODE_STRING)&OutPutString,
    (PCWSTR)TempIntStr);
    *(OutPutString.Buffer) =0;
    OutPutString.Length =0;
    OutPutString.MaximumLength =20;

    RtlInitUnicodeString((PUNICODE_STRING)&DotUniString, L".");

    for(iCount = 3;iCount > -1;iCount--)
    {
    dwTempIpAddr = dwIpAddr.S_un.S_addr;
    dwTempIpAddr = (dwTempIpAddr >> 8*iCount) & 0x000000ff;

    RtlIntegerToUnicodeString( dwTempIpAddr,10, &OutPutString );
    RtlAppendUnicodeStringToString( &UniCodeString, &OutPutString );

    RtlAppendUnicodeStringToString( &UniCodeString,&DotUniString );
    }

    RtlUnicodeStringToAnsiString( &DestinationString, &UniCodeString,
    FALSE);

    RtlCopyBytes(cBufPtr, DestinationString.Buffer,
    DestinationString.Length);

    return(TRUE);
    }
    ------------------------------------------------------------------------------------------------------------------------------------------------------------

    The machine code when the for free build of loop is (iCount = 3; iCount >= 0;
    iCount --) is ----



    ; COMDAT _WfcInetNtoA@8
    ; File e:\wfckrnl\nbt\wfcnbt.c
    _TEXT SEGMENT
    $SG13103 DB '000.000.000.000', 00H
    $SG13114 DB '.', 00H, 00H, 00H
    _dwIpAddr$ = 8
    _DestinationString$ = -32
    _OutPutString$ = -16
    _UniCodeString$ = -8
    _DotUniString$ = -24
    _OutputCharString$ = -48
    _WideStr$ = -288
    _TempIntStr$ = -88
    xxxxx@8 PROC NEAR ; COMDAT

    ; 6694 : {

    00014 55 push ebp
    00015 8b ec mov ebp, esp
    00017 81 ec 20 01 00
    00 sub esp, 288 ; 00000120H
    0001d 56 push esi
    0001e 57 push edi

    ; 6695 :
    ; 6696 : ULONG dwTempIpAddr;
    ; 6697 : ULONG iTotalLength=0;
    ; 6698 : ANSI_STRING DestinationString;
    ; 6699 : UNICODE_STRING OutPutString;
    ; 6700 : UNICODE_STRING UniCodeString;
    ; 6701 : UNICODE_STRING DotUniString;
    ; 6702 : CHAR OutputCharString[] = "000.000.000.000";

    0001f be 00 00 00 00 mov esi, OFFSET FLAT:$SG13103
    00024 8d 7d d0 lea edi, DWORD PTR _OutputCharString$[ebp]
    00027 a5 movsd
    00028 a5 movsd

    ; 6703 : WCHAR WideStr[100];
    ; 6704 : WCHAR TempIntStr[20];
    ; 6705 : int iCount;
    ; 6706 :
    ; 6707 :
    ; 6708 : RtlInitAnsiString(
    (PANSI_STRING)&DestinationString,(PCSZ)OutputCharString);

    00029 8d 45 d0 lea eax, DWORD PTR _OutputCharString$[ebp]
    0002c a5 movsd
    0002d 50 push eax
    0002e 8d 45 e0 lea eax, DWORD PTR _DestinationString$[ebp]
    00031 50 push eax
    00032 a5 movsd
    00033 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitAnsiString@8

    ; 6709 : RtlInitUnicodeString((PUNICODE_STRING)&UniCodeString,
    (PCWSTR)WideStr);

    00039 8b 35 00 00 00
    00 mov esi, DWORD PTR __imp__RtlInitUnicodeString@8
    0003f 8d 85 e0 fe ff
    ff lea eax, DWORD PTR _WideStr$[ebp]
    00045 50 push eax
    00046 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    00049 50 push eax
    0004a ff d6 call esi

    ; 6710 : *(UniCodeString.Buffer) = 0;

    0004c 8b 45 fc mov eax, DWORD PTR _UniCodeString$[ebp+4]
    0004f 33 ff xor edi, edi
    00051 66 89 38 mov WORD PTR [eax], di

    ; 6711 : UniCodeString.Length =0;
    ; 6712 : UniCodeString.MaximumLength = 100;
    ; 6713 :
    ; 6714 :
    ; 6715 : RtlInitUnicodeString((PUNICODE_STRING)&OutPutString,
    (PCWSTR)TempIntStr);

    00054 8d 45 a8 lea eax, DWORD PTR _TempIntStr$[ebp]
    00057 50 push eax
    00058 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    0005b 50 push eax
    0005c 66 89 7d f8 mov WORD PTR _UniCodeString$[ebp], di
    00060 66 c7 45 fa 64
    00 mov WORD PTR _UniCodeString$[ebp+2], 100 ; 00000064H
    00066 ff d6 call esi

    ; 6716 : *(OutPutString.Buffer) =0;

    00068 8b 45 f4 mov eax, DWORD PTR _OutPutString$[ebp+4]

    ; 6717 : OutPutString.Length =0;
    ; 6718 : OutPutString.MaximumLength =20;
    ; 6719 :
    ; 6720 : RtlInitUnicodeString((PUNICODE_STRING)&DotUniString, L".");

    0006b 68 00 00 00 00 push OFFSET FLAT:$SG13114
    00070 66 89 38 mov WORD PTR [eax], di
    00073 8d 45 e8 lea eax, DWORD PTR _DotUniString$[ebp]
    00076 50 push eax
    00077 66 89 7d f0 mov WORD PTR _OutPutString$[ebp], di
    0007b 66 c7 45 f2 14
    00 mov WORD PTR _OutPutString$[ebp+2], 20 ; 00000014H
    00081 ff d6 call esi
    00083 8b 35 00 00 00
    00 mov esi, DWORD PTR __imp__RtlAppendUnicodeStringToString@8
    00089 6a 18 push 24 ; 00000018H
    0008b 5f pop edi
    $L13115:

    ; 6721 :
    ; 6722 : for(iCount = 3;iCount >= 0;iCount--)
    ; 6723 : {
    ; 6724 :
    ; 6725 : dwTempIpAddr = dwIpAddr.S_un.S_addr;
    ; 6726 :
    ; 6727 : dwTempIpAddr = (dwTempIpAddr >> 8*iCount) & 0x000000ff;
    ; 6728 :
    ; 6729 : RtlIntegerToUnicodeString( dwTempIpAddr,
    ; 6730 : 10,
    ; 6731 : &OutPutString
    ; 6732 : );

    0008c 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    0008f 8b cf mov ecx, edi
    00091 50 push eax
    00092 8b 45 08 mov eax, DWORD PTR _dwIpAddr$[ebp]
    00095 d3 e8 shr eax, cl
    00097 6a 0a push 10 ; 0000000aH
    00099 25 ff 00 00 00 and eax, 255 ; 000000ffH
    0009e 50 push eax
    0009f ff 15 00 00 00
    00 call DWORD PTR __imp__RtlIntegerToUnicodeString@12

    ; 6733 :
    ; 6734 : RtlAppendUnicodeStringToString(
    ; 6735 : &UniCodeString,
    ; 6736 : &OutPutString
    ; 6737 : );

    000a5 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    000a8 50 push eax
    000a9 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    000ac 50 push eax
    000ad ff d6 call esi

    ; 6738 :
    ; 6739 :
    ; 6740 : RtlAppendUnicodeStringToString(
    ; 6741 : &UniCodeString,
    ; 6742 : &DotUniString
    ; 6743 : );

    000af 8d 45 e8 lea eax, DWORD PTR _DotUniString$[ebp]
    000b2 50 push eax
    000b3 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    000b6 50 push eax
    000b7 ff d6 call esi
    000b9 83 ef 08 sub edi, 8
    000bc eb ce jmp SHORT $L13115
    xxxxx@8 ENDP
    _TEXT ENDS
    EXTRN __imp__RtlUnicodeStringToInteger@12:NEAR
    EXTRN __imp__RtlAnsiStringToUnicodeString@12:NEAR
    EXTRN xxxxx@4:NEAR
    ; COMDAT _WfcInetAddr@4


    --------------------------------------------------------------------------
    when the for loop ishe free build with the for loop as you said (iCount = 3;
    iCount >-1;iCount--) the m/c code for free build will be




    ; COMDAT _WfcInetNtoA@8
    ; File e:\wfckrnl\nbt\wfcnbt.c
    _TEXT SEGMENT
    $SG13103 DB '000.000.000.000', 00H
    $SG13114 DB '.', 00H, 00H, 00H
    _dwIpAddr$ = 8
    _cBufPtr$ = 12
    _DestinationString$ = -24
    _OutPutString$ = -16
    _UniCodeString$ = -8
    _DotUniString$ = -32
    _OutputCharString$ = -48
    _WideStr$ = -288
    _TempIntStr$ = -88
    xxxxx@8 PROC NEAR ; COMDAT

    ; 6694 : {

    00014 55 push ebp
    00015 8b ec mov ebp, esp
    00017 81 ec 20 01 00
    00 sub esp, 288 ; 00000120H
    0001d 53 push ebx
    0001e 56 push esi
    0001f 57 push edi

    ; 6695 :
    ; 6696 : ULONG dwTempIpAddr;
    ; 6697 : ULONG iTotalLength=0;
    ; 6698 : ANSI_STRING DestinationString;
    ; 6699 : UNICODE_STRING OutPutString;
    ; 6700 : UNICODE_STRING UniCodeString;
    ; 6701 : UNICODE_STRING DotUniString;
    ; 6702 : CHAR OutputCharString[] = "000.000.000.000";

    00020 be 00 00 00 00 mov esi, OFFSET FLAT:$SG13103
    00025 8d 7d d0 lea edi, DWORD PTR _OutputCharString$[ebp]

    ; 6703 : WCHAR WideStr[100];
    ; 6704 : WCHAR TempIntStr[20];
    ; 6705 : int iCount;
    ; 6706 :
    ; 6707 :
    ; 6708 : RtlInitAnsiString(
    (PANSI_STRING)&DestinationString,(PCSZ)OutputCharString);

    00028 8d 45 d0 lea eax, DWORD PTR _OutputCharString$[ebp]
    0002b a5 movsd
    0002c a5 movsd
    0002d a5 movsd
    0002e 50 push eax
    0002f 8d 45 e8 lea eax, DWORD PTR _DestinationString$[ebp]
    00032 50 push eax
    00033 a5 movsd
    00034 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitAnsiString@8

    ; 6709 : RtlInitUnicodeString((PUNICODE_STRING)&UniCodeString,
    (PCWSTR)WideStr);

    0003a 8b 35 00 00 00
    00 mov esi, DWORD PTR __imp__RtlInitUnicodeString@8
    00040 8d 85 e0 fe ff
    ff lea eax, DWORD PTR _WideStr$[ebp]
    00046 50 push eax
    00047 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    0004a 50 push eax
    0004b ff d6 call esi

    ; 6710 : *(UniCodeString.Buffer) = 0;

    0004d 8b 45 fc mov eax, DWORD PTR _UniCodeString$[ebp+4]
    00050 33 db xor ebx, ebx
    00052 66 89 18 mov WORD PTR [eax], bx

    ; 6711 : UniCodeString.Length =0;
    ; 6712 : UniCodeString.MaximumLength = 100;
    ; 6713 :
    ; 6714 :
    ; 6715 : RtlInitUnicodeString((PUNICODE_STRING)&OutPutString,
    (PCWSTR)TempIntStr);

    00055 8d 45 a8 lea eax, DWORD PTR _TempIntStr$[ebp]
    00058 50 push eax
    00059 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    0005c 50 push eax
    0005d 66 89 5d f8 mov WORD PTR _UniCodeString$[ebp], bx
    00061 66 c7 45 fa 64
    00 mov WORD PTR _UniCodeString$[ebp+2], 100 ; 00000064H
    00067 ff d6 call esi

    ; 6716 : *(OutPutString.Buffer) =0;

    00069 8b 45 f4 mov eax, DWORD PTR _OutPutString$[ebp+4]

    ; 6717 : OutPutString.Length =0;
    ; 6718 : OutPutString.MaximumLength =20;
    ; 6719 :
    ; 6720 : RtlInitUnicodeString((PUNICODE_STRING)&DotUniString, L".");

    0006c 68 00 00 00 00 push OFFSET FLAT:$SG13114
    00071 66 89 18 mov WORD PTR [eax], bx
    00074 8d 45 e0 lea eax, DWORD PTR _DotUniString$[ebp]
    00077 50 push eax
    00078 66 89 5d f0 mov WORD PTR _OutPutString$[ebp], bx
    0007c 66 c7 45 f2 14
    00 mov WORD PTR _OutPutString$[ebp+2], 20 ; 00000014H
    00082 ff d6 call esi
    00084 8b 35 00 00 00
    00 mov esi, DWORD PTR __imp__RtlAppendUnicodeStringToString@8
    0008a 6a 18 push 24 ; 00000018H
    0008c 5f pop edi
    $L13115:

    ; 6721 :
    ; 6722 : for(iCount = 3;iCount > -1;iCount--)
    ; 6723 : {
    ; 6724 :
    ; 6725 : dwTempIpAddr = dwIpAddr.S_un.S_addr;
    ; 6726 :
    ; 6727 : dwTempIpAddr = (dwTempIpAddr >> 8*iCount) & 0x000000ff;
    ; 6728 :
    ; 6729 : RtlIntegerToUnicodeString( dwTempIpAddr,
    ; 6730 : 10,
    ; 6731 : &OutPutString
    ; 6732 : );

    0008d 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    00090 8b cf mov ecx, edi
    00092 50 push eax
    00093 8b 45 08 mov eax, DWORD PTR _dwIpAddr$[ebp]
    00096 d3 e8 shr eax, cl
    00098 6a 0a push 10 ; 0000000aH
    0009a 25 ff 00 00 00 and eax, 255 ; 000000ffH
    0009f 50 push eax
    000a0 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlIntegerToUnicodeString@12

    ; 6733 :
    ; 6734 : RtlAppendUnicodeStringToString(
    ; 6735 : &UniCodeString,
    ; 6736 : &OutPutString
    ; 6737 : );

    000a6 8d 45 f0 lea eax, DWORD PTR _OutPutString$[ebp]
    000a9 50 push eax
    000aa 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    000ad 50 push eax
    000ae ff d6 call esi

    ; 6738 :
    ; 6739 :
    ; 6740 : RtlAppendUnicodeStringToString(
    ; 6741 : &UniCodeString,
    ; 6742 : &DotUniString
    ; 6743 : );

    000b0 8d 45 e0 lea eax, DWORD PTR _DotUniString$[ebp]
    000b3 50 push eax
    000b4 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    000b7 50 push eax
    000b8 ff d6 call esi
    000ba 83 ef 08 sub edi, 8
    000bd 83 ff f8 cmp edi, -8 ; fffffff8H
    000c0 77 cb ja SHORT $L13115

    ; 6744 : }
    ; 6745 :
    ; 6746 : RtlUnicodeStringToAnsiString( &DestinationString,
    ; 6747 : &UniCodeString,
    ; 6748 : FALSE);

    000c2 8d 45 f8 lea eax, DWORD PTR _UniCodeString$[ebp]
    000c5 53 push ebx
    000c6 50 push eax
    000c7 8d 45 e8 lea eax, DWORD PTR _DestinationString$[ebp]
    000ca 50 push eax
    000cb ff 15 00 00 00
    00 call DWORD PTR __imp__RtlUnicodeStringToAnsiString@12

    ; 6749 :
    ; 6750 : RtlCopyBytes(cBufPtr, DestinationString.Buffer,
    DestinationString.Length);

    000d1 0f b7 4d e8 movzx ecx, WORD PTR _DestinationString$[ebp]
    000d5 8b 75 ec mov esi, DWORD PTR _DestinationString$[ebp+4]
    000d8 8b 7d 0c mov edi, DWORD PTR _cBufPtr$[ebp]
    000db 8b c1 mov eax, ecx
    000dd c1 e9 02 shr ecx, 2
    000e0 f3 a5 rep movsd
    000e2 8b c8 mov ecx, eax

    ; 6751 :
    ; 6752 : return(TRUE);

    000e4 b0 01 mov al, 1
    000e6 83 e1 03 and ecx, 3
    000e9 f3 a4 rep movsb
    000eb 5f pop edi
    000ec 5e pop esi
    000ed 5b pop ebx

    ; 6753 : }

    000ee c9 leave
    000ef c2 08 00 ret 8
    xxxxx@8 ENDP
    _TEXT ENDS
    EXTRN __imp__RtlUnicodeStringToInteger@12:NEAR
    EXTRN __imp__RtlAnsiStringToUnicodeString@12:NEAR
    EXTRN xxxxx@4:NEAR
    ; COMDAT _WfcInetAddr@4
    ---------------------------------------------------------------------------------------------------------------------



    3. If the for loop is (iCount = 3; iCount > =0 ; iCount --) and the m/c code
    for checked build will be




    ; COMDAT _WfcInetNtoA@8
    ; File e:\wfckrnl\nbt\wfcnbt.c
    _TEXT SEGMENT
    $SG13112 DB '000.000.000.000', 00H
    $SG13123 DB '.', 00H, 00H, 00H
    _dwIpAddr$ = 8
    _cBufPtr$ = 12
    _dwTempIpAddr$ = -300
    _iTotalLength$ = -264
    _DestinationString$ = -260
    _OutPutString$ = -280
    _UniCodeString$ = -252
    _DotUniString$ = -272
    _OutputCharString$ = -296
    _WideStr$ = -244
    _TempIntStr$ = -44
    _iCount$ = -4
    xxxxx@8 PROC NEAR ; COMDAT

    ; 6694 : {

    00014 55 push ebp
    00015 8b ec mov ebp, esp
    00017 81 ec 2c 01 00
    00 sub esp, 300 ; 0000012cH
    0001d 56 push esi
    0001e 57 push edi

    ; 6695 :
    ; 6696 : ULONG dwTempIpAddr;
    ; 6697 : ULONG iTotalLength=0;

    0001f c7 85 f8 fe ff
    ff 00 00 00 00 mov DWORD PTR _iTotalLength$[ebp], 0

    ; 6698 : ANSI_STRING DestinationString;
    ; 6699 : UNICODE_STRING OutPutString;
    ; 6700 : UNICODE_STRING UniCodeString;
    ; 6701 : UNICODE_STRING DotUniString;
    ; 6702 : CHAR OutputCharString[] = "000.000.000.000";

    00029 a1 00 00 00 00 mov eax, DWORD PTR $SG13112
    0002e 89 85 d8 fe ff
    ff mov DWORD PTR _OutputCharString$[ebp], eax
    00034 8b 0d 04 00 00
    00 mov ecx, DWORD PTR $SG13112+4
    0003a 89 8d dc fe ff
    ff mov DWORD PTR _OutputCharString$[ebp+4], ecx
    00040 8b 15 08 00 00
    00 mov edx, DWORD PTR $SG13112+8
    00046 89 95 e0 fe ff
    ff mov DWORD PTR _OutputCharString$[ebp+8], edx
    0004c a1 0c 00 00 00 mov eax, DWORD PTR $SG13112+12
    00051 89 85 e4 fe ff
    ff mov DWORD PTR _OutputCharString$[ebp+12], eax

    ; 6703 : WCHAR WideStr[100];
    ; 6704 : WCHAR TempIntStr[20];
    ; 6705 : int iCount;
    ; 6706 :
    ; 6707 :
    ; 6708 : RtlInitAnsiString(
    (PANSI_STRING)&DestinationString,(PCSZ)OutputCharString);

    00057 8d 8d d8 fe ff
    ff lea ecx, DWORD PTR _OutputCharString$[ebp]
    0005d 51 push ecx
    0005e 8d 95 fc fe ff
    ff lea edx, DWORD PTR _DestinationString$[ebp]
    00064 52 push edx
    00065 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitAnsiString@8

    ; 6709 : RtlInitUnicodeString((PUNICODE_STRING)&UniCodeString,
    (PCWSTR)WideStr);

    0006b 8d 85 0c ff ff
    ff lea eax, DWORD PTR _WideStr$[ebp]
    00071 50 push eax
    00072 8d 8d 04 ff ff
    ff lea ecx, DWORD PTR _UniCodeString$[ebp]
    00078 51 push ecx
    00079 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitUnicodeString@8

    ; 6710 : *(UniCodeString.Buffer) = 0;

    0007f 8b 95 08 ff ff
    ff mov edx, DWORD PTR _UniCodeString$[ebp+4]
    00085 66 c7 02 00 00 mov WORD PTR [edx], 0

    ; 6711 : UniCodeString.Length =0;

    0008a 66 c7 85 04 ff
    ff ff 00 00 mov WORD PTR _UniCodeString$[ebp], 0

    ; 6712 : UniCodeString.MaximumLength = 100;

    00093 66 c7 85 06 ff
    ff ff 64 00 mov WORD PTR _UniCodeString$[ebp+2], 100 ; 00000064H

    ; 6713 :
    ; 6714 :
    ; 6715 : RtlInitUnicodeString((PUNICODE_STRING)&OutPutString,
    (PCWSTR)TempIntStr);

    0009c 8d 45 d4 lea eax, DWORD PTR _TempIntStr$[ebp]
    0009f 50 push eax
    000a0 8d 8d e8 fe ff
    ff lea ecx, DWORD PTR _OutPutString$[ebp]
    000a6 51 push ecx
    000a7 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitUnicodeString@8

    ; 6716 : *(OutPutString.Buffer) =0;

    000ad 8b 95 ec fe ff
    ff mov edx, DWORD PTR _OutPutString$[ebp+4]
    000b3 66 c7 02 00 00 mov WORD PTR [edx], 0

    ; 6717 : OutPutString.Length =0;

    000b8 66 c7 85 e8 fe
    ff ff 00 00 mov WORD PTR _OutPutString$[ebp], 0

    ; 6718 : OutPutString.MaximumLength =20;

    000c1 66 c7 85 ea fe
    ff ff 14 00 mov WORD PTR _OutPutString$[ebp+2], 20 ; 00000014H

    ; 6719 :
    ; 6720 : RtlInitUnicodeString((PUNICODE_STRING)&DotUniString, L".");

    000ca 68 00 00 00 00 push OFFSET FLAT:$SG13123
    000cf 8d 85 f0 fe ff
    ff lea eax, DWORD PTR _DotUniString$[ebp]
    000d5 50 push eax
    000d6 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlInitUnicodeString@8

    ; 6721 :
    ; 6722 : for(iCount = 3;iCount >= 0;iCount--)

    000dc c7 45 fc 03 00
    00 00 mov DWORD PTR _iCount$[ebp], 3
    000e3 eb 09 jmp SHORT $L13124
    $L13125:
    000e5 8b 4d fc mov ecx, DWORD PTR _iCount$[ebp]
    000e8 83 e9 01 sub ecx, 1
    000eb 89 4d fc mov DWORD PTR _iCount$[ebp], ecx
    $L13124:
    000ee 83 7d fc 00 cmp DWORD PTR _iCount$[ebp], 0
    000f2 7c 62 jl SHORT $L13126

    ; 6724 :
    ; 6725 : dwTempIpAddr = dwIpAddr.S_un.S_addr;

    000f4 8b 55 08 mov edx, DWORD PTR _dwIpAddr$[ebp]
    000f7 89 95 d4 fe ff
    ff mov DWORD PTR _dwTempIpAddr$[ebp], edx

    ; 6726 :
    ; 6727 : dwTempIpAddr = (dwTempIpAddr >> 8*iCount) & 0x000000ff;

    000fd 8b 4d fc mov ecx, DWORD PTR _iCount$[ebp]
    00100 c1 e1 03 shl ecx, 3
    00103 8b 85 d4 fe ff
    ff mov eax, DWORD PTR _dwTempIpAddr$[ebp]
    00109 d3 e8 shr eax, cl
    0010b 25 ff 00 00 00 and eax, 255 ; 000000ffH
    00110 89 85 d4 fe ff
    ff mov DWORD PTR _dwTempIpAddr$[ebp], eax

    ; 6728 :
    ; 6729 : RtlIntegerToUnicodeString( dwTempIpAddr,
    ; 6730 : 10,
    ; 6731 : &OutPutString
    ; 6732 : );

    00116 8d 8d e8 fe ff
    ff lea ecx, DWORD PTR _OutPutString$[ebp]
    0011c 51 push ecx
    0011d 6a 0a push 10 ; 0000000aH
    0011f 8b 95 d4 fe ff
    ff mov edx, DWORD PTR _dwTempIpAddr$[ebp]
    00125 52 push edx
    00126 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlIntegerToUnicodeString@12

    ; 6733 :
    ; 6734 : RtlAppendUnicodeStringToString(
    ; 6735 : &UniCodeString,
    ; 6736 : &OutPutString
    ; 6737 : );

    0012c 8d 85 e8 fe ff
    ff lea eax, DWORD PTR _OutPutString$[ebp]
    00132 50 push eax
    00133 8d 8d 04 ff ff
    ff lea ecx, DWORD PTR _UniCodeString$[ebp]
    00139 51 push ecx
    0013a ff 15 00 00 00
    00 call DWORD PTR __imp__RtlAppendUnicodeStringToString@8

    ; 6738 :
    ; 6739 :
    ; 6740 : RtlAppendUnicodeStringToString(
    ; 6741 : &UniCodeString,
    ; 6742 : &DotUniString
    ; 6743 : );

    00140 8d 95 f0 fe ff
    ff lea edx, DWORD PTR _DotUniString$[ebp]
    00146 52 push edx
    00147 8d 85 04 ff ff
    ff lea eax, DWORD PTR _UniCodeString$[ebp]
    0014d 50 push eax
    0014e ff 15 00 00 00
    00 call DWORD PTR __imp__RtlAppendUnicodeStringToString@8

    ; 6744 : }

    00154 eb 8f jmp SHORT $L13125
    $L13126:

    ; 6745 :
    ; 6746 : RtlUnicodeStringToAnsiString( &DestinationString,
    ; 6747 : &UniCodeString,
    ; 6748 : FALSE);

    00156 6a 00 push 0
    00158 8d 8d 04 ff ff
    ff lea ecx, DWORD PTR _UniCodeString$[ebp]
    0015e 51 push ecx
    0015f 8d 95 fc fe ff
    ff lea edx, DWORD PTR _DestinationString$[ebp]
    00165 52 push edx
    00166 ff 15 00 00 00
    00 call DWORD PTR __imp__RtlUnicodeStringToAnsiString@12

    ; 6749 :
    ; 6750 : RtlCopyBytes(cBufPtr, DestinationString.Buffer,
    DestinationString.Length);

    0016c 8b 8d fc fe ff
    ff mov ecx, DWORD PTR _DestinationString$[ebp]
    00172 81 e1 ff ff 00
    00 and ecx, 65535 ; 0000ffffH
    00178 8b b5 00 ff ff
    ff mov esi, DWORD PTR _DestinationString$[ebp+4]
    0017e 8b 7d 0c mov edi, DWORD PTR _cBufPtr$[ebp]
    00181 8b c1 mov eax, ecx
    00183 c1 e9 02 shr ecx, 2
    00186 f3 a5 rep movsd
    00188 8b c8 mov ecx, eax
    0018a 83 e1 03 and ecx, 3
    0018d f3 a4 rep movsb

    ; 6751 :
    ; 6752 : return(TRUE);

    0018f b0 01 mov al, 1

    ; 6753 : }

    00191 5f pop edi
    00192 5e pop esi
    00193 8b e5 mov esp, ebp
    00195 5d pop ebp
    00196 c2 08 00 ret 8
    xxxxx@8 ENDP
    _TEXT ENDS
    EXTRN __imp__RtlUnicodeStringToInteger@12:NEAR
    EXTRN __imp__RtlAnsiStringToUnicodeString@12:NEAR
    EXTRN xxxxx@4:NEAR
    ; COMDAT _WfcInetAddr@4

    ------------------------------------------------------------------







    Duncan Hume wrote:

    > That is true, but as the variable was declared as int (should be signed),
    > 0xffffffff is -1. The code generated by the compiler for the var >= 0
    > should do a signed compare.
    >
    > Duncan
    >
    > -----Original Message-----
    > From: Maxim S. Shatskih [mailto:[email protected]]
    > Sent: 23 June 2000 00:39
    > To: NT Developers Interest List
    > Subject: [ntdev] RE: Can we declare a variable as 'int' in the driver
    > ???
    >
    > >And I've found it then :) This loop is infinite, 'cause uCount is always >=
    > 0.
    >
    > :-)))))
    > Surely, it will be 0 - and will overflow to 0xffffffff (which is MAX_ULONG
    > which is > 0) on next iteration.
    >
    > Max
    >
    > ---
    > You are currently subscribed to ntdev as: [email protected]
    > To unsubscribe send a blank email to $subst('Email.Unsub')
    >
    > ---
    > You are currently subscribed to ntdev as: [email protected]
    > To unsubscribe send a blank email to $subst('Email.Unsub')
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online