/** * test the data against a regex * * @param text the data we are testing * * @return if we have a match */ private boolean testRegex(String text) { log.debug("testRegex()"); String test = new String(match.getTest().array()); char comparator = match.getComparator(); log.debug("testRegex(): searching for '" + test + "'"); if (comparator == '=') { if (Pattern.matches(test, text)) { return true; } else { return false; } } else if (comparator == '!') { if (Pattern.matches(test, text)) { return false; } else { return true; } } return false; }
char comparator = match.getComparator();
final char comparator = this.match.getComparator();
/** Test to see if everything is in order for this match. * @return whether or not this match has enough data to be valid. */ public boolean isValid() { if (this.match == null || this.match.getTest() == null) { return false; } final String type = new String(this.match.getTest().array()).trim(); final char comparator = this.match.getComparator(); final String description = this.match.getDescription(); final String test = new String(this.match.getTest().array()).trim(); if (!type.equals("") && comparator != '\0' && //$NON-NLS-1$ (comparator == '=' || comparator == '!' || comparator == '>' || comparator == '<') && description != null && !description.equals("") && //$NON-NLS-1$ !test.equals("")) { //$NON-NLS-1$ return true; } return false; }
/** Test the data against the test byte. * @param data the data we are testing. * @return if we have a match. */ private boolean testByte(final ByteBuffer data) { final String test = new String(this.match.getTest().array()).trim(); final char comparator = this.match.getComparator(); final long bitmask = this.match.getBitmask(); final byte b = (byte) (data.get(0) & bitmask); final int tst = Integer.decode(test).byteValue(); final byte t = (byte) (tst & 0xff); switch (comparator) { case '=': return t == b; case '!': return t != b; case '>': return t > b; case '<': return t < b; default: return false; } }
char comparator = match.getComparator(); long bitmask = match.getBitmask();
char comparator = match.getComparator(); long bitmask = match.getBitmask();
/** * test to see if everything is in order for this match * * @return whether or not this match has enough data to be valid */ public boolean isValid() { log.debug("isValid()"); if ((match == null) || (match.getTest() == null)) { return false; } String type = new String(match.getTest().array()); char comparator = match.getComparator(); String description = match.getDescription(); String test = new String(match.getTest().array()); if ((type != null) && !type.equals("") && (comparator != '\0') && ((comparator == '=') || (comparator == '!') || (comparator == '>') || (comparator == '<')) && (description != null) && !description.equals("") && (test != null) && !test.equals("")) { return true; } return false; }
/** * test to see if everything is in order for this match * * @return whether or not this match has enough data to be valid */ public boolean isValid() { log.debug("isValid()"); if ((match == null) || (match.getTest() == null)) { return false; } String type = new String(match.getTest().array()); char comparator = match.getComparator(); String description = match.getDescription(); String test = new String(match.getTest().array()); if ((type != null) && !type.equals("") && (comparator != '\0') && ((comparator == '=') || (comparator == '!') || (comparator == '>') || (comparator == '<')) && (description != null) && !description.equals("") && (test != null) && !test.equals("")) { return true; } return false; }
char comparator = match.getComparator(); long bitmask = match.getBitmask();
/** Test the data against a long. * @param data the data we are testing. * @return if we have a match. */ private boolean testLong(final ByteBuffer data) { long val = 0; final String test = new String(this.match.getTest().array()).trim(); final char comparator = this.match.getComparator(); final long bitmask = this.match.getBitmask(); val = byteArrayToLong(data); // apply bitmask before the comparison val = val & bitmask; final long tst = Long.decode(test).longValue(); switch (comparator) { case '=': return val == tst; case '!': return val != tst; case '>': return val > tst; case '<': return val < tst; default: return false; } }
/** Test the data using a detector. * @param data the data we are testing. * @return if we have a match. */ private boolean testDetector(final ByteBuffer data) { final String detectorClassName = new String(this.match.getTest().array()).trim(); try { final Class<?> detectorClass = classForName(detectorClassName); final Object detectorObject = detectorClass.getDeclaredConstructor().newInstance(); final Method processMethod = detectorClass.getDeclaredMethod("process", byte[].class, //$NON-NLS-1$ Integer.TYPE, Integer.TYPE, Long.TYPE, Character.TYPE, String.class, Map.class); final String[] types = (String[]) processMethod.invoke(detectorObject, data.array(), Integer.valueOf(this.match.getOffset()), Integer.valueOf(this.match.getLength()), Long.valueOf(this.match.getBitmask()), Character.valueOf(this.match.getComparator()), this.match.getMimeType(), this.match.getProperties()); if (types != null && types.length > 0) { // the match object has no mime type set, so set from the detector class processing this.match.setMimeType(types[0]); return true; } } catch (final Throwable e) { java.util.logging.Logger.getLogger("es.gob.afirma").warning(e.toString()); //$NON-NLS-1$ } return false; }
char comparator = match.getComparator(); long bitmask = match.getBitmask();
final char comparator = this.match.getComparator(); final long bitmask = this.match.getBitmask();
/** * print a magic match * * @param stream DOCUMENT ME! * @param match DOCUMENT ME! * @param spacing DOCUMENT ME! */ public static void printMagicMatch(PrintStream stream, MagicMatch match, String spacing) { stream.println(spacing + "============================="); stream.println(spacing + "mime type: " + match.getMimeType()); stream.println(spacing + "description: " + match.getDescription()); stream.println(spacing + "extension: " + match.getExtension()); stream.println(spacing + "test: " + new String(match.getTest().array())); stream.println(spacing + "bitmask: " + match.getBitmask()); stream.println(spacing + "offset: " + match.getOffset()); stream.println(spacing + "length: " + match.getLength()); stream.println(spacing + "type: " + match.getType()); stream.println(spacing + "comparator: " + match.getComparator()); stream.println(spacing + "============================="); Collection submatches = match.getSubMatches(); Iterator i = submatches.iterator(); while (i.hasNext()) { printMagicMatch(stream, (MagicMatch) i.next(), spacing + " "); } }
/** Test the data against a regex. * @param text the data we are testing. * @return if we have a match. */ private boolean testRegex(final String text) { final String test = new String(this.match.getTest().array()).trim(); final char comparator = this.match.getComparator(); final Perl5Util utility = new Perl5Util(); if (comparator == '=') { if (utility.match(test, text)) { return true; } return false; } else if (comparator == '!') { if (utility.match(test, text)) { return false; } return true; } return false; }
/** * print a magic match * * @param stream DOCUMENT ME! * @param match DOCUMENT ME! * @param spacing DOCUMENT ME! */ public static void printMagicMatch(PrintStream stream, MagicMatch match, String spacing) { stream.println(spacing + "============================="); stream.println(spacing + "mime type: " + match.getMimeType()); stream.println(spacing + "description: " + match.getDescription()); stream.println(spacing + "extension: " + match.getExtension()); stream.println(spacing + "test: " + new String(match.getTest().array())); stream.println(spacing + "bitmask: " + match.getBitmask()); stream.println(spacing + "offset: " + match.getOffset()); stream.println(spacing + "length: " + match.getLength()); stream.println(spacing + "type: " + match.getType()); stream.println(spacing + "comparator: " + match.getComparator()); stream.println(spacing + "============================="); Collection<MagicMatch> submatches = match.getSubMatches(); Iterator<MagicMatch> i = submatches.iterator(); while (i.hasNext()) { printMagicMatch(stream, (MagicMatch) i.next(), spacing + " "); } }
/** * test the data against a regex * * @param text the data we are testing * * @return if we have a match */ private boolean testRegex(String text) { log.debug("testRegex()"); String test = new String(match.getTest().array()); char comparator = match.getComparator(); Perl5Util utility = new Perl5Util(); log.debug("testRegex(): searching for '" + test + "'"); if (comparator == '=') { if (utility.match(test, text)) { return true; } else { return false; } } else if (comparator == '!') { if (utility.match(test, text)) { return false; } else { return true; } } return false; }
MagicDetector detector = (MagicDetector) c.newInstance(); String[] types = detector.process(data.array(), match.getOffset(), match.getLength(), match.getBitmask(), match.getComparator(), match.getMimeType(), match.getProperties());
MagicDetector detector = (MagicDetector) c.newInstance(); String[] types = detector.process(data.array(), match.getOffset(), match.getLength(), match.getBitmask(), match.getComparator(), match.getMimeType(), match.getProperties());