├── .gitignore
├── .gitmodules
├── .travis.yml
├── BUILD.md
├── COPYING
├── ChangeLog
├── INSTALL
├── Jenkinsfile
├── Makefile.am
├── README.md
├── bootstrap.sh
├── c_example
└── main.c
├── configure.ac
├── design
├── .gitignore
├── debruijn
│ ├── 10.1.1.13.2152.pdf
│ ├── bubble3.pdf
│ ├── necklace_allerton.ps
│ ├── p752-sawada.pdf
│ ├── sdarticle.pdf
│ └── weston.pdf
├── fragments.pdf
├── fragments.tex
└── grammar
├── include
├── automata.h
├── basic.h
├── byteset.h
├── c_api_util.h
├── chain.h
├── codegen.h
├── compiler.h
├── container_out.h
├── decoders
│ ├── asciidecoder.h
│ ├── bytesource.h
│ ├── decoder.h
│ ├── decoderfactory.h
│ ├── icudecoder.h
│ ├── ocedecoder.h
│ ├── rotdecoder.h
│ ├── utf16.h
│ ├── utf16decoder.h
│ ├── utf32.h
│ ├── utf32decoder.h
│ ├── utf8.h
│ ├── utf8decoder.h
│ ├── utfdecoderbase.h
│ └── xordecoder.h
├── encoders
│ ├── ascii.h
│ ├── byteencoder.h
│ ├── caching_encoder.h
│ ├── charencoder.h
│ ├── concrete_encoders.h
│ ├── decorating_encoder.h
│ ├── encoder.h
│ ├── encoderbase.h
│ ├── encoderfactory.h
│ ├── icuencoder.h
│ ├── oceencoder.h
│ ├── rotencoder.h
│ ├── utf16.h
│ ├── utf32.h
│ ├── utf8.h
│ ├── utfbase.h
│ └── xorencoder.h
├── fragment.h
├── fsmthingy.h
├── fwd_pointers.h
├── graph.h
├── handles.h
├── icuconverter.h
├── icuutil.h
├── instructions.h
├── lightgrep
│ ├── api.h
│ ├── search_hit.h
│ ├── transforms.h
│ └── util.h
├── matchgen.h
├── nfabuilder.h
├── nfaoptimizer.h
├── ostream_join_iterator.h
├── pair_out.h
├── parsenode.h
├── parser.h
├── parsetree.h
├── parseutil.h
├── pattern.h
├── program.h
├── rangeset.h
├── rewriter.h
├── searchhit.h
├── sequences.h
├── simplevectorfamily.h
├── sparseset.h
├── states.h
├── thread.h
├── transition.h
├── transitionfactory.h
├── unicode.h
├── unparser.h
├── utility.h
├── vectorfamily.h
├── vm.h
└── vm_interface.h
├── jenkins.sh
├── liblightgrep.spec.in
├── m4
├── ax_append_compile_flags.m4
├── ax_append_flag.m4
├── ax_append_link_flags.m4
├── ax_boost_base.m4
├── ax_boost_program_options.m4
├── ax_boost_system.m4
├── ax_check_compile_flag.m4
├── ax_check_icu.m4
├── ax_check_library.m4
├── ax_check_link_flag.m4
├── ax_cxx_compile_stdcxx.m4
├── ax_cxx_compile_stdcxx_11.m4
├── ax_prog_bison.m4
├── lg_remove_flags.m4
└── lg_replace_flag.m4
├── mingw-liblightgrep.spec.in
├── pylightgrep
└── lightgrep.py
├── pytest
├── analyze_trace.py
├── corpora
│ ├── marktwainworks.txt
│ ├── norvig1mb.txt
│ ├── norvig6mb.txt
│ ├── russian-utf16BE.txt
│ ├── russian-utf16LE.txt
│ ├── russian-utf32BE.txt
│ ├── russian-utf32LE.txt
│ ├── russian-utf7.txt
│ ├── russian-utf8.txt
│ └── utf16LE-norvig6mb.txt
├── guid_gen.py
├── keys
│ ├── -----5.txt
│ ├── ----10.txt
│ ├── ----25.txt
│ ├── ----50.txt
│ ├── ---100.txt
│ ├── ---200.txt
│ ├── ---500.txt
│ ├── --1000.txt
│ ├── --1500.txt
│ ├── --2000.txt
│ ├── --2500.txt
│ ├── --3000.txt
│ ├── --4000.txt
│ ├── --4500.txt
│ ├── --5000.txt
│ ├── --6000.txt
│ ├── --7000.txt
│ ├── --8000.txt
│ ├── --9000.txt
│ ├── -10000.txt
│ ├── -11000.txt
│ ├── -12000.txt
│ ├── -13000.txt
│ ├── -14000.txt
│ ├── -15000.txt
│ ├── -17500.txt
│ ├── -20000.txt
│ ├── -25000.txt
│ ├── -30000.txt
│ ├── -35000.txt
│ ├── -40000.txt
│ ├── -45000.txt
│ ├── -50000.txt
│ ├── -60000.txt
│ ├── -70000.txt
│ ├── -80000.txt
│ ├── -90000.txt
│ ├── 100000.txt
│ ├── 114743.txt
│ ├── fixed30.txt
│ ├── shuf05.txt
│ ├── shuf10.txt
│ ├── shuf15.txt
│ ├── shuf20.txt
│ ├── shuf25.txt
│ ├── shuf30.txt
│ ├── shuf35.txt
│ ├── shuf40.txt
│ ├── shuf45.txt
│ ├── shuf50.txt
│ ├── shuf55.txt
│ └── twain.txt
├── receive_data.py
├── regression.py
├── results
│ ├── -----5.txt
│ ├── ----10.txt
│ ├── ----25.txt
│ ├── ----50.txt
│ ├── ---100.txt
│ ├── ---200.txt
│ ├── ---500.txt
│ ├── --1000.txt
│ ├── --1500.txt
│ ├── --2000.txt
│ ├── --2500.txt
│ ├── --3000.txt
│ ├── --4000.txt
│ ├── --4500.txt
│ ├── --5000.txt
│ ├── --6000.txt
│ ├── --7000.txt
│ ├── --8000.txt
│ ├── --9000.txt
│ ├── -10000.txt
│ ├── -11000.txt
│ ├── -12000.txt
│ ├── -13000.txt
│ ├── -14000.txt
│ ├── -15000.txt
│ ├── -17500.txt
│ ├── -20000.txt
│ ├── -25000.txt
│ ├── -30000.txt
│ ├── -35000.txt
│ ├── -40000.txt
│ ├── -45000.txt
│ ├── -50000.txt
│ ├── -60000.txt
│ ├── -70000.txt
│ ├── -80000.txt
│ ├── -90000.txt
│ ├── 100000.txt
│ └── 114743.txt
├── send_data_to_lg.py
├── tb_db_create.py
├── tinderbox.py
└── trace_runner.py
├── re_gen
├── Makefile
├── aQ-3-3.bz2
├── aQ-3.bz2
├── basic.h
├── db-abcd-4
├── lgtestlib.py
├── minfail.py
├── node.cpp
├── node.h
├── parsecheck.cpp
├── parsetree.h
├── pat2data-enc.py
├── pat2data.py
├── pat2sorttest.py
├── pat2swith.py
├── pat2test.py
├── pats-1000
├── patsample.py
├── randpat.cpp
├── shitgrep.cpp
├── testregex
│ ├── basic.dat
│ ├── categorize.dat
│ ├── forcedassoc.dat
│ ├── leftassoc.dat
│ ├── nullsubexpr.dat
│ ├── repetition.dat
│ └── rightassoc.dat
├── tests
│ ├── dot-star
│ └── dot-star_patterns
├── unparser.cpp
├── unparser.h
├── utf8-gen.py
├── utf8-singles.bz2
└── valid.bz2
├── src
├── enc
│ └── encodings.cpp
├── lib
│ ├── ascii.cpp
│ ├── automata.cpp
│ ├── byteencoder.cpp
│ ├── byteset.cpp
│ ├── c_api_util.cpp
│ ├── chain.cpp
│ ├── charencoder.cpp
│ ├── codegen.cpp
│ ├── compiler.cpp
│ ├── decoders
│ │ ├── decoder.cpp
│ │ ├── decoderfactory.cpp
│ │ └── ocedecoder.cpp
│ ├── encoderbase.cpp
│ ├── encoderfactory.cpp
│ ├── fsmthingy.cpp
│ ├── icuconverter.cpp
│ ├── icuencoder.cpp
│ ├── icuutil.cpp
│ ├── instructions.cpp
│ ├── lightgrep.pc.in
│ ├── lightgrep_c_api.cpp
│ ├── lightgrep_c_util.cpp
│ ├── matchgen.cpp
│ ├── nfabuilder.cpp
│ ├── nfaoptimizer.cpp
│ ├── oceencoder.cpp
│ ├── parsenode.cpp
│ ├── parser.cpp
│ ├── parsetree.cpp
│ ├── parseutil.cpp
│ ├── pattern.cpp
│ ├── program.cpp
│ ├── re_grammar.ypp
│ ├── rewriter.cpp
│ ├── states.cpp
│ ├── thread.cpp
│ ├── unparser.cpp
│ ├── utf8.cpp
│ ├── utfbase.cpp
│ ├── utility.cpp
│ ├── version.rc
│ └── vm.cpp
├── val
│ └── valid.cpp
└── what
│ └── what.cpp
├── test
├── data
│ ├── hectotest
│ ├── hectotest.dat
│ ├── kilotest
│ └── kilotest.dat
├── data_reader.cpp
├── data_reader.h
├── dtest.cpp
├── dtest.h
├── executor.h
├── mockcallback.cpp
├── mockcallback.h
├── stest.cpp
├── stest.h
├── test.cpp
├── test_ascii.cpp
├── test_auto_search_1.cpp
├── test_auto_search_2.cpp
├── test_auto_search_3.cpp
├── test_auto_search_4.cpp
├── test_auto_search_5.cpp
├── test_auto_search_6.cpp
├── test_auto_search_7.cpp
├── test_auto_search_8.cpp
├── test_auto_search_multi_1.cpp
├── test_auto_search_multi_2.cpp
├── test_auto_starts_with_1.cpp
├── test_auto_starts_with_2.cpp
├── test_auto_starts_with_3.cpp
├── test_auto_starts_with_4.cpp
├── test_auto_starts_with_5.cpp
├── test_auto_starts_with_6.cpp
├── test_auto_starts_with_7.cpp
├── test_auto_starts_with_multi_1.cpp
├── test_auto_starts_with_multi_2.cpp
├── test_basic.cpp
├── test_byteset.cpp
├── test_bytesource.cpp
├── test_c_api.cpp
├── test_c_util.cpp
├── test_compiler.cpp
├── test_graph.cpp
├── test_helper.cpp
├── test_helper.h
├── test_icu.cpp
├── test_icudecoder.cpp
├── test_icuutil.cpp
├── test_instructions.cpp
├── test_matchgen.cpp
├── test_nfabuilder.cpp
├── test_nfaoptimizer.cpp
├── test_oceencoder.cpp
├── test_ostream_join_iterator.cpp
├── test_parser.cpp
├── test_parseutil.cpp
├── test_program.cpp
├── test_rangeset.cpp
├── test_rewriter.cpp
├── test_rotencoder.cpp
├── test_search.cpp
├── test_search_assertions.cpp
├── test_search_data.cpp
├── test_search_data_driver.cpp
├── test_search_data_driver.h
├── test_sequences.h
├── test_sparseset.cpp
├── test_starts_with.cpp
├── test_states.cpp
├── test_testregex_basic_modified.cpp
├── test_thread.cpp
├── test_transitionfactory.cpp
├── test_unicode.cpp
├── test_unparser.cpp
├── test_utf16.cpp
├── test_utf32.cpp
├── test_utf8.cpp
├── test_utf8decoder.cpp
├── test_utility.cpp
├── test_vm.cpp
└── test_xorencoder.cpp
└── tools
├── macify.sh
└── thread_dump.pl
/.gitignore:
--------------------------------------------------------------------------------
1 | *.la
2 | *.lo
3 | *.o
4 | *.pyc
5 | .*.swp
6 | .deps/
7 | .dirstamp
8 | .libs/
9 | /INSTALL
10 | /Makefile
11 | /Makefile.in
12 | /aclocal.m4
13 | /autom4te.cache
14 | /autoscan.log
15 | /c_example/cex
16 | /c_example/cex.exe
17 | /config/
18 | /config.h
19 | /config.h.in
20 | /config.h.in~
21 | /config.log
22 | /config.status
23 | /configure
24 | /configure.scan
25 | /include/lightgrep/encodings.h
26 | /liblightgrep.spec
27 | /libtool
28 | /m4/libtool.m4
29 | /m4/ltoptions.m4
30 | /m4/ltsugar.m4
31 | /m4/ltversion.m4
32 | /m4/lt~obsolete.m4
33 | /mingw-liblightgrep.spec
34 | /re_gen/parsecheck
35 | /re_gen/randpat
36 | /re_gen/shitgrep
37 | /src/lib/lightgrep.pc
38 | /src/lib/re_grammar.cpp
39 | /src/lib/re_grammar.output
40 | /src/enc/enc
41 | /src/enc/enc.exe
42 | /src/val/val
43 | /src/val/val.exe
44 | /src/what/what
45 | /src/what/what.exe
46 | /stamp-h1
47 | /test-suite.log
48 | /test/test
49 | /test/test.log
50 | /test/test.exe
51 | /test/test.trs
52 | /tmp/
53 | /vendors/
54 | _libs/
55 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vendors/scope"]
2 | path = vendors/scope
3 | url = https://github.com/jonstewart/scope.git
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 | compiler:
3 | - gcc
4 | - clang
5 | before_install:
6 | - git submodule update --init
7 | - yes | sudo add-apt-repository ppa:mapnik/boost
8 | - yes | sudo add-apt-repository ppa:ubuntu-toolchain-r/test
9 | - sudo apt-get update
10 | install:
11 | - sudo apt-get install libicu-dev boost1.49 libboost-chrono1.49-dev libboost-filesystem1.49-dev libboost-program-options1.49-dev libboost-system1.49-dev libboost-thread1.49-dev gcc-4.8 g++-4.8
12 | - sudo ln -s -f /usr/bin/gcc-4.8 /usr/bin/gcc
13 | - sudo ln -s -f /usr/bin/g++-4.8 /usr/bin/g++
14 | script: $CXX --version && autoreconf -fi && ./configure && make -j2 check
15 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/ChangeLog
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | @Library('asdf_common') _
2 |
3 | def BUILDS = [
4 | 'linux/64/shared',
5 | 'windows/64/shared',
6 | // 'windows/64/shared-fat',
7 | 'windows/64/static',
8 | 'windows/32/shared',
9 | // 'windows/32/shared-fat',
10 | 'windows/32/static'
11 | ]
12 |
13 | def BASE_URL = 'ssh://git@stash.strozfriedberg.com/asdf'
14 | def DOWNSTREAM_REPOS = [
15 | ['hasher', 'master'],
16 | ['lightgrep', 'master'],
17 | ['lightgrep-java', 'master'],
18 | ['bulk_extractor', 'master']
19 | ]
20 | def UPSTREAM_REPOS = [['icu', 'master']]
21 |
22 | pipeline {
23 | agent none
24 | stages {
25 | stage('Handle Upstream Trigger') {
26 | steps {
27 | script {
28 | common.HandleUpstreamTrigger(env, params, BASE_URL, UPSTREAM_REPOS)
29 | }
30 | }
31 | }
32 | stage('Build') {
33 | steps {
34 | script {
35 | parallel common.makeConfigurations(scm, BUILDS)
36 | }
37 | }
38 | }
39 | stage('Trigger Downstream') {
40 | steps {
41 | script {
42 | common.TriggerDownstream(env, DOWNSTREAM_REPOS)
43 | }
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | liblightgrep
2 | ============
3 |
4 | not the worst forensics regexp engine
5 |
6 | About
7 | -----
8 | Lightgrep is a new regular expression engine, designed specifically for digital forensics. Why another regexp engine?
9 |
10 | Lightgrep:
11 | * searches for many patterns simultaneously
12 | * searches binary data as a stream, not as discrete lines of text
13 | * searches for patterns in many different encodings; give it dirty data, lightgrep don't care
14 | * never, ever, ever, never, never looks at a byte twice or backs up in your input
15 |
16 | Lightgrep is still pretty new and doesn't have all the regexp features you might be used to. But it has enough features to be more than a toy, and what is supported is well-tested.
17 |
18 | liblightgrep is copyright (c) 2010-2015, Stroz Friedberg, LLC. liblightgrep is available under version 3 of the GNU Public License. See [COPYING](COPYING) for details.
19 |
20 | Technical Info
21 | --------------
22 | Lightgrep is implemented in portable C++11 but exposes a concise C API. The core of the API is defined in [include/lightgrep/api.h](./include/lightgrep/api.h). You can see a small example program at [c_example/main.c](./c_example/main.c).
23 |
24 | Lightgrep depends on a number of [Boost](http://www.boost.org/) libraries and also on [ICU](http://www.icu-project.org). Currently you will need gcc 4.6+ or clang 3.1 to compile the libraries.
25 |
26 | Install
27 | -------
28 | See the [BUILD.md file](BUILD.md) for installation instructions.
29 |
--------------------------------------------------------------------------------
/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | autoreconf -fi
4 |
--------------------------------------------------------------------------------
/design/.gitignore:
--------------------------------------------------------------------------------
1 | *.aux
2 | *.log
3 |
--------------------------------------------------------------------------------
/design/debruijn/10.1.1.13.2152.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/debruijn/10.1.1.13.2152.pdf
--------------------------------------------------------------------------------
/design/debruijn/bubble3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/debruijn/bubble3.pdf
--------------------------------------------------------------------------------
/design/debruijn/p752-sawada.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/debruijn/p752-sawada.pdf
--------------------------------------------------------------------------------
/design/debruijn/sdarticle.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/debruijn/sdarticle.pdf
--------------------------------------------------------------------------------
/design/debruijn/weston.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/debruijn/weston.pdf
--------------------------------------------------------------------------------
/design/fragments.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/strozfriedberg/liblightgrep/3eed03a5b6698a09f5d08e2b686d9d03d96fa4c2/design/fragments.pdf
--------------------------------------------------------------------------------
/include/automata.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "basic.h"
22 | #include "graph.h"
23 | #include "transition.h"
24 | #include "transitionfactory.h"
25 | #include "vectorfamily.h"
26 |
27 | struct Properties {
28 | Properties(): Deterministic(true), TransFac(new TransitionFactory()) {}
29 |
30 | bool Deterministic;
31 | std::shared_ptr TransFac;
32 | };
33 |
34 | struct Glushkov {
35 | static const uint32_t NOLABEL;
36 |
37 | Glushkov(): Trans(0), IsMatch(false), Label(NOLABEL) {}
38 |
39 | std::string label() const;
40 |
41 | Transition* Trans;
42 | bool IsMatch;
43 | uint32_t Label;
44 | };
45 |
46 | struct Empty {};
47 |
48 | typedef Graph NFA;
49 |
50 |
--------------------------------------------------------------------------------
/include/basic.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | typedef unsigned char byte;
29 |
30 | // typedef unsigned short uint16_t;
31 |
32 | // typedef unsigned int uint32_t;
33 | // typedef int int32_t;
34 |
35 | // typedef unsigned long long uint64_t;
36 | // typedef long long int64_t;
37 |
38 | #define THROW_WITH_OUTPUT(exceptType, expression) \
39 | std::ostringstream buf; \
40 | buf << __FILE__ << ":" << __LINE__ << ": " << expression; \
41 | throw exceptType(buf.str())
42 |
43 | #define THROW_RUNTIME_ERROR_WITH_OUTPUT(expression) THROW_WITH_OUTPUT(std::runtime_error, expression)
44 |
45 | #define THROW_RUNTIME_ERROR_WITH_CLEAN_OUTPUT(expression) \
46 | std::ostringstream buf; \
47 | buf << expression; \
48 | throw std::runtime_error(buf.str())
49 |
--------------------------------------------------------------------------------
/include/c_api_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "lightgrep/api.h"
22 | #include "basic.h"
23 |
24 | LG_Error* makeError(
25 | const char* msg,
26 | const char* pattern = nullptr,
27 | const char* encodingChain = nullptr,
28 | const char* source = nullptr,
29 | int index = -1
30 | );
31 |
32 | template
33 | auto trapWithRetval(F&& func, decltype(func()) fail, LG_Error** err) -> decltype(func()) {
34 | try {
35 | return func();
36 | }
37 | catch (const std::exception& e) {
38 | if (err) {
39 | *err = makeError(e.what());
40 | }
41 | }
42 | catch (...) {
43 | if (err) {
44 | *err = makeError("Unspecified exception");
45 | }
46 | }
47 |
48 | return fail;
49 | }
50 |
51 | template
52 | auto trapWithRetval(F&& func, decltype(func()) fail) -> decltype(func()) {
53 | try {
54 | return func();
55 | }
56 | catch (...) {
57 | return fail;
58 | }
59 | }
60 |
61 | template
62 | R trapWithVals(F&& func, R succ, R fail, LG_Error** err) {
63 | try {
64 | func();
65 | return succ;
66 | }
67 | catch (const std::exception& e) {
68 | if (err) {
69 | *err = makeError(e.what());
70 | }
71 | }
72 | catch (...) {
73 | if (err) {
74 | *err = makeError("Unspecified exception");
75 | }
76 | }
77 |
78 | return fail;
79 | }
80 |
81 | template
82 | R trapWithVals(F&& func, R succ, R fail) {
83 | try {
84 | func();
85 | return succ;
86 | }
87 | catch (...) {
88 | return fail;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/include/chain.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | std::tuple<
26 | std::vector,
27 | std::string,
28 | std::vector
29 | >
30 | parseChain(const std::string& chain);
31 |
--------------------------------------------------------------------------------
/include/compiler.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "basic.h"
22 |
23 | #include "fwd_pointers.h"
24 |
25 | class Compiler {
26 | public:
27 |
28 | static ProgramPtr createProgram(const NFA& graph);
29 |
30 |
31 | };
32 |
--------------------------------------------------------------------------------
/include/container_out.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "ostream_join_iterator.h"
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | template > class C>
29 | std::ostream& operator<<(std::ostream& out, const C& con) {
30 | out << '[';
31 | std::copy(con.begin(), con.end(), ostream_join_iterator(out, ","));
32 | return out << ']';
33 | }
34 |
35 | template , typename A = std::allocator> class C>
37 | std::ostream& operator<<(std::ostream& out, const C& con) {
38 | out << '[';
39 | std::copy(con.begin(), con.end(), ostream_join_iterator(out, ","));
40 | return out << ']';
41 | }
42 |
--------------------------------------------------------------------------------
/include/decoders/asciidecoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "decoders/decoder.h"
22 |
23 | class ASCIIDecoder: public Decoder {
24 | public:
25 | ASCIIDecoder(const Decoder& trans):
26 | Trans(trans.clone())
27 | {}
28 |
29 | ASCIIDecoder(std::unique_ptr trans):
30 | Trans(std::move(trans))
31 | {}
32 |
33 | ASCIIDecoder(const ASCIIDecoder& other):
34 | Trans(other.Trans->clone())
35 | {}
36 |
37 | ASCIIDecoder(ASCIIDecoder&&) = default;
38 |
39 | ASCIIDecoder& operator=(const ASCIIDecoder& other) {
40 | Trans = std::unique_ptr(other.Trans->clone());
41 | return *this;
42 | }
43 |
44 | ASCIIDecoder& operator=(ASCIIDecoder&&) = default;
45 |
46 | virtual ASCIIDecoder* clone() const {
47 | return new ASCIIDecoder(*this);
48 | }
49 |
50 | virtual std::string name() const {
51 | std::ostringstream ss;
52 | ss << "ASCII" << Trans->name();
53 | return ss.str();
54 | }
55 |
56 | virtual std::pair next() {
57 | std::pair n = Trans->next();
58 | if (n.first >= 0x80) {
59 | n.first = -n.first-1;
60 | }
61 | return n;
62 | }
63 |
64 | virtual void reset(const byte* beg, const byte* end) {
65 | Trans->reset(beg, end);
66 | }
67 |
68 | virtual uint32_t maxByteLength() const {
69 | // ASCII is 1:1
70 | return Trans->maxByteLength();
71 | }
72 |
73 | private:
74 | std::unique_ptr Trans;
75 | };
76 |
--------------------------------------------------------------------------------
/include/decoders/bytesource.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "basic.h"
22 | #include "decoders/decoder.h"
23 |
24 | class ByteSource: public Decoder {
25 | public:
26 | ByteSource(const byte* beg, const byte* end):
27 | Cur(beg), End(end)
28 | {}
29 |
30 | ByteSource(const ByteSource&) = default;
31 |
32 | ByteSource& operator=(const ByteSource&) = default;
33 |
34 | virtual ByteSource* clone() const {
35 | return new ByteSource(*this);
36 | }
37 |
38 | virtual std::string name() const {
39 | return "";
40 | }
41 |
42 | virtual std::pair next() {
43 | if (Cur == End) {
44 | return std::make_pair(END, End);
45 | }
46 | else {
47 | const int32_t n = *Cur;
48 | return std::make_pair(n, Cur++);
49 | }
50 | }
51 |
52 | virtual void reset(const byte* beg, const byte* end) {
53 | Cur = beg;
54 | End = end;
55 | }
56 |
57 | virtual uint32_t maxByteLength() const {
58 | return 1;
59 | }
60 |
61 | private:
62 | const byte* Cur;
63 | const byte* End;
64 | };
65 |
--------------------------------------------------------------------------------
/include/decoders/decoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "basic.h"
22 |
23 | #include
24 | #include
25 |
26 | class Decoder {
27 | public:
28 | virtual ~Decoder() {}
29 |
30 | virtual Decoder* clone() const = 0;
31 |
32 | virtual std::string name() const = 0;
33 |
34 | virtual std::pair next() = 0;
35 |
36 | virtual void reset(const byte* beg, const byte* end) = 0;
37 |
38 | virtual uint32_t maxByteLength() const = 0;
39 |
40 | static const int32_t END;
41 | };
42 |
--------------------------------------------------------------------------------
/include/decoders/decoderfactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | liblightgrep: not the worst forensics regexp engine
3 | Copyright (C) 2013, Lightbox Technologies, Inc
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include