CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
fltdump.c-Dateireferenz
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "myio.h"
#include "flt.h"
+ Include-Abhängigkeitsdiagramm für fltdump.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define USE_INT32_FOR_PTRS
 

Funktionen

void dump_section (char *name, unsigned char *ptr, int size)
 
static void print_offs (char *prefix, uint32_t offs, char *postfix)
 
char * get_flat_string (int32_t offs)
 
int main (int argc, char **argv)
 

Variablen

flat_hdrflat
 
unsigned char * flat_buf
 
char * filename_elf =""
 
int FLAG_VERBOSE =0
 
int FLAG_DUMP_FLAT =0
 

Makro-Dokumentation

#define USE_INT32_FOR_PTRS

Definiert in Zeile 11 der Datei fltdump.c.

Dokumentation der Funktionen

void dump_section ( char *  name,
unsigned char *  ptr,
int  size 
)

Definiert in Zeile 21 der Datei fltdump.c.

22 {
23  printf("\n\nDump %s",name);
24 
25  int i;
26  for(i=0;i<size;i++)
27  {
28  if ((i % 16)==0 ) {printf("\n%06x: ",i);}
29  if ((i % 16)==8 ) {printf("| ");}
30  printf("%02x ",ptr[i]);
31  }
32  printf("\n");
33 }
char* get_flat_string ( int32_t  offs)

Definiert in Zeile 55 der Datei fltdump.c.

56 {
57  static char buf[200];
58 
59  if ( offs <0 )
60  {
61  sprintf(buf," LANGID %d",-offs);
62  return buf;
63  }
64 
65  if ( (uint32_t)offs >=flat->reloc_start || (uint32_t)offs<flat->data_start )
66  return "";
67 
68  strncpy( buf, (char*)flat_buf+offs, sizeof(buf)-1);
69  buf[sizeof(buf)-1]=0;
70  return buf;
71 }
int main ( int  argc,
char **  argv 
)

Definiert in Zeile 73 der Datei fltdump.c.

