Exemple #1
0
/***********************************************************************
 *
 * FUNCTION:    SubstituteStr
 *
 * DESCRIPTION: This routine substitutes the occurrence a token, within
 *              a string, with another string.
 *
 * PARAMETERS:  str    - string containing token string
 *              token  - the string to be replaced
 *              sub    - the string to substitute for the token
 *              subLen - length of the substitute string.
 *
 * RETURNED:    pointer to the string
 *
 ***********************************************************************/
static Char* SubstituteStr(Char* str, const Char* token, const Char* sub, UInt16 subLen) {
  const UInt16 tokenLen = StrLen(token);
  const UInt16 charsToMove = subLen - tokenLen;
  const UInt16 strLen = StrLen(str);
  MemHandle strH = MemPtrRecoverHandle(str);
  const UInt16 blockSize = MemHandleSize(strH);
  Char* ptr = StrStr(str, token);

  ASSERT(str);
  ASSERT(token);
  ASSERT(sub);

  /* Find the start of the token string, if it doesn't exist, exit. */
  if (ptr == NULL)
    return str;

  /* Resize the string if necessary. */
  if (strLen + charsToMove + 1 >= blockSize) {
    MemHandleUnlock(strH);
    MemHandleResize(strH, strLen + charsToMove + 1);
    str = MemHandleLock(strH);
    ASSERT(str);
    ptr = StrStr(str, token);
    ASSERT(ptr);
  }

  /* Make room for the substitute string. */
  if (charsToMove)
    MemMove(ptr + subLen, ptr + tokenLen, StrLen (ptr + tokenLen)+1);
  
  /* Replace the token with the substitute string. */
  MemMove(ptr, sub, subLen);
  
  return str;
}
Exemple #2
0
void OSystem_PalmZodiac::undraw_mouse() {
	if (!_mouseDrawn)
		return;

	int h = _mouseOldState.h;

	// no need to do clipping here, since draw_mouse() did that already
	if (_overlayVisible) {
		uint16 *dst;
		uint16 *bak = (uint16 *)_mouseBackupP;

		TwGfxLockSurface(_overlayP, (void **)&dst);
		dst += _mouseOldState.y * _screenWidth + _mouseOldState.x;

		do {
			MemMove(dst, bak, _mouseOldState.w * 2);
			dst += _screenWidth;
			bak += _mouseOldState.w;
		} while (--h);

		TwGfxUnlockSurface(_overlayP, true);

	} else {
		byte *dst = _offScreenP + _mouseOldState.y * _screenWidth + _mouseOldState.x;
		byte *bak = _mouseBackupP;

		do {
			MemMove(dst, bak, _mouseOldState.w);
			dst += _screenWidth;
			bak +=  _mouseOldState.w;
		} while (--h);
	}

	_mouseDrawn = false;
}
/*******************************************************
 * Function: stripCrypt
 * Description: encrypts/decrypts a memory block. puts 
 * the results into an out buffer. dkey is the string
 * ****************************************************/
void stripCryptC(char * ikey, MemPtr str, MemPtr out, int sLen, int enc)
{
       int offset=0;
	   char ivector[BLOCKC], ovector[BLOCKC], k[16]; 
		Boolean e;

		(enc==1)?(e=true):(e=false);
            //generate the key.
       MDString(ikey, k);
		xOrFold(k);

            //encrypt or decrypt block by block
       for(;offset<sLen;)
       {
           MemMove(ivector, str+offset, BLOCKC);
			EncDES(ivector, k, ovector, e);
           MemMove(out+offset, ovector, BLOCKC);
           offset+=BLOCKC;
       }  
       
            // wipeout keying info.
       MemSet(ivector, sizeof(ivector), 0);
       MemSet(ovector, sizeof(ovector), 0);
       MemSet(k,sizeof(k), 0);
}
Exemple #4
0
/*******************************************************
 * Function: stripCrypt
 * Description: encrypts/decrypts a memory block. puts 
 * the results into an out buffer. ikey is the string
 * ****************************************************/
