#include "global.h"#include <cctype>#include "signfile.hpp"#include "rawdump.h"#include "codeglob.h"Go to the source code of this file.
Functions | |
| void | WriteBinary (uint32_t address, const uint8_t *ibuffer, int _len) |
| 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 }
|
|
||||||||||||||||
|
Definition at line 39 of file rawdump.cpp. References _PRG_ASSERT. Referenced by RawDump(), and WriteResource().
00040 {
00041 _PRG_ASSERT(ibuffer != NULL);
00042 _PRG_ASSERT(_len>0);
00043 // remove warning
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 // inizializza buffer
00060 memset(buffer,' ',sizeof(buffer));
00061 }
00062 if (n<len)
00063 {
00064 uint8_t car = *ibuffer++;
00065
00066 // scrive il carattere in esadecimale e carattere relativo
00067 sprintf(buffer+part*3,"%02X",car);
00068 buffer[part*3+2] = part==(nCarInRow/2-1)?'-':' ';
00069 // !!! settare come opzione carattere ?
00070 buffer[nCarInRow*3+1+part] = isprint(car)?car:'.';
00071 }
00072 }
00073 }
|
1.2.15