コード例 #1
0
def umount(image_file):
    loop_device = get_mount_loop_device(image_file)
    if loop_device != "":
        print(run_shell('udisksctl loop-delete -b ' + loop_device))
        print(run_shell('udisksctl unmount -b ' + loop_device + 'p1'))
        print(run_shell('udisksctl unmount -b ' + loop_device + 'p2'))
        print(run_shell('udisksctl unmount -b ' + loop_device + 'p3'))
コード例 #2
0
ファイル: disk.py プロジェクト: wxuefei/NaOS
def mount_point(image_file, pat):
    loop_device = get_mount_loop_device(image_file)
    if loop_device != "":
        point = run_shell('udisksctl info -b ' + loop_device + 'p' + str(pat) +
                          ' | grep MountPoints | awk \'{print $2}\'').strip(
                              '\n')
        return point
    return None
コード例 #3
0
ファイル: make_symbols.py プロジェクト: kadds/NaOS
def gen_symbols(file, target_file, force):
    try:
        os.makedirs(os.path.dirname(os.path.realpath(target_file)))
    except FileExistsError:
        pass

    if os.path.exists(cache_file_name) and not force:
        cache_file = open(cache_file_name, "r")
        cache_line = cache_file.readlines()
        if len(cache_line) == 1:
            line = cache_line[0].split("?")
            filename = line[0].strip()
            if len(line) > 1 and filename == file:
                time = line[1].strip()
                if time == datetime.datetime.fromtimestamp(
                        os.path.getmtime(file)).strftime(
                            "%Y-%m-%d %H:%M:%S.%f"):
                    print("ksybs is cached. do nothing.")
                    cache_file.close()
                    return None

        cache_file.close()

    smps = run_shell("nm \"" + file + "\" -C | sort | uniq", None, False)
    lines = smps.splitlines(False)
    output = open(target_file, 'wb')
    output.write(struct.pack("Q", 0xF0EAEACC))  # magic
    output.write(struct.pack("Q", 1))  # version
    output.write(struct.pack("Q", len(lines)))  # list count

    print("revice %d symbols" % len(lines))
    offset = 0
    list = []
    for line in lines:
        v = line.split(" ")
        addr = v[0].strip()
        name = " ".join(v[2:])
        type_name = v[1].strip()

        output.write(struct.pack("Q", int(addr, 16)))
        output.write(struct.pack("Q", offset))
        list.append((name, offset, type_name))
        offset += len(name.encode("utf-8")) + 2

    for it in list:
        output.write(struct.pack("c", it[2].encode("utf-8")))  # type
        output.write(
            struct.pack(str(len(it[0]) + 1) + "s",
                        it[0].encode('utf-8')))  # name

    output.close()

    cache_file = open(cache_file_name, "w")
    cache_file.write(file + "?" + datetime.datetime.fromtimestamp(
        os.path.getmtime(file)).strftime("%Y-%m-%d %H:%M:%S.%f"))
    cache_file.close()

    print("make %s success" % (os.path.realpath(target_file)))
コード例 #4
0
ファイル: disk.py プロジェクト: wxuefei/NaOS
def mount(image_file):
    image_file = os.path.realpath(image_file)
    current_loop_device = get_mount_loop_device(image_file)
    if current_loop_device == "":
        current_loop_device = run_shell('udisksctl loop-setup -f ' +
                                        image_file +
                                        " | awk '{print $5}'").strip('\n')
        config = configparser.ConfigParser()
        config.read(cfg_file_name)
        if config.has_section(image_file) == False:
            config.add_section(image_file)
        config.set(image_file, "loop_device", "")
        assert current_loop_device != ''
        current_loop_device = current_loop_device[0:-1]
        config.set(image_file, "loop_device", current_loop_device)
        config.write(open(cfg_file_name, 'w'))
        run_shell("udisksctl mount -b " + current_loop_device +
                  "p1").strip('\n')
        run_shell("udisksctl mount -b " + current_loop_device +
                  "p2").strip('\n')

    print(current_loop_device)
コード例 #5
0
ファイル: disk.py プロジェクト: wxuefei/NaOS
def get_mount_loop_device(image_file):
    image_file = os.path.realpath(image_file)
    config = configparser.ConfigParser()
    config.read(cfg_file_name)
    if config.has_section(image_file):
        dev = config.get(image_file, "loop_device")
        if dev == "":
            return ""
        point = run_shell('udisksctl info -b ' + dev +
                          ' | grep BackingFile | awk \'{print $2}\'',
                          print_command=False).strip('\n')
        if point != image_file:
            config.set(image_file, "loop_device", "")
            config.write(open(cfg_file_name, 'w'))
            return ""
        return dev
    return ""
コード例 #6
0
                            "--source",
                            action='store_true',
                            help="show source code")
        parser.add_argument("component",
                            type=str,
                            nargs="+",
                            choices=choices,
                            help="the component want to decompile")
        args = parser.parse_args()

        cmd = "objdump "

        if args.detail:
            cmd += "-l "
        if args.source:
            cmd += "-S "
        cmd += "-d --section=.text -C -l -m"

        targets = args.component
        for target in targets:
            tp = fileMap.get(target, "")
            if tp != "":
                print("find target at ", tp)
                run_shell(cmd + "i386:x86-64 " + tp + " > " +
                          os.path.split(tp)[0] + "/" + target + ".dbg.S")
        print("%d target(s) is generated." % (len(targets)))
    except Exception:
        traceback.print_exc()
        parser.print_help()
        exit(-1)
コード例 #7
0
ファイル: run.py プロジェクト: meehoyuen/NaOS
                        action='store_true',
                        help="try don't show window")
    parser.add_argument("emulator_name",
                        type=str,
                        choices=["q", "b", "v"],
                        help="q: run qemu\nb: run bochs\nv: run virtual box")

    base_mnt = mount_point("../run/image/disk.img", 2)

    args = parser.parse_args()
    if base_mnt == "" or base_mnt == None:
        print("Mount disk before run.\n    try 'python disk.py mount'")
        exit(-1)

    try:
        run_shell('cp -R ../build/bin/system/* ' + base_mnt + '/boot/')
        run_shell('sync')
        tp = args.emulator_name
        if tp == 'q':
            if args.nographic:
                print('run qemu without graphic')
                run_shell(qemu_headless)
            else:
                print("run qemu")
                run_shell(qemu)

        elif tp == 'b':
            print('run bochs')
            run_shell_input(bochs)
        elif tp == 'v':
            print('run VBox')