Exemplo n.º 1
0
bool java_bytecode_parse(
  const std::string &file,
  java_bytecode_parse_treet &parse_tree,
  message_handlert &message_handler)
{
  std::ifstream in(file, std::ios::binary);

  if(!in)
  {
    messaget message(message_handler);
    message.error() << "failed to open input file `"
                    << file << '\'' << messaget::eom;
    return true;
  }

  return java_bytecode_parse(in, parse_tree, message_handler);
}
Exemplo n.º 2
0
java_bytecode_parse_treet &java_class_loadert::get_parse_tree(
  java_class_loader_limitt &class_loader_limit,
  const irep_idt &class_name)
{
  java_bytecode_parse_treet &parse_tree=class_map[class_name];

  // First check given JAR files
  for(const auto &jf : jar_files)
  {
    read_jar_file(class_loader_limit, jf);

    const auto &jm=jar_map[jf];

    auto jm_it=jm.entries.find(class_name);

    if(jm_it!=jm.entries.end())
    {
      debug() << "Getting class `" << class_name << "' from JAR "
              << jf << eom;

      std::string data=jar_pool(class_loader_limit, jf)
        .get_entry(jm_it->second.class_file_name);

      std::istringstream istream(data);

      java_bytecode_parse(
        istream,
        parse_tree,
        get_message_handler());

      return parse_tree;
    }
  }

  // See if we can find it in the class path
  for(const auto &cp : config.java.classpath)
  {
    // in a JAR?
    if(has_suffix(cp, ".jar"))
    {
      read_jar_file(class_loader_limit, cp);

      const auto &jm=jar_map[cp];

      auto jm_it=jm.entries.find(class_name);

      if(jm_it!=jm.entries.end())
      {
        debug() << "Getting class `" << class_name << "' from JAR "
                << cp << eom;

        std::string data=jar_pool(class_loader_limit, cp)
          .get_entry(jm_it->second.class_file_name);

        std::istringstream istream(data);

        java_bytecode_parse(
          istream,
          parse_tree,
          get_message_handler());

        return parse_tree;
      }
    }
    else
    {
      // in a given directory?
      std::string full_path=
        #ifdef _WIN32
        cp+'\\'+class_name_to_file(class_name);
        #else
        cp+'/'+class_name_to_file(class_name);
        #endif

      // full class path starts with './'
      if(class_loader_limit.load_class_file(full_path.substr(2)) &&
         std::ifstream(full_path))
      {
        if(!java_bytecode_parse(
             full_path,
             parse_tree,
             get_message_handler()))
          return parse_tree;
      }
    }
  }

  // not found
  warning() << "failed to load class `" << class_name << '\'' << eom;
  parse_tree.parsed_class.name=class_name;
  return parse_tree;
}