Ejemplo n.º 1
0
void
AnyOption::justValue( char *type )
{

	if ( strlen(chomp(type)) == 1  ){ /* this is a char option */
		for( int i = 0 ; i < optchar_counter ; i++ ){
			if(  optionchars[i] == type[0]  ){ /* match */
				if( optchartype[i] == COMMON_FLAG ||
				    optchartype[i] == FILE_FLAG )
				{
			 		setFlagOn( type[0] );
			 		return;
				}
			}
		}
	}	
	/* if no char options matched */
	for( int i = 0 ; i < option_counter ; i++ ){
		if( strcmp( options[i], type ) == 0 ){ /* match */
			if( optiontype[i] == COMMON_FLAG ||
			    optiontype[i] == FILE_FLAG )
			{
		 		setFlagOn( type );
		 		return;
			}
		}
	}
        printVerbose( "Unknown option in resourcefile : " );
	printVerbose( type  );
	printVerbose( );
}
Ejemplo n.º 2
0
int
AnyOption::parseGNU( char *arg )
{
	int split_at = 0;
	/* if has a '=' sign get value */
	for( unsigned int i = 0 ; i < strlen(arg) ; i++ ){
		if(arg[i] ==  equalsign ){
			split_at = i ; /* store index */
			i = strlen(arg); /* get out of loop */
		}
	}
	if( split_at > 0 ){ /* it is an option value pair */
		char* tmp = (char*) malloc(  (split_at+1)*sizeof(char) );
		for( int i = 0 ; i < split_at ; i++ )
			tmp[i] = arg[i];
		tmp[split_at] = '\0';

		if ( matchOpt( tmp ) >= 0 ){
			setValue( options[matchOpt(tmp)] , arg+split_at+1 );
			free (tmp);
		}else{
			printVerbose( "Unknown command argument option : " );
			printVerbose( arg );
			printVerbose( );
			printAutoUsage();
			free (tmp);
			return -1;
		}
	}else{ /* regular options with no '=' sign  */
		return  matchOpt(arg);
	}
	return -1;
}
Ejemplo n.º 3
0
char 
AnyOption::parsePOSIX( char* arg )
{

	for( unsigned int i = 0 ; i < strlen(arg) ; i++ ){ 
		char ch = arg[i] ;
		if( matchChar(ch) ) { /* keep matching flags till an option */
			/*if last char argv[++i] is the value */
			if( i == strlen(arg)-1 ){ 
				return ch;
			}else{/* else the rest of arg is the value */
				i++; /* skip any '=' and ' ' */
				while( arg[i] == whitespace 
			    		|| arg[i] == equalsign )
					i++;	
				setValue( ch , arg+i );
				return '0';
			}
		}
	}
	printVerbose( "Unknown command argument option : " );
	printVerbose( arg );
	printVerbose( );
	printAutoUsage();
	return '0';
}
Ejemplo n.º 4
0
//return 0 on no error
static int tskDataSourceOpen(ScalpelInputReader * const reader) {
	printVerbose("tskDataSourceOpen()\n");

	JNIEnv * env = attachThread();
	TskInputStreamSourceInfo * tskData = castTskDataSource(reader);
	if (!tskData) {
		setThrowScalpelException(* (env), "tskDataSourceOpen() - ERROR object not initialized");
		detachThread();
		return -1;
	}

	if (reader->isOpen) {
		fprintf(stdout, "tskDataSourceOpen() WARNING stream already open\n");
		//already open, should really close first, reset
		jlong zerOff = env->CallLongMethod(tskData->jInputStream, tskData->jSeekMethodId, (jlong)0);
		fprintf(stdout, "tskDataSourceOpen() rewinded, new offset: %"PRI64 "\n", (long long) zerOff);
	}
	else if (!tskData->firstOpen) {
		//closed but had already been open, so need to rewind to start
		//const jlong jnewOff =
		jlong zerOff = env->CallLongMethod(tskData->jInputStream, tskData->jSeekMethodId, (jlong)0);
		fprintf(stdout, "tskDataSourceOpen() rewinded, new offset: %"PRI64 "\n", (long long) zerOff);
	}


	reader->isOpen = TRUE;
	tskData->firstOpen = FALSE;
	detachThread();

	return 0;
}
Ejemplo n.º 5
0
int scalpelInputRead(ScalpelInputReader * const reader, 
                     void * buf, size_t size,
	             	 size_t count) 
{
    printVerbose("scalpelInputRead()\n");
    return reader->read(reader, buf, size, count);
}
Ejemplo n.º 6
0
int scalpelInputSeeko(ScalpelInputReader * const reader, 
                      long long offset,
		              scalpel_SeekRel whence) 
{
    printVerbose("scalpelInputSeeko()\n");
    return reader->seeko(reader, offset, whence);
}
Ejemplo n.º 7
0
long long scalpelInputGetSize(ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputGetSize()\n");
    if (!reader->open) {
        fprintf(stderr, "scalpelInputGetSize() - ERROR trying to get size on closed reader\n");
        return -1;
    }
    return reader->getSize(reader);
}
Ejemplo n.º 8
0
//return 0 on no-error
static int tskDataSourceSeekO(ScalpelInputReader * const reader, long long offset,
		scalpel_SeekRel whence) {
	printVerbose("tskDataSourceSeekO()\n");
	//fprintf (stdout, "tskDataSourceSeekO() offset: %"PRI64 "whence: %d\n", offset, whence);
	JNIEnv * env = attachThread();
	const TskInputStreamSourceInfo * tskData = castTskDataSource(reader);
	if (!tskData) {
		setThrowScalpelException(* (env), "tskDataSourceSeekO() - ERROR object not initialized");
		detachThread();
		return -1;
	}

	jlong newOffset = 0;
	jlong joffRel = 0;
	switch (whence) {
	case SCALPEL_SEEK_SET:
		newOffset = offset;
		break;
	case SCALPEL_SEEK_CUR:
		//get cur
		joffRel = env->CallLongMethod(tskData->jInputStream, tskData->jGetPositionMethodId);
		newOffset = offset + joffRel;
		break;
	case SCALPEL_SEEK_END:
		//get size
		joffRel = env->CallLongMethod(tskData->jInputStream, tskData->jGetSizeMethodId);
		newOffset = joffRel - offset; //TODO verify if need -1
		break;
	default:
		break;
	}

	if (newOffset < 0) {
		setThrowScalpelException(* (env), "tskDataSourceSeekO() - ERROR invalid negative resulting offset.");
		detachThread();
		return -1;
	}

	//const jlong jnewOff =
	env->CallLongMethod(tskData->jInputStream, tskData->jSeekMethodId, newOffset);

	if (env->ExceptionCheck() ){
		env->ExceptionDescribe();
		env->ExceptionClear();
		setThrowScalpelException(* (env), "tskDataSourceSeekO() - ERROR seek failed.");
		detachThread();
		return -1;
	}

	detachThread();

	//fprintf(stdout, "tskDataSourceSeekO() deltaOffset: %"PRI64", new offset: %"PRI64 "\n", newOffset, (long long) jnewOff);

	return 0;

}
Ejemplo n.º 9
0
int AnyOption::matchOpt (char *opt) {
        for (int i = 0; i < option_counter; i++) {
                if (strcmp (options[i], opt) == 0) {
                        if (optiontype[i] == COMMON_OPT || optiontype[i] == COMMAND_OPT) {
                                /* found option return index */
                                return i;
                        } else if (optiontype[i] == COMMON_FLAG || optiontype[i] == COMMAND_FLAG) {
                                /* found flag, set it */
                                setFlagOn (opt);
                                return -1;
                        }
                }
        }
        printVerbose ("Unknown command argument option : ");
        printVerbose (opt);
        printVerbose ();
        printAutoUsage ();
        return -1;
}
Ejemplo n.º 10
0
bool AnyOption::matchChar (char c) {
        for (int i = 0; i < optchar_counter; i++) {
                if (optionchars[i] == c) { /* found match */
                        if (optchartype[i] == COMMON_OPT || optchartype[i] == COMMAND_OPT) {
                                /* an option store and stop scanning */
                                return true;
                        } else if (optchartype[i] == COMMON_FLAG ||
                                   optchartype[i] == COMMAND_FLAG) { /* a flag store and keep scanning */
                                setFlagOn (c);
                                return false;
                        }
                }
        }
        printVerbose ("Unknown command argument option : ");
        printVerbose (c);
        printVerbose ();
        printAutoUsage ();
        return false;
}
Ejemplo n.º 11
0
void AnyOption::addOption (char opt, int type) {
        if (!POSIX ()) {
                printVerbose ("Ignoring the option character \"");
                printVerbose (opt);
                printVerbose ("\" ( POSIX options are turned off )");
                printVerbose ();
                return;
        }

        if (optchar_counter >= max_char_options) {
                if (doubleCharStorage () == false) {
                        addOptionError (opt);
                        return;
                }
        }
        optionchars[optchar_counter] = opt;
        optchartype[optchar_counter] = type;
        optcharindex[optchar_counter] = g_value_counter;
        optchar_counter++;
}
Ejemplo n.º 12
0
static void tskDataSourceClose(ScalpelInputReader * const reader) {
	printVerbose("tskDataSourceClose()\n");
	//nothing to be done, client closed the stream on java side and reset pos
	if (! reader->isOpen) {
		return;
	}

	reader->isOpen = FALSE;

	return;
}
Ejemplo n.º 13
0
void scalpelInputClose(ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputClose()\n");
    if (!reader->isOpen) {
        fprintf(stderr, "scalpelInputClose() -- ERROR -- reader for %s is not open, can't close\n", reader->id);
        return;
    }
    reader->close(reader);
    reader->isOpen = 0;
    return;
}
Ejemplo n.º 14
0
ScalpelInputReader * scalpel_createInputReaderFile(const char * const filePath) 
{
    printVerbose("createInputReaderFile()\n");

    ScalpelInputReader * fileReader = (ScalpelInputReader *) malloc(
        sizeof(ScalpelInputReader));
    if (!fileReader) {
        fprintf(stderr, "createInputReaderFile() - malloc() ERROR fileReader not created\n ");
        return NULL ;
    }

    //setup data

    size_t pathLen = strlen(filePath);
    fileReader->id = (char*) malloc((pathLen + 1) * sizeof(char));
    strncpy(fileReader->id, filePath, pathLen);
    fileReader->id[pathLen] = '\0';

    fileReader->dataSource = (void*) malloc(sizeof (FileDataSource) );
    if (!fileReader->dataSource) {
        fprintf(stderr, "createInputReaderFile() - malloc() ERROR dataSource not created\n ");
        return NULL ;
    }

    FileDataSource * fileSource = (FileDataSource *) fileReader->dataSource;
    fileReader->isOpen = 0;
    fileSource->fileHandle = NULL;

    //set up functions
    fileReader->open = fileDataSourceOpen;
    fileReader->close = fileDataSourceClose;
    fileReader->getError = fileDataSourceGetError;
    fileReader->getSize = fileDataSourceGetSize;
    fileReader->seeko = fileDataSourceSeekO;
    fileReader->tello = fileDataSourceTellO;
    fileReader->read = fileDataSourceRead;

    printVerbose("createInputReaderFile -- input reader created\n");

    return fileReader;
}
Ejemplo n.º 15
0
//return size, or -1 on error
static long long tskDataSourceGetSize(ScalpelInputReader * const reader) {
	printVerbose("tskDataSourceGetSize()\n");
	JNIEnv * env = attachThread();
	const TskInputStreamSourceInfo * tskData = castTskDataSource(reader);
	if (!tskData) {

		setThrowScalpelException(* (env), "tskDataSourceGetSize() - ERROR object not initialized");
		detachThread();
		return -1;
	}

	const jlong jsize = env->CallLongMethod(tskData->jInputStream, tskData->jGetSizeMethodId);

	detachThread();

	return (long long) jsize;
}
Ejemplo n.º 16
0
static unsigned long long tskDataSourceTellO(ScalpelInputReader * const reader) {
	printVerbose("tskDataSourceTellO()\n");
	JNIEnv * env = attachThread();
	const TskInputStreamSourceInfo * tskData = castTskDataSource(reader);
	if (!tskData) {
		setThrowScalpelException(*env, "tskDataSourceTellO() - ERROR object not initialized");
		detachThread();
		return 0;
	}

	const jlong joff = env->CallLongMethod(tskData->jInputStream, tskData->jGetPositionMethodId);

	detachThread();

	fprintf(stdout, "tskDataSourceTellO() ret %"PRIu64 "\n", joff );

	return (unsigned long long) joff;
}
Ejemplo n.º 17
0
void readFile(char *file)
{
  int fd;
  int num_files;
  header *fileHeader[1000];

  if((fd = open(file, O_RDONLY)) == -1)
  {
    perror("open");
    exit(EXIT_FAILURE);
  }
  
  num_files = readTar(fileHeader, fd);
  
  if(v_flag)
    printVerbose(fileHeader, num_files);
  else
    printFiles(fileHeader, num_files);

  return;
}
Ejemplo n.º 18
0
void
AnyOption::processCommandArgs()
{
    if(!(valueStoreOK() && CommandSet())) {
        return;
    }

    if(max_legal_args == 0) {
        max_legal_args = argc;
    }
    new_argv = (int*) malloc((max_legal_args+1) * sizeof(int));
    for(int i = 1 ; i < argc ; i++) { /* ignore first argv */
        if(argv[i][0] == long_opt_prefix[0] &&
           argv[i][1] == long_opt_prefix[1]) {  /* long GNU option */
            int match_at = parseGNU(argv[i]+2);   /* skip -- */
            if(match_at >= 0 && i < argc-1) { /* found match */
                setValue(options[match_at], argv[++i]);
            }
        } else if(argv[i][0] ==  opt_prefix_char) {   /* POSIX char */
            if(POSIX()) {
                char ch =  parsePOSIX(argv[i]+1);  /* skip - */
                if(ch != '0' && i < argc-1) { /* matching char */
                    setValue(ch,  argv[++i]);
                }
            } else { /* treat it as GNU option with a - */
                int match_at = parseGNU(argv[i]+1);   /* skip - */
                if(match_at >= 0 && i < argc-1) { /* found match */
                    setValue(options[match_at], argv[++i]);
                }
            }
        } else { /* not option but an argument keep index */
            if(new_argc < max_legal_args) {
                new_argv[ new_argc ] = i ;
                new_argc++;
            } else { /* ignore extra arguments */
                printVerbose("Ignoring extra argument: ");
                printVerbose(argv[i]);
                printVerbose();
                printAutoUsage();
            }
            printVerbose("Unknown command argument option : ");
            printVerbose(argv[i]);
            printVerbose();
            printAutoUsage();
        }
    }
}
Ejemplo n.º 19
0
void scalpel_freeInputReaderFile(ScalpelInputReader * fileReader) 
{
    printVerbose("freeInputReaderFile()\n");
    if (!fileReader) {
        return;
    }

    if (!fileReader->dataSource) {
        fprintf(stderr, "freeInputReaderFile() - ERROR dataSource not set, can't free\n ");
        return; //ERROR
    }

    FileDataSource * fileSource = (FileDataSource *) fileReader->dataSource;
    FILE * fileHandle = fileSource->fileHandle;

    if (fileReader->isOpen) {
        if (fileHandle) {
            fclose(fileHandle);
            fileReader->isOpen = 0;
            fileHandle = NULL;
        } else {
            //ERROR
            fprintf(stderr, "freeInputReaderFile() - WARNING reader open, but handle not set\n");
        }

    }

    if (fileReader->id) {
        free(fileReader->id);
        fileReader->id = NULL;
    }

    free(fileReader->dataSource);
    fileReader->dataSource = NULL;
    free(fileReader);
}
Ejemplo n.º 20
0
int flagOptions::completeTrade(pair<string, equityT*> op, bool x){
    
    int returnValue = 0;
    bool trueOrFalse = true;
    orderLine* buyer;
    unsigned  int zero = 0;
    orderLine* seller;
    if(op.second->empty() == true || op.first.empty() == true){
        return returnValue;
    }
    while(trueOrFalse){
        trueOrFalse = false;
        if(op.second->blimit >= op.second->slimit){
            buyer = op.second->buy.top();
            seller = op.second->sell.top();
            pp.first = buyer->client_name;
            pp.second = seller->client_name;
            if(x == true){
                buyer->timestamp = buyer->position;
                seller->timestamp = seller->position;
            }
            if(buyer->position < seller->position)
                xx.second = buyer->price;
            else if(buyer->position >= seller->position)
                xx.second = seller->price;
            if(buyer->quantity <= seller->quantity){
                xx.first = buyer->quantity;
            }
            else if(buyer->quantity > seller->quantity)
                xx.first = seller->quantity;
            seller->quantity = (seller->quantity - xx.first);
            buyer->quantity = (buyer->quantity - xx.first);
            printVerbose(buyer, seller,xx);
            if(buyer->quantity == zero) {
                op.second->buy.pop();
                if(op.second->buy.empty()) {
                    op.second->blimit = zero;
                }
                else{
                    int cost = op.second->buy.top()->price;
                    op.second->blimit = cost;
                }
            }
            else if(seller->quantity == zero) {
                op.second->sell.pop();
                if(op.second->sell.empty())
                    op.second->slimit = INT_MAX;
                else{
                    int cost = op.second->sell.top()->price;
                    op.second->slimit = cost;
                }
            }
            int zeroo = 0;
            trueOrFalse = true;
            if(xx.first > zeroo){
                returnValue = 1;
                //Add Transfers
                //Add Summary
                addSummary();
                medianMap[op.first].insertMedian(xx.second);
            }
        }
        
        else
            trueOrFalse = false;
    }
    return returnValue;
}
Ejemplo n.º 21
0
int main(void){
    FILE* fp = fopen("historicaldata.csv","r");
    struct DailyData  allData[3000];
    struct DailyData yearData[366];
    int numTotalRecords;
    numTotalRecords = readDailyData(fp, allData);
    int year;
    int reportType;
    struct MonthlyStatistic monthly[12];
    
    printf("Please enter the year for the report: ");
    scanf("%d",&year);
    printf("Please enter the type of report you wish to generate:\n");
    printf("1) summary\n");
    printf("2) detailed\n");
    scanf("%d",&reportType);
    
    int numDays = getRelevantRecords(year,allData,numTotalRecords,yearData);

    /*int j;

    printf("\nUNSORTED RECORDS\n");

    for(j=0; j < numDays; j++){      //test getRelevantRecords output =OK

        printf("%d,%d,%d,%f,%f,%f,%c\n",yearData[j].year,yearData[j].month,yearData[j].day,
                                        yearData[j].high,yearData[j].low,yearData[j].precipitation,
                                        yearData[j].condition);   
    }*/

    sortYearData(yearData,numDays);


    /*printf("\nSORTED RECORDS\n");

    for(j=0; j < numDays; j++){      //test sortYearData output =

        printf("%d,%d,%d,%f,%f,%f,%c\n",yearData[j].year,yearData[j].month,yearData[j].day,
                                        yearData[j].high,yearData[j].low,yearData[j].precipitation,
                                        yearData[j].condition);   
    }*/



    for(int i=0;i<12;i++){
        getStats(i+1,yearData,numDays,&monthly[i]);           //what does it mean &monthly[i]?
    }

    
    printf("\nWeather summary for %d\n\n",year);
    printf("|-----------|-------|-------|-------|---------|\n");
    printf("|   Month   | High  |  Low  |  Avg  | Precip  |\n");
    printf("|-----------|-------|-------|-------|---------|\n");
    
    for(int i=0;i<12;i++){
        printMonthlyStatistic(i+1,&monthly[i]);
    }
    
    printf("\n\n");
    printf("Precipitation Graph\n\n");
    
    for (int i=0;i<12;i++){
        graphLine(i+1,&monthly[i]);
    }
   
    if(reportType == 2){
        printf("\n\n");
        printf("Detailed report:\n");
        printVerbose(yearData,numDays);
    }
    return 0;
}
Ejemplo n.º 22
0
static int tskDataSourceGetError(ScalpelInputReader * const reader) {
	printVerbose("tskDataSourceGetError()\n");
	//not implemented
	return 0;
}
Ejemplo n.º 23
0
static ScalpelInputReader * createInputReaderTsk(JNIEnv & env, const char * inputId, jobject jInputStream) {
	printVerbose("createInputReaderTsk()\n");

	ScalpelInputReader * tskReader = (ScalpelInputReader *) malloc(
			sizeof(ScalpelInputReader));
	if (!tskReader) {
		fprintf(stdout, "createInputReaderTsk() - malloc() ScalpelInputReader ERROR tskReader not created\n ");
		setThrowScalpelException(env, "createInputReaderTsk() - malloc() ScalpelInputReader ERROR tskReader not created");
		return NULL ;
	}

	//setup data
	tskReader->id = const_cast<char*> (inputId);

	tskReader->dataSource = (TskInputStreamSourceInfo*) malloc(sizeof(TskInputStreamSourceInfo));
	if (!tskReader->dataSource) {
		free(tskReader);
		tskReader = NULL;
		fprintf(stdout, "createInputReaderTsk() - malloc() TskInputStreamSourceInfo ERROR tskReader not created\n ");
		setThrowScalpelException(env, "createInputReaderTsk() - malloc() TskInputStreamSourceInfo  ERROR tskReader not created");
		return NULL ;
	}

	TskInputStreamSourceInfo* tskData = (TskInputStreamSourceInfo*) tskReader->dataSource;

	tskData->firstOpen = TRUE;

	tskData->jInputStream = jInputStream;

	//alloc java read buffer
	jbyteArray jReadBuffer = env.NewByteArray(JAVA_READ_BUFFER_SIZE);
	if (!jReadBuffer || env.ExceptionCheck()) {
		fprintf(stdout, "createInputReaderTsk() - ERROR allocating read buffer\n ");
		if (env.ExceptionCheck() ){
			env.ExceptionDescribe();
		}
		setThrowScalpelException(env,  "createInputReaderTsk() - ERROR allocating read buffer");
		tskData->jInputStream = NULL;
		free(tskReader->dataSource);
		tskReader->dataSource = NULL;
		free(tskReader);
		tskReader = NULL;
		return NULL ;
	}

	tskData->jReadBuffer = (jbyteArray) env.NewGlobalRef(jReadBuffer);
	if (! tskData->jReadBuffer) {
		fprintf(stdout, "createInputReaderTsk() - ERROR creating read buffer global ref\n ");
		if (env.ExceptionCheck() ){
			env.ExceptionDescribe();
			env.ExceptionClear();
		}
		setThrowScalpelException(env,  "createInputReaderTsk() - ERROR creating read buffer global ref");
		jReadBuffer = NULL; // local ref will be automatically deleted anyways
		tskData->jInputStream = NULL;
		free(tskReader->dataSource);
		tskReader->dataSource = NULL;
		free(tskReader);
		tskReader = NULL;
		return NULL ;
	}



	tskReader->isOpen = 0;

	//initialize java method IDs
	jclass clazz = env.FindClass(TSK_INPUTSTREAM_CLASS);
	if (!clazz) {
		fprintf(stdout, "createInputReaderTsk() - ERROR cannot load java class\n ");
		setThrowScalpelException(env,  "createInputReaderTsk() - ERROR cannot load java class");

		env.DeleteGlobalRef(tskData->jReadBuffer);

		free(tskReader->dataSource);
		tskReader->dataSource = NULL;
		free(tskReader);
		tskReader = NULL;
		return NULL ;
	}

	//using disassembler to get the correct signatures like javap -s -p org.sleuthkit.datamodel.ReadContentInputStream
	tskData->jGetPositionMethodId = env.GetMethodID(clazz, "getCurPosition", "()J");
	tskData->jGetSizeMethodId = env.GetMethodID(clazz, "getLength", "()J");
	tskData->jReadMethodId = env.GetMethodID(clazz, "read", "([BII)I");
	tskData->jSeekMethodId = env.GetMethodID(clazz, "seek", "(J)J");


	if (!tskData->jGetPositionMethodId
			|| !tskData->jGetSizeMethodId
			|| !tskData->jReadMethodId
			|| !tskData->jSeekMethodId
			|| env.ExceptionCheck()
			) {
		fprintf(stdout, "createInputReaderTsk() - ERROR getting java method ids for the input stream class, check API version\n ");
		if (env.ExceptionCheck()) {
			env.ExceptionDescribe();
			env.ExceptionClear();
		}
		setThrowScalpelException(env,  "createInputReaderTsk() - ERROR getting java method ids for the input stream class, check API version");

		env.DeleteGlobalRef(tskData->jReadBuffer);

		free(tskReader->dataSource);
		tskReader->dataSource = NULL;
		free(tskReader);
		tskReader = NULL;
		return NULL ;
	}


	//set up functions
	tskReader->open = tskDataSourceOpen;
	tskReader->close = tskDataSourceClose;
	tskReader->getError = tskDataSourceGetError;
	tskReader->getSize = tskDataSourceGetSize;
	tskReader->seeko = tskDataSourceSeekO;
	tskReader->tello = tskDataSourceTellO;
	tskReader->read = tskDataSourceRead;

	printVerbose("createInputReaderTsk -- input reader created\n");

	return tskReader;
}
Ejemplo n.º 24
0
static void freeInputReaderTsk(JNIEnv & env, ScalpelInputReader * tskReader) {
	printVerbose("freeInputReaderTsk()\n");
	if (!tskReader) {
		return;
	}

	if (!tskReader->dataSource) {
		fprintf(stdout, "freeInputReaderTsk() - ERROR dataSource not set, can't free\n ");
		return; //ERROR
	}

	TskInputStreamSourceInfo* tskData = (TskInputStreamSourceInfo*) tskReader->dataSource;
	if (!tskData) {
		fprintf(stdout, "freeInputReaderTsk() - ERROR TskInputStreamSourceInfo not set, can't free\n ");
		free(tskReader);
		tskReader = NULL;
		return; //ERROR
	}


	if (tskData->jReadBuffer) {
		env.DeleteGlobalRef(tskData->jReadBuffer);
		tskData->jReadBuffer = NULL;
	}


	if (tskData->jInputStream) {
		//env.DeleteGlobalRef(tskData->jInputStream); //done by carveNat()
		tskData->jInputStream = NULL;
	}

	//tskData->env = NULL;

	//these do not need to be freed
	tskData->jGetPositionMethodId = NULL;
	tskData->jGetSizeMethodId = NULL;
	tskData->jReadMethodId = NULL;
	tskData->jSeekMethodId = NULL;


	//reset fn pointers
	tskReader->open = NULL;
	tskReader->close = NULL;
	tskReader->getError = NULL;
	tskReader->getSize = NULL;
	tskReader->seeko = NULL;
	tskReader->tello = NULL;
	tskReader->read = NULL;


	//java client side is responsible for closing the stream it created
	tskReader->isOpen = FALSE;


	tskReader->id = NULL; //freed by jni ReleaseStringUTFChars()

	free(tskReader->dataSource);
	tskReader->dataSource = NULL;

	free(tskReader);
	tskReader = NULL;
}
Ejemplo n.º 25
0
int main(int argc, const char * argv[]) {
    int i;
    FILE *trace = NULL;
    for (i = 0; i < argc; i++) {
        char arg = *++argv[i];
        
        switch (arg) {
            case 'h':
                help = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            case 's':
                sbits = atoi(argv[i+1]);
                S = 1 << sbits;
                break;
            case 'E':
                E = atoi(argv[i+1]);
                break;
            case 'b':
                bbits = atoi(argv[i+1]);
                break;
            case 't':
                trace = fopen(argv[i+1], "r");
                break;
            default:
                break;
        }
    }
    
    if (help == 1) {
        printHelpAndExit(argv[0]);
    }
    
    CacheSet cacheSets[S];
    buildCache(cacheSets);
    
    if (trace != NULL) {
        long address;
        int bufLen = 30;
        char buffer[bufLen], instruction, blockSize;
        while (fgets(buffer, bufLen, trace) != NULL) {
            sscanf(buffer, " %c %lx,%c", &instruction, &address, &blockSize);
            
            if (instruction != INSTRUCTION) {
                for (i = 0; i < bufLen; i++) {
                    if (buffer[i] == '\n') {
                        buffer[i] = '\0';
                    }
                }
                
                char hitType = 0;
                if (instruction == MODIFY) {
                    for (i = 0; i < 2; i++) {
                        hitType += cacheOperation(cacheSets, address);
                    }
                } else {
                    hitType = cacheOperation(cacheSets, address);
                }
                
                if (verbose == 1) {
                    printVerbose(hitType, buffer);
                }
            }
        }
        fclose(trace);
    } else {
        printf("Error: Must specify trace file, see usage\n");
        printHelpAndExit(argv[0]);
    }
    
    for (i = 0; i < S; i++) {
        free(cacheSets[i].lines);
    }
    
    printSummary(hits, misses, evictions);
    return 0;
}
Ejemplo n.º 26
0
int scalpelInputGetError(ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputGetError()\n");
    return reader->getError(reader);
}
Ejemplo n.º 27
0
const char * scalpelInputGetId (ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputGetId()\n");
    return reader->id;
}
Ejemplo n.º 28
0
const char scalpelInputIsOpen (ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputIsOpen()\n");
    return reader->isOpen;
}
Ejemplo n.º 29
0
int scalpelInputOpen(ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputOpen()\n");
    return reader->open(reader);
}
Ejemplo n.º 30
0
unsigned long long scalpelInputTello(ScalpelInputReader * const reader) 
{
    printVerbose("scalpelInputTello()\n");
    return reader->tello(reader);
}