void stripCryptA(char * ikey, MemPtr str, MemPtr out, int sLen, int enc)
{
       word32 vector[3], key[3];
       int offset=0;

            //generate the key.
       twKey(ikey, key);
       
            //encrypt or decrypt block by block
       for(;offset<sLen;)
       {
           MemMove(vector, str+offset, BLOCKA);
           if(enc)
               encrypt(vector, key);
           else
               decrypt(vector, key);
               
           MemMove(out+offset, vector, BLOCKA);
           offset+=BLOCKA;
       }  
       
            // wipe out keying info.
       MemSet(vector, 0, sizeof(vector));
       MemSet(key, 0, sizeof(key));   
}
Exemple #5
0
/*******************************************************
 * Function: stripCrypt
 * Description: encrypts/decrypts a memory block. puts 
 * the results into an out buffer. ikey is the string
 * ****************************************************/
void stripCrypt(md5_hash * ikey, MemPtr str, MemPtr out, int sLen, int enc)
{
       Idea_Data ivector, ovector;
       Idea_UserKey k;
       Idea_Key ekey;
       int offset=0;

            //generate the key.
       MemMove(k, ikey, sizeof(md5_hash));

       Idea_ExpandUserKey(k, ekey);
       
       if(!enc)
            Idea_InvertKey(ekey, ekey);

            //encrypt or decrypt block by block
       for(;offset<sLen;)
       {
           MemMove(ivector, str+offset, BLOCK);
           Idea_Crypt(ivector, ovector, ekey);
           MemMove(out+offset, ovector, BLOCK);
           offset+=BLOCK;
       }  
       
            // wipeout keying info.
       MemSet(ivector, sizeof(ivector), 0);
       MemSet(ovector, sizeof(ovector), 0);
       MemSet(k,sizeof(k), 0);
       MemSet(ekey,sizeof(ekey), 0);   
}
Exemple #6
0
/********************************************************
 * Function: twKey
 * Description: pass this function a null terminated
 * string or char array and it will generate a valid 
 * 96 bit key for the 3-way encryption algorithm. 
 * Method: generate the digest of the passed in string
 * followed by the digest for that digest. concatonate
 * the two arrays and get one big array of 256 bits.
 * Ignore the last 64 bits. take the resulting 192 bits 
 * and fold the last 96 bits over the first 96 bits using
 * and XOR. i.e bit[n]^=bit[n+96]. the resulting array is
 * 96 bits its bit pattern is totaly dependent on the 
 * original strings message digest. If anyone cant think
 * of a better way to do this, let me know.
 * ******************************************************/
