Go to the source code of this file.
Functions | |
void | RawDump (CSignFile &file, uint32_t imageBase, const RVAFileTranslator &rva) |
|
Definition at line 75 of file rawdump.cpp. References RVAFileTranslator::GetSection(), PeSection::RawAddress, CSignFile::RawRead(), PeSection::RawSize, PeSection::RvaAddress, CFile::Seek(), CFile::Tell(), and WriteBinary(). Referenced by main().
00076 { 00077 // get file size 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 // no more sections, write last part of file 00094 endFile = fileSize; 00095 } 00096 else 00097 { 00098 if (startFile == section->RawAddress ) 00099 { 00100 // write this section 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 // skip section (probably not file section) 00109 ++n; 00110 continue; 00111 } 00112 else 00113 { 00114 // write part before section 00115 endFile = section->RawAddress; 00116 } 00117 } 00118 00119 // normalize 00120 if (endFile > fileSize) 00121 endFile = fileSize; 00122 00123 // write dump of [startFile, endFile) 00124 // exclude empty sections 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 } |