3

I'm going to implement an SPI for my own hardware (maybe virtual). As I found (maybe I mistake) when an application calls WFSOpen, XFS calls WFPOpen in SPI. But this "in SPI" means where? Maybe I should give the address of the dll file in which WFPOpen is found somewhere in registry. I also think that the dll path should be given in HKLM\XFS\Service_Provider\\DllName. Is it so and is it enough? Is XFS sensitive to this registry path and key and uses it to find where is the SPI? I've done above, but I get WFS_ERR_SERVICE_NOT_FOUND. It seems that XFS doesn't look for the function in the dll. What can be wrong?

I thought it would be better to send xfs log for you to be able to process better the problem. https://www.dropbox.com/s/6wwbjfpxxibjnl1/9603071652%20-%20XFSTrace.7z?dl=0

hamidi
  • 1,611
  • 1
  • 15
  • 28
  • Did you export WFSOpen from your SPI dll module? Your SPI must export full set of XFS functions as declared in documentation. And then XFS manager can load your dll from path that you defined at the registry and call GetProcAddress for every function. – Alex.D.Alexeev May 15 '17 at 06:42
  • You really mean WFSOpen and not WFPOpen? I thought I should only put implementation of WFPOpen and other WFP functions in my SPI DLL. now you say that I should implement body of WFSOpen too?! – hamidi May 15 '17 at 13:17
  • Of course, you are right, I mean WFP functions – Alex.D.Alexeev May 15 '17 at 13:30
  • ok, so i did. i put spi dll there, but something seems to be wrong that causes me to get the error. what documents may i refer? what's wrong you think? – hamidi May 16 '17 at 07:52
  • There are many reasons to get such error. Maybe something wrong with dll exports, dependencies, SPI registration in registry an so on. Can you access XFS logs? There may be more details about reasons of your error. And [XFS documentation](https://www.cen.eu/work/areas/ICT/eBusiness/Pages/CWA16374.aspx) is only one good source of information about how to deal with XFS. – Alex.D.Alexeev May 16 '17 at 12:20
  • thank you for the reference. this is not my first time i export a function from a dll. it's in C++. i used .def file to export. i also tried __declspec(dllexport). i also tried with and without WINAPI. i also tried extern"C". but i don't know what may be wrong. for registry, i tried to put the dll path in HKLM\XFS\SERVICE_PROVIDER\device name. what's wrong? – hamidi May 17 '17 at 11:50
  • Please attach your registry configuration for this SPI and corresponding logical service, registry configuration for your xfs manager and dumpbin.exe /exports /dependents for your dll – Alex.D.Alexeev May 18 '17 at 13:47
  • sure, will do it tomorrow. thx – hamidi May 20 '17 at 12:22
  • i did. i didn't know where is better for upload. so i uploaded the file in my space in persiangig: http://hamidi2.persiangig.com/xfs.7z – hamidi May 21 '17 at 07:38
  • also note that when i use CDM300.exe from WincorTest, i don't see service name in the list. it seems that the service is not introduces properly for xfs. – hamidi May 21 '17 at 15:16
  • Hi, I think that you didn't added LOGICAL_SERVICE which using your SPI. In CDM300 utility you can see only logical services, not SPI directly – Alex.D.Alexeev May 25 '17 at 09:29
  • where in registry you mean? – hamidi May 28 '17 at 06:55
  • I put LOGICAL_SERVICE in HKU/.DEFAULT/XFS. Then I found XFSTrace.LOG in c:\Windows\SysWOW64. Then updated the question to include the log. I think now you may figure out what is the problem and where i went wrong. – hamidi May 28 '17 at 12:28
  • is there any where that i can download the source of the xfs dlls so that i may debug and see what reg key couldn't open etc.? – hamidi May 28 '17 at 12:52
  • Hmm. Did you try to add XFS key under HKLM\Software\WOW6432Node? And I don't know where to get sources of XFS manager. It's proprietary Microsoft library. – Alex.D.Alexeev May 29 '17 at 17:23
  • At last I could make XFS call WFPOpen. For this, I had to use HKCU/XFS/LOGICAL_SERVICES. I remember that in the previous day I could make XFS call WFPOpen without having to add any key to HKCU! It seems that XFS behavior changed! I also had to add HKU/.DEFAULT/XFS/SERVICE_PROVIDERS. XFS was previously looking for SERVICE_PROVIDERS in HKLM! I don't know what happened! It seems that I have not to add HKLM\Software\WOW6432Node, unless you say that it's required for something. Unfortunately, the XFS documents does not include sufficient explanation. I'm going on... Now WincorTest hangs when opens. – hamidi May 30 '17 at 09:38
  • About HKLM\SOFTWARE\WOW6432Node\XFS. If you are running at 64bit windows all 32 bit application working with Software key under this node. rededit.exe is 64 bit and can "see" all keys. XFS manager is 32 bit and see olny software key under WOW6432Node. That's a reason of using this key. WincorTest utilities can hung if more than on instance of cdm300.exe is running. At all: my working sample is running with LOGICAL_SERVICES under HKU\.DEFAULT\XFS\LOGICAL_SERVICES, SERVICE_PROVIDER under HKLM\SOFTWARE\WOW6432Node\XFS\SERVICE_PROVIDERS. Try this please. – Alex.D.Alexeev May 31 '17 at 17:21
  • Ok, thanks for your guide. I've lost connection to my system. I'll continue testing as soon as I can and will let you know what will happen. – hamidi Jun 04 '17 at 06:28
  • I thought more about your last comment. I see that the application can see keys in the paths i said, even though it's 32 bit. I don't know why, but this happens. Anyway, it's not the problem. The problem is that why WincorTest hangs. I don't run more than one instance of CDM300.exe. Now that changes in keys i sent is affected in CDM300 behavior, it's not seemed to be the problem of mislocating keys in registry. – hamidi Jun 06 '17 at 07:59
  • i put the latest xfslog here: https://www.dropbox.com/s/k78c5h9kxcf5phm/9603231315%20-%20XFSTrace.7z?dl=0 what you see to be wrong in it? hang still happens. now i've implemented WFPOpen and WFPRegister functions. – hamidi Jun 13 '17 at 08:46
  • I see only one line with unknown problem (Date)13.06.2017 (Time)12:29.04,262 Exception occurred And I don't know what does it mean. Did You try to attach cdm300.exe process and put a breakpoint on WFPOpen in your code? Maybe You can see something – Alex.D.Alexeev Jun 15 '17 at 14:50
  • good idea. i didn't. but i used log inside WFPOpen instead. everything seems ok. it seems that XFS remains in wait of something after it calls WFPOpen. maybe it should do something? – hamidi Jun 16 '17 at 11:36
  • Can You show me the code of Tour WFPOpen function? – Alex.D.Alexeev Jun 16 '17 at 12:47
  • sure, here: http://paste.debian.net/971964/ – hamidi Jun 18 '17 at 10:06
  • by the method you suggested for debugging CDM300, i found that it's waiting in NtWaitForSingleObject. for what? i couldn't figure out. – hamidi Jun 18 '17 at 12:03
  • instead of CDM300, i wrote a simple program to call WFSOpen using XFS. i get WFS_ERR_INTERNAL_ERROR while i return 0 from WFPOpen. i used calloc instead of WFMAllocateBuffer because it caused exception about not being able to remove all allocated buffers. now there's no exception, but still i get -15. – hamidi Jun 18 '17 at 14:30
  • Hi, your code looks good. Some moments: you must do not modify any parameters of WFPOpen. You must use WFMAllocateBuffer for any memory allocation to transfer between SPI and manager. Did you try SendMessage instead of PostMessage? Why you doing PostMessage in a loop? Is there any errors on PostMessage? – Alex.D.Alexeev Jun 19 '17 at 08:10
  • indeed i wonder why PostMessage should be called in a loop. maybe sometimes it will fail?! i inspired it from WOSAXFSTest. i think it should not be required and i don't get any error. then when the block allocated by WFMAllocateBuffer should be freed and by who? i thought i should return version and they're output parameters. i'm going to try SendMessage, but in WOSAXFSTest PostMessage is used and it seems to be ok. – hamidi Jun 20 '17 at 07:58
  • by replacing SendMessage my test also stalls in WFSOpen. CDM300 still hangs. – hamidi Jun 20 '17 at 08:03
  • Client application must call WFSFreeResult that will free memory allocated by WFMAllocateBuffer. SPI does not need to free any allocated result structure returned by SendMessage. And another idea. You wrote that WFMAllocateBuffer caused an exception? Maybe something wrong with shared memory file? – Alex.D.Alexeev Jun 20 '17 at 12:05
  • i saw that when i used WFMAllocateBuffer i got exception, while when i didn't i didn't. let me change it back from calloc to WFMAllocateBuffer and see what will happen. – hamidi Jun 20 '17 at 13:11
  • i simplified code to http://paste.debian.net/972385/. i get -15. the exception is: Unhandled exception at 0x00416219 (xfs_supp.dll) in EDMInit.exe: 0xC0000005: Access violation reading location 0x6bc09fd8. this happens at the end of EDMInit test application, somewhere in assemblies. i didn't free the allocated block by WFSFreeResult. at most it should cause memory leak. – hamidi Jun 20 '17 at 13:21
  • i had to change WINAPI to __cdecl. otherwise WFPOpen could not be called. so MODIFIER is defined to __declspec(dllexport). – hamidi Jun 20 '17 at 13:23
  • Did WFMAllocateBuffer return WFS_SUCCESS? It's looks like a bad allocation occured – Alex.D.Alexeev Jun 20 '17 at 16:34
  • i will check it sunday. thx – hamidi Jun 21 '17 at 10:13
  • sorry for late. it was holiday here and i had some other works to do. now i checked the return value of WFMAllocateBuffer. it's 0. it seems that it can allocate with no problem. and why not? – hamidi Jul 02 '17 at 02:25
  • Sorry, but I have no idea what is wrong. Maybe you can put your compiled dll somewhere and I can try to use it to look closer? – Alex.D.Alexeev Jul 06 '17 at 19:37
  • sure, i will do it tomorrow. now i've no access to it. if you prefer, i may put the source too. – hamidi Jul 08 '17 at 05:04
  • https://www.dropbox.com/s/imxypqx1ukprcqh/960420%20-%20xfs.zip?dl=0 – hamidi Jul 11 '17 at 04:53
  • I've got it! Just some small steps to get it work. 1) You do not need to change any XFS SDK header files. 2) Remove any extern "C" in your dllmain.cpp 3) In dllmain.cpp replace any word "MODIFIER" with WINAPI just like this "HRESULT WINAPI WFPxxxx" 4) And set option "Module definition file" to your cdm_spi3.def in project linker options. This steps allowed me to call WFSOpen with hr = WFS_SUCCEESS – Alex.D.Alexeev Jul 11 '17 at 19:28
  • And one more step. Your need HKLM\SOFTWARE\WOW6432Node\XFS for service provider and HKU\.DEFAULT\XFS\LOGICAL_SERVICES for logical service Registration must be like this: [HKEY_USERS\.DEFAULT\XFS] [HKEY_USERS\.DEFAULT\XFS\LOGICAL_SERVICES] [HKEY_USERS\.DEFAULT\XFS\LOGICAL_SERVICES\CashDispenser] "class"="CDM" "provider"="cdm_spi3" **[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node**\XFS\SERVICE_PROVIDERS] [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\XFS\SERVICE_PROVIDERS\cdm_spi3] "class"="CDM" "version"="3.00" "vendor name"="ModernISC" "DllName"="<>\\cdm_spi3.dll" – Alex.D.Alexeev Jul 11 '17 at 19:30
  • really thanks :) i'll go on and will let u know if any further problems occur. – hamidi Jul 16 '17 at 04:54

1 Answers1

1

When you execute WFSOpen from an application, you set the Logical Service Name you want to open. The XFS Manager will try to find this name in the windows registry, in:

HKEY_USERS/.DEFAULT(OR USER WHO START SESION)/XFS/LOGICAL_SERVICES/.

For each logical service name, there is a registry entry with "provider" variable.

With the value of this "provider" variable, the XFS MANAGER goes to:

HKEY_LOCAL_MACHINE/SOFTWARE/XFS/value_for_this_provider/.

In this folder, the variable "dllname" contails the dll to load for this SPI.

Good luck!

SuperG280
  • 271
  • 3
  • 9