void twKey(char * ikey, MemPtr out)
{
       int i;
       char dKey[24], mdKey1[16], mdKey2[16];
      
       // Hash the input string, hash the output, then concatonate 
       MDString(ikey, mdKey1);
       MDBlock(mdKey1, 16, mdKey2);

       //concatanate the arrays
       MemMove(dKey, mdKey1, 16);
       MemMove(dKey+16, mdKey2, 8);

       //now fold dKey over itself at 96 bits, XORing as we go.
       for(i=0; i<12; i++)
       {
           dKey[i]^=dKey[i+BLOCKA];
       }

       MemMove(out, dKey, BLOCKA);
       
            //wipe out keying info.
       MemSet(dKey,0, sizeof(dKey));
       MemSet(mdKey1, 0, sizeof(mdKey1));
       MemSet(mdKey2, 0, sizeof(mdKey2));
}
Exemple #7
0
void sortScript()
{
	//this saves dynamic space
	UInt16 i, k, size;
	Err err;
	ScriptType temp[map.numCmds];
	
	//get rid of all map cmds
	for(i = 0; i < map.numCmds; i++)
	{
		if(!cmdIsAI(script[i].type))
		{
			//copy next cmd into this one if there is			
			for(k = i; k < map.numCmds;k++)
			{
				//if there is a cmd left
				if(k != (map.numCmds - 1))
				{
					//if it still isn't ai then continue
					if(!cmdIsAI(script[k + 1].type))
					{
						continue;
					}
					else
					{
						//copy it into new, discard old
						MemMove(&temp[i], &script[k + 1], sizeof(ScriptType));						
						size++;
						//get out of loop
						break;
					}	
				}
			}
		}	
		//leave it if it is an ai	
	}	
	
	//resize script to value of size
	err = MemHandleResize(scriptH, sizeof(ScriptType) * size);
	if(err == memErrChunkLocked)
	{
		//unlock
		MemHandleUnlock(scriptH);
		if(err = MemHandleResize(scriptH, sizeof(ScriptType) * size))
		{
			ErrFatalDisplay("In sortscript, couldn't resize script");
		}
		script = (ScriptType *)MemHandleLock(scriptH);		 
	}		
	else if(err != 0)
	{
		//some other error
		ErrFatalDisplay("In sortscript, couldn't resize script");	
	}	
	
	//move all script into new one
	MemMove(script, &temp, sizeof(ScriptType) * size);
}
/*
** Load the record data (flags, ...) - but not the picture
*/
static void LoadRecordData(void) {
  MemHandle t = NULL;
  MemPtr ptr = NULL;
  UInt16 attr = 0;
  UInt32 highDataOffset = 0;
  Int16 len = 0;

  PRINT("Loading Record Data for %hd", p.dbI);

  /* Clear unmasked flag */
  d.unmaskedCurrentRecord = false;

  /* Open and lock the record */
  t = DmQueryRecord(d.dbR, p.dbI);
  if (!t) abort();
  ptr = MemHandleLock(t);

  /* Is the record private? */
  DmRecordInfo(d.dbR, p.dbI, &attr, NULL, NULL);
  d.record_private = attr & dmRecAttrSecret;

  /* Read the header data */
  MemMove(&d.record, ptr, sizeof(DiddleBugRecordType));

  /* Read the additional alarm info */
  highDataOffset = sketchDataOffset + d.record.sketchLength;

  len = StrLen((Char*)(ptr + highDataOffset)) + 1; /* +1 for null char */
  if (d.record_name) MemHandleFree(d.record_name);
  d.record_name = MemHandleNew(len);
  ASSERT(d.record_name);
  MemMove(MemHandleLock(d.record_name), ptr + highDataOffset, len);
  MemHandleUnlock(d.record_name);

  highDataOffset += len;

  len = StrLen((Char*)(ptr + highDataOffset)) + 1; /* +1 for null char */
  if (d.record_note) MemHandleFree(d.record_note);
  d.record_note = MemHandleNew(len);
  ASSERT(d.record_note);
  MemMove(MemHandleLock(d.record_note), ptr + highDataOffset, len);
  MemHandleUnlock(d.record_note);

  highDataOffset += len;

  /* Clear old data since there may not be an extra-data block yet */
  MemSet(&d.record_sound, sizeof(AlarmSoundInfoType), 0);
  d.record_sound.listIndex = -1; /* default */
  /* Read new extra-data (if it exists and is from a compatible version) */
  if (d.record.extraLength == sizeof(AlarmSoundInfoType))
    MemMove(&d.record_sound, ptr + highDataOffset, d.record.extraLength);

  /* Unlock record */
  MemHandleUnlock(t);
}
Exemple #9
0
/**************************************************************************
 * Function: generateAccountHash
 * Description: returns the unique hash for the account.
 * ************************************************************************/ 
md_hash * generateAccountHash (Account * acct) {
	static md_hash ret;
	unsigned char * hashable;
	int data_length = 0, string_length = 0;
	
	MemSet(ret, sizeof(md_hash), 0);
	
	/* username, password, acct mod date, 
	 * pw mod date, and 256 bits of randomness */
	data_length = 
		StrLen(acct->username)+
		StrLen(acct->system)+
		StrLen(acct->password)+
		StrLen(acct->service)+
		StrLen(acct->comment)+
		sizeof(acct->account_mod_date)+
		sizeof(acct->password_mod_date)+
		(sizeof(Int16)*16)+1;
		
		
	if((hashable=MemPtrNew(data_length))) {
		MemSet(hashable, data_length, 0);
		StrCopy(hashable, acct->username);	
		string_length+=StrLen(acct->username);
		StrCat(hashable, acct->system);	
		string_length+=StrLen(acct->system);
		StrCat(hashable, acct->password);
		string_length+=StrLen(acct->password);	
		StrCat(hashable, acct->service);
		string_length+=StrLen(acct->service);	
		StrCat(hashable, acct->comment);
		string_length+=StrLen(acct->comment);	
		
		MemMove(hashable+string_length, 
			&acct->account_mod_date, 
			sizeof(acct->account_mod_date));
		string_length+=sizeof(acct->account_mod_date);
		
		MemMove(hashable+string_length, 
			&acct->password_mod_date, 				
			sizeof(acct->password_mod_date));
		string_length+=sizeof(acct->password_mod_date);
		
		/* move some randomness onto the end 
		 * to make dictionary attacks impossible.   */
		random_bytes(hashable+string_length, 32);
		string_length+=32;
		
		md_block(hashable, string_length, ret);	
		MemPtrFree(hashable);
	}	
	return &ret;
}
/* Handle the Gesture preferences */
Boolean PrefsGesturePreferenceEvent
    (
    ActionType action
    )
{
    Boolean handled;

    handled = false;

    switch ( action ) {
        case AVAILABLE:
            /* Always available */
            handled = true;
            break;

        case SHOWFIRST:
            handled = showFirst;
            showFirst = false;
            break;

        case LOAD:
            gestureSelected = GESTURES_UP;
            MemMove( gestureMode, Prefs()->gestMode, sizeof( gestureMode ) );
            InitializeActionList( frmPrefsGestureActionList );
            CtlSetValue( GetObjectPtr( frmPrefsGestureGestures ),
                Prefs()->gestures );
            SetListToSelection( frmPrefsGestureActionList,
                frmPrefsGestureSelectAction, gestureMode[ gestureSelected ] );
            handled = true;
            break;

        case DISPLAY:
            AffirmControlImage( gestureSelected, frmPrefsGestureUp,
                bmpGestureUp );
            handled = true;
            break;

        case SAVE:
            Prefs()->gestures = CtlGetValue( GetObjectPtr(
                frmPrefsGestureGestures ) );
            MemMove( Prefs()->gestMode, gestureMode, sizeof( gestureMode ) );
            handled = true;
            break;

        default:
            handled = false;
            break;
    }
    return handled;
}
Exemple #11
0
/************************************************************************************
 * Function: UnpackAccountA
 * Description: This is a utility function that will take a packed account ,
 * optionally decrypt it based on the passed in password, and set up 
 * an unpacked account. isRec determines whether the packed account is a full record.
 * remember that fullrecords have the plaintext system id prepended, so if it
 * is a full record we will ignore this space.
 * **********************************************************************************/ 
