Skip to content

Commit

Permalink
adtg2log: add hook for RP
Browse files Browse the repository at this point in the history
  • Loading branch information
coon42 committed Jan 4, 2025
1 parent 72efeb0 commit bf50a28
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/dev_tools/adtglog2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MODULE_NAME = adtglog2
MODULE_OBJS = $(BUILD_DIR)/adtglog2.o \
$(BUILD_DIR)/hooks_thumb_200D.o \
$(BUILD_DIR)/hooks_thumb_6D2.o \
$(BUILD_DIR)/hooks_thumb_RP.o \
$(BUILD_DIR)/hooks_arm_70D.o
TOP_DIR = ../../..

Expand All @@ -22,5 +23,8 @@ $(BUILD_DIR)/hooks_thumb_200D.o: hooks_thumb_200D.c
$(BUILD_DIR)/hooks_thumb_6D2.o: hooks_thumb_6D2.c
$(CC) $(CFLAGS_ARCHLESS) -mthumb -march=armv7 $(CDEPS_FLAGS) -c -o $@ $<

$(BUILD_DIR)/hooks_thumb_RP.o: hooks_thumb_RP.c
$(CC) $(CFLAGS_ARCHLESS) -mthumb -march=armv7 $(CDEPS_FLAGS) -c -o $@ $<

$(BUILD_DIR)/hooks_arm_70D.o: hooks_arm_70D.c
$(CC) $(CFLAGS) $(CDEPS_FLAGS) -c -o $@ $<
29 changes: 29 additions & 0 deletions modules/dev_tools/adtglog2/adtglog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,35 @@ static unsigned int init()
}
apply_patches(patches, COUNT(f_patches));
}
else if (is_camera("RP", "1.6.0"))
{
buf_item_size = 32;

// install hooks
struct function_hook_patch f_patches[] = {
{
.patch_addr = 0xe067b7e0, // CMOS_write
.orig_content = {0x2d, 0xe9, 0xfc, 0x5f, 0x04, 0x46, 0x9b, 0x4e},
.target_function_addr = (uint32_t)hook_CMOS_write_RP,
.description = "Log ADTG CMOS writes"
},
};

struct patch patches[COUNT(f_patches)] = {};
uint8_t code_hooks[8 * COUNT(f_patches)] = {};

for (int i = 0; i < COUNT(f_patches); i++)
{
if (convert_f_patch_to_patch(&f_patches[i],
&patches[i],
&code_hooks[8 * i]))
{
return 1;
}
}
apply_patches(patches, COUNT(f_patches));
}

else if (is_camera("70D", "1.1.2"))
{
buf_item_size = 16;
Expand Down
1 change: 1 addition & 0 deletions modules/dev_tools/adtglog2/hooks_thumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
// one instruction in Thumb, so it's harder to be as generic as the ARM hook code.
void __attribute__((noreturn,noinline,naked,aligned(4)))hook_CMOS_write_200D(void);
void __attribute__((noreturn,noinline,naked,aligned(4)))hook_CMOS_write_6D2(void);
void __attribute__((noreturn,noinline,naked,aligned(4)))hook_CMOS_write_RP(void);

#endif
34 changes: 34 additions & 0 deletions modules/dev_tools/adtglog2/hooks_thumb_RP.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "adtglog2.h"
#include "hooks_thumb.h"
#include "dryos.h"
#include "log.h"

// ADTG logging

void __attribute__((noreturn,noinline,naked,aligned(4)))hook_CMOS_write_RP(void)
{
asm(
"push { r2-r12, lr }\n"
);

uint32_t *cmos_buf;
uint32_t lr;
asm __volatile__ (
"mov %0, r0\n"
"mov %1, lr\n" : "=&r"(cmos_buf), "=&r"(lr)
);

log_cmos_command_buffer(cmos_buf, lr);

asm(
"pop { r2-r12, lr }\n"

// do overwritten instructions
"push {r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}\n"
"mov r4, r0\n"
"ldr r6, =0x6b9c4\n"

// jump back
"ldr pc, =0xe067b7e9\n"
);
}

0 comments on commit bf50a28

Please sign in to comment.