/** analyze datalink layer (ethernet) **/ jobject analyze_datalink(JNIEnv *env,u_char *data,int linktype){ struct ether_header *ether_hdr; jobject packet; jbyteArray src_addr,dst_addr; #ifdef DEBUG puts("analyze datalink"); #endif switch(linktype){ case DLT_EN10MB: packet=AllocObject(EthernetPacket); src_addr=(*env)->NewByteArray(env,6); dst_addr=(*env)->NewByteArray(env,6); ether_hdr=(struct ether_header *)data; (*env)->SetByteArrayRegion(env,src_addr,0,6,ether_hdr->ether_src); (*env)->SetByteArrayRegion(env,dst_addr,0,6,ether_hdr->ether_dest); (*env)->CallVoidMethod(env,packet,setEthernetValueMID,dst_addr,src_addr, (jchar)ntohs(ether_hdr->ether_type)); DeleteLocalRef(src_addr); DeleteLocalRef(dst_addr); break; default: packet=AllocObject(DatalinkPacket); break; } return packet; }
int CloneObject (CObject *objP) { short nObject, nSegment; int nSignature; CObject *cloneP; if (0 > (nObject = AllocObject ())) return -1; cloneP = OBJECTS + nObject; nSignature = cloneP->info.nSignature; memcpy (cloneP, objP, sizeof (CObject)); cloneP->info.nSignature = nSignature; cloneP->info.nCreator = -1; cloneP->mType.physInfo.thrust.SetZero (); cloneP->SetCreationTime (gameData.time.xGame); nSegment = objP->info.nSegment; cloneP->info.nSegment = cloneP->info.nPrevInSeg = cloneP->info.nNextInSeg = -1; cloneP->InitLinks (); cloneP->SetLinkedType (OBJ_NONE); objP->Link (); objP->LinkToSeg (nSegment); return nObject; }
/** * Initialise a object using a OBJ_INIT structure to supply parameters. * @param pInitTbl Pointer to object initialisation table */ OBJECT *InitObject(const OBJ_INIT *pInitTbl) { // allocate a new object OBJECT *pObj = AllocObject(); // make sure object created assert(pObj != NULL); // set objects shape pObj->hImg = pInitTbl->hObjImg; // set objects ID pObj->oid = pInitTbl->objID; // set objects flags pObj->flags = DMA_CHANGED | pInitTbl->objFlags; // set objects Z position pObj->zPos = pInitTbl->objZ; // get pointer to image if (pInitTbl->hObjImg) { int aniX, aniY; // objects animation offsets PALQ *pPalQ = NULL; // palette queue pointer const IMAGE *pImg = (const IMAGE *)LockMem(pInitTbl->hObjImg); // handle to image if (pImg->hImgPal) { // allocate a palette for this object pPalQ = AllocPalette(FROM_LE_32(pImg->hImgPal)); // make sure palette allocated assert(pPalQ != NULL); } // assign palette to object pObj->pPal = pPalQ; // set objects size pObj->width = FROM_LE_16(pImg->imgWidth); pObj->height = FROM_LE_16(pImg->imgHeight) & ~C16_FLAG_MASK; pObj->flags &= ~C16_FLAG_MASK; pObj->flags |= FROM_LE_16(pImg->imgHeight) & C16_FLAG_MASK; // set objects bitmap definition pObj->hBits = FROM_LE_32(pImg->hImgBits); // get animation offset of object GetAniOffset(pObj->hImg, pInitTbl->objFlags, &aniX, &aniY); // set objects X position - subtract ani offset pObj->xPos = intToFrac(pInitTbl->objX - aniX); // set objects Y position - subtract ani offset pObj->yPos = intToFrac(pInitTbl->objY - aniY); } else { // no image handle - null image // set objects X position pObj->xPos = intToFrac(pInitTbl->objX); // set objects Y position pObj->yPos = intToFrac(pInitTbl->objY); } // return new object return pObj; }
/** * Main text outputting routine. If a object list is specified a * multi-object is created for the whole text and a pointer to the head * of the list is returned. * @param pList Object list to add text to * @param szStr String to output * @param color Color for monochrome text * @param xPos X position of string * @param yPos Y position of string * @param hFont Which font to use * @param mode Mode flags for the string * @param sleepTime Sleep time between each character (if non-zero) */ OBJECT *ObjectTextOut(OBJECT **pList, char *szStr, int color, int xPos, int yPos, SCNHANDLE hFont, int mode, int sleepTime) { int xJustify; // x position of text after justification int yOffset; // offset to next line of text OBJECT *pFirst; // head of multi-object text list OBJECT *pChar = 0; // object ptr for the character byte c; SCNHANDLE hImg; const IMAGE *pImg; // make sure there is a linked list to add text to assert(pList); // get font pointer const FONT *pFont = (const FONT *)LockMem(hFont); // init head of text list pFirst = NULL; // get image for capital W assert(pFont->fontDef[(int)'W']); pImg = (const IMAGE *)LockMem(FROM_32(pFont->fontDef[(int)'W'])); // get height of capital W for offset to next line yOffset = FROM_16(pImg->imgHeight) & ~C16_FLAG_MASK; while (*szStr) { // x justify the text according to the mode flags xJustify = JustifyText(szStr, xPos, pFont, mode); // repeat until end of string or end of line while ((c = *szStr) != EOS_CHAR && c != LF_CHAR) { if (g_bMultiByte) { if (c & 0x80) c = ((c & ~0x80) << 8) + *++szStr; } hImg = FROM_32(pFont->fontDef[c]); if (hImg == 0) { // no image for this character // add font spacing for a space character xJustify += FROM_32(pFont->spaceSize); } else { // printable character int aniX, aniY; // char image animation offsets OBJ_INIT oi; oi.hObjImg = FROM_32(pFont->fontInit.hObjImg); oi.objFlags = FROM_32(pFont->fontInit.objFlags); oi.objID = FROM_32(pFont->fontInit.objID); oi.objX = FROM_32(pFont->fontInit.objX); oi.objY = FROM_32(pFont->fontInit.objY); oi.objZ = FROM_32(pFont->fontInit.objZ); // allocate and init a character object if (pFirst == NULL) // first time - init head of list pFirst = pChar = InitObject(&oi); // FIXME: endian issue using fontInit!!! else // chain to multi-char list pChar = pChar->pSlave = InitObject(&oi); // FIXME: endian issue using fontInit!!! // convert image handle to pointer pImg = (const IMAGE *)LockMem(hImg); // fill in character object pChar->hImg = hImg; // image def pChar->width = FROM_16(pImg->imgWidth); // width of chars bitmap pChar->height = FROM_16(pImg->imgHeight) & ~C16_FLAG_MASK; // height of chars bitmap pChar->hBits = FROM_32(pImg->hImgBits); // bitmap // check for absolute positioning if (mode & TXT_ABSOLUTE) pChar->flags |= DMA_ABS; // set characters color - only effective for mono fonts pChar->constant = color; // get Y animation offset GetAniOffset(hImg, pChar->flags, &aniX, &aniY); // set x position - ignore animation point pChar->xPos = intToFrac(xJustify); // set y position - adjust for animation point pChar->yPos = intToFrac(yPos - aniY); if (mode & TXT_SHADOW) { // we want to shadow the character OBJECT *pShad; // allocate a object for the shadow and chain to multi-char list pShad = pChar->pSlave = AllocObject(); // copy the character for a shadow CopyObject(pShad, pChar); // add shadow offsets to characters position pShad->xPos += intToFrac(FROM_32(pFont->xShadow)); pShad->yPos += intToFrac(FROM_32(pFont->yShadow)); // shadow is behind the character pShad->zPos--; // shadow is always mono pShad->flags = DMA_CNZ | DMA_CHANGED; // check for absolute positioning if (mode & TXT_ABSOLUTE) pShad->flags |= DMA_ABS; // shadow always uses first palette entry // should really alloc a palette here also ???? pShad->constant = 1; // add shadow to object list InsertObject(pList, pShad); } // add character to object list InsertObject(pList, pChar); // move to end of list if (pChar->pSlave) pChar = pChar->pSlave; // add character spacing xJustify += FROM_16(pImg->imgWidth); } // finally add the inter-character spacing xJustify += FROM_32(pFont->xSpacing); // next character in string ++szStr; } // adjust the text y position and add the inter-line spacing yPos += yOffset + FROM_32(pFont->ySpacing); // check for newline if (c == LF_CHAR) // next character in string ++szStr; } // return head of list return pFirst; }
int CreateObject (ubyte nType, ubyte nId, short nCreator, short nSegment, const CFixVector& vPos, const CFixMatrix& mOrient, fix xSize, ubyte cType, ubyte mType, ubyte rType) { short nObject; CObject *objP; #if DBG if (nType == OBJ_WEAPON) { nType = nType; if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_ROBOT)) { nType = nType; if ((nDbgSeg >= 0) && (nSegment == nDbgSeg)) nDbgSeg = nDbgSeg; } if (nId == FLARE_ID) nType = nType; if (gameData.objs.bIsMissile [(int) nId]) nType = nType; } else if (nType == OBJ_ROBOT) { #if 0 if (ROBOTINFO ((int) nId).bossFlag && (BOSS_COUNT >= MAX_BOSS_COUNT)) return -1; #endif } else if (nType == OBJ_HOSTAGE) nType = nType; else if (nType == OBJ_FIREBALL) nType = nType; else if (nType == OBJ_REACTOR) nType = nType; else if (nType == OBJ_DEBRIS) nType = nType; else if (nType == OBJ_MARKER) nType = nType; else if (nType == OBJ_PLAYER) nType = nType; else if (nType == OBJ_POWERUP) { nType = nType; if (nId == POW_MONSTERBALL) nId = nId; } #endif //if (GetSegMasks (vPos, nSegment, 0).m_center)) if (nSegment < -1) nSegment = -nSegment - 2; else nSegment = FindSegByPos (vPos, nSegment, 1, 0); if ((nSegment < 0) || (nSegment > gameData.segs.nLastSegment)) return -1; if (nType == OBJ_DEBRIS) { if (gameData.objs.nDebris >= gameStates.render.detail.nMaxDebrisObjects) return -1; } // Find next free object if (0 > (nObject = AllocObject ())) return -1; objP = OBJECTS + nObject; objP->SetId (nObject); // Zero out object structure to keep weird bugs from happening in uninitialized fields. objP->info.nSignature = gameData.objs.nNextSignature++; objP->info.nType = nType; objP->info.nId = nId; objP->info.vLastPos = objP->info.position.vPos = vPos; objP->SetOrigin (vPos); objP->info.xSize = xSize; objP->info.nCreator = sbyte (nCreator); objP->info.xLifeLeft = IMMORTAL_TIME; if (IsMultiGame && (gameData.app.nGameMode & GM_ENTROPY) && (nType == OBJ_POWERUP) && (nId == POW_ENTROPY_VIRUS)) { if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_PLAYER)) objP->info.nCreator = sbyte (GetTeam (OBJECTS [nCreator].info.nId) + 1); if (extraGameInfo [1].entropy.nVirusLifespan > 0) objP->info.xLifeLeft = I2X (extraGameInfo [1].entropy.nVirusLifespan); } objP->info.position.mOrient = mOrient; objP->info.controlType = cType; objP->info.movementType = mType; objP->info.renderType = rType; objP->info.contains.nType = -1; objP->info.nAttachedObj = -1; if (objP->info.controlType == CT_POWERUP) objP->cType.powerupInfo.nCount = 1; // Init physics info for this CObject if (objP->info.movementType == MT_PHYSICS) objP->SetStartVel ((CFixVector*) &CFixVector::ZERO); if (objP->info.renderType == RT_POLYOBJ) objP->rType.polyObjInfo.nTexOverride = -1; objP->SetCreationTime (gameData.time.xGame); if (objP->info.nType == OBJ_WEAPON) { Assert (objP->info.controlType == CT_WEAPON); objP->mType.physInfo.flags |= WI_persistent (objP->info.nId) * PF_PERSISTENT; objP->cType.laserInfo.xCreationTime = gameData.time.xGame; objP->cType.laserInfo.nLastHitObj = 0; objP->cType.laserInfo.xScale = I2X (1); } else if (objP->info.nType == OBJ_DEBRIS) gameData.objs.nDebris++; if (objP->info.controlType == CT_POWERUP) objP->cType.powerupInfo.xCreationTime = gameData.time.xGame; else if (objP->info.controlType == CT_EXPLOSION) objP->cType.explInfo.attached.nNext = objP->cType.explInfo.attached.nPrev = objP->cType.explInfo.attached.nParent = -1; objP->Link (); objP->LinkToSeg (nSegment); memset (&objP->HitInfo (), 0, sizeof (CObjHitInfo)); #if 1 if (IsMultiGame && IsCoopGame && (nType == OBJ_WEAPON) && gameData.objs.bIsMissile [int (nId)] && (nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_PLAYER)) { extern char powerupToObject [MAX_POWERUP_TYPES]; for (int i = 0; i < MAX_POWERUP_TYPES; i++) { if (powerupToObject [i] == nId) gameData.multiplayer.maxPowerupsAllowed [i]--; } } #endif OBJECTS [nObject].ResetDamage (); OBJECTS [nObject].SetTarget (NULL); return nObject; }
CK_RV PKCS11_Objects_OpenSSL::LoadX509Cert(Cryptoki_Session_Context* pSessionCtx, X509* x, OBJECT_DATA** ppObject, EVP_PKEY* privateKey, CK_OBJECT_HANDLE_PTR phObject) { CERT_DATA* pCert; EVP_PKEY* pubKey = X509_get_pubkey(x); UINT32 keyType = CKK_VENDOR_DEFINED; if(phObject == NULL) return CKR_ARGUMENTS_BAD; *phObject = AllocObject(pSessionCtx, CertificateType, sizeof(CERT_DATA), ppObject); if(*phObject == CK_OBJECT_HANDLE_INVALID) { return CKR_FUNCTION_FAILED; } if(pubKey != NULL) { switch(pubKey->type) { case EVP_PKEY_RSA: case EVP_PKEY_RSA2: keyType = CKK_RSA; break; case EVP_PKEY_DSA: case EVP_PKEY_DSA1: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: case EVP_PKEY_DSA4: keyType = CKK_DSA; break; case EVP_PKEY_DH: keyType = CKK_DH; break; case EVP_PKEY_EC: keyType = CKK_DH; break; } } pCert = (CERT_DATA*)(*ppObject)->Data; pCert->cert = x; pCert->privKeyData.key = privateKey; if(privateKey != NULL) { pCert->privKeyData.attrib = Private; pCert->privKeyData.type = keyType; pCert->privKeyData.size = EVP_PKEY_bits(privateKey); } pCert->pubKeyData.key = pubKey; pCert->pubKeyData.attrib = Public; pCert->pubKeyData.type = keyType; pCert->pubKeyData.size = EVP_PKEY_bits(pubKey); return CKR_OK; }