From a9550de75aaf8fa1cd4630657c9acbf5b0c667d4 Mon Sep 17 00:00:00 2001 From: Gregor Haas Date: Thu, 27 Feb 2020 16:14:05 -0500 Subject: [PATCH] Cleaned up headers --- .gitignore | 2 +- c8_remote/include/checkm8.h | 20 +++++++++++++++++-- .../include/{bootrom_addr.h => dev/addr.h} | 8 ++++---- .../include/{bootrom_type.h => dev/types.h} | 6 +++--- c8_remote/include/{ => tool}/command.h | 11 ---------- c8_remote/include/{ => tool}/payload.h | 0 c8_remote/include/{ => tool}/usb_helpers.h | 4 ---- c8_remote/include/{ => util}/experiments.h | 4 ++-- c8_remote/include/{ => util}/host_crypto.h | 2 +- c8_remote/lib/CMakeLists.txt | 2 +- c8_remote/lib/crypto/aes_sw_host.c | 2 +- c8_remote/lib/crypto/aes_sw_impl.c | 2 +- c8_remote/lib/experiments/aes_sw.c | 9 ++++----- c8_remote/lib/experiments/power.c | 5 ++--- c8_remote/lib/experiments/system.c | 6 ++---- c8_remote/lib/payload/include/bootrom_func.h | 4 ++-- .../include/{cacheutil.h => dev_cache.h} | 6 +++--- c8_remote/lib/payload/include/dev_crypto.h | 2 +- c8_remote/lib/payload/payload_entry.c | 2 +- c8_remote/lib/payload/src/aes_sw_bern.c | 4 ++-- c8_remote/lib/payload/src/cachelib.c | 2 +- c8_remote/lib/payload/src/exit_usb_task.c | 2 +- c8_remote/main.c | 11 +++------- c8_remote/src/command.c | 4 ++-- c8_remote/src/exploit.c | 6 +++--- c8_remote/src/payload.c | 9 ++++----- c8_remote/src/usb_helpers.c | 2 +- 27 files changed, 64 insertions(+), 73 deletions(-) rename c8_remote/include/{bootrom_addr.h => dev/addr.h} (93%) rename c8_remote/include/{bootrom_type.h => dev/types.h} (86%) rename c8_remote/include/{ => tool}/command.h (78%) rename c8_remote/include/{ => tool}/payload.h (100%) rename c8_remote/include/{ => tool}/usb_helpers.h (92%) rename c8_remote/include/{ => util}/experiments.h (92%) rename c8_remote/include/{ => util}/host_crypto.h (94%) rename c8_remote/lib/payload/include/{cacheutil.h => dev_cache.h} (93%) diff --git a/.gitignore b/.gitignore index f281ac5..c4c2a7e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ cmake-build-debug/ /c8_arduino/cmake-build-debug/ # generated files -/c8_remote/include/libpayload.h \ No newline at end of file +/c8_remote/include/tool/libpayload.h \ No newline at end of file diff --git a/c8_remote/include/checkm8.h b/c8_remote/include/checkm8.h index 7e69b24..62d619e 100644 --- a/c8_remote/include/checkm8.h +++ b/c8_remote/include/checkm8.h @@ -46,9 +46,25 @@ struct pwned_device #endif }; +struct dev_cmd_resp +{ + int ret; + unsigned long long magic; + unsigned long long retval; + unsigned char *data; + int len; +}; + struct pwned_device *exploit_device(); -int demote_device(struct pwned_device *dev); -int fix_heap(struct pwned_device *dev); void free_device(struct pwned_device *dev); +int demote_device(struct pwned_device *dev); +int fix_heap(struct pwned_device *dev); + +int open_device_session(struct pwned_device *dev); +int close_device_session(struct pwned_device *dev); +int is_device_session_open(struct pwned_device *dev); + +void free_dev_cmd_resp(struct dev_cmd_resp *resp); + #endif //CHECKM8_TOOL_CHECKM8_H diff --git a/c8_remote/include/bootrom_addr.h b/c8_remote/include/dev/addr.h similarity index 93% rename from c8_remote/include/bootrom_addr.h rename to c8_remote/include/dev/addr.h index 6f4ec0c..5cf9f8c 100644 --- a/c8_remote/include/bootrom_addr.h +++ b/c8_remote/include/dev/addr.h @@ -1,8 +1,8 @@ -#ifndef CHECKM8_TOOL_BOOTROM_ADDR_H -#define CHECKM8_TOOL_BOOTROM_ADDR_H +#ifndef CHECKM8_TOOL_ADDR_H +#define CHECKM8_TOOL_ADDR_H #include "checkm8_config.h" -#include "bootrom_type.h" +#include "types.h" #if CHECKM8_PLATFORM == 8010 @@ -53,4 +53,4 @@ #error "Unsupported checkm8 platform" #endif -#endif //CHECKM8_TOOL_BOOTROM_ADDR_H +#endif //CHECKM8_TOOL_ADDR_H diff --git a/c8_remote/include/bootrom_type.h b/c8_remote/include/dev/types.h similarity index 86% rename from c8_remote/include/bootrom_type.h rename to c8_remote/include/dev/types.h index 7bbf3dc..d371813 100644 --- a/c8_remote/include/bootrom_type.h +++ b/c8_remote/include/dev/types.h @@ -1,5 +1,5 @@ -#ifndef CHECKM8_TOOL_BOOTROM_TYPE_H -#define CHECKM8_TOOL_BOOTROM_TYPE_H +#ifndef CHECKM8_TOOL_TYPES_H +#define CHECKM8_TOOL_TYPES_H struct event { @@ -41,4 +41,4 @@ struct corr_data unsigned char data[N_CORR_ENTRIES]; }; -#endif //CHECKM8_TOOL_BOOTROM_TYPE_H +#endif //CHECKM8_TOOL_TYPES_H diff --git a/c8_remote/include/command.h b/c8_remote/include/tool/command.h similarity index 78% rename from c8_remote/include/command.h rename to c8_remote/include/tool/command.h index 4a4dbaf..7756e72 100644 --- a/c8_remote/include/command.h +++ b/c8_remote/include/tool/command.h @@ -5,15 +5,6 @@ #define CMD_USB_READ_LIMIT 0xFF0 -struct dev_cmd_resp -{ - int ret; - unsigned long long magic; - unsigned long long retval; - unsigned char *data; - int len; -}; - struct dev_cmd_resp *dev_memset(struct pwned_device *dev, unsigned long long addr, unsigned char c, int len); struct dev_cmd_resp *dev_memcpy(struct pwned_device *dev, unsigned long long dest, unsigned long long src, int len); struct dev_cmd_resp *dev_exec(struct pwned_device *dev, int response_len, int nargs, unsigned long long *args); @@ -21,6 +12,4 @@ struct dev_cmd_resp *dev_exec(struct pwned_device *dev, int response_len, int na struct dev_cmd_resp *dev_read_memory(struct pwned_device *dev, unsigned long long addr, int len); struct dev_cmd_resp *dev_write_memory(struct pwned_device *dev, unsigned long long addr, unsigned char *data, int len); -void free_dev_cmd_resp(struct dev_cmd_resp *resp); - #endif //CHECKM8_TOOL_COMMAND_H diff --git a/c8_remote/include/payload.h b/c8_remote/include/tool/payload.h similarity index 100% rename from c8_remote/include/payload.h rename to c8_remote/include/tool/payload.h diff --git a/c8_remote/include/usb_helpers.h b/c8_remote/include/tool/usb_helpers.h similarity index 92% rename from c8_remote/include/usb_helpers.h rename to c8_remote/include/tool/usb_helpers.h index 841600c..b3df825 100644 --- a/c8_remote/include/usb_helpers.h +++ b/c8_remote/include/tool/usb_helpers.h @@ -15,10 +15,6 @@ struct libusb_device_bundle }; #endif -int open_device_session(struct pwned_device *dev); -int close_device_session(struct pwned_device *dev); -int is_device_session_open(struct pwned_device *dev); - int partial_ctrl_transfer(struct pwned_device *dev, unsigned char bmRequestType, unsigned char bRequest, unsigned short wValue, unsigned short wIndex, diff --git a/c8_remote/include/experiments.h b/c8_remote/include/util/experiments.h similarity index 92% rename from c8_remote/include/experiments.h rename to c8_remote/include/util/experiments.h index 72e206a..4f2bf35 100644 --- a/c8_remote/include/experiments.h +++ b/c8_remote/include/util/experiments.h @@ -1,8 +1,8 @@ #ifndef CHECKM8_TOOL_EXPERIMENTS_H #define CHECKM8_TOOL_EXPERIMENTS_H -#include "payload.h" -#include "bootrom_type.h" +#include "tool/payload.h" +#include "dev/types.h" /* AES Software */ DEV_PTR_T setup_bern_exp(struct pwned_device *dev); diff --git a/c8_remote/include/host_crypto.h b/c8_remote/include/util/host_crypto.h similarity index 94% rename from c8_remote/include/host_crypto.h rename to c8_remote/include/util/host_crypto.h index f475417..c78b214 100644 --- a/c8_remote/include/host_crypto.h +++ b/c8_remote/include/util/host_crypto.h @@ -1,7 +1,7 @@ #ifndef CHECKM8_TOOL_HOST_CRYPTO_H #define CHECKM8_TOOL_HOST_CRYPTO_H -#include "bootrom_type.h" +#include "dev/types.h" void expand_key(unsigned char key[16], unsigned char key_sched[176], int n, struct aes_constants *c); diff --git a/c8_remote/lib/CMakeLists.txt b/c8_remote/lib/CMakeLists.txt index fbbb94a..13c07c1 100644 --- a/c8_remote/lib/CMakeLists.txt +++ b/c8_remote/lib/CMakeLists.txt @@ -37,7 +37,7 @@ add_custom_command(TARGET payload POST_BUILD BYPRODUCTS ${CMAKE_SOURCE_DIR}/c8_remote/include/libpayload.h COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/scripts/headerize.py ${CMAKE_CURRENT_BINARY_DIR}/lib_cfiles - ${CMAKE_SOURCE_DIR}/c8_remote/include) + ${CMAKE_SOURCE_DIR}/c8_remote/include/tool) add_library(experiments experiments/aes_sw.c experiments/system.c diff --git a/c8_remote/lib/crypto/aes_sw_host.c b/c8_remote/lib/crypto/aes_sw_host.c index 4caa57e..31ebf2f 100644 --- a/c8_remote/lib/crypto/aes_sw_host.c +++ b/c8_remote/lib/crypto/aes_sw_host.c @@ -1,7 +1,7 @@ #include #include -#include "bootrom_type.h" +#include "dev/types.h" static const unsigned char sbox[256] = { diff --git a/c8_remote/lib/crypto/aes_sw_impl.c b/c8_remote/lib/crypto/aes_sw_impl.c index d001940..2471ca3 100644 --- a/c8_remote/lib/crypto/aes_sw_impl.c +++ b/c8_remote/lib/crypto/aes_sw_impl.c @@ -1,4 +1,4 @@ -#include "bootrom_type.h" +#include "dev/types.h" #ifdef DEV_CRYPTO #include "dev_util.h" diff --git a/c8_remote/lib/experiments/aes_sw.c b/c8_remote/lib/experiments/aes_sw.c index 3ba1cbf..a3a4118 100644 --- a/c8_remote/lib/experiments/aes_sw.c +++ b/c8_remote/lib/experiments/aes_sw.c @@ -1,14 +1,13 @@ -#include "experiments.h" +#include "util/experiments.h" #include #include #include #include -#include "bootrom_addr.h" -#include "usb_helpers.h" -#include "command.h" -#include "host_crypto.h" +#include "dev/addr.h" +#include "tool/command.h" +#include "util/host_crypto.h" DEV_PTR_T install_aes_data(struct pwned_device *dev) { diff --git a/c8_remote/lib/experiments/power.c b/c8_remote/lib/experiments/power.c index 39bdd6e..319bd35 100644 --- a/c8_remote/lib/experiments/power.c +++ b/c8_remote/lib/experiments/power.c @@ -1,8 +1,7 @@ -#include "experiments.h" +#include "util/experiments.h" #include -#include "usb_helpers.h" -#include "command.h" +#include "tool/payload.h" void floppysleep(struct pwned_device *dev) { diff --git a/c8_remote/lib/experiments/system.c b/c8_remote/lib/experiments/system.c index 48be147..0855cc6 100644 --- a/c8_remote/lib/experiments/system.c +++ b/c8_remote/lib/experiments/system.c @@ -1,9 +1,7 @@ -#include "experiments.h" +#include "util/experiments.h" #include - -#include "usb_helpers.h" -#include "command.h" +#include "tool/command.h" void usb_task_exit(struct pwned_device *dev) { diff --git a/c8_remote/lib/payload/include/bootrom_func.h b/c8_remote/lib/payload/include/bootrom_func.h index 1e249c3..f07c673 100644 --- a/c8_remote/lib/payload/include/bootrom_func.h +++ b/c8_remote/lib/payload/include/bootrom_func.h @@ -1,8 +1,8 @@ #ifndef CHECKM8_TOOL_BOOTROM_FUNC_H #define CHECKM8_TOOL_BOOTROM_FUNC_H -#include "bootrom_addr.h" -#include "bootrom_type.h" +#include "dev/addr.h" +#include "dev/types.h" #include "dev_util.h" /* Crypto */ diff --git a/c8_remote/lib/payload/include/cacheutil.h b/c8_remote/lib/payload/include/dev_cache.h similarity index 93% rename from c8_remote/lib/payload/include/cacheutil.h rename to c8_remote/lib/payload/include/dev_cache.h index 363eb54..6a3638b 100644 --- a/c8_remote/lib/payload/include/cacheutil.h +++ b/c8_remote/lib/payload/include/dev_cache.h @@ -1,5 +1,5 @@ -#ifndef CHECKM8_TOOL_CACHEUTIL_H -#define CHECKM8_TOOL_CACHEUTIL_H +#ifndef CHECKM8_TOOL_DEV_CACHE_H +#define CHECKM8_TOOL_DEV_CACHE_H #include "dev_util.h" @@ -59,4 +59,4 @@ static inline void clean_inv_va(void *addr) __asm__ volatile ("dc ivac, %0"::"r" (addr)); } -#endif //CHECKM8_TOOL_CACHEUTIL_H +#endif //CHECKM8_TOOL_DEV_CACHE_H diff --git a/c8_remote/lib/payload/include/dev_crypto.h b/c8_remote/lib/payload/include/dev_crypto.h index 936febe..1daef7e 100644 --- a/c8_remote/lib/payload/include/dev_crypto.h +++ b/c8_remote/lib/payload/include/dev_crypto.h @@ -1,7 +1,7 @@ #ifndef CHECKM8_TOOL_CRYPTO_H #define CHECKM8_TOOL_CRYPTO_H -#include "bootrom_type.h" +#include "dev/types.h" void expand_key(unsigned char key[16], unsigned char key_sched[176], int n, struct aes_constants *c); diff --git a/c8_remote/lib/payload/payload_entry.c b/c8_remote/lib/payload/payload_entry.c index cd9c2f1..9685f22 100644 --- a/c8_remote/lib/payload/payload_entry.c +++ b/c8_remote/lib/payload/payload_entry.c @@ -1,5 +1,5 @@ #include "dev_util.h" -#include "bootrom_addr.h" +#include "dev/addr.h" PAYLOAD_SECTION void load_sync_entry() diff --git a/c8_remote/lib/payload/src/aes_sw_bern.c b/c8_remote/lib/payload/src/aes_sw_bern.c index 2639a58..cffdf52 100644 --- a/c8_remote/lib/payload/src/aes_sw_bern.c +++ b/c8_remote/lib/payload/src/aes_sw_bern.c @@ -1,6 +1,6 @@ #include "bootrom_func.h" -#include "bootrom_type.h" -#include "cacheutil.h" +#include "dev/types.h" +#include "dev_cache.h" #include "dev_crypto.h" PAYLOAD_SECTION diff --git a/c8_remote/lib/payload/src/cachelib.c b/c8_remote/lib/payload/src/cachelib.c index 35e4735..a14d899 100644 --- a/c8_remote/lib/payload/src/cachelib.c +++ b/c8_remote/lib/payload/src/cachelib.c @@ -1,5 +1,5 @@ #include "bootrom_func.h" -#include "cacheutil.h" +#include "dev_cache.h" PAYLOAD_SECTION diff --git a/c8_remote/lib/payload/src/exit_usb_task.c b/c8_remote/lib/payload/src/exit_usb_task.c index f9f5a6a..66e8d91 100644 --- a/c8_remote/lib/payload/src/exit_usb_task.c +++ b/c8_remote/lib/payload/src/exit_usb_task.c @@ -1,4 +1,4 @@ -#include "bootrom_addr.h" +#include "dev/addr.h" #include "bootrom_func.h" PAYLOAD_SECTION diff --git a/c8_remote/main.c b/c8_remote/main.c index 1824bd3..7e6c55d 100644 --- a/c8_remote/main.c +++ b/c8_remote/main.c @@ -4,19 +4,14 @@ #include #include #include -#include -#include "payload.h" -#include "usb_helpers.h" -#include "bootrom_type.h" -#include "experiments.h" -#include "host_crypto.h" +#include "dev/types.h" +#include "util/experiments.h" +#include "util/host_crypto.h" #ifdef CHECKM8_LOGGING - #include #include - #endif void checkm8_debug_indent(const char *format, ...) diff --git a/c8_remote/src/command.c b/c8_remote/src/command.c index 66f3c7f..0595a3e 100644 --- a/c8_remote/src/command.c +++ b/c8_remote/src/command.c @@ -1,7 +1,7 @@ -#include "command.h" +#include "tool/command.h" #include "checkm8.h" -#include "usb_helpers.h" +#include "tool/usb_helpers.h" #include #include diff --git a/c8_remote/src/exploit.c b/c8_remote/src/exploit.c index ce1d05f..7db4548 100644 --- a/c8_remote/src/exploit.c +++ b/c8_remote/src/exploit.c @@ -5,9 +5,9 @@ #include #include -#include "usb_helpers.h" -#include "command.h" -#include "bootrom_addr.h" +#include "tool/usb_helpers.h" +#include "tool/command.h" +#include "dev/addr.h" static unsigned char data_0xA_0xC0_buf[192] = { diff --git a/c8_remote/src/payload.c b/c8_remote/src/payload.c index 6eb0f4d..482852f 100644 --- a/c8_remote/src/payload.c +++ b/c8_remote/src/payload.c @@ -1,14 +1,13 @@ -#include "payload.h" +#include "tool/payload.h" #include #include #include -#include "command.h" -#include "usb_helpers.h" +#include "tool/command.h" +#include "tool/libpayload.h" -#include "bootrom_addr.h" -#include "libpayload.h" +#include "dev/addr.h" struct payload { diff --git a/c8_remote/src/usb_helpers.c b/c8_remote/src/usb_helpers.c index fb70697..cd2a331 100644 --- a/c8_remote/src/usb_helpers.c +++ b/c8_remote/src/usb_helpers.c @@ -1,4 +1,4 @@ -#include "usb_helpers.h" +#include "tool/usb_helpers.h" #ifdef WITH_ARDUINO