jp-slackspace / x-tension-c-sharp

An updated C# port of X-Ways X-Tensions API.
GNU General Public License v3.0
12 stars 1 forks source link

X-ways not unloading Dll #4

Open rcairnc opened 6 years ago

rcairnc commented 6 years ago

Hello,

According to the X-ways documentation the DLL should be unloaded when its finished, however DLLs compiled from this don't appear to. This prevents recompiling without the need to restart X-ways.

Also as a result when it is run again in x-ways without restarting, Private Static variables are still set from the first use. For example if a timecode is set in the first use, the timecode will be the same when next run.

To ensure that this is not due to any changes I have made I have tested the compiled DLL found in in this repository. This DLL cannot be deleted after first use as it is 'still in use', without closing x-ways first.

Thanks!

PS. thanks for resolving the other issue so quickly. This repository is incredibly useful.

jp-slackspace commented 6 years ago

No problem and thank you for submitting tickets. It’s a huge help. As for unloading, the way I understood the documentation is that X-Ways handle that. They expose a method that lets me do stuff before unloading. I assumed it was a bug in the software that was causing the unloading issue. I’ll see what I can figure out but it will take a little longer than my previous quick fix. Feel free to submit any other issues you see!

rcairnc commented 6 years ago

Hi, Thank you for the update. I have been trying to narrow down the cause of this issue so have stripped down the code to just a basic XWF_Init function (as this is the only mandatory function) which opnes a Windows message box. This will work within X-Ways as expected, however X-Ways still holds onto DLL once its finished. The only thing I can think of is that the "[DLLExport]" package is the cause of the problem. There is a newer version of this (https://github.com/3F/DllExport) however this has not fixed this issue. I have also tested this with X-ways versions back to 19.0 and the problem persists.

Thanks

jp-slackspace commented 6 years ago

Thanks for the update, you've been following a similar path to me, though I hadn't yet tried the new version of DLLExport. I've noticed that execution never gets to XT_Done or XT_Finalize, even if they are exported. I've got several more things I'm trying, then I'm going to post a message in the forum to seek help from the Stefan, given that the API says that X-Ways will unload the DLL when it's done, rather than leaving it up to the API developers.

jp-slackspace commented 6 years ago

Scratch the part about not executing XT_Finalize. It is doing that at least. I followed execution all the way through that and to where it return to X-Ways. For some reason, X-Ways is not unloading the DLL. I'll post a message and see what Stefan says.

EricZimmerman commented 6 years ago

Good luck!

jp-slackspace commented 6 years ago

I'm sure you've noticed if you follow the X-Ways support forums, but I've provided Stefan with a skeleton DLL to test with. Hopefully he will be able to figure out why the DLL isn't unloading after completion. And even more; hopefully it's not my fault. Don't laugh at me if it is. =)

EricZimmerman commented 6 years ago

so far so good as far as i can tell

rcairnc commented 6 years ago

Yes I have seen thank you, hopefully he can identify the problem! With regards to the debugging, I'm not sure it's possible to see the call by freelibrary as we don't have access the the debugging info for the xways executable. I think we would need this to see anything, I may of course be completely worng! Thanks again!

jp-slackspace commented 6 years ago

I was able to find the FreeLibrary call in IDA Pro by searching for XT_Done and seeing what came after that. Then I was able to attach the X-Ways process with x64dbg and break at that call. However, from there, it'll take me a while to figure out what is happening. I thought he might be able to know what's going on easier! This was a good excuse for me to attack this long-running issue, thanks again for reporting. Cheers.

jp-slackspace commented 6 years ago

Per Stefan after I sent DLL: "Thank you. I am able to reproduce the problem. It is very mysterious. At first FreeLibrary failed several times with the reason "Access is denied". Later it signaled success but still did not unload the DLL. I managed to get the DLL unloaded by (unnecessarily) first retrieving its handle (the same handle that I already had) with GetModuleHandleW and then calling FreeLibrary twice. Doesn't make sense but works here. You could give it a try in v19.6 SR-2." I'll keep this open till I verify it's fixed in the next release.

jp-slackspace commented 6 years ago

Tested with 19.6 SR-2. Still doesn't unload.

jp-slackspace commented 6 years ago

Can you test again on your end? Stefan says it should be fixed...

rcairnc commented 6 years ago

Hi, actually its now not possible to run any DLL created in C# as X-ways now hangs when run (it does the Init without issue, but everything else causes a Not Responding including the About.) . I have tried this using my own full x-tension, a stripped down version and the one created in this repo on Windows 7 and 10.

jp-slackspace commented 6 years ago

Sorry for the trouble. Not sure if X-Ways' developer is going to help much at this point. I'm scrapping DLLExport and attempting to write my own C++ wrapper to handle the exports. That way I can at least exclude 3rd party code that I don't maintain. On vacation, so working on it when I have a chance. Will hopefully have something to test with this evening.

rcairnc commented 6 years ago

Thanks for the update, I will keep and eye out for any future updates! Thanks again.

rcairnc commented 6 years ago

Hi JP, I was just wondering how you are getting on with this and weather or not you think its fixable? I don't like to chase you as you have helped so much already, but I may need to think about porting my extension to something else if this can't be resolved. Many thanks!

jp-slackspace commented 6 years ago

I do think it’s fixable, but I believe it depends on the developer. I’ve tried everything I can to get it working. I’m currently compiling all my attempts into a post I plan to make on the support forums, but my time has been limited. I completely understand you porting it. C++ with the native API would be my suggestion. It would however help if you would post a reply to my post on the support forum though, so he knows it’s affecting more than just me. Thank you for your patience and understanding. Feel free to email me at jp@slackspace.com so I can let you know if it’s ever resolved.