Skip to content

Commit

Permalink
add coolscan-memory-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
kosma committed Nov 13, 2022
1 parent e739972 commit 742a906
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion coolscan-updater/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*.dylib

# Executables
*.exe
#*.exe
*.out
*.app
*.i*86
Expand Down
1 change: 1 addition & 0 deletions coolscan-updater/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ project(coolscan_updater C)
set(CMAKE_C_STANDARD 99)

add_executable(coolscan-updater src/coolscan-updater.c src/coolscan_transport_winapi_usb.c src/coolscan_buffer.c src/coolscan_command.c src/coolscan_updatefile.c)
add_executable(coolscan-memory-dump src/coolscan-memory-dump.c src/coolscan_transport_winapi_usb.c src/coolscan_buffer.c src/coolscan_command.c)
Binary file added coolscan-updater/coolscan-memory-dump.exe
Binary file not shown.
43 changes: 43 additions & 0 deletions coolscan-updater/src/coolscan-memory-dump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <unistd.h>
#include <conio.h>

#include "coolscan_command.h"
#include "coolscan_transport.h"
#include "coolscan_updatefile.h"

void press_any_key_to_continue(void)
{
printf("Press any key to continue...\n");
_getch();
}

int main() {
atexit(press_any_key_to_continue);

printf("***************************************\n");
printf("* Nikon Memory Dumper by Kosma Moczek *\n");
printf("***************************************\n");

coolscan_connection scanner = coolscan_scanner_open();
const char *model = coolscan_scanner_get_model(scanner);

printf("Checking scanner...\n");
printf("...scanner says it's a %s\n", coolscan_command_inquiry(scanner));

const size_t memory_dump_addr = 0xFFFFC0;
const size_t memory_dump_last = 0xFFFFDF;
const size_t memory_dump_size = memory_dump_last - memory_dump_addr + 1;
struct coolscan_buffer memory_dump_buffer = {
.length = memory_dump_size,
.data = malloc(memory_dump_size),
};
printf("Reading memory at 0x%06x to 0x%06x...\n", memory_dump_addr, memory_dump_last);
coolscan_command_read_buffer(scanner, 2, 0, memory_dump_addr, &memory_dump_buffer);
coolscan_buffer_dump_long("I/O Registers", &memory_dump_buffer);

coolscan_scanner_close(scanner);
printf("Finished.\n");

return 0;
}
20 changes: 20 additions & 0 deletions coolscan-updater/src/coolscan_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
#include <stdio.h>


#define COLUMN_SIZE 8


void coolscan_buffer_dump(const char *label, const struct coolscan_buffer *buffer) {
printf("%s:", label);

for (int i=0; i<buffer->length; i++) {
printf(" %02x", buffer->data[i]);
}

printf("\n");
}

void coolscan_buffer_dump_long(const char *label, const struct coolscan_buffer *buffer)
{
printf("%s:\n", label);

for (int i=0; i<buffer->length; i++) {
if ((i % COLUMN_SIZE) == 0) {
printf("%04x:", i);
}
printf(" %02x", buffer->data[i]);
if (((i+1) % COLUMN_SIZE) == 0) {
printf("\n");
}
}

printf("\n");
}
2 changes: 2 additions & 0 deletions coolscan-updater/src/coolscan_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ struct coolscan_buffer

void coolscan_buffer_dump(const char *label, const struct coolscan_buffer *buffer);

void coolscan_buffer_dump_long(const char *label, const struct coolscan_buffer *buffer);

#endif // COOLSCAN_UPDATER_COOLSCAN_BUFFER_H
19 changes: 19 additions & 0 deletions coolscan-updater/src/coolscan_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,22 @@ void coolscan_command_firmware_update_execute(coolscan_connection scanner)
};
coolscan_scanner_exchange(scanner, &cmd, NULL, NULL, NULL);
}

void coolscan_command_read_buffer(coolscan_connection scanner, uint8_t mode, uint8_t buffer_id, uint32_t address, struct coolscan_buffer *buffer)
{
struct coolscan_buffer cmd = {
10, (uint8_t []){
0x3C, // READ BUFFER
mode,
buffer_id,
(address >> 16) & 0xFF,
(address >> 8) & 0xFF,
(address >> 0) & 0xFF,
(buffer->length >> 16) & 0xFF,
(buffer->length >> 8) & 0xFF,
(buffer->length >> 0) & 0xFF,
0x00, // Control
},
};
coolscan_scanner_exchange(scanner, &cmd, NULL, buffer, NULL);
}
6 changes: 6 additions & 0 deletions coolscan-updater/src/coolscan_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ void coolscan_command_firmware_update_set(coolscan_connection scanner);
*/
void coolscan_command_firmware_update_execute(coolscan_connection scanner);

/**
* Standard SCSI command to read diagnostic data.
* NOTE: This can be dangerous, depending on the exact
*/
void coolscan_command_read_buffer(coolscan_connection scanner, uint8_t mode, uint8_t buffer_id, uint32_t address, struct coolscan_buffer *buffer);

#endif // COOLSCAN_UPDATER_COOLSCAN_COMMAND_H

0 comments on commit 742a906

Please sign in to comment.