Fare9 / KUNAI-static-analyzer

Tool aimed to provide a binary analysis of different file formats through the use of an Intermmediate Representation.
https://fare9.github.io/KUNAI-static-analyzer/
MIT License
136 stars 17 forks source link

Apply code cleanup and fix issues #41

Closed Fare9 closed 1 year ago

Fare9 commented 1 year ago

For next release, it would be nice to do some code cleanup in order to make the code more readable. With this fixes to the code could be done as well as more error handling. Probably in this issue, the next issue: https://github.com/Fare9/KUNAI-static-analyzer/issues/25, should be fixed too. Efficiency of the code could be checked, for example: check if it's possible to apply disassembly without re-reading the buffer all the times an instruction is disassembled. Look for possible access to variables that can take long time, etc.

Fare9 commented 1 year ago

In this comment I will write the checked classes, to keep track of the code cleanup process. Probably this is a good issue for learning the structure of the tool @sunniAngela. And also for everyone here to discuss improvements in the code @jalopezg-r00t

General

DEX

APK

MjolnIR

Fare9 commented 1 year ago

Checked dex_strings.cpp and dex_strings.hpp but need some check for the API. Commit is: https://github.com/Fare9/KUNAI-static-analyzer/commit/af78e74744f7891ff0dfc4858e0512d1c4b04bdc, I modified the std::map for a std::unordered_map, and also modified the for loops.

Fare9 commented 1 year ago

Checked dex_types.cpp and dex_types.hpp, commit: https://github.com/Fare9/KUNAI-static-analyzer/commit/441b0b35eb268ce52ac635912b7a4b231b89603e.

Fare9 commented 1 year ago

Applied different optimizations to code, created a new issue to solve: https://github.com/Fare9/KUNAI-static-analyzer/issues/43. Changed some useless std::map for std::pair, and whenever it's better changed std::map by std::unordered_map.

Fare9 commented 1 year ago

Modified the way disassembler reads method's buffer with instructions, before it was read once by each decoded instruction, now it's read once and seekg is called to move buffer's pointer, commit: https://github.com/Fare9/KUNAI-static-analyzer/commit/8327ee0789a3707d5e6d59c8c51a40d72f90af73.

Fare9 commented 1 year ago

Massive code cleanup has been applied already in the next branch: https://github.com/Fare9/KUNAI-static-analyzer/tree/refactoring