Пример #1
0
void GenerateModulus(unsigned long * P, unsigned long * Q)
{
	while(1)
	{
		if (!IsPrime(*P) || *P == 0|| *P == *Q )
			*P = (unsigned long)GenerateRandomNumber(MIN,MAX);
		if (!IsPrime(*Q) || *Q == 0)
			*Q = (unsigned long)GenerateRandomNumber(MIN,MAX);
		if (IsPrime(*P) && IsPrime(*Q) && *Q != *P)
			break;
	}
}
Пример #2
0
/**
 * @fn unsigned long CreateRandomAddress(void)
 *
 * @brief This function creates a random address for the node ID. 
 *
 * @return an unsigned long
 */
unsigned long CreateRandomAddress(void)
{
  unsigned int  tempRandom1,tempRandom2;
  unsigned long randomNum = 0;

  while ((randomNum == 0x00000000) || (randomNum == 0xFFFFFFFF))
  {
    tempRandom1 = GenerateRandomNumber();
    tempRandom2 = GenerateRandomNumber();
    randomNum = ((long)tempRandom1 << 16) | tempRandom2;                        // Create a 32 bit random number using 2 16-bit random numbers.
  }
  return randomNum;
}
Пример #3
0
void base_tetrix_scene::StartGame()
{
	ClearSceneContext(m_pcontext_freeze);
	ClearSceneContext(m_pcontext_activity);
	//BlockFactory();
	m_i_current_block_index = GenerateRandomNumber( 0, 4);

	m_pblock->initblock(m_pcontext_freeze->pSceneData, 
						m_pcontext_freeze->b_x_size,
						m_pcontext_freeze->b_y_size,
						(block_category)m_i_current_block_index);
	m_i_next_block_index = GenerateRandomNumber( 0, 4);
	m_pblock->draw(m_pcontext_activity);
}
Пример #4
0
__INLINE__ __byte __INTERNAL_FUNC__ RandJmpCode() {
	__byte bCode = 0;
	__integer iIndex = 0;
	iIndex = GenerateRandomNumber() % __MAX_JMPINSTR_NUM__;
	bCode = g_JmpCode[iIndex];
	return bCode;
}
Пример #5
0
/* Generate Pink noise values between -1.0 and +1.0 */
float GeneratePinkNoise( PinkNoise *pink )
{
    long newRandom;
    long sum;
    float output;
    /* Increment and mask index. */
    pink->pink_Index = (pink->pink_Index + 1) & pink->pink_IndexMask;
    /* If index is zero, don't update any random values. */
    if( pink->pink_Index != 0 )
    {
        /* Determine how many trailing zeros in PinkIndex. */
        /* This algorithm will hang if n==0 so test first. */
        int numZeros = 0;
        int n = pink->pink_Index;
        while( (n & 1) == 0 )
        {
            n = n >> 1;
            numZeros++;
        }
        /* Replace the indexed ROWS random value.
         * Subtract and add back to RunningSum instead of adding all the random
         * values together. Only one changes each time.
         */
        pink->pink_RunningSum -= pink->pink_Rows[numZeros];
        newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT;
        pink->pink_RunningSum += newRandom;
        pink->pink_Rows[numZeros] = newRandom;
    }
Пример #6
0
__INLINE__ __byte __INTERNAL_FUNC__ RandOneByteInst() {
	__byte bCode = 0;
	__integer iIndex = 0;
	iIndex = GenerateRandomNumber() % __MAX_ONE_BYTE_INSTRUCTION__;
	bCode = g_OneByteInstruction[iIndex];
	return bCode;
}
Пример #7
0
int CUniformRandomStream::_RandomInt( int iLow, int iHigh )
{
	//ASSERT(lLow <= lHigh);
	unsigned int maxAcceptable;
	unsigned int x = iHigh-iLow+1;
	unsigned int n;
	if (x <= 1 || MAX_RANDOM_RANGE < x-1)
	{
		return iLow;
	}

	// The following maps a uniform distribution on the interval [0,MAX_RANDOM_RANGE]
	// to a smaller, client-specified range of [0,x-1] in a way that doesn't bias
	// the uniform distribution unfavorably. Even for a worst case x, the loop is
	// guaranteed to be taken no more than half the time, so for that worst case x,
	// the average number of times through the loop is 2. For cases where x is
	// much smaller than MAX_RANDOM_RANGE, the average number of times through the
	// loop is very close to 1.
	//
	maxAcceptable = MAX_RANDOM_RANGE - ((MAX_RANDOM_RANGE+1) % x );
	do
	{
		n = GenerateRandomNumber();
	} while (n > maxAcceptable);

	return iLow + (n % x);
}
Пример #8
0
__INLINE__ __word __INTERNAL_FUNC__ RandTwoByteInst() {
	__word wCode = 0;
	__integer iIndex = 0;
	iIndex = GenerateRandomNumber() % __MAX_TWO_BYTE_INSTRUCTION__;
	wCode = g_TwoByteInstruction[iIndex];
	return wCode;
}
Пример #9
0
instanceInfo *CreateInstance(int length)
{
  instanceInfo *pInstance = calloc(sizeof(instanceInfo));
  pInstance->name = GenerateRandomString(length);
  pInstance->port = GenerateRandomNumber(0, 65535);
  pInstance->adminPortOffset = GetNextAdminPort();
  return pInstance;
}
Пример #10
0
float CUniformRandomStream::RandomFloat( float flLow, float flHigh )
{
	// float in [0,1)
	float fl = (float)(AM * GenerateRandomNumber());
	if (fl > RNMX) 
		fl = (float)RNMX;

	return (fl * (flHigh-flLow)) + flLow; // float in [low,high)
}
Пример #11
0
void InitializeSimulation() 
{
  adminPortOffset = 0;
  serverList = NewList(LIST_SERVER);
  // Create Servers
  int numServers = GenerateRandomNumber(10,32);
  int nameLength = GenerateRandomNumber(34, 64);
  for (int i=0; i<numServers; i++) 
  {
    serverInfo *server = CreateServer(nameLength - i);
    AddToList(serverList, server, LIST_SERVER);
    // Create and link instances to servers
    int numInstances = GenerateRandomNumber(1, 15);
    int instanceLength = GenerateRandomNumber(32, 64);
    for(int j=0; j<numInstances; j++) 
    {
      instanceInfo *instance = CreateInstance(instanceLength - j);
      AddInstanceToServer(server, instance);
    }
  }
}
Пример #12
0
void daKoopaThrow::beginState_Straight() {
	float rand = (float)GenerateRandomNumber(10) * 0.4;

	if (this->direction == 0) { // directions 1 spins clockwise, fly rightwards
		speed.x = 1.5 + rand;
	}
	else {						// directions 0 spins anti-clockwise, fly leftwards
		speed.x = -1.5 - rand;
	}

	speed.y = 9.0;
}
Пример #13
0
void daWrench::beginState_Kaboom() {
	float rand = (float)GenerateRandomNumber(10) * 0.4;

	if (this->direction == 0) { // directions 1 spins clockwise, fly rightwards
		speed.x = 1.0 + rand;
	}
	else {						// directions 0 spins anti-clockwise, fly leftwards
		speed.x = -1.0 - rand;
	}

	speed.y = 6.0;
}
Пример #14
0
	void daBalboa_c::beginState_ManholeUp() {

		bindAnimChr_and_setUpdateRate("throw_1", 1, 0.0, 1.0);

		this->timer = 0;

		int randChoice;
		randChoice = GenerateRandomNumber(3);

		this->pos = this->PopUp[randChoice];



		if 		(randChoice == 0) { // On the left side!
			this->rot.y = 0xE000;
			this->rot.z = 0;
			this->upsideDown = 0;
			this->direction = 0; }

		else if (randChoice == 1) {	// On the right side!
			this->rot.y = 0x2000;
			this->rot.z = 0;
			this->upsideDown = 0;
			this->direction = 1; }

		// else if (randChoice == 2) {	// On the right ceiling!
		// 	this->rot.y = 0xE000;
		// 	this->rot.z = 0x8000;
		// 	this->upsideDown = 1;
		// 	this->direction = 0; }

		// else if (randChoice == 3) {	// On the left ceiling!
		// 	this->rot.y = 0x2000;
		// 	this->rot.z = 0x8000;
		// 	this->upsideDown = 1;
		// 	this->direction = 1; }

		else if (randChoice == 2) {	// In the Center!
			char Pdir = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos);

			if (Pdir == 1) {
				this->rot.y = 0xE000;
				this->direction = 0; }
			else {
				this->rot.y = 0x2000;
				this->direction = 1; }
		}

		PlaySound(this, 0x21F);
	}
