June 24, 2024, 01:46:57 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dll2lib

Started by sapero, January 10, 2007, 05:27:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

sapero 
What I use your program to convert the 1st dll to a static lib.
I use that in a 2nd src file and create a static lib of the 2nd file

Will the 2nd static lib be a standalone lib that I can distribute to users without any other files?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

If the second lib has references to the first, someone will get unresolved externals. Try to rename the first one, then compile using the second lib, to check this.
If you checked the "compression" option, you need also to share zlib.lib.
Optionally you can merge two, or more libraries to one library, using the commandline ar.exe or link.exe tool, depending on library format.

ts-soft

Dll2Lib doesn't work with unicode dlls in EmergencyBasic.

I think, you have to change in  MemoryGetProcAddress the second parameter, this should allways the functionname in ascii.
WinAPI GetProcAddress doesn't support Unicode, but I am not sure whether this is the mistake

greetings

Thomas
Sorry for my bad english

sapero

I can't help without additional informations - which dll? Any code?
This tool has nothing to do with the code inside target dll, it reads only the exported names (always ascii) and creates import library wrapper that calls directry to memory, the dll code is untouched, but the IMAGE_DOS_HEADER is modified - one DWORD is used to store a pointer to internal structure.

ts-soft

Sorry sapero, my mistake, i have defined UNICODE on the wrong place  :-[

It works as aspected
Sorry for my bad english

LarryMc

Sapero
I tried to use your converter on the attached dll.
Everything convertered and when I compiled and linked it into my application it did that fine.

However, when I ran my application it crashed with the "tell MS all about it" message box.

Any ideas.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

TazMan47

Hey Larry, great tool. Thanks for sharing.   ;D

TazMan47

Reference the post above. I am very sorry for changing your name to Larry. I was chatting with a friend at the time and switched your name with his. Again, I am very sorry and I hope you will forgive me.   Ken.  ;D

sapero

August 29, 2008, 08:51:12 AM #33 Last Edit: August 29, 2008, 08:58:15 AM by sapero
Larry, Olly shows that this dll calls (and relies on) GetModuleFileName, searches for last '.' (_mbsrchr) and writes a NULL to that address.
GetModuleFileName fails with memory only modules, _mbsrchr returns NULL, and the code writes NULL byte to NULL pointer.
DllMain(hinstance)
{
GetModuleFileName(hinstance, bufer, ...); // set bufer to path\image323.dll
char *p = _mbsrchr(bufer, '.'); // find last '.'
*p = 0; // remove extension

You may hook the GetModuleFileName api before calling __Loadimage323_dll.

sapero

Here is working exception handler: it copies dll name to the buffer provided for GetModuleFileName and resumes execution
#use "image323_m.lib"
#use "zlib.lib"
extern int __Loadimage323_dll();
extern void __Unloadimage323_dll();
#include "windows.inc"

declare import, About();

sub main(),int
{
LPTOP_LEVEL_EXCEPTION_FILTER OldFilter = SetUnhandledExceptionFilter(&Loadimage323Filter);
// load the dll from memory
__Loadimage323_dll();
SetUnhandledExceptionFilter(OldFilter);

// call some functions here
About();

// finally free the dll from memory
__Unloadimage323_dll();
return 0;
}


sub Loadimage323Filter(EXCEPTION_POINTERS* ExceptionInfo),LONG
{
EXCEPTION_RECORD *rec = ExceptionInfo->ExceptionRecord;
CONTEXT *ctx = ExceptionInfo->ContextRecord;

/*
73DC9CB2     MOV     EBX,104
73DC9CB7     PUSH    EBX
73DC9CB8     LEA     EAX,[EBP+84]
73DC9CBE     PUSH    EAX
73DC9CBF     PUSH    [DWORD ESI+6C]
73DC9CC2     CALL    [<&KERNEL32.GetModuleFileNameA>]
73DC9CC8     LEA     EAX,[EBP+84]     <- resume here
73DC9CCE     PUSH    2E
73DC9CD0     PUSH    EAX
73DC9CD1     CALL    [<&msvcrt._mbsrchr>]
73DC9CD7     POP     ECX
73DC9CD8     POP     ECX
73DC9CD9     MOV     [EBP-80],EAX
73DC9CDC     MOV     [BYTE EAX],0 <- exception
*/
// copy image323.dll to [EBP+0x84]
string *pModuleName = ctx->Ebp + 0x84;
*pModuleName = "image323.dll";

// resume execution after GetModuleFileNameA
const RESUMEOFFSET = 0x73DC9CDC - 0x73DC9CC8;
ctx->Eip = rec->ExceptionAddress - RESUMEOFFSET;

// continue execution
return EXCEPTION_CONTINUE_EXECUTION;
}

LarryMc

Sapero
Although this is the Aurora forum I'm trying to use this in EB.  Will the above code convert over to EB?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Sure.$use "d:\\aurora\\libs\\image323_m.lib" /* change this*/

$use "zlib.lib"
declare extern __Loadimage323_dll(),int
declare extern __Unloadimage323_dll()
$include "windows.inc"

declare import, About()

main()

sub main()

LPTOP_LEVEL_EXCEPTION_FILTER OldFilter

OldFilter= SetUnhandledExceptionFilter(&Loadimage323Filter)

' load the dll from memory
__Loadimage323_dll()
SetUnhandledExceptionFilter(OldFilter)

' call some functions here
About()

' finally free the dll from memory
__Unloadimage323_dll()
return
endsub


sub Loadimage323Filter(EXCEPTION_POINTERS ExceptionInfo),LONG

pointer rec, ctx, pModuleName

rec = ExceptionInfo.ExceptionRecord
ctx = ExceptionInfo.ContextRecord
settype rec, EXCEPTION_RECORD
settype ctx, CONTEXT

' copy "image323.dll" to [EBP+0x84]
pModuleName = *ctx.Ebp + 0x84
*<STRING>pModuleName = "image323.dll"

' resume execution after GetModuleFileNameA
const RESUMEOFFSET = 0x73DC9CDC - 0x73DC9CC8
*ctx.Eip = *rec.ExceptionAddress - RESUMEOFFSET

' continue execution
return EXCEPTION_CONTINUE_EXECUTION
endsub

LarryMc

Thanks again, Sapero

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library