Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Windows Preinstallation Environment(WinPE). WinBuilder (2)

Модерирует : KLASS, IFkO

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

Sonya



Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору


Код:
 
#!/usr/bin/env python
# -*- Mode: Python; tab-width: 4 -*-
#
# Windows OSLoader Modification Tool
#
# Copyright (C) 2006-2007 Gianluigi Tiesi <sherpya@netfarm.it>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# ======================================================================
 
from sys import argv, exit as sys_exit
from string import digits, letters
from getopt import getopt
from struct import pack, unpack
import re
 
__version__ = '0.1'
 
__usage__ = """%s: [-l loader] [-p port] [-v] [-r response] inputfile
startrom:
 - changes SetupLoader       [-l] : exactly 5 chars - only if not yet modified
SetupLDR:
 - changes the udp port      [-p] : 16 bit integer
 - displays the current port [-v] : no modification are made
 - change response file      [-r] : exactly 9 chars - only if not yet modified
 
!!! Warning modifications are made in-place, so the file is modified !!!"""
 
arglist = 'l:p:vr:'
ppattern = re.compile(r'\x6a\x04\x68(..)\x00\x00\xff\x35', re.DOTALL)
allowed_chars = digits + letters + '.'
 
def check_name(name):
    for i in range(len(name)):
        if name[i] not in allowed_chars:
            return 0
    return 1
 
if __name__ == '__main__':
    loader = None
    port = None
    response = None
    display = None
 
    try:
        optlist, args = getopt(argv[1:], arglist)
        if (len(optlist) == 0) or (len(args) != 1): raise Exception
    except:
        print __usage__ % argv[0]
        sys_exit(-1)
 
    for arg in optlist:
        if arg[0] == '-l':
            loader = arg[1]
            continue
        if arg[0] == '-p':
            port = arg[1]
            continue
        if arg[0] == '-v':
            display = 1
            continue
        if arg[0] == '-r':
            response = arg[1]
            continue
 
    filename = args[0]
    data = open(filename, 'rb').read()
    if len(data) < 1024: # enough ?
        print 'Short read, file too small'
        sys_exit(-1)
 
    filetype = data[:2]
 
    if filetype != 'MZ':
        ### Assume pxe rom
        if loader is None or port is not None or response is not None or display is not None:
            print 'Invalid operation for startrom file'
            sys_exit(-1)
        if len(loader) != 5:
            print 'The loader should be EXACTLY 5 character'
            sys_exit(-1)
        if not check_name(loader):
            print 'Invalid character in loader name, allowed chars are:'
            print allowed_chars
        pat = re.compile(r'NTLDR', re.IGNORECASE)
        out = pat.sub(loader, data)
        if out == data:
            print 'No string was replaced, make sure that the string was not already changed'
            sys_exit(-1)
        open(filename, 'wb').write(out)
        print 'Loader succesfully changed to', loader
        sys_exit(0)
    else:
        ### Assume OsLoader
        if loader is not None:
            print 'Invalid operation for SetupLDR file'
            sys_exit(-1)
 
        if display is not None and (port is not None or response is not None):
            print 'Display option should be used alone'
            sys_exit(-1)
 
        ### Changing port
        if port is not None:
            try:
                port = int(port)
                if (port <= 0) or (port >= 0xfff):
                    raise Exception
            except:
                print 'Invalid port specified, it must be in range 1-65534'
                sys_exit(-1)
            ##
            res = ppattern.search(data)
            if res is None:
                print 'Port pattern not found in file, if you think it\'s an error, please report'
                sys_exit(-1)
            hdr = data[:res.start() + 3]
            footer = data[res.end() - 4:]
            out = hdr + pack('!H', port) + footer
            data = out
 
        ### Changing response file
        if response is not None:
            if len(response) != 9:
                print 'The response should be EXACTLY 9 character'
                sys_exit(-1)
            if not check_name(response):
                print 'Invalid character in response name, allowed chars are:'
                print allowed_chars
            pat = re.compile(r'winnt\.sif', re.IGNORECASE)
            out = pat.sub(response, data)
            if out == data:
                print 'No string was replaced, make sure that the string is not already changed'
                sys_exit(-1)
            print 'Response changed to', response
 
        if display is None:
            open(filename, 'wb').write(out)
            print 'File succesfully modified'
        else:
            res = ppattern.search(data)
            if res is None:
                print 'Port location not found, bad file?'
                sys_exit(-1)
            port = unpack('!H', res.group(0)[3:5])[0]
            print 'SetupLDR is currently using port', port
 
        sys_exit(0)
 


Всего записей: 270 | Зарегистр. 30-12-2005 | Отправлено: 21:41 02-07-2009 | Исправлено: Sonya, 18:40 04-07-2009
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Windows Preinstallation Environment(WinPE). WinBuilder (2)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru