Skip to content

Parser v1#1

Open
alexthenugget wants to merge 3 commits intomainfrom
parser_v1
Open

Parser v1#1
alexthenugget wants to merge 3 commits intomainfrom
parser_v1

Conversation

@alexthenugget
Copy link
Copy Markdown
Owner

No description provided.

v2

v3

Update README.md
Comment on lines +9 to +24
class OutputFormat(Enum):
"""Перечисление форматов вывода результатов анализа PE файла (text/json)."""

TEXT = "text"
JSON = "json"


class Color:
"""ANSI коды цветов для терминала."""

HEADER = '\033[95m'
RED = '\033[91m'
PINK = '\033[95m'
GREEN = '\033[92m'
END = '\033[0m'
BOLD = '\033[1m'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class OutputFormat(Enum):
"""Перечисление форматов вывода результатов анализа PE файла (text/json)."""
TEXT = "text"
JSON = "json"
class Color:
"""ANSI коды цветов для терминала."""
HEADER = '\033[95m'
RED = '\033[91m'
PINK = '\033[95m'
GREEN = '\033[92m'
END = '\033[0m'
BOLD = '\033[1m'
class OutputFormat(StrEnum):
"""Перечисление форматов вывода результатов анализа PE файла (text/json)."""
TEXT = "text"
JSON = "json"
class Color(StrEnum):
"""ANSI коды цветов для терминала."""
HEADER = '\033[95m'
RED = '\033[91m'
PINK = '\033[95m'
GREEN = '\033[92m'
END = '\033[0m'
BOLD = '\033[1m'

print(f"{indent_str}{colorize(name + ':', Color.PINK)} {value}")


def format_pe_info(pe_file: PEFile, sections: Optional[list[str]] = None) -> dict[str, Any]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все Optional убрать. Вместо них | None

"""Форматирует информацию о PE файле в словарь для JSON вывода."""
result: dict[str, Any] = {}

if sections is None or "dos" in sections:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

все вот эти dos и т.д. тоже вынести в какой-нибудь енам

}
result["DOS Header"] = dos_header

if sections is None or "pe" in sections:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нахрена 100 раз проверять, что sections is None?

return result


def print_pe_info(pe_file: PEFile, sections: Optional[list[str]] = None) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут комментарии ко всему методу аналогичные с Optional, енамом и проверкой

"""Перехватывает вывод print для сохранения в буфер."""
output_lines.append(" ".join(str(v) for v in values))

import builtins
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

откуда импорт посреди взялся вообще????

Comment on lines +215 to +225
def local_colorize(text: str, color: str) -> str:
"""Локальная версия colorize с настраиваемыми цветами."""
return f"{color}{text}{LocalColor.END}"

def local_print_section_header(title: str) -> None:
"""Локальная версия print_section_header с настраиваемыми цветами."""
print(local_colorize(f"\n=== {title} ===", LocalColor.RED + LocalColor.BOLD))

def local_print_field(name: str, value: Any, indent: int = 0) -> None:
"""Локальная версия print_field с настраиваемыми цветами."""
indent_str = " " * indent
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему это все внутри?

Comment on lines +228 to +230
globals()['colorize'] = local_colorize
globals()['print_section_header'] = local_print_section_header
globals()['print_field'] = local_print_field
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а как-то симпатичнее это можно сделать?

print_field("", "No imports found", 2)


def main() -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

громадина

combine_as_imports = true
include_trailing_comma = true

[tool.flake8]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну это вранье, оно отсюда не работает

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