List a File's Dependencies
Get a list of a files dependencies. For example, calling ListDependencies "C:\WINDOWS\SYSTEM32\MSVBVM60.DLL", results in "KERNEL32.dll USER32.dll GDI32.dll ADVAPI32.dll ole32.dll OLEAUT32.dll".
AI
Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Kode Sumber
'Lists the dependencies of sFile
Public Function ListDependencies(sFile As String)
If (Dir(sFile, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem) <> "") Then
Dim lRet As Long
Dim m_LI As LOADED_IMAGE
Dim m_NTHdr As IMAGE_NT_HEADERS
Dim sWholeFile As String
sWholeFile = sFile
DoEvents
If MapAndLoad(sWholeFile, vbNullString, m_LI, True, True) Then
MoveMemory m_NTHdr, ByVal m_LI.FileHeader, Len(m_NTHdr)
Dim aModules() As String
Dim lNumModules As Long
Dim ImpDir As IMAGE_IMPORT_DESCRIPTOR
Dim lNamePtr As Long, lIdx As Long
Dim lImpPtr As Long, lSize As Long
lNumModules = 0
Erase aModules
lImpPtr = ImageDirectoryEntryToData(m_LI.MappedAddress, 0, 1, lSize)
If lImpPtr Then
MoveMemory ImpDir, ByVal lImpPtr, Len(ImpDir)
Do Until ImpDir.Name = 0
ReDim Preserve aModules(0 To lIdx)
aModules(lIdx) = sStringFromRVA(ImpDir.Name, m_LI)
lIdx = lIdx + 1
MoveMemory ImpDir, ByVal lImpPtr + (Len(ImpDir) * lIdx), Len(ImpDir)
DoEvents
Loop
lNumModules = lIdx
End If
For lIdx = 0 To lNumModules - 1
Debug.Print aModules(lIdx)
Next lIdx
UnMapAndLoad m_LI
End If
Else
Debug.Print "File " & sFile & " Doesn't Exist"
End If
End Function
'sStringFromRVA(ByVal RVA As Long) As String
'This will grab a string located at a given RVA
Private Function sStringFromRVA(ByVal RVA As Long, m_LI As LOADED_IMAGE) As String
Dim lVA As Long
lVA = ImageRvaToVa(ByVal m_LI.FileHeader, m_LI.MappedAddress, RVA)
sStringFromRVA = String$(lstrlenA(lVA) + 1, 0)
lstrcpyA sStringFromRVA, lVA
If InStr(sStringFromRVA, vbNullChar) Then
sStringFromRVA = Left$(sStringFromRVA, InStr(sStringFromRVA, vbNullChar) - 1)
End If
End Function
Komentar Asli (3)
Dipulihkan dari Wayback Machine