p8n_types/lib.rs
1// Panopticon - A libre program analysis library for machine code
2// Copyright (C) 2014-2018 The Panopticon Developers
3//
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8//
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18//! A library for disassembling and analysing binary code.
19//!
20//! The panopticon crate implements structures to model the in-memory representation of a
21//! program including is control flow, call graph and memory maps.
22//! The most important types and their interaction are as follows:
23//!
24//! ```text
25//! Project
26//! ├── Region
27//! │ └── Layer
28//! └── Program
29//! └── Function
30//! └── BasicBlock
31//! └── Mnemonic
32//! └── Statement
33//! ```
34//!
35//! The [`Program`](program/index.html), [`Function`](function/index.html),
36//! [`BasicBlock`](basic_block/index.html) and [`Statement`](il/struct.Statement.html)
37//! types model the behaviour of code.
38//! The [`Region`](region/index.html) and [`Layer`](layer/index.html) types
39//! represent how the program is laid out in memory.
40//!
41//! # Code
42//!
43//! Panopticon models code as a collection of programs. Each
44//! [`Program`](program/index.html) consists of functions. A [`Function`](function/index.html) a graph with nodes representing a
45//! sequence of instructions and edges representing jumps. These instruction sequences are [`BasicBlock`s](basic_block/index.html)
46//! and contain a list of [`Mnemonic`](mnemonic/index.html)s. The meaning of each
47//! `Mnemonic` is described in the [RREIL][1] language. Each mnemonic includes a sequence of
48//! [`Statement`s](il/struct.Statement.html) implementing it.
49//!
50//! Panopticon allows multiple programs per project. For example, imagine a C# application that calls into a
51//! native DLL written in C. Such an application would have two program instances. One for the CIL
52//! code of the C# part of the application and one for the AMD64 object code inside the DLL.
53//!
54//! The [`Disassembler`](disassembler/index.html) and [`CodeGen`](codegen/index.html) are used to fill `Function`
55//! structures with `Mnemonic`s.
56//!
57//! # Data
58//!
59//! The in-memory layout of an executable is modeled using the [`Region`](region/index.html), [`Layer`](layer/index.html) and
60//! [`Cell`](layer/type.Cell.html) types. All data is organized into `Region`s. Each `Region` is an array of
61//! `Cell`s numbered from 0 to n. Each `Cell` is an is either
62//! undefined or has a value between 0 and 255 (both including). `Region`s are read
63//! only. Changing their contents is done by applying `Layer` instance to them. A `Layer`
64//! reads part of a `Region` or another `Layer` and returns a new `Cell` array. For example, `Layer`
65//! can decrypt parts of a `Region` or replace individual `Cell`s with new
66//! ones.
67//!
68
69//! In normal operation there is one `Region` for each memory address space, one on
70//! Von-Neumann machines two on Harvard architectures. Other uses for `Region`s are
71//! applying functions to `Cell` array where the result is not equal in size to the
72//! input (for example uncompressing parts of the executable image).
73
74#![recursion_limit = "1024"]
75#![warn(missing_docs)]
76
77#[macro_use] extern crate log;
78extern crate num_traits;
79extern crate byteorder;
80extern crate goblin;
81#[macro_use] extern crate error_chain;
82extern crate leb128;
83extern crate petgraph;
84extern crate smallvec;
85extern crate memmap;
86extern crate simple_logger;
87extern crate chrono;
88extern crate vec_map;
89extern crate ron_uuid;
90
91#[cfg(not(test))]
92extern crate quickcheck;
93#[cfg(test)]
94#[macro_use] extern crate quickcheck;
95
96pub use ron_uuid::UUID;
97
98mod table;
99pub use self::table::{
100 Name,
101 NameRef,
102 Names,
103 Strings,
104 StrRef,
105 Segments,
106 SegmentRef,
107 Table
108};
109
110mod value;
111pub use self::value::{
112 Variable,
113 Constant,
114 Value,
115 Segment
116};
117
118mod constraint;
119pub use self::constraint::{
120 Constraint
121};
122
123mod guard;
124pub use self::guard::{
125 Guard
126};
127
128mod il;
129pub use self::il::{
130 Operation,
131 Statement,
132 Endianess,
133 CallTarget,
134 MemoryOperation,
135 FlowOperation,
136 Area,
137};
138
139mod bitcode;
140pub use self::bitcode::{
141 Bitcode,
142 BitcodeIter
143};
144
145mod function;
146pub use self::function::{
147 Function,
148 CfgNode,
149 IntoStatementRange,
150};
151
152mod statements;
153pub use self::statements::{
154 RewriteControl,
155 Statements,
156};
157
158mod basic_block;
159pub use self::basic_block::{
160 BasicBlock,
161 BasicBlockIndex,
162 BasicBlockIterator,
163};
164
165mod mnemonic;
166pub use self::mnemonic::{
167 Mnemonic,
168 MnemonicIndex,
169 MnemonicIterator,
170};
171
172mod region;
173pub use self::region::{
174 Region,
175};
176
177mod architecture;
178pub use self::architecture::{
179 Architecture,
180 Match,
181 TestArch,
182};
183
184mod loader;
185pub use self::loader::{
186 Content,
187 Machine,
188 Pointer,
189};
190
191mod errors {
192 #![allow(missing_docs)]
193 error_chain!{
194 foreign_links {
195 Fmt(::std::fmt::Error);
196 Io(::std::io::Error);
197 Leb128(::leb128::read::Error);
198 Goblin(::goblin::error::Error);
199 Utf8String(::std::string::FromUtf8Error);
200 Utf8Str(::std::str::Utf8Error);
201 }
202 }
203}
204pub use errors::*;
205
206/// Our string type.
207pub type Str = ::std::borrow::Cow<'static,str>;