Esempio n. 1
0
static int
ETContext_init(ETContextObject *self, PyObject *args, PyObject *kwds)
{
    char *pzId=NULL,*pzAtr=NULL;
    int lId=0,lAtr=0;
    static char *kwlist[] = {"dwIndex","dwVersion","hLock","dwCustomer","bAtr","bID",NULL};
    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiiis#s#", kwlist, 
                                      &self->context.dwIndex,
                                      &self->context.dwVersion,
                                      &self->context.hLock,
                                      &self->context.dwCustomer,
                                      &pzAtr,&lAtr,
                                      &pzId,&lId))

        return -1; 
    if(pzId!=NULL && lId!=MAX_ID_LEN){
      INVALID_PARAMS("Length of ID must be 8!",-1);
    }
    memcpy(self->context.bID,pzId,MAX_ID_LEN);
    if(pzAtr!=NULL && lAtr>MAX_ATR_LEN){
      INVALID_PARAMS("Length of Atr must not be longer than 16!",-1);
    }
    memcpy(self->context.bAtr,pzAtr,lAtr);
    return 0;
}
Esempio n. 2
0
/**
 *	Console command handler:	dmm pause
 */
static void cmd_dmm_pause(const idCmdArgs& args) {
	int unid = 0;
	int force = 0;
	
	if (sscanf(args.argv[2], "%i", &unid) < 1) {
		/* invalid conversion - bad parameter */
		CONSOLE_PRINTF(CINFO INVALID_PARAMS("pause"));
		return;
	}
	
	if (args.argc >= 4)
		/* force specified? */
		if (!cstrcmp(args.argv[3], "force"))
			force = 1;
	
	int op = pause_plugin_by_unid(unid, force);

	if (op == 0)
		CONSOLE_PRINTF(CINFO "Invalid plugin unid %i.\n", unid);
	else if (op == 1)
		CONSOLE_PRINTF(CINFO "Successfully paused plugin unid %i.\n", unid);
	else if (op == 2)
		CONSOLE_PRINTF(CINFO "Plugin unid %i already paused.\n", unid);
	else if (op == -1)
		CONSOLE_PRINTF(CINFO "Pausing a zombie plugin is not permitted.\n", unid);
	else
		CONSOLE_PRINTF(CINFO "Plugin unid %i can not be paused.\n", unid);
}
Esempio n. 3
0
static PyObject *
ETContext_create_dir(ETContextObject* self, PyObject *args)
{
  BYTE pszDirId[5]={0};
  WORD dirId=0;
  DWORD dwRet,dwDirSize,dwFlags=ET_CREATE_ROOT_DIR;
  ET_CREATEDIRINFO createInfo={0};
  PyObject *pyDirInfo=NULL,*pyAtr=NULL;
  if(!PyArg_ParseTuple(args, "HII|O", &dirId,&dwDirSize,&dwFlags,&pyDirInfo)) {
    return NULL;
  }
  Py_XINCREF(pyDirInfo);

  if(0!=dirId){
    sprintf(pszDirId,"%04x",dirId);
  }else{
    dwDirSize=0;
    dwFlags=ET_CREATE_ROOT_DIR;
  }
  if(NULL != pyDirInfo){
    if(!PyTuple_Check(pyDirInfo) 
        || 2!=PyTuple_Size(pyDirInfo)
        || !PyInt_Check(PyTuple_GetItem(pyDirInfo,0))
        || !PyString_Check(PyTuple_GetItem(pyDirInfo,1))){
      INVALID_PARAMS("DirInfo should be a tuple with one integer and one bytearray!",NULL);
    }
    pyAtr = PyTuple_GetItem(pyDirInfo,1);
    Py_XINCREF(pyAtr);
    dwRet = PyString_Size(pyAtr);
    if(dwRet>16 || dwRet<1){
      INVALID_PARAMS("ATR length must between 1~16!",NULL);
    }
    createInfo.dwCreateDirInfoSize = PyInt_AsUnsignedLongMask(PyTuple_GetItem(pyDirInfo,0));
    memcpy(createInfo.szAtr,PyString_AsString(pyAtr),dwRet);
    dwRet = ETCreateDirEx(&self->context,pszDirId,dwDirSize,dwFlags,&createInfo);
    DWRET_VALIDATE(dwRet,NULL);
  }else{
    dwRet = ETCreateDir(&self->context,pszDirId,dwDirSize,dwFlags);
    DWRET_VALIDATE(dwRet,NULL);
  }
  Py_XDECREF(pyAtr);
  Py_XDECREF(pyDirInfo);
  Py_RETURN_TRUE;
}
Esempio n. 4
0
/**
 *	Console command handler:	dmm info
 */
