Skip to content

Commit 04e5dc1

Browse files
Fix - bug in handling defined name value
1 parent bd362df commit 04e5dc1

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

XLMMacroDeobfuscator/deobfuscator.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -608,32 +608,38 @@ def evaluate_formula(self, current_cell, name, arguments, interactive, destinati
608608
if isinstance(destination, list):
609609
destination = [] if not destination else destination[0]
610610

611-
if destination.data == 'defined_name' or destination.data == 'name':
612-
defined_name_formula = self.xlm_wrapper.get_defined_name(destination.children[2])
613-
if isinstance(defined_name_formula, Tree):
614-
destination = defined_name_formula
615-
else:
616-
destination = self.xlm_parser.parse('=' + defined_name_formula).children[0]
611+
if(isinstance(destination, str)):
612+
destination = self.xlm_parser.parse('=' + destination).children[0]
613+
614+
if isinstance(destination, Tree):
615+
if destination.data == 'defined_name' or destination.data == 'name':
616+
defined_name_formula = self.xlm_wrapper.get_defined_name(destination.children[2])
617+
if isinstance(defined_name_formula, Tree):
618+
destination = defined_name_formula
619+
else:
620+
destination = self.xlm_parser.parse('=' + defined_name_formula).children[0]
617621

618-
if destination.data == 'concat_expression' or destination.data == 'function_call':
619-
res = self.evaluate_parse_tree(current_cell, destination, interactive)
620-
if isinstance(res.value, tuple) and len(res.value) == 3:
621-
destination_str = "'{}'!{}{}".format(res.value[0], res.value[1], res.value[2])
622-
dst_start_sheet, dst_start_col, dst_start_row = res.value
623-
else:
624-
destination_str = res.text
625-
dst_start_sheet, dst_start_col, dst_start_row = Cell.parse_cell_addr(destination_str)
626-
dst_end_sheet, dst_end_col, dst_end_row = dst_start_sheet, dst_start_col, dst_start_row
622+
if destination.data == 'concat_expression' or destination.data == 'function_call':
623+
res = self.evaluate_parse_tree(current_cell, destination, interactive)
624+
if isinstance(res.value, tuple) and len(res.value) == 3:
625+
destination_str = "'{}'!{}{}".format(res.value[0], res.value[1], res.value[2])
626+
dst_start_sheet, dst_start_col, dst_start_row = res.value
627+
else:
628+
destination_str = res.text
629+
dst_start_sheet, dst_start_col, dst_start_row = Cell.parse_cell_addr(destination_str)
630+
dst_end_sheet, dst_end_col, dst_end_row = dst_start_sheet, dst_start_col, dst_start_row
627631

628-
else:
629-
if destination.data == 'range':
630-
dst_start_sheet, dst_start_col, dst_start_row = self.get_cell_addr(current_cell,
631-
destination.children[0])
632-
dst_end_sheet, dst_end_col, dst_end_row = self.get_cell_addr(current_cell, destination.children[2])
633632
else:
634-
dst_start_sheet, dst_start_col, dst_start_row = self.get_cell_addr(current_cell, destination)
635-
dst_end_sheet, dst_end_col, dst_end_row = dst_start_sheet, dst_start_col, dst_start_row
636-
destination_str = XLMInterpreter.convert_ptree_to_str(destination)
633+
if destination.data == 'range':
634+
dst_start_sheet, dst_start_col, dst_start_row = self.get_cell_addr(current_cell,
635+
destination.children[0])
636+
dst_end_sheet, dst_end_col, dst_end_row = self.get_cell_addr(current_cell, destination.children[2])
637+
else:
638+
dst_start_sheet, dst_start_col, dst_start_row = self.get_cell_addr(current_cell, destination)
639+
dst_end_sheet, dst_end_col, dst_end_row = dst_start_sheet, dst_start_col, dst_start_row
640+
destination_str = XLMInterpreter.convert_ptree_to_str(destination)
641+
642+
637643
text = src_eval_result.get_text(unwrap=True)
638644
if src_eval_result.status == EvalStatus.FullEvaluation:
639645
for row in range(int(dst_start_row), int(dst_end_row) + 1):

0 commit comments

Comments
 (0)