| 3901 | } |
| 3902 | |
| 3903 | UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base, QByteArray& reconstructed) |
| 3904 | { |
| 3905 | if (!index.isValid()) |
| 3906 | return ERR_SUCCESS; |
| 3907 | |
| 3908 | UINT8 result; |
| 3909 | |
| 3910 | // No action |
| 3911 | if (model->action(index) == Actions::NoAction || model->action(index) == Actions::DoNotRebuild) { |
| 3912 | reconstructed = model->header(index).append(model->body(index)); |
| 3913 | return ERR_SUCCESS; |
| 3914 | } |
| 3915 | else if (model->action(index) == Actions::Remove) { |
| 3916 | reconstructed.clear(); |
| 3917 | return ERR_SUCCESS; |
| 3918 | } |
| 3919 | else if (model->action(index) == Actions::Insert || |
| 3920 | model->action(index) == Actions::Replace || |
| 3921 | model->action(index) == Actions::Rebuild || |
| 3922 | model->action(index) == Actions::Rebase) { |
| 3923 | QByteArray header = model->header(index); |
| 3924 | EFI_COMMON_SECTION_HEADER* commonHeader = (EFI_COMMON_SECTION_HEADER*)header.data(); |
| 3925 | bool extended = false; |
| 3926 | if (uint24ToUint32(commonHeader->Size) == 0xFFFFFF) { |
| 3927 | extended = true; |
| 3928 | } |
| 3929 | |
| 3930 | // Reconstruct section with children |
| 3931 | if (model->rowCount(index)) { |
| 3932 | reconstructed.clear(); |
| 3933 | // Construct new section body |
| 3934 | UINT32 offset = 0; |
| 3935 | |
| 3936 | // Reconstruct section body |
| 3937 | for (int i = 0; i < model->rowCount(index); i++) { |
| 3938 | // Align to 4 byte boundary |
| 3939 | UINT8 alignment = offset % 4; |
| 3940 | if (alignment) { |
| 3941 | alignment = 4 - alignment; |
| 3942 | offset += alignment; |
| 3943 | reconstructed.append(QByteArray(alignment, '\x00')); |
| 3944 | } |
| 3945 | |
| 3946 | // Reconstruct subsections |
| 3947 | QByteArray section; |
| 3948 | result = reconstruct(index.child(i, 0), section); |
| 3949 | if (result) |
| 3950 | return result; |
| 3951 | |
| 3952 | // Check for empty queue |
| 3953 | if (section.isEmpty()) |
| 3954 | continue; |
| 3955 | |
| 3956 | // Append current subsection to new section body |
| 3957 | reconstructed.append(section); |
| 3958 | |
| 3959 | // Change current file offset |
| 3960 | offset += section.size(); |
nothing calls this directly
no test coverage detected