Example #1
0
bool Application::StartMonoAndLoadAssemblies()
{
	// shutdown the child domain
	StopMono();

	// create a new child domain
	if (!StartMono()) {
		mono_environment_exitcode_set(-1);
		return true;
	}


	std::string dll = "EmbedThings.dll";
	std::string filename = File::BuildRootedPath(assemblyDir, dll);
	size_t length;
	// read our entry point assembly
	char* data = File::Read(filename.c_str(), &length);

	printf_console("Loading %s into Domain\n", dll.c_str());

	MonoImageOpenStatus status;
	// open the assembly from the data we read, so we never lock files
	auto image = mono_image_open_from_data_with_name(data, length, true /* copy data */, &status, false /* ref only */, filename.c_str());
	if (status != MONO_IMAGE_OK || image == nullptr)
	{
		printf_console("Failed loading assembly %s\n", dll);
		return true;
	}

	// load the assembly
	auto  assembly = mono_assembly_load_from_full(image, filename.c_str(), &status, false);
	if (status != MONO_IMAGE_OK || assembly == nullptr)
	{
		mono_image_close(image);
		printf_console("Failed loading assembly %s\n", dll);
		return true;
	}

	// save the image for lookups later and for cleaning up
	images.push_back(image);

	if (!assembly) {
		printf_console("Couldn't find assembly %s\n", filename.c_str());
		return true;
	}

	// locate the class we want to load
	MonoClass* klass = mono_class_from_name(image, "EmbedThings", "EntryPoint");
	if (klass == nullptr) {
		printf_console("Failed loading class %s\n", "EmbedThings.EntryPoint");
		return true;
	}

	// create the class (doesn't run constructors)
	MonoObject* obj = mono_object_new(mono_domain_get(), klass);
	if (obj == nullptr) {
		printf_console("Failed loading class instance %s\n", "EmbedThings.EntryPoint");
		return true;
	}

	// initialize the class instance (runs default constructors)
	mono_runtime_object_init(obj);
	if (obj == nullptr) {
		printf_console("Failed initializing class instance %s\n", "EmbedThings.EntryPoint");
		return true;
	}

	// save the class instance for lookups later
	instances.push_back(obj);

	// find the Run() method
	auto method = find_method(klass, "Run");
	MonoObject *result, *exception;

	// call the Run method. This will block until the managed code decides to exit
	result = mono_runtime_invoke(method, obj, NULL, NULL);
	int val = *(int*)mono_object_unbox(result);

	// if the managed code returns with 0, it wants to exit completely
	if (val == 0) {
		return true;
	}
	return false;
}
Example #2
0
File: hash.c Project: skarb/skarb
/*
 * Implements GEqualFunc, used for comparing keys in the hash.
 */
