470 Commits

Author SHA1 Message Date
Djordje Todorovic 46bc14bc73 Model: Add an opt for user defined paths of PDB 2022-07-28 14:52:50 +02:00
Djordje Todorovic a36e22729f Model: Add PDB support 2022-07-28 14:52:50 +02:00
Djordje Todorovic 9efb9cb55f Model: Add parsing of delay dyn syms to PECOFF
This parses dedicated symbols similar to ELF's lazy linking.
2022-07-28 14:52:02 +02:00
Djordje Todorovic b3cd1316f0 ELFImporter: Fix the documentation comment 2022-07-28 14:52:02 +02:00
Djordje Todorovic 098f864d8d Model: Add parsing of dyn syms to PECOFFImporter
This parses symbols similar to ELF's .dynsym.
2022-07-28 14:52:02 +02:00
Djordje Todorovic b79158bafc Model: Add parseSymbols() to PECOFFImporter
This parses symbols similar to ELF's .symtab.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 9d18d84f68 ELFImporter: Improve the parseSymbols()
This is an NFC.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 5a72d968e5 Model: Add a method for parsing pe sections hdrs
This is an NFC.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 8cbdcf278d Model: Import PE when file size is > than virtual
Without this patch, the import part would fail with an assertion
even for a simple case since it doesn't expect that file size
could be larger than virtual.

From the microsoft documentation:
```
Because the SizeOfRawData field is rounded but the VirtualSize field
is not, it is possible for SizeOfRawData to be greater than
VirtualSize as well. When a section contains only uninitialized data,
this field should be zero.
```
We rather choose not to percolate this into the Model.
2022-07-28 14:52:02 +02:00
Djordje Todorovic 6d390af909 Model: Factor target-dep code out of ELFImporter 2022-07-28 14:51:40 +02:00
Giacomo Vercesi 09009836a1 PipelineC: expose globals verification 2022-07-28 08:47:46 +02:00
Alessandro Di Federico d42fb9bb13 Segment::verify(): relocations can be out segment
We used to check that the target address of a relocation needs to be
within the `model::Segment` it's referring to.
However this is not correct.
2022-07-27 18:57:21 +02:00
Antonio Frighetto 4bc21328d8 Model: reserve type prefixes 2022-07-22 16:10:51 +02:00
Antonio Frighetto 5500fadb0e MachOImporter: add segment name 2022-07-22 16:10:51 +02:00
Antonio Frighetto 186d907be3 Model: extend model::Segment
`Segment` now includes a `Type` of struct kind. This is intended to
emit the segment as a struct later in decompilation. The implementation
of name has also been added.
2022-07-22 16:10:51 +02:00
Giacomo Vercesi 24c51f385a CMake: generate model.ts 2022-05-09 13:37:58 +02:00
Alessandro Di Federico a4d7e78856 Stop registering Invalid model::Functions 2022-04-29 17:57:49 +02:00
Alvise de Faveri a3110c0b59 Add QualifiedType::is(TypeKind) 2022-04-20 11:25:46 +02:00
Massimo Fioravanti 44720eedbd Redesign TupleTreeDiff
`TupleTreeDiff` is now type-safe and owns the changes.
2022-04-15 15:14:13 +02:00
Pietro Fezzardi 7f65b1117a New AddPrimitiveTypesPipe
This pipe is executed during the Lift step and populates the model with
all the required primitive types.
2022-04-12 16:40:27 +02:00
Pietro Fezzardi 6b2b2e8ada Make model::Type::edges() method const 2022-04-08 18:58:58 +02:00
Pietro Fezzardi e40ded965f QualifiedType RawFunctionType.StackArgumentsType
The `StackArgumentsType` field of `RawFunctionType` was the only
cross-reference between `model::Type`s that did not use
`model::QualifiedType` but a naked `TupleTreeReference`.

Switching it to `QualifiedType` make all cross-references across
`model::Type`s homogeneous.
2022-04-08 18:58:58 +02:00
Pietro Fezzardi 63a6676551 Make EnumType.UnderlyingType a QualifiedType
This was one of the few places left in the type system where a
`model::Type` referred to another one not using QualifiedType, but a
naked `TupleTreeReference`.

Switching it to be a `model::QualifiedType` makes cross-references
between `model::Type`s more homogenenous, requiring less corner-cases
to handle for whoever manipulates types.
2022-04-08 18:58:58 +02:00
Giacomo Vercesi a2b5dbb1dc TupleTreeGenerator: autogenerate Kind 2022-04-08 17:36:59 +02:00
Giacomo Vercesi 039f7db93e model::*: ensure Kind -> Class correspondence 2022-04-08 17:31:05 +02:00
Antonio Frighetto 20cdfe668a EFA: take the control-flow graph out of the model
The control-flow graph and all its hierarchy components
have been moved from `model` to `efa`. The CFG is now
serialized onto the LLVM IR module as a metadata.
2022-04-05 15:37:57 +02:00
Ivan Krysak 1b03adca5e Make function type convertions self-sufficient 2022-03-28 15:38:04 +02:00
Massimo Fioravanti b2dfd2bc64 TupleTreeGenerator.cmake: single call generation 2022-03-28 12:17:05 +02:00
Massimo Fioravanti 5bdce4bf36 LoadModelPass: support command-line path
It is now possible to load a model from file instead of the one written
in the module itself:

    revng opt --model-path=<path>
