PowerShell - Adaptar este script a PowerShell

 
Vista:
sin imagen de perfil
Val: 8
Ha mantenido su posición en PowerShell (en relación al último mes)
Gráfica de PowerShell

Adaptar este script a PowerShell

Publicado por Meta (9 intervenciones) el 07/07/2020 17:55:10
Hola:

Antes que nada.

¿Con Visual studio 2019 Community 2019 se puede usar PowerShell?

A lo que iba.

Quiero adaptar este código de Python 2.7 a PowerShell.

¿Es posible?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os, sys, tkFileDialog,Tkinter
 
root = Tkinter.Tk()
root.withdraw()
 
formats = [ ('Roms Super Nintendo SMC','.smc'),('Roms Super Nintendo SFC','.sfc'),('Fichier Bin','.bin'),('Roms Super Nintendo','.smc .sfc .bin') ]
 
input = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=formats,
                                 title='Seleccione el archivo para intercambiar bin HI a LO como A16->A15, A17->A16...A21->A20 y A15->21')
if not input:
    print "Error: no se puede abrir el archivo."
    sys.exit()
 
output = tkFileDialog.asksaveasfile(parent=root,mode='wb',filetypes=formats,title='Crear nombre de archivo de salida.')
if not output:
    print "Error: no se puede crear el archivo de salida."
    sys.exit()
 
 
    # Leer el archivo de entrada a una matriz de bytes.
    data = bytearray(input.read())
 
    # Calculando el tamaño de la habitación en 2 exponentes.
    expsize = 0
    bytesize = len(data)
    while bytesize > 1:
            expsize += 1
            bytesize = bytesize // 2
 
    # Iniciar una matriz de bytes vacía de tamaño adecuado.
    buffer = bytearray()
    for i in range(2**expsize): buffer.append(0)
 
    # Hagamos el intercambio.
    count = 0
    for i in range(len(data)):
            addr = (i & 0x7fff) + ((i & 0x008000) << (expsize - 16)) + ((i & 0x010000) >> 1) + ((i & 0x020000) >> 1) + ((i & 0x040000) >> 1)
            + ((i & 0x080000) >> 1) +	((i & 0x100000) >> 1) + ((i & 0x200000) >> 1)
            if addr != i: count += 1
            buffer[addr] = data[i]
    print "Intercambiadas %s (%s) direcciones" % (count, hex(count))
 
    # Escribir archivo de salida.
    output.write(buffer)
 
    # Cerrar archivos maneja.
    input.close()
    output.close()

Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder