Skip to content

Commit

Permalink
bump up
Browse files Browse the repository at this point in the history
  • Loading branch information
Catminusminus committed Jun 19, 2023
1 parent b5d015f commit 3f82782
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 495 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 FFRI Security, Inc.
Copyright 2023 FFRI Security, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Yet another implementation of [PEiD](https://github.com/K-atc/PEiD) with yara-py

## Requirements

- Python 3.7+
- poetry
- Python 3.11
- Poetry 1.2+

## Install

Expand All @@ -17,7 +17,7 @@ $ cd pypeid
$ poetry shell
$ poetry install --no-root
$ poetry build
$ pip install dist/pypeid-0.1.1-py3-none-any.whl
$ pip install dist/pypeid-0.1.2-py3-none-any.whl
$ python
>>> from pypeid import PEiDScanner
>>> scanner = PEiDScanner()
Expand All @@ -29,20 +29,20 @@ $ python

```
$ poetry run pytest
================================================================ test session starts ================================================================
platform linux -- Python 3.9.7, pytest-7.1.1, pluggy-1.0.0
================================================= test session starts ==================================================
platform linux -- Python 3.11.2, pytest-7.2.2, pluggy-1.0.0
rootdir: /home/ffri/pypeid
collected 3 items
tests/test_scanner.py ... [100%]
tests/test_scanner.py ... [100%]
================================================================= 3 passed in 1.79s =================================================================
================================================== 3 passed in 1.10s ===================================================
```

## Tested platform

- Ubuntu 20.04 on WSL2 & Python 3.9.7
- Ubuntu 22.04 on WSL2 & Python 3.11.2

## Author

Koh M. Nakagawa. © FFRI Security, Inc. 2020-2022
Koh M. Nakagawa. © FFRI Security, Inc. 2020-2023
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.6
python_version = 3.11
disallow_untyped_calls = True
disallow_untyped_defs = True

Expand Down
627 changes: 267 additions & 360 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
[tool.poetry]
name = "pypeid"
version = "0.1.1"
version = "0.1.2"
description = "Yet another implementation of PEiD with yara-python"
authors = ["Koh Nakagawa <tsunekou1019@gmail.com>"]
license = "Apache License 2.0"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7,<3.11"
yara-python = "^4.2.0"
python = "^3.11"
yara-python = "^4.3.0"

[tool.poetry.dev-dependencies]
mypy = "^0.942"
black = "^22.3.0"
pytest = "^7.1.1"
isort = "^5.10.1"
pip-licenses = "^3.5.3"
requests = "^2.27.1"

[tool.poetry.group.dev.dependencies]
mypy = "^1.1.1"
pytest = "^7.2.2"
black = "^23.1.0"
isort = "^5.12.0"
requests = "^2.28.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 2 additions & 2 deletions src/pypeid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
__version__ = "0.1.1"
__version__ = "0.1.2"

from .scanner import PEiDScanner
from .scanner import format_as_katc_peid
Expand Down
14 changes: 7 additions & 7 deletions src/pypeid/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
#
if __name__ == "__main__":
from .cli import main

main()
#
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
if __name__ == "__main__":
from .cli import main

main()
34 changes: 17 additions & 17 deletions src/pypeid/cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
#
def main() -> None:
import sys
from .scanner import PEiDScanner, format_as_katc_peid

if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} input_file")
return
peid_scanner = PEiDScanner()
scan_result = peid_scanner.scan_file(sys.argv[1])
print(format_as_katc_peid(scan_result))


if __name__ == "__main__":
main()
#
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
def main() -> None:
import sys
from .scanner import PEiDScanner, format_as_katc_peid

if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} input_file")
return
peid_scanner = PEiDScanner()
scan_result = peid_scanner.scan_file(sys.argv[1])
print(format_as_katc_peid(scan_result))


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/pypeid/scanner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
import yara
import logging
Expand Down
170 changes: 85 additions & 85 deletions tests/__main__.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
#
import sys
import os
import subprocess
import requests
import csv
from typing import Optional
from pypeid import PEiDScanner, format_as_katc_peid


script_dir: str = os.path.dirname(os.path.abspath(__file__))


