/** * Generates CA Certificate File, writes CA private and public keys to storage * * @param[in] updateCAkeys use new or old keys */ int GenerateCACertificateFile(const int updateCAkeys) { // Variables definition uint8_t derData[DEFAULT_DER_DATA_SIZE] = {0}; uint8_t caPubKey[PUBLIC_KEY_SIZE] = {0}; uint8_t caPrivKey[PRIVATE_KEY_SIZE] = {0}; uint8_t defaultCaName[] = "Default_CA_Name"; ByteArray certDer = BYTE_ARRAY_CONSTRUCTOR(derData); ByteArray pubKeyIss = BYTE_ARRAY_CONSTRUCTOR(caPubKey); ByteArray privKeyIss = BYTE_ARRAY_CONSTRUCTOR(caPrivKey); ByteArray rootName = BYTE_ARRAY_CONSTRUCTOR(defaultCaName); // Generate if (updateCAkeys) { GenerateCAKeyPair(&privKeyIss, &pubKeyIss); printf("CA key pair was changed!\n"); if (GenerateDERCertificateFile(&pubKeyIss, DEFAULT_CA_PUBLIC_KEY_NAME) != PKI_SUCCESS) { printf("Unable to generate CA public key file!\n"); exit(0); } else { printf("CA public key file generated: %s\n", DEFAULT_CA_PUBLIC_KEY_NAME); }; } SetSerialNumber(DEFAULT_SN); SetRootName(rootName); CKMIssueRootCertificate(0, 0, &certDer); // Writes ByteArray to file if (GenerateDERCertificateFile(&certDer, DEFAULT_CA_CRT_NAME) != PKI_SUCCESS) { printf("Unable to generate CA Certificate file!\n"); exit(0); } else { printf("CA Certificate File generated: %s\n", DEFAULT_CA_CRT_NAME); }; return 0; }
/** * Check if the settings are valid and if not initialize them */ void WidgetSettingsClass::Init() { int magic_number = ReadInt(MAGIC_NUMBER_OFFSET); if (magic_number != MAGIC_NUMBER) { // init the settings WriteInt(MAGIC_NUMBER_OFFSET, MAGIC_NUMBER); SetStartAddress(1); SetEstaId(0x7a70); SetSerialNumber(DEFAULT_SERIAL_NUMBER); SetDeviceLabel(DEFAULT_LABEL, sizeof(DEFAULT_LABEL)); SetDevicePowerCycles(0); SaveSensorValue(0); SetPersonality(1); } else { m_start_address = ReadInt(START_ADDRESS_OFFSET); m_personality = EEPROM.read(DMX_PERSONALITY_VALUE); } IncrementDevicePowerCycles(); }
/////////////////////////// // PROGRAM CAMERA void AltaUsbIo::Program(const std::string & FilenameCamCon, const std::string & FilenameBufCon, const std::string & FilenameFx2, const std::string & FilenameGpifCamCon,const std::string & FilenameGpifBufCon, const std::string & FilenameGpifFifo, bool Print2StdOut ) { m_Print2StdOut = Print2StdOut; //STEP 1 //get the current product and device identifier uint16_t Vid = 0; uint16_t Pid = 0; uint16_t Did = 0; GetUsbVendorInfo( Vid, Pid, Did ); //if this programmed with apogee fx2 code //grab the custom serial number now, so we //can write it back at the end of the firmware //programming std::string serialNum; if ( ( UsbFrmwr::ALTA_USB_PID == Pid ) && (UsbFrmwr::ALTA_USB_DID <= Did) ) { serialNum = GetSerialNumber(); } Progress2StdOut( 8 ); //STEP 2 //download the alta firmware DownloadFirmware(); Progress2StdOut( 16 ); //STEP 3 // initialize prom header information Eeprom::Header hdr; memset(&hdr, 0, sizeof( hdr ) ); hdr.Size = sizeof( hdr ); hdr.Version = Eeprom::HEADER_VERSION; Progress2StdOut( 24 ); //STEP 4 //download bufcon PromFx2Io pf( m_Usb, ALTA_EEPROM_MAX_BLOCKS, ALTA_EEPROM_MAX_BANKS ); uint32_t DownloadSize = 0; pf.WriteFile2Eeprom( FilenameBufCon, BUFCON_PROM_BANK, BUFCON_PROM_BLOCK , BUFCON_PROM_ADDR, DownloadSize ); hdr.BufConSize = DownloadSize; hdr.Fields |= Eeprom::HEADER_BUFCON_VALID_BIT; Progress2StdOut( 32 ); //STEP 5 //download camcon pf.WriteFile2Eeprom( FilenameCamCon, CAMCON_PROM_BANK, CAMCON_PROM_BLOCK , CAMCON_PROM_ADDR, DownloadSize ); hdr.CamConSize = DownloadSize; hdr.Fields |= Eeprom::HEADER_CAMCON_VALID_BIT; Progress2StdOut( 40 ); //STEP 6 //download the fx2 pf.WriteFile2Eeprom( FilenameFx2, FX2_PROM_BANK, FX2_PROM_BLOCK, FX2_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_BOOTROM_VALID_BIT; Progress2StdOut( 48 ); //STEP 7 //download the bufcon gpif waveform pf.WriteFile2Eeprom( FilenameGpifBufCon, GPIF_WAVEFORM_BUFCON_PROM_BANK, GPIF_WAVEFORM_BUFCON_PROM_BLOCK, GPIF_WAVEFORM_BUFCON_PROM_ADDR, DownloadSize ); Progress2StdOut( 56 ); //STEP 8 //download the camcon gpif waveform pf.WriteFile2Eeprom( FilenameGpifCamCon, GPIF_WAVEFORM_CAMCON_PROM_BANK, GPIF_WAVEFORM_CAMCON_PROM_BLOCK, GPIF_WAVEFORM_CAMCON_PROM_ADDR, DownloadSize ); Progress2StdOut( 64 ); //STEP 9 //download the FIFO gpif waveform pf.WriteFile2Eeprom( FilenameGpifFifo, GPIF_WAVEFORM_FIFO_PROM_BANK, GPIF_WAVEFORM_FIFO_PROM_BLOCK, GPIF_WAVEFORM_FIFO_PROM_ADDR, DownloadSize ); hdr.Fields |= Eeprom::HEADER_GPIF_VALID_BIT; Progress2StdOut( 72 ); //STEP 10 //set the vid, pid, and did hdr.VendorId = UsbFrmwr::APOGEE_VID; hdr.Fields |= Eeprom::HEADER_VID_VALID; hdr.ProductId = UsbFrmwr::ALTA_USB_PID; hdr.Fields |= Eeprom::HEADER_PID_VALID ; hdr.DeviceId = UsbFrmwr::ALTA_USB_DID; hdr.Fields |= Eeprom::HEADER_DID_VALID; Progress2StdOut( 80 ); //STEP 11 //write the header hdr.CheckSum = Eeprom::CalcHdrCheckSum( hdr ); pf.WriteEepromHdr( hdr, HEADER_PROM_BANK, HEADER_PROM_BLOCK, HEADER_PROM_ADDR); Progress2StdOut( 88 ); //STEP 12 //write the stored serial number to the camera SetSerialNumber( serialNum ); Progress2StdOut( 100 ); //turn this off on exit m_Print2StdOut = false; }
/* create ASN.1 fomatted RecipientInfo structure, returns sequence size */ CYASSL_LOCAL int CreateRecipientInfo(const byte* cert, word32 certSz, int keyEncAlgo, int blockKeySz, RNG* rng, byte* contentKeyPlain, byte* contentKeyEnc, int* keyEncSz, byte* out, word32 outSz) { word32 idx = 0; int ret = 0, totalSz = 0; int verSz, issuerSz, snSz, keyEncAlgSz; int issuerSeqSz, recipSeqSz, issuerSerialSeqSz; int encKeyOctetStrSz; byte ver[MAX_VERSION_SZ]; byte serial[MAX_SN_SZ]; byte issuerSerialSeq[MAX_SEQ_SZ]; byte recipSeq[MAX_SEQ_SZ]; byte issuerSeq[MAX_SEQ_SZ]; byte keyAlgArray[MAX_ALGO_SZ]; byte encKeyOctetStr[MAX_OCTET_STR_SZ]; RsaKey pubKey; DecodedCert decoded; InitDecodedCert(&decoded, (byte*)cert, certSz, 0); ret = ParseCert(&decoded, CA_TYPE, NO_VERIFY, 0); if (ret < 0) { FreeDecodedCert(&decoded); return ret; } /* version */ verSz = SetMyVersion(0, ver, 0); /* IssuerAndSerialNumber */ if (decoded.issuerRaw == NULL || decoded.issuerRawLen == 0) { CYASSL_MSG("DecodedCert lacks raw issuer pointer and length"); FreeDecodedCert(&decoded); return -1; } issuerSz = decoded.issuerRawLen; issuerSeqSz = SetSequence(issuerSz, issuerSeq); if (decoded.serial == NULL || decoded.serialSz == 0) { CYASSL_MSG("DecodedCert missing serial number"); FreeDecodedCert(&decoded); return -1; } snSz = SetSerialNumber(decoded.serial, decoded.serialSz, serial); issuerSerialSeqSz = SetSequence(issuerSeqSz + issuerSz + snSz, issuerSerialSeq); /* KeyEncryptionAlgorithmIdentifier, only support RSA now */ if (keyEncAlgo != RSAk) return ALGO_ID_E; keyEncAlgSz = SetAlgoID(keyEncAlgo, keyAlgArray, keyType, 0); if (keyEncAlgSz == 0) return BAD_FUNC_ARG; /* EncryptedKey */ ret = InitRsaKey(&pubKey, 0); if (ret != 0) return ret; if (RsaPublicKeyDecode(decoded.publicKey, &idx, &pubKey, decoded.pubKeySize) < 0) { CYASSL_MSG("ASN RSA key decode error"); return PUBLIC_KEY_E; } *keyEncSz = RsaPublicEncrypt(contentKeyPlain, blockKeySz, contentKeyEnc, MAX_ENCRYPTED_KEY_SZ, &pubKey, rng); FreeRsaKey(&pubKey); if (*keyEncSz < 0) { CYASSL_MSG("RSA Public Encrypt failed"); return *keyEncSz; } encKeyOctetStrSz = SetOctetString(*keyEncSz, encKeyOctetStr); /* RecipientInfo */ recipSeqSz = SetSequence(verSz + issuerSerialSeqSz + issuerSeqSz + issuerSz + snSz + keyEncAlgSz + encKeyOctetStrSz + *keyEncSz, recipSeq); if (recipSeqSz + verSz + issuerSerialSeqSz + issuerSeqSz + snSz + keyEncAlgSz + encKeyOctetStrSz + *keyEncSz > (int)outSz) { CYASSL_MSG("RecipientInfo output buffer too small"); return BUFFER_E; } XMEMCPY(out + totalSz, recipSeq, recipSeqSz); totalSz += recipSeqSz; XMEMCPY(out + totalSz, ver, verSz); totalSz += verSz; XMEMCPY(out + totalSz, issuerSerialSeq, issuerSerialSeqSz); totalSz += issuerSerialSeqSz; XMEMCPY(out + totalSz, issuerSeq, issuerSeqSz); totalSz += issuerSeqSz; XMEMCPY(out + totalSz, decoded.issuerRaw, issuerSz); totalSz += issuerSz; XMEMCPY(out + totalSz, serial, snSz); totalSz += snSz; XMEMCPY(out + totalSz, keyAlgArray, keyEncAlgSz); totalSz += keyEncAlgSz; XMEMCPY(out + totalSz, encKeyOctetStr, encKeyOctetStrSz); totalSz += encKeyOctetStrSz; XMEMCPY(out + totalSz, contentKeyEnc, *keyEncSz); totalSz += *keyEncSz; FreeDecodedCert(&decoded); return totalSz; }
/* build PKCS#7 signedData content type */ int PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz) { static const byte outerOid[] = { ASN_OBJECT_ID, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02 }; static const byte innerOid[] = { ASN_OBJECT_ID, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 }; ESD esd; word32 signerInfoSz = 0; word32 totalSz = 0; int idx = 0, ret = 0; byte* flatSignedAttribs = NULL; word32 flatSignedAttribsSz = 0; word32 innerOidSz = sizeof(innerOid); word32 outerOidSz = sizeof(outerOid); if (pkcs7 == NULL || pkcs7->content == NULL || pkcs7->contentSz == 0 || pkcs7->encryptOID == 0 || pkcs7->hashOID == 0 || pkcs7->rng == 0 || pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0 || pkcs7->privateKey == NULL || pkcs7->privateKeySz == 0 || output == NULL || outputSz == 0) return BAD_FUNC_ARG; XMEMSET(&esd, 0, sizeof(esd)); ret = InitSha(&esd.sha); if (ret != 0) return ret; if (pkcs7->contentSz != 0) { ShaUpdate(&esd.sha, pkcs7->content, pkcs7->contentSz); esd.contentDigest[0] = ASN_OCTET_STRING; esd.contentDigest[1] = SHA_DIGEST_SIZE; ShaFinal(&esd.sha, &esd.contentDigest[2]); } esd.innerOctetsSz = SetOctetString(pkcs7->contentSz, esd.innerOctets); esd.innerContSeqSz = SetExplicit(0, esd.innerOctetsSz + pkcs7->contentSz, esd.innerContSeq); esd.contentInfoSeqSz = SetSequence(pkcs7->contentSz + esd.innerOctetsSz + innerOidSz + esd.innerContSeqSz, esd.contentInfoSeq); esd.issuerSnSz = SetSerialNumber(pkcs7->issuerSn, pkcs7->issuerSnSz, esd.issuerSn); signerInfoSz += esd.issuerSnSz; esd.issuerNameSz = SetSequence(pkcs7->issuerSz, esd.issuerName); signerInfoSz += esd.issuerNameSz + pkcs7->issuerSz; esd.issuerSnSeqSz = SetSequence(signerInfoSz, esd.issuerSnSeq); signerInfoSz += esd.issuerSnSeqSz; esd.signerVersionSz = SetMyVersion(1, esd.signerVersion, 0); signerInfoSz += esd.signerVersionSz; esd.signerDigAlgoIdSz = SetAlgoID(pkcs7->hashOID, esd.signerDigAlgoId, hashType, 0); signerInfoSz += esd.signerDigAlgoIdSz; esd.digEncAlgoIdSz = SetAlgoID(pkcs7->encryptOID, esd.digEncAlgoId, keyType, 0); signerInfoSz += esd.digEncAlgoIdSz; if (pkcs7->signedAttribsSz != 0) { byte contentTypeOid[] = { ASN_OBJECT_ID, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 }; byte contentType[] = { ASN_OBJECT_ID, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01 }; byte messageDigestOid[] = { ASN_OBJECT_ID, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 }; PKCS7Attrib cannedAttribs[2] = { { contentTypeOid, sizeof(contentTypeOid), contentType, sizeof(contentType) }, { messageDigestOid, sizeof(messageDigestOid), esd.contentDigest, sizeof(esd.contentDigest) } }; word32 cannedAttribsCount = sizeof(cannedAttribs)/sizeof(PKCS7Attrib); esd.signedAttribsCount += cannedAttribsCount; esd.signedAttribsSz += EncodeAttributes(&esd.signedAttribs[0], 2, cannedAttribs, cannedAttribsCount); esd.signedAttribsCount += pkcs7->signedAttribsSz; esd.signedAttribsSz += EncodeAttributes(&esd.signedAttribs[2], 4, pkcs7->signedAttribs, pkcs7->signedAttribsSz); flatSignedAttribs = (byte*)XMALLOC(esd.signedAttribsSz, 0, NULL); flatSignedAttribsSz = esd.signedAttribsSz; if (flatSignedAttribs == NULL) return MEMORY_E; FlattenAttributes(flatSignedAttribs, esd.signedAttribs, esd.signedAttribsCount); esd.signedAttribSetSz = SetImplicit(ASN_SET, 0, esd.signedAttribsSz, esd.signedAttribSet); } /* Calculate the final hash and encrypt it. */ { RsaKey privKey; int result; word32 scratch = 0; byte digestInfo[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ + SHA_DIGEST_SIZE]; byte digestInfoSeq[MAX_SEQ_SZ]; byte digestStr[MAX_OCTET_STR_SZ]; word32 digestInfoSeqSz, digestStrSz; int digIdx = 0; if (pkcs7->signedAttribsSz != 0) { byte attribSet[MAX_SET_SZ]; word32 attribSetSz; attribSetSz = SetSet(flatSignedAttribsSz, attribSet); ret = InitSha(&esd.sha); if (ret < 0) { XFREE(flatSignedAttribs, 0, NULL); return ret; } ShaUpdate(&esd.sha, attribSet, attribSetSz); ShaUpdate(&esd.sha, flatSignedAttribs, flatSignedAttribsSz); } ShaFinal(&esd.sha, esd.contentAttribsDigest); digestStrSz = SetOctetString(SHA_DIGEST_SIZE, digestStr); digestInfoSeqSz = SetSequence(esd.signerDigAlgoIdSz + digestStrSz + SHA_DIGEST_SIZE, digestInfoSeq); XMEMCPY(digestInfo + digIdx, digestInfoSeq, digestInfoSeqSz); digIdx += digestInfoSeqSz; XMEMCPY(digestInfo + digIdx, esd.signerDigAlgoId, esd.signerDigAlgoIdSz); digIdx += esd.signerDigAlgoIdSz; XMEMCPY(digestInfo + digIdx, digestStr, digestStrSz); digIdx += digestStrSz; XMEMCPY(digestInfo + digIdx, esd.contentAttribsDigest, SHA_DIGEST_SIZE); digIdx += SHA_DIGEST_SIZE; result = InitRsaKey(&privKey, NULL); if (result == 0) result = RsaPrivateKeyDecode(pkcs7->privateKey, &scratch, &privKey, pkcs7->privateKeySz); if (result < 0) { XFREE(flatSignedAttribs, 0, NULL); return PUBLIC_KEY_E; } result = RsaSSL_Sign(digestInfo, digIdx, esd.encContentDigest, sizeof(esd.encContentDigest), &privKey, pkcs7->rng); FreeRsaKey(&privKey); if (result < 0) { XFREE(flatSignedAttribs, 0, NULL); return result; } esd.encContentDigestSz = (word32)result; } signerInfoSz += flatSignedAttribsSz + esd.signedAttribSetSz; esd.signerDigestSz = SetOctetString(esd.encContentDigestSz, esd.signerDigest); signerInfoSz += esd.signerDigestSz + esd.encContentDigestSz; esd.signerInfoSeqSz = SetSequence(signerInfoSz, esd.signerInfoSeq); signerInfoSz += esd.signerInfoSeqSz; esd.signerInfoSetSz = SetSet(signerInfoSz, esd.signerInfoSet); signerInfoSz += esd.signerInfoSetSz; esd.certsSetSz = SetImplicit(ASN_SET, 0, pkcs7->singleCertSz, esd.certsSet); esd.singleDigAlgoIdSz = SetAlgoID(pkcs7->hashOID, esd.singleDigAlgoId, hashType, 0); esd.digAlgoIdSetSz = SetSet(esd.singleDigAlgoIdSz, esd.digAlgoIdSet); esd.versionSz = SetMyVersion(1, esd.version, 0); totalSz = esd.versionSz + esd.singleDigAlgoIdSz + esd.digAlgoIdSetSz + esd.contentInfoSeqSz + esd.certsSetSz + pkcs7->singleCertSz + esd.innerOctetsSz + esd.innerContSeqSz + innerOidSz + pkcs7->contentSz + signerInfoSz; esd.innerSeqSz = SetSequence(totalSz, esd.innerSeq); totalSz += esd.innerSeqSz; esd.outerContentSz = SetExplicit(0, totalSz, esd.outerContent); totalSz += esd.outerContentSz + outerOidSz; esd.outerSeqSz = SetSequence(totalSz, esd.outerSeq); totalSz += esd.outerSeqSz; if (outputSz < totalSz) return BUFFER_E; idx = 0; XMEMCPY(output + idx, esd.outerSeq, esd.outerSeqSz); idx += esd.outerSeqSz; XMEMCPY(output + idx, outerOid, outerOidSz); idx += outerOidSz; XMEMCPY(output + idx, esd.outerContent, esd.outerContentSz); idx += esd.outerContentSz; XMEMCPY(output + idx, esd.innerSeq, esd.innerSeqSz); idx += esd.innerSeqSz; XMEMCPY(output + idx, esd.version, esd.versionSz); idx += esd.versionSz; XMEMCPY(output + idx, esd.digAlgoIdSet, esd.digAlgoIdSetSz); idx += esd.digAlgoIdSetSz; XMEMCPY(output + idx, esd.singleDigAlgoId, esd.singleDigAlgoIdSz); idx += esd.singleDigAlgoIdSz; XMEMCPY(output + idx, esd.contentInfoSeq, esd.contentInfoSeqSz); idx += esd.contentInfoSeqSz; XMEMCPY(output + idx, innerOid, innerOidSz); idx += innerOidSz; XMEMCPY(output + idx, esd.innerContSeq, esd.innerContSeqSz); idx += esd.innerContSeqSz; XMEMCPY(output + idx, esd.innerOctets, esd.innerOctetsSz); idx += esd.innerOctetsSz; XMEMCPY(output + idx, pkcs7->content, pkcs7->contentSz); idx += pkcs7->contentSz; XMEMCPY(output + idx, esd.certsSet, esd.certsSetSz); idx += esd.certsSetSz; XMEMCPY(output + idx, pkcs7->singleCert, pkcs7->singleCertSz); idx += pkcs7->singleCertSz; XMEMCPY(output + idx, esd.signerInfoSet, esd.signerInfoSetSz); idx += esd.signerInfoSetSz; XMEMCPY(output + idx, esd.signerInfoSeq, esd.signerInfoSeqSz); idx += esd.signerInfoSeqSz; XMEMCPY(output + idx, esd.signerVersion, esd.signerVersionSz); idx += esd.signerVersionSz; XMEMCPY(output + idx, esd.issuerSnSeq, esd.issuerSnSeqSz); idx += esd.issuerSnSeqSz; XMEMCPY(output + idx, esd.issuerName, esd.issuerNameSz); idx += esd.issuerNameSz; XMEMCPY(output + idx, pkcs7->issuer, pkcs7->issuerSz); idx += pkcs7->issuerSz; XMEMCPY(output + idx, esd.issuerSn, esd.issuerSnSz); idx += esd.issuerSnSz; XMEMCPY(output + idx, esd.signerDigAlgoId, esd.signerDigAlgoIdSz); idx += esd.signerDigAlgoIdSz; /* SignerInfo:Attributes */ if (pkcs7->signedAttribsSz != 0) { XMEMCPY(output + idx, esd.signedAttribSet, esd.signedAttribSetSz); idx += esd.signedAttribSetSz; XMEMCPY(output + idx, flatSignedAttribs, flatSignedAttribsSz); idx += flatSignedAttribsSz; XFREE(flatSignedAttribs, 0, NULL); } XMEMCPY(output + idx, esd.digEncAlgoId, esd.digEncAlgoIdSz); idx += esd.digEncAlgoIdSz; XMEMCPY(output + idx, esd.signerDigest, esd.signerDigestSz); idx += esd.signerDigestSz; XMEMCPY(output + idx, esd.encContentDigest, esd.encContentDigestSz); idx += esd.encContentDigestSz; return idx; }
void CDBCard::Load(long msgid, BYTE* msgBuf, long& msgBufPos) { // 解析消息 CDBEntityManager::DBCardMapItr itr = GetGame()->GetDBEntityManager()->GetDBCardMap().find(GetExID()); char szGuid[128]; GetExID().tostring(szGuid); if(itr != GetGame()->GetDBEntityManager()->DBCardMapEnd()) { WORD attrNum = _GetWordFromByteArray(msgBuf, msgBufPos); for(int i=0; i<(int)attrNum; i++) { // add one card data _GetWordFromByteArray(msgBuf, msgBufPos); DB_CARD_ATTR_TYPE attrType = (DB_CARD_ATTR_TYPE)_GetLongFromByteArray(msgBuf, msgBufPos); switch(attrType) { case DB_CARD_ATTR_SZ_CARDNUMBER: { char num[1024]; _GetStringFromByteArray(msgBuf, msgBufPos, num); SetCardNumber(num, strlen(num)); } break; case DB_CARD_ATTR_SZ_CARDTYPE: { char num[1024]; _GetStringFromByteArray(msgBuf, msgBufPos, num); SetCardType(num, strlen(num)); } break; case DB_CARD_ATTR_SZ_SELLERACCOUNT: { char num[1024]; _GetStringFromByteArray(msgBuf, msgBufPos, num); SetSellerAccount(num, strlen(num)); } break; case DB_CARD_ATTR_LONG_SELLERID: { CGUID value; _GetBufferFromByteArray(msgBuf, msgBufPos, value); SetSellerID(value); } break; case DB_CARD_ATTR_SZ_BUYERACCOUNT: { char num[1024]; _GetStringFromByteArray(msgBuf, msgBufPos, num); SetCardNumber(num, strlen(num)); } break; case DB_CARD_ATTR_LONG_BUYERID: { CGUID value; _GetBufferFromByteArray(msgBuf, msgBufPos, value); SetBuyerID(value); } break; case DB_CARD_ATTR_DWORD_PRICE: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetPrice(value); } break; case DB_CARD_ATTR_DWORD_CHARGEPRICE: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetChargePrice(value); } break; case DB_CARD_ATTR_DWORD_CARDSTATE: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetCardState(value); } break; case DB_CARD_ATTR_DWORD_CARDTIME: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetCardTime(value); } break; case DB_CARD_ATTR_DWORD_STARTTIME: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetStartTime(value); } break; case DB_CARD_ATTR_DWORD_SERIALNUMBER: { DWORD value = _GetDwordFromByteArray(msgBuf, msgBufPos); SetSerialNumber(value); } break; } } CCard *pCard = new CCard; if( !pCard) { return; } GetGame()->GetDBEntityManager()->CDBCardToCCard(this, pCard); // 返回0为真。 if( CCardsHandler::getInstance()->InsertCard(pCard) ) { return; } ////AddLogText("DB2W[%d] : DB_OPER_LOAD_CARD, CardID[%s]...OK!", msgid, szGuid); return; } // //AddLogText("DB2W[%d] : DB_OPER_LOAD_CARD, CardID[%s]...FAILED!", msgid, szGuid); }