Exemplo n.º 1
0
Arquivo: sgutil.c Projeto: rwgk/sglite
int SgOpsCmp(const T_SgOps *t, const T_SgOps *s)
{
  int  c;

  if (t->NoExpand < s->NoExpand) return -1;
  if (t->NoExpand > s->NoExpand) return  1;

  if (t->nLSL < s->nLSL) return -1;
  if (t->nLSL > s->nLSL) return  1;

  if (t->nSSL < s->nSSL) return -1;
  if (t->nSSL > s->nSSL) return  1;

  if (t->nLTr < s->nLTr) return -1;
  if (t->nLTr > s->nLTr) return  1;

  if (t->fInv < s->fInv) return -1;
  if (t->fInv > s->fInv) return  1;

  if (t->nSMx < s->nSMx) return -1;
  if (t->nSMx > s->nSMx) return  1;

  c = MemCmp(t->LTr, s->LTr, SgOps_mLTr);
  if (c) return c;

  c = MemCmp(t->InvT, s->InvT, 3);
  if (c) return c;

  return MemCmp(t->SMx, s->SMx, SgOps_mSMx);
}
Exemplo n.º 2
0
static const wchar *ParseRegistryFileName(const wchar *fname, win::HKEY &root, wchar path[MAX_PATH]){

   assert(*fname==':');
   ++fname;
   root = 0;
   if(!MemCmp(fname, L"HKLM\\", 10))
      //root = HKEY_LOCAL_MACHINE;
      root = (win::HKEY)(win::ULONG_PTR)((win::LONG)0x80000002);
   else
   if(!MemCmp(fname, L"HKCU\\", 10))
      //root = HKEY_CURRENT_USER;
      root = (win::HKEY)(win::ULONG_PTR)((win::LONG)0x80000001);
   else
   if(!MemCmp(fname, L"HKCR\\", 10))
      //root = HKEY_CLASSES_ROOT;
      root = (win::HKEY)(win::ULONG_PTR)((win::LONG)0x80000000);
   else
      return NULL;
   fname += 5;
   const wchar *value = wcsrchr(fname, '\\');
   if(!value)
      return NULL;
   int i = 0;
   while(fname < value)
      path[i++] = *fname++;
   path[i] = 0;
   ++value;
   return value;
}
Exemplo n.º 3
0
// Function compares Boards
char boardEquals(board_p a, board_p b)
{
    if (!a || !b)
        return 0;
    if (a == b)
        return 1;

    if (a->width != b->width)
        return 0;
    if (a->height != b->height)
        return 0;

    if (a->state != b->state)
        return 0;

    if (a->round != b->round)
        return 0;
    if (a->score != b->score)
        return 0;

    if (a->progress != b->progress)
        return 0;
    if (a->goal != b->goal)
        return 0;

    return 0 == MemCmp(a->board, b->board,
                       sizeof(a->board));
};
Exemplo n.º 4
0
/// <summary>
/// Answer whether two strings are equal, i.e., of the same length and containing the same bytes.
/// </summary>
/// <param name="str">The first string to compare.</param>
/// <param name="other">The second string to compare.</param>
/// <returns>True if they are equal, False if they are not of the same length or contain different bytes.</returns>
Bool String_Equals(const String str, const String other)
{
	const struct StringInt *a = (const struct StringInt *)str;
	const struct StringInt *b = (const struct StringInt *)other;
	const Byte *aText, *bText;

	if (a == b) return True;

	if (a == NULL) return b != NULL;
	if (b == NULL) return False;

	if (a->length != b->length) return False;

	aText = a->text;
	bText = b->text;

	switch (a->length)
	{
		case 0: return True;
		case 1: return aText[0] == bText[0];
		case 2: return aText[0] == bText[0] && aText[1] == bText[1];
		case 3: return aText[0] == bText[0] && aText[1] == bText[1] && aText[2] == bText[2];
		case 4: return aText[0] == bText[0] && aText[1] == bText[1] && aText[2] == bText[2] && aText[3] == bText[3];

		default:
			return MemCmp(aText, bText, a->length) == 0;
	}
}
Exemplo n.º 5
0
/// <summary>
/// Assert that the given string is a valid string and matches the given text and length.
/// This will fail the current unit test if this string does not match.
/// </summary>
/// <param name="str">The string to validate.</param>
/// <param name="expectedString">The expected contents of that string.</param>
/// <param name="expectedLength">The expected length of that string.</param>
/// <param name="message">A message to display to the user to explain why the test failed.</param>
/// <param name="file">The file in which a failure would be considered to have occured.</param>
/// <param name="line">The line at which a failure would be considered to have occured.</param>
void AssertStringWithLineInternal(String str, const char *expectedString, Int expectedLength, const char *message, const char *file, int line)
{
	char buffer[1024];

	if (str == NULL) {
		sprintf(buffer, "%s: actual string is a NULL pointer", message);
		FailTestWithLineInternal(buffer, file, line);
	}

	if (String_Length(str) != expectedLength) {
		sprintf(buffer, "%s: actual string length is %d", message, (int)String_Length(str));
		FailTestWithLineInternal(buffer, file, line);
	}

	if (String_GetBytes(str)[expectedLength] != '\0') {
		sprintf(buffer, "%s: actual string is missing '\\0' after end", message);
		FailTestWithLineInternal(buffer, file, line);
	}

	if (expectedLength > 0) {
		if (MemCmp(String_GetBytes(str), expectedString, expectedLength)) {
			sprintf(buffer, "%s: actual string bytes do not match", message);
			FailTestWithLineInternal(buffer, file, line);
		}
	}
	else {
		if (str != String_Empty) {
			sprintf(buffer, "%s: actual string is not the String_Empty singleton", message);
			FailTestWithLineInternal(buffer, file, line);
		}
	}
}
Exemplo n.º 6
0
bool BootpRx(char *bootpHeader, short len){
	BOOTP_HEADER	*bhp = (BOOTP_HEADER *)bootpHeader;

	if (len!=BOOTP_HDR_SIZE)		return false;

	// check bootp.
	if (bhp->bh_opcode!=2)			return false;
	if (bhp->bh_htype!=1)			return false;
	if (bhp->bh_hlen!=6)			return false;
	if (MemCmp(&bhp->bh_tid, &bootpID, 4)) return false;
	if (MemCmp(&bhp->bh_chaddr, &clientEther, 6)) return false;

	// get infomation from bootp packet.
	MemCpy(&clientIP, &bhp->bh_yiaddr, 4);
	MemCpy(&hostIP  , &bhp->bh_siaddr, 4);

	bootpState = BOOTP_SUCCESS;
	return true;
}	// BootpRx.
Exemplo n.º 7
0
//------------------------------------------------------------------
void	INetworkedObject::Update( uint dt )
{
	for ( size_t i = 0; i < _fields.size(); ++i )
	{
		SField& field( _fields[i] );
		if ( MemCmp( field.data, field.prevValue, field.size ) != 0 )
		{
			i = i;
		}
	}
}
Exemplo n.º 8
0
Arquivo: sggen.c Projeto: rwgk/sglite
static int AddSgSMx(T_SgOps *SgOps, const T_RTMx *NewSMx)
{
  int     mR[9], NewLTr[3], InvT[3], i;
  int     iLSMx;
  T_RTMx  *LSMx;


  for (i = 0; i < 9; i++) mR[i] = -NewSMx->s.R[i];

  LSMx = SgOps->SMx;

  for (iLSMx = 0; iLSMx < SgOps->nSMx; iLSMx++, LSMx++)
  {
    if (MemCmp(LSMx->s.R, NewSMx->s.R, 9) == 0) {
      for (i = 0; i < 3; i++)   NewLTr[i] = LSMx->s.T[i] - NewSMx->s.T[i];
      return AddSgLTr(SgOps, NewLTr);
    }

    if (MemCmp(LSMx->s.R, mR, 9) == 0) {
      for (i = 0; i < 3; i++)     InvT[i] = LSMx->s.T[i] + NewSMx->s.T[i];
      return AddSgInv(SgOps, InvT);
    }
  }

  if (SgOps->nSMx >= SgOps_mSMx) {
    SetSgError("Error: Non-crystallographic rotation matrix encountered");
    return -1;
  }

  MemCpy(LSMx->s.R, NewSMx->s.R, 9);
  for (i = 0; i < 3; i++) LSMx->s.T[i] = iModPositive(NewSMx->s.T[i], STBF);

  SgOps->nSMx++;

  if (   ! SgOps->NoExpand
      &&   SgOps->fInv == 2
      && AddLtrDueToInvT(SgOps, LSMx) < 0)
    return -1;

  return 1;
}
Exemplo n.º 9
0
   void CorrectText(bool detect){

      dword len = win::SendMessage(hwnd_ctrl, WM_GETTEXTLENGTH, 0, 0);
      if(mask_password && !len)
         return;
#ifdef USE_RICHINK
      if(detect && len==dword(text.size()-1)){
         C_buffer<wchar> tmp;
         tmp.Resize(len+1);
         SendMessageW(hwnd_ctrl, WM_GETTEXT, len, (win::LPARAM)tmp.Begin());
         if(!MemCmp(tmp.Begin(), text.begin(), len*sizeof(wchar)))
            return;
         MemCpy(text.begin(), tmp.Begin(), len*sizeof(wchar));
      }else{
         text.resize(len+1);
         win::SendMessage(hwnd_ctrl, WM_GETTEXT, len, (win::LPARAM)text.begin());
      }
      text[len] = 0;
#else
      if(detect && len==dword(text.size()-1)){
         C_buffer<wchar> tmp;
         tmp.Resize(len+1);
         SendMessageW(hwnd_ctrl, WM_GETTEXT, len+1, (win::LPARAM)tmp.Begin());
         if(!MemCmp(tmp.Begin(), text.begin(), (len+1)*sizeof(wchar)))
            return;
         MemCpy(text.begin(), tmp.Begin(), (len+1)*sizeof(wchar));
      }else{
         text.resize(len+1);
         win::SendMessage(hwnd_ctrl, WM_GETTEXT, len+1, (win::LPARAM)text.begin());
         text.begin()[len] = 0;
      }
#endif
      mask_password = false;
      text_dirty = true;
      SetSelFromWin();
      ResetCursor();
   }
Exemplo n.º 10
0
static int VerifyRotMxOrder(const int *ProperR, int AbsOrder, int *CumMx)
{
  int  MxA[9], MxB[9];
  int  *RR, *RRR, *Swp, iO, i;

  const int IdentityMx[] = { 1, 0, 0,
                             0, 1, 0,
                             0, 0, 1 };


  if (CumMx) for (i = 0; i < 9; i++) CumMx[i] = ProperR[i];

  RR = (int *) ProperR;
  RRR = MxA;

  for (iO = 1; iO < AbsOrder; iO++)
  {
    for (i = 0; i < 9; i++)
      if (-1 > RR[i] || RR[i] > 1)
        return -1;

    if (MemCmp(IdentityMx, RR, 9) == 0)
      return -1;

    RotMxMultiply(RRR, ProperR, RR);
    if (RR == ProperR) RR = MxB;
    Swp = RR; RR = RRR; RRR = Swp;

    if (CumMx) for (i = 0; i < 9; i++) CumMx[i] += RR[i];
  }

  if (MemCmp(IdentityMx, RR, 9) != 0)
    return -1;

  return 0;
}
Exemplo n.º 11
0
bool ImageFormat_PNG::TestAsset(const Asset& asset)
	{
	// Check if the header matches PNG files
	if (asset.Open())
		{
		unsigned char pngheader[]={137,80,78,71,13,10,26,10};
		unsigned char buffer[8];
		asset.Read(buffer,8);
		asset.Close();
		if (MemCmp(buffer,pngheader,8)==0)
			{
			return true;
			}
		}

	return false;
	}
