diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 84b8a4d5..a5c38a16 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,6 +1,6 @@ { "env": { - "BOLOS_SDK": "~/.ledger/sdk", + "BOLOS_SDK": "~/.ledger/nanos-sdk", "ARM_GCC": "~/.ledger/gcc-arm-none-eabi-13.2-2023.10" }, "configurations": [ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..79469d37 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "gdb", + "request": "attach", + "name": "Attach to gdbserver", + "executable": "${workspaceFolder}/bin/app.elf", + "target": ":1234", + "remote": true, + "cwd": "${workspaceFolder}", + "valuesFormatting": "parseText", + "gdbpath": "gdb-multiarch", + "autorun": [ + "set substitute-path /project ${workspaceFolder}", + "set architecture arm", + "set backtrace limit 15", + "handle SIGILL nostop pass noprint", + "add-symbol-file ${workspaceFolder}/bin/app.elf 0x40000000", + "b *0x40000000" + ] + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 8efc96bb..003de6cf 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,9 @@ VARIANT_VALUES = ERGO # Enabling DEBUG flag will enable PRINTF and disable optimizations #DEBUG = 1 +# Enabling stack canary +HAVE_BOLOS_APP_STACK_CANARY = 1 + ######################################## # Application custom permissions # ######################################## diff --git a/src/app_main.c b/src/app_main.c index da27a0d0..8acb7405 100644 --- a/src/app_main.c +++ b/src/app_main.c @@ -62,6 +62,15 @@ void app_main() { continue; } + PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n", + cmd.cla, + cmd.ins, + cmd.p1, + cmd.p2, + cmd.lc, + cmd.lc, + cmd.data); + // Dispatch structured APDU command to handler if (apdu_dispatcher(&cmd) < 0) { PRINTF("=> apdu_dispatcher failure\n"); diff --git a/src/common/rwbuffer.c b/src/common/rwbuffer.c index 008b5a94..686efe9a 100644 --- a/src/common/rwbuffer.c +++ b/src/common/rwbuffer.c @@ -64,9 +64,9 @@ bool rw_buffer_write_u32(rw_buffer_t *buffer, uint32_t value, endianness_t endia } if (endianness == BE) { - write_u32_be((uint8_t *) buffer->read.ptr, buffer->size, value); + write_u32_be((uint8_t *) buffer->read.ptr, buffer->read.size, value); } else { - write_u32_le((uint8_t *) buffer->read.ptr, buffer->size, value); + write_u32_le((uint8_t *) buffer->read.ptr, buffer->read.size, value); } rw_buffer_seek_write_cur(buffer, 4); @@ -80,9 +80,9 @@ bool rw_buffer_write_u64(rw_buffer_t *buffer, uint64_t value, endianness_t endia } if (endianness == BE) { - write_u64_be((uint8_t *) buffer->read.ptr, buffer->size, value); + write_u64_be((uint8_t *) buffer->read.ptr, buffer->read.size, value); } else { - write_u64_le((uint8_t *) buffer->read.ptr, buffer->size, value); + write_u64_le((uint8_t *) buffer->read.ptr, buffer->read.size, value); } rw_buffer_seek_write_cur(buffer, 8); @@ -95,7 +95,7 @@ bool rw_buffer_write_bytes(rw_buffer_t *buffer, const uint8_t *from, size_t from return false; } - memmove((uint8_t *) buffer->read.ptr + buffer->size, from, from_len); + memmove(rw_buffer_write_ptr(buffer), from, from_len); rw_buffer_seek_write_cur(buffer, from_len); @@ -103,9 +103,9 @@ bool rw_buffer_write_bytes(rw_buffer_t *buffer, const uint8_t *from, size_t from } void rw_buffer_shift_data(rw_buffer_t *buffer) { - if (buffer->read.offset == 0) return; + if (rw_buffer_read_position(buffer) == 0) return; size_t data_len = rw_buffer_data_len(buffer); - memmove((uint8_t *) buffer->read.ptr, buffer->read.ptr + buffer->read.offset, data_len); - buffer->read.size = data_len; - buffer->read.offset = 0; + memmove((uint8_t *) buffer->read.ptr, rw_buffer_read_ptr(buffer), data_len); + rw_buffer_seek_read_set(buffer, 0); + rw_buffer_seek_write_set(buffer, data_len); }