static void cmd_dmm_info(const idCmdArgs& args) {
	int unid = 0;
	if (sscanf(args.argv[2], "%i", &unid) < 1) {
		/* invalid conversion - bad parameter */
		CONSOLE_PRINTF(CINFO INVALID_PARAMS("info"));
		return;
	}
	
	plugin_info(unid);
}
Esempio n. 5
0
/**
 *	Console command handler:	dmm list
 */
static void cmd_dmm_list(const idCmdArgs& args) {
	int zombies = 0;
	
	if (args.argc > 2) {
		if (!cstrcmp(args.argv[2], "zombies")) {
			CONSOLE_PRINTF(CINFO INVALID_PARAMS("list"));
			return;
		} else
			zombies = 1;
	}
	
	plugin_list(zombies);
}
Esempio n. 6
0
static PyObject * 
as_ETContext(ETContextObject *self, PyObject *args)
{
  ETContextObject *obj=NULL;
  if (!PyArg_ParseTuple(args, "O", &obj)) {
    return NULL;
  }
  if(NULL == obj || !PyETContext_CheckExact(obj)){
    INVALID_PARAMS("Invalid param!",NULL);
  }
  Py_XINCREF(obj);
  return (PyObject*)obj;
}
Esempio n. 7
0
static PyObject *
ETContext_change_dir(ETContextObject* self, PyObject *args)
{
  BYTE  pszPath[5]={0};
  WORD  wPath;
  DWORD dwRet;
  if(!PyArg_ParseTuple(args, "H", &wPath)) {
    return NULL;
  }
  if(wPath==0){
    INVALID_PARAMS("Not a valid path!",NULL);
  }
  sprintf(pszPath,"%04x",wPath);
  dwRet = ETChangeDir(&self->context,pszPath);
  DWRET_VALIDATE(dwRet,NULL);
  Py_RETURN_TRUE;
}
Esempio n. 8
0
/**
 *	Console command handler:	dmm unpause
 */
