diff --git a/dump-prog/dump.cpp b/dump-prog/dump.cpp index 4c42a69..d91438f 100644 --- a/dump-prog/dump.cpp +++ b/dump-prog/dump.cpp @@ -110,7 +110,10 @@ int printSecs(void *N, { cout << "Sec Name: " << secName << endl; cout << "Sec Base: 0x" << to_string(secBase, hex) << endl; - cout << "Sec Size: " << to_string(data->bufLen, dec) << endl; + if (data) + cout << "Sec Size: " << to_string(data->bufLen, dec) << endl; + else + cout << "Sec Size: 0" << endl; return 0; } diff --git a/python/pepy.cpp b/python/pepy.cpp index 4030368..d5781aa 100644 --- a/python/pepy.cpp +++ b/python/pepy.cpp @@ -745,15 +745,31 @@ static PyObject *pepy_data_converter(bounded_buffer *data) { } int section_callback(void *cbd, VA base, std::string &name, image_section_header s, bounded_buffer *data) { + uint32_t buflen; PyObject *sect; PyObject *tuple; PyObject *list = (PyObject *) cbd; + /* + * I've seen some interesting binaries with a section where the + * PointerToRawData and SizeOfRawData are invalid. The parser library + * handles this by setting sectionData to NULL as returned by splitBuffer(). + * The sectionData (passed in to us as *data) is converted using + * pepy_data_converter() which will return an empty string object. + * However, we need to address the fact that we pass an invalid length + * via data->bufLen. + */ + if (!data) { + buflen = 0; + } else { + buflen = data->bufLen; + } + /* * The tuple item order is important here. It is passed into the * section type initialization and parsed there. */ - tuple = Py_BuildValue("sKKIIHHIO&", name.c_str(), base, data->bufLen, + tuple = Py_BuildValue("sKKIIHHIO&", name.c_str(), base, buflen, s.VirtualAddress, s.Misc.VirtualSize, s.NumberOfRelocations, s.NumberOfLinenumbers, s.Characteristics, pepy_data_converter, data);