CallReplace::CallReplace(ElfFile* elf, char* traceFile, char* libList)
    : InstrumentationTool(elf)
{
    programEntry = NULL;
    programExit = NULL;

    functionList = new Vector<char*>();
    initializeFileList(traceFile, functionList);

    // replace any ':' character with a '\0'
    for (uint32_t i = 0; i < (*functionList).size(); i++){
        char* both = (*functionList)[i];
        uint32_t numrepl = 0;
        for (uint32_t j = 0; j < strlen(both); j++){
            if (both[j] == ':'){
                both[j] = '\0';
                numrepl++;
            }
        }
        if (numrepl != 1){
            PRINT_ERROR("input file %s line %d should contain a ':'", traceFile, i+1);
        }
    }

    Vector<uint32_t> libIdx;
    libIdx.append(0);
    uint32_t listSize = strlen(libList);
    for (uint32_t i = 0; i < listSize; i++){
        if (libList[i] == ','){
            libList[i] = '\0';
            libIdx.append(i+1);
        }
    }
    for (uint32_t i = 0; i < libIdx.size(); i++){
        if (libIdx[i] < listSize){
            libraries.append(libList + libIdx[i]);
        } else {
            PRINT_ERROR("improperly formatted library list given to call replacement tool");
            __SHOULD_NOT_ARRIVE;
        }
    }

    for (uint32_t i = 0; i < libraries.size(); i++){
        PRINT_INFOR("library -- %s", libraries[i]);
    }

}
Exemple #2
0
void initializeFileList(char *name, int level){
	DIR *dir;
	struct dirent *ent;
	char path[1024]="";
    char t[ 512 ] = "";
	
	char ctime[100], mtime[100], atime[100];
	
    int len;
	struct stat b;
	if (!(dir = opendir(name))) return;
    if (!(ent = readdir(dir))) return;
	do{
        // if folder
        if (ent->d_type == DT_DIR){
            if(strcmp(ent->d_name,"..")==0) len = snprintf(path, sizeof(path)-1, "%s", name);
            else{
				len = snprintf(path, sizeof(path)-1, "%s/%s", name, ent->d_name);
			}
            path[len] = 0;
            if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue;
            initializeFileList(path,level+1);
        }
        else{
        	len = snprintf(path, sizeof(path)-1, "%s", name);
			char *ext=strrchr(ent->d_name, '.');			// gets extension of a file
            char file[strlen(path)+strlen(ent->d_name)+1];
            strcpy(file,path);
            strcat(file,"/");
            strcat(file,ent->d_name);
			stat(file, &b);
			
			
			char *sha=getSha2(file);
			
			/* file1 */
			fprintf(file1, "%s|", sha);
			
			fprintf(file2, "%s|",file);
			fprintf(file2, "%s|",sha);
			
			int size=getSize(file);
            fprintf(file1, "%d|", size);
			fprintf(file2, "%d|",size);

            strftime(ctime, 100, "%S:%M:%H:%d:%m:%Y", localtime(&b.st_ctime));
            //fprintf(file1, "%s|",ctime);
			//fprintf(file2, "%s|",ctime);
			printf("CREATED: %s\n", ctime);

            strftime(mtime, 100, "%S:%M:%H:%d:%m:%Y", localtime(&b.st_mtime));
            //printf("%s|",t);
            //fprintf(file1, "%s|",mtime);
			//fprintf(file2, "%s|",mtime);
			printf("MODIFIED: %s\n", mtime);

            strftime(atime, 100, "%S:%M:%H:%d:%m:%Y", localtime(&b.st_atime));
            //printf("%s",t);
			//fprintf(file2, "%s\n", atime);
			//strcat(atime,"|");
            //fprintf(file1, "%s||\"%s\"\n",atime,file);
			
			/* EXPERIMENT: File Age
			 * Note: Since File Age can be edited, we should proceed cautiously.
			 * File Age is considered to be [NOW] - [Created / Last Modified Time] in seconds
			 *
			 * TASKS:
			 * [X] Compare Created Time and Modified Time (get what's earlier)
			 * [X] Get current time
			 * [X] Get year and months for each of the two times
			 * [X] Get difference and place it.
			 * [ ] Stamp File Age (in terms of days)
			 */
			
			char *splitCr[6], *splitMo[6], *splitCurr[6];
			int i = 0;
			
			//Parse created time and modified time and current time
			i = 0;
			splitCr[i] = strtok(ctime, ":");
			while (splitCr[i] != NULL) {
				splitCr[++i] = strtok(NULL, ":");
			}
			
			i = 0;
			splitMo[i] = strtok(mtime, ":");
			while (splitMo[i] != NULL) {
				splitMo[++i] = strtok(NULL, ":");
			}	

			time_t nownow;
			time(&nownow);
			strftime(t, 100, "%S:%M:%H:%d:%m:%Y", localtime(&nownow));
			
			printf("CURRENT TIME: %s\n", t);
			
			i = 0;
			splitCurr[i] = strtok(t, ":");
			while (splitCurr[i] != NULL) {
				splitCurr[++i] = strtok(NULL, ":");
			}
			
			//Semaphore for Created (0) or Modified (1)
			int mode = 0;
			
			//Compare created and modified time
			//UGH THIS IS SO DIRTY
			if (atoi(splitCr[5]) < atoi(splitMo[5])) {			//year
				mode = 0;
			} else if (atoi(splitCr[5]) > atoi(splitMo[5])) {		
				mode = 1;
			} else {											
				if (atoi(splitCr[4]) < atoi(splitMo[4])) {		//month
					mode = 0;
				} else if (atoi(splitCr[4]) > atoi(splitMo[4])) {
					mode = 1;
				} else {				
					if (atoi(splitCr[3]) < atoi(splitMo[3])) {	//day
						mode = 0;
					} else if (atoi(splitCr[3]) > atoi(splitMo[3])) {
						mode = 1;
					} else {									//hour
						if (atoi(splitCr[2]) < atoi(splitMo[2])) {
							mode = 0;
						} else if (atoi(splitCr[2]) > atoi(splitMo[2])) {
							mode = 1;
						} else {								//minute
							if (atoi(splitCr[1]) < atoi(splitMo[1])) {
								mode = 0;
							} else if (atoi(splitCr[1]) > atoi(splitMo[1])) {
								mode = 1;
							} else {
								printf("LOL THIS IS THE END!");
							}
						}
					}
				}
			}
			
			int diffyear = 0, diffmonth = 0, diffday = 0, diffhour = 0;
			
			//Get "File Age" of file
			if (mode == 0) {				//Created
				printf("USE CREATED!!!\n");
				diffyear = abs(atoi(splitCr[5]) - atoi(splitCurr[5]));
				diffmonth = abs(atoi(splitCr[4]) - atoi(splitCurr[4]));
				diffday = abs(atoi(splitCr[3]) - atoi(splitCurr[3]));
				diffhour = abs(atoi(splitCr[2]) - atoi(splitCurr[2]));	
			} else if (mode == 1) {
				printf("USE MODIFIED!!!\n");
				diffyear = abs(atoi(splitMo[5]) - atoi(splitCurr[5]));
				diffmonth = abs(atoi(splitMo[4]) - atoi(splitCurr[4]));
				diffday = abs(atoi(splitMo[3]) - atoi(splitCurr[3]));
				diffhour = abs(atoi(splitMo[2]) - atoi(splitCurr[2]));	
			}
			
			//Test
			for (i = 0; i < 6; i++)
				printf("$ %s %s %s\n", splitCurr[i], splitCr[i], splitMo[i]);
			
			//Convert in terms of days (leap year automatically assumed 365, month assumed 30)
			diffday += (diffyear*365) + (diffmonth*30);
			
			fprintf(file2, "%d\n", diffday);
			fprintf(file1, "%d||\"%s\"\n",diffday,file);
		}
			
			
    }while (ent = readdir(dir));

}
Exemple #3
0
int raf() {
	int i=1,
        folderNum=0,
        folderChoice=0,br=0;
    
    struct dirent *ent;
	FILE *f;
	do{
		printf("\n[1] Initialize a backup session from scratch (this clears hashcatalog.txt)");
	    printf("\n[2] Delete chunk files");
		printf("\n[3] Deduplicate \"Files\" folder\n[4] Exit\n:");
		scanf("%d",&folderChoice);
		
		/* code according to choice */
		switch(folderChoice){
			case 1:{
				FILE *ff;
				ff=fopen("hashcatalog.txt","w");
				fclose(ff);
				ff=fopen("cache.txt","w");
				fprintf(ff,"onwoief\n");
				fclose(ff);

				DIR *dir;
				struct dirent *ent2;
				if(!(dir = opendir("./Outputs"))){ printf("No \"Outputs\" folder!"); return;}
				if(!(ent2 = readdir(dir))) return;
				do{
					if(strcmp(ent2->d_name,"..")!=0 && strcmp(ent2->d_name,".")!=0){
						char tempStr[9+strlen(ent2->d_name)];
						strcpy(tempStr,"./Outputs/");
						strcat(tempStr,ent2->d_name);
						remove(tempStr);
					}
				}while (ent2 = readdir(dir));
				printf("Cleared");
				break;
			}case 2:{
				DIR *dirDel;
				struct dirent *entDel;
				
				if (!(dirDel = opendir("./chunkstempofolder"))) return;
				if (!(entDel = readdir(dirDel))) return;
				do{
					if(entDel->d_type!=DT_DIR){
						char strDel[strlen(entDel->d_name)+100];
						strcpy(strDel,"./chunkstempofolder/");
						strcat(strDel,ent->d_name);
						remove(strDel);
					}
				}while(ent = readdir(dirDel));
				closedir(dirDel);
				break;
			}case 3:{
				file1=fopen("initFiles.txt","w+");
				file2=fopen("./Outputs/out.Files","w+");
				
				initializeFileList("./Files",0);
				fclose(file1);
				fclose(file2);
				br=1;
				break;
			}case 4:{
				br=1;
				break;
			}
		}
		//////////////////////////////
		
	}while(!br);
	if(folderChoice==3) return 1;
	else return 0;
}