core
Core functionality of codablellm.
DecompileConfig
dataclass
Configuration for decompiling binaries.
Source code in src/codablellm/core/decompiler.py
decompiler_args = field(default_factory=list)
class-attribute
instance-attribute
Positional arguments to pass to the decompiler's __init__ method.
decompiler_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
Keyword arguments to pass to the decompiler's __init__ method.
max_workers = None
class-attribute
instance-attribute
Maximum number of binaries to decompile in parallel.
recursive = False
class-attribute
instance-attribute
If True, recursively scan directories for binaries to decompile.
strict = False
class-attribute
instance-attribute
If True, raise exceptions on decompilation failures; otherwise, continue and log warnings.
symbol_remover = None
class-attribute
instance-attribute
Optional strategy used to remove symbols from decompiled functions.
DecompiledFunction
dataclass
Bases: Function
A decompiled function extracted from a compiled binary file.
Source code in src/codablellm/core/function.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 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 426 427 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 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
address
instance-attribute
The starting address of the function in the binary file.
architecture
instance-attribute
The architecture of the binary file from which the function was decompiled.
assembly
instance-attribute
Assembly code of the function.
create_uid(file_path, name, _repo_path=None)
staticmethod
Creates a UID for a function based on its file path and name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The full file path of the function definition. |
required |
name
|
str
|
The name of the function. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A UID string in the format: |
Source code in src/codablellm/core/function.py
to_stripped()
Creates a stripped version of the decompiled function with anonymized symbol names.
This method replaces all function symbols in both the function definition and assembly code
with generated placeholders (e.g., sub_<uuid>), ensuring sensitive or original identifiers
are removed. The resulting DecompiledFunction has an updated definition, stripped function name,
and modified assembly code.
Returns:
| Type | Description |
|---|---|
DecompiledFunction
|
A new |
Source code in src/codablellm/core/function.py
Decompiler
Bases: ABC
Abstract base class for a decompiler that extracts decompiled functions from compiled binaries.
Source code in src/codablellm/core/decompiler.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
decompile(path)
abstractmethod
Decompiles a binary and retrieves all decompiled functions contained in it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
The path to the binary file to be decompiled. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[DecompiledFunction]
|
A sequence of |
Source code in src/codablellm/core/decompiler.py
decompile_stripped(path, strategy)
Decompiles a binary and applies a symbol removal strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Path to the binary to decompile. |
required |
strategy
|
SymbolRemovalStrategy
|
Strategy for symbol removal. Options include "strip" (using the |
required |
Returns:
| Type | Description |
|---|---|
Sequence[DecompiledFunction]
|
A sequence of |
Source code in src/codablellm/core/decompiler.py
get_stripped_function_name(address)
abstractmethod
Returns the anonymized name for a function at the given address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
int
|
The memory address of the function. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A stripped-down or anonymized function name (e.g., |
Source code in src/codablellm/core/decompiler.py
ExtractConfig
dataclass
Configuration for extracting source code functions.
Source code in src/codablellm/core/extractor.py
accurate_progress = True
class-attribute
instance-attribute
Whether to accurately track progress by counting extractable files in advance. This may take longer to start but provides more accurate progress tracking.
checkpoint = 10
class-attribute
instance-attribute
The number of steps between saving checkpoints. Set to 0 to disable checkpoints.
exclude_subpaths = field(default_factory=set)
class-attribute
instance-attribute
A set of subpaths to exclude from extraction. If specified, these subpaths will be ignored.
exclusive_subpaths = field(default_factory=set)
class-attribute
instance-attribute
A set of subpaths to exclusively extract functions from. If specified, only these subpaths will be extracted.
extract_as_repo = True
class-attribute
instance-attribute
True if the path should be treated as a repository root for calculating relative function scopes.
extractor_args = field(default_factory=dict)
class-attribute
instance-attribute
Positional arguments to pass to the extractor's __init__ method. The keys are language
names. The values are sequences of arguments. For example, {'C': [arg1, arg2]}.
extractor_kwargs = field(default_factory=dict)
class-attribute
instance-attribute
Keyword arguments to pass to the extractor's __init__ method. The keys are language names.
The values are dictionaries of keyword arguments. For example, {'C': {'kwarg1': value1}}.
max_workers = None
class-attribute
instance-attribute
Maximum number of files to extract functions in parallel.
transform = None
class-attribute
instance-attribute
An optional transformation to apply to each source code function.
use_checkpoint = True
class-attribute
instance-attribute
True if a checkpoint file should be loaded and used to resume extraction.
Extractor
Bases: ABC
Abstract base class for source code extractors.
Extractors are responsible for parsing source code files and returning extracted function
definitions as SourceFunction instances.
Source code in src/codablellm/core/extractor.py
extract(file_path, repo_path=None)
abstractmethod
Extracts functions from the given source code file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
PathLike
|
The path to the source file. |
required |
repo_path
|
Optional[PathLike]
|
Optional repository root path to calculate relative function scopes. |
None
|
Returns:
| Type | Description |
|---|---|
Sequence[SourceFunction]
|
A sequence of |
Source code in src/codablellm/core/extractor.py
get_extractable_files(path)
abstractmethod
Retrieves all files that can be processed by the extractor from the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
A file or directory path to search for extractable files. |
required |
Returns:
| Type | Description |
|---|---|
Set[Path]
|
A sequence of |
Source code in src/codablellm/core/extractor.py
Function
dataclass
Bases: SupportsJSON
Base class for functions used in datasets.
Source code in src/codablellm/core/function.py
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
definition
instance-attribute
The source code of the function.
metadata
property
A read-only view of the metadata associated with the function.
Returns:
| Type | Description |
|---|---|
Mapping[str, Any]
|
A mapping containing the metadata associated with the function. |
name
instance-attribute
The name of the function.
path
instance-attribute
Absolute path to the file containing the function.
uid
instance-attribute
A unique identifier for the function. This should be unique across all functions in a dataset.
create_uid(file_path, name, repo_path=None)
staticmethod
Creates a unique identifier for a function.
The UID is constructed based on the function's file path and name. If a repository path is provided, the UID uses the file's relative path from the repository root to ensure precision across different subdirectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The path to the source code file containing the function definition. |
required |
name
|
str
|
The name of the function. |
required |
repo_path
|
Optional[Path]
|
Optional repository root path to calculate the relative file path. If provided, the UID is constructed using the relative path from the repository root. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string UID in the format of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given |
Source code in src/codablellm/core/function.py
get_function_name(uid)
staticmethod
Extracts the function name from a UID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uid
|
str
|
The unique identifier of the function. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The function name. |
Source code in src/codablellm/core/function.py
SourceFunction
dataclass
Bases: Function
A subroutine extracted from source code.
Source code in src/codablellm/core/function.py
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 176 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 218 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 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 331 332 333 334 335 336 337 338 339 340 | |
class_name = None
class-attribute
instance-attribute
The name of the class containing the function, if applicable.
end_byte
instance-attribute
The ending byte offset of the function definition in the source code file.
is_method
property
Indicates whether the function is a method of a class.
Returns:
| Type | Description |
|---|---|
bool
|
|
language
instance-attribute
The programming language of the source code.
start_byte
instance-attribute
The starting byte offset of the function definition in the source code file.
create_uid(file_path, name, repo_path=None, class_name=None)
staticmethod
Creates a unique identifier (UID) for a source function to be used as a dataset key.
The UID is based on the function's file path and name, and optionally includes the class name if the function is a method. If a repository path is provided, the UID uses the relative file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The full file path of the function definition. |
required |
name
|
str
|
The name of the function. |
required |
repo_path
|
Optional[Path]
|
Optional repository root path for relative path calculation. |
None
|
class_name
|
Optional[str]
|
The class name to include in the UID if the function is a method. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A UID string in the format: |
Source code in src/codablellm/core/function.py
from_source(file_path, language, definition, name, start_byte, end_byte, class_name=None, repo_path=None, metadata={})
classmethod
Creates a SourceFunction instance from source code information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The file path where the function is defined. |
required |
language
|
str
|
The programming language of the function. |
required |
definition
|
str
|
The full source code of the function definition. |
required |
name
|
str
|
The function name. |
required |
start_byte
|
int
|
The starting byte offset of the function in the source file. |
required |
end_byte
|
int
|
The ending byte offset of the function in the source file. |
required |
class_name
|
Optional[str]
|
Optional name of the class containing the function. |
None
|
repo_path
|
Optional[Path]
|
Optional repository root path for relative UID creation. |
None
|
metadata
|
Mapping[str, Any]
|
Additional metadata to associate with the function. |
{}
|
Returns:
| Type | Description |
|---|---|
SourceFunction
|
A |
Source code in src/codablellm/core/function.py
get_function_name(uid)
staticmethod
Extracts the function name from a UID, removing any class name prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uid
|
str
|
The unique identifier of the function. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The function name. |
Source code in src/codablellm/core/function.py
with_definition(definition, name=None, write_back=True, metadata={})
Creates a new SourceFunction instance with an updated definition and optional new name.
This method generates a new UID if a new name is provided, merges existing and new metadata, and optionally writes the updated definition back to the source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
str
|
The new function definition to use. |
required |
name
|
Optional[str]
|
Optional new function name. If not provided, retains the current function name and UID. |
None
|
write_back
|
bool
|
If |
True
|
metadata
|
Mapping[str, Any]
|
Additional metadata to merge with the existing function metadata. |
{}
|
Returns:
| Type | Description |
|---|---|
SourceFunction
|
A new |