From 2607e92f544a4d02c7a107c0aa1c79271e321dd5 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 31 Aug 2021 13:25:11 +0200 Subject: [PATCH] WIP: experiment with variable hashing --- VTIL-Architecture/routine/basic_block.hpp | 8 +++++++ VTIL-Architecture/symex/variable.hpp | 2 +- VTIL-Tests/dummy.cpp | 27 +++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/VTIL-Architecture/routine/basic_block.hpp b/VTIL-Architecture/routine/basic_block.hpp index e64c899..9f57346 100644 --- a/VTIL-Architecture/routine/basic_block.hpp +++ b/VTIL-Architecture/routine/basic_block.hpp @@ -244,6 +244,14 @@ namespace vtil // routine* owner = nullptr; + static uint64_t unique_block_id() + { + static uint64_t id = 0; + return id++; + } + + uint64_t block_id = unique_block_id(); + // Virtual instruction pointer to the first instruction this block originated // from. ::front().vip will not do the job here in case of any skipped or // optimized out instructions. diff --git a/VTIL-Architecture/symex/variable.hpp b/VTIL-Architecture/symex/variable.hpp index 138a549..d58ab6b 100644 --- a/VTIL-Architecture/symex/variable.hpp +++ b/VTIL-Architecture/symex/variable.hpp @@ -223,7 +223,7 @@ namespace vtil::symbolic // Declare reduction. // - REDUCE_TO( at.block, at.entry, descriptor, is_branch_dependant ); + REDUCE_TO( at.block->block_id, at.entry, descriptor, is_branch_dependant ); // Packs all the variables in the expression where it'd be optimal. // diff --git a/VTIL-Tests/dummy.cpp b/VTIL-Tests/dummy.cpp index d02da9a..cec5037 100644 --- a/VTIL-Tests/dummy.cpp +++ b/VTIL-Tests/dummy.cpp @@ -1,8 +1,9 @@ #include "doctest.h" #include #include +#include -DOCTEST_TEST_CASE("dummy") +/*DOCTEST_TEST_CASE("dummy") { auto block = vtil::basic_block::begin(0); block->vemits("cpuid"); @@ -48,4 +49,26 @@ DOCTEST_TEST_CASE("Simplification") vtil::logger::log(":: After:\n"); vtil::debug::dump(block->owner); CHECK(1 == 1); -} +}*/ + +DOCTEST_TEST_CASE("Expression hash") +{ + // $sp#0x13df89?+0x90 + using namespace vtil::symbolic; + using namespace vtil::math; + using namespace vtil::logger; + auto block = vtil::basic_block::begin(0x13df89); + block->nop(); + auto var = variable(block->begin(), vtil::REG_SP); + log("var hash: %s\n", var.hash()); + + auto v = var.to_expression(); + log("v hash: %s\n", v.hash()); + //expression(unique_identifier()) + auto c = expression(0x90); + log("c hash: %s\n", c.hash()); + auto kurwa = expression::make(v, operator_id::add, c); + log("%s (Hash: %s)\n", kurwa.to_string(), kurwa.hash()); + kurwa.update(false); + log("%s (Hash: %s)\n", kurwa.to_string(), kurwa.hash()); +} \ No newline at end of file