

def PatchUpPyinstaller(self):
    'PyInstaller binaries need to be repaired.\n\n    PyInstaller just dumps the packed payload at the end of the ELF binary\n    without adjusting the ELF sections. This means that any manipulation of the\n    ELF file (e.g. prelinking the file as is commonly done on RedHat machines)\n    will strip the payload from the file.\n\n    We fix this by extending the last section to the end of the file so the\n    payload is included.\n    '
    root = config_lib.CONFIG.Get('PyInstaller.dpkg_root', context=self.context)
    with open(os.path.join(root, 'debian/grr-client/grr-client'), 'r+b') as fd:
        fd.seek(0, 2)
        size = fd.tell()
        fd.seek(0, 0)
        data = fd.read(1000000)
        if (data[:5] == '\x7fELF\x02'):
            shr_offset = struct.unpack('<Q', data[40:(40 + 8)])[0]
            number_of_sections = struct.unpack('<H', data[60:(60 + 2)])[0]
            size_of_section = struct.unpack('<H', data[58:(58 + 2)])[0]
            last_section_offset = (shr_offset + ((number_of_sections - 1) * size_of_section))
            start_of_section = struct.unpack('<Q', data[(last_section_offset + 24):((last_section_offset + 24) + 8)])[0]
            fd.seek((last_section_offset + 32))
            fd.write(struct.pack('<Q', (size - start_of_section)))
        elif (data[:5] == '\x7fELF\x01'):
            shr_offset = struct.unpack('<I', data[32:(32 + 4)])[0]
            number_of_sections = struct.unpack('<H', data[48:(48 + 2)])[0]
            size_of_section = struct.unpack('<H', data[46:(46 + 2)])[0]
            last_section_offset = (shr_offset + ((number_of_sections - 1) * size_of_section))
            start_of_section = struct.unpack('<I', data[(last_section_offset + 16):((last_section_offset + 16) + 4)])[0]
            fd.seek((last_section_offset + 20))
            number_of_sections.write(struct.pack('<I', (size - start_of_section)))

dataset/ETHPy150Open google/grr/grr/lib/builders/linux.py LinuxClientBuilder.PatchUpPyinstaller/VarMisuse@384/718 `fd`->`number_of_sections`