CHDK_DE Vorschauversion  Trunk Rev. 5412
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
dumpchk.c-Dateireferenz
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+ Include-Abhängigkeitsdiagramm für dumpchk.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define CHECK_FIND   0
 
#define CHECK_VXWORKS   1
 
#define CHECK_DRYOS   2
 

Funktionen

void usage (void)
 
int main (int argc, char **argv)
 

Variablen

const char vxworks_start_sig []
 
const char dryos_start_sig []
 

Makro-Dokumentation

#define CHECK_DRYOS   2

Definiert in Zeile 50 der Datei dumpchk.c.

#define CHECK_FIND   0

Definiert in Zeile 48 der Datei dumpchk.c.

#define CHECK_VXWORKS   1

Definiert in Zeile 49 der Datei dumpchk.c.

Dokumentation der Funktionen

int main ( int  argc,
char **  argv 
)

Definiert in Zeile 51 der Datei dumpchk.c.

51  {
52  int retval = 0;
53  int checkmode = CHECK_FIND;
54  int fix = 0;
55  int quiet = 0;
56  char *dumpname = NULL;
57  FILE *dumpfile;
58  int i,size;
59  for(i = 1; i < argc; i++) {
60  if ( strcmp(argv[i],"-vxworks") == 0 ) {
61  checkmode = CHECK_VXWORKS;
62  }
63  else if (strcmp(argv[i],"-dryos") == 0 ) {
64  checkmode = CHECK_DRYOS;
65  }
66  else if (strcmp(argv[i],"-fix") == 0 ) {
67  fix = 1;
68  }
69  else if (strcmp(argv[i],"-quiet") == 0 ) {
70  quiet = 1;
71  }
72  else if ( argv[i][0] == '-' ) {
73  fprintf(stderr,"%s unknown option %s\n",argv[0],argv[i]);
74  usage();
75  }
76  else {
77  if (!dumpname)
78  dumpname=argv[i];
79  else {
80  fprintf(stderr,"%s unexpected %s\n",argv[0],argv[i]);
81  usage();
82  }
83  }
84  }
85  if(!dumpname) {
86  usage();
87  }
88  dumpfile = fopen(dumpname,"rb");
89  if(!dumpfile) {
90  fprintf(stderr,"%s unable to open %s\n",argv[0],dumpname);
91  usage();
92  }
93  fseek(dumpfile,0,SEEK_END);
94  size=ftell(dumpfile);
95  fseek(dumpfile,0,SEEK_SET);
96 
97  if( checkmode == CHECK_FIND) {
98  char *buf;
99  const char *found=NULL;
100  if(size < sizeof(vxworks_start_sig) || size < sizeof(dryos_start_sig)) {
101  printf("%s TOO SMALL: 0x%X (%d) bytes\n",dumpname,size,size);
102  fclose(dumpfile);
103  return 1;
104  }
105  buf=malloc(size);
106  if(!buf) {
107  fprintf(stderr,"%s out of memory\n",argv[0]);
108  fclose(dumpfile);
109  exit(2);
110  }
111  fread(buf, 1, size, dumpfile);
112  for(i=0; i<size; i++) {
113  if( i+sizeof(vxworks_start_sig) < size) {
114  if(memcmp(buf+i,vxworks_start_sig,sizeof(vxworks_start_sig)) == 0) {
115  found = "VXWORKS";
116  }
117  }
118  if( i+sizeof(dryos_start_sig) < size) {
119  if(memcmp(buf+i,dryos_start_sig,sizeof(dryos_start_sig)) == 0) {
120  found = "DRYOS";
121  }
122  }
123  if(found) {
124  printf("%s %s ",dumpname,found);
125  if(i) {
126  printf("@0x%X (%d) REMAINING 0x%X (%d) bytes\n",i,i,size-i,size-i);
127  }
128  else {
129  printf("@Start SIZE 0x%X (%d)\n",size,size);
130  }
131  break;
132  }
133  }
134  if(i==size) {
135  printf("%s 0x%X (%d) bytes no sig found\n",dumpname,size,size);
136  retval = 0;
137  }
138  fclose(dumpfile);
139  if(fix && i && i < size) {
140  dumpfile = fopen(dumpname,"wb");
141  printf("fix: %s trim 0x%X (%d) ...",dumpname,i,i);
142  if(!dumpfile) {
143  fprintf(stderr,"\n%s unable to open %s for write\n",argv[0],dumpname);
144  }
145  else {
146  fwrite(buf+i,1,size-i,dumpfile);
147  printf(" wrote 0x%X (%d)\n",size-i,size-i);
148  }
149  }
150  free(buf);
151  }
152  else {
153  const char *sig=vxworks_start_sig,*osname = "VXWORKS";
154  char *buf;
155  int sigsize = sizeof(vxworks_start_sig);
156 
157  if (checkmode == CHECK_DRYOS) {
158  sig = dryos_start_sig;
159  sigsize = sizeof(dryos_start_sig);
160  osname = "DRYOS";
161  }
162  buf = malloc(sigsize);
163  if(!buf) {
164  fprintf(stderr,"%s out of memory\n",argv[0]);
165  fclose(dumpfile);
166  exit(2);
167  }
168  if( fread(buf,1,sigsize,dumpfile) != sigsize) {
169  retval = 0;
170  }
171  else {
172  retval = (memcmp(buf,sig,sigsize) == 0);
173  }
174  free(buf);
175 
176  if(!quiet) {
177  if(retval) {
178  printf("%s valid %s 0x%X (%d) bytes\n",dumpname,osname,size,size);
179  }
180  else {
181  printf("%s NOT valid %s 0x%X (%d) bytes\n",dumpname,osname,size,size);
182  }
183  }
184  }
185  fclose(dumpfile);
186  return retval == 0;
187 }
void usage ( void  )

Definiert in Zeile 27 der Datei dumpchk.c.

27  {
28  fprintf(stderr,"usage: dumpchk [-vxworks|-dryos|-fix] [-quiet] <dump>\n");
29  exit(1);
30 }

Variablen-Dokumentation

const char dryos_start_sig[]
Initialisierung:
= {
0x01, 0x00, 0x00, 0xEA,
'g', 'a','o', 'n', 'i', 's', 'o' ,'y'
}

Definiert in Zeile 42 der Datei dumpchk.c.

const char vxworks_start_sig[]
Initialisierung:
= {
0x02, 0x00, 0xA0, 0xE3,
0x12, 0x00, 0x00, 0xEA,
'C', 'o', 'p', 'y', 'r', 'i', 'g', 'h'
}

Definiert in Zeile 35 der Datei dumpchk.c.