Пример #15
0
__integer __INTERNAL_FUNC__ PowerProtecterGetJmpThunkCode(__memory pOutBuffer, __integer iThunkCodeSize) {
	__integer iSize = 0;
	switch (iThunkCodeSize) {
	case 1:{//JCC
		iSize = 1;
		*(__byte *)pOutBuffer = RandJmpCode();
		   }break;
	case 2:{//JCC OFFSET_8BITS
		iSize = 2;
		*(__byte *)pOutBuffer = RandJmpCode();
		*(__byte *)(pOutBuffer + 1) = (__byte)(GenerateRandomNumber() % 0x20);
		   }break;
	case 3:{//JCC OFFSET_8BITS; OneByteInst
		iSize = 3;
		*(__byte *)pOutBuffer = RandJmpCode();
		*(__byte *)(pOutBuffer + 1) = (__byte)(GenerateRandomNumber() % 0x20);
		*(__byte *)(pOutBuffer + 2) = RandOneByteInst();
		   }break;
	case 4:{//JCC OFFSET_8BITS; TwoByteInst
		iSize = 4;
		*(__byte *)pOutBuffer = RandJmpCode();
		*(__byte *)(pOutBuffer + 1) = (__byte)(GenerateRandomNumber() % 0x20);
		*(__word *)(pOutBuffer + 2) = RandTwoByteInst();
		   }break;
	case 5:{//JCC OFFSET_8BITS; TwoByteInst; JCC
		iSize = 5;
		*(__byte *)pOutBuffer = RandJmpCode();
		*(__byte *)(pOutBuffer + 1) = (__byte)(GenerateRandomNumber() % 0x20);
		*(__word *)(pOutBuffer + 2) = RandTwoByteInst();
		*(__byte *)(pOutBuffer + 4) = RandJmpCode();
		   }break;
	case 6:{//JCC OFFSET_8BITS; TwoByteInst; JCC OFFSET_8BITS
		iSize = 6;
		*(__byte *)pOutBuffer = RandJmpCode();
		*(__byte *)(pOutBuffer + 1) = (__byte)(GenerateRandomNumber() % 0x20);
		*(__word *)(pOutBuffer + 2) = RandTwoByteInst();
		*(__byte *)(pOutBuffer + 4) = RandJmpCode();
		*(__byte *)(pOutBuffer + 5) = (__byte)(GenerateRandomNumber() % 0x20);
		   }break;
	}
	return iSize;
}
Пример #16
0
        {
            n = n >> 1;
            numZeros++;
        }
        /* Replace the indexed ROWS random value.
         * Subtract and add back to RunningSum instead of adding all the random
         * values together. Only one changes each time.
         */
        pink->pink_RunningSum -= pink->pink_Rows[numZeros];
        newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT;
        pink->pink_RunningSum += newRandom;
        pink->pink_Rows[numZeros] = newRandom;
    }

    /* Add extra white noise value. */
    newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT;
    sum = pink->pink_RunningSum + newRandom;
    /* Scale to range of -1.0 to 0.9999. */
    output = pink->pink_Scalar * sum;
    return output;
}

