From c4fce626da4792ed3e5e208b554f42212295c7ca Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Wed, 19 Oct 2022 22:32:57 +0200 Subject: [PATCH] some clean up - move dos unpacker, fix arm32 unpacker formatting --- README.md | 2 +- asm_unpackers/unpack_arm32.S | 54 +++++++++---------- dos_unpacker/readme.txt | 13 +++++ .../unpack_x86_16_DOS.asm | 0 .../unpack_x86_16_DOS_no_relocation.asm | 0 .../unpack_x86_16_DOS_no_repeated_offset.asm | 0 6 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 dos_unpacker/readme.txt rename {asm_unpackers => dos_unpacker}/unpack_x86_16_DOS.asm (100%) rename {asm_unpackers => dos_unpacker}/unpack_x86_16_DOS_no_relocation.asm (100%) rename {asm_unpackers => dos_unpacker}/unpack_x86_16_DOS_no_repeated_offset.asm (100%) diff --git a/README.md b/README.md index 36f4add..d22c401 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ is both about twice as fast and smaller than the Shrinkler unpacker. The release includes a reference c unpacker, as well as some optimized asm unpackers (arm and riscv). The unpckers in c_unpacker and asm_unpackers unpack the default upkr compressed format. The z80_unpacker is based on some variations to the compressed format. (Use `upkr --z80` to select those variations.) -An optimized x86 (DOS) unpacker is currently being worked on out of tree. +The 16 bit dos unpacker also uses some variations. (`upkr --x86`) ## Usage diff --git a/asm_unpackers/unpack_arm32.S b/asm_unpackers/unpack_arm32.S index 81cfff9..ade42d0 100644 --- a/asm_unpackers/unpack_arm32.S +++ b/asm_unpackers/unpack_arm32.S @@ -17,7 +17,7 @@ upkr_unpack: push { r3-r11, lr } - mov r2, #384 + mov r2, #384 mov r3, #128 .Lclear: subs r2, r2, #1 @@ -29,7 +29,7 @@ upkr_unpack: bl upkr_decode_bit bcc .Ldata .Lmatch: - mov r5, #256 + mov r5, #256 rsbs r6, r4, #0 blcc upkr_decode_bit bcc .Lskip_offset @@ -39,7 +39,7 @@ upkr_unpack: popeq { r3-r11, pc } .Lskip_offset: - mov r5, #256+64 + mov r5, #256+64 bl upkr_decode_length .Lcopy_loop: ldrb r5, [r0, r3] @@ -55,46 +55,46 @@ upkr_unpack: .Ldata_loop: bl upkr_decode_bit adc r5, r5, r5 - movs r4, r5, lsr #8 + movs r4, r5, lsr #8 beq .Ldata_loop - b .Lstore + b .Lstore .type upkr_decode_length, %function upkr_decode_length: - mov r12, lr + mov r12, lr mov r4, #0 - mvn r6, #0 + mvn r6, #0 .Lbit_loop: bl upkr_decode_bit_inc - addcc r4, r4, r6 - movcc pc, r12 + addcc r4, r4, r6 + movcc pc, r12 bl upkr_decode_bit_inc addcs r4, r4, r6 - mov r6, r6, lsl #1 + mov r6, r6, lsl #1 b .Lbit_loop .type upkr_decode_bit, %function upkr_decode_bit_inc: - add r5, r5, #1 + add r5, r5, #1 upkr_decode_bit: - cmp r2, #4096 - ldrltb r8, [r1], #1 - orrlt r2, r8, r2, lsl#8 - blt upkr_decode_bit + cmp r2, #4096 + ldrltb r8, [r1], #1 + orrlt r2, r8, r2, lsl#8 + blt upkr_decode_bit ldrb r8, [sp, -r5] - and r9, r2, #255 - add r9, r9, #1 - cmp r8, r9 - rsbcs r8, r8, #256 - mvn r9, r2, lsr#8 - addcs r9, r9, #1 - mla r2, r8, r9, r2 - add r9, r8, #8 - sub r8, r8, r9, lsr#4 - rsbcs r8, r8, #256 - strb r8, [sp, -r5] - mov pc, r14 + and r9, r2, #255 + add r9, r9, #1 + cmp r8, r9 + rsbcs r8, r8, #256 + mvn r9, r2, lsr#8 + addcs r9, r9, #1 + mla r2, r8, r9, r2 + add r9, r8, #8 + sub r8, r8, r9, lsr#4 + rsbcs r8, r8, #256 + strb r8, [sp, -r5] + mov pc, r14 diff --git a/dos_unpacker/readme.txt b/dos_unpacker/readme.txt new file mode 100644 index 0000000..d76fb42 --- /dev/null +++ b/dos_unpacker/readme.txt @@ -0,0 +1,13 @@ +16 bit DOS executable stubs +--------------------------- + +by pestis and TomCat + +unpack_x86_16_DOS.asm: + maximum compatibility, relocates unpacked code to normal start address +unpack_x86_16_DOS_no_relocation.asm: + saves some bytes by not relocating, unpacked code needs to be assembled to + start at 0x3FFE +unpack_x86_16_DOS_no_repeated_offset.asm: + removes support for repeated offsets, potentially at the cost of some compression ratio. + most likely only a win in very narrow circumstances around the 1kb mark \ No newline at end of file diff --git a/asm_unpackers/unpack_x86_16_DOS.asm b/dos_unpacker/unpack_x86_16_DOS.asm similarity index 100% rename from asm_unpackers/unpack_x86_16_DOS.asm rename to dos_unpacker/unpack_x86_16_DOS.asm diff --git a/asm_unpackers/unpack_x86_16_DOS_no_relocation.asm b/dos_unpacker/unpack_x86_16_DOS_no_relocation.asm similarity index 100% rename from asm_unpackers/unpack_x86_16_DOS_no_relocation.asm rename to dos_unpacker/unpack_x86_16_DOS_no_relocation.asm diff --git a/asm_unpackers/unpack_x86_16_DOS_no_repeated_offset.asm b/dos_unpacker/unpack_x86_16_DOS_no_repeated_offset.asm similarity index 100% rename from asm_unpackers/unpack_x86_16_DOS_no_repeated_offset.asm rename to dos_unpacker/unpack_x86_16_DOS_no_repeated_offset.asm