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 #include "global.h"
00026 #ifdef HAVE_HDRSTOP
00027 #pragma hdrstop
00028 #endif
00029
00030 #include <cctype>
00031 #include "signfile.hpp"
00032 #include "rawdump.h"
00033 #include "codeglob.h"
00034
00035 using namespace std;
00036
00037
00038
00039 static void WriteBinary(uint32_t address,const uint8_t* ibuffer,int _len)
00040 {
00041 _PRG_ASSERT(ibuffer != NULL);
00042 _PRG_ASSERT(_len>0);
00043
00044 unsigned len = (unsigned)_len;
00045 const unsigned nCarInRow = 16;
00046 char buffer[3*nCarInRow+nCarInRow+10];
00047 for(unsigned n=0;;++n)
00048 {
00049 unsigned part = n%nCarInRow;
00050 if (part==0)
00051 {
00052 if (n>=nCarInRow)
00053 {
00054 buffer[nCarInRow*3+nCarInRow+1] = '\0';
00055 printf("%08X %s\n",static_cast<uint32_t>(address+n-nCarInRow),buffer);
00056 if (n>=len)
00057 return;
00058 }
00059
00060 memset(buffer,' ',sizeof(buffer));
00061 }
00062 if (n<len)
00063 {
00064 uint8_t car = *ibuffer++;
00065
00066
00067 sprintf(buffer+part*3,"%02X",car);
00068 buffer[part*3+2] = part==(nCarInRow/2-1)?'-':' ';
00069
00070 buffer[nCarInRow*3+1+part] = isprint(car)?car:'.';
00071 }
00072 }
00073 }
00074
00075 void RawDump(CSignFile& file,uint32_t imageBase,const RVAFileTranslator& rva)
00076 {
00077
00078 file.Seek(0,SEEK_END);
00079 uint32_t fileSize = (uint32_t)file.Tell();
00080
00081 uint32_t startFile = 0;
00082 uint32_t endFile;
00083
00084 printf("\nRaw dump\n");
00085
00086 for(unsigned n=0; ; )
00087 {
00088 const PeSection* section = rva.GetSection(n);
00089 uint32_t writeStart = startFile;
00090 int currSection = -1;
00091 if (!section)
00092 {
00093
00094 endFile = fileSize;
00095 }
00096 else
00097 {
00098 if (startFile == section->RawAddress )
00099 {
00100
00101 endFile = section->RawAddress + section->RawSize;
00102 writeStart = imageBase + section->RvaAddress;
00103 currSection = n;
00104 ++n;
00105 }
00106 else if (startFile > section->RawAddress )
00107 {
00108
00109 ++n;
00110 continue;
00111 }
00112 else
00113 {
00114
00115 endFile = section->RawAddress;
00116 }
00117 }
00118
00119
00120 if (endFile > fileSize)
00121 endFile = fileSize;
00122
00123
00124
00125 if (startFile != endFile)
00126 {
00127 if (currSection == -1)
00128 printf("\nFile section\n");
00129 else
00130 printf("\nSection %d\n",currSection);
00131 uint8_t buffer[256];
00132 file.Seek(startFile);
00133 while ( startFile < endFile)
00134 {
00135 unsigned left = (endFile - startFile) > 256 ? 256 : (endFile - startFile);
00136 file.RawRead(buffer,left*sizeof(uint8_t));
00137 WriteBinary(writeStart,buffer,left);
00138 startFile += left;
00139 writeStart += left;
00140 }
00141 }
00142
00143 startFile = endFile;
00144
00145 if (endFile == fileSize)
00146 break;
00147 }
00148 }
00149