Skip to content
Open

0.6.0 #120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ default = ["capstone4"]
thread_safe = []
capstone4 = ["falcon_capstone/capstone4"]
static = ["falcon_capstone/static"]
il-expression-ashr = []

[lib]
name = "falcon"
Expand Down
1 change: 0 additions & 1 deletion lib/executor/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn eval(expr: &il::Expression) -> Result<il::Constant> {
il::Expression::Xor(ref lhs, ref rhs) => eval(lhs)?.xor(&eval(rhs)?)?,
il::Expression::Shl(ref lhs, ref rhs) => eval(lhs)?.shl(&eval(rhs)?)?,
il::Expression::Shr(ref lhs, ref rhs) => eval(lhs)?.shr(&eval(rhs)?)?,
#[cfg(feature = "il-expression-ashr")]
il::Expression::AShr(ref lhs, ref rhs) => eval(lhs)?.ashr(&eval(rhs)?)?,
il::Expression::Cmpeq(ref lhs, ref rhs) => eval(lhs)?.cmpeq(&eval(rhs)?)?,
il::Expression::Cmpneq(ref lhs, ref rhs) => eval(lhs)?.cmpneq(&eval(rhs)?)?,
Expand Down
1 change: 0 additions & 1 deletion lib/executor/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl State {
self.symbolize_expression(lhs)?,
self.symbolize_expression(rhs)?,
)?,
#[cfg(feature = "il-expression-ashr")]
il::Expression::AShr(ref lhs, ref rhs) => il::Expression::ashr(
self.symbolize_expression(lhs)?,
self.symbolize_expression(rhs)?,
Expand Down
8 changes: 4 additions & 4 deletions lib/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ where
.vertices
.iter()
.map(|v| {
let label = v.1.dot_label().replace("\n", "\\l");
let label = v.1.dot_label().replace('\n', "\\l");
let fill_color = v.1.dot_fill_color();
let font_color = v.1.dot_font_color();
format!(
Expand All @@ -1014,7 +1014,7 @@ where
.edges
.iter()
.map(|e| {
let label = e.1.dot_label().replace("\n", "\\l");
let label = e.1.dot_label().replace('\n', "\\l");
let style = e.1.dot_style();
let fill_color = e.1.dot_fill_color();
let font_color = e.1.dot_font_color();
Expand Down Expand Up @@ -1483,7 +1483,7 @@ mod tests {
#[test]
fn test_is_acyclic_should_return_false_for_cyclic_graph() {
let graph = create_test_graph();
assert_eq!(graph.is_acyclic(1), false);
assert!(!graph.is_acyclic(1));
}

#[test]
Expand Down Expand Up @@ -1523,7 +1523,7 @@ mod tests {
graph
};

assert_eq!(graph.is_reducible(1).unwrap(), false);
assert!(!graph.is_reducible(1).unwrap());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion lib/il/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Constant {
.value
.to_usize()
.map(|bits| {
if bits as usize >= self.bits() {
if bits >= self.bits() {
BigUint::from_u64(0).unwrap()
} else {
self.value.clone() << bits
Expand Down
7 changes: 0 additions & 7 deletions lib/il/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub enum Expression {
Xor(Box<Expression>, Box<Expression>),
Shl(Box<Expression>, Box<Expression>),
Shr(Box<Expression>, Box<Expression>),
#[cfg(feature = "il-expression-ashr")]
AShr(Box<Expression>, Box<Expression>),

Cmpeq(Box<Expression>, Box<Expression>),
Expand Down Expand Up @@ -76,7 +75,6 @@ impl Expression {
| Expression::Xor(ref lhs, _)
| Expression::Shl(ref lhs, _)
| Expression::Shr(ref lhs, _) => lhs.bits(),
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref lhs, _) => lhs.bits(),
Expression::Cmpeq(_, _)
| Expression::Cmpneq(_, _)
Expand Down Expand Up @@ -159,7 +157,6 @@ impl Expression {
Expression::Shr(ref lhs, ref rhs) => {
Expression::shr(self.map(lhs)?, self.map(rhs)?)?
}
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref lhs, ref rhs) => {
Expression::ashr(self.map(lhs)?, self.map(rhs)?)?
}
Expand Down Expand Up @@ -228,7 +225,6 @@ impl Expression {
| Expression::Cmpneq(ref lhs, ref rhs)
| Expression::Cmplts(ref lhs, ref rhs)
| Expression::Cmpltu(ref lhs, ref rhs) => lhs.all_constants() && rhs.all_constants(),
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref lhs, ref rhs) => lhs.all_constants() && rhs.all_constants(),
Expression::Zext(_, ref rhs)
| Expression::Sext(_, ref rhs)
Expand Down Expand Up @@ -264,7 +260,6 @@ impl Expression {
scalars.append(&mut lhs.scalars());
scalars.append(&mut rhs.scalars());
}
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref lhs, ref rhs) => {
scalars.append(&mut lhs.scalars());
scalars.append(&mut rhs.scalars());
Expand Down Expand Up @@ -308,7 +303,6 @@ impl Expression {
scalars.append(&mut lhs.scalars_mut());
scalars.append(&mut rhs.scalars_mut());
}
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref mut lhs, ref mut rhs) => {
scalars.append(&mut lhs.scalars_mut());
scalars.append(&mut rhs.scalars_mut());
Expand Down Expand Up @@ -642,7 +636,6 @@ impl fmt::Display for Expression {
Expression::Xor(ref lhs, ref rhs) => write!(f, "({} ^ {})", lhs, rhs),
Expression::Shl(ref lhs, ref rhs) => write!(f, "({} << {})", lhs, rhs),
Expression::Shr(ref lhs, ref rhs) => write!(f, "({} >> {})", lhs, rhs),
#[cfg(feature = "il-expression-ashr")]
Expression::AShr(ref lhs, ref rhs) => write!(f, "({} >>> {})", lhs, rhs),
Expression::Cmpeq(ref lhs, ref rhs) => write!(f, "({} == {})", lhs, rhs),
Expression::Cmpneq(ref lhs, ref rhs) => write!(f, "({} != {})", lhs, rhs),
Expand Down
2 changes: 1 addition & 1 deletion lib/il/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'p> RefProgramLocation<'p> {
continue;
}

if function == None {
if function.is_none() {
function = Some(f);
continue;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/loader/elf/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,7 @@ impl Loader for Elf {
);
}

Ok(function_entries
.into_iter()
.map(|(_, entry)| entry)
.collect())
Ok(function_entries.into_values().collect())
}

fn program_entry(&self) -> u64 {
Expand Down
14 changes: 6 additions & 8 deletions lib/loader/elf/elf_linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl ElfLinker {
}
} else {
// Ensure all shared objects we rely on are loaded
for so_name in self.loaded[&filename].dt_needed()?.clone() {
for so_name in self.loaded[&filename].dt_needed()? {
if self.loaded.get(&so_name).is_none() {
self.next_lib_address += LIB_BASE_STEP;
let next_lib_address = self.next_lib_address;
Expand Down Expand Up @@ -289,7 +289,7 @@ impl ElfLinker {
None => bail!("Could not resolve symbol {}", sym_name),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_GOT32 => {
bail!("R_386_GOT32");
Expand Down Expand Up @@ -322,7 +322,7 @@ impl ElfLinker {
}
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_JMP_SLOT => {
let sym = &dynsyms
Expand All @@ -334,12 +334,10 @@ impl ElfLinker {
None => bail!("Could not resolve symbol {}", sym_name),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_RELATIVE => {
let value = self
.memory
.get32(reloc.r_offset as u64 + elf.base_address());
let value = self.memory.get32(reloc.r_offset + elf.base_address());
let value = match value {
Some(value) => elf.base_address() as u32 + value,
None => bail!(
Expand All @@ -349,7 +347,7 @@ impl ElfLinker {
),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_GOTPC => {
bail!("R_386_GOT_PC");
Expand Down
2 changes: 1 addition & 1 deletion lib/loader/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Json {
};

let bytes = match segment["bytes"] {
Value::String(ref bytes) => base64::decode(&bytes)?,
Value::String(ref bytes) => base64::decode(bytes)?,
_ => bail!("bytes missing for segment"),
};

Expand Down
2 changes: 1 addition & 1 deletion lib/memory/paged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
/// Set memory permissions for the page at the given address
pub fn set_permissions(&mut self, address: u64, len: u64, permissions: MemoryPermissions) {
let mut page_address = address & PAGE_MASK;
let total_length = len as u64 + (address - page_address);
let total_length = len + (address - page_address);
while page_address < total_length {
RC::make_mut(
self.pages
Expand Down
6 changes: 3 additions & 3 deletions lib/translator/aarch64/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ pub(super) fn b_cc(

pub(super) fn br(
instruction_graph: &mut il::ControlFlowGraph,
_successors: &mut Vec<(u64, Option<il::Expression>)>,
_successors: &mut [(u64, Option<il::Expression>)],
instruction: &bad64::Instruction,
) -> Result<()> {
let block_index = {
Expand Down Expand Up @@ -799,7 +799,7 @@ fn cbz_cbnz_tbz_tbnz(
let (dst, mut cond_true, mut cond_false);

let opr_value = 0;
let opr_bit = test_bit.then(|| 1);
let opr_bit = test_bit.then_some(1);
let opr_target = [1, 2][test_bit as usize];

let block_index = {
Expand Down Expand Up @@ -1202,7 +1202,7 @@ pub(super) fn nop(

pub(super) fn ret(
instruction_graph: &mut il::ControlFlowGraph,
_successors: &mut Vec<(u64, Option<il::Expression>)>,
_successors: &mut [(u64, Option<il::Expression>)],
_instruction: &bad64::Instruction,
) -> Result<()> {
let block_index = {
Expand Down
3 changes: 1 addition & 2 deletions lib/translator/aarch64/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fn init_driver_block<'d>(
.chain(Some(&NOP))
// The following code can be rewritten as `encoding.to_le_bytes()
// .into_iter()` in Rust 2021 but not in Rust 2018
.map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes()))
.flatten()
.flat_map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes()))
.collect();

let mut backing = memory::backing::Memory::new(Endian::Big);
Expand Down
2 changes: 1 addition & 1 deletion lib/translator/block_translation_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl BlockTranslationResult {
control_flow_graph.set_entry(block_index)?;
control_flow_graph.set_exit(block_index)?;

for &(_, ref cfg) in &self.instructions {
for (_, cfg) in &self.instructions {
control_flow_graph.append(cfg)?;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/translator/mips/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ fn nop() {
_ => None,
};

assert_eq!(nop.is_some(), true);
assert!(nop.is_some());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion lib/translator/ppc/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub fn addze(

let src = Expression::add(
lhs.clone(),
Expression::zext(lhs.bits() as usize, expr_scalar("carry", 1))?,
Expression::zext(lhs.bits(), expr_scalar("carry", 1))?,
)?;
block.assign(dst, src);

Expand Down
2 changes: 1 addition & 1 deletion lib/translator/x86/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Mode {
Expr::add(op, expr_const(mem.disp as u64, self.bits()))?
}
Ordering::Less => {
Expr::sub(op, expr_const(mem.disp.abs() as u64, self.bits()))?
Expr::sub(op, expr_const(mem.disp.unsigned_abs(), self.bits()))?
}
Ordering::Equal => op,
}
Expand Down