Skip to content

Instantly share code, notes, and snippets.

@RealityAnomaly
Last active January 4, 2024 10:55
Show Gist options
  • Save RealityAnomaly/d43b163921c9b3b50ad98f82799236d3 to your computer and use it in GitHub Desktop.
Save RealityAnomaly/d43b163921c9b3b50ad98f82799236d3 to your computer and use it in GitHub Desktop.
esxcli-software-patched.py
import shutil
import subprocess
import tempfile
import sys
# example use: python3 ./patch.py vib.install -v /vmfs/volumes/65790f67-650d4902-c890-d0431e4ede0e/BCM_bootbank_dell-shared-perc8_06.806.92.00-1OEM.700.1.0.15843807.vib -f --dryrun
patch_data = '''
# start of patch area
import inspect
import textwrap
import subprocess
patch1_fn_source = inspect.getsource(Transaction.Transaction._installVibs)
patch1_fn_source = patch1_fn_source.replace('replace=True', 'replace=False')
patch1_fn_source = patch1_fn_source.replace('Transaction.', 'self.')
patch1_fn_source = textwrap.dedent(patch1_fn_source)
result1_locals = {}
exec(patch1_fn_source, Transaction.__dict__, result1_locals)
Transaction.Transaction._installVibs = result1_locals['_installVibs']
patch2_fn_source = inspect.getsource(ImageProfile.ImageProfile._syncVibs)
patch2_fn_source = patch2_fn_source.replace('vibScanRes.vibs[vibId].replacedBy', 'False')
patch2_fn_source = textwrap.dedent(patch2_fn_source)
result2_locals = {}
exec(patch2_fn_source, ImageProfile.__dict__, result2_locals)
ImageProfile.ImageProfile._syncVibs = result2_locals['_syncVibs']
'''
with open('/usr/lib/vmware/esxcli-software', 'r') as f:
lines = f.readlines()
index = 0
for index, line in enumerate(lines):
if line.startswith('setupLogging()'):
break
the_patch = patch_data.strip().splitlines()
the_patch.reverse()
for line in the_patch:
lines.insert(index, line + '\n')
with tempfile.NamedTemporaryFile('w') as f:
f.writelines(lines)
f.flush()
subprocess.run(['python3', f.name] + sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment