Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rapid7/recog-java
Recog java
https://github.com/rapid7/recog-java
fingerprinting java regex xml
Last synced: 3 months ago
JSON representation
Recog java
- Host: GitHub
- URL: https://github.com/rapid7/recog-java
- Owner: rapid7
- License: bsd-3-clause
- Created: 2018-08-21T18:27:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-07T18:15:12.000Z (3 months ago)
- Last Synced: 2024-11-07T19:25:41.950Z (3 months ago)
- Topics: fingerprinting, java, regex, xml
- Language: Java
- Size: 197 KB
- Stars: 9
- Watchers: 63
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
## Recog Java
[![CI workflow](https://github.com/rapid7/recog-java/actions/workflows/ci.yml/badge.svg)](https://github.com/rapid7/recog-java/actions/workflows/ci.yml) [![Maven Central](https://img.shields.io/maven-central/v/com.rapid7.recog/recog-java.svg)](https://search.maven.org/artifact/com.rapid7.recog/recog-java) [![Javadocs](https://www.javadoc.io/badge/com.rapid7.recog/recog-java.svg)](https://www.javadoc.io/doc/com.rapid7.recog/recog-java)
Java implementation of [Recog](https://github.com/rapid7/recog) that supports parsing and matching.
#### Recog Content
Recog content (the XML files containing matchers) is maintained at the upstream [recog](https://github.com/rapid7/recog) project. The recog-java tests are configured to download a versioned archive of that repository in order to use the content for testing. The content is otherwise not deployed or handled by the recog-java project, so any consumers of recog-java must provide the content they need.
## Getting Started
Add the dependency to your pom file:
```xml
com.rapid7.recog
recog-java
0.7.0```
Implement a simple Recog client:
```java
public class RecogClient implements Recog {
private RecogMatchersProvider provider;public RecogClient(File matchersDirectory) {
this.provider = new RecogMatchersProvider(BUILTIN, matchersDirectory);
}@Override
public List fingerprint(String description) {
List matches = new ArrayList<>();
for (RecogMatchers matchers : provider.getMatchers(BUILTIN)) {
for (RecogMatch match : matchers.getMatches(description)) {
RecogMatcher matcher = match.getMatcher();
matches.add(new RecogMatchResult(matchers.getKey(), matchers.getType(), matchers.getProtocol(), matchers.getPreference(), match.getMatcher().getDescription(), matcher.getPattern(), matcher.getExamples(), match.getParameters()));
}
}
return matches;
}@Override
public RecogVersion refreshContent() {
throw new UnsupportedOperationException("Not implemented.");
}
}```
Fingerprint some input:
```java
RecogClient recog = new RecogClient(new File("path/to/recog/xml/"));
List matchResults = recog.fingerprint("Apache HTTPD 6.5");
// draw the rest of the owl...
```#### Configuring Pattern Matching
By default, recog-java uses Java's standard regular expression package, `java.util.regex`. To use a different implementation, users can implement their own `RecogPatternMatcher` instance:
```java
import com.rapid7.recog.pattern.RecogPatternMatcher;public class CustomPatternMatcher implements RecogPatternMatcher {
// custom implementation...
}RecogPatternMatcher patternMatcher = new CustomPatternMatcher("^Apache HTTPD (?.*)$");
RecogMatcher matcher = new RecogMatcher(patternMatcher);
Map results = matcher.match("Apache HTTPD 6.5");
```## Differences from Ruby implementation
This library is not yet at a 1:1 parity with the original [rapid7/recog](https://github.com/rapid7/recog) Ruby implementation.
Missing features:
- Matching against multi-line input strings
- Command line tools like `recog_match`## Development
Fork the repository and create a development branch in your fork. _Working from the master branch in your fork is not recommended._
1. Open your favorite IDE or text editor
2. Make some changes
3. Add some tests if needed
4. Run the tests
5. Push your changes
6. Open a pull requestYou can use `mvn clean install` to clean compile, run checkstyle, and run all tests.
#### Code Style
recog-java uses a variation of the Google Java code style, enforced with Checkstyle. Please make sure your changes adhere to this style before submitting a pull request.
## Testing
Run `mvn test` or `mvn clean install`.