1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 133 134 135 136 137 138 139 140 141 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
use yaxpeax_arch::Arch; use data::ValueLocations; #[macro_use] pub mod control_flow; pub mod data_flow; pub mod function_signatures; pub mod static_single_assignment; pub mod xrefs; pub mod evaluators; pub mod value_range; pub enum CompletionStatus { Incomplete, Complete, } pub struct ValueRes<V> { value: V, carry: V, } #[allow(dead_code)] impl<V: Value> ValueRes<V> { pub(crate) fn from_zero() -> Self { ValueRes::literal(V::from_const(0)) } pub(crate) fn literal(value: V) -> Self { ValueRes { value, carry: V::from_const(0), } } pub(crate) fn unknown() -> Self { ValueRes { value: V::unknown(), carry: V::unknown(), } } pub(crate) fn parts(self) -> (V, V) { (self.value, self.carry) } pub(crate) fn value(self) -> V { self.value } pub(crate) fn carry(self) -> V { self.carry } pub(crate) fn zero(&self) -> V { self.value.eq(&V::from_const(0)) } pub(crate) fn sign(&self) -> V { self.value.lt(&V::from_const(0)) } } pub trait DFG<V, A: Arch + ValueLocations> { fn read_loc(&self, loc: A::Location) -> V; fn read<T: ToDFGLoc<A::Location>>(&self, loc: &T) -> V { self.read_loc(loc.convert()) } fn write_loc(&mut self, loc: A::Location, value: V); fn write<T: ToDFGLoc<A::Location>>(&mut self, loc: &T, value: V) { self.write_loc(loc.convert(), value) } } pub trait ToDFGLoc<U> { fn convert(&self) -> U; } impl<T: Clone> ToDFGLoc<T> for T { fn convert(&self) -> T { self.to_owned() } } impl<'a, T: Clone> ToDFGLoc<T> for &'a T { fn convert(&self) -> T { self.to_owned().to_owned() } } pub trait Value: Sized { fn unknown() -> Self; fn from_const(_c: u64) -> Self { Self::unknown() } fn from_set(xs: &[Self]) -> Self; fn to_const(&self) -> Option<u64>; fn as_bool(&self) -> Option<bool> { self.ne(&Value::from_const(0)).to_const().map(|x| x != 0) } fn add(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn sub(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn mul(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn or(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn and(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn xor(&self, _other: &Self) -> ValueRes<Self> { ValueRes::unknown() } fn modulo(&self, _other: &Self) -> Self { Self::unknown() } fn ne(&self, _other: &Self) -> Self { Self::unknown() } fn le(&self, _other: &Self) -> Self { Self::unknown() } fn lt(&self, other: &Self) -> Self { self.le(other).and(&self.eq(other).not()).value() } fn gte(&self, other: &Self) -> Self { self.lt(other).not() } fn eq(&self, _other: &Self) -> Self { Self::unknown() } fn not(&self) -> Self { Self::unknown() } fn sxt(&self, _width: &Self) -> Self { Self::unknown() } fn zxt(&self, _width: &Self) -> Self { Self::unknown() } fn shr(&self, _amt: &Self) -> Self { Self::unknown() } fn sar(&self, _width: &Self) -> Self { Self::unknown() } fn shl(&self, _width: &Self) -> Self { Self::unknown() } fn sal(&self, _width: &Self) -> Self { Self::unknown() } fn rcl(&self, _width: &Self) -> Self { Self::unknown() } fn rcr(&self, _width: &Self) -> Self { Self::unknown() } fn rol(&self, _width: &Self) -> Self { Self::unknown() } fn ror(&self, _width: &Self) -> Self { Self::unknown() } }