Code to obtain playback file name - General Discussion and Assistance - CHDK Forum

Code to obtain playback file name

  • 4 Replies
  • 6822 Views
Code to obtain playback file name
« on: 29 / July / 2008, 00:17:01 »
Advertisements
There are two parts to this change:

  • The function get_playback_filename() declared in platform.h, which returns the file name of the currently viewed item.
  • The memory search program which looks for the address of the playback file name. You trigger this by the new menu item "Debug parameters -> Memory browser", and it loops through the memory, searching for a hard coded string.

Code: [Select]
Index: include/gui.h
===================================================================
--- include/gui.h (revision 459)
+++ include/gui.h (working copy)
@@ -18,6 +18,7 @@
                 GUI_MODE_READ,
                 GUI_MODE_OSD,
                 GUI_MODE_CALENDAR,
+                GUI_MODE_MEMSEARCH,
                 GUI_MODE_BENCH,
                 GUI_MODE_MPOPUP };
 
Index: include/platform.h
===================================================================
--- include/platform.h (revision 459)
+++ include/platform.h (working copy)
@@ -265,6 +265,10 @@
 long get_target_dir_num();
 long get_target_file_num();
 
+// Copy the string at POINTER_PLAYBACK_FILENAME. Return NULL on failure.
+// Caller owns the memory for the returned char pointer.
+char *get_playback_filename();
+
 /******************************************************************/
 
 void kbd_key_press(long key);
Index: platform/ixus860_sd870/shooting.c
===================================================================
--- platform/ixus860_sd870/shooting.c (revision 459)
+++ platform/ixus860_sd870/shooting.c (working copy)
@@ -1,4 +1,6 @@
 #define PARAM_FILE_COUNTER      0x38
+#define POINTER_PLAYBACK_FILENAME   0x590a8
+#define POINTER_PLAYBACK_THUMBNAIL  0x5980c
 
 // DRYOS-Notes:
 // propertycase
Index: platform/generic/shooting.c
===================================================================
--- platform/generic/shooting.c (revision 459)
+++ platform/generic/shooting.c (working copy)
@@ -840,6 +840,16 @@
     return v;
 }
 
+char *get_playback_filename() {
+#ifdef POINTER_PLAYBACK_FILENAME
+ char *path = umalloc(32);
+ strncpy(path, (char *) POINTER_PLAYBACK_FILENAME, 32);
+ return path;
+#else
+ return NULL;
+#endif
+}
+
 int shooting_get_zoom() {
     return lens_get_zoom_point();
 }
Index: core/gui_lang.c
===================================================================
--- core/gui_lang.c (revision 459)
+++ core/gui_lang.c (working copy)
@@ -427,6 +427,8 @@
 "339 \"RAWconv\"\n"
 
 "340 \"AF key\"\n"
+
+"341 \"Memory search\"\n"
 ;
 
 //-------------------------------------------------------------------
Index: core/gui_lang.h
===================================================================
--- core/gui_lang.h (revision 459)
+++ core/gui_lang.h (working copy)
@@ -438,9 +438,11 @@
 #define LANG_MENU_BAD_PIXEL_RAW_CONVERTER 339
 
 #define LANG_MENU_VIDEO_AF_KEY  340
+
+#define LANG_MENU_DEBUG_MEMORY_SEARCH   341
 //-------------------------------------------------------------------
 
-#define GUI_LANG_ITEMS                  340
+#define GUI_LANG_ITEMS                  341
 
 //-------------------------------------------------------------------
 extern void gui_lang_init();
Index: core/Makefile
===================================================================
--- core/Makefile (revision 459)
+++ core/Makefile (working copy)
@@ -13,7 +13,8 @@
 
 OBJS=entry.o nothumb.o main.o gui_draw.o gui_menu.o gui_palette.o gui_mbox.o \
      gui_reversi.o gui_debug.o gui_fselect.o gui_read.o gui.o kbd.o conf.o \
