diff -r 000000000000 -r 509e4801c378 srcanamdw/appdep/src/appdep_getters.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/srcanamdw/appdep/src/appdep_getters.cpp Sat Jan 09 10:04:12 2010 +0530 @@ -0,0 +1,631 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Utility functions for getting data via 3rd party tools +* +*/ + + +#include "appdep.hpp" + +// ---------------------------------------------------------------------------------------------------------- +// Note that in C/C++ code \ has been replaced with \\ and " with \". +// ---------------------------------------------------------------------------------------------------------- + +void GetImportTableWithPetran(const string& petran_location, binary_info& b_info) +{ + vector deps; + vector tempVector; + + // init defaults + b_info.binary_format = UNKNOWN; + b_info.uid1 = UNKNOWN; + b_info.uid2 = UNKNOWN; + b_info.uid3 = UNKNOWN; + b_info.secureid = NOT_VALID; + b_info.vendorid = NOT_VALID; + b_info.capabilities = 0; + b_info.min_heap_size = 0; + b_info.max_heap_size = 0; + b_info.stack_size = 0; + + // execute petran + string cmd; + + if (_cl_use_gcce || _cl_use_rvct) + cmd = petran_location + " -dump hi \"" + b_info.directory + b_info.filename + "\" " + CERR_TO_NULL; + else + cmd = petran_location + " \"" + b_info.directory + b_info.filename + "\" " + CERR_TO_NULL; + + //cerr << cmd << endl; + ExecuteCommand(cmd, tempVector); + + // get binary format, assuming it's the first line which begings with EPOC + for (unsigned int j=0; j imps; // imports + string filename = ms2+ms3; + + // get position of the filename in import libaries + int lib_pos = -1; + for (unsigned int x=0; x<_all_import_library_infos.size(); x++) + { + if (StringICmpFileNamesWithoutExtension(_all_import_library_infos.at(x).filename, filename) == 0) + { + lib_pos = x; + break; + } + } + + + // read ordinal numbers + for (unsigned int k=0; k= 0) + { + if (imp.funcpos-1 < _all_import_library_infos.at(lib_pos).symbol_table.size()) + imp.funcname = _all_import_library_infos.at(lib_pos).symbol_table.at(imp.funcpos-1); + else + imp.funcname = "BC break: This ordinal position is not in the import library!"; + } + else + { + imp.funcname = "Import library not found!"; + } + + // Checking for possible duplicate imported function ordinals. + import compare[] = { imp }; + vector::iterator it = find_first_of(imps.begin(), imps.end(), compare, compare+1, ImportFunctionsHasSameOrdinal); + if(it == imps.end()) + { + // No duplicate detected. Appending ordinal data to the array. + imps.push_back(imp); + } + + } + + // append to the vector + + dependency dep; + dep.filename = filename; + dep.imports = imps; + + deps.push_back( dep ); + + } + } + + break; //for (int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute nm + string cmd = nm_location + " --demangle \"" + lib_directory + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute readelf + // note: 2>NUL is used here to redirect standard error output to NULL since readelf seems to output lots of unwanted warning messages + string cmd = readelf_location + " -s -W \"" + lib_directory + lib_name + "\" " + CERR_TO_NULL; + ExecuteCommand(cmd, tempVector); + + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute armar + string cmd = armar_location + " --zs \"" + lib_directory + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + // parse the results of the command + for (unsigned int j=0; j& symbol_table) +{ + symbol_table.clear(); + vector tempVector; + vector ordinals; + + // execute fromelf + string cmd = fromelf_location + " -s \"" + lib_directory + lib_name + "\""; + ExecuteCommand(cmd, tempVector); + + // parse the results of the command + for (unsigned int j=0; j& ordinals, vector& symbol_table, const string& lib_path) +{ + // remove any invalid ordinals from the list + vector ordinalVectorCopy; + ordinalVectorCopy.reserve(ordinals.size()); + + for (unsigned int i=0; i 32000) + { + cerr << "Error: Invalid ordinal " << ordinals.at(i).funcname << " @ " << Int2Str(ordinals.at(i).funcpos) << endl; + } + else + { + ordinalVectorCopy.push_back(ordinals.at(i)); + } + } + + // sort the ordinal list + sort(ordinalVectorCopy.begin(), ordinalVectorCopy.end(), OrdinalCompare); + + // now check that there are no missing ordinals in the list + unsigned int previous_ordnumber = 0; + unsigned int current_ordnumber = 1; + for (unsigned int i=0; i25000) + { + cerr << endl << "Something went horribly wrong when trying to parse " << lib_path << ". Aborting." << endl; + exit(10); + } + } + + // finally copy data from the ordinal list to the symbol table + if (symbol_table.size() < ordinalVectorCopy.size()) + { + symbol_table.reserve(ordinalVectorCopy.size()); + } + for (unsigned int i=0; i& symbol_table) +{ + ofstream f(_tempfile_location.c_str(), ios::trunc); + if (f.is_open()) + { + // create a temp file which contain all the function names + for (unsigned int k=0; k cfilt_result_set; + string cmd = cfilt_location + " < " + _tempfile_location; + ExecuteCommand(cmd, cfilt_result_set); + + // check that all functions exist and then replace the symbol table with demangled functions + if (cfilt_result_set.size() == symbol_table.size()) + { + symbol_table = cfilt_result_set; + } + } + else + { + f.close(); + } +} + +// ---------------------------------------------------------------------------------------------------------- + +bool OrdinalCompare(const ordinal& left, const ordinal& right) +{ + return left.funcpos < right.funcpos; +} + +// ---------------------------------------------------------------------------------------------------------- + +