2022-03-28 12:17:05 +02:00
Alessandro Di Federico af1828e090 DwarfImporter: better support for 0-sized types
We now ignore field of `struct`/`union` that have a 0-sized type.
We now also ignore types containing a an array with 0-sized elements.
2022-03-28 12:17:05 +02:00
Alessandro Di Federico 67706f05b6 Introduce a never-failing Type::trySize 2022-03-28 12:17:05 +02:00
Filippo Cremonese 70a460c46a TupleTreeGenerator: use dataclasses
Give up on pydantic.
2022-03-22 17:52:02 +01:00
Alessandro Di Federico 2b55d1df22 Adopt cmake-format 2022-03-17 18:52:18 +01:00
Pietro Fezzardi fb54cc22a2 QualifiedType: new typedef-aware helper methods
This commit reworks the helper methods for model::QualifiedType, to
properly traverse typedefs.

These methods are used to check if a QualifiedType is:
- scalar
- primitive
- float
- void
- pointer
- array

This commit add the methods for checking pointers and arrays (that
weren't available before), reworks all the helpers so that they all
traverse typedefs, and adds comments so that it's clear that they
traverse typedefs.
2022-03-17 17:03:28 +01:00
Pietro Fezzardi 630fee4500 model::Qualifier: add static methods for filtering
This commit adds the static methods:
- model::Qualifier::isConst
- model::Qualifier::isArray
- model::Qualifier::isPointer

These methods replace the old, non-static, methods:
- model::Qualifier::isConst
- model::Qualifier::isArray
- model::Qualifier::isPointer

Having these method static is very helpful for filtering, when
iterating on sequences of qualifiers, such as:

  for (const auto &Q :
       llvm::make_filter_range(Qualifiers, Qualifier::isPointer)) {
    // do stuff with Q
  }

This will be very helpful for defining other helper functions for
model::QualifiedType.

This commit also drops the non-static version of the methods, since they
are redundant, and because they would cause ambiguity and failure of
type inference in the snippet above, making them effectively useless for
the goal they were designed for, which is filtering ranges.
2022-03-17 17:03:22 +01:00
Pietro Fezzardi 0158354dc7 DwarfImporter: fix order of Qualifiers
Before this commit the DwarfImporter was importing qualifiers in
reverse order.

As an example the following declaration in C:

  int *x[4];

was imported as a pointer to array, instead of an array of pointers.

This commit fixes the order of the qualifiers.
2022-03-17 17:02:48 +01:00
Alessandro Di Federico ea6383c476 mv {d,registerD}efaultFunctionPrototype 2022-03-17 14:10:50 +01:00
Alessandro Di Federico bc8e6a6a24 Minor changes 2022-03-16 22:10:15 +01:00
Alessandro Di Federico 0793e4afcb Turn lifting into a pass 2022-03-11 15:37:12 +01:00
Alessandro Di Federico ee0b8f44c1 Introduce BinaryImporter
This is a big step to split revng-lift in two parts: one that only
writes the model and one that actually lifts to LLVM IR.

* Introduce `revng import binary`
* Split off `BinaryFile.h`
* Drop `revng.h`
* `GeneratedCodeBasicInfo`: use model
* Reduce role of `GeneratedCodeBasicInfo` in favor of
  `model::Architecture` and `model::Register` methods
* `CodeGenerator`: adopt `RawBinaryView` and model
* `JumpTargetManager`: adopt `RawBinaryView` and model
* `ExternalJumpsHandler`: adopt model
* `InstructionTranslator`: discard `Architecture` in favor of
  `EndianessMismatch`
* Many other changes
2022-03-08 15:15:24 +01:00
Alessandro Di Federico e9b1879067 Handle invalid model::DynamicFunction::Prototype 2022-03-08 15:04:34 +01:00
Alessandro Di Federico 0a5d2c04a7 Rework LoadModelPass 2022-03-08 15:04:34 +01:00
Alessandro Di Federico 1a57229693 Introduce model::Binary::DefaultPrototype 2022-03-08 15:04:34 +01:00
Alessandro Di Federico a88a9e52c3 Improve model::Segment 2022-03-08 13:06:47 +01:00
Alessandro Di Federico 97f0941aee Introduce model::Section 2022-03-08 12:26:07 +01:00
Alessandro Di Federico 8570923d64 Introduce model::Relocation 2022-03-08 12:25:59 +01:00
Alessandro Di Federico 39ace7dc56 mv revng{DwarfImporter,ModelImporterDwarf} 2022-03-08 12:25:47 +01:00
Alessandro Di Federico 0589697dca CMake: sort headers for tuple_tree_generator 2022-03-08 12:25:35 +01:00
Massimo Fioravanti b982b69c5d revng-model-inject: support model-less modules
Inject is meant to inject a model into an `llvm::Module`, but it fails
when operating on a Module that had no model metadata.

This commit fixes the bug.
2022-03-02 15:40:27 +01:00
Ivan Krysak 2c35fc87d5 Conversion to RawFunctionType cannot fail 2022-02-25 00:31:14 +01:00