Results 1 to 7 of 7

Thread: A (quite) simple ASM compiling question!

  1. #1

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    Wink A (quite) simple ASM compiling question!

    Hiya peeps...
    Still working on a prog with kedaman (see our Icon question in the General Forums)...

    We're currently working on the plugin-mechanism. We'll call Unmanaged (yes that's a .NET term, the core is written in C#) Dll.

    The thing is, we're loading the DLL at runtime, and we ran into some problems calling the function... I looked up some stuff on the internet, and came accros this article that describes exactely our problem ( http://www.codeproject.com/csharp/dyninvok.asp )

    As you can see, it uses some assembly code to fix the problem of the dynamicly calling of the function... yes, the guy included the source code, but didn't shipped a compiled version of the DLL, only the ASM code and a makefile (+ some test C# code which is inrelevant to the question)...

    When I try to compile the code using Visual Studio.NET, I get some compiling errors (something about a namespace and stuff)...

    Now could someone please tell me what the problem is with the code, or compile it for me and send the compiled version?

    Here's the ASM code I try to compile:
    VB Code:
    1. ; -------------------------------------------------------------
    2. ;
    3. ; InvokeFuncAsm - Invokes a function through a function pointer passed as
    4. ; the first argument. All other parameters are forwarded on, plus the return
    5. ; value of the function invoked is returned.
    6. ;
    7. ; Copyright (c) Richard Birkby, ThunderMain ltd, November 2001
    8. ;
    9. ; -------------------------------------------------------------
    10.  
    11. .386
    12. .model flat
    13.  
    14. option prologue:none
    15. option epilogue:none
    16. option dotname
    17.  
    18.  
    19. .code
    20. align DWORD
    21. DllMain     proc    stdcall public, instance:DWORD, reason:DWORD, reserved:DWORD
    22.         mov     eax, 1  ; success
    23.         ret 12
    24. DllMain     endp
    25.  
    26.  
    27. align DWORD
    28. InvokeFunc  proc    stdcall public, funcptr:DWORD
    29.  
    30.     pop ecx ; save return address
    31.     pop edx ; Get function pointer
    32.     push    ecx ; Restore return address
    33.     jmp edx ; Transfer control to the function pointer
    34. InvokeFunc  endp
    35.  
    36. end

    Thanks for your Help!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  2. #2
    Zaei
    Guest
    YOu can do this in MSVC^, so it should work in MSVC.NET:
    Code:
    __declspec(naked) InvokeProc(void* func) {
        __asm {
            pop	ecx	
            pop	edx	
            push	 ecx	
            jmp	edx
        }
    }
    That should do it. The __declspec(naked) attribute removes the prolog and epilog code from the function, leaving only the asm block, which is what your pure asm function does anyway.

    Z.

  3. #3

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Wow thanks alot for the quick reply, I'll try it soon..
    thanks alot man!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I managed to compile the DLL from pure ASM, someone at another forum pointed out how to use the NMAKE command from the Visual Studio Command Prompt... so there's a sweet 2,5 KB dll now

    But thanks alot for your reply!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Zaei
    Guest
    Try mine anyway... I want to know if it would work =).

    Z.

  6. #6

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Well I did, but when I tried to use it in C# it said something about that it couldn't find the entry point for that function (eventhough I made a .def file with the appropriate stuff in it)

    Thanks for the suggestion though!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    Zaei
    Guest
    Oh well =).

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width