Sub Include(sInstFile)
Dim oFSO, f, s
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set f = oFSO.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End Sub
Set m_Filec = New MyFileClass
Set m_Regc = New MyRegClass
Set m_Strc = new MyStrGetStrClass
dim FileData
dim m_FileListFileName
dim m_TempFileName
dim m_SetOutFile
dim m_SetOutFileName
m_Filec.MyCreaterFile m_FileListFileName , m_SetOutFileName
m_Filec.MyReadFileLineStr_Old m_FileListFileName , 1 , m_TempFileName
if m_SetOutFileName = m_TempFileName then
m_SetOutFile = 1
m_Filec.MyDeleteFile m_SetOutFileName
end if
m_Filec.SetReadFileName m_FileListFileName
do while m_Filec.TestReadFileLineStr()
m_FileListFileName = m_Filec.ReadFileLineStr()
if 1 = m_Filec.MyCheckFile( m_FileListFileName ) then
FileData = ReadBinary( m_FileListFileName )
if 1 = m_SetOutFile then
m_TempFileName = m_SetOutFileName
else
m_TempFileName = m_Strc.GetShortFileNameStr( m_FileListFileName ) & "_需要的输入模块列表.txt"
m_Filec.MyDeleteFile m_TempFileName
end if
Get_PEImportDirectory_ListToFile FileData , Len(FileData) , m_TempFileName
End if
Loop
msgbox "操作结束"
'获取输入表字符串 输出到文件 I_OutListFileName
Public Function Get_PEImportDirectory_ListToFile( ByVal I_FileData , ByVal I_FileData_Len , ByVal I_OutListFileName )
dim t_TempOffset
dim t_PeHOffset ' PE头部的RVA PE标签(00004550) 的RVA PE文件头部 大小 24B
dim t_SizeOfOptionalHeader ' PE可选头部的大小
dim t_PEOptiHeader ' PE扩展头部的RVA
dim t_PEDataDirectory ' PE数据目录的RVA
dim t_PESectionHeader ' 节表的RVA
dim t_NumberOfSections ' 节表计数
dim t_Magic ' PE类型标签 这里区分32位还是64位的PE
dim t_FileAlignment ' PE节数据在文件中的对齐粒度
dim t_ImportDirectory_Rva ' 输入表的 RVA
dim t_ImportDirectory_Len ' 输入表的 大小
if 0 = IsPEFile_InHexStr( I_FileData , I_FileData_Len ) then
Exit Function
end if
'节表的RVA
t_PESectionHeader = t_PEOptiHeader + t_SizeOfOptionalHeader
if ( t_PESectionHeader + t_NumberOfSections * 40 ) * 2 >= I_FileData_Len then
Exit Function
end if
' PE节数据在文件中的对齐粒度
t_FileAlignment = 0
if 523 = t_Magic then
t_FileAlignment = &H134 - &H110 + t_PEOptiHeader
end if
if 267 = t_Magic then
t_FileAlignment = &H124 - &H100 + t_PEOptiHeader
end if
if ( 0 = t_ImportDirectory_Rva ) Or ( 0 = t_ImportDirectory_Len ) then
Exit Function
end if
dim th_ImportDirectory ' 输入表的偏移量
dim i , tti
dim t_DllName
dim th_DllName
dim t_DllName_Rva
Set t_Filec = New MyFileClass
th_ImportDirectory = GetRvaInPESectionHeader( I_FileData , I_FileData_Len , t_PESectionHeader , t_NumberOfSections , t_FileAlignment , t_ImportDirectory_Rva )
if 0 = th_ImportDirectory then
Exit Function
end if
if th_ImportDirectory + t_ImportDirectory_Len * 2 >= I_FileData_Len then
Exit Function
end if
i = 12 * 2
do while 1
if th_ImportDirectory + i + 8 >= I_FileData_Len then
Exit Do
end if
t_DllName = H2H( mid( I_FileData , th_ImportDirectory + i , 8 ))
if "00000000" = t_DllName then
Exit Do
end if
t_DllName_Rva = Clng( "&H" & t_DllName )
th_DllName = GetRvaInPESectionHeader( I_FileData , I_FileData_Len , t_PESectionHeader , t_NumberOfSections , t_FileAlignment , t_DllName_Rva )
if 0 = th_DllName then
Exit Do
end if
t_DllName = ""
tti = 0
do while 1
if "00" = mid( I_FileData , th_DllName + tti , 2 ) then
Exit Do
end if
t_DllName = t_DllName + Chr("&H" & mid( I_FileData , th_DllName + tti , 2 ))
tti = tti + 2
Loop
if 0 <> t_SizeOfRawData then
't_SizeOfRawData = Clng(( t_SizeOfRawData + I_FileAlignment - 1) / I_FileAlignment ) '这里的运算视乎有问题
if (( t_VirtualAddress + t_SizeOfRawData ) > I_Rva ) and ( I_Rva >= t_VirtualAddress ) then
if ( t_PointerToRawData + t_SizeOfRawData ) * 2 > I_FileData_Len then
Exit Function
end if