<p>Yes, and i have a kernel32.def for my .d file and a kernel33.def for the original kernel dll. Your not confused, I am. I thought i needed kerel33.def so i could acces the dll from d, isnt this the case?</p>
<div class="gmail_quote">Op 1-mei-2011 22:10 schreef "Rainer Schuetze" <<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a>> het volgende:<br type="attribution">> I must have completely misunderstood what you want to do. What do you <br>
> want to build from kernel33.def? Isn't kernel33.dll the original DLL <br>> that you want to intercept by replacing it with the compiled DLL?<br>> <br>> maarten van damme wrote:<br>>> Great, now the error in kernel32.def is resolved but it gets the same <br>
>> problem in kernel33.def.<br>>> here is the start of the exports from kernel33.def:<br>>> EXPORTS<br>>> _hread @1334<br>>> how can I change this to resolve that?<br>>> <br>>> 2011/5/1 Rainer Schuetze <<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a> <mailto:<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a>>><br>
>> <br>>>     It seems you have hit another of those dreaded optlink bugs.<br>>> <br>>>     With less symbols, it works if you declare the imports like this<br>>>     (because of the described name mangling):<br>
>> <br>>>     IMPORTS<br>>>            _imported_hread@0 =  kernel33._hread<br>>> <br>>>     2 more notes:<br>>>     - you don't need to import kernel33.di<br>>>     - you should not use "SINGLE" in the DATA statement of the def file,<br>
>>     it will share the memory across processes.<br>>> <br>>> <br>>> <br>>>     maarten van damme wrote:<br>>> <br>>>         Number overflow?<br>>>         So I implemented the suggested changes (you can check them out<br>
>>         at <a href="http://dl.dropbox.com/u/15024434/version2.zip">http://dl.dropbox.com/u/15024434/version2.zip</a>)<br>>> <br>>>         But now I get when I compile it : "kernel32.def(738) : Error 12:<br>
>>         Number Overflow: (strange symbol over here)"<br>>> <br>>>         I do agree I should've picked a simpler example but I think the<br>>>         statisfaction will be even bigger if I were to succeed :p<br>
>> <br>>>         2011/5/1 maarten van damme <<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a><br>>>         <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>> <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a><br>
>>         <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>>>><br>>> <br>>> <br>>>            Wow, thanks for the help<br>>>            The first thing I did was in the .di file adding<br>
>>         extern(windows){ .... }<br>>>            and now compiling doesn't give errors and when examining with<br>>>         dllexp<br>>>            I can see that it exports the same functions as the real<br>
>>         kernel32.dll :D<br>>> <br>>>            Now I'm going to implement all other suggested changes,<br>>>         thanks a lot<br>>> <br>>> <br>>>            2011/4/30 Rainer Schuetze <<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a><br>
>>         <mailto:<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a>><br>>>            <mailto:<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a> <mailto:<a href="mailto:r.sagitario@gmx.de">r.sagitario@gmx.de</a>>>><br>
>> <br>>> <br>>>                I'm not sure your wrapping will work with kernel32.dll,<br>>>         but in<br>>>                general here are a few tips:<br>>> <br>>>                - most functions in the windows API use the __stdcall calling<br>
>>                convention in C/C++, which translates to D as<br>>>         "extern(Windows)"<br>>> <br>>>                - this will usually add the number of bytes passed on the<br>>>         stack<br>
>>                as a "@NN" postfix to the function name. This postfix<br>>>         does not<br>>>                exist in kernel32.dll, but in the import library kernel32.lib<br>>>                that you find in the dmd lib folder. Maybe you can use the<br>
>>                standard import library, or use the translation shown below..<br>>> <br>>>                - as the exported function and the function you want to<br>>>         chain to<br>>>                have identical names, you have to change at least one of<br>
>>         these<br>>>                and modify them in some build step. I'd suggest to do this in<br>>>                the def file:<br>>> <br>>>                The symbols in the d-source file containing:<br>
>> <br>>>                ----<br>>>                extern(Windows) HANDLE imported_GetCurrentProcess();<br>>> <br>>>                export extern(Windows) HANDLE internal_GetCurrentProcess()<br>
>>                {<br>>>                 return imported_GetCurrentProcess();<br>>>                }<br>>>                ----<br>>> <br>>>                can be mapped to other symbols in the def file:<br>
>> <br>>>                ----<br>>>                EXPORTS<br>>>                 GetCurrentProcess = internal_GetCurrentProcess<br>>> <br>>>                IMPORTS<br>>>                 imported_GetCurrentProcess = kernel33.GetCurrentProcess<br>
>>                ----<br>>> <br>>>                - if you don't know the number of arguments, you should<br>>>         not call<br>>>                the wrapped function, as this will change the callstack.<br>
>>                Instead, you should just jump to it:<br>>> <br>>>                void internal_hread()<br>>>                {<br>>>                 asm<br>>>                 {<br>>>                   naked;<br>
>>                   jmp imported_hread;<br>>>                 }<br>>>                }<br>>> <br>>>                I haven't tried all that, though, so there might be some<br>>>         mistakes...<br>
>> <br>>>                Rainer<br>>> <br>>> <br>>> <br>>>                Denis Koroskin wrote:<br>>> <br>>>                    On Sat, 30 Apr 2011 13:47:53 +0400, maarten van damme<br>
>>                    <<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a><br>>>         <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>> <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a><br>
>>         <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>>>><br>>> <br>>>                    wrote:<br>>> <br>>>                        I've changed this, I think I'm still kinda<br>
>>         confused with<br>>>                        lib files. They've<br>>>                        told me you can't do something with them without<br>>>         a .di file<br>>>                        So I went ahead and made a kernel33.di file.. I now<br>
>>                        import it in kernel32.d<br>>>                        and my declaration is<br>>>                        System(C){<br>>>                        export void * exportedfunctionblablabal(){<br>
>>                          return exportedfunctionblablablal();<br>>>                        }<br>>>                        ....<br>>>                        }<br>>> <br>>>                        The file in the directory are:<br>
>>                        kernel32.d :<br>>>         <a href="http://dl.dropbox.com/u/15024434/d/kernel32.d">http://dl.dropbox.com/u/15024434/d/kernel32.d</a><br>>>                        kernel33.di :<br>
>>         <a href="http://dl.dropbox.com/u/15024434/d/kernel33.di">http://dl.dropbox.com/u/15024434/d/kernel33.di</a><br>>>                        kernel33.lib :<br>>>                        <a href="http://dl.dropbox.com/u/15024434/d/kernel33.lib">http://dl.dropbox.com/u/15024434/d/kernel33.lib</a><br>
>>                        kernel33.dll :<br>>>                        <a href="http://dl.dropbox.com/u/15024434/d/kernel33.dll">http://dl.dropbox.com/u/15024434/d/kernel33.dll</a><br>>> <br>>>                        I've tried to compile using dmd -d kernel32.d<br>
>>                        kernel33.di kernel33.lib but<br>>>                        it throws errors like<br>>>                        "Error 42: Symbol undifined _Dkernel1336_hreadfzpV"<br>>>                        I have literally no clue why this is the case, can<br>
>>                        someone help me out or<br>>>                        look at the files?<br>>> <br>>>                        2011/4/27 maarten van damme<br>>>         <<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a> <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>><br>
>>                        <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a><br>>>         <mailto:<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>>>><br>
>> <br>>> <br>>>                            I'm afraid I've been a little unclear.<br>>>                            I've copied kernel32.dll from the windows dir,<br>>>                            renamed it to kernel33.dll<br>
>>                            and generated a .lib from it using implib.<br>>>                            Then I've created a d file with a correct<br>>>                            dllmain(stolen from examples) and<br>
>>                            between<br>>> <br>>>                            system(C){<br>>>                            export void * exportedfunctionfromkernel33.dll();<br>>>                            export void *<br>
>>         exportedfunction2fromkernel33.dll();<br>>>                            ....<br>>>                            }<br>>> <br>>>                            But it looks like you can't both declare a<br>
>>         function<br>>>                            from another lib and<br>>>                            export it at the same time.<br>>> <br>>> <br>>>                    In your kernel33.di, try making it extern (C) export<br>
>>         void*<br>>>                    _hread(); etc. You functions get D mangling otherwise.<br>>> <br>>>                    I'd also suggest you to start with a less complex<br>>>         example,<br>
>>                    e.g. export only one function, make sure it works,<br>>>         then add<br>>>                    the rest.<br>>> <br>>>                    If you think your .lib files doesn't do its job, try<br>
>>         using<br>>>                    .def file instead. I find them extremely helpful, and<br>>>         they<br>>>                    are a lot easier to edit/extend.<br>>> <br>>>                    Hope that helps.<br>
>> <br>>> <br>>> <br>>> <br></div>