static void cmd_dmm_unpause(const idCmdArgs& args) {
	int unid = 0;
	if (sscanf(args.argv[2], "%i", &unid) < 1) {
		/* invalid conversion - bad parameter */
		CONSOLE_PRINTF(CINFO INVALID_PARAMS("unpause"));
		return;
	}
	
	int op = unpause_plugin_by_unid(unid);

	if (op == 0)
		CONSOLE_PRINTF(CINFO "Invalid plugin unid %i.\n", unid);
	else if (op == 1)
		CONSOLE_PRINTF(CINFO "Successfully unpaused plugin unid %i.\n", unid);
	else if (op == -1)
		CONSOLE_PRINTF(CINFO "Unpausing a zombie plugin is not permitted.\n", unid);
	else
		CONSOLE_PRINTF(CINFO "Plugin unid %i already paused.\n", unid);
}
Esempio n. 9
0
static PyObject *
ETContext_create_file(ETContextObject* self, PyObject *args)
{
  BYTE *lpszFileID[5]={0};
  WORD fileId;
  DWORD dwRet,dwFileSize;
  BYTE  bFileType;
  if(!PyArg_ParseTuple(args, "HII", &fileId,&dwFileSize,&dwRet)) {
    return NULL;
  }
  if(fileId==0){
    INVALID_PARAMS("Invalid File Id!",NULL);
  }
  sprintf(lpszFileID,"%04x",fileId);
  bFileType=dwRet;
  dwRet = ETCreateFile(&self->context,lpszFileID,dwFileSize,bFileType);
  DWRET_VALIDATE(dwRet,NULL);
  Py_RETURN_TRUE;
}
Esempio n. 10
0
static PyObject *
ETContext_gen_rsa_key(ETContextObject* self, PyObject *args)
{
  PyObject *pyRet=NULL;
  WORD wKeySize;
  DWORD dwRet,dwE,dwPubKeyDataSize=2120,dwPriKeyDataSize=2120;
  BYTE lpszPubFileID[5]={0},lpszPriFileID[5]={0},pbPubKeyData[2120],pbPriKeyData[2120];
  WORD pubFileId,priFileId;
  if(!PyArg_ParseTuple(args,"HIHH", 
                            &wKeySize,
                            &dwE,
                            &pubFileId,
                            &priFileId)) {
    return NULL;
  }
  if(0==pubFileId || 0==priFileId){
    INVALID_PARAMS("Invalid File Id!",NULL);
  }
  sprintf(lpszPubFileID,"%04x",pubFileId);
  sprintf(lpszPriFileID,"%04x",priFileId);
  dwRet = ETGenRsaKey(&self->context,
                      wKeySize,
                      dwE,
                      lpszPubFileID,
                      lpszPriFileID,
                      pbPubKeyData,
                      &dwPubKeyDataSize,
                      pbPriKeyData,
                      &dwPriKeyDataSize);
  DWRET_VALIDATE(dwRet,NULL);
  #if 1
  pyRet =  Py_BuildValue("(s#s#)",pbPubKeyData,dwPubKeyDataSize,pbPriKeyData,dwPriKeyDataSize);
  #else
  pyRet = PyTuple_New(2);
  PyTuple_SetItem(pyRet,0,PyString_FromStringAndSize(pbPubKeyData,dwPubKeyDataSize));
  PyTuple_SetItem(pyRet,1,PyString_FromStringAndSize(pbPriKeyData,dwPriKeyDataSize));
  Py_INCREF(pyRet);
  return pyRet;
  #endif
  Py_XINCREF(pyRet);
  return pyRet;
}
Esempio n. 11
0
static PyObject *
ETContext_execute(ETContextObject* self, PyObject *args)
{
  BYTE lpszFileID[5]={0},*pInBuffer=NULL,bFileType,OutBuffer[256];
  DWORD dwRet,dwInbufferSize,dwBytesReturned;
  WORD fileId;
  PyObject *pyRet = NULL;
  if(!PyArg_ParseTuple(args, "Hz#", &fileId,&pInBuffer,&dwInbufferSize)) {
    return NULL;
  }
  if(fileId==0){
    INVALID_PARAMS("Invalid File Id!",NULL);
  }
  sprintf(lpszFileID,"%04x",fileId);
  dwRet = ETExecute(&self->context,lpszFileID,pInBuffer,dwInbufferSize,OutBuffer,256,&dwBytesReturned);
  DWRET_VALIDATE(dwRet,NULL);
  pyRet = Py_BuildValue("z#",OutBuffer,dwBytesReturned);
  Py_XINCREF(pyRet);
  return pyRet;
}
Esempio n. 12
0
static PyObject *
ETContext_open(ETContextObject* self, PyObject *args)
{
    DWORD dwRet;
    ET_OPENINFO OpenInfo;
    PyObject *pyOpenInfo=NULL;
    if (!PyArg_ParseTuple(args, "|O", &pyOpenInfo)) {
      return NULL;
    }
    Py_XINCREF(pyOpenInfo);
  #if defined(WIN32)
    if(NULL != pyOpenInfo){
      //printf("PyTuple_Check(pyOpenInfo)=%d\n",PyTuple_Check(pyOpenInfo));
      //printf("PyTuple_Size(pyOpenInfo)=%d\n",PyTuple_Size(pyOpenInfo));
      //printf("PyInt_Check(PyTuple_GetItem(pyOpenInfo,0)=%d\n",PyInt_Check(PyTuple_GetItem(pyOpenInfo,0)));
      //printf("PyInt_Check(PyTuple_GetItem(pyOpenInfo,1))=%d\n",PyInt_Check(PyTuple_GetItem(pyOpenInfo,1)));
      if(!PyTuple_Check(pyOpenInfo) 
        || 2!=PyTuple_Size(pyOpenInfo)
        || !PyInt_Check(PyTuple_GetItem(pyOpenInfo,0))
        || !PyInt_Check(PyTuple_GetItem(pyOpenInfo,1))){
        INVALID_PARAMS("Open Info must be a tuple with 2 integers.",NULL);
      }
      OpenInfo.dwOpenInfoSize=PyInt_AsUnsignedLongMask(PyTuple_GetItem(pyOpenInfo,0));
      OpenInfo.dwShareMode=PyInt_AsUnsignedLongMask(PyTuple_GetItem(pyOpenInfo,1));
      //printf("OpenInfo: %08x,%08x\n",OpenInfo.dwOpenInfoSize,OpenInfo.dwShareMode);
      dwRet= ETOpenEx(&self->context,&OpenInfo);
    }else{
      dwRet = ETOpen(&self->context);
    }
  #else
      dwRet = ETOpen(&self->context);
  #endif /*WIN32 | LINUX*/
    Py_XDECREF(pyOpenInfo);
    DWRET_VALIDATE(dwRet,NULL);
    Py_XINCREF(self);
    return self;
}
Esempio n. 13
0
/**
 *	Console command handler:	dmm unload
 */
