void InitDecoder() { CleanupDecoder(); UINT32 numFormats = 0; GetNumberOfFormats(&numFormats); for(unsigned int i = 0; i < numFormats; i++) { PROPVARIANT var = {VT_EMPTY}; ArchiveFormatInfo info; GetHandlerProperty2(i, NArchive::kName, &var); if(var.vt == VT_BSTR) info.name = wstrToStr(var.bstrVal); GetHandlerProperty2(i, NArchive::kExtension, &var); if(var.vt == VT_BSTR) info.extensions = tokenize(wstrToStr(var.bstrVal), " "); GetHandlerProperty2(i, NArchive::kStartSignature, &var); if(var.vt == VT_BSTR) info.signature = (const char*)var.bstrVal; // note: there's no 100% correct way of doing this with the existing 7-zip interface, but this is much better than using SysStringLen() in any way (it would return 1 for the signature "BZh", for example) GetHandlerProperty2(i,NArchive::kClassID,&var); if(var.vt == VT_BSTR) memcpy(&info.guid, var.bstrVal, 16); else memset(&info.guid, 0, 16); s_formatInfos.push_back(info); VariantClear((VARIANTARG*)&var); } }
TechTree *TechTree::fromJSONObject(const JSONObject &tree, ImageManager *imgMgr) { TechTree *that = new TechTree(); JSONObject::const_iterator tree_it; for (tree_it = tree.begin(); tree_it != tree.end(); tree_it++) { std::string type = wstrToStr(tree_it->first); const JSONObject &obj = tree_it->second->AsObject(); JSONObject::const_iterator it; for (it = obj.begin(); it != obj.end(); it++) { const std::string &className = wstrToStr(it->first); const JSONObject &content = it->second->AsObject(); const std::wstring &displayName = content.find(L"displayName")->second->AsString(); const JSONArray &rectVect = content.find(L"spriteRect")->second->AsArray(); int size = content.find(L"size")->second->AsNumber(); sf::IntRect spriteRect(rectVect[0]->AsNumber(), rectVect[1]->AsNumber(), rectVect[2]->AsNumber(), rectVect[3]->AsNumber()); if (type == "units") { that->units[className] = new Unit(className, wstrToStr(displayName), spriteRect, size, imgMgr); } else if (type == "buildings") { that->buildings[className] = new Building(className, wstrToStr(displayName), spriteRect, size, imgMgr); } else break; } } log("Successfully loaded the technology tree"); return that; }
void SchannelCertificate::parse() { // // Subject name // DWORD requiredSize = CertNameToStr(X509_ASN_ENCODING, &m_cert->pCertInfo->Subject, CERT_OID_NAME_STR, NULL, 0); if (requiredSize > 1) { vector<char> rawSubjectName(requiredSize); CertNameToStr(X509_ASN_ENCODING, &m_cert->pCertInfo->Subject, CERT_OID_NAME_STR, &rawSubjectName[0], rawSubjectName.size()); m_subjectName = std::string(&rawSubjectName[0]); } // // Common name // // Note: We only pull out one common name from the cert. requiredSize = CertGetNameString(m_cert, CERT_NAME_ATTR_TYPE, 0, szOID_COMMON_NAME, NULL, 0); if (requiredSize > 1) { vector<char> rawCommonName(requiredSize); requiredSize = CertGetNameString(m_cert, CERT_NAME_ATTR_TYPE, 0, szOID_COMMON_NAME, &rawCommonName[0], rawCommonName.size()); m_commonNames.push_back( std::string(&rawCommonName[0]) ); } // // Subject alternative names // PCERT_EXTENSION pExtensions = CertFindExtension(szOID_SUBJECT_ALT_NAME2, m_cert->pCertInfo->cExtension, m_cert->pCertInfo->rgExtension); if (pExtensions) { CRYPT_DECODE_PARA decodePara = {0}; decodePara.cbSize = sizeof(decodePara); CERT_ALT_NAME_INFO* pAltNameInfo = NULL; DWORD altNameInfoSize = 0; BOOL status = CryptDecodeObjectEx( X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_SUBJECT_ALT_NAME2, pExtensions->Value.pbData, pExtensions->Value.cbData, CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, &decodePara, &pAltNameInfo, &altNameInfoSize); if (status && pAltNameInfo) { for (int i = 0; i < pAltNameInfo->cAltEntry; i++) { if (pAltNameInfo->rgAltEntry[i].dwAltNameChoice == CERT_ALT_NAME_DNS_NAME) addDNSName( wstrToStr( pAltNameInfo->rgAltEntry[i].pwszDNSName ) ); } } } // if (pExtensions) // { // vector<wchar_t> subjectAlt // CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_SUBJECT_ALT_NAME, pExtensions->Value->pbData, pExtensions->Value->cbData, ) // } // // // subjectAltNames // int subjectAltNameLoc = X509_get_ext_by_NID(cert.get(), NID_subject_alt_name, -1); // if(subjectAltNameLoc != -1) { // X509_EXTENSION* extension = X509_get_ext(cert.get(), subjectAltNameLoc); // std::shared_ptr<GENERAL_NAMES> generalNames(reinterpret_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(extension)), GENERAL_NAMES_free); // std::shared_ptr<ASN1_OBJECT> xmppAddrObject(OBJ_txt2obj(ID_ON_XMPPADDR_OID, 1), ASN1_OBJECT_free); // std::shared_ptr<ASN1_OBJECT> dnsSRVObject(OBJ_txt2obj(ID_ON_DNSSRV_OID, 1), ASN1_OBJECT_free); // for (int i = 0; i < sk_GENERAL_NAME_num(generalNames.get()); ++i) { // GENERAL_NAME* generalName = sk_GENERAL_NAME_value(generalNames.get(), i); // if (generalName->type == GEN_OTHERNAME) { // OTHERNAME* otherName = generalName->d.otherName; // if (OBJ_cmp(otherName->type_id, xmppAddrObject.get()) == 0) { // // XmppAddr // if (otherName->value->type != V_ASN1_UTF8STRING) { // continue; // } // ASN1_UTF8STRING* xmppAddrValue = otherName->value->value.utf8string; // addXMPPAddress(ByteArray(ASN1_STRING_data(xmppAddrValue), ASN1_STRING_length(xmppAddrValue)).toString()); // } // else if (OBJ_cmp(otherName->type_id, dnsSRVObject.get()) == 0) { // // SRVName // if (otherName->value->type != V_ASN1_IA5STRING) { // continue; // } // ASN1_IA5STRING* srvNameValue = otherName->value->value.ia5string; // addSRVName(ByteArray(ASN1_STRING_data(srvNameValue), ASN1_STRING_length(srvNameValue)).toString()); // } // } // else if (generalName->type == GEN_DNS) { // // DNSName // addDNSName(ByteArray(ASN1_STRING_data(generalName->d.dNSName), ASN1_STRING_length(generalName->d.dNSName)).toString()); // } // } // } }
ArchiveFile::ArchiveFile(const char* filename) { assert(!s_formatInfos.empty()); m_typeIndex = -1; m_numItems = 0; m_items = NULL; m_filename = NULL; FILE* file = fopen(filename, "rb"); if(!file) return; m_filename = new char[strlen(filename)+1]; strcpy(m_filename, filename); // detect archive type using format signature in file for(size_t i = 0; i < s_formatInfos.size() && m_typeIndex < 0; i++) { fseek(file, 0, SEEK_SET); std::string& formatSig = s_formatInfos[i].signature; int len = formatSig.size(); if(len == 0) continue; // because some formats have no signature char* fileSig = (char*)_alloca(len); fread(fileSig, 1, len, file); if(!memcmp(formatSig.c_str(), fileSig, len)) m_typeIndex = i; } // if no signature match has been found, detect archive type using filename. // this is only for signature-less formats const char* fileExt = strrchr(filename, '.'); if(fileExt++) { for(size_t i = 0; i < s_formatInfos.size() && m_typeIndex < 0; i++) { if(s_formatInfos[i].signature.empty()) { std::vector<std::string>& formatExts = s_formatInfos[i].extensions; for(size_t j = 0; j < formatExts.size(); j++) { if(!_stricmp(formatExts[j].c_str(), fileExt)) { m_typeIndex = i; break; } } } } } if(m_typeIndex < 0) { // uncompressed m_numItems = 1; m_items = new ArchiveItem[m_numItems]; fseek(file, 0, SEEK_END); m_items[0].size = ftell(file); m_items[0].name = new char[strlen(filename)+1]; strcpy(m_items[0].name, filename); } else { IInArchive* object = NULL; if(SUCCEEDED(CreateObject(&s_formatInfos[m_typeIndex].guid, &IID_IInArchive, (void**)&object))) { InFileStream* ifs = new InFileStream(filename); if(SUCCEEDED(object->Open(ifs,0,0))) { UInt32 numItems = 0; object->GetNumberOfItems(&numItems); m_numItems = numItems; m_items = new ArchiveItem[m_numItems]; for(int i = 0; i < m_numItems; i++) { PROPVARIANT var = {VT_EMPTY}; ArchiveItem& item = m_items[i]; object->GetProperty(i, kpidSize, &var); item.size = var.uhVal.LowPart; object->GetProperty(i, kpidPath, &var); std::string& path = wstrToStr(var.bstrVal); item.name = new char[path.size()+1]; strcpy(item.name, path.c_str()); //object->GetProperty(i, kpidMethod, &var); //std::string& method = wstrToStr(var.bstrVal); //item.method = new char[method.size()+1]; //strcpy(item.method, method.c_str()); object->GetProperty(i, kpidEncrypted, &var); #ifdef _NO_CRYPTO if(var.boolVal) item.size = 0; // don't support decompressing it, pretend size zero #else #error password support NYI... see client7z.cpp item.encrypted = !!var.boolVal; #endif VariantClear((VARIANTARG*)&var); } object->Close(); } object->Release(); } } fclose(file); }