Tak patrzę jak czas przechodzi bezczynnie – święta mijają…
Wpadłem więc na pomysł, że może coś na blogu zamieszczę z mojej pracy. Jak, niektórzy wiedzą współtworzyłem projekt Odin – Win32 dla OS/2. Dawno temu już o tym zapomniałem, ale baaaardzo lubię hacking. Będąc w Kolumbii miałem źródła wcześniejszej wersji całego softu, lecz nie miałem najnowszej wersji. DLLki różniły się exportami, więc potrzebowałem czegoś takiego jak pod OS/2 – DLL -> LIB, żeby można było zlinkować mój kod z nowymi bibliotekami. Nie wiedziałem, że trzeba było troszkę się pomęczyć. Najpierw dumpbin.exe, a następnie lib. Ale pomiędzy tymi dwoma czynnościami należało zrobić plik def… Załączam więc prosty skrypt w vbs, który to robi automatycznie (Copy & Paste).
Używamy: Dll2Lib.vbs kernel32.dll kernel32.lib
PS. Używam Visual Studio 2005, więc jeśli ktoś potrzebuje inne to należy zmienić ścieżki w VC_ENVIRNOMENT.
' Dll2Lib.Vbs
'
' made by dobrawek for his usage
' but if you need it use it on GPL licence
'
' ChangeLog:
' 1.0 17/12/2009 dobrawek - created
'
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Consts defs for files usage
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TristateUseDefault = -2
Const TristateTrue = -1
Const TristateFalse = 0
Dim objArgs
Set objArgs = WScript.Arguments
Dim sIn, sOut
If (objArgs.Count = 1 ) Then
sIn = UCase(objArgs(0))
WshShell.Run MakeDumpBinBatch(sIn),0,true
sOut = Replace(sIn,".DLL",".DEF")
ConvertDumpFileToDef "FileDump.out",sOut
WshShell.Run MakeLinkBatch(sOut),0,true
Else
WScript.Echo "Wrong usage!"
End If
Const VC_ENVIRNOMENT = "call ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86"
Const TemporaryFolder = 2
Function MakeDumpBinBatch(sDll)
Set oOutFile = objFSO.CreateTextFile(objFSO.GetSpecialFolder(TemporaryFolder) & "\FileDump.bat", true)
oOutFile.WriteLine "@echo off"
oOutFile.WriteLine VC_ENVIRNOMENT
oOutFile.WriteLine "dumpbin.exe /EXPORTS " & sDll & " /OUT:FileDump.out"
oOutFile.Close
MakeDumpBinBatch = objFSO.GetSpecialFolder(TemporaryFolder) & "\FileDump.bat"
End Function
Function MakeLinkBatch(sDef)
Set oOutFile = objFSO.CreateTextFile(objFSO.GetSpecialFolder(TemporaryFolder) & "\LinkConv.bat", true)
oOutFile.WriteLine "@echo off"
oOutFile.WriteLine VC_ENVIRNOMENT
oOutFile.WriteLine "lib.exe /DEF:" & sDef & " /OUT:" & Replace(sDef,".DEF",".LIB")
oOutFile.Close
MakeLinkBatch = objFSO.GetSpecialFolder(TemporaryFolder) & "\LinkConv.bat"
End Function
Sub ConvertDumpFileToDef(sIn, sOut)
Dim oOutFile ' The object contains output file (.DEF)
Dim oInFile ' The object contains input file (.OUT - generated by dumpbin.exe)
WScript.Echo sIn
WScript.Echo sOut
Dim bHeader
bHeader = true
Set oOutFile = objFSO.CreateTextFile(sOut, true)
Set oInFile = objFSO.GetFile(sIn)
Set oStream = oInFile.OpenAsTextStream(ForReading, TristateUseDefault)
Dim pos
Dim exportArray
Do While Not oStream.AtEndOfStream
sRecord=oStream.ReadLine
if (bHeader = true) then
pos = InStr(sRecord, "Dump of file")
if ( pos <> 0) then
oOutFile.WriteLine "LIBRARY " & Mid(sRecord,pos+12) & Chr(13) & Chr(10) & "EXPORTS"
end if
pos = InStr(sRecord,"ordinal hint RVA name")
if ( pos <> 0) then
bHeader = false
end if
else
sRecord = Trim(sRecord)
do while InStr(sRecord," ") <> 0
sRecord = Replace(sRecord," "," ")
loop
exportArray = Split(sRecord," ")
if Ubound(exportArray) > 0 then
oOutFile.WriteLine exportArray(3) & " @" & exportArray(0) & " NONAME"
end if
pos = InStr(sRecord,"Summary")
if (pos <> 0) then
exit Do
end if
end if
Loop
oStream.Close
oOutFile.Close
End Sub