/*
   ** Similar to above - except that there is no second occurrence of the final left fragment - and
   ** the sole occurrence of this fragment is beyond the maximum offset for the sequence as a whole
   ** from BOF. N.B. This test passes in the previous version DROID 6.2.1
   */
  @Test
  public void testFinalLeftFragmentBeyondSeqMaxOffset() throws Exception {

    final String sigFile = "left-frag-1200.xml";
    final String fileToScan = "left1200a.ext";
    final String expectedPuid = "dev/1200";

    BinarySignatureIdentifier droid = new BinarySignatureIdentifier();
    droid.setSignatureFile(TESTAREA + sigFile);
    try {
      droid.init();
    } catch (SignatureParseException x) {
      assertEquals("Can't parse signature file", x.getMessage());
    }
    File file = new File(TESTAREA + fileToScan);
    assertTrue(file.exists());
    URI resourceUri = file.toURI();

    RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), fileToScan);
    RequestIdentifier identifier = new RequestIdentifier(resourceUri);
    identifier.setParentId(1L);

    IdentificationRequest<File> request = new FileSystemIdentificationRequest(metaData, identifier);
    request.open(file);

    IdentificationResultCollection resultsCollection = droid.matchBinarySignatures(request);
    List<IdentificationResult> results = resultsCollection.getResults();

    assertEquals(0, results.size());

    Iterator<IdentificationResult> iter = results.iterator();
    while (iter.hasNext()) {
      IdentificationResult result = iter.next();
      assertEquals(expectedPuid, result.getPuid());
    }
  }
예제 #2
0
    /**
     * Run droid identification on file
     *
     * @param filePath Absolute file path
     * @return Result list
     * @throws FileNotFoundException
     * @throws IOException
     */
    @Override
    public HashMap<String, String> identify(File file) throws FileNotFoundException {
        HashMap<String, String> droidIdRes = new HashMap<String, String>();
        InputStream in = null;
        IdentificationRequest request = null;

        try {
            URI resourceUri = file.toURI();
            in = new FileInputStream(file);
            LOG.debug("Identification of resource: " + resourceUri.toString());
            RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), file.getName());
            LOG.debug("File length: " + file.length());
            LOG.debug("File modified: " + file.lastModified());
            LOG.debug("File name: " + file.getName());
            RequestIdentifier identifier = new RequestIdentifier(resourceUri);
            request = new FileSystemIdentificationRequest(metaData, identifier);
            request.open(in);
            IdentificationResultCollection results = bsi.matchBinarySignatures(request);
            bsi.removeLowerPriorityHits(results);
            if (results == null || results.getResults() == null || results.getResults().isEmpty()) {
                LOG.debug("No identification result");
            } else {
                List<IdentificationResult> result = results.getResults();
                if (result != null && !result.isEmpty()) {
                    for (IdentificationResult ir : result) {
                        String mime = ir.getMimeType();
                        if (mime != null && !mime.isEmpty()) {
                            // take first mime, ignore others
                            if (!droidIdRes.containsKey("mime")) {
                                droidIdRes.put("mime", mime);
                            }
                        }
                        String puid = ir.getPuid();
                        if (puid != null && !puid.isEmpty()) {
                            // take first puid, ignore others
                            if (!droidIdRes.containsKey("puid")) {
                                droidIdRes.put("puid", puid);
                            }
                        }
                    }
                }
            }
            in.close();
            request.close();
        } catch (IOException ex) {
            LOG.error("I/O Exception", ex);
        } finally {
            try {
                in.close();
                request.close();
            } catch (IOException _) {
            }
        }
        if (!droidIdRes.containsKey("mime")) {
            droidIdRes.put("mime", MIME_UNKNOWN);
        }
        if (!droidIdRes.containsKey("puid")) {
            droidIdRes.put("puid", "fmt/0");
        }
        return droidIdRes;
    }