00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "BinaryFile.h"
00033 #include "ElfBinaryFile.h"
00034 #include "ExeBinaryFile.h"
00035 #include "HpSomBinaryFile.h"
00036 #include "PalmBinaryFile.h"
00037 #include "Win32BinaryFile.h"
00038
00039
00040 int main(int argc, char* argv[])
00041 {
00042
00043
00044 if (argc != 2) {
00045 printf ("Usage: %s <filename>\n", argv[0]);
00046 printf ("%s dumps the contents of the given executable file\n", argv[0]);
00047 return 1;
00048 }
00049
00050
00051
00052 BinaryFile *pbf = NULL;
00053 BinaryFileFactory bff;
00054 pbf = bff.Load(argv[1]);
00055
00056 if (pbf == NULL) {
00057 return 2;
00058 }
00059
00060
00061
00062
00063
00064
00065 pbf->DisplayDetails (argv[0]);
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 for (int i=0; i < pbf->GetNumSections(); i++) {
00084 SectionInfo* pSect = pbf->GetSectionInfo(i);
00085 if (pSect->bCode) {
00086 printf(" Code section:\n");
00087 ADDRESS a = pSect->uNativeAddr;
00088 unsigned char* p = (unsigned char*) pSect->uHostAddr;
00089 for (unsigned off = 0; off < pSect->uSectionSize; ) {
00090 printf("%04X: ", a);
00091 for (int j=0; (j < 16) && (off < pSect->uSectionSize); j++) {
00092 printf("%02X ", *p++);
00093 a++;
00094 off++;
00095 }
00096 printf("\n");
00097 }
00098 printf("\n");
00099 }
00100 }
00101
00102
00103
00104 for (int i=0; i < pbf->GetNumSections(); i++) {
00105 SectionInfo* pSect = pbf->GetSectionInfo(i);
00106 if (pSect->bData) {
00107 printf(" Data section: %s\n", pSect->pSectionName);
00108 ADDRESS a = pSect->uNativeAddr;
00109 unsigned char* p = (unsigned char*) pSect->uHostAddr;
00110 for (unsigned off = 0; off < pSect->uSectionSize; ) {
00111 printf("%04X: ", a);
00112 for (int j=0; (j < 16) && (off < pSect->uSectionSize); j++) {
00113 printf("%02X ", *p++);
00114 a++;
00115 off++;
00116 }
00117 printf("\n");
00118 }
00119 printf("\n");
00120 }
00121 }
00122
00123 pbf->UnLoad();
00124 return 0;
00125 }
00126