0

I am trying to read a value from a text file through kernel, which I do so via: 'ZwReadFile' and read into a CHAR streamRead[32]

Printing this value shows

Value is: 0000021A5DFFD9B0 which is the correct string from the file, I then wish to pass this to a call of MmCopyVirtualMemory, which causes me problems and the functions fails because of this variable, replacing it with the hardcoded 0x0000021A5DFFD9B0 works fine, can someone please point me in the right direction on how I can convert my value to a memory address?

The final form needs to be PVOID, but tried everything and can't get this to work properly, any help much appreciated,

Thanks

Lit
  • 15
  • 4
  • 1
    Presumably it's read in hexadecimal (ASCII characters between 0-9a-fA-F), so you need to convert back to bytes (combining two hex characters to make one raw byte). You'd also need to [reverse the byte order if the data was stored big endian and you're on a little endian system](https://stackoverflow.com/q/3022552/364696). – ShadowRanger Aug 25 '22 at 19:43
  • You want to convert a string to a number, in hexadecimal. That's what to look for. – user253751 Aug 25 '22 at 19:58
  • Can you use strtoull ? like this: https://onlinegdb.com/DwIsa6aQ1 – Jerry Jeremiah Aug 25 '22 at 21:46
  • Here is another question about converting strings of hex to integers: https://stackoverflow.com/questions/10156409/convert-hex-string-char-to-int https://stackoverflow.com/questions/10324/convert-a-hexadecimal-string-to-an-integer-efficiently-in-c – Jerry Jeremiah Aug 25 '22 at 21:51

1 Answers1

0
long long hexstr_to_hexint(char hex[])
{
    long long decimal = 0, base = 1;
    int i = 0, length;
    length = strlen(hex);
    for (i = length--; i >= 0; i--)
    {
        if (hex[i] >= '0' && hex[i] <= '9')
        {
            decimal += (hex[i] - 48) * base;
            base *= 16;
        }
        else if (hex[i] >= 'A' && hex[i] <= 'F')
        {
            decimal += (hex[i] - 55) * base;
            base *= 16;
        }
        else if (hex[i] >= 'a' && hex[i] <= 'f')
        {
            decimal += (hex[i] - 87) * base;
            base *= 16;
        }
    }

    return decimal;
}

Found some of this code elsewhere but can't remember where, edited to work properly however and removed clutter.

Lit
  • 15
  • 4