Commit Graph
19 Commits
Author SHA1 Message Date
Willi BallenthinandWilli Ballenthin a6dd0faf9f fix: use integer division in get_printable_len for UTF-16 LE operands
`get_printable_len` returned a float for UTF-16 LE operands due to `/`
instead of `//`, violating the `-> int` annotation and silently
propagating a float into `_bb_has_stackstring`'s accumulator. Aligns
with the IDA extractor equivalent.

Closes SURF-58
2026-05-08 17:58:07 +02:00
Willi BallenthinandWilli Ballenthin fdd571eaed fix: close file handle in get_file_taste using a with statement
`get_file_taste` opened a file handle with `sample_path.open("rb").read(8)`,
discarding the file object without explicitly closing it. CPython reference-
counting closes it promptly in practice, but other implementations (PyPy,
Jython) and CPython under GC pressure may defer closure. Use a `with` statement
to guarantee the handle is released immediately after reading.
2026-05-08 17:58:07 +02:00
Willi BallenthinandWilli Ballenthin 316aeaf8e5 fix: remove unreachable backports.functools_lru_cache fallback
`functools.lru_cache` has been in the standard library since Python 3.2.
The project requires Python >=3.10, so the `except ImportError` branch
importing `backports.functools_lru_cache` can never execute.

Remove the try/except block and keep only the direct stdlib import.
Also remove `types-backports` from dev dependencies, `backports` from
`[tool.deptry.known_first_party]`, and `types-backports` from the
DEP002 ignore list in `pyproject.toml`.
2026-05-08 17:58:07 +02:00
Willi BallenthinandWilli Ballenthin d9402d8041 fix: add missing ELF branch in get_format_from_extension for .elf_ files
EXTENSIONS_ELF = "elf_" was defined but never used: get_format_from_extension
had branches for every other EXTENSIONS_* constant except ELF. Since .elf_
files are real test fixtures and a recognised input format, the fix is to add
the missing elif branch (and import FORMAT_ELF) rather than delete the
constant.

Closes #3031
2026-05-08 17:58:07 +02:00
Willi BallenthinandWilli Ballenthin a5082beed0 fix: remove unused gzip import in test_helpers.py 2026-04-23 18:04:10 +03:00
Willi BallenthinandWilli Ballenthin f6f3380fd3 fix: EXTENSIONS_DYNAMIC has inconsistent leading dots
Closes #3028
2026-04-23 18:04:10 +03:00
Willi BallenthinandWilli Ballenthin 9289f09f15 fix: load_one_jsonl_from_path: finally block runs on unrelated exceptions
Closes #3018
2026-04-23 18:04:10 +03:00
Ana Maria Martinez GomezandWilli Ballenthin 3cd97ae9f2 [copyright + license] Fix headers
Replace the header from source code files using the following script:
```Python
for dir_path, dir_names, file_names in os.walk("capa"):
    for file_name in file_names:
        # header are only in `.py` and `.toml` files
        if file_name[-3:] not in (".py", "oml"):
            continue
        file_path = f"{dir_path}/{file_name}"
        f = open(file_path, "rb+")
        content = f.read()
        m = re.search(OLD_HEADER, content)
        if not m:
            continue
        print(f"{file_path}: {m.group('year')}")
        content = content.replace(m.group(0), NEW_HEADER % m.group("year"))
        f.seek(0)
        f.write(content)
```

Some files had the copyright headers inside a `"""` comment and needed
manual changes before applying the script. `hook-vivisect.py` and
`pyinstaller.spec` didn't include the license in the header and also
needed manual changes.

The old header had the confusing sentence `All rights reserved`, which
does not make sense for an open source license. Replace the header by
the default Google header that corrects this issue and keep capa
consistent with other Google projects.

Adapt the linter to work with the new header.

Replace also the copyright text in the `web/public/index.html` file for
consistency.
2025-01-15 08:52:42 -07:00
ed5dd38e7e feat: auto-generate ruleset cache on source change (#2133)
* feat: auto-generate ruleset cache on source change

---------

Co-authored-by: mr-tz <moritz.raabe@mandiant.com>
Co-authored-by: Moritz <mr-tz@users.noreply.github.com>
Co-authored-by: Willi Ballenthin <wballenthin@google.com>
2024-08-26 14:01:10 +02:00
N0stalgikowandGitHub 0eb4291b25 Updating copyright across all files based on when it was first introduced. (#2027)
* updating copyright, back to the date of origin of file

* updating regex to account for linter violation
2024-03-13 14:04:53 +01:00
mr-tz 51ddadbc87 fix symbol generation, ordinals 2023-12-03 17:49:54 +02:00
Willi Ballenthin c86ab51210 fix copyright headers everywhere 2023-07-13 05:03:33 +02:00
Harsh MehtaandGitHub 74009eb4a4 Updated Copyright (#1383)
* Updated Copyright
2023-03-14 17:58:43 +01:00
William Ballenthin ac59e50b5f move capa/features/__init__.py logic to common.py
also cleanup imports across the board,
thanks to pylance.
2021-06-09 22:20:53 -06:00
Ana Maria Martinez Gomez c0d6468347 py3: Remove Python 2 tests
Tests don't need to support Python 2 any longer. Do not run tests with
Python 2.
2021-04-07 18:20:07 +02:00
William Ballenthin baeea5b6ec *: update license header to reference Apache 2.0
closes #173
2020-07-22 15:05:24 -06:00
William Ballenthin 3faf175da7 *: add license header
closes #144
2020-07-15 14:14:53 -06:00
William Ballenthin d23ef48bb6 pep8 2020-07-01 12:33:13 -06:00
William Ballenthin add3537447 import source files, forgetting about 938 prior commits 2020-06-18 09:13:19 -06:00