def SetPeSubsystem(fd, console=True):
 current_pos = fd.tell()
 fd.seek(60)
 header_offset = struct.unpack('<I', fd.read(4))[0]
 subsystem_offset = (header_offset + 92)
 fd.seek(subsystem_offset)
 if console:
  fd.write('\x03')
 else:
  fd.write('\x02')
 fd.seek(current_pos)

def SetPeSubsystem ( fd , console = True ) : current_pos = fd . tell ( ) fd . seek ( 60 ) header_offset = struct . unpack ( '<I' , fd . read ( 4 ) ) [ 0 ] subsystem_offset = ( header_offset + 92 ) fd . seek ( subsystem_offset ) if console : fd . write ( '\x03' ) else : fd . write ( '\x02' ) fd . seek ( current_pos )
takes file like obj and returns for the pe subsystem .