[BATCH]Bin2Bat

Iniciado por Binary_Death, 29 Julio 2012, 02:25 AM

0 Miembros y 1 Visitante están viendo este tema.

Binary_Death

Este es un pequeño script que hice hace ya tiempo que es capaz de descomponer un fichero de un tamaño no superior a 64kb en hexadecimal, para luego volver a ensamblarlo usando debug.

Por cierto, no se me olvida, ¡muchas gracias a "Germaniac", que me ayudó a perfeccionarlo y a quitar la basura innecesaria!


@Echo Off
Title Bin2Bat
Set/P "File_Con=File: "
Set/P "File_Fin=BAT Name: "
Echo.
If Not Exist "%File_Con%" (
    Echo.File not Found.
    Pause>Nul
    Exit
)
Call:BfE "%File_Con%" "%File_Fin%"
Echo.Completed.
Pause>NUL
Exit
:BfE
  SetLocal EnableDelayedExpansion
Set "_=Echo."
   Set/A "$=%~z1+0xFF"
Call:D2H "%~z1" "#" & Call:D2H "%$%" "$"
    !_!@more +1 %%0^|Debug^>NUL^&Exit>"%~2"
   For /f "Eol=- Tokens=*" %%z in ('
       ^(!_!D 0100 %$%^&!_!Q^)^|DEBUG %~1
      ') do (Set "_TEX=%%z"
       Set "_SEX= !_TEX:~11,47!"
       Set "_SEX=!_SEX:   =!"
        call !_!e!_TEX:~5,4!%%_SEX:-= %%>>"%~2"
   )
(!_!RCX&!_!!#!&!_!N %~n2%~x1&!_!W&!_!Q)>>"%~2"
EndLocal & Exit/B
:D2H
  %ComSpec% /c Exit/B %~1
For /f "Tokens=* Delims=0" %%_ in (
     "%=ExitCode%") Do Set "%~2=%%_"
GoTo:EoF


Y ya que estamos, dejo un ejemplo de cómo queda el "CHOICE.COM" (para quienes no lo tengan para correr el Batch Tetris que posteé).



@more +1 %0|Debug>NUL&Exit
e0100 E9 32 04 59 4E 00 00 00 00 00 00 00 00 00 00 00
e0110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0180 00 00 00 00 00 57 61 69 74 73 20 66 6F 72 20 74
e0190 68 65 20 75 73 65 72 20 74 6F 20 63 68 6F 6F 73
e01A0 65 20 6F 6E 65 20 6F 66 20 61 20 73 65 74 20 6F
e01B0 66 20 63 68 6F 69 63 65 73 2E 0D 0A 0D 0A 00 43
e01C0 48 4F 49 43 45 20 5B 2F 43 5B 3A 5D 63 68 6F 69
e01D0 63 65 73 5D 20 5B 2F 4E 5D 20 5B 2F 53 5D 20 5B
e01E0 2F 54 5B 3A 5D 63 2C 6E 6E 5D 20 5B 74 65 78 74
e01F0 5D 0D 0A 0D 0A 00 2F 43 5B 3A 5D 63 68 6F 69 63
e0200 65 73 20 53 70 65 63 69 66 69 65 73 20 61 6C 6C
e0210 6F 77 61 62 6C 65 20 6B 65 79 73 2E 20 44 65 66
e0220 61 75 6C 74 20 69 73 20 59 4E 0D 0A 2F 4E 20 20
e0230 20 20 20 20 20 20 20 20 20 44 6F 20 6E 6F 74 20
e0240 64 69 73 70 6C 61 79 20 63 68 6F 69 63 65 73 20
e0250 61 6E 64 20 3F 20 61 74 20 65 6E 64 20 6F 66 20
e0260 70 72 6F 6D 70 74 20 73 74 72 69 6E 67 2E 0D 0A
e0270 2F 53 20 20 20 20 20 20 20 20 20 20 20 54 72 65
e0280 61 74 20 63 68 6F 69 63 65 20 6B 65 79 73 20 61
e0290 73 20 63 61 73 65 20 73 65 6E 73 69 74 69 76 65
e02A0 2E 0D 0A 2F 54 5B 3A 5D 63 2C 6E 6E 20 20 20 20
e02B0 44 65 66 61 75 6C 74 20 63 68 6F 69 63 65 20 74
e02C0 6F 20 63 20 61 66 74 65 72 20 6E 6E 20 73 65 63
e02D0 6F 6E 64 73 0D 0A 74 65 78 74 20 20 20 20 20 20
e02E0 20 20 20 50 72 6F 6D 70 74 20 73 74 72 69 6E 67
e02F0 20 74 6F 20 64 69 73 70 6C 61 79 0D 0A 0D 0A 45
e0300 52 52 4F 52 4C 45 56 45 4C 20 69 73 20 73 65 74
e0310 20 74 6F 20 6F 66 66 73 65 74 20 6F 66 20 6B 65
e0320 79 20 75 73 65 72 20 70 72 65 73 73 65 73 20 69
e0330 6E 20 63 68 6F 69 63 65 73 2E 0D 0A 0D 0A 00 49
e0340 6E 76 61 6C 69 64 20 73 77 69 74 63 68 20 6F 6E
e0350 20 63 6F 6D 6D 61 6E 64 20 6C 69 6E 65 2E 20 45
e0360 78 70 65 63 74 65 64 20 66 6F 72 6D 3A 0D 0A 20
e0370 20 20 20 00 43 48 4F 49 43 45 3A 20 69 6E 76 61
e0380 6C 69 64 20 63 68 6F 69 63 65 20 73 77 69 74 63
e0390 68 20 73 79 6E 74 61 78 2E 20 45 78 70 65 63 74
e03A0 65 64 20 66 6F 72 6D 3A 20 2F 43 5B 3A 5D 63 68
e03B0 6F 69 63 65 73 0D 0A 00 43 48 4F 49 43 45 3A 20
e03C0 49 6E 63 6F 72 72 65 63 74 20 74 69 6D 65 6F 75
e03D0 74 20 73 79 6E 74 61 78 2E 20 20 45 78 70 65 63
e03E0 74 65 64 20 66 6F 72 6D 20 54 63 2C 6E 6E 20 6F
e03F0 72 20 54 3A 63 2C 6E 6E 0D 0A 00 43 48 4F 49 43
e0400 45 3A 20 54 69 6D 65 6F 75 74 20 64 65 66 61 75
e0410 6C 74 20 6E 6F 74 20 69 6E 20 73 70 65 63 69 66
e0420 69 65 64 20 28 6F 72 20 64 65 66 61 75 6C 74 29
e0430 20 63 68 6F 69 63 65 73 2E 0D 0A 00 43 48 4F 49
e0440 43 45 3A 20 6F 6E 6C 79 20 6F 6E 65 20 70 72 6F
e0450 6D 70 74 20 73 74 72 69 6E 67 20 61 6C 6C 6F 77
e0460 65 64 2E 20 45 78 70 65 63 74 65 64 20 46 6F 72
e0470 6D 3A 0D 0A 20 20 20 20 00 43 48 4F 49 43 45 3A
e0480 20 72 65 71 75 69 72 65 73 20 4D 53 2D 44 4F 53
e0490 20 76 65 72 73 69 6F 6E 20 34 2E 30 20 6F 72 20
e04A0 6C 61 74 65 72 2E 0D 0A 00 00 00 01 00 00 00 00
e04B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e04C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e04D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e04E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e04F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0500 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0510 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0520 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0530 00 00 00 00 00 FC B0 01 B4 30 CD 21 3C 03 7F 0B
e0540 BB 79 04 E8 57 02 B0 FF E9 4E 02 06 B8 02 65 BB
e0550 FF FF B9 05 00 8B D3 0E BF 2F 05 CD 21 47 C4 3D
e0560 26 8B 1D B8 00 01 2B C3 A3 33 05 83 C7 02 89 3E
e0570 2F 05 8C 06 31 05 07 BE 81 00 AC 3C 0D 75 03 E9
e0580 38 01 3C 2F 74 41 3C 20 74 F0 3C 09 74 EC BF AF
e0590 04 80 3D 00 75 20 3C 22 75 04 B2 22 EB 03 B2 2F
e05A0 AA 8A 04 3C 0D 74 D3 3A C2 74 04 AA 46 EB F2 3C
e05B0 2F 74 C7 46 EB C4 BB 3C 04 E8 E1 01 BB BF 01 E8
e05C0 DB 01 B0 FF E9 D2 01 AC E8 E9 01 3C 3F 74 24 3C
e05D0 43 74 37 3C 4E 74 6D 3C 54 74 71 3C 53 75 03 E9
e05E0 D0 00 BB 3F 03 E8 B5 01 BB BF 01 E8 AF 01 B0 FF
e05F0 E9 A6 01 BB 85 01 E8 A4 01 BB BF 01 E8 9E 01 BB
e0600 F6 01 E8 98 01 B0 FF E9 8F 01 BF 03 01 8A 04 3C
e0610 3A 75 03 46 8A 04 3C 20 74 12 3C 09 74 0E 3C 0D
e0620 74 0A 3C 2F 74 06 AA 46 8A 04 EB EA B0 00 88 05
e0630 81 FF 03 01 74 03 E9 41 FF BB 74 03 E8 5E 01 B0
e0640 FF E9 55 01 C6 06 AB 04 00 E9 2E FF 8A 04 3C 3A
e0650 75 03 46 8A 04 3C 0D 74 4E 3C 2F 74 4A 3C 20 74
e0660 46 3C 09 74 42 A2 AE 04 46 8A 04 3C 2C 75 38 46
e0670 8A 04 3C 30 72 31 3C 39 77 2D 83 E0 0F A2 AD 04
e0680 46 8A 04 3C 30 73 03 E9 F0 FE 3C 39 76 03 E9 E9
e0690 FE A0 AD 04 BA 0A 00 F6 E2 8A 1C 80 E3 0F 02 C3
e06A0 A2 AD 04 46 E9 D3 FE BB B8 03 E8 F0 00 B0 FF E9
e06B0 E7 00 C6 06 AC 04 01 E9 C0 FE 80 3E AC 04 01 74
e06C0 1B A0 AE 04 E8 ED 00 A2 AE 04 BE 03 01 80 3C 00
e06D0 74 0A 8A 04 E8 DD 00 88 04 46 EB F1 BF 03 01 B9
e06E0 80 00 A0 AE 04 F2 AE 74 0B BB FB 03 E8 AE 00 B0
e06F0 FF E9 A5 00 BB AF 04 E8 A3 00 80 3E AB 04 01 75
e0700 29 BF 03 01 B4 02 B2 5B CD 21 B4 02 8A 15 CD 21
e0710 47 80 3D 00 74 08 B4 02 B2 2C CD 21 EB EC B4 02
e0720 B2 5D CD 21 B4 02 B2 3F CD 21 80 3E AD 04 00 74
e0730 2D B4 2C CD 21 88 36 AA 04 B4 0B CD 21 83 E0 01
e0740 83 C8 00 75 19 B4 2C CD 21 38 36 AA 04 74 EA 88
e0750 36 AA 04 FE 0E AD 04 75 E0 A0 AE 04 EB 04 B4 08
e0760 CD 21 BF 03 01 80 3E AC 04 01 74 03 E8 45 00 80
e0770 3D 00 74 05 AE 74 0A EB F6 B4 02 B2 07 CD 21 EB
e0780 DD B4 02 8A D0 CD 21 B4 02 B2 0D CD 21 B4 02 B2
e0790 0A CD 21 81 EF 03 01 8B C7 B4 4C CD 21 50 57 52
e07A0 B4 02 33 FF 8A 11 80 FA 00 74 05 CD 21 47 EB F4
e07B0 5A 5F 58 C3 53 57 06 3C 61 72 1B 3C 7A 77 04 2C
e07C0 20 EB 13 3C 80 72 0F C4 3E 2F 05 8B D8 32 FF 2B
e07D0 1E 33 05 26 8A 01 07 5F 5B C3
RCX
6DA
N CHOICE.COM
W
Q


Un saludo  :P