Core API Reference
utils
Generic helpers
Modules:
-
analyzer–Binary Analyzer utils
-
api–Threaded HTTP server
-
database–Generic abstraction layer for databases
-
repo–Generic abstraction for storing files
Functions:
-
create_tar–Create a tar.gz file containing the given files.
-
download_file–Download a file from the given URL and return a file-like object containing its content.
-
extract_tar–Unpack a tar file into the given directory.
-
get_appdata_dir–Returns an OS-dependent application data directory.
-
get_hash–Compute the SHA256 of the given data
-
get_minimal_paths–Calculate the minimal common prefix path from a list of paths and return it
-
is_stdin_piped–Return True if stdin is piped, False otherwise
-
is_stdout_piped–Return True if stdout is piped, False otherwise
-
parse_menuconfig–Parse menuconfig file and return a dict containing the configuration
-
parse_uri–Parse an uri and return it's components
-
run_process–Run the given command(s) in new process(es).
-
write_menuconfig–Write menuconfig options into the given path in menuconfig format
create_tar
create_tar(base_name: Path, files: Sequence[Union[Path, str]]) -> BytesIO
Create a tar.gz file containing the given files.
Parameters:
-
(base_namePath) –The name of the resulting tar.gz file. This will be used to set relative paths for each file in the archive.
-
–files (Sequence[Union[Path, str]]A sequence of str or Path objects representing files to include in the tar archive
Returns:
-
BytesIO(BytesIO) –A BytesIO object containing the tar.gz file data
Raises:
-
ValueError–If the input list is empty.
-
TypeError–If the input list contain elements that are neither str or Path objects.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
download_file
Download a file from the given URL and return a file-like object containing its content. Returns None if the URL is not valid or if an error occurs during the download.
Parameters:
-
(urlstr) –The URL of the file to be downloaded
-
(timeoutint, default:3600) –Timeout in seconds
Returns:
-
Optional[BytesIO]–Optional[BytesIO]: A BytesIO object containing the file's content, or None if an error occurred or the input was invalid
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
extract_tar
Unpack a tar file into the given directory.
Parameters:
-
(fileUnion[str, Path, BytesIO, bytes]) –The source of the tar archive. Can be a file path as string or Path object, a BytesIO object, or raw bytes data.
-
(toPath) –The destination directory where files will be extracted
Returns:
-
bool(bool) –True on success and False otherwise
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
get_appdata_dir
get_appdata_dir() -> Path
Returns an OS-dependent application data directory.
Creates the directory and its parents if it doesn't exist.
Returns:
-
Path(Path) –The Path to the application data directory.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
get_hash
get_hash(data: bytes) -> str
Compute the SHA256 of the given data
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
378 379 380 | |
get_minimal_paths
get_minimal_paths(paths: Sequence[Union[Path, str]]) -> Tuple[Path, List[Path]]
Calculate the minimal common prefix path from a list of paths and return it along with the relative paths.
This function finds the shortest common prefix that all provided paths share, then returns this common prefix as well as a list of paths made relative to this common prefix. This is useful for normalizing file structures or comparing paths.
Parameters:
-
–paths Sequence[Union[Path, str]]A sequence of string/Path objects representing path.
Returns:
-
Tuple[Path, List[Path]]–Tuple[Path, List[Path]]: A tuple where the first element is the minimal common prefix as a Path object and the second element is a list of paths relative to this common prefix.
Raises:
-
ValueError–If the input list is empty or if there's an error in finding a valid common prefix (should not occur under normal circumstances).
-
TypeError–If the input list contain elements that are neither str or Path objects.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
is_stdin_piped
is_stdin_piped() -> bool
Return True if stdin is piped, False otherwise
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
383 384 385 | |
is_stdout_piped
is_stdout_piped() -> bool
Return True if stdout is piped, False otherwise
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
388 389 390 | |
parse_menuconfig
parse_menuconfig(path: str | Path) -> Dict[str, Optional[str]]
Parse menuconfig file and return a dict containing the configuration
Parameters:
-
(path(str, Path)) –The path to the configuration file.
Returns:
-
dict(Dict[str, Optional[str]]) –A dictionary containing the options
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
parse_uri
cached
parse_uri(uri: str) -> Dict[str, Any]
Parse an uri and return it's components
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
run_process
run_process(process_args: Union[List[str], List[List[str]]], capture_output: bool = False, env: Optional[Dict[str, str]] = None, cwd: Optional[Union[str, Path]] = None, timeout: float = -1.0) -> Tuple[int, bytes, bytes]
Run the given command(s) in new process(es). Supports pipes when process_args is a list of lists.
Supports both single commands and pipes.
Parameters:
-
(process_argsUnion[List[str], List[List[str]]]) –List of command argument lists. Single command: ['echo', 'aaa']. Pipes: [['echo', 'aaa'], ['sed', 's/a/b/g']].
-
(capture_outputbool, default:False) –If True, capture stdout/stderr. Otherwise print to console.
-
(envOptional[Dict[str, str]], default:None) –Optional environment variables dictionary.
-
(cwdOptional[Union[str, Path]], default:None) –Optional working directory.
-
(timeoutfloat, default:-1.0) –Timeout in seconds. -1 for no timeout.
Returns:
-
int–Tuple of (returncode, stdout, stderr). If capture_output is False, stdout/stderr
-
bytes–are empty bytes.
Examples:
Single command: >>> run_process(['echo', 'aaa'], capture_output=True) (0, b'aaa\n', b'')
Pipeline: >>> run_process([['echo', 'aaa'], ['sed', 's/a/b/g']], capture_output=True) (0, b'bbb\n', b'')
With timeout: >>> run_process(['sleep', '10'], timeout=2, capture_output=True) (-9, b'', b'')
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
write_menuconfig
Write menuconfig options into the given path in menuconfig format
Parameters:
-
(path(str, Path)) –The path to the configuration file.
-
(optionsdict) –A dictionary containing the options
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/__init__.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
api
Threaded HTTP server
Classes:
-
ServerThread–A threaded HTTP server that runs a Flask application.
ServerThread
Bases: Thread
A threaded HTTP server that runs a Flask application.
This class extends the Thread class to host a Flask application in a separate thread,
allowing for non-blocking operation in applications that need to handle concurrent
requests. The server will run until explicitly shut down.
Parameters:
-
(appFlask) –The Flask application instance that this server will host.
-
(hoststr) –The host address (e.g., '127.0.0.1' or '0.0.0.0') on which the server will listen for incoming requests.
-
(portint) –The port number (typically between 1024 and 65535) on which the server will accept connections.
-
API Reference
Frontend API Reference
restapiFrontendRestAPI
Methods:
-
run–Starts the HTTP server, listening for incoming requests
-
shutdown–Shuts down the running server gracefully.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/api.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
run
run() -> None
Starts the HTTP server, listening for incoming requests and serving the Flask application.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/api.py
37 38 39 40 | |
shutdown
shutdown() -> None
Shuts down the running server gracefully.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/api.py
42 43 44 | |
repo
Generic abstraction for storing files
Classes:
-
Repo–A class that abstract the storage of files. Repository can be a local file based
Repo
Repo(uri: str, exist_ok: bool = False, secure: bool = True)
A class that abstract the storage of files. Repository can be a local file based or rely on a S3 compatible server to store and retrieve files.
Parameters:
-
(uristr) –The URI of the repository which could be local or S3. Local URIs typically start with "file://" and S3 URIs start with "s3://".
Methods:
-
delete_file–Deletes the specified file from either local filesystem or S3.
-
download_sharefile–Downloads and returns the content of a file from a given URL or local path.
-
get_file–Retrieves the content of the specified file from either local filesystem or S3.
-
get_sharefile–Returns the path or URL for sharing the file.
-
list_directory–Lists all files in the specified directory from either local filesystem or S3.
-
push_file–Pushes or uploads a file to the specified path in either local filesystem or S3.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
delete_file
delete_file(upload_path: str) -> None
Deletes the specified file from either local filesystem or S3.
Parameters:
-
(upload_pathstr) –The path of the file to be deleted.
Raises:
-
ValueError–If URI scheme is unsupported.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
download_sharefile
staticmethod
Downloads and returns the content of a file from a given URL or local path.
Parameters:
-
(urlstr) –The URL or local path to the file to be downloaded.
-
(timeoutint, default:3600) –Timeout in seconds
Returns:
-
Optional[bytes]–bytes | None: The content of the file if found, otherwise None.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
get_file
get_file(upload_path: str) -> Optional[bytes]
Retrieves the content of the specified file from either local filesystem or S3.
Parameters:
-
(upload_pathstr) –The path of the file to be retrieved.
Returns:
-
Optional[bytes]–bytes | None: The content of the file if found, otherwise None.
Raises:
-
ValueError–If URI scheme is unsupported.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
get_sharefile
get_sharefile(upload_path: str) -> Path | str
Returns the path or URL for sharing the file.
Parameters:
-
(upload_pathstr) –The path of the file to be shared.
Returns:
-
Path | str–Path | str: A POSIX absolute path if local, a pre-signed URL if S3.
Raises:
-
ValueError–If URI scheme is unsupported.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
list_directory
list_directory(path: str | Path) -> list[str]
Lists all files in the specified directory from either local filesystem or S3.
Parameters:
-
(pathstr | Path) –The directory to be listed.
Returns:
-
list[str]–list[str]: A list of file names and directories within the specified path.
Raises:
-
ValueError–If URI scheme is unsupported.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
push_file
push_file(upload_path: str, content: bytes) -> bool
Pushes or uploads a file to the specified path in either local filesystem or S3.
Parameters:
-
(upload_pathstr) –The path where the file should be uploaded.
-
(contentbytes) –The content of the file to be uploaded.
Returns:
-
bool(bool) –True if successful, False otherwise.
Raises:
-
ValueError–If URI scheme is unsupported.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/repo.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
database
Generic abstraction layer for databases
Classes:
-
Database–A class to manage connections and operations for various database types,
Database
A class to manage connections and operations for various database types, including SQLite, PostgreSQL, and MySQL.
Parameters:
-
(uristr) –The URI string used to parse connection parameters.
-
(exist_okbool, default:False) –If True, allows the creation of new databases. Defaults to False.
Methods:
-
close–Close the database connection safely. This method is Thread safe.
-
connect–Establish a connection to the database using parameters parsed from the URI.
-
execute–Execute an SQL query with optional parameters. This method is Thread safe.
-
fetch–Fetch results from a query, with support for fetching all, one, or many rows.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/database.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
close
close() -> None
Close the database connection safely. This method is Thread safe.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/database.py
217 218 219 220 221 222 223 224 225 | |
connect
connect(exist_ok: bool = True) -> None
Establish a connection to the database using parameters parsed from the URI.
Parameters:
-
(exist_okbool, default:True) –If True, allows the creation of new databases. Defaults to True.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/database.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
execute
Execute an SQL query with optional parameters. This method is Thread safe.
Parameters:
-
(querystr) –The SQL command to execute.
-
(paramsOptional[Tuple], default:None) –Optional parameters for the query execution.
Returns:
-
Optional[int]–Optional[int]: An optional integer corresponding to the ID of the inserted row.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/database.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
fetch
fetch(request: str, parameters: Tuple = (), mode: str = 'all') -> List[Tuple]
Fetch results from a query, with support for fetching all, one, or many rows. This method is Thread safe.
Parameters:
-
(requeststr) –The SQL query to execute.
-
(parameterstuple, default:()) –Optional parameters for the query execution. Defaults to an empty tuple.
-
(modestr, default:'all') –Mode of fetching: 'all', 'one', or 'many'. Defaults to 'all'.
Returns:
-
List[Tuple]–list[tuple]: Result set from the executed query.
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/database.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
analyzer
Binary Analyzer utils
Functions:
-
build_script–Compile Ghidra scripts to .class files to speed up loading process
-
clean_install–Cleanup ghidra directory with the file we have installed
-
create_bsim_database–Create an empty BSIM database
-
get_ghidra_languages–Return the list of Ghidra supported languages
-
get_ghidra_version–Return the version of a given ghidra installation or None on failure
-
run_ghidra_script–Run a given Ghidra script
build_script
build_script(ghidradir: Path, script_dir: Path) -> None
Compile Ghidra scripts to .class files to speed up loading process and avoid random OSGi errors
Reversed from https://github.com/NationalSecurityAgency/ghidra/blob/ 7dd38f2d95597c618af3d921f950fd6674805dd2/Ghidra/Features/ Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java#L1019
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
clean_install
clean_install(ghidradir: Path, jars: Optional[List[str]] = None) -> None
Cleanup ghidra directory with the file we have installed
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
12 13 14 15 16 17 18 19 20 21 22 23 | |
create_bsim_database
create_bsim_database(ghidradir: Path, bsim_urls: list[str], config_template: str = 'medium_nosize', username: str = 'bsim_user', capture_output: bool = False) -> bool
Create an empty BSIM database
Enumerated Options:
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
get_ghidra_languages
get_ghidra_languages(ghidradir: Path) -> List[str]
Return the list of Ghidra supported languages
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
get_ghidra_version
get_ghidra_version(ghidradir: Path) -> Optional[str]
Return the version of a given ghidra installation or None on failure
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
run_ghidra_script
run_ghidra_script(ghidradir: Path, script: Path, args: List[str], env: Optional[Dict[str, str]] = None, capture_output: bool = False, logfile: Optional[Path] = None) -> tuple[int, bytes, bytes]
Run a given Ghidra script
Source code in venv/lib/python3.12/site-packages/sighthouse/core/utils/analyzer.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |