# Look through 'file' for a pattern signifying a KBD01.SYS or BASEDD01.SYS # which will cause division by zero traps on faster systems. If found, save # a backup with extension .old; if the backup file already exists, abort. # Replaces multiple occurrences, which is useful for patching floppy images # with several instances of the bad code in multiple files (e.g. BASEDD01.SYS, # as well as BASEDD02.SYS and BASEDD03.SYS). # # Copyright (C) 2011 The OS/2 Museum # import os import sys def usage(): print 'usage: ' + sys.argv[0] + ' ' args = sys.argv[1:] if len(args) != 1 : usage() sys.exit(1) # Get the arguments fname = args[0] # Initialize patterns old_pat = ( "\xB8\xF4\x01" # MOV AX, 1F4h "\xBB\xC8\x00" # MOV BX, 0C8h "\xF7\xE3" # MUL BX "\xF7\xF1" # DIV CX ) new_pat = ( "\xB8\xF4\x01" # MOV AX, 1F4h "\xBB\xC8\x00" # MOV BX, 0C8h "\xF7\xE3" # MUL BX "\x90" # NOP "\x90" # NOP ) # Read the source file fs = open(fname, "r+b") buf = fs.read() # Look for pattern pos = buf.find(old_pat) if pos == -1: print "Pattern not found, nothing to do." sys.exit(2) # Save a backup, unless backup file already exists fb_name = fname + '.old' fb = open(fb_name, "a+b") if os.fstat(fb.fileno()).st_size: print "Backup file", fb_name, "already exists, aborting." sys.exit(3) fb.write(buf) fb.close() # Replace all occurrences of pattern buf = buf.replace(old_pat, new_pat) # And finally write back modified file fs.seek(0) fs.write(buf) fs.close()

AltStyle によって変換されたページ (->オリジナル) /