J_Class.c
J_Error_t jParseFields(J_Class* jc,uint8_t* p,uint32_t* poolLen){
  J_UtfString us;
  uint8_t* start = p;
  uint16_t i, j, attrCount, nameIdx, accessFlags;
  uint32_t bytesCount;
  
  *poolLen = 0;
  if(jc->fieldsCount>0){
	jc->fields = (J_ClassFields*) calloc(jc->fieldsCount,sizeof(J_ClassFields));
	if(jc->fields==NULL){
      dbg(DBG_MEMORY,"not enought memory for fields");
      return ENOMEM;
	}

   /* clear number of vars */
	jc->numVars = 0;

   /* start count cycle */
	for(i=0;i<jc->fieldsCount;i++){
	 /* get access flags */
      accessFlags = getUint16(p); p += 2;
      jc->fields[i].accessFlags = accessFlags;
	  
	 /* Check for static flags */
      if(!(accessFlags & ACCESS_STATIC)){
        jc->fields[i].var.varOffs = jc->numVars++;   /* local variable */
        accessFlags = 1;
      } else {  
		jc->fields[i].var.varOffs = 0; /* static var */
		accessFlags = 0;  
	  }

     /* get name idx and description idx */
      jc->fields[i].nameIdx = getUint16(p);	 p += 2; 
	  jc->fields[i].descrIdx = getUint16(p); p += 2; 

	  attrCount = getUint16(p); p += 2;
	  
	 /* for all attributes  */
	  for(j=0;j<attrCount;j++){
		nameIdx = getUint16(p);
		us = jGetUtfString(jc,nameIdx); p += 2;

		bytesCount = getUint32(p); p += 4;

	   // if final ... (constant)
		jc->fields[i].isFinal = 0;
		if(accessFlags && (us.len==13) && (bytesCount==2) &&
	       !strncmp(us.str,"ConstantValue",13)){
		  jc->fields[i].var = getConstant(jc,getUint16(p));
		  jc->fields[i].isFinal = 1;
		}
		p += bytesCount;
      }  // for(j= ...
	} // for(i= ...
  } // if(jc->fieldsCount>0)
  
  *poolLen = p - start;
  return EOK;
}
/**
 *  Parse fields from the class file 
 */
Parse fields from the class file
Parse fields from the class file
J_Error_t jParseFields(J_Class* jc,uint8_t* p,uint32_t* poolLen){
  J_UtfString us;
  uint8_t* start = p;
  uint16_t i, j, attrCount, nameIdx, accessFlags;
  uint32_t bytesCount;
  *poolLen = 0;
  if(jc->fieldsCount>0){
	jc->fields = (J_ClassFields*) calloc(jc->fieldsCount,sizeof(J_ClassFields));
	if(jc->fields==NULL){
      dbg(DBG_MEMORY,"not enought memory for fields");
      return ENOMEM;
	}
	jc->numVars = 0;
	for(i=0;i<jc->fieldsCount;i++){
      accessFlags = getUint16(p); p += 2;
      jc->fields[i].accessFlags = accessFlags;
      if(!(accessFlags & ACCESS_STATIC)){
        jc->fields[i].var.varOffs = jc->numVars++;   
        accessFlags = 1;
      } else {  
		jc->fields[i].var.varOffs = 0; 
		accessFlags = 0;  
	  }
      jc->fields[i].nameIdx = getUint16(p);	 p += 2; 
	  jc->fields[i].descrIdx = getUint16(p); p += 2; 
	  attrCount = getUint16(p); p += 2;
	  for(j=0;j<attrCount;j++){
		nameIdx = getUint16(p);
		us = jGetUtfString(jc,nameIdx); p += 2;
		bytesCount = getUint32(p); p += 4;
		jc->fields[i].isFinal = 0;
		if(accessFlags && (us.len==13) && (bytesCount==2) &&
	       !strncmp(us.str,"ConstantValue",13)){
		  jc->fields[i].var = getConstant(jc,getUint16(p));
		  jc->fields[i].isFinal = 1;
		}
		p += bytesCount;
      }  
	} 
  } 
  *poolLen = p - start;
  return EOK;
}
J_Error_t jParseFields ( J_Class * jc , uint8_t * p , uint32_t * poolLen ) { J_UtfString us ; uint8_t * start = p ; uint16_t i , j , attrCount , nameIdx , accessFlags ; uint32_t bytesCount ; * poolLen = 0 ; if ( jc -> fieldsCount > 0 ) { jc -> fields = ( J_ClassFields * ) calloc ( jc -> fieldsCount , sizeof ( J_ClassFields ) ) ; if ( jc -> fields == NULL ) { dbg ( DBG_MEMORY , " " ) ; return ENOMEM ; } jc -> numVars = 0 ; for ( i = 0 ; i < jc -> fieldsCount ; i ++ ) { accessFlags = getUint16 ( p ) ; p += 2 ; jc -> fields [ i ] . accessFlags = accessFlags ; if ( ! ( accessFlags & ACCESS_STATIC ) ) { jc -> fields [ i ] . var . varOffs = jc -> numVars ++ ; accessFlags = 1 ; } else { jc -> fields [ i ] . var . varOffs = 0 ; accessFlags = 0 ; } jc -> fields [ i ] . nameIdx = getUint16 ( p ) ; p += 2 ; jc -> fields [ i ] . descrIdx = getUint16 ( p ) ; p += 2 ; attrCount = getUint16 ( p ) ; p += 2 ; for ( j = 0 ; j < attrCount ; j ++ ) { nameIdx = getUint16 ( p ) ; us = jGetUtfString ( jc , nameIdx ) ; p += 2 ; bytesCount = getUint32 ( p ) ; p += 4 ; jc -> fields [ i ] . isFinal = 0 ; if ( accessFlags && ( us . len == 13 ) && ( bytesCount == 2 ) && ! strncmp ( us . str , " " , 13 ) ) { jc -> fields [ i ] . var = getConstant ( jc , getUint16 ( p ) ) ; jc -> fields [ i ] . isFinal = 1 ; } p += bytesCount ; } } } * poolLen = p - start ; return EOK ; }
Parse fields from the class file
Parse fields from the class file
/* clear number of vars */ /* start count cycle */ /* get access flags */ /* Check for static flags */ /* local variable */ /* static var */ /* get name idx and description idx */ /* for all attributes  */ // if final ... (constant) // for(j= ... // for(i= ... // if(jc->fieldsCount>0)