I need to use a Dll supplied with TradeStation. The documetation
is poor for it. I know roughly what i am looking for but i dont
know the exact Function name and the variable types it expects.
I found some code a while back while surfing (pls claim it if its yours)
that will list all the exported functions. I have converted it
to drag and drop using the same code we used for the variable stuff
I want to see ALL the functions in the Dll (not just the exported ones
AND i would like to see the number and type of variables each function
expects.
I have read the WINAPI and Poffs on the subject (whats rebasing mean?)
but I dont see how to get this information.
I am a little out of my depth here tho so can you tell me
if this is even possible?
Heres the code ...
------------------
Kind Regards
Mike
is poor for it. I know roughly what i am looking for but i dont
know the exact Function name and the variable types it expects.
I found some code a while back while surfing (pls claim it if its yours)
that will list all the exported functions. I have converted it
to drag and drop using the same code we used for the variable stuff
I want to see ALL the functions in the Dll (not just the exported ones
AND i would like to see the number and type of variables each function
expects.
I have read the WINAPI and Poffs on the subject (whats rebasing mean?)
but I dont see how to get this information.
I am a little out of my depth here tho so can you tell me
if this is even possible?
Heres the code ...
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' ' Show a Dlls Contents - Converted by Mike Trader 2001 ' #COMPILE EXE "DllReadr.exe" #INCLUDE "WIN32API.INC" ' Basic Win API definitions 'xConfirm 4000 'xErrors 5000 TYPE DLLENTRY_IMAGE_DEBUG_INFORMATION ' Struct to retrieve the DLL information. nList AS LONG nSize AS LONG MappedBase AS LONG Machine AS LONG Characteristics AS LONG CheckSum AS LONG ImageBase AS LONG SizeOfImage AS LONG NumberOfSections AS LONG Sections AS LONG ExportedNamesSize AS DWORD ExportedNames AS DWORD NumberOfFunctionTableEntries AS LONG FunctionTableEntries AS LONG LowestFunctionStartingAddress AS LONG HighestFunctionEndingAddress AS LONG NumberOfFpoTableEntries AS LONG FpoTableEntries AS LONG SizeOfCoffSymbols AS LONG CoffSymbols AS LONG SizeOfCodeViewSymbols AS LONG CodeViewSymbols AS LONG ImageFilePath AS LONG ImageFileName AS LONG DebugFilePath AS LONG TimeDateStamp AS LONG RomImage AS LONG DebugDirectory AS LONG NumberOfDebugDirectories AS LONG OriginalFunctionTableBaseAddress AS LONG Reserved0 AS LONG Reserved1 AS LONG Reserved2 AS LONG END TYPE GLOBAL DllContents AS DLLENTRY_IMAGE_DEBUG_INFORMATION ' an instance of the TYPE Global hDlg as long, Done as long GLOBAL Wdth AS LONG, Hght AS LONG, BtnH AS LONG, FrmS AS LONG, FrmW AS LONG, TxtH AS LONG GLOBAL TempStr AS STRING, FileNameStr AS STRING, FilePathStr AS STRING, DestFile AS STRING GLOBAL Files() AS STRING, Folders() AS STRING DECLARE FUNCTION DLLENTRY_MapDebugInformation ( BYVAL FileHandle AS LONG, _ 'use Call Dword to call the procedures in Imagehlp.dll. FILENAME AS ASCIIZ, SymbolPath AS ASCIIZ, BYVAL ImageBase AS LONG ) AS DWORD DECLARE FUNCTION DLLENTRY_UnmapDebugInformation( BYVAL DebugInfo AS DWORD ) AS LONG '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' FUNCTION DLLENTRY_GetEntries(BYVAL sDllName AS STRING, sExpNames() AS STRING) AS LONG 'dll name(full path), returns a string array. LOCAL Result AS STRING LOCAL Found AS LONG, hFile AS LONG, hLib AS LONG, i AS LONG LOCAL pMDI AS DWORD, pUDI AS DWORD LOCAL pDBG AS DLLENTRY_IMAGE_DEBUG_INFORMATION PTR hLib = LoadLibrary( "Imagehlp.dll" ) 'Load the imagehlp dll. IF hLib = 0 THEN EXIT FUNCTION pMDI = GetProcAddress( hLib, "MapDebugInformation" ) 'Retrieve the procedures we need. IF CLNG( pMDI ) = 0 THEN GOTO DLLENTRY_GetEntries_Close pUDI = GetProcAddress( hLib, "UnmapDebugInformation" ) IF CLNG( pUDI ) = 0 THEN GOTO DLLENTRY_GetEntries_Close hFile = CreateFile( BYVAL STRPTR( sDLLName ), %GENERIC_READ, %FILE_SHARE_READ OR %FILE_SHARE_WRITE, _ 'Open the DLL as file. BYVAL 0&, %OPEN_EXISTING, %FILE_ATTRIBUTE_NORMAL, BYVAL 0& ) IF hFile = 0 OR hFile = %INVALID_HANDLE_VALUE THEN GOTO DLLENTRY_GetEntries_Close CALL DWORD pMDI _ 'Call the debuginfo and get the necessary struct. USING DLLENTRY_MapDebugInformation( hFile, BYVAL STRPTR( sDLLName ), BYVAL 0&, 0& ) TO pDBG IF pDBG = 0 THEN GOTO DLLENTRY_GetEntries_Close 'DllContents = ????? IF CLNG( @pDBG.ExportedNames ) THEN 'Retrieve the string data and copy this into a local string. Result = PEEK$( @pDBG.ExportedNames, @pDBG.ExportedNamesSize ) end if Found = PARSECOUNT( Result, CHR$(0) ) 'Count the amount of functions in the DLL. FUNCTION = Found 'Return Number Found. IF Found THEN 'Parse the names into the array provided. REDIM sExpNames( 1 TO Found ) FOR i = 1 TO Found sExpNames(i) = PARSE$( Result, CHR$(0), i ) NEXT i END IF DLLENTRY_GetEntries_Close: IF hLib AND pDBG THEN CALL DWORD pUDI USING DLLENTRY_UnmapDebugInformation( pDBG ) 'Destroy the debuginformation. IF hFile THEN CloseHandle hFile 'Close the filehandle. IF hLib THEN FreeLibrary hLib 'Unload library. END FUNCTION '************************************************************************ ' Pad a string to a fixed length '************************************************************************ FUNCTION Pad ( BYVAL PadStr AS STRING, length AS LONG ) AS STRING ' adjust to taste FUNCTION = LEFT$(PadStr + SPACE$(length), length) END FUNCTION '************************************************************************ ' Seperate FileName and FilePath, return Long Filename '************************************************************************ FUNCTION Seperate(pf AS STRING, p AS STRING, f AS STRING) AS LONG ' seperate LOCAL i AS LONG i = INSTR(-1, pf, ANY "\/") ' find last backslash p = LEFT$(pf, i) ' Path ShortName f = RIGHT$(pf, LEN(pf)-i) ' File ShortName f = DIR$(p+f) ' File LongName FUNCTION = i END FUNCTION '************************************************************************ ' GetDroppedFiles - FUNCTION Loads File/Folder names into the GLOBAL arrays '************************************************************************ FUNCTION GetDroppedFiles(BYVAL hDrop AS LONG, Fi() AS STRING, Fo() AS STRING) AS LONG 'returns %true, if any files where placed in Files LOCAL Cnt AS DWORD, i AS LONG, j AS LONG, k AS LONG, Pos AS LONG LOCAL fString AS ASCIIZ*%MAX_PATH Cnt = DRAGQUERYFILE(hDrop, &HFFFFFFFF&, "", BYVAL 0&) ' Get number of dropped files IF Cnt > 0 THEN ' Do we really need this check? REDIM Fi(Cnt) ' Make room in the GLOBAL array REDIM Fo(Cnt) ' Make room in the GLOBAL array FOR k = 1 TO Cnt fString = SPACE$(%MAX_PATH) 'clear zero terminators Pos = DRAGQUERYFILE(hDrop, k-1, fString, LEN(fString)-1) 'put FileName(i-1) into fString And Get Position TempStr = LEFT$(fString, Pos) IF GETATTR(TempStr) = 16 THEN ' check if it's a dir INCR i Fo(i) = TempStr ' directorys ELSE INCR j Fi(j) = TempStr ' Files END IF NEXT REDIM PRESERVE Fi(j) 'Make array the correct size REDIM PRESERVE Fo(i) 'Make array the correct size FUNCTION = %True END IF CALL DRAGFINISH(hDrop) END FUNCTION '************************************************************************ ' GetCommandFiles - FUNCTION Loads File/Folder names into the GLOBAL arrays '************************************************************************ FUNCTION GetCommandFiles(BYVAL CmdStr AS STRING, Fi() AS STRING, Fo() AS STRING) AS LONG 'Returns the number of files in the string LOCAL i AS LONG, j AS LONG, k AS LONG, Cnt AS LONG, pStr AS STRING IF INSTR(CmdStr, $DQ) THEN pStr = $DQ ELSE pStr = " " END IF Cnt = PARSECOUNT(CmdStr, pStr) FUNCTION = Cnt REDIM Fi(Cnt) 'Make room in the GLOBAL array REDIM Fo(Cnt) 'Make room in the GLOBAL array DO INCR k TempStr = TRIM$(PARSE$(CmdStr, pStr, k)) IF LEN(TempStr) = 0 THEN EXIT DO IF (GETATTR(TempStr) AND 16) THEN ' check if it's a dir INCR i Fo(i) = TempStr ' directorys ELSE INCR j Fi(j) = TempStr ' Files END IF LOOP REDIM PRESERVE Fi(j) 'Make array the correct size REDIM PRESERVE Fo(i) 'Make array the correct size END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' FUNCTION ReadDllMAIN ( ) AS LONG Local FileNum as long, i as long LOCAL ExpNames() AS STRING Dim ExpNames(1) ' Starting value Done = 0 FileNum = 0 DO WHILE FileNum < UBOUND(Files) AND Done = 0 INCR FileNum Seperate Files(FileNum), FilePathStr, FileNameStr ' Extract Path and Name CHDIR FilePathStr '=================================================== TempStr = RIGHT$(UCASE$(FileNameStr), 4) IF TempStr <> ".DLL" THEN MSGBOX "Source File MUST be a .Dll extension.",,"Error" EXIT FUNCTION END IF '=================================================== i = DLLENTRY_GetEntries( FilePathStr+FileNameStr, ExpNames() ) ' the Dlls Exported functions '=================================================== if i then CONTROL SET TEXT hDlg, 114, STR$(i)+" Functions Found" 'ARRAY SORT ExpNames() DestFile = PARSE$(FileNameStr, ANY ".", 1)+".log" OPEN FilePathStr+DestFile FOR OUTPUT AS 300 LEN = 32768' open output file Error Log PRINT# 300, PRINT# 300, DATE$+": "+STR$(Ubound(ExpNames))+" Functions Found in "+FileNameStr PRINT# 300, PRINT# 300, Pad("", 5) + pad(" Functions", 34) PRINT# 300, PRINT# 300, FOR i = 1 TO Ubound(ExpNames) PRINT# 300, Pad(Str$(i), 5) + Pad(ExpNames(i), 34) NEXT CLOSE #300 SLEEP 20 SHELLEXECUTE 0, "open", FilePathStr+DestFile, BYVAL 0, BYVAL 0, %SW_SHOWNORMAL ' launch log file ELSE CONTROL SET TEXT hDlg, 114, "Nothing Found" END IF '=================================================== WEND 'DIALOG END hDlg ' QUIT END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' CALLBACK FUNCTION MainCB() AS LONG SELECT CASE CBMSG CASE %WM_INITDIALOG DIM Files(1), Folders(1) ' Starting condition IF LEN(COMMAND$) THEN CALL GetCommandFiles(COMMAND$, Files(), Folders()) ' Retrieve the contents of the Command String REDIM PRESERVE Files(1) LOCAL sTimer AS LONG sTimer = SETTIMER(CBHNDL, 1, 400, %NULL) ' wait for window to draw END IF CONTROL SET TEXT hDlg, 114, "DRAG and DROP here" CASE %WM_TIMER KILLTIMER CBHNDL, 1 CALL ReadDllMain CASE %WM_DROPFILES REDIM Files(0) ' Reset Array CALL GetDroppedFiles(CBWPARAM, Files(), Folders()) ' Retrieve the Dropped filenames CALL ReadDllMain CASE %WM_DESTROY CALL DRAGACCEPTFILES(CBHNDL, 0) CASE %WM_COMMAND SELECT CASE CBCTL CASE 124 ' Quit Done = 1 ' jump out of any loops DIALOG END hDlg ' and QUIT END SELECT END SELECT END FUNCTION FUNCTION PBMAIN LOCAL rc AS RECT Wdth = 130 : Hght = 80 : FrmS = 4 : FrmW = Wdth-2*FrmS DIALOG NEW 0, " Read Dll contents", 0, 0, Wdth, Hght, %WS_SYSMENU OR %WS_CAPTION TO hDlg IF hDlg = 0 THEN EXIT FUNCTION DRAGACCEPTFILES hDlg, %True 'enable drag&drop CONTROL ADD LABEL, hDlg, 114, "", FrmS, Hght-31, FrmW, 12, %SS_CENTER OR %SS_SUNKEN CONTROL ADD BUTTON, hDlg, 124, "&Quit", FrmS, Hght-16, FrmW, 14, 1 SYSTEMPARAMETERSINFO %SPI_GETWORKAREA, BYVAL 0, VARPTR(rc), 0 'grab desktop cordinates DIALOG PIXELS hDlg, rc.nRight, rc.nBottom TO UNITS rc.nRight, rc.nBottom 'convert to dialog units DIALOG SET LOC hDlg, rc.nRight/2 - Wdth/2, rc.nTop + 20 'rc.nBottom - 100 'place dialog center top SETWINDOWPOS hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE 'set dialog topmost DIALOG SHOW MODAL hDlg CALL MainCB END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Kind Regards
Mike
Comment