예제 #1
0
    def flash_unlock(self, selected_file):
        if module_selection_is_dsg(self.module_choice.GetSelection()):
            self.feedback_text.AppendText(
                "SKIPPED: Unlocking is unnecessary for DSG\n")
            return

        input_bytes = Path(self.row_obj_dict[selected_file]).read_bytes()
        if str.endswith(self.row_obj_dict[selected_file], ".frf"):
            self.feedback_text.AppendText("Extracting FRF for unlock...\n")
            (
                flash_data,
                allowed_boxcodes,
            ) = extract_flash.extract_flash_from_frf(
                input_bytes,
                self.flash_info,
                is_dsg=module_selection_is_dsg(
                    self.module_choice.GetSelection()),
            )
            self.input_blocks = {}
            for i in self.flash_info.block_names_frf.keys():
                filename = self.flash_info.block_names_frf[i]
                self.input_blocks[filename] = constants.BlockData(
                    i, flash_data[filename])

            cal_block = self.input_blocks[self.flash_info.block_names_frf[5]]
            file_box_code = str(
                cal_block.block_bytes[self.flash_info.
                                      box_code_location[5][0]:self.flash_info.
                                      box_code_location[5][1]].decode())
            if (file_box_code.strip() != self.flash_info.patch_info.
                    patch_box_code.split("_")[0].strip()):
                self.feedback_text.AppendText(
                    f"Boxcode mismatch for unlocking. Got box code {file_box_code} but expected {self.flash_info.patch_box_code}. Please don't try to be clever. Supply the correct file and the process will work."
                )
                return

            self.input_blocks["UNLOCK_PATCH"] = constants.BlockData(
                self.flash_info.patch_info.patch_block_index + 5,
                Path(self.flash_info.patch_info.patch_filename).read_bytes(),
            )
            key_order = list(
                map(lambda i: self.flash_info.block_names_frf[i],
                    [1, 2, 3, 4, 5]))
            key_order.insert(4, "UNLOCK_PATCH")
            input_blocks_with_patch = {
                k: self.input_blocks[k]
                for k in key_order
            }
            self.input_blocks = input_blocks_with_patch
            self.flash_bin(get_info=False)
        else:
            self.feedback_text.AppendText(
                "File did not appear to be a valid FRF. Unlocking is possible only with a specific FRF file for your ECU family.\n"
            )
예제 #2
0
 def try_extract_frf(self, frf_data: bytes):
     flash_infos = [
         simos18.s18_flash_info,
         simos1810.s1810_flash_info,
         dq250mqb.dsg_flash_info,
         simos184.s1841_flash_info,
         simos16.s16_flash_info,
         simos12.s12_flash_info,
         simos122.s122_flash_info,
         simos10.s10_flash_info,
         simos8.s8_flash_info,
     ]
     for flash_info in flash_infos:
         try:
             (flash_data,
              allowed_boxcodes) = extract_flash.extract_flash_from_frf(
                  frf_data,
                  flash_info,
                  is_dsg=(flash_info is dq250mqb.dsg_flash_info),
              )
             output_blocks = {}
             for i in flash_info.block_names_frf.keys():
                 filename = flash_info.block_names_frf[i]
                 output_blocks[filename] = constants.BlockData(
                     i, flash_data[filename],
                     flash_info.number_to_block_name[i])
             return [output_blocks, flash_info]
         except:
             pass
예제 #3
0
 def flash_bin_file(self, selected_file, patch_cboot=False):
     input_bytes = Path(self.row_obj_dict[selected_file]).read_bytes()
     if str.endswith(self.row_obj_dict[selected_file], ".frf"):
         self.feedback_text.AppendText("Extracting FRF...\n")
         (
             flash_data,
             allowed_boxcodes,
         ) = extract_flash.extract_flash_from_frf(
             input_bytes,
             self.flash_info,
             is_dsg=module_selection_is_dsg(
                 self.module_choice.GetSelection()),
         )
         self.input_blocks = {}
         for i in self.flash_info.block_names_frf.keys():
             filename = self.flash_info.block_names_frf[i]
             self.input_blocks[filename] = constants.BlockData(
                 i, flash_data[filename])
         self.flash_bin(get_info=False, should_patch_cboot=patch_cboot)
     elif len(input_bytes) == self.flash_info.binfile_size:
         self.input_blocks = binfile.blocks_from_bin(
             self.row_obj_dict[selected_file], self.flash_info)
         self.flash_bin(get_info=False, should_patch_cboot=patch_cboot)
     else:
         self.feedback_text.AppendText(
             "File did not appear to be a valid BIN or FRF\n")