Exemplo n.º 12
0
Arquivo: sggen.c Projeto: rwgk/sglite
static int AddLLTr(int LTBF, int mLLTr,
                   T_LTr *LLTr, int *nLLTr, const int *NewLTr)
{
  int    NLTr[3], iLLTr, i;


  rangei(3) NLTr[i] = iModPositive(NewLTr[i], LTBF);

  for (iLLTr = 0; iLLTr < *nLLTr; iLLTr++, LLTr++)
    if (MemCmp(LLTr->v, NLTr, 3) == 0)
      return 0;

  if (*nLLTr >= mLLTr) return -1;

  MemCpy(LLTr->v, NLTr, 3);
  (*nLLTr)++;

  return 1;
}
Exemplo n.º 13
0
SaneWinMain( argc, argv )
{
	if( argc > 1 )
	{
		TEXTSTR result;
		uint8_t* buf;
		size_t length;
		FILE *file = sack_fopen( 0, argv[1], "rb" );
		length = sack_fseek( file, 0, SEEK_END );
		buf = NewArray( uint8_t, length );
		sack_fseek( file, 0, SEEK_SET );
		sack_fread( buf, 1, length, file );
		sack_fclose( file );
		result = SRG_EncryptData( buf, length );
		{
			int wrote = 0;
			while( result[wrote] )
			{
				wrote += printf( "%.80s", result + wrote );
				if( result[wrote] )
					printf("\\\n" );
			}
		}
		{
			size_t testlen;
			uint8_t* testbuf;
			SRG_DecryptData( result, &testbuf, &testlen );
			if( testlen != length )
				printf( "\n length fail \n" );
			if( MemCmp( testbuf, buf, testlen ) )
				printf( "\nFAIL\n" );
			Release( testbuf );
		}
		Release( buf );
		Release( result );

	}
}
Exemplo n.º 14
0
INT ParseResToWin(CHAR* pResFile)
{
	FILE* pFile;
	INT  iCurState;
	INT  iCurStrLen;
	CHAR czCurStr[256];

	CList list;
	PList pList;
	PWindow pWin;
	
	
	pFile = fopen(pResFile, "w+");
	if(pFile == NULL)
	{
		return -1;
	}

	iCurState = PARSE_STATE_START;
	iCurStrLen = 0;
	MemSet(czCurStr, 0, sizeof(czCurStr));

	InitList(&list);
	pList = &list;
	
	while(TRUE)
	{
		switch(iCurState)
		{
			case PARSE_STATE_START:
				czCurStr[iCurStrLen] = GetNextAvaliChar(pFile, "\n	 ", 3);
				iCurStrLen++;
				iCurStrLen += GetStringUntil(pFile, czCurStr+1, "\n	 ", 3);

				if(MemCmp(czCurStr, WIN_RES_FLAG_WINDOW_START, iCurStrLen) == 0)
				{
					iCurState = PARSE_STATE_WINSTART;
				}

				if(MemCmp(czCurStr, WIN_RES_FLAG_WINDOW_END, iCurStrLen) == 0)
				{
					iCurState = PARSE_STATE_WINEND;
				}

				iCurStrLen = 0;
			break;

			case PARSE_STATE_WINSTART:
				pWin = (PWindow)Malloc(sizeof(CWindow));
				PushList(pList, pWin);				
				iCurState = PARSE_STATE_START;
			break;

			case PARSE_STATE_WINEND:
				
				iCurState = PARSE_STATE_START;
			break;

			case 

			case PARSE_STATE_ATTR_ID:

			break;

			case PARSE_STATE_STRING:

			break;

			case PARSE_STATE_LABEL:

			break;

			case PARSE_STARE_END:

			break;

			default:

			break;
		}
	}

	fclose(pFile);
	return 0;
}
Exemplo n.º 15
0
/********************************************************************************
 * Description: this is the function responsible for checking the 
 * input password value of the authentication form. 
 * ******************************************************************************/ 
