ClassFile * ClassFile::setClassByMethod(std::string p_methodName, std::string p_methodDescription) { for (int i = 0; i < methods_count; i++) { std::string name, description; getAttrName(methods[i] . name_index, name); getAttrName(methods[i] . descriptor_index, description); if(name.compare(p_methodName) == 0 and description.compare(p_methodDescription) == 0) { return this; } } if(super_class != 0) { return classHeap -> getClass(getClassNameFromRef(super_class)) -> setClassByMethod(p_methodName, p_methodDescription); } throw 23; }
method_info_w_code ClassFile::getMethod(std::string methodName, std::string methodDescription) { for (int i = 0; i < methods_count; i++) { std::string name, description; getAttrName(methods[i] . name_index, name); getAttrName(methods[i] . descriptor_index, description); if(name.compare(methodName) == 0 and description.compare(methodDescription) == 0) { return methods[i]; } } if(super_class != 0) { return classHeap -> getClass(getClassNameFromRef(super_class)) -> getMethod(methodName, methodDescription); } throw 20; }
// ---------------------------------- void XML::Node::write(Stream &out, int level) { int i; #if 0 char tabs[64]; for(i=0; i<level; i++) tabs[i] = ' '; tabs[i] = '\0'; if (level) out.write(tabs,i); #endif char *name = getAttrValue(0); out.write("<",1); out.write(name,strlen(name)); for(i=1; i<numAttr; i++) { out.write(" ",1); char *at = getAttrName(i); out.write(at,strlen(at)); out.write("=\"",2); char *av = getAttrValue(i); out.write(av,strlen(av)); out.write("\"",1); } if ((!contData) && (!child)) { out.write("/>\n",3); }else { out.write(">\n",2); if (contData) out.write(contData,strlen(contData)); if (child) child->write(out,level+1); #if 0 if (level) out.write(tabs,strlen(tabs)); #endif out.write("</",2); out.write(name,strlen(name)); out.write(">\n",2); } if (sibling) sibling->write(out,level); }
// ---------------------------------- char *XML::Node::findAttr(const char *name) { size_t nlen = strlen(name); for(int i=1; i<numAttr; i++) { char *an = getAttrName(i); if (strnicmp(an,name,nlen)==0) return getAttrValue(i); } return NULL; }
std::string ClassFile::getName() { // get class info on this classIndex u1 * p_classInfo = (u1*)constant_pool[this_class]; // get name_index of this class (ref to constant_pool with class name) u2 nameIndexClass = getu2(p_classInfo + 1); // get string name of this class from constant pool std::string className; getAttrName(nameIndexClass, className); return className; }
char HBase::hasNamedAttr(const char * attrName) { hsize_t nattr = H5Aget_num_attrs(fObjectId); //std::cout<<"\n "<<fObjectPath<<" has "<<nattr<<" attrs\n"; hsize_t i; for(i = 0; i < nattr; i++) { hid_t aid = H5Aopen_idx(fObjectId, (unsigned int)i ); //std::cout<<getAttrName(aid)<<"\n"; if(getAttrName(aid) == attrName) { //std::cout<<"found "<<attrName; H5Aclose(aid); return 1; } H5Aclose(aid); } return 0; }
int ClassFile::getFieldIndex(std::string fieldName) { int fieldIndex = -1; if(super_class != 0) { std::string className = getClassNameFromRef(super_class); fieldIndex = classHeap -> getClass(className) -> getObjectSize(); } for (int i = 0; i < fields_count; i++) { std::string fielNamePool; getAttrName(fields[i] . name_index, fielNamePool); if(fieldName.compare(fielNamePool) == 0) { return i + fieldIndex; } } if(super_class != 0) { std::string className = getClassNameFromRef(super_class); fieldIndex = classHeap -> getClass(className) -> getFieldIndex(fieldName); } return fieldIndex; }
int ClassFile::loadMethods(char * &p) { methods = new method_info_w_code[methods_count]; for (int i = 0; i < methods_count; i++) { methods[i] . access_flags = getu2(p); p += 2; methods[i] . name_index = getu2(p); p += 2; methods[i] . descriptor_index = getu2(p); p += 2; methods[i] . attributes_count = getu2(p); p += 2; if(methods[i] . attributes_count > 0) { //methods[i] . attributes = new attribute_info[methods[i] . attributes_count]; methods[i] . code_attr = NULL; for (int j = 0; j < methods[i] . attributes_count; j++) { /* methods[i] . attributes[j] . */ u2 attribute_name_index = getu2(p); p += 2; /* methods[i] . attributes[j] . */ u4 attribute_length = getu4(p); p += 4; /* if(methods[i] . attributes[j] . attribute_length > 0) { methods[i] . attributes[j] . info = new u1[methods[i] . attributes[j] . attribute_length]; for (unsigned int k = 0; k < methods[i] . attributes[j] . attribute_length; k++) { methods[i] . attributes[j] . info[k] = getu1(p); p += 1; } } */ //if Attribute is "Code, save it to code_attr" methods[i] . code_attr = new Code_attribute; std::string attr_value; getAttrName( /*methods[i] . attributes[j] . */ attribute_name_index, attr_value); if(attr_value.compare("Code") == 0) { char * pA = p;//(char *)methods[i] . attributes[j] . info; methods[i] . code_attr -> attribute_name_index = /* methods[i] . attributes[j] .*/ attribute_name_index; methods[i] . code_attr -> attribute_length = /* methods[i] . attributes[j] .*/ attribute_length; methods[i] . code_attr -> max_stack = getu2(pA); pA += 2; methods[i] . code_attr -> max_locals = getu2(pA); pA += 2; methods[i] . code_attr -> code_length = getu4(pA); pA += 4; if(methods[i] . code_attr -> code_length > 0) { methods[i] . code_attr -> code = new u1[methods[i] . code_attr -> code_length]; memcpy(methods[i] . code_attr -> code, pA, methods[i] . code_attr -> code_length); } else { methods[i] . code_attr -> code = NULL; } pA += methods[i] . code_attr -> code_length; methods[i] . code_attr -> exception_table_length = getu2(pA); pA += 2; if(methods[i] . code_attr -> exception_table_length > 0) { methods[i] . code_attr -> exception_table = new Exception_table[methods[i] . code_attr -> exception_table_length]; for (int l = 0; l < methods[i] . code_attr -> exception_table_length; l++) { methods[i] . code_attr -> exception_table[l] . start_pc = getu2(pA); pA += 2; methods[i] . code_attr -> exception_table[l] . end_pc = getu2(pA); pA += 2; methods[i] . code_attr -> exception_table[l] . handler_pc = getu2(pA); pA += 2; methods[i] . code_attr -> exception_table[l] . catch_type = getu2(pA); pA += 2; } } methods[i] . code_attr -> attributes_count = getu2(pA); pA += 2; if(methods[i] . code_attr -> attributes_count > 0) { methods[i] . code_attr -> attributes = new attribute_info[methods[i] . code_attr -> attributes_count]; for (int m = 0; m < methods[i] . code_attr -> attributes_count; m++) { methods[i] . code_attr -> attributes[m] . attribute_name_index = getu2(pA); pA += 2; methods[i] . code_attr -> attributes[m] . attribute_length = getu4(pA); pA += 4; if( methods[i] . code_attr -> attributes[m] . attribute_length > 0) { methods[i] . code_attr -> attributes[m] . info = new u1[methods[i] . code_attr -> attributes[m] . attribute_length]; for (unsigned int o = 0; o < methods[i] . code_attr -> attributes[m] . attribute_length; o++) { methods[i] . code_attr -> attributes[m] . info[o] = getu1(pA); pA += 1; } } } } } p += attribute_length; } } } return 0; }