MIT License

Copyright (c) IBM and Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

-r
AX=0000 BX=0000 CX=4CA9 DX=0000 SP=0080 BP=0000 SI=0000 DI=0000
DS=2B31 ES=2B31 SS=3010 CS=2FCB IP=0012 NV UP EI PL ZR NA PE NC
0012 8CC0              mov     ax, es
-dw cs:0 l 12
header     0    2    4    6    8    A    C    E    0123456789ABCDEF
2FCB:0000  1EC0 0000 0000 0409-2000 1122 048E 0001 ......... ".....
2FCB:0010  4252               -                    RB
-u
0012 8CC0              mov     ax, es
0014 051000            add     ax, word 0010	; => image destination
0017 0E                push    cs
0018 1F                pop     ds		; => depacker
0019 A30400            mov     [0004], ax
001C 03060C00          add     ax, [000C]	; => depacker destination
0020 8EC0              mov     es, ax
0022 8B0E0600          mov     cx, [0006]	; = depacker length
0026 8BF9              mov     di, modrm cx
0028 4F                dec     di		; -> last byte
0029 8BF7              mov     si, modrm di	; -> last byte
002B FD                std
002C F3A4              rep     movsb		; copy depacker up
002E 8B160E00          mov     dx, [000E]	; = ???
-
0032 50                push    ax
0033 B83800            mov     ax, 0038
0036 50                push    ax		; -> relocated entry
0037 CB                retf			; branch to relocated depacker
0038 8CC3              mov     bx, es		; => behind image destination
003A 8CD8              mov     ax, ds		; => behind image source
003C 2BC2              sub     ax, modrm dx
003E 8ED8              mov     ds, ax		; => image end
0040 8EC0              mov     es, ax
0042 BF0F00            mov     di, 000F
0045 B91000            mov     cx, 0010
0048 B0FF              mov     al, FF		; scan for FFh
004A F3AE              repe    scasb		; scan until non-equal
004C 47                inc     di		; -> highest non-FFh
004D 8BF7              mov     si, modrm di
004F 8BC3              mov     ax, modrm bx
0051 2BC2              sub     ax, modrm dx	; => destination
-
0053 8EC0              mov     es, ax
0055 BF0F00            mov     di, 000F
	; main depack loop jumps to here:
0058 B104              mov     cl, 04
005A 8BC6              mov     ax, modrm si
005C F7D0              not     ax
005E D3E8              shr     ax, cl		; = 0FFFh in first iteration
0060 7409              jz      006B
0062 8CDA              mov     dx, ds
0064 2BD0              sub     dx, modrm ax
0066 8EDA              mov     ds, dx		; negative segment
0068 83CEF0            or      si, -10		; OR mask FFF0h
006B 8BC7              mov     ax, modrm di
006D F7D0              not     ax
006F D3E8              shr     ax, cl
0071 7409              jz      007C
-
0073 8CC2              mov     dx, es
0075 2BD0              sub     dx, modrm ax
0077 8EC2              mov     es, dx		; negative segment
0079 83CFF0            or      di, -10		; OR mask FFF0h
007C AC                lodsb
007D 8AD0              mov     dl, modrm al	; save header byte
007F 4E                dec     si		; prepare lodsw
0080 AD                lodsw
0081 8BC8              mov     cx, modrm ax	; save length
0083 46                inc     si		; prepare subsequent lodsb
0084 8AC2              mov     al, modrm dl	; get header byte
0086 24FE              and     al, FE
0088 3CB0              cmp     al, B0		; B0h or B1h ?
008A 7506              jnz     0092		; no -->
008C AC                lodsb			; get RLE value
008D F3AA              rep     stosb		; fill RLE area
008F EB07              jmp     0098		; next -->
0091 90                nop
0092 3CB2              cmp     al, B2		; B2h or B3h ?
-
0094 756B              jnz     0101		; no -->
0096 F3A4              rep     movsb		; copy literals
0098 8AC2              mov     al, modrm dl	; get header byte
009A A801              test    al, 01		; low bit set ?
009C 74BA              jz      0058		; no, loop -->
	; relocation code starts here
009E BE2D01            mov     si, 012D
00A1 0E                push    cs
00A2 1F                pop     ds		; -> relocations table
00A3 8B1E0400          mov     bx, [0004]	; => image
00A7 FC                cld			; UP
00A8 33D2              xor     dx, modrm dx
	; outer loop for next relocation area starts here
00AA AD                lodsw			; = counter for this area
00AB 8BC8              mov     cx, modrm ax
00AD E313              jcxz    00C2		; if counter zero -->
00AF 8BC2              mov     ax, modrm dx
00B1 03C3              add     ax, modrm bx
00B3 8EC0              mov     es, ax		; => point at this area
-
	; inner loop within a relocation area starts here