static void cmd_dmm_unload(const idCmdArgs& args) {
	int unid = 0;
	int force = 0;

	if (sscanf(args.argv[2], "%i", &unid) < 1) {
		/* invalid conversion - bad parameter */
		CONSOLE_PRINTF(CINFO INVALID_PARAMS("unload"));
		return;
	}
	
	if (args.argc >= 4)
		/* force specified? */
		if (!cstrcmp(args.argv[3], "force"))
			force = 1;

	int op = unload_plugin_by_unid(unid, force);
		
	if (op == 0)
		CONSOLE_PRINTF(CINFO "Invalid plugin unid %i.\n", unid);
	else if ((op == 1) || (op == 2))
		CONSOLE_PRINTF(CINFO "Successfully unloaded plugin unid %i (%scleanly).\n", unid, (op == 1 ? "" : "not "));
	else 
		CONSOLE_PRINTF(CINFO "Plugin unid %i can not be unloaded.\n", unid);
}
Esempio n. 14
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;
}
Esempio n. 15
0
static PyObject *
ETContext_ctrl_set(ETContextObject* self, PyObject *args)
{
    DWORD ctrlcode=0,dwRet,dwOut,len;
    BYTE  buffer[24]={0};
    PyObject *pyParam=NULL;
    if (!PyArg_ParseTuple(args, "i|O", &ctrlcode,&pyParam)) {
      return NULL;
    }
    Py_XINCREF(pyParam);
    switch(ctrlcode){
      case ET_SET_DEVICE_ATR:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("ATR should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>16 || len<1){
          INVALID_PARAMS("ATR length must between 1~16!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_DEVICE_ATR,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_DEVICE_TYPE:
        if(NULL == pyParam || !PyInt_Check(pyParam)){
          INVALID_PARAMS("Param should be an integer.",NULL);
        }
        dwRet = PyInt_AsUnsignedLongMask(pyParam);
        if(dwRet!=ET_DEVICE_TYPE_PKI && dwRet!=ET_DEVICE_TYPE_DONGLE && dwRet!=ET_DEVICE_TYPE_EMPTY){
          INVALID_PARAMS("Device type should be 1,2 or 4!",NULL);
        }
        buffer[0] = dwRet;
        dwRet = ETControl(&self->context,ET_SET_DEVICE_ATR,buffer,1,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_SHELL_KEY:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("Shell key should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>8 || len<1){
          INVALID_PARAMS("ATR length must between 1~8!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_SHELL_KEY,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      case ET_SET_CUSTOMER_NAME:
        if(NULL == pyParam || !PyString_Check(pyParam)){
          INVALID_PARAMS("Customer name should provide must be a bytearray!",NULL);
        }
        len = PyString_Size(pyParam);
        if(len>250 || len<1){
          INVALID_PARAMS("ATR length must between 1~250!",NULL);
        }
        dwRet = ETControl(&self->context,ET_SET_CUSTOMER_NAME,PyString_AsString(pyParam),len,NULL,0,&dwOut);
        DWRET_VALIDATE(dwRet,NULL);
        break;
      default:
        INVALID_PARAMS("param must between ET_SET_DEVICE_ATR - ET_SET_CUSTOMER_NAME!",NULL);
        break;
    }
    Py_XDECREF(pyParam);
    Py_RETURN_TRUE;
}
Esempio n. 16
0
static PyObject *
ETContext_ctrl_get(ETContextObject* self, PyObject *args)
{
    DWORD ctrlcode=0,dwRet;
    BYTE  bFileId[5]={0};
    WORD  wFileId=0;
    DWORD fileIdLen=0,i;
    BYTE  outBuffer[256]={0},*pTmp;
    DWORD bytesReturned=0;
    PET_MANUFACTURE_DATE pManuDate=NULL;
    PEFINFO pFileInfo=NULL;
    PyObject *pyRet=NULL;
    if (!PyArg_ParseTuple(args, "i|H", &ctrlcode,&wFileId)) {
      return NULL;
    }

    switch(ctrlcode){
        case ET_GET_DEVICE_TYPE:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_TYPE,NULL,0,outBuffer,1,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0] as ?
            pyRet = Py_BuildValue("i",outBuffer[0]);
            break;
        case ET_GET_SERIAL_NUMBER:
            dwRet = ETControl(&self->context,ET_GET_SERIAL_NUMBER,NULL,0,outBuffer,9,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-7] as String
            return Py_BuildValue("z#",outBuffer,8);
            break;
        case ET_GET_DEVICE_USABLE_SPACE:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_USABLE_SPACE,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-3] as DWORD
            pyRet = Py_BuildValue("i",*(DWORD*)outBuffer);
            break;
        case ET_GET_DEVICE_ATR:
            dwRet = ETControl(&self->context,ET_GET_DEVICE_ATR,NULL,0,outBuffer,17,&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-15] as String
            pyRet = Py_BuildValue("z#",outBuffer,16);
            break;
        case ET_GET_CUSTOMER_NAME:
            dwRet = ETControl(&self->context,ET_GET_CUSTOMER_NAME,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-3] as DWORD
            pyRet = Py_BuildValue("I",*(DWORD*)outBuffer);
            break;
        case ET_GET_MANUFACTURE_DATE:
            pManuDate=(PET_MANUFACTURE_DATE)outBuffer;
            dwRet = ETControl(&self->context,ET_GET_MANUFACTURE_DATE,NULL,0,outBuffer,sizeof(ET_MANUFACTURE_DATE),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return pManuDate as DateTime
            #if 1
            pyRet = Py_BuildValue("(iiiiii)",2000+pManuDate->byYear,
                                              pManuDate->byMonth,
                                              pManuDate->byDay,
                                              pManuDate->byHour,
                                              pManuDate->byMinute,
                                              pManuDate->bySecond);
            #else //PyDateTime_FromDateAndTime cause a segmentation fault... WHY??
            Py_XINCREF()
            pyRet = PyDateTime_FromDateAndTime(2000+pManuDate->byYear,
                                              pManuDate->byMonth,
                                              pManuDate->byDay,
                                              pManuDate->byHour,
                                              pManuDate->byMinute,
                                              pManuDate->bySecond,
                                              0);
            #endif
            break;
        case ET_GET_DF_AVAILABLE_SPACE:
            dwRet = ETControl(&self->context,ET_GET_DF_AVAILABLE_SPACE,NULL,0,outBuffer,sizeof(DWORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-1] as WORD
            pyRet = Py_BuildValue("I",*(DWORD*)outBuffer);
            break;
        case ET_GET_EF_INFO:
            pFileInfo=(PEFINFO)outBuffer;
            if(bFileId==0){
                INVALID_PARAMS("An valid File Id should provide!",NULL);
            }
            sprintf(bFileId,"%04x",wFileId);
            dwRet = ETControl(&self->context,ET_GET_EF_INFO,bFileId,4,outBuffer,sizeof(EFINFO),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return pFileInfo as Dict
            pyRet = Py_BuildValue("{sHsbsI}",
                                    "wFileID",pFileInfo->wFileID,
                                    "bFileType",pFileInfo->bFileType,
                                    "wFileSize",pFileInfo->wFileSize);
            break;
        case ET_GET_COS_VERSION:
            dwRet = ETControl(&self->context,ET_GET_COS_VERSION,NULL,0,outBuffer,sizeof(WORD),&bytesReturned);
            DWRET_VALIDATE(dwRet,NULL);
            //Return outBuffer[0-1] as WORD
            pyRet = Py_BuildValue("H",*(WORD*)outBuffer);
            break;
        default:
            INVALID_PARAMS("param must between ET_GET_DEVICE_TYPE - ET_GET_COS_VERSION!",NULL);
            break;
    }
    Py_XINCREF(pyRet);
    return pyRet;
}