-     histogram.o gui_batt.o gui_space.o gui_osd.o script.o raw.o gui_sokoban.o gui_calendar.o \
+     histogram.o gui_batt.o gui_space.o gui_osd.o script.o raw.o gui_sokoban.o \
+     gui_calendar.o gui_memsearch.o \
      gui_lang.o gui_bench.o gui_mpopup.o gui_grid.o motion_detector.o raw_merge.o
 
 gui.o: FORCE
Index: core/gui_memsearch.c
===================================================================
--- core/gui_memsearch.c (revision 0)
+++ core/gui_memsearch.c (revision 0)
@@ -0,0 +1,47 @@
+#include "stdlib.h"
+#include "gui.h"
+#include "gui_draw.h"
+#include "gui_memsearch.h"
+
+//-------------------------------------------------------------------
+// Search parameters
+#define SEARCH_STRING  "A/DCIM/100CANON/MVI_2519.AVI"
+#define START_ADDRESS (void*) 0x0
+#define END_ADDRESS (void*) 0x100000
+
+//-------------------------------------------------------------------
+// Display parameters
+#define OUTPUT_COLOR   (MAKE_COLOR(COLOR_WHITE, COLOR_BLACK))
+#define ERROR_COLOR    (MAKE_COLOR(COLOR_WHITE, COLOR_RED))
+#define X_POSITION     2
+#define Y_POSITION     1
+#define DONE_MSG       "Done"
+#define NOT_FOUND_MSG  "Not found"
+
+//-------------------------------------------------------------------
+void gui_memsearch_init() {
+    void* addr;
+    int found = 0;
+ char buf[32];
+    int y = Y_POSITION;
+
+ draw_clear();
+
+ const char* search_string = SEARCH_STRING;
+ int len = strlen(search_string);
+
+    for (addr = START_ADDRESS; addr < END_ADDRESS; addr += 0x4) {
+    if (memcmp(search_string, addr, len) == 0) {
+    sprintf(buf, "0x%08X", addr);
+    draw_txt_string(X_POSITION, y, buf, OUTPUT_COLOR);
+    found = 1;
+    y = y + 1;
+    }
+    }
+
+    if (found) {
+    draw_txt_string(X_POSITION, y+1, DONE_MSG, OUTPUT_COLOR);
+    } else {
+       draw_txt_string(X_POSITION, y, NOT_FOUND_MSG, ERROR_COLOR);
+    }
+}
Index: core/gui_memsearch.h
===================================================================
--- core/gui_memsearch.h (revision 0)
+++ core/gui_memsearch.h (revision 0)
@@ -0,0 +1,9 @@
+#ifndef GUI_MEMSEARCH_H
+#define GUI_MEMSEARCH_H
+
+//-------------------------------------------------------------------
+extern void gui_memsearch_init();
+
+//-------------------------------------------------------------------
+
+#endif
Index: core/gui.c
===================================================================
--- core/gui.c (revision 459)
+++ core/gui.c (working copy)
@@ -23,6 +23,7 @@
 #include "gui_osd.h"
 #include "gui_read.h"
 #include "gui_calendar.h"
+#include "gui_memsearch.h"
 #include "gui_bench.h"
 #include "gui_grid.h"
 #include "histogram.h"
@@ -105,6 +106,7 @@
 static void gui_draw_load_menu_rbf(int arg);
 static void gui_draw_load_rbf(int arg);
 static void gui_draw_calendar(int arg);
+static void gui_draw_memsearch(int arg);
 static void gui_draw_load_lang(int arg);
 static void gui_menuproc_mkbootdisk(int arg);
 #ifndef OPTIONS_AUTOSAVE
@@ -273,6 +275,7 @@
     {LANG_MENU_DEBUG_PROPCASE_PAGE,     MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,   &debug_propcase_page, MENU_MINMAX(0, 128) },
     {LANG_MENU_DEBUG_SHOW_MISC_VALS,    MENUITEM_BOOL,          &debug_vals_show },
     {LANG_MENU_DEBUG_MEMORY_BROWSER,    MENUITEM_PROC,          (int*)gui_draw_debug },
