flat assembler
Message board for the users of flat assembler.
Index
> Windows > Windows and USB HID |
| Author |
|
|
macomics 05 Jul 2022, 14:12
Functions are exported from hid.dll . You can make yourself a static import file of these functions. hid.lib are recommendations for MASM
|
|||
|
|
I 06 Jul 2022, 05:19
I'm no expert but can cut and paste some part from a Razer mouse control I lost interest in and have mostly forgotten about. Didn't like the huge download for their app. Hopefully it should help.
Code: format PE console include 'win32a.inc' VID = 0x1532 ; Razer Viper Mini (mouse) PID = 0x008A ; Vendor & Product ID struct SP_DEVICE_INTERFACE_DATA Size dd ? Guid rd 4 Flags dd ? Rsvd dd ? ends struct SP_DEVICE_INTERFACE_DETAIL_DATA_A Size dd ? DevicePath db ? ; Variable size, reserve space directly after this ends struct HIDD_ATTRIBUTES Size dd ? VendorID dw ? ProductID dw ? VersionNumber dw ? ends struct Urb Unk db ? Status db ? Trans db ? Packet dw ? Proto db ? DataSize db ? Class db ? CMD db ? Data rb 80 CS db 0 Rsvd db 0 ends GetFW = 0x87000800 ; A specific code for Viper Mini! DIGCF_DEFAULT = 1 DIGCF_PRESENT = 2 DIGCF_ALLCLASSES = 4 DIGCF_PROFILE = 8 DIGCF_DEVICEINTERFACE = 0x10 ;---------------------------------------- section '.text' code readable executable invoke GetStdHandle,STD_OUTPUT_HANDLE mov [hstd],eax mov [HidAttribs.Size],sizeof.HIDD_ATTRIBUTES invoke HidD_GetHidGuid,HidGuid ; Get Hid GUID invoke SetupDiGetClassDevs,HidGuid,0,0,DIGCF_PRESENT or DIGCF_DEVICEINTERFACE cmp eax,INVALID_HANDLE_VALUE je exit mov [hDev],eax invoke WriteFile,[hstd],Enum,Enum.len,NULL,NULL NextMember: mov [SPDiD.Size],sizeof.SP_DEVICE_INTERFACE_DATA invoke SetupDiEnumDeviceInterfaces,[hDev],NULL,HidGuid,[MemberIndex],SPDiD cmp eax,0 je None mov dword[SPDiD_Detail.Size],sizeof.SP_DEVICE_INTERFACE_DETAIL_DATA_A ; struct dword size + 1 char byte! :/ invoke SetupDiGetDeviceInterfaceDetail,[hDev],SPDiD,SPDiD_Detail,DPlen,RequiredSize,0 cmp eax,0 je exit mov eax,[RequiredSize] sub eax,5 ; 4 Bytes for Size header dword + 1 Byte zero termination invoke WriteFile,[hstd],SPDiD_Detail.DevicePath,eax,NULL,NULL invoke WriteFile,[hstd],CR,1,NULL,NULL invoke CreateFile,SPDiD_Detail.DevicePath,0,FILE_SHARE_READ or FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0 mov [hFile],eax cmp eax,INVALID_HANDLE_VALUE je BadFile ; invoke HidD_GetAttributes,[hFile],HidAttribs ; Too simplistic in this case ; cmp [HidAttribs.VendorID],VID ; jne NotFound ; cmp [HidAttribs.ProductID],PID ; jne NotFound push esi ; Need to be more specific with VID/PID as several Razer devices are generated from one mouse. push edi cld mov esi,CheckDev mov edi,SPDiD_Detail.DevicePath + 3 mov ecx,28/4 repe cmpsd pop edi pop esi je Found NotFound: invoke CloseHandle,[hFile] inc [MemberIndex] jmp NextMember Found: mov [Present],1 jmp None BadFile: inc [MemberIndex] jmp NextMember None: invoke SetupDiDestroyDeviceInfoList,[hDev] cmp eax,0 je exit cmp [Present],0 je exit mov dword[UrbBuffer+1],0x1f00 ; Status mov dword[UrbBuffer+5],GetFW ; Proto FW mov dword[UrbBuffer+9],0 ; Data mov dword[UrbBuffer+13],0 ; mov dword[UrbBuffer+17],0 ; call UrbPkt movzx eax,byte[UrbBuffer.Data] movzx ecx,byte[UrbBuffer.Data+1] movzx edx,byte[UrbBuffer.Data+2] cinvoke wsprintf,_FWVer,wsFW,eax,ecx,edx invoke WriteFile,[hstd],_FWVer,eax,NULL,NULL invoke HidD_GetProductString,[hFile],ProdBuff,ProdBuff.len invoke CloseHandle,[hFile] exit: cmp [Present],1 je @f invoke MessageBox,0,NotPresent,Product,0 invoke ExitProcess, 0 @@: invoke MessageBoxW,0,ProdBuff,ProductW,0 ; unicode! invoke ExitProcess, 0 ;---------------------------------------------- UrbPkt: push esi xor eax,eax lea esi,[UrbBuffer+3] mov ecx,86 xor dl,dl @@: ; UrbPkt checksum lodsb xor dl,al dec ecx jnz @b mov byte[esi],dl invoke HidD_SetFeature,[hFile],UrbBuffer,sizeof.Urb invoke Sleep,1 invoke HidD_GetFeature,[hFile],UrbBuffer,sizeof.Urb pop esi ret ;---------------------------------------------- align 4 CheckDev db '\hid#vid_1532&pid_008a&mi_00',0 wsFW db 10,'Firmware Version %u.%02u.%02u',0 CR db 10 NotPresent db 'Product Not Found',0 Product db 'Product',0 ProductW du 'Product',0 Enum db 10,'Searching Hid Devices...',10,10 .len = $ - Enum ;=========================================== section '.data' data readable writeable HidGuid rd 4 hDev dd ? hFile dd ? Present dd ? hstd dd ? RequiredSize dd ? BytesWritten dd ? MemberIndex dd ? HidAttribs HIDD_ATTRIBUTES SPDiD SP_DEVICE_INTERFACE_DATA UrbBuffer Urb _FWVer rb 10h SPDiD_Detail SP_DEVICE_INTERFACE_DETAIL_DATA_A rb 200h - 1 DPlen = $ - SPDiD_Detail - 4 ProdBuff rb 200h .len = $ - ProdBuff ;---------------------------------------- section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ Hid,'Hid.DLL',\ Setupapi,'Setupapi.dll' include 'api/kernel32.inc' include 'api/user32.inc' import Hid,\ HidD_SetFeature,'HidD_SetFeature',\ HidD_GetFeature,'HidD_GetFeature',\ HidD_GetHidGuid,'HidD_GetHidGuid',\ HidD_GetProductString,'HidD_GetProductString',\ HidD_GetAttributes,'HidD_GetAttributes' import Setupapi,\ SetupDiGetClassDevs,'SetupDiGetClassDevsA',\ SetupDiEnumDeviceInterfaces,'SetupDiEnumDeviceInterfaces',\ SetupDiGetDeviceInterfaceDetail,'SetupDiGetDeviceInterfaceDetailA',\ SetupDiDestroyDeviceInfoList,'SetupDiDestroyDeviceInfoList' |
|||
|
|
VSH 06 Jul 2022, 11:08
Thank you very much!
Quote:
Yes it is! Any examples are welcome. Quote:
import Hid,\...... this is it! It works in FASM, and i can call these APIs.I use Easy Code and i am very happy with it,so i will try to find solution there. |
|||
|
|
VSH 07 Jul 2022, 15:42
Hello,again.I wold like to share with you, that i ask Easy Code developers for support,and on the other day they created and send me needed files for the functions of “hid.dll”. Now everything is alright(as usual with this IDE
Many thanks to Easy Code developers for the fast and accurate support,and to the members of this forum! |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.