()
| 35 | |
| 36 | |
| 37 | def main(): |
| 38 | with enterprise.LicenseCheckout(): |
| 39 | # Connect to remote from Enterprise |
| 40 | remote = collaboration.enterprise_remote() |
| 41 | if not remote: |
| 42 | return |
| 43 | if not remote.is_connected: |
| 44 | # Will pull default credentials from Enterprise |
| 45 | remote.connect() |
| 46 | |
| 47 | # Create test project |
| 48 | project = remote.create_project("Test Project", "Test project for test purposes") |
| 49 | file = None |
| 50 | project_dir = None |
| 51 | try: |
| 52 | print(f'Created project {project.name}') |
| 53 | file = project.upload_new_file(TEST_FILE) |
| 54 | print(f'Created file {project.name}/{file.name}') |
| 55 | |
| 56 | project_dir = Path(file.default_path).parent |
| 57 | |
| 58 | print(f'Snapshots: {[snapshot.id for snapshot in file.snapshots]}') |
| 59 | bv = binaryninja.load(file.default_path) |
| 60 | view_type = bv.view_type |
| 61 | assert collaboration.RemoteFile.get_for_bv(bv) == file |
| 62 | |
| 63 | print(f'Setting entry function at 0x{bv.entry_function.start:08x} name to \'entry_function\'') |
| 64 | bv.entry_function.name = 'entry_function' |
| 65 | bv.file.save_auto_snapshot() |
| 66 | |
| 67 | file.sync(bv, lambda conflicts: False) |
| 68 | print(f'Snapshots: {[snapshot.id for snapshot in file.snapshots]}') |
| 69 | |
| 70 | # Try deleting the bndb, redownload and see if the function name is preserved |
| 71 | bv.file.close() |
| 72 | Path(file.default_path).unlink() |
| 73 | |
| 74 | print(f'Redownloading {project.name}/{file.name}...') |
| 75 | metadata = file.download_to_bndb() |
| 76 | bv = metadata.get_view_of_type(view_type) |
| 77 | print(f'Entry function name: {bv.entry_function.name}') |
| 78 | assert bv.entry_function.name == 'entry_function' |
| 79 | bv.file.close() |
| 80 | |
| 81 | finally: |
| 82 | # Clean up |
| 83 | if file is not None: |
| 84 | project.delete_file(file) |
| 85 | if project.is_open: |
| 86 | project.core_project.close() |
| 87 | remote.delete_project(project) |
| 88 | if project_dir is not None: |
| 89 | shutil.rmtree(project_dir) |
| 90 | |
| 91 | |
| 92 | if __name__ == '__main__': |
no test coverage detected