Exemplo n.º 1
0
static int et199_encrypt_write_data(void *encrypt, char *src_data, int length, FILE_TYPE type)
{
	ENCRYPT *encrypt_ins = (ENCRYPT *)encrypt;
	struct ET_CONTEXT*pContext = (struct ET_CONTEXT*)encrypt_ins->private_data;
	int dwRet = 0;
	if(length > DATA_FILE_LENGTH)
	{
		return WRITE_LEN_LONGER;
	}
	dwRet = ETVerifyPin(&pContext[0], (unsigned char *)encrypt_ins->dev_passwd,
		strlen(encrypt_ins->dev_passwd), ET_DEV_PIN);
	if(dwRet)
	{
		if(dwRet == ET_E_KEY_REMOVED || dwRet == ET_E_NO_LIST)
		{
			return DEV_REMOVED;
		}
		PostError("ETVerifyPin", dwRet);
		return VERIFYPASSWD_ERR;
	}

	dwRet = ETWriteFile(&pContext[0], file_name[type], 0, (unsigned char *)src_data, length);
	if(dwRet)
	{
		if(dwRet == ET_E_KEY_REMOVED || dwRet == ET_E_NO_LIST)
		{
			return DEV_REMOVED;
		}
		PostError("ETWriteFile", dwRet);
		return WRITEFILE_ERR;
	}

	return 0;
}
Exemplo n.º 2
0
static PyObject *
ETContext_write_file(ETContextObject* self, PyObject *args)
{
  BYTE lpszFileID[5]={0},*pBuffer=NULL,bFileType;
  WORD fileId;
  DWORD dwRet,dwOffset,dwBufferSize,dwFileSize=0,dwFlags,dwBytesWritten;
  if(!PyArg_ParseTuple(args, "HIs#|III", &fileId,&dwOffset,&pBuffer,&dwBufferSize,&dwFileSize,&dwFlags,&dwRet)) {
    return NULL;
  }
  if(fileId==0){
    INVALID_PARAMS("Invalid File Id!",NULL);
  }
  sprintf(lpszFileID,"%04x",fileId);
  if(dwFileSize>0){
    bFileType = dwRet;
    dwRet = ETWriteFileEx(&self->context,lpszFileID,dwOffset,pBuffer,dwBufferSize,dwFileSize,&dwBytesWritten,dwFlags,bFileType);
    DWRET_VALIDATE(dwRet,NULL);
    return Py_BuildValue("i",dwBytesWritten);
  }else{
    dwRet = ETWriteFile(&self->context,lpszFileID,dwOffset,pBuffer,dwBufferSize);
    DWRET_VALIDATE(dwRet,NULL);
  }
  Py_RETURN_TRUE;
}