13 ((a = src[1]) && (b = src[2])) &&
14 (isxdigit(a) && isxdigit(b))){
40 if(s <=
',' || s ==
'/' ||
41 (s >=
':' && s <=
'@') ||
42 s ==
'[' || s ==
']' ||
44 char a = s >> 4, b = s & 0xF;
66 int16_t data2, data3, data4a;
68 if(sscanf(guid,
"{%08X-%04hX-%04hX-%04hX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
69 &data1, &data2, &data3, &data4a, data4b, data4b + 1, data4b + 2, data4b + 3, data4b + 4, data4b + 5) != 10)
71 memcpy(id->
guid + 0x0, &data1, 4);
72 memcpy(id->
guid + 0x4, &data2, 2);
73 memcpy(id->
guid + 0x6, &data3, 2);
74 memcpy(id->
guid + 0x8, &data4a, 2);
75 memcpy(id->
guid + 0xA, data4b, 6);
81 int16_t data2, data3, data4a;
83 memcpy(&data1, id->
guid + 0x0, 4);
84 memcpy(&data2, id->
guid + 0x4, 2);
85 memcpy(&data3, id->
guid + 0x6, 2);
86 memcpy(&data4a, id->
guid + 0x8, 2);
87 memcpy(data4b, id->
guid + 0xA, 6);
88 char* guid = malloc(39);
89 snprintf(guid, 39,
"{%08X-%04hX-%04hX-%04hX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
90 data1, data2, data3, data4a, data4b[0], data4b[1], data4b[2], data4b[3], data4b[4], data4b[5]);
97 void u16enc(
char* in,
ushort* out,
size_t* srclen,
size_t* dstlen){
99 utf8to16 = iconv_open(
"UTF-16LE",
"UTF-8");
100 memset(out, 0, *dstlen * 2);
101 *dstlen = *dstlen * 2 - 2;
102 iconv(
utf8to16, &in, srclen, (
char**)&out, dstlen);
107 utf16to8 = iconv_open(
"UTF-8",
"UTF-16LE");
108 size_t srclen2 = 0, srclenmax = *srclen;
109 for(; srclen2 < srclenmax; srclen2++){
113 *srclen = srclen2 * 2;
114 iconv(
utf16to8, (
char**)&in, srclen, &out, dstlen);
122 char decoded[strlen(name) + 1];
124 size_t srclen = strlen(decoded), dstlen =
MD_NAME_LEN;
125 u16enc(decoded, mode->
name, &srclen, &dstlen);
134 char decoded[strlen(name) + 1];
136 size_t srclen = strlen(decoded), dstlen =
PR_NAME_LEN;
137 u16enc(decoded, profile->
name, &srclen, &dstlen);
142 char* buffer = calloc(1, length * 4 - 3);
143 size_t srclen = length, dstlen = length * 4 - 4;
144 u16dec(name, buffer, &srclen, &dstlen);
146 char* buffer2 = malloc(strlen(buffer) * 3 + 1);
175 if(!
setid(&mode->
id,
id) && sscanf(
id,
"%08x", &newmodified) == 1)
176 memcpy(mode->
id.
modified, &newmodified,
sizeof(newmodified));
186 if(!
setid(&profile->
id,
id) && sscanf(
id,
"%08x", &newmodified) == 1)
187 memcpy(profile->
id.
modified, &newmodified,
sizeof(newmodified));
192 memset(mode, 0,
sizeof(*mode));
216 memset(mode, 0,
sizeof(*mode));
224 pthread_mutex_lock(
imutex(kb));
227 pthread_mutex_unlock(
imutex(kb));
247 pthread_mutex_lock(
imutex(kb));
250 pthread_mutex_unlock(
imutex(kb));
263 memcpy(&profile->
id, hw->
id,
sizeof(
usbid));
265 for(
int i = 0; i < modecount; i++){
268 memcpy(&mode->
id, hw->
id + i + 1,
sizeof(
usbid));
280 memcpy(hw->
id, &profile->
id,
sizeof(
usbid));
282 for(
int i = 0; i < modecount; i++){
285 memcpy(hw->
id + i + 1, &mode->
id,
sizeof(
usbid));
void freeprofile(usbdevice *kb)
char * getprofilename(usbprofile *profile)
void urlencode2(char *dst, const char *src)
char * getmodename(usbmode *mode)
int setid(usbid *id, const char *guid)
void cmd_id(usbdevice *kb, usbmode *mode, int dummy1, int dummy2, const char *id)
void u16enc(char *in, ushort *out, size_t *srclen, size_t *dstlen)
static void _freeprofile(usbdevice *kb)
void cmd_name(usbdevice *kb, usbmode *mode, int dummy1, int dummy2, const char *name)
char * gethwprofilename(hwprofile *profile)
char * gethwmodename(hwprofile *profile, int index)
void cmd_profilename(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *name)
void allocprofile(usbdevice *kb)
void urldecode2(char *dst, const char *src)
void cmd_profileid(usbdevice *kb, usbmode *mode, int dummy1, int dummy2, const char *id)
void hwtonative(usbprofile *profile, hwprofile *hw, int modecount)
void nativetohw(usbprofile *profile, hwprofile *hw, int modecount)
static void freemode(usbmode *mode)
void cmd_erase(usbdevice *kb, usbmode *mode, int dummy1, int dummy2, const char *dummy3)
static void initmode(usbmode *mode)
char * printname(ushort *name, int length)
void u16dec(ushort *in, char *out, size_t *srclen, size_t *dstlen)
#define hwloadprofile(kb, apply)
void cmd_eraseprofile(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
int loadprofile(usbdevice *kb)