J_Class.c
J_Error_t jParseConstants(J_Class *jc,uint8_t* p,uint32_t* poolLen){
  uint32_t size, i;
  uint8_t* start = p;
  uint16_t tag;
  
  *poolLen = 0;
  p += 8;
  jc->numConsts = getUint16(p);
  
  p += 2;
  if(jc->numConsts!=0){
	size = jc->numConsts * sizeof(uint32_t);

   /* allocate memory for constants pool */
	jc->consts = (uint32_t*) calloc(1,size);

	if(jc->consts==NULL){
	  dbg(DBG_MEMORY,"not enought memory for constant pool");
      return ENOMEM;
	}
	
   /* for each constant in the pool */
	for(i=1;i<jc->numConsts;i++){
	  if(p - jc->classmem>0x7fffffff){
		dbg(DBG_MEMORY,"class too large");
		return ENOMEM;
	  }

      jc->consts[i] = p - jc->classmem;
      p = jLoadClassConst(jc,i,p,&tag);

      if((tag==CONSTANT_Long)||(tag==CONSTANT_Double)) i++;
     }
    }
  *poolLen = p - start;
  return EOK;
}
/**
 * Parse constant pool from the class file 
 */
Parse constant pool from the class file
Parse constant pool from the class file
J_Error_t jParseConstants(J_Class *jc,uint8_t* p,uint32_t* poolLen){
  uint32_t size, i;
  uint8_t* start = p;
  uint16_t tag;
  *poolLen = 0;
  p += 8;
  jc->numConsts = getUint16(p);
  p += 2;
  if(jc->numConsts!=0){
	size = jc->numConsts * sizeof(uint32_t);
	jc->consts = (uint32_t*) calloc(1,size);
	if(jc->consts==NULL){
	  dbg(DBG_MEMORY,"not enought memory for constant pool");
      return ENOMEM;
	}
	for(i=1;i<jc->numConsts;i++){
	  if(p - jc->classmem>0x7fffffff){
		dbg(DBG_MEMORY,"class too large");
		return ENOMEM;
	  }
      jc->consts[i] = p - jc->classmem;
      p = jLoadClassConst(jc,i,p,&tag);
      if((tag==CONSTANT_Long)||(tag==CONSTANT_Double)) i++;
     }
    }
  *poolLen = p - start;
  return EOK;
}
J_Error_t jParseConstants ( J_Class * jc , uint8_t * p , uint32_t * poolLen ) { uint32_t size , i ; uint8_t * start = p ; uint16_t tag ; * poolLen = 0 ; p += 8 ; jc -> numConsts = getUint16 ( p ) ; p += 2 ; if ( jc -> numConsts != 0 ) { size = jc -> numConsts * sizeof ( uint32_t ) ; jc -> consts = ( uint32_t * ) calloc ( 1 , size ) ; if ( jc -> consts == NULL ) { dbg ( DBG_MEMORY , " " ) ; return ENOMEM ; } for ( i = 1 ; i < jc -> numConsts ; i ++ ) { if ( p - jc -> classmem > 0x7fffffff ) { dbg ( DBG_MEMORY , " " ) ; return ENOMEM ; } jc -> consts [ i ] = p - jc -> classmem ; p = jLoadClassConst ( jc , i , p , & tag ) ; if ( ( tag == CONSTANT_Long ) || ( tag == CONSTANT_Double ) ) i ++ ; } } * poolLen = p - start ; return EOK ; }
Parse constant pool from the class file
Parse constant pool from the class file
/* allocate memory for constants pool */ /* for each constant in the pool */