mirror of
https://github.com/exoticorn/upkr.git
synced 2026-01-20 11:36:42 +01:00
first version of arm32 unpacker: 240 bytes
This commit is contained in:
@@ -39,6 +39,19 @@ build/unpack_armv6m.bin: unpack_armv6m.S
|
|||||||
arm-none-eabi-gcc -march=armv6-m -c -o build/unpack_armv6m.o $?
|
arm-none-eabi-gcc -march=armv6-m -c -o build/unpack_armv6m.o $?
|
||||||
arm-none-eabi-objcopy -O binary --only-section=.text build/unpack_armv6m.o $@
|
arm-none-eabi-objcopy -O binary --only-section=.text build/unpack_armv6m.o $@
|
||||||
|
|
||||||
|
build/unpack_arm32: ../c_unpacker/main.c unpack_arm32.S
|
||||||
|
mkdir -p build
|
||||||
|
arm-linux-gnueabihf-gcc -g -static -o $@ $^
|
||||||
|
|
||||||
|
test_arm32: build/unpack_arm32
|
||||||
|
qemu-arm $< test_data.upk /tmp/out.bin
|
||||||
|
cmp test_data.bin /tmp/out.bin
|
||||||
|
|
||||||
|
build/unpack_arm32.bin: unpack_arm32.S
|
||||||
|
mkdir -p build
|
||||||
|
arm-none-eabi-gcc -c -o build/unpack_arm32.o $?
|
||||||
|
arm-none-eabi-objcopy -O binary --only-section=.text build/unpack_arm32.o $@
|
||||||
|
|
||||||
build/unpack_c: ../c_unpacker/main.c ../c_unpacker/unpack.c
|
build/unpack_c: ../c_unpacker/main.c ../c_unpacker/unpack.c
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
gcc -g -o $@ $^
|
gcc -g -o $@ $^
|
||||||
@@ -47,5 +60,5 @@ test_c: build/unpack_c
|
|||||||
$< test_data.upk /tmp/out.bin
|
$< test_data.upk /tmp/out.bin
|
||||||
cmp test_data.bin /tmp/out.bin
|
cmp test_data.bin /tmp/out.bin
|
||||||
|
|
||||||
sizes: build/unpack_armv6m.bin build/unpack_riscv64.bin build/unpack_riscv32.bin
|
sizes: build/unpack_armv6m.bin build/unpack_riscv64.bin build/unpack_riscv32.bin build/unpack_arm32.bin
|
||||||
ls -l build/*.bin
|
ls -l build/*.bin
|
||||||
106
asm_unpackers/unpack_arm32.S
Normal file
106
asm_unpackers/unpack_arm32.S
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
.arm
|
||||||
|
|
||||||
|
.section .text
|
||||||
|
|
||||||
|
.global upkr_unpack
|
||||||
|
.type upkr_unpack, %function
|
||||||
|
// r0 .. out_ptr (returned)
|
||||||
|
// r1 .. in_ptr (returned)
|
||||||
|
// r2 .. state
|
||||||
|
// r3 .. offset
|
||||||
|
// r4 .. prev_was_literal / decode_length ret
|
||||||
|
// r5 .. context index
|
||||||
|
// r6 .. decode_length temp
|
||||||
|
// r7 .. probs ptr
|
||||||
|
// r8-r11 .. decode_bit temp
|
||||||
|
// r12 .. decode_length return address
|
||||||
|
upkr_unpack:
|
||||||
|
push { r3-r11, lr }
|
||||||
|
|
||||||
|
mov r2, #384
|
||||||
|
movs r3, #128
|
||||||
|
.Lclear:
|
||||||
|
subs r2, r2, #1
|
||||||
|
strb r3, [sp, -r2]
|
||||||
|
bne .Lclear
|
||||||
|
|
||||||
|
.Lloop:
|
||||||
|
movs r5, #0
|
||||||
|
bl upkr_decode_bit
|
||||||
|
bcc .Ldata
|
||||||
|
.Lmatch:
|
||||||
|
mov r5, #256
|
||||||
|
cmp r4, #0
|
||||||
|
beq 1f
|
||||||
|
|
||||||
|
bl upkr_decode_bit
|
||||||
|
bcc 2f
|
||||||
|
|
||||||
|
1:
|
||||||
|
bl upkr_decode_length
|
||||||
|
subs r3, r4, #1
|
||||||
|
popeq { r3-r11, pc }
|
||||||
|
2:
|
||||||
|
|
||||||
|
mov r5, #256+64
|
||||||
|
bl upkr_decode_length
|
||||||
|
.Lcopy_loop:
|
||||||
|
ldrb r5, [r0, -r3]
|
||||||
|
.Lstore:
|
||||||
|
strb r5, [r0], #1
|
||||||
|
subs r4, r4, #1
|
||||||
|
bgt .Lcopy_loop
|
||||||
|
b .Lloop
|
||||||
|
|
||||||
|
.Ldata:
|
||||||
|
movs r5, #1
|
||||||
|
|
||||||
|
.Ldata_loop:
|
||||||
|
bl upkr_decode_bit
|
||||||
|
adcs r5, r5, r5
|
||||||
|
rsbs r4, r5, #256
|
||||||
|
bgt .Ldata_loop
|
||||||
|
b .Lstore
|
||||||
|
|
||||||
|
.type upkr_decode_length, %function
|
||||||
|
upkr_decode_length:
|
||||||
|
mov r12, lr
|
||||||
|
|
||||||
|
movs r6, #0
|
||||||
|
mov r4, #1
|
||||||
|
.Lbit_loop:
|
||||||
|
adds r5, r5, #1
|
||||||
|
bl upkr_decode_bit
|
||||||
|
addcc r4, r4, r6
|
||||||
|
movcc pc, r12
|
||||||
|
|
||||||
|
adds r5, r5, #1
|
||||||
|
bl upkr_decode_bit
|
||||||
|
addcs r6, r6, r4
|
||||||
|
lsls r4, r4, #1
|
||||||
|
b .Lbit_loop
|
||||||
|
|
||||||
|
.type upkr_decode_bit, %function
|
||||||
|
upkr_fill_state:
|
||||||
|
ldrb r8, [r1], #1
|
||||||
|
orr r2, r8, r2, lsl #8
|
||||||
|
|
||||||
|
upkr_decode_bit:
|
||||||
|
cmp r2, #4096
|
||||||
|
blt upkr_fill_state
|
||||||
|
|
||||||
|
ldrb r8, [sp, -r5]
|
||||||
|
and r9, r2, #255
|
||||||
|
add r9, r9, #1
|
||||||
|
cmp r8, r9
|
||||||
|
rsbcs r8, r8, #256
|
||||||
|
mov r9, r2, lsr#8
|
||||||
|
addcc r9, r9, #1
|
||||||
|
mul r9, r8, r9
|
||||||
|
sub r2, r2, r9
|
||||||
|
add r9, r8, #8
|
||||||
|
sub r8, r8, r9, lsr#4
|
||||||
|
rsbcs r8, r8, #256
|
||||||
|
strb r8, [sp, -r5]
|
||||||
|
mov pc, r14
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ upkr_decode_bit:
|
|||||||
addi x14, x14, 1
|
addi x14, x14, 1
|
||||||
|
|
||||||
sub t2, sp, x14
|
sub t2, sp, x14
|
||||||
lbu x12, 0(t2)
|
lbu x12, (t2)
|
||||||
|
|
||||||
andi x8, x13, 255
|
andi x8, x13, 255
|
||||||
sltu x15, x8, x12
|
sltu x15, x8, x12
|
||||||
@@ -104,7 +104,7 @@ upkr_decode_bit:
|
|||||||
sub x12, x0, x12
|
sub x12, x0, x12
|
||||||
1:
|
1:
|
||||||
|
|
||||||
sb x12, 0(t2)
|
sb x12, (t2)
|
||||||
|
|
||||||
jalr ra
|
jalr ra
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user