static void 
UnpackAccount_old (Account_old * acct, MemPtr p, MemPtr scratch,
				char *pass, UInt16 recLen, Boolean decrypt, Boolean isRec,
				int v) 
{
	PAccount_old * pacct;
	char *s;

	UInt16 offset = sizeof (offset);
	recLen = recLen - offset;
	
		// decrypt if neccessary
	if (decrypt)
		switch (v)
			
		{
			case 0:
				stripCrypt_tw (pass, p + offset, scratch, recLen, 0);
				break;
			case 1:
				stripCrypt_idea (pass, p + offset, scratch, recLen, 0);
				break;
			case 2:
				stripCrypt_des (pass, p + offset, scratch, recLen, 0);
				break;
		}	
	else
		
			// if buffer has the systemID header disregard it.
		if (isRec)
		MemMove (scratch, p + offset, recLen);
	
	else
		MemMove (scratch, p, recLen);
	
		// split record up into its different components.   
		pacct = (PAccount_old *) scratch;
	s = pacct->username;
	acct->SystemID = pacct->SystemID;
	acct->AccountID = pacct->AccountID;
	acct->username = s;
	s += StrLen (s) + 1;
	acct->password = s;
	s += StrLen (s) + 1;
	acct->type = s;
	s += StrLen (s) + 1;
	acct->comment = s;
	s += StrLen (s) + 1;
}
Exemple #12
0
static Char * PrvAddPadding(Char * startOfBlock, Char * dstP, const Int16 minimumSize,
	const Boolean leftJustify, Boolean zeroPad, Char sign)
{	
	Int16 stringSize = StrLen(startOfBlock);
	
	ErrNonFatalDisplayIf( sign && (sign != '+') && (sign != ' '), "illegal sign character specified in PrvAddPadding" );
	
	if (leftJustify && stringSize < minimumSize)		// Left Justified
		{
		MemSet(dstP, minimumSize - stringSize, ' ');
		dstP += minimumSize - stringSize;
		*dstP = '\0';
		}
	else if (!leftJustify && stringSize < minimumSize)	// Right Justified
		{
		
		// If there is a sign present and the calling function as specified padding with
		// zero bytes then do not move the sign character with the rest of the value.
		if ( (sign == '+' || sign == ' ') && zeroPad )
			{
			// If there is a sign present then only MemMove the value and not the sign.
			// The value will be moved minimum size specified for this value minus the
			// actual string size of the value plus the size of the sign (1).
			MemMove(startOfBlock + minimumSize - stringSize + 1, startOfBlock + 1, 
						stringSize - 1);
						
			// MemSet the space between the sign and moved value with the desired
			// padding value.
			MemSet(startOfBlock + 1, minimumSize - stringSize, zeroPad ? '0' : ' ');
			}
		else
			{
			// MemMove the value and any potential sign character to make room for padding
			// characters.  The number of bytes to move is determined by the minimum string
			// specified for the value minus the actual string size of the value.
			MemMove(startOfBlock + minimumSize - stringSize, startOfBlock, stringSize);
			
			// MemSet the space between the sign and moved value with the desired
			// padding value.
			MemSet(startOfBlock, minimumSize - stringSize, zeroPad ? '0' : ' ');
			}	
			
		dstP += minimumSize - stringSize;
		*dstP = '\0';
		}
		
	return dstP;
}
Exemple #13
0
void deserData(unsigned char *valOut, int len, const unsigned char **data, long *pBlobSizeLeft)
{
    Assert( data && *data && pBlobSizeLeft && (*pBlobSizeLeft>=len) );
    MemMove( valOut, *data, len );
    *data = *data+len;
    *pBlobSizeLeft -= len;
}
Exemple #14
0
/************************************************************************************
 * Function: UnpackSystem_old
 * Description: This is a utility function that will take a packed System ,
 * optionally decrypt it based on the passed in password, and set up 
 * an unpacked system. 
 * **********************************************************************************/ 
