SmartAudio/lichee/linux-4.9/drivers/char/oases/inlinehook_subfunc_post.S

131 lines
3.0 KiB
ArmAsm
Executable File

#include "inlinehook_const.h"
#if defined(__aarch64__)
subfunc_post:
sub sp, sp, #0xa0
stp x29, x30, [sp]
mov x29, sp
stp x0, x1, [sp, #0x18]
stp x2, x3, [sp, #0x28]
stp x4, x5, [sp, #0x38]
stp x6, x7, [sp, #0x48]
ldr x16, orig_addr
blr x16
stp x0, x1, [sp, #0x58]
stp x2, x3, [sp, #0x68]
stp x4, x5, [sp, #0x78]
stp x6, x7, [sp, #0x88]
str x0, [x29, #0x10]
ldp x6, x7, [sp, #0x40]
ldp x4, x5, [sp, #0x30]
ldp x2, x3, [sp, #0x20]
ldp x0, x1, [sp, #0x10]
add x0, x29, #0x10
ldr x16, filter_addr
blr x16
cbz x0, not_attack_log
ldr x0, patch_info
ldr x1, attack_logger
blr x1
not_attack_log:
ldp x6, x7, [sp, #0x88]
ldp x4, x5, [sp, #0x78]
ldp x2, x3, [sp, #0x68]
ldp x0, x1, [sp, #0x58]
ldr x0, [x29, #0x10]
ldp x29, x30, [sp]
add sp, sp, #0xa0
ret
orig_addr:
.quad ORIGIN_ADDR_MAGIC
filter_addr:
.quad FILTER_ADDR_MAGIC
patch_info:
.quad PATCH_INFO_CTX_MAGIC
attack_logger:
.quad ATTACK_LOGGER_MAGIC
#elif defined(__arm__)
.arm
subfunc_post:
@ assume at most 4 args on stack
@ assume all argument size are within 32 bits
@ stack layout:
@ ret, padding, cpsr, r0-r11, lr, padding, args * 4, cpsr, r0-r11, lr, padding, args * 4, = 0xa0
sub sp, #0xa0 @ save state
add r12, sp, #0x94
stmfd r12, {r0-r11,lr}
mrs r12, cpsr
str r12, [sp, #0x94]
ldr r12, [sp, #0xa0] @ copy possible args
str r12, [sp, #0x4c]
str r12, [sp, #0]
ldr r12, [sp, #0xa4]
str r12, [sp, #0x50]
str r12, [sp, #4]
ldr r12, [sp, #0xa8]
str r12, [sp, #0x54]
str r12, [sp, #8]
ldr r12, [sp, #0xac]
str r12, [sp, #0x58]
str r12, [sp, #0xc]
ldr r12, [sp, #0xb0] @ padding can hold one more arg
str r12, [sp, #0x5c]
str r12, [sp, #0x10]
add r12, sp, #0x60 @ restore state
ldmfd r12, {r0-r11}
ldr r12, [sp, #0x94]
msr cpsr_c, r12 @ call original function
ldr r12, orig_addr
blx r12
add r12, sp, #0x48
stmfd r12, {r0-r11,lr} @ save state after calling
mrs r12, cpsr
str r12, [sp, #0x48]
str r0, [sp, #0x9c] @ save return value
ldr r12, [sp, #0x6c] @ move old r3 to stack
str r12, [sp, #0]
ldr r12, [sp, #0x4c] @ copy old args to stack
str r12, [sp, #4]
ldr r12, [sp, #0x50]
str r12, [sp, #8]
ldr r12, [sp, #0x54]
str r12, [sp, #0xc]
ldr r12, [sp, #0x58]
str r12, [sp, #0x10]
ldr r12, [sp, #0x5c]
str r12, [sp, #0x14]
add r0, sp, #0x9c
ldr r1, [sp, #0x60]
ldr r2, [sp, #0x64]
ldr r3, [sp, #0x68]
ldr r12, filter_addr @ call filter
blx r12
cmp r0, #0
beq not_attack_log
ldr r0, patch_info
ldr r1, attack_logger
blx r1
not_attack_log:
add r12, sp, #0x14
ldmfd r12, {r0-r11}
ldr r12, [sp, #0x48]
ldr r0, [sp, #0x9c]
ldr lr, [sp, #0x90]
add sp, #0xa0
msr cpsr_c, r12
bx lr
filter_addr:
.word FILTER_ADDR_MAGIC
orig_addr:
.word ORIGIN_ADDR_MAGIC
patch_info:
.word PATCH_INFO_CTX_MAGIC
attack_logger:
.word ATTACK_LOGGER_MAGIC
#endif