Solved

DLL Questions Series, 3

Posted on 2000-02-16
12
267 Views
Last Modified: 2010-04-02
This is the second part of the series.
The Overview can be found at:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10294044  
The previous parts can be found at:
(1) http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10294050
(2) http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10295050

This question is not hard, but it can in my opinion grow into an interesting discussion.

"Polite" programmists will provide an .H file for there DLL, and also a .LIB file. But if one doesn't, and only ships out a .DLL file,

1) How does the potential user of a DLL know what exports can he use from this DLL?
2) How can he create a LIB from this DLL? (This was already discussed in Part 2 of the series, but since "nietod" couldn't name any specific utilities, I repeat the question here).
3) What other things must a DLL creator do in order to qualify for being "polite"?
0
Comment
Question by:Lescha
  • 6
  • 5
12 Comments
 
LVL 1

Author Comment

by:Lescha
Comment Utility
Oops, sorry... Naturally, it's the _third_ part of the series ;)
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Hi Lescha:

1) You can use QuickView (right-click on the DLL and select Quick View) for a list of exported function names if you do not have the .H file, otherwise the .H file descrive all you need to know.

2) If by .LIB you mean a compiled library, I am not sure if you can do this. If you mean a .DEF file containing the list of exports you can create this from the QuickView report.

3) A 'polite' DLL creator really just needs to ensure that a user of the DLL can acess the functions within it. To that end a .H file is really all that is required, though providing a .DEF/.LIB(?) file is a courtesy that allows easy setup of early bound DLLs.

Unfortunately, in the abscence of a .H file, a DLL is essentially useless if you cannot determine the arguments (from the author) for each function it contains. It is essentially not possible to determine the arguments from the DLL directly.

Cheers,
Raymond.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
I answered several questions about this issue.  URLs below, cut-n-paste in a forthcoming comments.

  http://www.experts-exchange.com/bin/Q.10032070
  http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=10119315
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
** Q.10032070 "View DLL's" (5 pts) **

> where I can obtain a free View DLL's (see for each *.DLL the functions with sintax, parameters, etc) ?

** Accepted Answer **

(Assuming a Win32 platform and C language)

You can get the list of names that a DLL exports but function parameters are a different thing.

The easiest way of getting the list of exported names is to QuickView the DLL.  QuickView comes with every Win32 platform so no need to look elswhere.

Look for the section "Export table" for the exported names.

Now, some issues:

1) How to determine if the name refers to a function or a variable?

Each entry in the export table has an address.  Look for the "Sections" part to see which section the address resides in.  The section's characteristics state if it contains executable code.

2) Why there are some entries without names?

A DLL can export functions by name or by ordinal number (or both).  Functions exported by ordinal number only need an import library or a DEF file to be called by name (you cannot infer the name from the DLL).

3) What about parameters?

Due to the way parameters are passed, you cannot infer the parameters from the DLL (unless it's C++).

However, sometimes you'll see entries like _FunctionName@8

That means that the function FunctionName() takes 8 bytes of paramteres.  There is no way (aside from disassembly) to know if it is two 4-byte longs, four 2-byte shorts, eight chars or any combination thereof (and I'm not even talking about pointers, floating point types or structs).

More than that, depending on the calling convention, the parameters may be pushed on the stack in a left-to-rigt order, right-to-left order or passed in registers.

If it's C++ code, the function name is mangled (compiler specific) and contains the number and types of the parameters in the name.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
** Q.10119315 "Getting Parameters to DLL functions" (10 pts) **

If I have a dll, with exported functions, but no .lib or .h file. Is it possible to work out what parameters thoses functions take, and therefore do a GetProcAddress.. and call them ?

any clues anyone ?

** Combined Answers **

The general answer is no.
If the DLL functions use the __stdcall convention, you can see how many BYTES the function expects to be pushed on the stack from it's name (the format is funcname@num).  Most arguments will be 32bit integers or pointers so you can guess the number of arguments as num/4.

Also, Borland C++ comes with an IMPLIB program that is supposed to generate import libraries from DLL files.

A brief search showed that it is downloadable from:
     ftp.cs.uregina.ca/pub/class/250/class/MASM Disks
(As part of the MASM package).
0
 
LVL 1

Author Comment

by:Lescha
Comment Utility
"rwilson": by .lib I mean a static library containing stubs of functions within the .dll. See discussion of this point in Part 2 of the Series.

---

For all:

I will increase the points for this question to 100 that will go to the Expert naming one of those utilities that "nietod" mentioned in Part 2: the one to create a .lib from .dll.

This question remains open, but I will post Part 4 shortly.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:Lescha
Comment Utility
Adjusted points to 100
0
 
LVL 1

Author Comment

by:Lescha
Comment Utility
Oh, and for "alexo": this IMPLIB you mentioned for Borland C++, does it work also on .dll that is generated with Visual Studio?

If no, it's not quite relevant.
If yes, please lock the answer.
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
It works with MS DLLs also.
Unfortunately the file is no longer there.  I'll search for a replacement...
0
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
Comment Utility
OK, Borland (Inprise) is giving away their C++ compiler.  AFAIK, implib is part of the package.  Even if not, sounds like a good deal to me.

  http://www.borland.com/bcppbuilder/freecompiler/
0
 
LVL 1

Author Comment

by:Lescha
Comment Utility
Thanks to all the Experts who participated in answering:

"nietod", "alexo".

Next part will be posted shortly.
0
 
LVL 1

Author Comment

by:Lescha
Comment Utility
I forgot to mention the Expert named "rwilson". Sorry about that.

Closing question does not necessarily ends the discussion, so if anyone has anything to add - about politeness or other things - feel free to do that.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now