static void 
UnpackSystem_old (System_old * sys, MemPtr p, MemPtr scratch, char *pass,
			   UInt16 recLen, Boolean decrypt, int v) 
{
	PSystem_old * psys;
	char *s;

	
		// if necessary, decrypt, otherwise just copy the memory to the scratch buffer
		if (decrypt)
		switch (v)
			
		{
			case 0:
				stripCrypt_tw (SysPass, p, scratch, recLen, 0);
				break;
			case 1:
				stripCrypt_idea (SysPass, p, scratch, recLen, 0);
				break;
			case 2:
				stripCrypt_des (SysPass, p, scratch, recLen, 0);
				break;
		}
	
	else
		MemMove (p, scratch, recLen);
	
		// set up the system, pointing the name to the first char in the name string.
		psys = (PSystem_old *) scratch;
	s = psys->name;
	sys->SystemID = psys->SystemID;
	sys->name = s;
	s += StrLen (s) + 1;
}
Exemple #15
0
void* PrvRealloc(void* p, UInt32 newSize)
{
    if (0 == newSize)
    {
        if (NULL != p)
            MemPtrFree(p);
        return NULL;
    }
    newSize = PrvBlockSize(newSize);
    if (NULL == p)
        return MemGluePtrNew(newSize);

    UInt32 size = MemPtrSize(p);
    if (newSize <= size)
        return p;

    Err err = MemPtrResize(p, newSize);
    if (errNone == err)
        return p;

    void* np = MemGluePtrNew(newSize);
    if (NULL != np)
        MemMove(np, p, size);

    MemPtrFree(p);
    return np;
}
static void ModSetStack(UInt32 newSize, UInt16 cardNo, LocalID dbID) {
	DmOpenRef dbRef = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);

	if (dbRef) {
		MemHandle pref = DmGetResource('pref',0);
		UInt32 size = 0;
		
		if (pref) {
			SysAppPrefsType *data = (SysAppPrefsType *)MemHandleLock(pref);
			size = data->stackSize;

			if (newSize) {
				SysAppPrefsType newData;
				MemMove(&newData, data, sizeof(SysAppPrefsType));
				newData.stackSize = newSize;
				DmWrite(data, 0, &newData, sizeof(SysAppPrefsType));
			}

			MemPtrUnlock(data);
			DmReleaseResource(pref);
		}

		DmCloseDatabase(dbRef);
	}
}
Exemple #17
0
static void
/*FCN*/OnFeatMove (
  ButtoN b
){
  Int2 i,j,k;
  Int2 movFeat;

  movFeat = featAr[curFeatureInd];
  i = GetValue ( featPopup );
  if ( groupAr[curGroupInd] <= i ) i++;
  MemMove ( &(featAr[curFeatureInd]), &(featAr[curFeatureInd+1]),
            (totalFeatures - curFeatureInd - 1)*sizeof(Int2) );
  if ( curFeatureInd >= nHideFeatures ){
    Nlm_SetMuskCParamEd(movFeat,MSM_FGROUP,MSM_NUM,(BigScalar)i);
  } else {
    nHideFeatures--;
    for ( j=1; j<=MSM_TOTAL_POSITIVE; j++ ){
      if ( (Int2)Nlm_GetMuskCParamEd(j,MSM_FGROUP,MSM_NUM ) == i ){
        k = (Int2)Nlm_GetMuskCParamEd(j,MSM_FORDER,MSM_NUM );
        if ( k > 0 ){
          Nlm_SetMuskCParamEd(j,MSM_FORDER,MSM_NUM,(BigScalar)(k+1));
        }
      }
    }
    Nlm_SetMuskCParamEd(movFeat,MSM_FGROUP,MSM_NUM,(BigScalar)i);
    Nlm_SetMuskCParamEd(movFeat,MSM_FORDER,MSM_NUM,1);
  }
  totalFeatures--;
  if ( curFeatureInd == totalFeatures ) curFeatureInd--;
  FillFeatList(TRUE);
  SetFeatValue ( curFeatureInd );
  SaveFeatureArray();
  UpdateDlgControls();
}
Exemple #18
0
static void
/*FCN*/OnGroupNew (
  ButtoN b
){
  Int2 i;
  Char newName[64];

  GetTitle ( groupDialog, &(newName[0]), 64 );
  if ( newName[0] == 0 ) return;
  newName[63] = 0;
  for ( i=1; i<=totalGroups; i++ ){
    if ( StringCmp ( (CharPtr)Nlm_GetMuskCParamEd(MSM_GROUPS,
                      i,MSM_STRING), &(newName[0]) ) == 0 ) return;
  }
  MemMove ( &(groupAr[1]), &(groupAr[0]), totalGroups*sizeof(Int2) );
  totalGroups++;
  nHideGroups++;
  groupAr[0] = totalGroups;
  Nlm_SetMuskCParamEd(MSM_GROUPS,MSM_NOSUBCLASS,MSM_NUM,(BigScalar)totalGroups);
  Nlm_SetMuskCParamEd(MSM_GROUPS,totalGroups,MSM_STRING,(BigScalar)&(newName[0]));
  curGroupInd = 0;
  FillGroupList(TRUE);
  SetGroupValue ( curGroupInd );
  FillFeatPopup(TRUE);
  LoadFeatureArray();
  FillFeatList(TRUE);
  if ( totalFeatures == 0 ){
    curFeatureInd = -1;
  } else {
    curFeatureInd = 0;
    SetFeatValue ( curFeatureInd );
  }
  UpdateDlgControls();
  SaveGroupArray();
}
XPTEXP1 void * XPTAPI XPTEXP2 xppRealloc(void *ptr, size_t size) {
   Err rc;
   UInt32 currentSize;
   void *newMem;

   /* If original pointer is null, act like a normal malloc                */
   if (!ptr) return MemPtrNew(size);

   /* Try resizing original area.  This will always work if the new area   */
   /* is smaller.  It may or may not work if growing the area.             */
   rc = MemPtrResize(ptr, size);
   if (!rc) return ptr;             /* It worked.  Return same pointer.    */

   /* Resizing didn't work.  Allocate a new, larger, area, and copy the    */
   /* previous data from the old area.                                     */
   newMem = MemPtrNew(size);
   if (!newMem) return newMem;      /* Pass error to caller                */

   /* The original size must be smaller than the new size                  */
   currentSize = MemPtrSize(ptr);
   MemMove(newMem, ptr, currentSize);

   /* Release the old area.                                                */
   MemPtrFree(ptr);

   return newMem;
}
Exemple #20
0
/* remove an item from the list and move te rest one position up */
static Int16 RemoveFileRec(FileRef fr)
{
    Int16 i;
    Err ret;
    file_rec_t* axxFileList;
    axxPacFD FileDesc;

    axxFileList = MemHandleLock(axxFileListHandle);
    i = GetFilePos((Int16)fr);
    if (i == -1)
        return -1;
    
    FileDesc=axxFileList[i].fd;
    for (; i < axxFLSize - 1; i++) {
        MemMove (&axxFileList[i], &axxFileList[i + 1],sizeof(axxFileList));
    }    
    axxFLSize--;
    ret = MemHandleResize(axxFileListHandle, sizeof(file_rec_t) * axxFLSize);
    ret = MemHandleUnlock(axxFileListHandle);
    /* Check if the current file is the one removed from the list */
    if ((currFileDesc != -1) && ( FileDesc== currFileDesc)) {
        /* the cache of offsets is no longer valid if this file
           was closed */
        currFileDesc = -1;
        MemHandleFree(moff);
    }
    return 0;
}
Exemple #21
0
static void NewAddrUnpack(PrvAddrPackedDBRecord *src, AddrDBRecordPtr dest)
{
    Int16   				index;
    AddrDBRecordFlags 		flags;
    char 					*p;

    MemMove(&(dest->options), &(src->options), sizeof(AddrOptionsType));
    MemMove(&flags, &(src->flags), sizeof(AddrDBRecordFlags));
    p = &src->firstField;

    for (index = firstAddressField; index < addrNumStringFields; index++)
    {
        // If the flag is set, point to the string else NULL

        if (GetBitMacro(flags, index) != 0)
        {
            dest->fields[index] = p;
            p += StrLen(p) + 1;
        }
        else
            dest->fields[index] = NULL;
    }

    // Unpack birthday info
    MemSet(&(dest->birthdayInfo), sizeof(BirthdayInfo), 0 );

    if(GetBitMacro(flags, birthdayDate))
    {
        MemMove(&(dest->birthdayInfo.birthdayDate), p, sizeof(DateType));
        p += sizeof(DateType);
    }

    if(GetBitMacro(flags, birthdayMask))
    {
        MemMove(&(dest->birthdayInfo.birthdayMask), p, sizeof(AddressDBBirthdayFlags));
        //Dest->birthdayInfo.birthdayMask = *((AddressDBBirthdayFlags*)p);
        p += sizeof(AddressDBBirthdayFlags);
    }

    if(GetBitMacro(flags, birthdayPreset))
    {
        dest->birthdayInfo.birthdayPreset = *((UInt8*)p);
        p += sizeof(UInt8);
    }

    // Ignore the blob part - I don't use it
}
Exemple #22
0
void GenMatchedRule(Rule * rule)
{
    Var rule_proc;
    Var * args[MACRO_ARG_CNT];
    rule_proc.instr = rule->to;
    MemMove(args, MACRO_ARG, sizeof(args));
    GenMacro(&rule_proc, args);
}
Exemple #23
0
/************************************************************************************
 * Function: PackRegistration
 * Description: Utility function that takes an unpacked Registration, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackRegistration (MemPtr retbuff, Registration reg) {
	UInt16 offset = 0;
	MemPtr preg;
	if ((preg = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (preg + offset, &reg.first_use, sizeof (reg.first_use));
		offset += sizeof (reg.first_use);
		MemMove (preg + offset, reg.email, StrLen (reg.email) + 1);
		offset += StrLen (reg.email) + 1;
		MemMove (preg + offset, reg.code, StrLen (reg.code) + 1);
		offset += StrLen (reg.code) + 1;

		MemMove (retbuff, preg, MemPtrSize(preg));
		MemSet (preg, MemPtrSize (preg), 0);
		MemPtrFree (preg);
	}
}
Exemple #24
0
/************************************************************************************
 * Function: UnpackSystem
 * Description: This is a utility function that will take a packed System ,
 * optionally decrypt it based on the passed in password, and set up 
 * an unpacked system. 
 * **********************************************************************************/ 
