diff options
author | Jordan Borean <jborean93@gmail.com> | 2018-07-31 08:33:49 +1000 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2018-07-30 18:33:49 -0400 |
commit | d115794bf73566a1d401795b8512281951fe26d0 (patch) | |
tree | 2e61916e90741722426da9b0f6efa75857619e1c /lib/ansible/module_utils/powershell | |
parent | 240b65ddda85706d9fac330c711ff257c9ad840e (diff) | |
download | ansible-d115794bf73566a1d401795b8512281951fe26d0.tar.gz |
PrivilegeUtil: use native methods to get pointer offset (#43461)
Diffstat (limited to 'lib/ansible/module_utils/powershell')
-rw-r--r-- | lib/ansible/module_utils/powershell/Ansible.ModuleUtils.PrivilegeUtil.psm1 | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/ansible/module_utils/powershell/Ansible.ModuleUtils.PrivilegeUtil.psm1 b/lib/ansible/module_utils/powershell/Ansible.ModuleUtils.PrivilegeUtil.psm1 index 97eb44d4bf..9152d51411 100644 --- a/lib/ansible/module_utils/powershell/Ansible.ModuleUtils.PrivilegeUtil.psm1 +++ b/lib/ansible/module_utils/powershell/Ansible.ModuleUtils.PrivilegeUtil.psm1 @@ -166,7 +166,7 @@ namespace Ansible.PrivilegeUtil NativeHelpers.TOKEN_PRIVILEGES privilegeInfo = (NativeHelpers.TOKEN_PRIVILEGES)Marshal.PtrToStructure(privilegesPtr, typeof(NativeHelpers.TOKEN_PRIVILEGES)); privileges = new NativeHelpers.LUID_AND_ATTRIBUTES[privilegeInfo.PrivilegeCount]; - PtrToStructureArray(privileges, privilegesPtr.ToInt64() + Marshal.SizeOf(privilegeInfo.PrivilegeCount)); + PtrToStructureArray(privileges, IntPtr.Add(privilegesPtr, Marshal.SizeOf(privilegeInfo.PrivilegeCount))); } finally { @@ -301,7 +301,7 @@ namespace Ansible.PrivilegeUtil // Marshal the oldStatePtr to the struct NativeHelpers.TOKEN_PRIVILEGES oldState = (NativeHelpers.TOKEN_PRIVILEGES)Marshal.PtrToStructure(oldStatePtr, typeof(NativeHelpers.TOKEN_PRIVILEGES)); oldStatePrivileges = new NativeHelpers.LUID_AND_ATTRIBUTES[oldState.PrivilegeCount]; - PtrToStructureArray(oldStatePrivileges, oldStatePtr.ToInt64() + Marshal.SizeOf(oldState.PrivilegeCount)); + PtrToStructureArray(oldStatePrivileges, IntPtr.Add(oldStatePtr, Marshal.SizeOf(oldState.PrivilegeCount))); } finally { @@ -334,11 +334,11 @@ namespace Ansible.PrivilegeUtil return name.ToString(); } - private static void PtrToStructureArray<T>(T[] array, Int64 pointerAddress) + private static void PtrToStructureArray<T>(T[] array, IntPtr ptr) { - Int64 pointerOffset = pointerAddress; - for (int i = 0; i < array.Length; i++, pointerOffset += Marshal.SizeOf(typeof(T))) - array[i] = (T)Marshal.PtrToStructure(new IntPtr(pointerOffset), typeof(T)); + IntPtr ptrOffset = ptr; + for (int i = 0; i < array.Length; i++, ptrOffset = IntPtr.Add(ptrOffset, Marshal.SizeOf(typeof(T)))) + array[i] = (T)Marshal.PtrToStructure(ptrOffset, typeof(T)); } private static int StructureToBytes<T>(T structure, byte[] array, int offset) |