float ProcessBiquad(const BiQuad* coeffs, float* memory, float input)
{
    float w = input - coeffs->bq_a1 * memory[0] - coeffs->bq_a2 * memory[1];
    float out = coeffs->bq_b1 * memory[0] + coeffs->bq_b2 * memory[1] + coeffs->bq_b0 * w;
    memory[1] = memory[0];
    memory[0] = w;
    return out;
}
Пример #17
0
void daFuzzyBear_c::executeState_Bounce() {

	float wallDistance, scaleDown, scaleUp, scaleBase;

	if (BigBossFuzzyBear == 0) {
		wallDistance = 32.0;
		scaleDown = 24.0;
		scaleUp = 10.0;
		scaleBase = 2.5;
	}
	else {
		wallDistance = 38.0;
		scaleDown = 32.0;
		scaleUp = 12.0;
		scaleBase = 3.0;
	}


	if (this->falldown == 1) { this->speed.x = 0; this->timer = 0; }


	// Check for walls

	if (this->pos.x <= this->initialPos.x - ((17 * 16.0) + wallDistance))  { // Hit left wall, head right.
		this->speed.x = -this->speed.x;
		this->direction = 1;
		this->pos.x = this->pos.x + 1.0; }

	if (this->pos.x >= this->initialPos.x + ((7.5 * 16.0) - wallDistance))  { // Hit right wall, head left.
		this->speed.x = -this->speed.x;
		this->direction = 0;
		this->pos.x = this->pos.x - 1.0; }


	// Check if we're on the ground.

	if (this->pos.y < this->Baseline) {

		this->falldown = 0;

		this->timer = this->timer + 1;
		if (this->speed.x != 0) {
			this->storeSpeed = this->speed.x; }
		this->speed.x = 0;
		this->speed.y = 0;


		if (this->timer < 10) {
			float modifier;
			modifier = scaleBase - (this->timer * 0.1);

			this->scale.y = modifier;
			this->pos.y = this->pos.y + (scaleDown/10.0);
			if (this->pos.y > this->Baseline) { this->pos.y = this->Baseline - 1.0; }
		}
		else if (this->timer == 10) {
			Vec tempPos = (Vec){this->pos.x, this->pos.y - wallDistance, 5500.0};
			S16Vec nullRot = {0,0,0};
			Vec oneVec = {1.0f, 1.0f, 1.0f};
			SpawnEffect("Wm_mr_beachlandsmk", 0, &tempPos, &nullRot, &oneVec);
		}
		else {
			float modifier;
			modifier = (scaleBase - 1.0) + ((this->timer - 10) * 0.1);

			this->scale.y = modifier;
			this->pos.y = this->pos.y + (scaleUp/10.0);
			if (this->pos.y > this->Baseline) { this->pos.y = this->Baseline - 1.0; }
			PlaySound(this, SE_PLY_JUMPDAI);
		}

		if (this->timer > 20) {

			int randChoice;

			randChoice = GenerateRandomNumber(5);
			if (randChoice == 0) { doStateChange(&StateID_Wait); }

			randChoice = GenerateRandomNumber(4);
			if (randChoice == 0) { this->speed.y = 8.0; }
			else { this->speed.y = 6.0; }

			this->timer = 0;
			this->pos.y = this->Baseline + 1;

			this->speed.x = this->storeSpeed;
		 }
	}

	else { this->speed.y = this->speed.y - 0.1; } // Gravity


	this->HandleXSpeed();
	this->HandleYSpeed();

	this->UpdateObjectPosBasedOnSpeedValuesReal();

}
Пример #18
0
/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
*/
static int patestCallback( const void *inputBuffer, void *outputBuffer,
                           unsigned long framesPerBuffer,
                           const PaStreamCallbackTimeInfo *timeInfo,
                           PaStreamCallbackFlags statusFlags, void *userData )
{
    /* Cast data passed through stream to our structure. */
    paTestData *data = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    unsigned int i;
    (void) inputBuffer;

    data->latency = timeInfo->outputBufferDacTime - timeInfo->currentTime;

    for( i=0; i<framesPerBuffer; i++ )
    {
        switch( data->state )
        {
        case STATE_BKG_IDLE:
            /* Schedule beep at some random time in the future. */
            if( data->requestBeep )
            {
                int random = GenerateRandomNumber() >> 14;
                data->beepTime = timeInfo->outputBufferDacTime + (( (double)(random + SAMPLE_RATE)) * SAMPLE_PERIOD );
                data->state = STATE_BKG_PENDING;
            }
            *out++ = 0.0;  /* left */
            *out++ = 0.0;  /* right */
            break;

        case STATE_BKG_PENDING:
            if( (timeInfo->outputBufferDacTime + (i*SAMPLE_PERIOD)) >= data->beepTime )
            {
                data->state = STATE_BKG_BEEPING;
                data->beepCount = BEEP_DURATION;
                data->left_phase = data->right_phase = 0.0;
            }
            *out++ = 0.0;  /* left */
            *out++ = 0.0;  /* right */
            break;

        case STATE_BKG_BEEPING:
            if( data->beepCount <= 0 )
            {
                data->state = STATE_BKG_IDLE;
                data->requestBeep = 0;
                *out++ = 0.0;  /* left */
                *out++ = 0.0;  /* right */
            }
            else
            {
                /* Play sawtooth wave. */
                *out++ = data->left_phase;  /* left */
                *out++ = data->right_phase;  /* right */
                /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */
                data->left_phase += 0.01f;
                /* When signal reaches top, drop back down. */
                if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f;
                /* higher pitch so we can distinguish left and right. */
                data->right_phase += 0.03f;
                if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f;
            }
            data->beepCount -= 1;
            break;

        default:
            data->state = STATE_BKG_IDLE;
            break;
        }
    }
Пример #19
0
__byte __INTERNAL_FUNC__ PowerProtecterRandGetExceptionInst() {
	__dword dwRand;
	dwRand = GenerateRandomNumber() % __MAX_EXCEPTIONINSTR_NUM__;
	return (__byte)(g_ExceptionInstrTable[dwRand]);
}
Пример #20
0
int main(void)
{
        int s;          /* This end of connection*/
        int len;        /* length of sockaddr */
        int nread;      /* return from read() */
        int nready;     /* # fd's ready. */
        int maxfd;      /* fd's 0 to maxfd-1 checked. */ 
        char buf[1024]; /* buffer from server */
		char buf1[1024]; /* buffer from client */
        fd_set fds;     /* set of file descriptors to check. */
        struct sockaddr_un name;
		int arrTicketNum[10];  /* array store ticket number received from server */
		int n;           /* status from read and write */


        if( (s = socket(AF_UNIX, SOCK_STREAM, 0) ) < 0){
                perror("socket");
                exit(1);
        }

		/*Create the address of the server.*/

        memset(&name, 0, sizeof(struct sockaddr_un));

        name.sun_family = AF_UNIX;
        strcpy(name.sun_path, SOCKETNAME);
        len = sizeof(name.sun_family) + strlen(name.sun_path);


        /*Connect to the server.*/

        if (connect(s, (struct sockaddr *) &name, len) < 0){
                perror("connect");
                exit(1);
        }

		/* Initialize array of ticket number */
		int i;
		for (i = 0; i < 10; i++)
			{
			arrTicketNum[i] = 0;
			}

		/* used for generate random number */
		srand((unsigned)time(0));

        /* generate a random 5 digit number to cancel invalid ticket at first */
		int ticketNumber;
		
		/* generate 7 Buy commands and 1 cancel randomly*/
		for (i = 0; i < 8; i ++)
			{
			int randomNum;
			randomNum = GenerateRandomNumber(0, 9);
			if (randomNum > 0) //send buy commmand
				{
				bzero(buf1,256);
				sprintf(buf1, "%s", BUY_COMMAND);
				printf("[Client 2:] %s\n",buf1);
				n = write(s,buf1,strlen(buf1));

				/* print out response from server */
				bzero(buf,256);
				n = read(s,buf,255);
				if (n < 0) 
						error("ERROR reading from socket");

				//printf("[Client 2:] %s\n",buf1);

				printf("[Server:] %s\n",buf);
				ticketNumber = atoi(buf);
				/* save ticket number to array */
				UpdateTicketNumber(ticketNumber, arrTicketNum,1);
				}
			else if (randomNum <= 3) 
				{
				/* cancel a ticket number got from list */
				ticketNumber = GetAvailableTicket(arrTicketNum);
				/* send valid cancel ticket */
				bzero(buf1,256);
				sprintf(buf1, "Cancel %d", ticketNumber);
				printf("[Client 1:] %s\n",buf1);
				n = write(s,buf1,strlen(buf1));

				/* print out response from server */
				bzero(buf,256);
				n = read(s,buf,255);
				if (n < 0) 
						error("ERROR reading from socket");

				//printf("[Client 2:] %s\n",buf1);
				printf("[Server:] %s\n",buf);
				UpdateTicketNumber(ticketNumber, arrTicketNum, 0);
				}
		}

		

		/* send out wrong command */
		bzero(buf1,256);
		sprintf(buf1, "%s", "Send Wrong Command");						
		n = write(s,buf1,strlen(buf1));
		printf("[Client 2:] %s\n",buf1);
		/* print out response from server */
		bzero(buf,256);
		n = read(s,buf,255);
		if (n < 0) 
				error("ERROR reading from socket");		
		printf("[Server:] %s\n",buf);

		/* print out ticket table */
		printf("Print out All Buy Tickets from this Client \n");
		for (i = 0; i < 10; i++)
		{
		if (arrTicketNum[i] != 0)
			{
			printf("Ticket %d: %d\n", i, arrTicketNum[i]);
			}
		}
	
	//	/* wait for a while to ensure that server is ready to exit */
		for (i = 0; i < 99999999; i++)
			;
	close(s);
    return 0;
}
Пример #21
0
/*
 * 参数:
 *	pMem:被保护程序的文件映射
 *	pud_obj:反汇编结构
 *	ofProcMemRVA:函数的内存RVA
 *	iProcSize:函数的长度
 *	pInstruction:要加密的指令
 *	pEncryptInstruction:加密指令的结构的指针(写入点)
 *
 * 介绍:
 *	加密指定的指令
 */
__INLINE__ __void __INTERNAL_FUNC__ PowerProtectThisInstruction(__memory pMem, ud_t *pud_obj, __offset ofProcMemRVA, __integer iProcSize, \
	PPOWER_PROTECTER_INSTRUCTION pInstruction, PPOWER_PROTECTER_ENCRYPT_INSTRUCTION pEncryptInstruction) {
	__memory pFileAddress = NULL;
	__integer iInstLength = 0;
	__offset ofRVA = 0;
	POWER_PROTECTER_FLOW_TYPE JmpType = PPFT_NONE;
	__offset ofProcEndMemRVA = 0;

	// 计算出函数的结尾
	ofProcEndMemRVA = ofProcMemRVA + iProcSize;

	iInstLength = pud_obj->inp_ctr;
	pFileAddress = pud_obj->inp_buff;
	pFileAddress -= iInstLength;

	// 设置基本信息
	pEncryptInstruction->ofMemRVA = pInstruction->Instruction.ofMemRVA;
	ofRVA = pEncryptInstruction->ofMemRVA;

	// 获取这条指令的类型
	JmpType = IsFlowInstructionByOffset(pud_obj);

	/*
	 * 这里是流程与非流程指令公用的设置部分
	 */

	// 设置这条指令的跳转类型
	pEncryptInstruction->JmpType = JmpType;

	// 指令长度
	pEncryptInstruction->iInstLen = iInstLength;

	// 如果这条指令是偏移跳转指令
	if (JmpType != PPFT_NONE) {

		// 如果是流程指令直接进行异常处理
		if (iInstLength == 1) {
			*(__byte *)pFileAddress = PowerProtecterRandGetExceptionInst();
		} else {
			__integer iRemainSize = 0;
			*(__byte *)pFileAddress = PowerProtecterRandGetExceptionInst();
			iRemainSize = iInstLength - 1;
			PowerProtecterGetJmpThunkCode(pFileAddress + 1, iRemainSize);
		}

		// 如果是返回指令
		if (JmpType == PPFT_RET) {
			// 记录要返回的参数个数
			pEncryptInstruction->iRetSize = pud_obj->operand[0].lval.udword;//记录它的参数长度
			pEncryptInstruction->bOut = TRUE;
			pEncryptInstruction->ofTargetMemRVA = 0;//RET指令的目标地址为0
		} else {
			// 计算他们的目的地址
			__offset ofTargetRVA = 0;
			__offset ofOffset = 0;
			ofOffset = pud_obj->operand[0].lval.udword;
			if (pud_obj->operand[0].size == 8) {
				__byte bOffset = 0;
				bOffset = pud_obj->operand[0].lval.ubyte;
				if (__IsNegative8__(bOffset)) {
					ofTargetRVA = (__offset)CalcTargetAddress(8, (__address)ofRVA, bOffset, iInstLength, TRUE);
				} else {
					ofTargetRVA = (__offset)CalcTargetAddress(8, (__address)ofRVA, bOffset, iInstLength, FALSE);
				}
			} else if (pud_obj->operand[0].size == 16) {
				__word wOffset = 0;
				wOffset = pud_obj->operand[0].lval.uword;
				if (__IsNegative16__(wOffset)) {
					ofTargetRVA = (__offset)CalcTargetAddress(16, (__address)ofRVA, wOffset, iInstLength, TRUE);
				} else {
					ofTargetRVA = (__offset)CalcTargetAddress(16, (__address)ofRVA, wOffset, iInstLength, FALSE);
				}
			} else if (pud_obj->operand[0].size == 32) {
				__dword dwOffset = 0;
				dwOffset = pud_obj->operand[0].lval.udword;
				if (__IsNegative32__(dwOffset)) {
					ofTargetRVA = (__offset)CalcTargetAddress(32, (__address)ofRVA, dwOffset, iInstLength, TRUE);
				} else {
					ofTargetRVA = (__offset)CalcTargetAddress(32, (__address)ofRVA, dwOffset, iInstLength, FALSE);
				}
			}
			// 检测是否跳出函数
			if (IsJmpGotoOut(ofProcMemRVA, ofProcEndMemRVA, ofTargetRVA)) {
				if (JmpType == PPFT_CALL)//CALL指令不属于向外部跳转的指令
					pEncryptInstruction->bOut = FALSE;
				else
					pEncryptInstruction->bOut = TRUE;
			} else 
				pEncryptInstruction->bOut = FALSE;

			// 设置目的地址
			pEncryptInstruction->ofTargetMemRVA = ofTargetRVA;
		}/* end else */
	} else {
		// 这些是非流程指令
		// 保存这条指令
		__logic_memset__(pEncryptInstruction->InstBuf, 0x90, __POWER_PROTECTER_MAX_INSTRUCTION_BUFFER_SIZE__);
		__logic_memcpy__(pEncryptInstruction->InstBuf, pFileAddress, iInstLength);

		// 这条指令是否有监视的内存地址
		if (pInstruction->bWatched) {
			__memory pWatchFileAddress = NULL;
			__integer iWatchSize = 0;
			__dword dwKey = 0;

			pEncryptInstruction->bIsWatched = TRUE;
			pEncryptInstruction->WatchRecord.ofMemRVA = pInstruction->WatchRecord.ofMemRVA;
			pEncryptInstruction->WatchRecord.iSize = pInstruction->WatchRecord.iSize;

			pWatchFileAddress = pMem + Rva2Raw(pMem, pEncryptInstruction->WatchRecord.ofMemRVA);
			iWatchSize = pEncryptInstruction->WatchRecord.iSize;

			// 计算监视内存的Key
			dwKey = crc32(pWatchFileAddress, iWatchSize);
			XorArray(dwKey, pEncryptInstruction->InstBuf, pEncryptInstruction->InstBuf, iInstLength);

		} else {
			// 使用默认的KEY进行加密
			__dword dwKey = 0;

			pEncryptInstruction->bIsWatched = FALSE;
			dwKey = GenerateRandomNumber();//随机产生密钥
			XorArray(dwKey, pEncryptInstruction->InstBuf, pEncryptInstruction->InstBuf, iInstLength);
			pEncryptInstruction->dwKey = dwKey;//设置密钥
		}

		// 非流程指令,在最后在异常指令
		if (iInstLength == 1) {
			*(__byte *)pFileAddress = PowerProtecterRandGetExceptionInst();
		} else {
			__integer iRemainSize = 0;
			*(__byte *)pFileAddress = PowerProtecterRandGetExceptionInst();
			iRemainSize = iInstLength - 1;
			PowerProtecterGetJmpThunkCode(pFileAddress + 1, iRemainSize);
		}

		pEncryptInstruction->bOut = FALSE;//无跳转
	}/* end else */
}
/**
 * Generates a random rgb color value. Values for rgb are in the range
 * [0,1]
 */
void mitk::LabeledImageLookupTable::GenerateRandomColor ( vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b )
{
  r = GenerateRandomNumber();
  g = GenerateRandomNumber();
  b = GenerateRandomNumber();
}
/**
 * Generates a random rgb color value. Values for rgb are in the range
 * [0,1]
 */
void mitk::LabeledImageLookupTable::GenerateRandomColor(double &r, double &g, double &b)
{
  r = GenerateRandomNumber();
  g = GenerateRandomNumber();
  b = GenerateRandomNumber();
}