Executables¶
The Executable class allows to abstract an executable. It inherits from the tinyscript.Path class, based on pathlib's one.
Use Cases¶
This class can be used in four different ways:
-
As a classical
Pathinstance, not bound to aDatasetinstance```console
exe = Executable("test.exe") exe.filetype 'PE32 executable (GUI) Intel 80386, for MS Windows' ``
-
As a classical
Pathinstance with aDatasetinstance specified, to be bound```console
exe = Executable("test.exe", dataset=Dataset("my-dataset")) exe.signature # data gets retrieved from "my-dataset" 'PE32 executable (GUI) Intel 80386, for MS Windows, UPX compressed' ``
Note that, in this case, the file is required to compute attributes.
-
With exactly one positional argument being the data row with all the attributes to be added to the bound dataset
```console
exe = Executable("test.exe", dataset=Dataset("my-dataset")) exe.signature # data gets retrieved from "my-dataset" 'PE32 executable (GUI) Intel 80386, for MS Windows, UPX compressed' ``
Note that, in this case, the file is not required as attributes come from the input data row.
-
With no positional argument but a
Datasetinstance and a hash as keyword-arguments ; this will bind theExecutableinstance to the dataset, getting its attributes with data coming from the dataset, and make its path point to the executable with the given hash from within the dataset```console
exe = Executable(hash="9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", dataset=Dataset("my-dataset")) exe.signature # data gets retrieved from "my-dataset" 'PE32 executable (GUI) Intel 80386, for MS Windows, UPX compressed' ``
Note that, in this case, the file is not required as attributes are retrieved from dataset's data.
-
With no positional argument but a source
Datasetinstance as dataset, a destinationDatasetinstance as dataset2 and a hash as keyword-arguments ; this will bind theExecutableinstance to the source dataset and copy its attributes to the destination dataset```console
exe = Executable(hash="9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", dataset=Dataset("my-dataset"), dataset2=Dataset("my-new-dataset")) ``
Supported Formats¶
This abstraction handles multiple executable formats sorted in categories:
All
+-- ELF
| +-- ELF32 ^(set[gu]id )?ELF 32-bit
| +-- ELF64 ^(set[gu]id )?ELF 64-bit
+-- Mach-O
| +-- Mach-O32 ^Mach-O 32-bit
| +-- Mach-O64 ^Mach-O 64-bit
| +-- Mach-Ou ^Mach-O universal binary
+-- MSDOS ^MS-DOS executable\s*
+-- PE
+-- .NET ^PE32\+? executable (.+?)\.Net assembly
+-- PE32 ^PE32 executable
+-- PE64 ^PE32\+ executable
Each processing depending on categories flattens its list from this tree structure ; e.g. ["PE", "ELF64"] will be expanded to [".NET", "PE32", "PE64", "ELF64"]
Executable Class¶
This class subclasses ts.Path (from Tinyscript), itself extending pathlib.Path with additional methods.
>>> exe = Executable("hello-world.exe")
>>> exe.category
'.NET'
>>> exe.ctime
datetime.datetime(2021, 7, 8, 7, 41, 4, 875819)
>>> exe.hash
'889ce94c1f7f909c045247adf1f883928e7760cb9e49f2340a233a361f690d28'
>>> exe.data
{'dll_characteristics_1': 0, 'dll_characteristics_2': 0, 'dll_characteristics_3': 0, [...]
This abstraction facilitates the retrieval of important attributes and the integration of new features.
Attributes:
_dataset: parentDatasetinstance (if any)label: packer label (if any)
Properties:
ctime*: creation time as adatetimeinstancedata*: set of features computed based on theformatdestination*: destination path for integrating the executable into a dataset (only works if aDatasetinstance is bound)features: dictionary of features (key: feature name, value: feature description)filetype*: file type description (based onpython-magic)format*: executable format (e.g. PE, ELF32, .NET)hash*: file hash (based onhashlib)metadata: dictionary with properties (see hereafter)realpath,format,size,ctimeandmtimemtime*: last modification time as adatetimeinstancerealpath*: real path the executable comes from (only works if aDatasetinstance is bound)-
size: size of the executable as an integer
Methods:
alter(): apply alterations to the executablecopy(): copy the file toself.destination, that is, to the dataset it is bound to (note that its permissions are restricted to READ for the owner, that isuser)modify(name): apply a modifier bynameto the executableobjdump(n): dumpndisassembled bytes from the executableparse(name): parse the binary with a given parser byname(by default, the one defined in~/.packing-box.confor, if not defined, the default from thepboxpackage)plot(...): plot the executable's sections with colors and entropy levelsshow(...): show information about the executable