0

I have the following code involving a struct including pointer variables and I am not able to retrieve the correct contents of each variable.

Someone can help me please?

struct MyData
    {
        ULONG Value[3];
        wchar_t *Str1;
        int Str1Len;
        wchar_t *Str2;
        int Str2Len;
    };

    // In the driver, on method that receives commands i have following:

    struct MyData *pData = (struct MyData*) Irp->AssociatedIrp.SystemBuffer; 

    DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", &pData->Value[0], &pData->Value[1], &pData->Value[2], &pData.Str1, &pData->Str1Len, &pData->Str2, &pData->Str2Len);

1 Answers1

1

DbgPrint is called very much like printf is called, so you should pass the values, not the address of the values. So

DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", &pData->Value[0], // etc...

should be

DbgPrint("0x%x \n 0x%x \n 0x%x \n %s \n %d \n %s \n %d", pData->Value[0],  // etc...
Weather Vane
  • 33,872
  • 7
  • 36
  • 56
  • Moreover, the format specifiers do not all match the data types. – Weather Vane Aug 13 '17 at 23:50
  • your suggestion worked to `ULONG` type, but not worked to `wchar_t*`. –  Aug 13 '17 at 23:56
  • eg: if i send: `\\SystemRoot\\System32\\win32k.sys`, not works. Receives only one "\" on each variable `wchar_t*` –  Aug 13 '17 at 23:58
  • 1
    See my first comment. Even the `%x` for `ULONG` is incorrect, it should be `%lx`. Use `%S` for wide strings (I think). – Weather Vane Aug 14 '17 at 00:00
  • i'm sending `PWideChar` (Delphi) for each `wchar_t*` on driver. –  Aug 14 '17 at 00:05
  • still no tested, but probably the solution to `wchar_t*` is capture as index. Eg: `pData->Str1[3]` ... etc, i had forgot, sorry. –  Aug 14 '17 at 00:24