J_Native.c
void jLoadNativeFunction(J_Class* jc,uint16_t midx){
  int i = 0;
  uint32_t h;
  char tmp[MAX_NATIVE_NAME_LEN];
  J_UtfString name, desc, cname;
  J_ClassMethods* m = &jc->methods[midx];
  J_FuncNativeHash* p;
  
  cname = jGetClassName(jc,jc->thisClassIdx);
  name  = jGetUtfString(jc,m->nameIdx);
  desc  = jGetUtfString(jc,m->descrIdx);

 /* Make full method name:
  * for example native method 'int valueOf(String s)'
  *  of 'java.lang.String' class will translated into
  * 'java/lang/String.valueOf(Ljava/lang/String;)I' string
  * NOTE: to avoid a sprintf use memcpy function instead
  */
  i = cname.len;
  memcpy(tmp,cname.str,i);
  tmp[i++] = '.';
  memcpy(tmp+i,name.str,name.len);
  i += name.len;
  memcpy(tmp+i,desc.str,desc.len);
  i += desc.len;
  tmp[i] = 0;
  
 /* get hash code and try to find such method */
  h = hash((uint8_t*)tmp);
  for(p=funcHash;p->fptr!=NULL;p++)
	if(p->fHash==h){
	  m->fnative = (J_NativeFunction) p->fptr;
	  return;
	}
  dbg(ERR_WARNING,"native method %s not found",tmp);
}
/**
 *  Find native function and init method
 */
Find native function and init method
Find native function and init method
void jLoadNativeFunction(J_Class* jc,uint16_t midx){
  int i = 0;
  uint32_t h;
  char tmp[MAX_NATIVE_NAME_LEN];
  J_UtfString name, desc, cname;
  J_ClassMethods* m = &jc->methods[midx];
  J_FuncNativeHash* p;
  cname = jGetClassName(jc,jc->thisClassIdx);
  name  = jGetUtfString(jc,m->nameIdx);
  desc  = jGetUtfString(jc,m->descrIdx);
  i = cname.len;
  memcpy(tmp,cname.str,i);
  tmp[i++] = '.';
  memcpy(tmp+i,name.str,name.len);
  i += name.len;
  memcpy(tmp+i,desc.str,desc.len);
  i += desc.len;
  tmp[i] = 0;
  h = hash((uint8_t*)tmp);
  for(p=funcHash;p->fptr!=NULL;p++)
	if(p->fHash==h){
	  m->fnative = (J_NativeFunction) p->fptr;
	  return;
	}
  dbg(ERR_WARNING,"native method %s not found",tmp);
}
void jLoadNativeFunction ( J_Class * jc , uint16_t midx ) { int i = 0 ; uint32_t h ; char tmp [ MAX_NATIVE_NAME_LEN ] ; J_UtfString name , desc , cname ; J_ClassMethods * m = & jc -> methods [ midx ] ; J_FuncNativeHash * p ; cname = jGetClassName ( jc , jc -> thisClassIdx ) ; name = jGetUtfString ( jc , m -> nameIdx ) ; desc = jGetUtfString ( jc , m -> descrIdx ) ; i = cname . len ; memcpy ( tmp , cname . str , i ) ; tmp [ i ++ ] = ' ' ; memcpy ( tmp + i , name . str , name . len ) ; i += name . len ; memcpy ( tmp + i , desc . str , desc . len ) ; i += desc . len ; tmp [ i ] = 0 ; h = hash ( ( uint8_t * ) tmp ) ; for ( p = funcHash ; p -> fptr != NULL ; p ++ ) if ( p -> fHash == h ) { m -> fnative = ( J_NativeFunction ) p -> fptr ; return ; } dbg ( ERR_WARNING , " " , tmp ) ; }
Find native function and init method
Find native function and init method
/* Make full method name:
  * for example native method 'int valueOf(String s)'
  *  of 'java.lang.String' class will translated into
  * 'java/lang/String.valueOf(Ljava/lang/String;)I' string
  * NOTE: to avoid a sprintf use memcpy function instead
  */ /* get hash code and try to find such method */