Esempio n. 1
0
static void
gum_v8_probe_args_on_get_nth (uint32_t index,
                              const PropertyCallbackInfo<Value> & info)
{
  Handle<Object> instance = info.This ();
  GumV8CallProbe * self = static_cast<GumV8CallProbe *> (
      instance->GetAlignedPointerFromInternalField (0));
  GumCallSite * site = static_cast<GumCallSite *> (
      instance->GetAlignedPointerFromInternalField (1));
  gsize value;
  gsize * stack_argument = static_cast<gsize *> (site->stack_data);

#if defined (HAVE_I386) && GLIB_SIZEOF_VOID_P == 8
  switch (index)
  {
# if GUM_NATIVE_ABI_IS_UNIX
    case 0: value = site->cpu_context->rdi; break;
    case 1: value = site->cpu_context->rsi; break;
    case 2: value = site->cpu_context->rdx; break;
    case 3: value = site->cpu_context->rcx; break;
    case 4: value = site->cpu_context->r8;  break;
    case 5: value = site->cpu_context->r9;  break;
    default:
      value = stack_argument[index - 6];
      break;
# else
    case 0: value = site->cpu_context->rcx; break;
    case 1: value = site->cpu_context->rdx; break;
    case 2: value = site->cpu_context->r8;  break;
    case 3: value = site->cpu_context->r9;  break;
    default:
      value = stack_argument[index];
      break;
# endif
  }
#else
  value = stack_argument[index];
#endif

  info.GetReturnValue ().Set (
      _gum_v8_native_pointer_new (GSIZE_TO_POINTER (value), self->parent->core));
}
Esempio n. 2
0
v8::Handle<v8::Value> v8Sprite::RenderTo(const v8::Arguments &args) {
	HandleScope scope;

	v8Sprite *spriteWrapper = ObjectWrap::Unwrap<v8Sprite>(args.Holder());

	if (NULL == spriteWrapper) {
		return ThrowException(v8::Exception::ReferenceError(String::NewSymbol(
			"Sprite::renderTo(): NULL Holder."
		)));
	}

	// This is kinda strange, but I can't think of a simpler way to handle
	// dynamically accepting both Canvas and Window in a secure (e.g. not
	// depending on (mutable) JavaScript state to determine which to use) way.
	// We'll manually unwrap the internal pointer, and use RTTI to determine
	// which class of instance we have been passed.
	Handle<Object> instanceHandle = args[0]->ToObject();

	if (instanceHandle.IsEmpty() || 0 == instanceHandle->InternalFieldCount()) {
		return ThrowException(v8::Exception::ReferenceError(String::NewSymbol(
			"Sprite::render(): NULL destination."
		)));
	}

	ObjectWrap *instance = static_cast<ObjectWrap *>(
		instanceHandle->GetAlignedPointerFromInternalField(0)
	);

	v8Canvas *destinationCanvas = dynamic_cast<v8Canvas *>(instance);
	v8Window *destinationWindow = dynamic_cast<v8Window *>(instance);

	if (destinationCanvas) {
		spriteWrapper->sprite->renderTo(destinationCanvas->wrappedCanvas());
	}
	else {
		spriteWrapper->sprite->renderTo(destinationWindow->wrappedWindow());
	}

	return v8::Undefined();
}