void UnpackSystem (System * sys, MemPtr p, MemPtr scratch, md_hash * pass, 
	UInt16 recLen, Boolean decrypt) {
	PSystem * psys;
	char *s;
	
	/*	if necessary, decrypt, otherwise just copy the memory to the scratch buffer */
	if (decrypt) {
		MemMove(scratch, p, SYST_HEADER); 	
		stripCrypt (*pass, (p+SYST_HEADER), (scratch+SYST_HEADER), (recLen-SYST_HEADER), DECRYPT);
	} else MemMove (p, scratch, recLen);
	
	/*	set up the system, pointing the name to the first char in the name string. */
	psys = (PSystem *) scratch;
	s = psys->name;
	sys->SystemID = psys->SystemID;
	sys->name = s;
	s += StrLen (s) + 1;
}
Exemple #25
0
/***********************************************************************************
 * Function: PackPassword
 * Description: pack a password and encrypt it using spass
 * *********************************************************************************/ 
void PackPassword (MemPtr retbuff,  md_hash * spass) {
	MemPtr ppass;
	if ((ppass = MemPtrNew (getSCSize(sizeof(md_hash))))) {
		MemMove (ppass, spass, sizeof (md_hash));
		stripCrypt (*spass, ppass, retbuff, getSCSize(sizeof(md_hash)), ENCRYPT);
		MemSet (ppass, MemPtrSize (ppass), 0);
		MemPtrFree (ppass);
	}
}
Exemple #26
0
/******************************************************************************
 * Function: getSIDForSystemIndex
 * Description: this will get the system id for a given index in the
 * system database.
 * ****************************************************************************/ 
