| | @@ -854,46 +852,56 @@ |
854 | 852 | std::uint32_t ptr;
|
855 | 853 | addrPtrStream.Read( &ptr, sizeof(ptr) );
|
856 | 854 |
|
857 | | - // Determine if we are a forwarder or an export.
|
| 855 | + // We could be an empty entry.
|
| 856 | + // (encountered in system DLLs)
|
| 857 | + if ( ptr != 0 )
|
858 | 858 | {
|
859 | | - typedef sliceOfData <std::uint32_t> rvaSlice_t;
|
| 859 | + // Determine if we are a forwarder or an export.
|
| 860 | + {
|
| 861 | + typedef sliceOfData <std::uint32_t> rvaSlice_t;
|
860 | 862 |
|
861 | | - rvaSlice_t requestSlice( ptr, 1 );
|
| 863 | + rvaSlice_t requestSlice( ptr, 1 );
|
862 | 864 |
|
863 | | - rvaSlice_t expDirSlice( expDirEntry.VirtualAddress, expDirEntry.Size );
|
| 865 | + rvaSlice_t expDirSlice( expDirEntry.VirtualAddress, expDirEntry.Size );
|
864 | 866 |
|
865 | | - rvaSlice_t::eIntersectionResult intResult = requestSlice.intersectWith( expDirSlice );
|
| 867 | + rvaSlice_t::eIntersectionResult intResult = requestSlice.intersectWith( expDirSlice );
|
866 | 868 |
|
867 | | - isForwarder = ( rvaSlice_t::isFloatingIntersect( intResult ) == false );
|
868 | | - }
|
| 869 | + isForwarder = ( rvaSlice_t::isFloatingIntersect( intResult ) == false );
|
| 870 | + }
|
869 | 871 |
|
870 | | - // Store properties according to the type.
|
871 | | - PESection *exportOffPtrSect;
|
872 | | - PEDataStream expOffStream;
|
873 | | - {
|
874 | | - bool gotStream = sections.GetPEDataStream( ptr, expOffStream, &exportOffPtrSect );
|
| 872 | + // Store properties according to the type.
|
| 873 | + PESection *exportOffPtrSect;
|
| 874 | + PEDataStream expOffStream;
|
| 875 | + {
|
| 876 | + bool gotStream = sections.GetPEDataStream( ptr, expOffStream, &exportOffPtrSect );
|
875 | 877 |
|
876 | | - if ( !gotStream )
|
877 | | - {
|
878 | | - throw peframework_exception(
|
879 | | - ePEExceptCode::CORRUPT_PE_STRUCTURE,
|
880 | | - "failed to get PE export offset pointer"
|
881 | | - );
|
| 878 | + if ( !gotStream )
|
| 879 | + {
|
| 880 | + throw peframework_exception(
|
| 881 | + ePEExceptCode::CORRUPT_PE_STRUCTURE,
|
| 882 | + "failed to get PE export offset pointer"
|
| 883 | + );
|
| 884 | + }
|
882 | 885 | }
|
883 | | - }
|
884 | 886 |
|
885 | | - // We store the location of the data entry, but NOTE that
|
886 | | - // this behavior NEVER is an allocation!
|
887 | | - if ( !isForwarder ) // we need to know nothing about forwarders.
|
888 | | - {
|
889 | | - std::uint32_t offStore = ( ptr - exportOffPtrSect->GetVirtualAddress() );
|
| 887 | + // We store the location of the data entry, but NOTE that
|
| 888 | + // this behavior NEVER is an allocation!
|
| 889 | + if ( !isForwarder ) // we need to know nothing about forwarders.
|
| 890 | + {
|
| 891 | + std::uint32_t offStore = ( ptr - exportOffPtrSect->GetVirtualAddress() );
|
890 | 892 |
|
891 | | - fentry.expRef = PESectionDataReference( exportOffPtrSect, offStore );
|
| 893 | + fentry.expRef = PESectionDataReference( exportOffPtrSect, offStore );
|
| 894 | + }
|
| 895 | + // Otherwise read the forwarder entry.
|
| 896 | + else
|
| 897 | + {
|
| 898 | + ReadPEString( expOffStream, fentry.forwarder );
|
| 899 | + }
|
892 | 900 | }
|
893 | | - // Otherwise read the forwarder entry.
|
894 | 901 | else
|
895 | 902 | {
|
896 | | - ReadPEString( expOffStream, fentry.forwarder );
|
| 903 | + // Empty settings.
|
| 904 | + isForwarder = false;
|
897 | 905 | }
|
898 | 906 | }
|
899 | 907 | fentry.isForwarder = isForwarder;
|
| | @@ -985,22 +994,13 @@ |
985 | 994 | );
|
986 | 995 | }
|
987 | 996 |
|
988 | | - PEExportDir::func& fentry = funcs[ mapIndex ];
|
| 997 | + // Store this link.
|
| 998 | + PEExportDir::mappedName nameMap;
|
| 999 | + nameMap.name = std::move( realName );
|
| 1000 | +
|
| 1001 | + realNamePtrSect->SetPlacedMemory( nameMap.nameAllocEntry, namePtrRVA );
|
989 | 1002 |
|
990 | | - // Check for ambiguous name mappings.
|
991 | | - // TODO: this is actually allowed and is called "alias"; pretty evil.
|
992 | | - if ( fentry.isNamed )
|
993 | | - {
|
994 | | - throw peframework_exception(
|
995 | | - ePEExceptCode::UNSUPPORTED,
|
996 | | - "ambiguous PE export name mapping"
|
997 | | - );
|
998 | | - }
|
999 | | -
|
1000 | | - fentry.name = std::move( realName );
|
1001 | | - fentry.isNamed = true; // yes, we have a valid name!
|
1002 | | -
|
1003 | | - realNamePtrSect->SetPlacedMemory( fentry.nameAllocEntry, namePtrRVA );
|
| 1003 | + expInfo.funcNameMap.insert( std::make_pair( std::move( nameMap ), std::move( mapIndex ) ) );
|
1004 | 1004 | }
|
1005 | 1005 | }
|
1006 | 1006 |
|