AM电脑吧 - Win10精简版系统_Win11精简版_Win7旗舰版

Yes
查看: 4856|回复: 0
收起左侧

[其它] 一段获取ADSL用户名密码的au3 Func

[复制链接]
ampc81

签到天数: 679 天

[LV.9]九级电脑高手

id 发表于 2011-05-09 18:16:49
  1. Global Const $POLICY_GET_PRIVATE_INFORMATION = 4
  2. If Not IsDeclared("ERROR_INVALID_SID") Then Global Const $ERROR_INVALID_SID = 1337
  3. Global Const $tagLSAUNICODE = "ushort Length;ushort MaxLength;ptr Wbuffer"
  4. Global Const $tagLSAOBJATTR = "ulong Length;hWnd RootDir;ptr objName;ulong Attr;ptr SecurDescr;ptr SecurQuality"
  5. MsgBox(0, "ADSL 账号密码", _FINDADSL()); 失败返回0,成功返回ADSL用户名及密码
  6. Func _FINDADSL()
  7. Dim $pSid = _LookupAccountName(@UserName) ; 获取用户SID指针。
  8. Dim $sSid = _ConvertSidToStringSid($pSid) ; 转换为字符型SID。
  9. _HeapFree($pSid)
  10. Dim $bData = _LsaRetrievePrivateData("RasDialParams!" & $sSid & "#0")
  11. $iSize = @extended
  12. If $bData <> "" Then
  13. Return _ADSL($iSize, $bData)
  14. Else
  15. $bData = _LsaRetrievePrivateData("L$_RasDefaultCredentials#0")
  16. $iSize = @extended
  17. If $bData <> "" Then
  18. Return _ADSL($iSize, $bData)
  19. EndIf
  20. EndIf
  21. EndFunc ;==>_FINDADSL
  22. Func _ADSL($iSize, $bData)
  23. Dim $tB = DllStructCreate("byte[" & $iSize & "]")
  24. Dim $pB = DllStructGetPtr($tB)
  25. Dim $tW = DllStructCreate("wchar[" & $iSize / 2 & "]", $pB)
  26. DllStructSetData($tB, 1, $bData)
  27. Dim $sR = ""
  28. For $i = 1 To $iSize / 2
  29. Dim $sC = DllStructGetData($tW, 1, $i)
  30. If $sC = Chr(0) And StringRight($sR, 1) <> " " Then $sR &= " "
  31. If $sC <> Chr(0) Then $sR &= $sC
  32. Next
  33. Dim $ADSJ = StringSplit($sR, " ", 1)
  34. If $ADSJ[4] <> "" And $ADSJ[5] <> "" Then
  35. Return $ADSJ[4] & "|" & $ADSJ[5]
  36. Else
  37. Return 0
  38. EndIf
  39. EndFunc ;==>_ADSL
  40. Func _LookupAccountName($sName, $sSystem = "")
  41. Local $iResult, $pSid, $pDomain, $iSysError
  42. $iResult = DllCall("Advapi32.dll", "int", "LookupAccountName", _
  43. "str", $sSystem, "str", $sName, "ptr", 0, "int*", 0, _
  44. "ptr", 0, "int*", 0, "int*", 0)
  45. $pSid = _HeapAlloc($iResult[4])
  46. $pDomain = _HeapAlloc($iResult[6])
  47. $iResult = DllCall("Advapi32.dll", "int", "LookupAccountName", _
  48. "str", $sSystem, "str", $sName, _
  49. "ptr", $pSid, "int*", $iResult[4], _
  50. "ptr", $pDomain, "int*", $iResult[6], "int*", 0)
  51. $iSysError = _GetLastError()
  52. _HeapFree($pDomain)
  53. Return SetError($iSysError, $iResult[7], $pSid)
  54. EndFunc ;==>_LookupAccountName
  55. Func _ConvertSidToStringSid($pSid)
  56. Local $iResult, $tBuffer, $iSysError, $sResult
  57. If Not _IsValidSid($pSid) Then Return SetError(@error, 0, "")
  58. $iResult = DllCall("Advapi32.dll", "int", "ConvertSidToStringSid", _
  59. "ptr", $pSid, "ptr*", 0)
  60. If $iResult[0] = 0 Then $iSysError = _GetLastError()
  61. If $iResult[2] = 0 Then Return SetError($iSysError, 0, "")
  62. $tBuffer = DllStructCreate("char[256]", $iResult[2])
  63. $sResult = DllStructGetData($tBuffer, 1)
  64. _LsaLocalFree($iResult[2])
  65. Return SetError($iSysError, _FreeVariable($tBuffer), $sResult)
  66. EndFunc ;==>_ConvertSidToStringSid
  67. Func _LsaRetrievePrivateData($sKeyName, $sSystem = "")
  68. Local $hPolicy, $iResult, $pKeyName, $bData, $iSize, $tBuffer
  69. $hPolicy = _LsaOpenPolicy($POLICY_GET_PRIVATE_INFORMATION, $sSystem)
  70. If $hPolicy = 0 Then Return SetError(@error, 0, 0)
  71. $pKeyName = _LsaInitializeBufferW($sKeyName)
  72. $iResult = DllCall("Advapi32.dll", "dword", "LsaRetrievePrivateData", _
  73. "hWnd", $hPolicy, "ptr", $pKeyName, "ptr*", 0)
  74. $iSize = _LsaLocalSize($iResult[3]) - 12
  75. $tBuffer = DllStructCreate("byte[" & $iSize & "]", $iResult[3] + 12)
  76. $bData = DllStructGetData($tBuffer, 1)
  77. _LsaClose($hPolicy)
  78. _FreeVariable($tBuffer)
  79. _HeapFree($pKeyName)
  80. _LsaFreeMemory($iResult[3])
  81. Return SetError(_LsaNtStatusToWinError($iResult[0]), $iSize, $bData)
  82. EndFunc ;==>_LsaRetrievePrivateData
  83. Func _HeapAlloc($iSize, $iAllocOption = 8)
  84. If $iSize < 1 Then Return 0
  85. Local $pMem, $hHeap = _GetProcessHeap()
  86. $pMem = DllCall("Kernel32.dll", "ptr", "HeapAlloc", "hWnd", $hHeap, _
  87. "dword", $iAllocOption, "dword", $iSize)
  88. Return $pMem[0]
  89. EndFunc ;==>_HeapAlloc
  90. Func _GetLastError()
  91. Local $iSysError = DllCall("Kernel32.dll", "long", "GetLastError")
  92. Return $iSysError[0]
  93. EndFunc ;==>_GetLastError
  94. Func _IsValidSid($pSid)
  95. Local $iResult
  96. $iResult = DllCall("Advapi32.dll", "int", "IsValidSid", "ptr", $pSid)
  97. If $iResult[0] Then Return SetError(0, 0, True)
  98. Return SetError($ERROR_INVALID_SID, 0, False)
  99. EndFunc ;==>_IsValidSid
  100. Func _LsaOpenPolicy($iAccessMask, $sSystem = "")
  101. Local $hPolicy, $tSystem, $pSystem, $iLength
  102. Local $tObjAttr, $pObjAttr, $tName, $pName
  103. If $sSystem <> "" Then
  104. $iLength = StringLen($sSystem) * 2
  105. $tSystem = DllStructCreate($tagLSAUNICODE)
  106. $pSystem = DllStructGetPtr($tSystem)
  107. $tName = DllStructCreate("wchar[" & $iLength & "]")
  108. $pName = DllStructGetPtr($tName)
  109. DllStructSetData($tName, 1, $sSystem)
  110. DllStructSetData($tSystem, "Length", $iLength)
  111. DllStructSetData($tSystem, "MaxLength", $iLength + 2)
  112. DllStructSetData($tSystem, "Wbuffer", $pName)
  113. EndIf
  114. $tObjAttr = DllStructCreate($tagLSAOBJATTR)
  115. $pObjAttr = DllStructGetPtr($tObjAttr)
  116. $hPolicy = DllCall("Advapi32.dll", "dword", "LsaOpenPolicy", _
  117. "ptr", $pSystem, "ptr", $pObjAttr, _
  118. "dword", $iAccessMask, "hWnd*", 0)
  119. _FreeVariable($tName)
  120. _FreeVariable($tObjAttr)
  121. _FreeVariable($tSystem)
  122. Return SetError(_LsaNtStatusToWinError($hPolicy[0]), 0, $hPolicy[4])
  123. EndFunc ;==>_LsaOpenPolicy
  124. Func _HeapFree($pMem)
  125. If $pMem < 1 Then Return SetError(87, 0, False)
  126. Local $iResult, $hHeap = _GetProcessHeap()
  127. $iResult = DllCall("Kernel32.dll", "int", "HeapFree", "hWnd", $hHeap, _
  128. "dword", 0, "ptr", $pMem)
  129. Return $iResult[0] <> 0
  130. EndFunc ;==>_HeapFree
  131. Func _LsaLocalFree($pMem)
  132. Local $iResult
  133. $iResult = DllCall("Kernel32.dll", "int", "LocalFree", "ptr", $pMem)
  134. Return $iResult[0] <> $pMem
  135. EndFunc ;==>_LsaLocalFree
  136. Func _FreeVariable(ByRef $vVariable)
  137. $vVariable = 0
  138. EndFunc ;==>_FreeVariable
  139. Func _LsaInitializeBufferW($sData, $fDecode = False)
  140. Local $pMem, $iLength, $tBuffer, $sResult
  141. If $fDecode = False Then
  142. $iLength = StringLen($sData) * 2 + 2
  143. $pMem = _HeapAlloc($iLength + 8)
  144. $tBuffer = DllStructCreate($tagLSAUNICODE & ";wchar Data[" & $iLength - 2 & "]", $pMem)
  145. DllStructSetData($tBuffer, "Length", $iLength - 2)
  146. DllStructSetData($tBuffer, "MaxLength", $iLength)
  147. DllStructSetData($tBuffer, "Wbuffer", $pMem + 8)
  148. DllStructSetData($tBuffer, "Data", $sData)
  149. Return $pMem
  150. ElseIf Not IsPtr($sData) Then
  151. Return ""
  152. EndIf
  153. $tBuffer = DllStructCreate($tagLSAUNICODE, $sData)
  154. $iLength = DllStructGetData($tBuffer, "MaxLength") * 2
  155. If $iLength < 1 Then Return ""
  156. $pMem = DllStructCreate("wchar Data[" & $iLength & "]", DllStructGetData($tBuffer, "Wbuffer"))
  157. $sResult = DllStructGetData($pMem, "Data")
  158. Return SetExtended(_FreeVariable($pMem), $sResult)
  159. EndFunc ;==>_LsaInitializeBufferW
  160. Func _LsaLocalSize($pMem)
  161. Local $iSize = DllCall("Kernel32.dll", "long", "LocalSize", "ptr", $pMem)
  162. Return $iSize[0]
  163. EndFunc ;==>_LsaLocalSize
  164. Func _LsaCloseServiceHandle($hService)
  165. Local $iResult = DllCall("Advapi32.dll", "int", "CloseServiceHandle", "hWnd", $hService)
  166. Return SetError(_GetLastError(), 0, $iResult[0] <> 0)
  167. EndFunc ;==>_LsaCloseServiceHandle
  168. Func _LsaCloseHandle($hHandle)
  169. Local $iResult = DllCall("Kernel32.dll", "int", "CloseHandle", "long", $hHandle)
  170. Return $iResult[0] <> 0
  171. EndFunc ;==>_LsaCloseHandle
  172. Func _LsaClose($hPolicy)
  173. Local $iResult
  174. $iResult = DllCall("Advapi32.dll", "dword", "LsaClose", "hWnd", $hPolicy)
  175. Return SetError(_LsaNtStatusToWinError($iResult[0]), 0, $iResult = 0)
  176. EndFunc ;==>_LsaClose
  177. Func _LsaFreeMemory($pMem)
  178. Local $iResult = DllCall("Advapi32.dll", "dword", "LsaFreeMemory", "ptr", $pMem)
  179. Return SetError(_LsaNtStatusToWinError($iResult[0]), 0, $iResult[0] = 0)
  180. EndFunc ;==>_LsaFreeMemory
  181. Func _LsaNtStatusToWinError($iNtStatus)
  182. Local $iSysError
  183. $iSysError = DllCall("Advapi32.dll", "ulong", "LsaNtStatusToWinError", "dword", $iNtStatus)
  184. Return $iSysError[0]
  185. EndFunc ;==>_LsaNtStatusToWinError
  186. Func _GetProcessHeap()
  187. Local $hHeap = DllCall("Kernel32.dll", "hWnd", "GetProcessHeap")
  188. Return $hHeap[0]
  189. EndFunc ;==>_GetProcessHeap
复制代码

本文地址: https://www.ampc8.com/thread-493-1-1.html
上一篇:Windows XP2003 序列号更换工具au3源码
下一篇:VMware Workstation 7.0.1 Build 227600 Lite 英文版 (VM虚拟机)
回复

举报

您需要登录后才可以回帖 登录 | 验证注册

Powered by AMpc8.Com (晋ICP备13003365号ghs 晋公网安备 14090202000112号 |GMT+8, 2025/5/1 04:00 | A
快速回复 返回顶部 返回列表