static gboolean equal_func(gconstpointer a, gconstpointer b) {
    return boolean_value(
        ( (Object*(*)(Object*,Object*)) find_method(as_object(a)->type,
           l_classes_dictionary, _EQ__EQ__id, "==", 2))(as_object(a),
           as_object(b)));
}
Example #3
0
/**
* @brief Gets a method of the object on top of the stack.
*
* This is equivalent to find_method(-1, function_name).
*
* @param function_name Name of the function to find in the object.
* @return true if the function was found.
*/
bool LuaContext::find_method(const std::string& function_name)
{
	return find_method(-1, function_name);
}
Example #4
0
void emit_class(EmitUnitState& state,
                UnitEmitter& ue,
                const php::Class& cls) {
  FTRACE(2, "    class: {}\n", cls.name->data());
  auto const pce = ue.newPreClassEmitter(
    cls.name,
    cls.hoistability
  );
  pce->init(
    std::get<0>(cls.srcInfo.loc),
    std::get<1>(cls.srcInfo.loc),
    ue.bcPos(),
    cls.attrs,
    cls.parentName ? cls.parentName : s_empty.get(),
    cls.srcInfo.docComment
  );
  pce->setUserAttributes(cls.userAttributes);

  for (auto& x : cls.interfaceNames)     pce->addInterface(x);
  for (auto& x : cls.usedTraitNames)     pce->addUsedTrait(x);
  for (auto& x : cls.requirements)       pce->addClassRequirement(x);
  for (auto& x : cls.traitPrecRules)     pce->addTraitPrecRule(x);
  for (auto& x : cls.traitAliasRules)    pce->addTraitAliasRule(x);
  pce->setNumDeclMethods(cls.numDeclMethods);

  pce->setIfaceVtableSlot(state.index.lookup_iface_vtable_slot(&cls));

  for (auto& m : cls.methods) {
    FTRACE(2, "    method: {}\n", m->name->data());
    auto const fe = ue.newMethodEmitter(m->name, pce);
    emit_init_func(*fe, *m);
    pce->addMethod(fe);
    auto const info = emit_bytecode(state, ue, *m);
    emit_finish_func(*m, *fe, info);
  }

  std::vector<Type> useVars;
  if (is_closure(cls)) {
    auto f = find_method(&cls, s_invoke.get());
    useVars = state.index.lookup_closure_use_vars(f);
  }
  auto uvIt = useVars.begin();

  auto const privateProps   = state.index.lookup_private_props(&cls);
  auto const privateStatics = state.index.lookup_private_statics(&cls);
  for (auto& prop : cls.properties) {
    auto const makeRat = [&] (const Type& ty) -> RepoAuthType {
      if (ty.couldBe(TCls)) {
        return RepoAuthType{};
      }
      auto const rat = make_repo_type(*state.index.array_table_builder(), ty);
      merge_repo_auth_type(ue, rat);
      return rat;
    };

    auto const privPropTy = [&] (const PropState& ps) -> Type {
      if (is_closure(cls)) {
        // For closures use variables will be the first properties of the
        // closure object, in declaration order
        if (uvIt != useVars.end()) return *uvIt++;
        return Type{};
      }

      auto it = ps.find(prop.name);
      if (it == end(ps)) return Type{};
      return it->second;
    };

    Type propTy;
    auto const attrs = prop.attrs;
    if (attrs & AttrPrivate) {
      propTy = privPropTy((attrs & AttrStatic) ? privateStatics : privateProps);
    } else if ((attrs & AttrPublic) && (attrs & AttrStatic)) {
      propTy = state.index.lookup_public_static(&cls, prop.name);
    }

    pce->addProperty(
      prop.name,
      prop.attrs,
      prop.typeConstraint,
      prop.docComment,
      &prop.val,
      makeRat(propTy)
    );
  }
  assert(uvIt == useVars.end());

  for (auto& cconst : cls.constants) {
    if (!cconst.val.hasValue()) {
      pce->addAbstractConstant(
        cconst.name,
        cconst.typeConstraint,
        cconst.isTypeconst
      );
    } else {
      pce->addConstant(
        cconst.name,
        cconst.typeConstraint,
        &cconst.val.value(),
        cconst.phpCode,
        cconst.isTypeconst
      );
    }
  }

  pce->setEnumBaseTy(cls.enumBaseTy);
}
Example #5
0
int main(int argc, char *argv[])
{
    struct GModule *module;
    struct
    {
	struct Option *rastin, *rastout, *method, *quantile;
    } parm;
    struct
    {
	struct Flag *nulls, *weight;
    } flag;
    struct History history;
    char title[64];
    char buf_nsres[100], buf_ewres[100];
    struct Colors colors;
    int row;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("resample"));
    module->description =
	_("Resamples raster map layers to a coarser grid using aggregation.");

    parm.rastin = G_define_standard_option(G_OPT_R_INPUT);

    parm.rastout = G_define_standard_option(G_OPT_R_OUTPUT);

    parm.method = G_define_option();
    parm.method->key = "method";
    parm.method->type = TYPE_STRING;
    parm.method->required = NO;
    parm.method->description = _("Aggregation method");
    parm.method->options = build_method_list();
    parm.method->answer = "average";

    parm.quantile = G_define_option();
    parm.quantile->key = "quantile";
    parm.quantile->type = TYPE_DOUBLE;
    parm.quantile->required = NO;
    parm.quantile->description = _("Quantile to calculate for method=quantile");
    parm.quantile->options = "0.0-1.0";
    parm.quantile->answer = "0.5";

    flag.nulls = G_define_flag();
    flag.nulls->key = 'n';
    flag.nulls->description = _("Propagate NULLs");

    flag.weight = G_define_flag();
    flag.weight->key = 'w';
    flag.weight->description = _("Weight according to area (slower)");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    nulls = flag.nulls->answer;

    method = find_method(parm.method->answer);
    if (method < 0)
	G_fatal_error(_("Unknown method <%s>"), parm.method->answer);

    if (menu[method].method == c_quant) {
	quantile = atoi(parm.quantile->answer);
	closure = &quantile;
    }

    G_get_set_window(&dst_w);

    /* set window to old map */
    Rast_get_cellhd(parm.rastin->answer, "", &src_w);

    /* enlarge source window */
    {
	int r0 = (int)floor(Rast_northing_to_row(dst_w.north, &src_w));
	int r1 = (int)ceil(Rast_northing_to_row(dst_w.south, &src_w));
	int c0 = (int)floor(Rast_easting_to_col(dst_w.west, &src_w));
	int c1 = (int)ceil(Rast_easting_to_col(dst_w.east, &src_w));

	src_w.south -= src_w.ns_res * (r1 - src_w.rows);
	src_w.north += src_w.ns_res * (-r0);
	src_w.west -= src_w.ew_res * (-c0);
	src_w.east += src_w.ew_res * (c1 - src_w.cols);
	src_w.rows = r1 - r0;
	src_w.cols = c1 - c0;
    }

    Rast_set_input_window(&src_w);
    Rast_set_output_window(&dst_w);

    row_scale = 2 + ceil(dst_w.ns_res / src_w.ns_res);
    col_scale = 2 + ceil(dst_w.ew_res / src_w.ew_res);

    /* allocate buffers for input rows */
    bufs = G_malloc(row_scale * sizeof(DCELL *));
    for (row = 0; row < row_scale; row++)
	bufs[row] = Rast_allocate_d_input_buf();

    /* open old map */
    infile = Rast_open_old(parm.rastin->answer, "");

    /* allocate output buffer */
    outbuf = Rast_allocate_d_output_buf();

    /* open new map */
    outfile = Rast_open_new(parm.rastout->answer, DCELL_TYPE);

    if (flag.weight->answer && menu[method].method_w)
	resamp_weighted();
    else
	resamp_unweighted();

    G_percent(dst_w.rows, dst_w.rows, 2);

    Rast_close(infile);
    Rast_close(outfile);

    /* record map metadata/history info */
    sprintf(title, "Aggregate resample by %s", parm.method->answer);
    Rast_put_cell_title(parm.rastout->answer, title);

    Rast_short_history(parm.rastout->answer, "raster", &history);
    Rast_set_history(&history, HIST_DATSRC_1, parm.rastin->answer);
    G_format_resolution(src_w.ns_res, buf_nsres, src_w.proj);
    G_format_resolution(src_w.ew_res, buf_ewres, src_w.proj);
    Rast_format_history(&history, HIST_DATSRC_2,
			"Source map NS res: %s   EW res: %s",
			buf_nsres, buf_ewres);
    Rast_command_history(&history);
    Rast_write_history(parm.rastout->answer, &history);

    /* copy color table from source map */
    if (strcmp(parm.method->answer, "sum") != 0) {
	if (Rast_read_colors(parm.rastin->answer, "", &colors) < 0)
	    G_fatal_error(_("Unable to read color table for %s"),
			  parm.rastin->answer);
	Rast_mark_colors_as_fp(&colors);
	Rast_write_colors(parm.rastout->answer, G_mapset(), &colors);
    }

    return (EXIT_SUCCESS);
}
Example #6
0
// Combine the given delegated method with the existing one, if any, in the
// given entity.
// The trait_ref is the entry in the delegates list that causes this method
// inclusion. Needed for error reporting.
// Returns true on success, false on failure in which case an error will have
// been reported.
static bool delegated_method(ast_t* entity, ast_t* method, ast_t* field,
  ast_t* trait_ref, pass_opt_t* opt)
{
  assert(entity != NULL);
  assert(method != NULL);
  assert(is_method(method));
  assert(field != NULL);
  assert(trait_ref != NULL);

  if(ast_id(method) == TK_NEW)  // Don't delegate constructors.
    return true;

  // Check for existing method of the same name.
  const char* name = ast_name(ast_childidx(method, 1));
  assert(name != NULL);

  ast_t* existing = find_method(entity, name);

  if(existing != NULL)
  {
    // We already have a method with this name.
    method_t* info = (method_t*)ast_data(existing);
    assert(info != NULL);

    // Nothing new to add.
    if(info->local_define || info->delegated_field == field)
      return true;

    assert(info->trait_ref != NULL);

    ast_error(opt->check.errors, trait_ref,
      "clashing delegates for method %s, local disambiguation required", name);
    ast_error_continue(opt->check.errors, trait_ref,
      "field %s delegates to %s here", ast_name(ast_child(field)), name);
    ast_error_continue(opt->check.errors, info->trait_ref,
      "field %s delegates to %s here",
      ast_name(ast_child(info->delegated_field)), name);
    info->failed = true;
    info->delegated_field = NULL;
    return false;
  }

  // This is a new method, reify and add it.
  ast_t* reified = reify_provides_type(method, trait_ref, opt);

  // Reification error, already reported
  if(reified == NULL)
    return false;

  ast_t* new_method = add_method(entity, trait_ref, reified, "delegate", opt);

  if(new_method == NULL)
  {
    ast_free_unattached(reified);
    return false;
  }

  // Convert the newly added method into a delegation redirection.
  make_delegation(new_method, field, trait_ref, entity);
  return true;
}
Example #7
0
File: main.c Project: caomw/grass
int main(int argc, char **argv)
{
    RASTER3D_Map *input;
    RASTER3D_Map *output;
    RASTER3D_Region region;
    struct GModule *module;
    stat_func *method_fn;
    double quantile;
    int x, y, z;

    /* Initialize GRASS */
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster3d"));
    G_add_keyword(_("neighbor"));
    G_add_keyword(_("aggregation"));
    G_add_keyword(_("statistics"));
    G_add_keyword(_("filter"));
    module->description =
	_("Makes each voxel value a "
	  "function of the values assigned to the voxels "
	  "around it, and stores new voxel values in an output 3D raster map");

    /* Get parameters from user */
    set_params();

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    if (NULL == G_find_raster3d(param.input->answer, ""))
	Rast3d_fatal_error(_("3D raster map <%s> not found"),
			   param.input->answer);

    Rast3d_init_defaults();
    Rast3d_get_window(&region);

    nx = region.cols;
    ny = region.rows;
    nz = region.depths;

    /* Size fo the moving window */
    x_size = atoi(param.window->answers[0]);
    y_size = atoi(param.window->answers[1]);
    z_size = atoi(param.window->answers[2]);

    /* Distances in all directions */
    x_dist = x_size / 2;
    y_dist = y_size / 2;
    z_dist = z_size / 2;

    /* Maximum size of the buffer */
    size = x_size * y_size * z_size;

    /* Set the computation method */
    method_fn = menu[find_method(param.method->answer)].method;

    if (param.quantile->answer)
	quantile = atof(param.quantile->answer);
    else
	quantile = 0.0;

    input = Rast3d_open_cell_old(param.input->answer,
				 G_find_raster3d(param.input->answer, ""),
				 &region, RASTER3D_TILE_SAME_AS_FILE,
				 RASTER3D_USE_CACHE_DEFAULT);

    if (input == NULL)
	Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"),
			   param.input->answer);

    output =
	Rast3d_open_new_opt_tile_size(param.output->answer,
				      RASTER3D_USE_CACHE_X, &region,
				      DCELL_TYPE, 32);

    if (output == NULL)
	Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"),
			   param.output->answer);

    Rast3d_min_unlocked(output, RASTER3D_USE_CACHE_X);
    Rast3d_autolock_on(output);
    Rast3d_unlock_all(output);

    DCELL *buff = NULL, value;

    buff = (DCELL *) calloc(size, sizeof(DCELL));

    if (buff == NULL)
	Rast3d_fatal_error(_("Unable to allocate buffer"));

    for (z = 0; z < nz; z++) {
	for (y = 0; y < ny; y++) {
	    for (x = 0; x < nx; x++) {
		/* Gather values in moving window */
		int num = gather_values(input, buff, x, y, z);

		/* Compute the resulting value */
		if (num > 0)
		    (*method_fn) (&value, buff, num, &quantile);
		else
		    Rast_set_d_null_value(&value, 1);
		/* Write the value */
		Rast3d_put_double(output, x, y, z, value);
	    }
	}
    }

    free(buff);

    if (!Rast3d_flush_all_tiles(output))
	G_fatal_error(_("Error flushing tiles"));

    Rast3d_autolock_off(output);
    Rast3d_unlock_all(output);

    Rast3d_close(input);
    Rast3d_close(output);

    return 0;
}
Example #8
0
// Combine the given inherited method with the existing one, if any, in the
// given entity.
// The provided method must already be reified.
// The trait_ref is the entry in the provides list that causes this method
// inclusion. Needed for error reporting.
// Returns true on success, false on failure in which case an error will have
// been reported.
static bool add_method_from_trait(ast_t* entity, ast_t* method,
  ast_t* trait_ref, pass_opt_t* opt)
{
  assert(entity != NULL);
  assert(method != NULL);
  assert(trait_ref != NULL);

  AST_GET_CHILDREN(method, cap, id, t_params, params, result, error,
    method_body);

  const char* method_name = ast_name(id);
  ast_t* existing_method = find_method(entity, method_name);

  if(existing_method == NULL)
  {
    // We don't have a method yet with this name, add the one from this trait.
    ast_t* m = add_method(entity, trait_ref, method, "provided", opt);

    if(m == NULL)
      return false;

    if(ast_id(ast_childidx(m, 6)) != TK_NONE)
      ast_visit(&m, rescope, NULL, opt, PASS_ALL);

    return true;
  }

  // A method with this name already exists.
  method_t* info = (method_t*)ast_data(existing_method);
  assert(info != NULL);

  // Method has already caused an error, do nothing.
  if(info->failed)
    return false;

  if(info->local_define || info->delegated_field != NULL)
    return true;

  // Existing method is also provided, signatures must match exactly.
  if(!compare_signatures(existing_method, method))
  {
    assert(info->trait_ref != NULL);

    ast_error(opt->check.errors, trait_ref,
      "clashing definitions for method '%s' provided, local disambiguation "
      "required",
      method_name);
    ast_error_continue(opt->check.errors, trait_ref,
      "provided here, type: %s",
      ast_print_type(method));
    ast_error_continue(opt->check.errors, info->trait_ref,
      "and here, type: %s",
      ast_print_type(existing_method));

    info->failed = true;
    return false;
  }

  // Resolve bodies, if any.
  ast_t* existing_body = ast_childidx(existing_method, 6);

  bool multiple_bodies =
    (info->body_donor != NULL) &&
    (ast_id(method_body) != TK_NONE) &&
    (info->body_donor != (ast_t*)ast_data(method));

  if(multiple_bodies ||
    ast_checkflag(existing_method, AST_FLAG_AMBIGUOUS) ||
    ast_checkflag(method, AST_FLAG_AMBIGUOUS))
  {
    // This method body ambiguous, which is not necessarily an error.
    ast_setflag(existing_method, AST_FLAG_AMBIGUOUS);

    if(ast_id(existing_body) != TK_NONE) // Ditch existing body.
      ast_replace(&existing_body, ast_from(existing_method, TK_NONE));

    info->body_donor = NULL;
    return true;
  }

  // No new body to resolve.
  if((ast_id(method_body) == TK_NONE) ||
    (info->body_donor == (ast_t*)ast_data(method)))
    return true;

  // Trait provides default body. Use it and patch up symbol tables.
  assert(ast_id(existing_body) == TK_NONE);
  ast_replace(&existing_body, method_body);
  ast_visit(&method_body, rescope, NULL, opt, PASS_ALL);

  info->body_donor = (ast_t*)ast_data(method);
  info->trait_ref = trait_ref;
  return true;
}
Example #9
0
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
 {

  if(intifinit)
  {
    return JNI_VERSION_1_6;
  }
  intifinit = 1;
  MSImageRef image_time;
  image_time = MSGetImageByName("/system/lib/libc.so");

  int (*gettimeofday_org)(struct timeval*tv, struct timezone *tz);
  gettimeofday_org = (int (*)(struct timeval*tv, struct timezone *tz)) MSFindSymbol(image_time, "gettimeofday");

  int (*clock_gettime_org)(clockid_t clk_id,struct timespec *tp);
  clock_gettime_org = (int (*)(clockid_t clk_id,struct timespec *tp)) MSFindSymbol(image_time, "clock_gettime");
  
 
  //MSHookFunction((void *)gettimeofday_org, (void*)gettimeofday_hook, (void**)&gettimeofday_f);
  //MSHookFunction((void *)clock_gettime_org, (void*)clock_gettime_hook, (void**)&clock_gettime_f);


 	MSImageRef image;
 	image = MSGetImageByName("/data/data/com.babeltime.fknsango_gwphone/lib/libgame.so");
  LOGD("image is %d" , image) ;
 	void *(*lua_loadbuffer_org_sym)(void *,  char *s, long len,void *s2,void *s5);
 	lua_loadbuffer_org_sym = (void * (*)(void *,  char *s, long len,void *s2,void *s5)) MSFindSymbol(image, "luaL_loadbufferx");
	//lua_gettop =(int (*) (void*)) MSFindSymbol(image, "lua_gettop") ;
 	lua_pcall= (int (*) (void *L, int nargs, int nresults, int errfunc))MSFindSymbol(image, "lua_pcall") ; 
  lua_gettop= (int (*) (void *L))MSFindSymbol(image, "lua_gettop") ; 
  lua_type= (int (*)(void *L,int i))MSFindSymbol(image, "lua_type") ; 
  lua_typename= (char* (* )(void *L, int a2))MSFindSymbol(image, "lua_typename") ; 
  lua_tolstring= (char* (*)(void *L, signed int a2, int a3))MSFindSymbol(image, "lua_tolstring") ; 
  _Z17getPackageNameJNIv = (  char* (* )(std::string &s  ))  MSFindSymbol(image, "_Z17getPackageNameJNIv");
  
  ; 
  _ZN7cocos2d18CCFileUtilsAndroid15getWritablePathEv = (std::string (*)(int a1)) MSFindSymbol(image,"_ZN7cocos2d18CCFileUtilsAndroid15getWritablePathEv") ;
  MSHookFunction((void *)_ZN7cocos2d18CCFileUtilsAndroid15getWritablePathEv, (void*)my_ZN7cocos2d18CCFileUtilsAndroid15getWritablePathEv, (void**)&_ZN7cocos2d18CCFileUtilsAndroid15getWritablePathEv);



	//lua_getfield = ( void (*) (void *L, int index, const char *k)) MSFindSymbol(image, "lua_getfield") ; 
	//MSHookFunction( (void *)lua_getfield,(void*)mylua_getfield,(void**)&lua_getfield);
	if(lua_loadbuffer_org_sym != NULL)
 	 {
 	 	//LOGD("lua_pushlstring_org_sym is %p!!!!!!!!!!!!\n",lua_loadbuffer_org_sym);
 	 	MSHookFunction((void *)lua_loadbuffer_org_sym, (void*)lua_loadbuffer_hook, (void**)&lua_loadbuffer_f);
 	 }
 	 else
 	 {
 	 //	LOGD("lua_pushlstring_org no find!!!!!!!!!!!!!!!!!!\n");
 	 }
   
 




 	//以下为hook java的,为了显示按钮
  JNIEnv *env = GetEnv(vm);
  MSImageRef dvm_image = MSGetImageByName("/system/lib/libc.so");
  void *gp = dlopen("/data/data/com.youzu.snsgz.linyou.youmi/lib/libsubstrate-dvm.so",RTLD_LAZY);
  cydia_dvm_image = MSGetImageByName("/data/data/sh.lilith.dgame.lemon/lib/libsubstrate-dvm.so");
  LOGD("dlopen %d , dvm %d" , gp , cydia_dvm_image) ; 

  jclass gameutil = env->FindClass("com/youzu/sanguohero/GameUtils");
  jmethodID getBRAND = env->GetStaticMethodID( gameutil, "getBRAND","()Ljava/lang/String;");
  jstring jstr =  (jstring)env->CallStaticObjectMethod( gameutil,getBRAND);
  const char* str;  
  str = env->GetStringUTFChars(jstr, false);  
  LOGD("getBRAND %s" , str) ; 
  if( strstr(str,"Meizu") != NULL) {
      return JNI_VERSION_1_6 ;
  }

  find_method = (void (*)(JNIEnv *, jclass , jmethodID , void *, void **)) MSFindSymbol(cydia_dvm_image, "MSJavaHookMethod");
  const char *target_class = "android/app/Instrumentation";//对大部分app来说,这是一个父类
  jvm_org = vm;
  jclass clazzTarget = env->FindClass(target_class);
   
  const char *fun_show = "init",*fun_hid = "hidden";
  javaClientClass_org = env->FindClass("com/youzu/sanguohero/TestWM");
   
  inject_method_show = env->GetStaticMethodID(javaClientClass_org, fun_show, "(Landroid/app/Activity;)V");
  
  inject_method_hidden = env->GetStaticMethodID(javaClientClass_org, fun_hid, "(Landroid/app/Activity;)V");
   
  //显示按钮
  jmethodID method_resume = env->GetMethodID(clazzTarget,
                 "callActivityOnResume",
                 "(Landroid/app/Activity;)V"
             );

  //隐藏按钮
  jmethodID method_pause = env->GetMethodID(clazzTarget,
                   "callActivityOnPause",
                   "(Landroid/app/Activity;)V"
               );


  find_method(env, clazzTarget, method_resume, reinterpret_cast<void *>(&newCodejava_show),reinterpret_cast<void **>(&oldCode_java_show));
  find_method(env, clazzTarget, method_pause, reinterpret_cast<void *>(&newCodejava_hidden),reinterpret_cast<void **>(&oldCode_java_hidden));

  DetachCurrent(vm);
   
  return JNI_VERSION_1_6;
 }
