KUNAI-static-analyzer icon indicating copy to clipboard operation
KUNAI-static-analyzer copied to clipboard

Apply code cleanup and fix issues

Open Fare9 opened this issue 2 years ago • 6 comments

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 avatar Sep 20 '22 14:09 Fare9

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

  • [x] Utils

DEX

  • [ ] Parser
    • [ ] dex_annotations
    • [x] dex_classes
    • [x] dex_encoded
    • [x] dex_fields
    • [x] dex_header
    • [x] dex_methods
    • [ ] dex_parser
    • [x] dex_protos
    • [x] dex_strings
    • [x] dex_types
  • [ ] DVM
    • [ ] dex_dalvik_opcodes
    • [ ] dex_disassembler
    • [ ] dex_dvm_types
    • [ ] dex_exxternal_classes
    • [ ] dex_external_methods
    • [ ] dex_instructions
    • [x] dex_linear_sweep_disassembly
    • [x] dex_recursive_traversal_disassembly
  • [ ] Analysis
    • [ ] dex_analysis
    • [ ] dex_class_analysis
    • [ ] dex_dvm_basic_block
    • [ ] dex_exception_analysis
    • [ ] dex_field_analysis
    • [ ] dex_method_analysis
    • [ ] dex_string_analysis

APK

  • [ ] apk

MjolnIR

  • [ ] Analysis
    • [ ] ir_graph_ssa
    • [ ] optimizer
    • [ ] reachingDefinition
    • [ ] single_block_optimizations
    • [ ] single_instruction_optimizations
  • [ ] Lifters
    • [ ] lifter_android
  • [ ] IR
    • [ ] ir_blocks
    • [ ] ir_expr
    • [ ] ir_graph
    • [ ] ir_stmnt
    • [ ] ir_type
    • [ ] ir_utils

Fare9 avatar Sep 26 '22 21:09 Fare9

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 avatar Sep 26 '22 22:09 Fare9

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

Fare9 avatar Oct 02 '22 11:10 Fare9

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 avatar Oct 02 '22 22:10 Fare9

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 avatar Oct 05 '22 21:10 Fare9

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

Fare9 avatar Nov 12 '22 14:11 Fare9