Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2006, 00:08
nino nino is offline
Friend
 
Join Date: Jan 2002
Posts: 58
Rept. Given: 0
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
nino Reputation: 2
Static import by ordinal

Is there any way to import a function in a C program that is only exported by ordinal from a DLL (besides dynamically using LoadLibrary/GetProcAddress)?
For example the IsOS function is documented by MS (recently) and is exported by shlwapi.dll as ordinal 437, how can it be statically linked in a C program?
Reply With Quote
  #2  
Old 09-27-2006, 00:45
MarkusO
 
Posts: n/a
Simply use a *.DEF file and pass "import by ordinals" to your linker.
Reply With Quote
  #3  
Old 10-02-2006, 07:40
nino nino is offline
Friend
 
Join Date: Jan 2002
Posts: 58
Rept. Given: 0
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
nino Reputation: 2
Your answer was a bit cryptic but it put me on the way to the solution.
For other readers of this post I would recommend the following article on Microsoft's Knowledge Base: "How To Create 32-bit Import Libraries Without .OBJs or Source". As the title suggests the modifications are NOT to your application but are related to the DLL instead. Also the "import by ordinal" linker option is only relevant to Borland C/C++ products. Hope this helps...
Reply With Quote
  #4  
Old 10-02-2006, 19:14
MarkusO
 
Posts: n/a
The way Microsoft describes the problem is quite complex and I don't see how to use the document to import by ordinals (since "IsOS" is not exported by name, only by ordinal). I only know a far more simple way.

Create a *.DEF file with the following content:
Code:
IMPORTS
  IsOS = SHLWAPI.437
Declare the "IsOS" function as external. Then pass the *.DEF file to your linker and use the "import by ordinal" option (every linker has it, not only the Borland linker). The problem is that the Microsoft linker says that "IMPORTS" is not supported on Win32, which makes it quite useless here (but it works with Win16 ordinals).

This will then import all functions by name, expect the one you called "IsOS", which is imported by ordinal. If you don't use the "import by ordinal" switch, your program will try to load "IsOS" from SHLWAPI.DLL and (of course) fail.

If you have to use the Microsoft linker for some reason, you should simply create yourself a program which parses your import table and replaces a given imported name with it's ordinal. Of course this will require manual input if the function isn't exported by name at all.
Reply With Quote
  #5  
Old 10-03-2006, 03:37
nino nino is offline
Friend
 
Join Date: Jan 2002
Posts: 58
Rept. Given: 0
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
nino Reputation: 2
The IMPORT section is no longer valid in a .DEF file. So there is no way you could tell your C program how to import. Other compilers - including managed code in Visual C++ - do have the option to specify import attributes such as the ordinal for the import.
The article explains two alternatives: one with import by ordinals only for C functions and the other for general functions (but does not use import by ordinal). However, just combine the two solutions and you can get what you want. That is, create stubs for the functions you want to import and also create a DEF file with EXPORTS to specify the ordinal, then generate the dummy DLL and you get a LIB that allows you to import the desired function by ordinal. I did it and it worked.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CrackMes.de Static Mirror SmilingWolf General Discussion 4 01-16-2019 19:07
How create Static Library (lib) in delphi? Newbie_Cracker General Discussion 7 10-26-2011 22:33
Import Rebuilding Without Import Table Kerlingen General Discussion 11 01-13-2005 10:24


All times are GMT +8. The time now is 17:20.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2022 )