예제 #4
0
 def setUp(self):
     self.flash_utils = simos_flash_utils
     self.flash_info = simos1810.s1810_flash_info
     frf_raw_blocks = Simos1810FlashUtilsTestCase.frf_raw_blocks
     input_blocks = {}
     for i in self.flash_info.block_names_frf.keys():
         filename = self.flash_info.block_names_frf[i]
         input_blocks[filename] = constants.BlockData(
             i, frf_raw_blocks[filename].copy()
         )
     self.flash_data = input_blocks
예제 #5
0
 def setUp(self):
     self.flash_utils = dsg_flash_utils
     self.flash_info = dq250mqb.dsg_flash_info
     frf_raw_blocks = DsgFlashUtilsTestCase.frf_raw_blocks
     input_blocks = {}
     for i in self.flash_info.block_names_frf.keys():
         filename = self.flash_info.block_names_frf[i]
         input_blocks[filename] = constants.BlockData(
             i, frf_raw_blocks[filename].copy()
         )
     self.flash_data = input_blocks
예제 #6
0
    def flash_cal(self, selected_file: str):
        # Flash a Calibration block only
        self.input_blocks = {}

        if module_selection_is_dsg(self.module_choice.GetSelection()):
            # Populate DSG Driver block from a fixed file name for now.
            dsg_driver_path = path.join(self.options["cal"], "FD_2.DRIVER.bin")
            self.feedback_text.AppendText("Loading DSG Driver from: " +
                                          dsg_driver_path + "\n")
            self.input_blocks["FD_2.DRIVER.bin"] = constants.BlockData(
                self.flash_info.block_name_to_number["DRIVER"],
                Path(dsg_driver_path).read_bytes(),
            )
            self.input_blocks[
                self.row_obj_dict[selected_file]] = constants.BlockData(
                    self.flash_info.block_name_to_number["CAL"],
                    Path(self.row_obj_dict[selected_file]).read_bytes(),
                )
        else:
            input_bytes = Path(self.row_obj_dict[selected_file]).read_bytes()
            if len(input_bytes) == self.flash_info.binfile_size:
                self.feedback_text.AppendText(
                    "Extracting Calibration from full binary...\n")
                input_blocks = binfile.blocks_from_bin(
                    self.row_obj_dict[selected_file], self.flash_info)
                # Filter to only CAL block.
                self.input_blocks = {
                    k: v
                    for k, v in input_blocks.items() if v.block_number ==
                    self.flash_info.block_name_to_number["CAL"]
                }
            else:
                self.input_blocks[
                    self.row_obj_dict[selected_file]] = constants.BlockData(
                        self.flash_info.block_name_to_number["CAL"],
                        input_bytes,
                    )

        self.flash_bin()
예제 #7
0
def process_data(data: bytes, is_bin=False):
    try:
        flash_infos = [
            simos18.s18_flash_info,
            simos1810.s1810_flash_info,
            simos184.s1841_flash_info,
            simos16.s16_flash_info,
            simos12.s12_flash_info,
            simos122.s122_flash_info,
            simos10.s10_flash_info,
            simos8.s8_flash_info,
        ]
        flash_data = None
        for flash_info in flash_infos:
            try:
                if is_bin:
                    flash_data = binfile.blocks_from_data(data, flash_info)
                    allowed_boxcodes = []
                else:
                    (flash_data, allowed_boxcodes) = extract_data_from_odx(
                        data, flash_info)

                flash_blocks: dict[int, constants.BlockData] = {}

                for block_number in flash_info.block_names_frf.keys():
                    flash_blocks[block_number] = constants.BlockData(
                        block_number,
                        flash_data[flash_info.block_names_frf[block_number]],
                        block_name=flash_info.
                        number_to_block_name[block_number],
                    )

                if len(binfile.filter_blocks(flash_blocks, flash_info)) > 0:
                    return extract_info_from_flash_blocks(
                        flash_blocks, flash_info, allowed_boxcodes)
            except:
                pass
        return None

    except:
        print(
            "Couldn't handle file, continuing with other files:",
            sys.exc_info()[0],
        )
        return None