Example #1
0
int libscalpel_carve_input(scalpelState * state, ScalpelInputReader * const reader)
{
    std::string funcname("libscalpel_carve_input");

    if (state == NULL)
        throw std::runtime_error(funcname + ": NULL pointer provided for state.");

    if (reader == NULL)
        throw std::runtime_error(funcname + ": NULL pointer provided for Reader.");

    if (!reader->dataSource || !reader->id) {
        throw std::runtime_error(funcname + ": Reader datasource or id not set.");
    }

    if (!reader->open || !reader->read || !reader->seeko || !reader->tello
        || !reader->close || !reader->getError || !reader->getSize) {
            throw std::runtime_error(funcname + ": Reader callbacks not setup");
    }

    state->inReader = reader;

    int err = 0;

    if ((err = digImageFile(state))) {
        handleError(state, err); //can throw
        std::stringstream ss;
        ss << ": Error digging file, error code: " << err;
        throw std::runtime_error(funcname + ss.str());
    }

    if ((err = carveImageFile(state))) {
        handleError(state, err); //can throw
        std::stringstream ss;
        ss << ": Error carving file, error code: " << err;
        throw std::runtime_error(funcname + ss.str());
    }

    return SCALPEL_OK;
}
Example #2
0
void digAllFiles(int argc, char **argv, struct scalpelState *state) {

  int i = 0, j = 0; 
  FILE* listoffiles = NULL;

  if (state->useInputFileList) {
    fprintf(stdout, "Batch mode: reading list of images from %s.",
	    state->inputFileList);
    listoffiles = fopen(state->inputFileList,"r");
    if (listoffiles == NULL) {
      fprintf(stderr, "Couldn't open file: %s -- %s\n", 
	      (*(state->inputFileList)=='\0')?"<blank>":state->inputFileList,
	      strerror(errno));
      closeFile(state->auditFile);
      exit(-1);
    }
    j=0;
    do {
      j++;
      
      if (fgets(state->imagefile,MAX_STRING_LENGTH,listoffiles) == NULL) {
	
	fprintf(stderr,
		"Error reading line %d of %s. Skipping line.\n", 
		j,state->inputFileList);
	continue;
      }
      if(state->imagefile[strlen(state->imagefile)-1] == '\n'){
	state->imagefile[strlen(state->imagefile)-1] = '\x00';
      }

      // GGRIII: this function now *only* builds the header/footer
      // database.  Carving is handled afterward, in carveImageFile().
      
      if ((i = digImageFile(state))) {
	handleError(state,i);
      }
      else {
	// GGRIII: "digging" is now complete and header/footer database
	// has been built.  The function carveImageFile() performs
	// extraction of files based on this database.
      
	if ((i = carveImageFile(state))) {
	  handleError(state,i);
	}		
      }
    } 
    while (!feof(listoffiles));
    closeFile(listoffiles);
  }
  else {
    do {
      state->imagefile = *argv;
      
      // GGRIII: this function now *only* builds the header/footer
      // database.  Carving is handled afterward, in carveImageFile().

      if ((i = digImageFile(state))) {
	handleError(state,i);
      }		
      else {
	// GGRIII: "digging" is now complete and header/footer database
	// has been built.  The function carveImageFile() performs extraction 
	// of files based on this database.
	
	if ((i = carveImageFile(state))) {
	  handleError(state,i);
	}		
      }
      ++argv;  
    } while (*argv);
  }
}
Example #3
0
// the exposed libscalpel API
// NOTE: This function is deprecated and will be removed. Use the
// libscalpel_* functions instead.
// TODO make the driver in scalpel_exec.c use this (minor refactoring needed)
// TODO add support for the remaining options avail from cmd-line
// returns SCALPEL_OK on no error, can throw runtime_error exception on errors
int scalpel_carveSingleInput(ScalpelInputReader * const reader, const char * const confFilePath,
    const char * const outDir, const unsigned char generateFooterDb,
    const unsigned char handleEmbedded, const unsigned char organizeSubdirs,
    const unsigned char previewMode,
    const unsigned char carveWithMissingFooters,
    const unsigned char noSearchOverlap) throw (std::runtime_error) {

    if (!reader || ! confFilePath || ! outDir) {
        //invalid args
        throw std::runtime_error("Invalid empty arguments");
    }

    if (!reader->dataSource || !reader->id) {
        throw std::runtime_error("Invalid empty input reader arguments");
    }

    //check fns
    if (!reader->open || !reader->read || !reader->seeko || !reader->tello
        || !reader->close || !reader->getError || !reader->getSize) {
            throw std::runtime_error("Reader callbacks not setup");
    }

    struct scalpelState state;

    std::string processorName ("scalpel_carveSingleInput()");
    char * args[5];
    args[0] = const_cast<char*> ( processorName.c_str());
    args[1] = reader->id;
    args[2] = const_cast<char*> (confFilePath);
    args[3] = const_cast<char*> (outDir);
    args[4] = 0;


    initializeState(args, &state);

    //setup input
    state.inReader = reader;

    //setup options
    const size_t outDirLen = strlen(outDir);
    strncpy(state.outputdirectory, outDir, outDirLen);
    state.outputdirectory[outDirLen] = 0;
    const size_t confFilePathLen = strlen(confFilePath);
    strncpy(state.conffile, confFilePath, confFilePathLen);
    state.conffile[confFilePathLen] = 0;
    state.generateHeaderFooterDatabase = generateFooterDb;
    state.handleEmbedded = handleEmbedded;
    state.organizeSubdirectories = organizeSubdirs;
    state.previewMode = previewMode;
    state.carveWithMissingFooters = carveWithMissingFooters;
    state.noSearchOverlap = noSearchOverlap;

    convertFileNames(&state);

    // read configuration file
    int err;
    if ((err = readSearchSpecFile(&state))) {
        // problem with config file
        handleError(&state, err); //can throw
        freeState(&state);
        std::stringstream ss;
        ss << "Error reading spec file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    // prepare audit file and make sure output directory is empty.
    if ((err = openAuditFile(&state))) {
        handleError(&state, err); //can throw
        freeState(&state);
        std::stringstream ss;
        ss << "Error opening audit file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    // Initialize the backing store of buffer to read-in, process image data.
    init_store();

    // Initialize threading model for cpu or gpu search.
    init_threading_model(&state);

    if ((err = digImageFile(&state))) {
        handleError(&state, err); //can throw
        closeAuditFile(state.auditFile);
        destroyStore();
        freeState(&state);
        std::stringstream ss;
        ss << "Error digging file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    if ((err = carveImageFile(&state))) {
        handleError(&state, err); //can throw
        closeAuditFile(state.auditFile);
        destroy_threading_model(&state);
        destroyStore();
        freeState(&state);
        std::stringstream ss;
        ss << "Error carving file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    closeAuditFile(state.auditFile);
    destroy_threading_model(&state);
    destroyStore();
    freeState(&state);

    return SCALPEL_OK;
}