flat assembler
Message board for the users of flat assembler.

Index > Windows > [HELP] - Import and execute DLL function

Author
Thread Post new topic Reply to topic
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Hi folks!

I'm trying to import and execute some functions from a dll. This dll belongs to a program that does not run above win2k, but this dll is well documented.

These are the functions:
Code:
typedef void * tSr9000Hdl;
SR9000API tSr9000Hdl MSVC_STDCALL Sr9000HandleGet    ( void );
SR9000API void MSVC_STDCALL Sr9000HandleClose  ( const tSr9000Hdl hdl );
    


I wrote the following code to import and execute two functions, but can't make it work. Could someone please help me?
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [h_process],eax
        ;invoke  LoadLibrary,dll
        ;mov     [h_dll],eax
        ;invoke  GetProcAddress,[h_dll],func
        ;mov     [h_func],eax
        ;invoke  h_func
        invoke  Sr9000HandleGet
        invoke  Sr9000HandleClose,eax

  exit:
        invoke  ExitProcess,0

section '.data' data readable writeable

  dll db 'SR9000.DLL',0
  func  db 'Sr9000HandleGet',0

section '.bss' readable writeable

  h_process  dd ? ;handles to the executable process.
  ;h_dll      dd ?
  ;h_func     dd ?

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          sr9000,'SR9000.DLL'

  import sr9000,\
         Sr9000HandleGet,'Sr9000HandleGet',\
         Sr9000HandleClose,'Sr9000HandleClose'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'
         ;GetProcAddress,'GetProcAddress',\
         ;LoadLibrary,'LoadLibraryA',\


  ;import user,\
        ; MessageBoxA,'MessageBoxA'
    


Attached you can get the .h file of the dll and the dll itself.

Thanks,
ctl3d32


Description: Files that you will need
Download
Filename: files.rar
Filesize: 55.4 KB
Downloaded: 81 Time(s)

Post 30 Oct 2010, 01:42
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:54; edited 1 time in total
Post 30 Oct 2010, 04:45
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Hi!

Thanks, but LoadLibrary was still returning 00000000 instead of the handle of the .DLL (it fails).

GetLastError was returning:

ERROR_DLL_INIT_FAILED 1114 (0x45A)
A dynamic link library (DLL) initialization routine failed.

I tried LoadLibraryEx with flag DONT_RESOLVE_DLL_REFERENCES. It WORKED, but there might be an incompatibility with Win7 and XP because a call inside the DLL is failing.

Just fot the record, what i wanted was to control a pc card made by Matec Instruments (http://www.matec.com/mindt/products/pc_cards/sr-9000/).

I'm giving up. Theres nothing else i can do to make it work.

Thanks a lot,
ctl3d32
Post 30 Oct 2010, 10:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Make sure the DLL is in the same folder as the exe file. Either that or put the DLL in the system folder.

LoadLibrary has a set method it uses to find the DLL, make sure the DLL is in one of those places that LoadLibrary looks.
Post 30 Oct 2010, 11:57
View user's profile Send private message Visit poster's website Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
It's in the same folder as the .exe.

It's an old dll and an old program. Just for the record, it does not even run correctly under winXP. Sad

The university my brother works at bought this very expensive pc board, and they can't switch back to Win2k doe to compatibility issues with other software.

Thanks anyway,
ctl3d32
Post 30 Oct 2010, 12:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
I doubt anyone else can test this for you unless they also have the same card.
Post 30 Oct 2010, 12:59
View user's profile Send private message Visit poster's website Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
I tried rename of IOrange.dll it's return an error when i load library with sr9000.dll
this error <in messagebox>
This application has failed to start because IORange.dll was not found. Re-installing the application may fix this problem.

then i tried Loadlibrary with IOrange.dll i get an error
Code:
invoke  LoadLibrary,'IORANGE.DLL'
test  eax,eax
jnz   @f
  invoke MessageBox,0,'Error in LoadLibrary','Error',0
  jmp   exit
@@:
    

IORANGE.DLL is corrupted?
Post 30 Oct 2010, 17:37
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
ctl3d32,

IORANGE.DLL seems to depend on some driver ("\\.\IORangeDevice0" or "VIORange.VXD").
Post 30 Oct 2010, 18:29
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
but i use Dev-C++ and i write
Code:
#include "windows.h"
int APIENTRY WinMain(HINSTANCE  hInstance,
                     HINSTANCE  hPrevInstance,
                     LPSTR    lpCmdLine,
                     int nCmdShow)
{
   HWND hLib=LoadLibraryEx("SR9000.DLL",NULL,1);
   TCHAR add[50]="";
   if (!hLib)
   {
     MessageBox(0,"Load Error","LoadLibrary",0);
     return 0;
   }else{
     MessageBox(0,"Load OK","LoadLibrary",0);
     HWND hFunc=GetProcAddress(hLib,"Sr9000HandleGet");
     wsprintf(add,"Address= %d",&hFunc);
     MessageBox(0,add,"LoadLibrary",0);
    /* if (hFunc)
       MessageBox(0,"Get OK","LoadLibrary",0);*/
     return 0;
   }      
    return 0;
}
    

it's work fine.
can you use C or c++ for your work?


Last edited by pearlz on 30 Oct 2010, 18:57; edited 1 time in total
Post 30 Oct 2010, 18:48
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Thanks guys!

You all gave me an idea, and i think it worked. I copied the source code to the software's folder and it seemed to work ( when debugging it with olly). I will try more with it.

Thank you all very very much, this was letting me crazy.

I'm so stupid!!!!

Thumbs Up for all of you!

Cheers,
ctl3d32
Post 30 Oct 2010, 18:51
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
but hLib and hFunc have one value
it's equal.
Post 30 Oct 2010, 19:00
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
but wish you success.
Post 30 Oct 2010, 19:01
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
oh i'm sory
Code:
wsprintf(add,"Address= %d",&hFunc);
;change to
wsprintf(add,"Address= %d",hFunc);
    

but it work Very Happy
who stupid? Very Happy
Post 30 Oct 2010, 19:04
View user's profile Send private message Reply with quote
pearlz



Joined: 07 Jun 2010
Posts: 55
Location: Viet Nam
pearlz
Baldr my idol, he so intelligent.
Post 30 Oct 2010, 19:08
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Just for the record, it was missing "VIORange.VXD",since it was located at the installation folder. As soon as i copied my .ASM source to the installation folder, it worked flawlessly.

Thank you all!!!!!
Post 30 Oct 2010, 21:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.