static void 
checkPassword (void) 
{
	MemPtr pass1, scratch = NULL;
	char *input;

	UInt16 index = 0;
	MemHandle rec;
	mdKey in;
	ListType *list;
	
		// compact text and get a pointer.
		FldCompactText (GetObjectFromActiveForm (PasswordField));
	input = FldGetTextPtr (GetObjectFromActiveForm (PasswordField));
	list = GetObjectFromActiveForm (selPopupList);
	
		// if SysPass is defined, free it. this happens when Strip locks
		// itself after the timeout.
		if (SysPass)
		MemPtrFree (SysPass);
	
		// if its the first time the user has used the program we need 
		// to set some things up. 
		if (input && StrLen (input))
		
	{
		
			// read the password from the database, decrypt with the input text.
			if ((rec = DmQueryRecord (PasswordDB, index)))
			
		{
			pass1 = MemHandleLock (rec);
			if ((scratch = MemPtrNew (24)))
				
			{
				UInt16 chk = LstGetSelection (list);
				
					//printf("%d\n", LstGetSelection(list)); 
					switch (chk)
					
				{
					case 0:
						UnpackPassword_old (pass1, scratch, input, 1);
						break;
					case 1:
						UnpackPassword_old (pass1, scratch, input, 2);
						break;
					case 2:
						UnpackPassword_old (pass1, scratch, input, 0);
						break;
				}
			}
			MemHandleUnlock (rec);
		}
		
			// the message digest of the password they provided should be exactly the
			// same as the message digest that was just decrypted out of the password
			// database. Do a MemCmp to make sure they are the same.
		md5_string (input, in);

		if ((!MemCmp (in, scratch, 16)) && input)
			
		{
			
				// if so, copy the password onto the system-password
		if ((SysPass = MemPtrNew (StrLen (input) + 1)))
				StrCopy (SysPass, input);
		if (scratch)
				MemPtrFree (scratch);
		md_string(SysPass, NewSysPass);
		cryptSwitch (LstGetSelection (list));
		}
		
		else
			
		{
			
				// FAILURE!!!!!!
				// free the memory and tell the user they entered the wrong password.
				FieldType *fld = GetObjectFromActiveForm (PasswordField);
			FrmCustomAlert (GenericError,
							  "The password you entered is incorrect", NULL,
							  NULL);
				FldSetSelection (fld, 0, FldGetTextLength (fld));
			LstDrawList (list);
			if (scratch)
				
			{
				MemPtrFree (scratch);
				SysPass = NULL;
			}
		}
	}
	
		// null string is always wrong!!!
		else
		
	{
		FrmCustomAlert (GenericError, "You forgot to enter a password!!",
						 NULL, NULL);
		LstDrawList (list);
	}
}
Exemplo n.º 16
0
Boolean IsChangedAddressDB()
{
    return !((MemCmp((char*) &gAdcdate, gPrefsR.adrcdate, 4) == 0) &&
            (MemCmp((char*) &gAdmdate, gPrefsR.adrmdate, 4) == 0));
}