intptr的指针地址

时间:2014-10-11 00:12:53

标签: c# intptr

很抱歉问这个愚蠢的问题,但我正在尝试获取在远程进程中运行的lib的地址(指针)。

地址保存在intptr类型中,但是当我打印该值时,我得到一个巨大的int。

如何将其转换为0x00000等?

示例代码:

    public uint GetModuleBase(string _moduleName)
    {
        MODULEENTRY32 me32 = new MODULEENTRY32();
        IntPtr hSnapshot = IntPtr.Zero;

        me32.dwSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(me32);
        hSnapshot = CreateToolhelp32Snapshot(0x00000008, this.processId);

        // can we start looking?
        if (!Module32First(hSnapshot, ref me32))
        {
            CloseHandle(hSnapshot);
            return 0;
        }

        // enumerate all modules till we find the one we are looking for 
        // or until every one of them is checked
        while (String.Compare(me32.szModule, _moduleName) != 0 && Module32Next(hSnapshot, ref me32))
        {
            modules.Add(me32.szModule, me32.modBaseAddr);
        }

        // close the handle
        CloseHandle(hSnapshot);

        // check if module handle was found and return it
        if (String.Compare(me32.szModule, _moduleName) == 0)
        {
            return (uint)me32.modBaseAddr;
        }
        return 0;
    }

进程黑客显示lib是在地址(0x6f300000)加载的,但是当我尝试打印intptr值时,我得到一个int值(1865416704)。

1 个答案:

答案 0 :(得分:3)

您可以使用0x00000000并将ToString()部分添加为0x前缀,将整数转换为int yourNumber = 1234567890; string hexNumber = string.Format("0x{0:X}", yourNumber); 格式(仅为hexadecimal表示形式):

{{1}}

然而,没有必要这样做,因为它基本上只是一种显示格式。

相关问题