// Generate MAC address void NullGenerateMacAddress(UCHAR *mac, UINT id, UINT seq) { UCHAR hash[SHA1_SIZE]; char name[MAX_SIZE]; BUF *b; // Validate arguments if (mac == NULL) { return; } b = NewBuf(); WriteBufInt(b, id); WriteBufInt(b, seq); GetMachineHostName(name, sizeof(name)); #ifdef OS_WIN32 WriteBufInt(b, MsGetCurrentProcessId()); #endif // OS_WIN32 WriteBufStr(b, name); HashSha1(hash, b->Buf, b->Size); FreeBuf(b); Copy(mac, hash, 6); mac[0] = 0x7E; }
// Save the Unicode cache void SaveUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash) { UNICODE_CACHE c; BUF *b; UINT i; IO *io; wchar_t name[MAX_PATH]; UCHAR binhash[MD5_SIZE]; // Validate arguments if (strfilename == NULL || hash == NULL) { return; } Zero(&c, sizeof(c)); UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename); c.StrFileSize = strfilesize; GetMachineName(c.MachineName, sizeof(c.MachineName)); c.OsType = GetOsInfo()->OsType; Copy(c.hash, hash, MD5_SIZE); #ifdef OS_UNIX GetCurrentCharSet(c.CharSet, sizeof(c.CharSet)); #else // OS_UNIX { UINT id = MsGetThreadLocale(); Copy(c.CharSet, &id, sizeof(id)); } #endif // OS_UNIX b = NewBuf(); WriteBuf(b, &c, sizeof(c)); WriteBufInt(b, LIST_NUM(TableList)); for (i = 0;i < LIST_NUM(TableList);i++) { TABLE *t = LIST_DATA(TableList, i); WriteBufInt(b, StrLen(t->name)); WriteBuf(b, t->name, StrLen(t->name)); WriteBufInt(b, StrLen(t->str)); WriteBuf(b, t->str, StrLen(t->str)); WriteBufInt(b, UniStrLen(t->unistr)); WriteBuf(b, t->unistr, UniStrLen(t->unistr) * sizeof(wchar_t)); } Hash(binhash, b->Buf, b->Size, false); WriteBuf(b, binhash, MD5_SIZE); GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash); io = FileCreateW(name); if (io != NULL) { SeekBuf(b, 0, 0); BufToFile(io, b); FileClose(io); } FreeBuf(b); }
PACK *WpcCallEx(char *url, INTERNET_SETTING *setting, UINT timeout_connect, UINT timeout_comm, char *function_name, PACK *pack, X *cert, K *key, void *sha1_cert_hash, bool *cancel, UINT max_recv_size, char *additional_header_name, char *additional_header_value) { URL_DATA data; BUF *b, *recv; UINT error; WPC_PACKET packet; // Validate arguments if (function_name == NULL || pack == NULL) { return PackError(ERR_INTERNAL_ERROR); } if (ParseUrl(&data, url, true, NULL) == false) { return PackError(ERR_INTERNAL_ERROR); } PackAddStr(pack, "function", function_name); b = WpcGeneratePacket(pack, cert, key); if (b == NULL) { return PackError(ERR_INTERNAL_ERROR); } SeekBuf(b, b->Size, 0); WriteBufInt(b, 0); SeekBuf(b, 0, 0); if (IsEmptyStr(additional_header_name) == false && IsEmptyStr(additional_header_value) == false) { StrCpy(data.AdditionalHeaderName, sizeof(data.AdditionalHeaderName), additional_header_name); StrCpy(data.AdditionalHeaderValue, sizeof(data.AdditionalHeaderValue), additional_header_value); } recv = HttpRequestEx(&data, setting, timeout_connect, timeout_comm, &error, false, b->Buf, NULL, NULL, sha1_cert_hash, cancel, max_recv_size); FreeBuf(b); if (recv == NULL) { return PackError(error); } if (WpcParsePacket(&packet, recv) == false) { FreeBuf(recv); return PackError(ERR_PROTOCOL_ERROR); } FreeBuf(recv); FreeX(packet.Cert); return packet.Pack; }
// VALUE を書き出す void WriteValue(BUF *b, VALUE *v, UINT type) { UINT len; BYTE *u; UINT u_size; // 引数チェック if (b == NULL || v == NULL) { return; } // データ項目 switch (type) { case VALUE_INT: // 整数 WriteBufInt(b, v->IntValue); break; case VALUE_INT64: // 64 bit 整数 WriteBufInt64(b, v->Int64Value); break; case VALUE_DATA: // データ // サイズ WriteBufInt(b, v->Size); // 本体 WriteBuf(b, v->Data, v->Size); break; case VALUE_STR: // ANSI 文字列 len = StrLen(v->Str); // 長さ WriteBufInt(b, len); // 文字列本体 WriteBuf(b, v->Str, len); break; case VALUE_UNISTR: // Unicode 文字列 // UTF-8 に変換する u_size = CalcUniToUtf8(v->UniStr) + 1; u = ZeroMalloc(u_size); UniToUtf8(u, u_size, v->UniStr); // サイズ WriteBufInt(b, u_size); // UTF-8 文字列本体 WriteBuf(b, u, u_size); Free(u); break; } }
// ELEMENT を書き出す void WriteElement(BUF *b, ELEMENT *e) { UINT i; // 引数チェック if (b == NULL || e == NULL) { return; } // 名前 WriteBufStr(b, e->name); // 項目の種類 WriteBufInt(b, e->type); // 項目数 WriteBufInt(b, e->num_value); // VALUE for (i = 0;i < e->num_value;i++) { VALUE *v = e->values[i]; WriteValue(b, v, e->type); } }
// PACK を書き出す void WritePack(BUF *b, PACK *p) { UINT i; // 引数チェック if (b == NULL || p == NULL) { return; } // ELEMENT 数 WriteBufInt(b, LIST_NUM(p->elements)); // ELEMENT を書き出す for (i = 0;i < LIST_NUM(p->elements);i++) { ELEMENT *e = LIST_DATA(p->elements, i); WriteElement(b, e); } }
// Create a Status Info Attribute SSTP_ATTRIBUTE *SstpNewStatusInfoAttribute(UCHAR attrib_id, UINT status) { SSTP_ATTRIBUTE *a; UCHAR uc; BUF *b = NewBuf(); uc = 0; WriteBuf(b, &uc, 1); WriteBuf(b, &uc, 1); WriteBuf(b, &uc, 1); WriteBuf(b, &attrib_id, 1); WriteBufInt(b, status); a = SstpNewAttribute(SSTP_ATTRIB_STATUS_INFO, b->Buf, b->Size); FreeBuf(b); return a; }
// Adding Attributes void RadiusAddValue(BUF *b, UCHAR t, UINT v, UCHAR vt, void *data, UINT size) { UINT len; // Validate arguments if (b == NULL || (data == NULL && size != 0)) { return; } // type WriteBufChar(b, t); // length len = 2 + size; if (t == 26) { len += 6; } WriteBufChar(b, (UCHAR)len); if (t != 26) { // value WriteBuf(b, data, size); } else { // vendor WriteBufInt(b, v); // vendor type WriteBufChar(b, vt); // length2 len = size + 2; WriteBufChar(b, (UCHAR)len); // value WriteBuf(b, data, size); } }
// Generate a set of dummy IP addresses and mark void GenerateDummyIpAndMark(void *hash_seed, IPTABLES_ENTRY *e, UINT id) { PRAND *p; BUF *b; if (hash_seed == NULL || e == NULL) { return; } b = NewBuf(); WriteBufInt(b, id); WriteBuf(b, hash_seed, SHA1_SIZE); WriteBufStr(b, "20151002"); p = NewPRand(b->Buf, b->Size); FreeBuf(b); GenerateDummyIp(p, &e->DummySrcIp); GenerateDummyIp(p, &e->DummyDestIP); e->DummyMark = GenerateDummyMark(p); FreePRand(p); }
// Output the folder contents (Recursive, binary) void CfgOutputFolderBin(BUF *b, FOLDER *f) { UINT i; // Validate arguments if (b == NULL || f == NULL) { return; } // Folder name WriteBufStr(b, f->Name); // The number of the subfolder WriteBufInt(b, LIST_NUM(f->Folders)); // Subfolder for (i = 0;i < LIST_NUM(f->Folders);i++) { FOLDER *sub = LIST_DATA(f->Folders, i); CfgOutputFolderBin(b, sub); if ((i % 100) == 99) { YieldCpu(); } } // The number of Items WriteBufInt(b, LIST_NUM(f->Items)); // Item for (i = 0;i < LIST_NUM(f->Items);i++) { char *utf8; UINT utf8_size; ITEM *t = LIST_DATA(f->Items, i); // Item Name WriteBufStr(b, t->Name); // Type WriteBufInt(b, t->Type); switch (t->Type) { case ITEM_TYPE_INT: // Integer WriteBufInt(b, *((UINT *)t->Buf)); break; case ITEM_TYPE_INT64: // 64-bit integer WriteBufInt64(b, *((UINT64 *)t->Buf)); break; case ITEM_TYPE_BYTE: // Data size WriteBufInt(b, t->size); // Data WriteBuf(b, t->Buf, t->size); break; case ITEM_TYPE_STRING: // String utf8_size = CalcUniToUtf8((wchar_t *)t->Buf) + 1; utf8 = ZeroMalloc(utf8_size); UniToUtf8(utf8, utf8_size, (wchar_t *)t->Buf); WriteBufInt(b, StrLen(utf8)); WriteBuf(b, utf8, StrLen(utf8)); Free(utf8); break; case ITEM_TYPE_BOOL: // Boolean type if (*((bool *)t->Buf) == false) { WriteBufInt(b, 0); } else { WriteBufInt(b, 1); } break; } } }