UInt16 getSIDForSystemIndex (DmOpenRef SystemDB, UInt16 i) {
	UInt16 ret;
	MemHandle rec = DmQueryRecord (SystemDB, i);
	if (rec) {
		MemPtr buff = MemHandleLock (rec);
		MemMove (&ret, buff, sizeof (ret));
		MemHandleUnlock (rec);
	}
	return ret;
}
Exemple #27
0
int
load_preferences(void)
{UInt16 prefs_size=0;int version,n;char*p,*_;
 version=PrefGetAppPreferences(CREATOR,prefs_id,0,&prefs_size,0);
 if(version!=prefs_version)return try_db_name();
 if(prefs_size<db_name_size+1)return try_db_name();
 p=MemPtrNew(prefs_size);if(!p)return try_db_name();_=p;
 version=PrefGetAppPreferences(CREATOR,prefs_id,p,&prefs_size,0);
 if(version!=prefs_version){MemPtrFree(p);return try_db_name();}
 n=db_name_size;MemMove(db_name,_,n);_+=n;prefs_size-=n;db_name[n]=0;
 if(try_db_name())return!0;
 if(prefs_size>1)
 {n=StrLen(_)+1;lookup=MemPtrNew(n);
  if(lookup)MemMove(lookup,_,n);prefs_size-=n;_+=n;
 }if(prefs_size>0)
 {char aux_flags=*_;set_list_mode(2*!!(aux_flags&(1<<list_mode_bit)));
  prefs_size-=1;_+=1;
 }MemPtrFree(p);return 0;
}static int
Exemple #28
0
/************************************************************************************
 * Function: PackSystem
 * Description: Utility function that takes an unpacked system, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackSystem (MemPtr retbuff, System sys, md_hash * pass, Boolean encrypt) {
	UInt16 offset = 0;
	MemPtr psys;
	if ((psys = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (psys + offset, &sys.SystemID, sizeof (sys.SystemID));
		offset += sizeof (sys.SystemID);
		MemMove (psys + offset, sys.name, StrLen (sys.name) + 1);
		offset += StrLen (sys.name) + 1;
		
		if (encrypt) {
			MemMove(retbuff, psys, SYST_HEADER);
			stripCrypt (*pass, psys+SYST_HEADER, retbuff+SYST_HEADER, getSystemSize(&sys, true)-SYST_HEADER, ENCRYPT);
		} else MemMove (retbuff, psys, getSystemSize (&sys, true));

		MemSet (psys, MemPtrSize (psys), 0);
		MemPtrFree (psys);
	}
}
Exemple #29
0
/**************************************************************************
 * Function: getAIDFromAccountIndex
 * Description: returns the account id for the account located at a given
 * index. Remember that the first few bytes of an account record are the
 * system ID of the account.  Just skip these an pop off the AID.
 * ************************************************************************/ 
UInt16 getAIDFromAccountIndex(DmOpenRef AccountDB, UInt16 index) {
	UInt16 ret = 0;
	MemHandle rec = DmQueryRecord (AccountDB, index);
	if (rec) {
		MemPtr buff = MemHandleLock (rec);
		MemMove (&ret, buff+sizeof(ret), sizeof (ret));
		MemHandleUnlock (rec);
	}
	return ret;
}
Exemple #30
0
/**************************************************************************
 * Function: getHashFromAccountIndex
 * Description: returns the unique has for the account located at a given
 * index. Remember that the first few bytes of an account record are the
 * system ID of the account.  Just skip these an pop off the AID.
 * ************************************************************************/ 
md_hash * getHashFromAccountIndex (DmOpenRef AccountDB, UInt16 index) {
	static md_hash ret;
	MemHandle rec = DmQueryRecord (AccountDB, index);
	if (rec) {
		MemPtr buff = MemHandleLock (rec);
		MemMove (ret, buff+sizeof(UInt16)+sizeof(UInt16), sizeof (ret));
		MemHandleUnlock (rec);
	}
	return &ret;
}