Example #10
0
int main(int argc, char *argv[])
{
    struct GModule *module;
    struct
    {
	struct Option *input, *output, *method, *quantile, *range;
    } parm;
    struct
    {
	struct Flag *nulls;
    } flag;
    int i;
    int num_inputs;
    struct input *inputs;
    int num_outputs;
    struct output *outputs;
    struct History history;
    DCELL *values, *values_tmp;
    int nrows, ncols;
    int row, col;
    double lo, hi;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("series"));
    module->description =
	_("Makes each output cell value a "
	  "function of the values assigned to the corresponding cells "
	  "in the input raster map layers.");

    parm.input = G_define_standard_option(G_OPT_R_INPUTS);

    parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
    parm.output->multiple = YES;

    parm.method = G_define_option();
    parm.method->key = "method";
    parm.method->type = TYPE_STRING;
    parm.method->required = YES;
    parm.method->options = build_method_list();
    parm.method->description = _("Aggregate operation");
    parm.method->multiple = YES;

    parm.quantile = G_define_option();
    parm.quantile->key = "quantile";
    parm.quantile->type = TYPE_DOUBLE;
    parm.quantile->required = NO;
    parm.quantile->description = _("Quantile to calculate for method=quantile");
    parm.quantile->options = "0.0-1.0";
    parm.quantile->multiple = YES;

    parm.range = G_define_option();
    parm.range->key = "range";
    parm.range->type = TYPE_DOUBLE;
    parm.range->key_desc = "lo,hi";
    parm.range->description = _("Ignore values outside this range");

    flag.nulls = G_define_flag();
    flag.nulls->key = 'n';
    flag.nulls->description = _("Propagate NULLs");

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    if (parm.range->answer) {
	lo = atof(parm.range->answers[0]);
	hi = atof(parm.range->answers[1]);
    }

    /* process the input maps */
    for (i = 0; parm.input->answers[i]; i++)
	;
    num_inputs = i;

    if (num_inputs < 1)
	G_fatal_error(_("Raster map not found"));

    inputs = G_malloc(num_inputs * sizeof(struct input));

    for (i = 0; i < num_inputs; i++) {
	struct input *p = &inputs[i];

	p->name = parm.input->answers[i];
	G_message(_("Reading raster map <%s>..."), p->name);
	p->fd = Rast_open_old(p->name, "");
	p->buf = Rast_allocate_d_buf();
    }

    /* process the output maps */
    for (i = 0; parm.output->answers[i]; i++)
	;
    num_outputs = i;

    for (i = 0; parm.method->answers[i]; i++)
	;
    if (num_outputs != i)
	G_fatal_error(_("output= and method= must have the same number of values"));

    outputs = G_calloc(num_outputs, sizeof(struct output));

    for (i = 0; i < num_outputs; i++) {
	struct output *out = &outputs[i];
	const char *output_name = parm.output->answers[i];
	const char *method_name = parm.method->answers[i];
	int method = find_method(method_name);

	out->name = output_name;
	out->method_fn = menu[method].method;
	out->quantile = (parm.quantile->answer && parm.quantile->answers[i])
	    ? atof(parm.quantile->answers[i])
	    : 0;
	out->buf = Rast_allocate_d_buf();
	out->fd = Rast_open_new(output_name,
				menu[method].is_int ? CELL_TYPE : DCELL_TYPE);
    }

    /* initialise variables */
    values = G_malloc(num_inputs * sizeof(DCELL));
    values_tmp = G_malloc(num_inputs * sizeof(DCELL));

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();

    /* process the data */
    G_verbose_message(_("Percent complete..."));

    for (row = 0; row < nrows; row++) {
	G_percent(row, nrows, 2);

	for (i = 0; i < num_inputs; i++)
	    Rast_get_d_row(inputs[i].fd, inputs[i].buf, row);

	for (col = 0; col < ncols; col++) {
	    int null = 0;

	    for (i = 0; i < num_inputs; i++) {
		DCELL v = inputs[i].buf[col];

		if (Rast_is_d_null_value(&v))
		    null = 1;
		else if (parm.range->answer && (v < lo || v > hi)) {
		    Rast_set_d_null_value(&v, 1);
		    null = 1;
		}

		values[i] = v;
	    }

	    for (i = 0; i < num_outputs; i++) {
		struct output *out = &outputs[i];

		if (null && flag.nulls->answer)
		    Rast_set_d_null_value(&out->buf[col], 1);
		else {
		    memcpy(values_tmp, values, num_inputs * sizeof(DCELL));
		    (*out->method_fn)(&out->buf[col], values_tmp, num_inputs, &out->quantile);
		}
	    }
	}

	for (i = 0; i < num_outputs; i++)
	    Rast_put_d_row(outputs[i].fd, outputs[i].buf);
    }

    G_percent(row, nrows, 2);

    /* close maps */
    for (i = 0; i < num_outputs; i++) {
	struct output *out = &outputs[i];

	Rast_close(out->fd);

	Rast_short_history(out->name, "raster", &history);
	Rast_command_history(&history);
	Rast_write_history(out->name, &history);
    }

    for (i = 0; i < num_inputs; i++)
	Rast_close(inputs[i].fd);

    exit(EXIT_SUCCESS);
}
Example #11
0
static DBusHandlerResult
on_message(DBusConnection *connection,
           DBusMessage    *message,
           void           *user_data)
{
  SeedContext ctx;
  const char *path;
  DBusHandlerResult result;
  SeedObject obj;
  const char *method_name;
  char *async_method_name;
  SeedValue method_value;
  DBusMessage *reply;
  Exports *priv;

  priv = user_data;
  async_method_name = NULL;
  reply = NULL;

  ctx = seed_context_create (group, NULL);
  seed_prepare_global_context (ctx);

  if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

  method_value = seed_make_undefined (ctx);

  result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

  path = dbus_message_get_path(message);

  obj = find_js_property_by_path(ctx,
				 priv->object,
				 path);
    if (obj == NULL)
      {
        g_warning("There is no JS object at %s",
                  path);
        goto out;
      }

    method_name = dbus_message_get_member(message);

    async_method_name = g_strdup_printf("%sAsync", method_name);

    /* try first if an async version exists */
    if (find_method(ctx,
                    obj,
                    async_method_name,
                    &method_value)) {

      g_warning ("Invoking async method %s on JS obj at dbus path %s",
		 async_method_name, path);

        reply = invoke_js_async_from_dbus(ctx,
                                          priv->which_bus,
                                          message,
                                          obj,
                                          method_value,
					  NULL); // Need exception here.

        result = DBUS_HANDLER_RESULT_HANDLED;

    /* otherwise try the sync version */
    } else if (find_method(ctx,
                           obj,
                           method_name,
                           &method_value)) {

      g_warning("Invoking method %s on JS obj at dbus path %s",
                  method_name, path);

        reply = invoke_js_from_dbus(ctx,
                                    message,
                                    obj,
				    method_value,
				    NULL); // Need exception here

        result = DBUS_HANDLER_RESULT_HANDLED;
    /* otherwise FAIL */
    } else {
      g_warning("There is a JS object at %s but it has no method %s",
                  path, method_name);
    }

    if (reply != NULL) {
        dbus_connection_send(connection, reply, NULL);
        dbus_message_unref(reply);
    }

out:
    seed_context_unref (ctx);
    if (async_method_name)
        g_free(async_method_name);
    return result;
}
Example #12
0
/**
 * Call a java static method from the VM
 * NOTE: This can only be used to call methods that have a signature
 * value that is less than 255. Normally it will be used to call
 * one of the specialsignature entries (which are all less than 255).
 */
void dispatch_java(byte classIndex, byte sig, byte *retAddr, byte *btAddr)
{
  ClassRecord *classRecord = get_class_record (classIndex);
  MethodRecord *mRec = find_method (classRecord, sig);
  dispatch_special_checked(classIndex, mRec - get_method_table(classRecord), retAddr, btAddr);
}