예제 #1
0
//! calculate hashes for entire reconstructed picture
Void SEIEncoder::initDecodedPictureHashSEI(SEIDecodedPictureHash *decodedPictureHashSEI, TComPic *pcPic, std::string &rHashString, const BitDepths &bitDepths)
{
  assert (m_isInitialized);
  assert (decodedPictureHashSEI!=NULL);
  assert (pcPic!=NULL);

  if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::MD5;
    UInt numChar=calcMD5(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
  else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::CRC;
    UInt numChar=calcCRC(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
  else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::CHECKSUM;
    UInt numChar=calcChecksum(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
}
예제 #2
0
int main(int argc, char** argv){

	if(argc != 2){
		printf("Invalid Arguments. Usage: raw_image_reader <path_to_file>\n");
		return -1;
	} 
	struct stat fstats;	
	int file = open(argv[1], O_RDONLY);
	MBR mbr;
	VBR vbr[NUM_OF_PARTITIONS];
	if(file<0){
		printf("Unable to open file");
		return -1;
	}
	printDivider();
	fstat(file, &fstats);
	calcMD5(file, fstats.st_size, argv[1]);
	calcSHA1(file, fstats.st_size, argv[1]);
	readMBR(file, (char*)&mbr);
	readVBR(file, &mbr, vbr);
	printDivider();
	printPartitions(&mbr);
	printDivider();
	printVBR(&mbr,vbr);
	close(file);
	return 1;
}
예제 #3
0
/**
*Send name,length and md5sum of all files in current directory(dropbox directory)
*/
int sendFileList(int *socket)
{
  DIR *d;
  FILE *fptr;
  struct dirent *dir;
  struct stat fileStat;
  char md5_hex[32];
  d = opendir("./");
  if(d)
  {
    while((dir = readdir(d)))
    {
      if(dir->d_type != DT_DIR )
      {
        if(stat(dir->d_name,&fileStat) < 0)   
        {
          fprintf(stderr,"Cannot retrieve informations about file %s.File will be ignored\n",dir->d_name);
          continue;
        }
        else
        {
          printf("Checking file %s ...",dir->d_name);
          fptr = fopen (dir->d_name, "rb");
          if (fptr == NULL)
          {
            fprintf(stderr,"Client failed to open file %s.Sync has stopped.Close this file and press enter to retry.\n",dir->d_name);
            return 0;
          }
          size_t sz;  //holds the length of the string to send (including NULL terminator)
          calcMD5(fptr,md5_hex);
          sz = snprintf(NULL,0,"%s/%d/%s/", dir->d_name,(int)fileStat.st_size,md5_hex) + 1; //snprintf will return the length of the string to send (excluding NULL terminator)
          char *msg = malloc(sz); //allocate sz bytes of memory using malloc
          memset(msg, 0, sz);  //clears the buffer
          snprintf(msg,sz,"%s/%d/%s/", dir->d_name,(int)fileStat.st_size,md5_hex); //store string at msg buffer
          if(!sendMessage(socket,msg))
          {
            free(msg);
            return 0;
          }
          free(msg);  //free dynamically allocated memory
          fclose(fptr);
          printf("\n");
        }
      }
    }
    closedir(d);
    sendMessage(socket,"\4");    //send EOT(=End Of Transmission,special ASCII char)
  }
  else
  {
    printf("Cannot open dropbox directory.Sync has stopped.\n");
    return 0;
  }
  return 1;
}
예제 #4
0
void initDevID(){
   
   static int iInitOk=0;
   if(iInitOk)return;
   iInitOk=1;
   memset(bufDevID,0,sizeof(bufDevID));
#if 0
   //depricated  6.0
   NSString *n = [[UIDevice currentDevice]uniqueIdentifier];
   
   const char *pn=n.UTF8String;
#else
   int iDevIdLen=0;
   char fn[1024];
   snprintf(fn,sizeof(fn)-1, "%s/devid-hex.txt", getFileStorePath());
   
   char *pn=loadFile(fn, iDevIdLen);
   
   if(!pn || iDevIdLen<=0){
      
      pn=&bufDevID[0];
      
      FILE *f=fopen("/dev/urandom","rb");
      if(f){
         unsigned char buf[T_MAX_DEV_ID_LEN_BIN+1];
         fread(buf,1,T_MAX_DEV_ID_LEN_BIN,f);
         fclose(f);
         void bin2Hex(unsigned char *Bin, char * Hex ,int iBinLen);
         bin2Hex(buf, bufDevID, T_MAX_DEV_ID_LEN_BIN);
         bufDevID[T_MAX_DEV_ID_LEN]=0;
         
         saveFile(fn, bufDevID, T_MAX_DEV_ID_LEN);
         setFileAttributes(fn,0);
      }
      
   }
   
#endif
   void safeStrCpy(char *dst, const char *name, int iMaxSize);
   safeStrCpy(&bufDevID[0],pn,sizeof(bufDevID)-1);
   
   int calcMD5(unsigned char *p, int iLen, char *out);
   calcMD5((unsigned char*)pn,strlen(pn),&bufMD5[0]);
   
   
}
예제 #5
0
	// メイン処理
	virtual unsigned worker() {
		m_md5 = calcMD5(m_targetFile.c_str());
		return 0;
	}
예제 #6
0
/**
 * Calculate and print hash for pic, compare to picture_digest SEI if
 * present in seis.  seis may be NULL.  Hash is printed to stdout, in
 * a manner suitable for the status line. Theformat is:
 *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
 * Where, x..x is the hash
 *        yyy has the following meanings:
 *            OK          - calculated hash matches the SEI message
 *            ***ERROR*** - calculated hash does not match the SEI message
 *            unk         - no SEI message was available for comparison
 */
static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
{
  /* calculate MD5sum for entire reconstructed picture */
  UChar recon_digest[3][16];
  Int numChar=0;
  const Char* hashType = "\0";

  if (pictureHashSEI)
  {
    switch (pictureHashSEI->method)
    {
    case SEIDecodedPictureHash::MD5:
      {
        hashType = "MD5";
        calcMD5(pic, recon_digest);
        numChar = 16;
        break;
      }
    case SEIDecodedPictureHash::CRC:
      {
        hashType = "CRC";
        calcCRC(pic, recon_digest);
        numChar = 2;
        break;
      }
    case SEIDecodedPictureHash::CHECKSUM:
      {
        hashType = "Checksum";
        calcChecksum(pic, recon_digest);
        numChar = 4;
        break;
      }
    default:
      {
        assert (!"unknown hash type");
      }
    }
  }

  /* compare digest against received version */
  const Char* ok = "(unk)";
  Bool mismatch = false;

  if (pictureHashSEI)
  {
    ok = "(OK)";
    for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
    {
      for (UInt i = 0; i < numChar; i++)
      {
        if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
        {
          ok = "(***ERROR***)";
          mismatch = true;
        }
      }
    }
  }

  printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok);

  if (mismatch)
  {
    g_md5_mismatch = true;
    printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
  }
}
예제 #7
0
파일: genhash.cpp 프로젝트: luyikei/GenHash
void GenHash::calcGenHash()
{
    sandbox_init();

    // cannot excute execve
    prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
    kDebug() << "execve" << execve("ls",NULL,NULL);

    if (child_pid){

        KParts::ReadOnlyPart * part = qobject_cast<KParts::ReadOnlyPart *>(parent());

        QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///konqueror"), i18n("*"), part->widget(), i18n("Open File To make MD5.")));

        if (!file.open(QIODevice::ReadOnly))
        {
            return;
        }

        // TODO QFile
        //char s[1024];

        // write file content
        {
            close(pipe_fd[0]);
            QByteArray s = file.readAll();
            char *ch = s.data();
            if (write(pipe_fd[1], ch, s.size()) < 0) {
                perror("write");
            }
            close(pipe_fd[1]);
        }

        //read result
        {
            close(pipe_result_fd[1]);
            char result[128];
            if (read(pipe_result_fd[0], &result[0], 128) < 0){
                perror("read");
            }
            close(pipe_result_fd[0]);

            KMessageBox::information(part->widget(),i18n("Md5 : %1").arg(QString(QByteArray(result, 128))));
        }

    }else{

        scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL);
        seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
        seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 3,
                                   SCMP_A0(SCMP_CMP_EQ, (scmp_datum_t)pipe_fd[0]),
                                   SCMP_A1(SCMP_CMP_EQ, (scmp_datum_t)buff),
                                   SCMP_A2(SCMP_CMP_LE, 1024));
        seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1,
                                    SCMP_CMP(0, SCMP_CMP_EQ, (scmp_datum_t)pipe_result_fd[1]));

        seccomp_load(ctx);
        seccomp_release(ctx);

        calcMD5();
    }
}