dataset
Code dataset generation.
DatasetGenerationMode = Literal['path', 'temp', 'temp-append']
module-attribute
How the dataset should be generated.
Generation Modes
-
path: Generates the dataset directly from the local repository path.- Note: If
extract_config.transformis provided, the source code in the local repository may be overridden by the transformed code.
- Note: If
-
temp: Copies the repository to a temporary directory and generates the dataset there.- If
extract_config.transformis not provided, the mode defaults topath.
- If
temp-append: Copies the repository to a temporary directory, applies the transformation usingextract_config.transform, and appends the transformed entries to the original source code from the local repository.- If
extract_config.transformis not provided, the mode defaults topath.
- If
Dataset
Bases: ABC
A code dataset.
Source code in src/codablellm/dataset.py
save_as(path)
Converts the dataset to a DataFrame and exports it to the specified file path based on
its extension. The export format is determined by the file extension provided in the
path parameter.
Example
Successfully saves the dataset as an Excel file to "output.xlsx".
Supported Formats and Extensions
- JSON: .json, .jsonl
- CSV/TSV: .csv, .tsv
- Excel: .xlsx, .xls, .xlsm (requires codablellm[excel])
- Markdown: .md, .markdown (requires codablellm[markdown])
- LaTeX: .tex
- HTML: .html, .htm
- XML: .xml (requires codablellm[xml])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Path to save the dataset at. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided file extension is unsupported. |
ExtraNotInstalled
|
If the file extension requires an additional library that is not installed. |
Source code in src/codablellm/dataset.py
to_df()
abstractmethod
Converts the code dataset to a pandas DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame representation of the code dataset. |
DecompiledCodeDataset
Bases: Dataset, Mapping[str, MappedFunction]
A dataset of decompiled functions mapped to their corresponding potential source functions.
This class provides functionality to manage and interact with decompiled functions and their possible source code counterparts, allowing for easy lookup by unique identifiers (UIDs).
Source code in src/codablellm/dataset.py
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 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
__init__(mappings)
Initializes a new decompiled code dataset instance with a collection of mappings between decompiled functions and their potential source functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappings
|
Iterable[MappedFunction]
|
An iterable collection of 2-tuples, where each tuple consists of the decompiled function and the corresponding potential source functions. |
required |
Source code in src/codablellm/dataset.py
from_repository(path, bins, extract_config=extractor.ExtractConfig(), dataset_config=DecompiledCodeDatasetConfig())
classmethod
Creates a decompiled code dataset from a built local repository.
This method scans the specified local repository, decompiles the provided binaries, and generates a dataset of decompiled functions mapped to their corresponding potential source code functions based on the provided extraction and dataset configuration.
Example
DecompiledCodeDataset.from_repository('path/to/my/repository',
[
'path/to/my/repository/bin1.exe',
'path/to/my/repository/bin2.exe'
],
extract_config=ExtractConfig(
transform=remove_comments
),
dataset_config=DecompiledCodeDatasetConfig(
strip=True
)
)
The above example creates a decompiled code dataset from a copy of
path/to/my/repository, removes all comments from the extracted source code
functions, decompiles the binaries bin1.exe and bin2.exe, and strips the symbols
after decompilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Path to the local repository to generate the dataset from. |
required |
bins
|
Collection[PathLike]
|
A sequence of paths to the built binaries of the repository that should be decompiled. |
required |
extract_config
|
ExtractConfig
|
Configuration settings for extracting source code functions. |
ExtractConfig()
|
dataset_config
|
DecompiledCodeDatasetConfig
|
Configuration settings for generating the decompiled code dataset. |
DecompiledCodeDatasetConfig()
|
Returns:
| Type | Description |
|---|---|
DecompiledCodeDataset
|
The generated dataset containing mappings of decompiled functions to their potential source code functions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/codablellm/dataset.py
lookup(key)
Finds all mappings where the given key may correspond to potential source functions.
The method searches through the dataset and returns all decompiled functions and their associated source code datasets where the specified key matches one of the source functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[str, SourceFunction]
|
The key to search for, which can be either a source function UID or a |
required |
Returns:
| Type | Description |
|---|---|
List[MappedFunction]
|
A list of tuples, where each tuple consists of a decompiled function and its |
List[MappedFunction]
|
corresponding source code dataset containing the potential matches. |
Source code in src/codablellm/dataset.py
to_source_code_dataset()
Converts the decompiled code dataset into a source code dataset.
This method aggregates all source functions from the decompiled code dataset
and constructs a SourceCodeDataset containing only the source functions.
Returns:
| Type | Description |
|---|---|
SourceCodeDataset
|
A dataset containing all source functions extracted from the decompiled code dataset. |
Source code in src/codablellm/dataset.py
to_stripped_dataset()
Converts the decompiled code dataset into a stripped decompiled code dataset.
The method applies the stripping process to each decompiled function in the dataset, resulting in a dataset with stripped versions of the decompiled functions.
Returns:
| Type | Description |
|---|---|
DecompiledCodeDataset
|
A new dataset where all decompiled functions have been stripped. |
Source code in src/codablellm/dataset.py
DecompiledCodeDatasetConfig
dataclass
Configuration options for generating a decompiled dataset.
This class defines the settings for extracting source code functions from binaries and configuring the decompilation process.
Source code in src/codablellm/dataset.py
decompiler_config = field(default_factory=(decompiler.DecompileConfig))
class-attribute
instance-attribute
Configuration settings for decompiling binaries.
extract_config = field(default_factory=(extractor.ExtractConfig))
class-attribute
instance-attribute
Configuration settings for extracting source code functions.
mapper = DEFAULT_MAPPER
class-attribute
instance-attribute
The mapping function used to determine if a decompiled function corresponds to a given source function.
SourceCodeDataset
Bases: Dataset, Mapping[str, SourceFunction]
A source code dataset.
This class provides functionality to manage and interact with a collection of source functions, allowing indexing and mapping by unique identifiers (UIDs)
Source code in src/codablellm/dataset.py
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 341 342 343 344 345 346 | |
__init__(functions)
Initializes a new source code dataset instance with a collection of source functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
|
Iterable[SourceFunction]
|
An iterable collection of source code functions used to populate the dataset. |
required |
Source code in src/codablellm/dataset.py
from_repository(path, config=SourceCodeDatasetConfig(log_generation_warning=False))
classmethod
Creates a source code dataset from a local repository.
This method scans the specified repository and generates a dataset of source code functions based on the provided configuration. Optionally, it can return a callable pool that allows deferred execution of the dataset generation process.
Example
SourceCodeDataset.from_repository('path/to/my/repository',
config=SourceCodeDatasetConfig(
generation_mode='path'
extract_config=ExtractConfig(
transform=remove_comments
)
)
)
Will create a source code dataset from path/to/my/repository, overriding the contents
of the repository and removing all comments from the extracted source code functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Path to the local repository to generate the dataset from. |
required |
config
|
SourceCodeDatasetConfig
|
Configuration settings for dataset generation. |
SourceCodeDatasetConfig(log_generation_warning=False)
|
as_callable_pool
|
If |
required |
Returns:
| Type | Description |
|---|---|
SourceCodeDataset
|
The generated source code dataset if |
Source code in src/codablellm/dataset.py
get_common_directory()
Returns the common directory shared by all entries in the dataset. This typically represents the path to the local repository from which the dataset was generated.
Returns:
| Type | Description |
|---|---|
Path
|
The common directory path for all dataset entries. |
Source code in src/codablellm/dataset.py
SourceCodeDatasetConfig
dataclass
Configuration options for generating a source code dataset.
This class provides flexible options for controlling how a source code dataset is generated, including handling of temporary directories, extraction settings, and generation modes.
Source code in src/codablellm/dataset.py
delete_temp = True
class-attribute
instance-attribute
Controls whether the temporary directory should be deleted after dataset generation.
- Applies only if
generation_modeis set totemp. When set toTrue, the temporary directory will be automatically deleted after dataset generation.
extract_config = field(default_factory=(extractor.ExtractConfig))
class-attribute
instance-attribute
Configuration settings for extracting source code functions.
generation_mode = 'temp'
class-attribute
instance-attribute
How the source code dataset should be generated.