def get_katc_peid() -> None:
try:
res = requests.get(
"https://github.com/K-atc/PEiD/releases/download/v0.1.1/PEiD"
)
with open(os.path.join(script_dir, "bin/PEiD"), "wb") as fout:
fout.write(res.content)
except requests.exceptions.RequestException as err:
print("Error occurs", file=sys.stderr)
print(f"{err}", file=sys.stderr)
sys.exit(1)


def katc_peid_exists() -> bool:
return os.path.exists(os.path.join(script_dir, "bin/PEiD"))


def is_katc_peid_prepared() -> bool:
return (
os.path.exists(os.path.join(os.getcwd(), "rules.zip"))
and os.path.exists(os.path.join(os.getcwd(), "rules"))
and os.path.exists(os.path.join(os.getcwd(), "yara"))
)


def get_katc_peid_output(path: str) -> Optional[str]:
peid_exe = os.path.join(script_dir, "bin/PEiD")
output_lines = (
subprocess.run([peid_exe, path], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split("\n")[:-1]
)

if any("WARN" in l for l in output_lines):
print("Error occurs.", file=sys.stderr)
return None

return "\n".join(
l
for l in output_lines
if "INFO" not in l and "=>" not in l and "RULES_FILE" not in l
)


def _main() -> None:
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} input_csv")
sys.exit(1)

if not katc_peid_exists():
get_katc_peid()

if not is_katc_peid_prepared():
subprocess.run([os.path.join(script_dir, "bin/PEiD"), "--prepare"], check=True)

target_csv = sys.argv[1]
peid_scanner = PEiDScanner()
with open(target_csv, "r") as fin:
reader = csv.reader(fin)
next(reader)
for path, _, _ in reader:
expected = get_katc_peid_output(path)
actual = format_as_katc_peid(peid_scanner.scan_file(path))
if expected != actual:
print(f"different from Katc version of PEiD @ {path}")
print("OK!")


if __name__ == "__main__":
_main()
#
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
import sys
import os
import subprocess
import requests
import csv
from typing import Optional
from pypeid import PEiDScanner, format_as_katc_peid


script_dir: str = os.path.dirname(os.path.abspath(__file__))


def get_katc_peid() -> None:
try:
res = requests.get(
"https://github.com/K-atc/PEiD/releases/download/v0.1.1/PEiD"
)
with open(os.path.join(script_dir, "bin/PEiD"), "wb") as fout:
fout.write(res.content)
except requests.exceptions.RequestException as err:
print("Error occurs", file=sys.stderr)
print(f"{err}", file=sys.stderr)
sys.exit(1)


def katc_peid_exists() -> bool:
return os.path.exists(os.path.join(script_dir, "bin/PEiD"))


def is_katc_peid_prepared() -> bool:
return (
os.path.exists(os.path.join(os.getcwd(), "rules.zip"))
and os.path.exists(os.path.join(os.getcwd(), "rules"))
and os.path.exists(os.path.join(os.getcwd(), "yara"))
)


def get_katc_peid_output(path: str) -> Optional[str]:
peid_exe = os.path.join(script_dir, "bin/PEiD")
output_lines = (
subprocess.run([peid_exe, path], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split("\n")[:-1]
)

if any("WARN" in l for l in output_lines):
print("Error occurs.", file=sys.stderr)
return None

return "\n".join(
l
for l in output_lines
if "INFO" not in l and "=>" not in l and "RULES_FILE" not in l
)


def _main() -> None:
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} input_csv")
sys.exit(1)

if not katc_peid_exists():
get_katc_peid()

if not is_katc_peid_prepared():
subprocess.run([os.path.join(script_dir, "bin/PEiD"), "--prepare"], check=True)

target_csv = sys.argv[1]
peid_scanner = PEiDScanner()
with open(target_csv, "r") as fin:
reader = csv.reader(fin)
next(reader)
for path, _, _ in reader:
expected = get_katc_peid_output(path)
actual = format_as_katc_peid(peid_scanner.scan_file(path))
if expected != actual:
print(f"different from Katc version of PEiD @ {path}")
print("OK!")


if __name__ == "__main__":
_main()
2 changes: 1 addition & 1 deletion tests/test_scanner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# (c) FFRI Security, Inc., 2020-2022 / Author: FFRI Security, Inc.
# (c) FFRI Security, Inc., 2020-2023 / Author: FFRI Security, Inc.
#
import os
import pytest
Expand Down

0 comments on commit 3f82782

Please sign in to comment.