74 {
75 
76  if ( argc < 2 )
77  {
78  printf("fltdump.exe filename.flt [-f]\n -f = dump content of FLAT sections\n");
79  return 1;
80  }
81 
82  if ( argc > 2 && argv[2][0]=='-' && argv[2][1]=='f' )
83  { FLAG_DUMP_FLAT=1;}
84 
85  char* filename_flt = argv[1];
86 
87  int rv;
88  if ( (rv=b_file_preload(filename_flt)) <= 0 )
89  {
90  fprintf(stderr, "Error load file '%s': loaded %d\n",filename_flt,rv);
91  return 1;
92  }
93 
94 
95  flat = (flat_hdr*) b_get_buf();
96  flat_buf = (unsigned char*)b_get_buf();
97 
98  char magic[5]; // "CFLA"
99  memcpy(magic,&flat->magic,4);
100  magic[4]=0;
101 
102  printf("\nFLT Headers:\n");
103  printf("->magic %s (flat rev.%d)\n", magic, flat->rev );
104 
105  if (flat->magic != FLAT_MAGIC_NUMBER)
106  {
107  printf("This is not CHDK-FLAT!\n");
108  return 1;
109  }
110 
111  if ( flat->rev != FLAT_VERSION )
112  {
113  printf("Bad FLAT revision! It is %d while should be %d\n", flat->rev, FLAT_VERSION);
114  }
115 
116  int flat_reloc_count;
117  flat_reloc_count = (flat->import_start-flat->reloc_start)/sizeof(uint32_t);
118  int flat_import_count;
119  flat_import_count = (flat->import_size)/sizeof(uint32_t);
120 
121 
122  printf("->entry(.text) 0x%x (size %d)\n", flat->entry, flat->data_start - flat->entry );
123  printf("->data_start 0x%x (size %d)\n", flat->data_start, flat->reloc_start - flat->data_start );
124  printf("->bss_start 0x%x (size %d)\n", flat->reloc_start, flat->bss_size );
125  printf("->reloc_start 0x%x (size %d)\n", flat->reloc_start, flat->import_start - flat->reloc_start );
126  printf("->import_start 0x%x (size %d)\n", flat->import_start, flat->import_size );
127  printf("\n");
128 
129  if ( flat->rev == FLAT_VERSION )
130  {
132  if ( _module_info->magicnum != MODULEINFO_V1_MAGICNUM )
133  {
134  printf("Malformed module info - bad magicnum!\n");
135  return 1;
136  }
137  if ( _module_info->sizeof_struct != sizeof(ModuleInfo) )
138  {
139  printf("Malformed module info - bad sizeof!\n");
140  return 1;
141  }
142 
143 
144  printf("\nModule info:\n");
145  printf("->Module Name: %s\n", get_flat_string(_module_info->moduleName) );
146  printf("->Module Ver: %d.%d\n", _module_info->module_version.major, _module_info->module_version.minor );
147 
148  char* branches_str[] = {"any branch","CHDK", "CHDK_DE", "CHDK_SDM", "PRIVATEBUILD"};
149  int branch = (_module_info->chdk_required_branch>REQUIRE_CHDK_PRIVATEBUILD) ?
151  printf("->Require: %s-build%d. ", branches_str[branch], _module_info->chdk_required_ver );
152  if ( _module_info->chdk_required_platfid == 0 )
153  printf("Any platform.\n");
154  else
155  printf(" Platform #%d only.\n", _module_info->chdk_required_platfid );
156  //printf("->Description: %s\n", get_flat_string(_module_info->description) );
157  print_offs("->lib = ", _module_info->lib,"\n");
158  //print_offs("->_module_loader() = ", _module_info->loader,"\n");
159  //print_offs("->_module_unloader() = ", _module_info->unloader,"\n");
160  //print_offs("->_module_can_unload()= ", _module_info->can_unload,"\n");
161  //print_offs("->_module_exit_alt() = ", _module_info->exit_alt,"\n");
162  }
163 
164  if ( !FLAG_DUMP_FLAT )
165  return 0;
166 
167  dump_section( "FLT_header", flat_buf, sizeof(flat_hdr) );
170  //dump_section( "FLT_bss", flat_buf+flat->reloc_start, flat->bss_size );
171 
172  int i;
173  printf("\nDump relocations 0x%x (size=%d):\n",flat->reloc_start,flat_reloc_count*sizeof(uint32_t));
174  for( i = 0; i< flat_reloc_count; i++)
175  print_offs("Offs: ",*(uint32_t*)(flat_buf+flat->reloc_start+i*sizeof(uint32_t)),"\n");
176 
177  printf("\nDump imports 0x%x (size=%d):\n",flat->import_start,flat_import_count*sizeof(uint32_t));
178  uint32_t *new_import_buf = (uint32_t*)(flat_buf+flat->import_start);
179  for( i = 0; i< flat_import_count; i++)
180  {
181  uint32_t idx = new_import_buf[i++];
182  int cnt = new_import_buf[i] >> 24;
183  int j;
184  for (j=0; j<cnt; j++)
185  {
186  uint32_t offs = new_import_buf[i++] & 0x00FFFFFF;
187  print_offs((j==0)?"Offs: ":" ",offs,"");
188  int addend = *(uint32_t*)(flat_buf+offs);
189  printf(" = sym_%08x[%s]+0x%x\n",idx,get_import_symbol(idx),addend);
190  }
191  }
192 
193  return 0;
194 
195 }
static void print_offs ( char *  prefix,
uint32_t  offs,
char *  postfix 
)
static

Definiert in Zeile 36 der Datei fltdump.c.

37 {
38  int secoffs = 0;
39  char* sect="unkn";
40 
41  if ( !offs ) {
42  printf("%s 0x00000000\n",prefix);
43  return;
44  }
45 
46  if ( offs >=flat->entry && offs<flat->data_start )
47  { sect="text"; secoffs=flat->entry;}
48  else if ( offs >=flat->data_start && offs<flat->reloc_start )
49  { sect="data"; secoffs=flat->data_start;}
50  else if ( offs >=flat->reloc_start && offs<(flat->reloc_start+flat->bss_size) )
51  { sect="bss"; secoffs=flat->reloc_start;}
52  printf("%s 0x%08x (%s+0x%08x)%s",prefix, offs,sect,offs-secoffs,postfix);
53 }

Variablen-Dokumentation

char* filename_elf =""

Definiert in Zeile 16 der Datei fltdump.c.

int FLAG_DUMP_FLAT =0

Definiert in Zeile 18 der Datei fltdump.c.

int FLAG_VERBOSE =0

Definiert in Zeile 17 der Datei fltdump.c.

flat_hdr* flat

Definiert in Zeile 14 der Datei fltdump.c.

unsigned char* flat_buf

Definiert in Zeile 15 der Datei fltdump.c.