working command structure and advanced llm Integration
This commit is contained in:
@@ -3,21 +3,32 @@
|
||||
# from pathlib import path
|
||||
import click
|
||||
|
||||
# This defines a group with name basic which will nest other comands to be imported in the main loop
|
||||
@click.group(name="basic")
|
||||
def basic_group(): pass
|
||||
|
||||
# Adds a simple commmand to be run with `ctf test` per the function name
|
||||
@click.command()
|
||||
def test():
|
||||
print("hello from test")
|
||||
|
||||
def Set_Challenge(comp: str, chal: str, setDirectory: bool):
|
||||
# set the current challenge and competition from input
|
||||
if state.current_comp != comp:
|
||||
state.current_comp=comp
|
||||
state.comp_dir=pathlib
|
||||
# TODO archive the old competitions
|
||||
# A simple command with a positional(required) argument name
|
||||
@click.command()
|
||||
@click.argument('name')
|
||||
def greet(name):
|
||||
print(f"hello {name}")
|
||||
|
||||
if state.current_chal != chal:
|
||||
state.current_chal=chal
|
||||
print("challenge already set")
|
||||
# TODO archive the old challenges
|
||||
# TODO set the directory to challenge directory, with ignore option
|
||||
# def Set_Challenge(comp: str, chal: str, setDirectory: bool):
|
||||
# # set the current challenge and competition from input
|
||||
# if state.current_comp != comp:
|
||||
# state.current_comp=comp
|
||||
# state.comp_dir=pathlib
|
||||
# # TODO archive the old competitions
|
||||
|
||||
# if state.current_chal != chal:
|
||||
# state.current_chal=chal
|
||||
# print("challenge already set")
|
||||
# # TODO archive the old challenges
|
||||
# # TODO set the directory to challenge directory, with ignore option
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,55 @@
|
||||
# src/forensics.py
|
||||
# src/ctf/forensics.py
|
||||
# Library for forensic analysis
|
||||
|
||||
import click
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
@click.group(name="forensics")
|
||||
def forensics_group(): pass
|
||||
|
||||
@forensics_group.command()
|
||||
def tf(): print("hello from forensics")
|
||||
|
||||
@dataclass
|
||||
class FileMetadata:
|
||||
filename: str
|
||||
size: int
|
||||
magic: str
|
||||
extension: str
|
||||
|
||||
@forensics_group.command()
|
||||
@click.argument('path', type=click.Path(exists=True))
|
||||
def inspect(path):
|
||||
p = Path(path)
|
||||
size = p.stat().st_size
|
||||
extension = p.suffix
|
||||
|
||||
try:
|
||||
with open(p, 'rb') as f:
|
||||
magic = f.read(4).hex().upper()
|
||||
except Exception:
|
||||
magic = "UNKNOWN"
|
||||
|
||||
meta = FileMetadata(
|
||||
filename=p.name,
|
||||
size=size,
|
||||
magic=magic,
|
||||
extension=extension
|
||||
)
|
||||
|
||||
# Present using Rich Table
|
||||
console = Console()
|
||||
table = Table(title=f"Metadata: {meta.filename}", show_header=False)
|
||||
table.add_column("Key", style="bold cyan")
|
||||
table.add_column("Value")
|
||||
|
||||
table.add_row("Filename", meta.filename)
|
||||
table.add_row("Size", f"{meta.size} bytes")
|
||||
table.add_row("Magic Bytes (Hex)", meta.magic)
|
||||
table.add_row("Extension", meta.extension)
|
||||
|
||||
console.print(table)
|
||||
return meta
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
# Parses and calls commands
|
||||
|
||||
import ctf.commands as commands
|
||||
from ctf.forensics import forensics_group
|
||||
import click
|
||||
|
||||
|
||||
def main():
|
||||
commands.test()
|
||||
@click.group()
|
||||
def cli(): pass
|
||||
|
||||
cli.add_command(forensics_group())
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user