00B5 AD                lodsw			; -> relocation
00B6 8BF8              mov     di, modrm ax
00B8 83FFFF            cmp     di, -01		; is it offset 0FFFFh ?
00BB 7411              jz      00CE		; yes -->
00BD 26011D            add     [es:di], bx	; relocate
00C0 E2F3              loop    00B5		; loop for area -->
00C2 81FA00F0          cmp     dx, F000		; was last area ?
00C6 7416              jz      00DE		; yes -->
00C8 81C20010          add     dx, 1000		; = next area base
00CC EBDC              jmp     00AA
00CE 8CC0              mov     ax, es
00D0 40                inc     ax
00D1 8EC0              mov     es, ax		; => segment 1 para above area
00D3 83EF10            sub     di, +10		; FFFFh to FFEFh
-
00D6 26011D            add     [es:di], bx	; relocate
00D9 48                dec     ax
00DA 8EC0              mov     es, ax		; restore => area
00DC EBE2              jmp     00C0		; next -->
00DE 8BC3              mov     ax, modrm bx	; => image
00E0 8B3E0800          mov     di, [0008]	; = value for sp
00E4 8B360A00          mov     si, [000A]	; = value for ss
00E8 03F0              add     si, modrm ax	; relocate value for ss
00EA 01060200          add     [0002], ax	; relocate value for cs
00EE 2D1000            sub     ax, word 0010	; => PSP
00F1 8ED8              mov     ds, ax
00F3 8EC0              mov     es, ax		; => PSP
00F5 BB0000            mov     bx, 0000		; cs:bx -> value for cs:ip
-
00F8 FA                cli
00F9 8ED6              mov     ss, si
00FB 8BE7              mov     sp, modrm di	; set stack
00FD FB                sti
00FE 2EFF2F            jmp     far [cs:bx]	; jump to entrypoint
0101 B440              mov     ah, 40		; DOS write
0103 BB0200            mov     bx, 0002		; stderr
0106 B91600            mov     cx, 0016		; length
0109 8CCA              mov     dx, cs
010B 8EDA              mov     ds, dx		; => cs
010D BA1701            mov     dx, 0117		; -> message
0110 CD21              int     21		; display error message
0112 B8FF4C            mov     ax, 4CFF
0115 CD21              int     21		; exit with code 255
0117 50                push    ax
-d cs:117 12D-1
0110                       50-61 63 6B 65 64 20 66 69        Packed fi
0120  6C 65 20 69 73 20 63 6F-72 72 75 70 74          le is corrupt
-dw cs:12D
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:0120                       -          015E 001E             ^...
2FCB:0130    0036 0040 004A 005C-0061 0074 0079 0083 6.@.J.\.a.t.y...
2FCB:0140    008B 009C 00A5 00BC-01C2 01D4 01D9 01EB ................
2FCB:0150    01F0 0202 0207 0219-021E 0228 023A 023F ..........(.:.?.
2FCB:0160    0244 024B 025A 0274-029D 02D8 0300 0420 D.K.Z.t....... .
2FCB:0170    0458 046D 0472 047C-0484 048D 04B5 09E9 X.m.r.|.........
2FCB:0180    09FF 0A0C 0A11 0A20-0A2F 0A3D 0A52 0A57 ...... ./.=.R.W.
2FCB:0190    0A6E 0A91 0A9B 0AA5-0AAF 0AB9 0AF6 0B11 n...............
2FCB:01A0    0B24 0B36 0B3B 0B4F-0B54 0B62           $.6.;.O.T.b.
-
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:01A0                       -          0B80 0B9E             ....
2FCB:01B0    0BBE 0BDE 0BEE 0BF8-0C02 0C0C 0C64 0C92 ............d...
2FCB:01C0    0CA3 0CCC 0CE3 0CFF-0D04 0D16 0D1B 0D2D ..............-.
2FCB:01D0    0D32 0D3F 0D6A 0DD9-0DEB 0DF0 0E02 0E12 2.?.j...........
2FCB:01E0    0E1F 0E2F 0E3C 0E41-0E53 0E58 0E6A 0E6F ../.<.A.S.X.j.o.
2FCB:01F0    0E8B 0E9D 0EA2 0EB4-0EB9 0ECB 0ED0 0EE3 ................
2FCB:0200    0EF5 0EFA 0F0C 0F11-0F26 0F2B 0F4E 0F53 ........&.+.N.S.
2FCB:0210    0FA0 0FB1 0FBF 0FD0-0FFD 1014 1026 1066 ............&.f.
2FCB:0220    106B 1079 1090 10A7-10AE 10BD           k.y.........
-
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:0220                       -          1113 1125             ..%.
2FCB:0230    112C 1142 115B 1175-117F 119E 11B5 11BA ,.B.[.u.........
2FCB:0240    11C4 11F1 1206 120B-12B7 12CE 135C 137D ............\.}.
2FCB:0250    13B0 13F4 1410 147C-1498 14FE 151F 1552 ......|.......R.
2FCB:0260    1596 15B2 15E5 15EA-15FA 160A 161F 163B ..............;.
2FCB:0270    1674 16EB 16FE 1716-1732 174A 1762 177A t.......2.J.b.z.
2FCB:0280    1792 17AA 17C1 17CE-17DF 17F0 17FA 1807 ................
2FCB:0290    1819 181E 18B3 18C1-18D3 18E3 18F0 1900 ................
2FCB:02A0    190D 1912 1924 1935-1942 194D           ....$.5.B.M.
-
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:02A0                       -          195B 1963             [.c.
2FCB:02B0    1970 197F 198C 1991-19A3 19BC 19C9 19D4 p...............
2FCB:02C0    19E2 19EA 19FC 1A09-1A18 1A25 1A2A 1A48 ..........%.*.H.
2FCB:02D0    1A5A 1A5F 1A71 1A7E-1A83 1A8D 1A9D 1AAF Z._.q.~.........
2FCB:02E0    1ABC 1AC9 1AD6 1ADB-1AEA 1AFD 1B02 1B10 ................
2FCB:02F0    1B1A 1B2C 1B41 1B4E-1B5B 1B68 1B6D 1B7C ..,.A.N.[.h.m.|.
2FCB:0300    1B89 1BAB 1BC0 1BD6-1BE5 1BF2 1C05 1C18 ................
2FCB:0310    1C2D 1C71 1C7C 1C81-1C90 1CA0 1CAB 1CB5 -.q.|...........
2FCB:0320    1D0D 1D2D 1D3B 1D52-1D70 1D84           ..-.;.R.p...
-
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:0320                       -          1D8E 1D9C             ....
2FCB:0330    1DAF 1DD3 1DDD 1DEB-1DFE 1E42 1E4C 1E5A ..........B.L.Z.
2FCB:0340    1EC3 1EC8 1EDD 1EE2-1EF4 1EF9 1F03 1F16 ................
2FCB:0350    2341 234B 2350 2362-2367 236C 237E 2383 A#K#P#b#g#l#~#.#
2FCB:0360    2388 239A 239F 23A4-23B6 23BB 23C0 23D8 .#.#.#.#.#.#.#.#
2FCB:0370    2408 242B 245E 246D-2472 2481 249B 24AA .$+$^$m$r$.$.$.$
2FCB:0380    24DD 24EC 24F2 24F7-2506 2520 252F 255D .$.$.$.$.% %/%]%
2FCB:0390    28C5 28E0 28FB 2916-2931 294C 2967 2982 .(.(.(.)1)L)g).)
2FCB:03A0    299D 29B8 29D3 29EE-2A09 2A24           .).).).).*$*
-
header     0 1    3    5    7    9    B    D    F    123456789ABCDEF0
2FCB:03A0                       -          2A3F 2A5A             ?*Z*
2FCB:03B0    2A7A 2A95 2AB0 2ACB-2AE6 2B01 2B1C 2B37 z*.*.*.*.*.+.+7+
2FCB:03C0    2B52 2B6D 2B88 2BA3-2BBE 2BD9 2BF4 2C0F R+m+.+.+.+.+.+.,
2FCB:03D0    2C2A 2C45 2C60 2C7A-2C94 2CAE 2CC8 2CDD *,E,`,z,.,.,.,.,
2FCB:03E0    2D01 2D18 30B1 318D-42FA 0000 0000 0000 .-.-.0.1.B......
2FCB:03F0    0000 0000 0000 0000-0000 0000 0000 0000 ................
2FCB:0400    0000 0000 0000 0000-2E21 168B 0C48 DB31 ........!...H.1.
2FCB:0410    48B4 21CD 2D72 C08E-D039 0676 49B4 21CD .H.!r-..9.v..I.!
2FCB:0420    21EB 9350 DBF7 D301-4AB4 21CD           .!P......J.!
-r bxcx.
BXCX 00004CA9
-r psp.
PSP 2B31
-h linear psp:100, + bxcx
000300B9  decimal: 196793
-h linear 2FCB:409
000300B9  decimal: 196793
-q
