Software & Application Miscellaneous: ZwOpenFile helppppppppp

  • anonymous / 205 / Fri, 29 Jan 2010 21:51:00 GMT / Comments (5)
  • Hi all !
    I must Open a file in my Driver , The fragment code as below . But it always can not be opened .. Pls tell me why '
    Thanks in advance !

    HANDLE fileOpen;
    OBJECT_ATTRIBUTES objAttr;
    UNICODE_STRING sLinkName;
    #define FILE_NAME L"C:\\test.out"
    RtlInitUnicodeString( &sLinkName, FILE_NAME);

    KIRQL oldIrql,
    newIrql = PASSIVE_LEVEL;
    KeRaiseIrql(newIrql,&oldIrql);
    InitializeObjectAttributes(
    &objAttr,
    &sLinkName,
    OBJ_KERNEL_HANDLE,
    NULL,
    NULL);

    LARGE_INTEGER nSize;
    IO_STATUS_BLOCK ioStat;

    NTSTATUS statusOpen = ZwOpenFile(
    OUT &fileOpen,
    IN FILE_READ_DATA | FILE_WRITE_DATA,
    IN &objAttr,
    OUT &ioStat,
    IN FILE_SHARE_READ,
    IN FILE_NON_DIRECTORY_FILE
    );
  • Keywords:

    zwopenfile, helppppppppp, software, application

  • http://software.itags.org/software-application/240742/«« Last Thread - Next Thread »»
    1. Alex
      You did not specify how exactly did the ZwOpenFile failed, more details could be useful..
      You cannot access files with this path, try \\'\\C:\\test.out
      Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you aren't already ther
      you should not try to use the ZwOpenFile

      G

      anonymous | Tues, 20 May 2008 08:05:00 GMT |

    2. Thank you so much ! Gram !
      In fact , I must Open COM port in my driver , but I tried to open a normal
      file first, and have not openned it . So I do not understand why .
      I have deleted the lines KeRaiseIrdl . And tried with path
      \\'\\C:\\test.out . and always get errors. Maybe in
      InitializeObjectAttrbutes'
      If you have any idea about openning COM port , pls help me directly with COM
      . I am now very confuse .
      Waiting for help from you !
      Thank you so much !

      HANDLE fileOpen;
      OBJECT_ATTRIBUTES objAttr;
      UNICODE_STRING sLinkName;
      #define COM_NAME L"\\'\\C:\\test.out"
      RtlInitUnicodeString( &sLinkName, COM_NAME);

      InitializeObjectAttributes(
      &objAttr,
      &sLinkName,
      OBJ_EXCLUSIVE,
      NULL,
      NULL);

      LARGE_INTEGER nSize;
      IO_STATUS_BLOCK ioStat;

      NTSTATUS statusOpen = ZwOpenFile(
      OUT &fileOpen,
      IN FILE_READ_DATA | FILE_WRITE_DATA,
      IN &objAttr,
      OUT &ioStat,
      IN FILE_SHARE_READ,
      IN FILE_NON_DIRECTORY_FILE
      );

      DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=C000000D.

      "Gram" <anonymous...discussions.microsoft.com> wrote in message
      news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
      > Alex,
      > You did not specify how exactly did the ZwOpenFile failed, more details
      could be useful...
      > You cannot access files with this path, try \\'\\C:\\test.out.
      > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
      aren't already there
      > you should not try to use the ZwOpenFile?
      > G.
      >

      alex | Tues, 20 May 2008 08:06:00 GMT |

    3. NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"

      So, double check your parameters, re-read the ddk documentation for
      ZwOpenFile, and, don' use something you don't understand or didn't check out
      in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?

      Did you looked in DDK what OBJ_EXCLUSIVE is used for?

      "Alex" <Chipheo2k...hotmail.com> wrote in message
      news:ujGwCnvREHA.3660...tk2msftngp13.phx.gbl...

      > Thank you so much ! Gram !
      > In fact , I must Open COM port in my driver , but I tried to open a
      normal
      > file first, and have not openned it . So I do not understand why .
      > I have deleted the lines KeRaiseIrdl . And tried with path
      > \\'\\C:\\test.out . and always get errors. Maybe in
      > InitializeObjectAttrbutes'
      > If you have any idea about openning COM port , pls help me directly with
      COM
      > . I am now very confuse .
      > Waiting for help from you !
      > Thank you so much !
      > HANDLE fileOpen;
      > OBJECT_ATTRIBUTES objAttr;
      > UNICODE_STRING sLinkName;
      > #define COM_NAME L"\\'\\C:\\test.out"
      > RtlInitUnicodeString( &sLinkName, COM_NAME);
      > InitializeObjectAttributes(
      > &objAttr,
      > &sLinkName,
      > OBJ_EXCLUSIVE,
      > NULL,
      > NULL);
      > LARGE_INTEGER nSize;
      > IO_STATUS_BLOCK ioStat;
      >
      > NTSTATUS statusOpen = ZwOpenFile(
      > OUT &fileOpen,
      > IN FILE_READ_DATA | FILE_WRITE_DATA,
      > IN &objAttr,
      > OUT &ioStat,
      > IN FILE_SHARE_READ,
      > IN FILE_NON_DIRECTORY_FILE
      > );
      >
      > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> C000000D.
      >
      >
      >
      > "Gram" <anonymous...discussions.microsoft.com> wrote in message
      > news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
      > > Alex,
      > > You did not specify how exactly did the ZwOpenFile failed, more details
      > could be useful...
      > > You cannot access files with this path, try \\'\\C:\\test.out.
      > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
      > aren't already there
      > > you should not try to use the ZwOpenFile?
      > >
      > > G.
      > >
      >

      alex | Tues, 20 May 2008 08:07:00 GMT |

    4. Thank Alex!
      So which value must be used for it ?
      For a normal file ( text file ) , and for a Device ( Comm Port ) . I only
      tried to pass different values to get true result . In DDK wrote nothing
      about it !
      damm ..

      "Alex the 1'ts" <AlX...a> wrote in message
      news:OrgLnzxREHA.2496...TK2MSFTNGP11.phx.gbl...
      > NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"
      > So, double check your parameters, re-read the ddk documentation for
      > ZwOpenFile, and, don' use something you don't understand or didn't check
      out
      > in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?
      > Did you looked in DDK what OBJ_EXCLUSIVE is used for?
      >
      > "Alex" <Chipheo2k...hotmail.com> wrote in message
      > news:ujGwCnvREHA.3660...tk2msftngp13.phx.gbl...
      > > Thank you so much ! Gram !
      > > In fact , I must Open COM port in my driver , but I tried to open a
      > normal
      > > file first, and have not openned it . So I do not understand why .
      > > I have deleted the lines KeRaiseIrdl . And tried with path
      > > \\'\\C:\\test.out . and always get errors. Maybe in
      > > InitializeObjectAttrbutes'
      > > If you have any idea about openning COM port , pls help me directly with
      > COM
      > > . I am now very confuse .
      > > Waiting for help from you !
      > > Thank you so much !
      > >
      > > HANDLE fileOpen;
      > > OBJECT_ATTRIBUTES objAttr;
      > > UNICODE_STRING sLinkName;
      > > #define COM_NAME L"\\'\\C:\\test.out"
      > > RtlInitUnicodeString( &sLinkName, COM_NAME);
      > >
      > > InitializeObjectAttributes(
      > > &objAttr,
      > > &sLinkName,
      > > OBJ_EXCLUSIVE,
      > > NULL,
      > > NULL);
      > >
      > > LARGE_INTEGER nSize;
      > > IO_STATUS_BLOCK ioStat;
      > >
      > >
      > > NTSTATUS statusOpen = ZwOpenFile(
      > > OUT &fileOpen,
      > > IN FILE_READ_DATA | FILE_WRITE_DATA,
      > > IN &objAttr,
      > > OUT &ioStat,
      > > IN FILE_SHARE_READ,
      > > IN FILE_NON_DIRECTORY_FILE
      > > );
      > >
      > >
      > > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> > C000000D.
      > >
      > >
      > >
      > >
      > >
      > >
      > > "Gram" <anonymous...discussions.microsoft.com> wrote in message
      > > news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
      > > > Alex,
      > > > You did not specify how exactly did the ZwOpenFile failed, more
      details
      > > could be useful...
      > > > You cannot access files with this path, try \\'\\C:\\test.out.
      > > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
      you
      > > aren't already there
      > > > you should not try to use the ZwOpenFile?
      > > >
      > > > G.
      > > >
      > >
      > >
      >

      alex | Tues, 20 May 2008 08:08:00 GMT |

    5. > > > InitializeObjectAttributes(
      > > > &objAttr,
      > > > &sLinkName,
      > > > OBJ_EXCLUSIVE,
      > > > NULL,
      > > > NULL);

      Why do you use OBJ_EXCLUSIVE? This flas IS documented in the DDK, did you
      look at it?

      > > >
      > > > LARGE_INTEGER nSize;
      > > > IO_STATUS_BLOCK ioStat;
      > > >
      > > >
      > > > NTSTATUS statusOpen = ZwOpenFile(
      > > > OUT &fileOpen,
      > > > IN FILE_READ_DATA | FILE_WRITE_DATA,
      > > > IN &objAttr,
      > > > OUT &ioStat,
      > > > IN FILE_SHARE_READ,
      > > > IN FILE_NON_DIRECTORY_FILE
      > > > );

      ZwOpenFile IS well documented in the DDK, did you read the documentation
      carefully? Even at a glance I can see a wrong parameter.
      If the OS tells you, you used same invalid parameters, you better belive it.
      Now, why don't you look in the DDK and see for yourself?

      > > >
      > > >
      > > > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> > > C000000D.
      > > >
      > > >
      > > >
      > > >
      > > >
      > > >
      > > > "Gram" <anonymous...discussions.microsoft.com> wrote in message
      > > > news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
      > > > > Alex,
      > > > > You did not specify how exactly did the ZwOpenFile failed, more
      > details
      > > > could be useful...
      > > > > You cannot access files with this path, try \\'\\C:\\test.out.
      > > > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
      > you
      > > > aren't already there
      > > > > you should not try to use the ZwOpenFile?
      > > > >
      > > > > G.
      > > > >
      > > >
      > > >
      > >
      > >
      >

      alex | Tues, 20 May 2008 08:09:00 GMT |