+    {LANG_MENU_DEBUG_MEMORY_SEARCH,     MENUITEM_PROC,          (int*)gui_draw_memsearch },
     {LANG_MENU_DEBUG_BENCHMARK,         MENUITEM_PROC,          (int*)gui_draw_bench },
     {LANG_MENU_DEBUG_DUMP_RAM,          MENUITEM_BOOL,          &conf.ns_enable_memdump },
     {LANG_MENU_DEBUG_MAKE_BOOTABLE,     MENUITEM_PROC,     (int*)gui_menuproc_mkbootdisk },
@@ -1569,6 +1572,7 @@
             case GUI_MODE_DEBUG:
             case GUI_MODE_OSD:
             case GUI_MODE_CALENDAR:
+            case GUI_MODE_MEMSEARCH:
             case GUI_MODE_BENCH:
                 draw_restore();
                 gui_mode = GUI_MODE_MENU;
@@ -2272,6 +2276,12 @@
 }
 
 //-------------------------------------------------------------------
+void gui_draw_memsearch(int arg) {
+    gui_mode = GUI_MODE_MEMSEARCH;
+    gui_memsearch_init();
+}
+
+//-------------------------------------------------------------------
 static void gui_draw_rbf_selected(const char *fn) {
     if (fn) {
         strcpy(conf.reader_rbf_file, fn);

One potential improvement is to store the search string in a file instead of hard code it. That way if you don't need to recompile if you want to look for a different string. But I figured that if you are looking for memory addresses, you are very likely to be a programmer, so recompiling shouldn't be a big deal.

Using the memory search program, I found two useful addresses: one for the playback filename, one for the corresponding thumbnail. I only added get_playback_filename(), and I can add one for the thumbnail as well, if there is interest.

Please let me know what you think. Thanks!

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Code to obtain playback file name
« Reply #1 on: 29 / July / 2008, 19:26:25 »
will look into it maybe tomorrow, looks promising :)

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Code to obtain playback file name
« Reply #2 on: 16 / August / 2008, 15:48:04 »
looked into this (and My modifications to CHDK), i think i will integrate this some day into the branch. the possible use would definitly be in ubasic: for playback you can now check if there is an avi or a jpg shown. this will allow to finally have extended slideshow features and automatic video playback (doesnt work on a620 for example). also cyril42e's features stand out in a great fashion, as he already utilizes his finding in a nice function.

however, finding the right adresses for other cameras will be very difficult, since these adresses are stored in ram. your function to find the adresses sure is a nice way for experienced coders, but the average guy wont be able to use it (btw, cant you just compare the string to *.jpg instead of a distinct jpg? this way you dont need to hardwire a string). maybe some skilled ASM guys (ewavr? :D) can find a generic way to get all the needed adresses via the dumps & IDA.

Re: Code to obtain playback file name
« Reply #3 on: 21 / August / 2008, 01:19:20 »
Interesting idea to look for *.JPG instead of the actual file name. I searched for a movie because that way I can tell the file name address vs thumbnail address. I can change it to look for *.AVI instead.

Re: Code to obtain playback file name
« Reply #4 on: 18 / October / 2008, 20:43:35 »
Hi,

I've been using chiuki's code to search for "A/DCIM".  When I find it I write out the entire string at that address.
Code: [Select]
    for (addr = START_ADDRESS; addr < END_ADDRESS; addr += 0x1) {
    if (memcmp(search_string, addr, len) == 0) {
    sprintf(buf, "0x%08X %-30s", addr, addr);
    draw_txt_string(X_POSITION, y, buf, OUTPUT_COLOR);
    found = 1;
    y = y + 1;
    }
    }


On my A570is and A720is there seem to be two places that always hold the filename of the current image and 5-6 other places that hold filenames of nearby images. My guess is that the second area is a stash of images read into ram either previously or anticipated to be viewed.

One thing that I did not find was a directory for all the images on disk.

Jon


 

Related Topics


SimplePortal © 2008-2014, SimplePortal