vtil-project / VTIL-Core

Virtual-machine Translation Intermediate Language
BSD 3-Clause "New" or "Revised" License
1.31k stars 165 forks source link

Comparison between unknowns return immediate result. #9

Closed Mahorori closed 4 years ago

Mahorori commented 4 years ago
vtil::symbolic::expression op1 = { {"op1"}, 4 };
vtil::symbolic::expression op2 = { {"op2"}, 4 };

// out: (op1==op2)
auto dst1 = op1 == op2;
vtil::logger::log("%s\n", dst1.simplify().to_string().c_str());

// out: 0x0
auto dst2 = (op1 - op2) == 0;
vtil::logger::log("%s\n", dst2.simplify().to_string().c_str());
can1357 commented 4 years ago

Because it should have been ?? What is the expected answer?

can1357 commented 4 years ago

Few things, if you meant a 32-bit integer, you need to do 32 and not 4. As for the dst2.simplify().to_string().c_str(), simplification is done automatically when you do an operation and std::string can be passed as is to logger so you could just do dst2.to_string().

expression op1 = { {"op1"}, 32 };
expression op2 = { {"op2"}, 32 };

// Out:  (op1==op2)
//       ?
auto dst1 = op1 == op2;
log( "%s\n", dst1.to_string() );
log( "%s\n", dst1.value.to_string() );

// Out:  ((op1-op2)==0x0)
//       ?
auto dst2 = ( op1 - op2 ) == 0;
log( "%s\n", dst2.to_string() );
log( "%s\n", dst2.value.to_string() );

Also if you are not using this equality comparison in a statement, I'd recommend using expression::equals / expression::is_identical instead.

Mahorori commented 4 years ago

yes the result should've been unknown I think. and It's been fixed, thank you for the quick fix and even advice for improving my code :) and indeed i'm using it as statement to check if it's symbolized or not