Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to ScanQr #406

Merged
merged 6 commits into from
Oct 24, 2023
Merged

Improvements to ScanQr #406

merged 6 commits into from
Oct 24, 2023

Conversation

ryanohoro
Copy link
Collaborator

@ryanohoro ryanohoro commented Oct 24, 2023

Describe the change

In an effort to improve the consistency of output from ScanQr the following changes are introduced:

  • Removes Type field which was confusing and imprecise
  • Converts Data field from string to list of strings
  • Adds the ability to scan multiple barcodes in one image (existing function now exposed)
  • Adds the ability to scan inverted QR codes (optional in the config, on by default)
  • Added numerous new test images for varying QR formats
  • Upgrades related dependencies for ScanQr
  • Upgrades related dependencies for ScanTranscode to fix failing tests in Python 3.11 These upgrades are already in poetry

Enabling inversion support adds some performance penalty. The following numbers are for an image with both a normal and an inverted QR code. Images with only one code will have a slightly lower penalty.

"elapsed":0.058496 support_inverted: True
"elapsed":0.042361 support_inverted: False

Describe testing procedures

Successfully built the container with included updated ScanQr tests. Confirmed correct event output from oneshot.

Sample output

./strelka-oneshot -l - -f src/python/strelka/tests/fixtures/test_qr_multi_inverted.png
{
    "file": {
        "depth": 0,
        "flavors": {
            "mime": ["image/png"],
            "yara": ["png_file"]
        },
        "name": "src/python/strelka/tests/fixtures/test_qr_multi_inverted.png",
        "scanners": ["ScanEntropy", "ScanExiftool", "ScanFooter", "ScanHash", "ScanHeader", "ScanLsb", "ScanOcr", "ScanPngEof", "ScanQr", "ScanTlsh", "ScanYara"],
        "size": 14335,
        "tree": {
            "node": "9fc2136c-1825-4e32-98d7-0e9959f93d48",
            "root": "9fc2136c-1825-4e32-98d7-0e9959f93d48"
        }
    },
    "request": {
        "attributes": {
            "filename": "src/python/strelka/tests/fixtures/test_qr_multi_inverted.png"
        },
        "client": "go-oneshot",
        "id": "9fc2136c-1825-4e32-98d7-0e9959f93d48",
        "source": "ubuntu",
        "time": 1698162502
    },
    "scan": {
        "entropy": {
            "elapsed": 0.000063,
            "entropy": 7.606290828895655
        },
        "exiftool": {
            "elapsed": 0.12819,
            "keys": [{
                    "key": "ImageWidth",
                    "value": 974
                }, {
                    "key": "ImageHeight",
                    "value": 440
                }
            ]
        },
        "footer": {
            "backslash": "H\\xa46\\x00\\xd8#\\xb5\\x01 $R\\x1b\\x00\\xec\\x91\\xda\\x00\\x10\\x12\\xa9\\r\\x00\\xf6Hm\\x00\\x08\\xe9\\xff\\x01\\x80yf\\xe2\\xc6\\xe3\\xbd\\xc8\\x00\\x00\\x00\\x00IEND\\xaeB`\\x82",
            "elapsed": 0.000048,
            "footer": "H�6\u0000�#�\u0001 $R\u001b\u0000��\u0000\u0010\u0012\r\u0000�Hm\u0000\u0008��\u0001�yf����\u0000\u0000\u0000\u0000IEND�B`�"
        },
        "hash": {
            "elapsed": 0.009965,
            "md5": "ce3dad271656ad5406c5e09bbafaff24",
            "sha1": "b260579ad6d7f6fb96e714a1c0fcd53cd04f0fd1",
            "sha256": "869e27f2be68742335fbfcadc3556271ddf4f471a43cc2c9779fe8fda94dd65a",
            "ssdeep": "384:zAuzwx+X9YjYJEdjD336wOwZsssssssssV:zAiw4S36wOwZsssssssssV",
            "tlsh": "T1E1526CEBA2682E560C9C315F9ED684708CD1C3C6584414D28DBC74A59F2B05C67ABEBF"
        },
        "header": {
            "backslash": "\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x03\\xce\\x00\\x00\\x01\\xb8\\x08\\x02\\x00\\x00\\x00\\x1b\\x93)\\xfa\\x00\\x007\\xc6IDATx\\xda\\xed\\xda_\\x8c_E\\xf9",
            "elapsed": 0.000046,
            "header": "�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0003\u0000\u0000\u0001\u0008\u0002\u0000\u0000\u0000\u001b�)�\u0000\u00007�IDATx���_�_E�"
        },
        "lsb": {
            "elapsed": 0.004859,
            "lsb": true
        },
        "ocr": {
            "elapsed": 0.136508
        },
        "png_eof": {
            "elapsed": 0.000047,
            "flags": ["no_trailer"]
        },
        "qr": {
            "data": ["https://www.example.com/", "Plain Text Code"],
            "elapsed": 0.058496,
            "flags": ["inverted"]
        },
        "tlsh": {
            "elapsed": 0.001471
        },
        "yara": {
            "elapsed": 0.002284,
            "matches": ["test"],
            "rules_loaded": 1
        }
    }
}

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of and tested my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@ryanohoro
Copy link
Collaborator Author

Closes #404

@phutelmyer phutelmyer merged commit ce2dc51 into target:master Oct 24, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants