小编Sti*_*rds的帖子

交换属性GetMethod实现运行时

我目前正在尝试通过用一些IL替换它来交换属性获取实现.我正在使用这个问题作为参考:如何替换指向从系统类继承的方法类中的方法的指针?

我唯一的区别是我的方法是通过MethodBuilder声明的:

MethodBuilder propertyGetBuilder = builder.DefineMethod
(
    dynamicFunctionName,
    MethodAttributes.Public,
    propertyInfo.PropertyType,
    Type.EmptyTypes
);

ILGenerator propertyGetIlGenerator = propertyGetBuilder.GetILGenerator();

propertyGetIlGenerator.Emit(OpCodes.Ldarg_0);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, propertyInfo.Name);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, relationKeyField.Name);
propertyGetIlGenerator.Emit(OpCodes.Ldstr, relationAttribute.RelationColumn);
propertyGetIlGenerator.Emit(OpCodes.Call, loadRelationMethod);

propertyGetIlGenerator.Emit(OpCodes.Ret);
Run Code Online (Sandbox Code Playgroud)

这会为生成的类型添加一个新函数 BeforeGet{PropertyName}

生成新类型后,我实例化它以确保内存地址存在: dynamic fakeType = Activator.CreateInstance(type);

我从现有类中检索propertyInfo GetMethod,以及新创建的BeforeGet{PropertyName}fakeType类Type.

之后,在此函数中使用了两个MethodInfo:

RuntimeHelpers.PrepareMethod(methodA.MethodHandle);
RuntimeHelpers.PrepareMethod(methodB.MethodHandle);

unsafe
{
    if (IntPtr.Size == 4)
    {
        int* inj = (int*)methodA.MethodHandle.Value.ToPointer() + 2;
        int* tar = (int*)methodB.MethodHandle.Value.ToPointer() + 2;
#if DEBUG
        Console.WriteLine("\nVersion x86 Debug?\n");

        byte* injInst = (byte*)*inj;
        byte* tarInst = (byte*)*tar;

        int* injSrc = (int*)(injInst + 1);
        int* …
Run Code Online (Sandbox Code Playgroud)

c# pointers

10
推荐指数
1
解决办法
373
查看次数

Mono mkbundle抛出'IKVM.Reflection.BadImageFormatException'

我一直在尝试使用mkbundle编译或捆绑我的应用程序.这是我正在执行的脚本:

set -o errexit
set -o nounset

mono_version="3.2.3"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version

machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.0\\machine.config

export PATH=$PATH:$MONO/bin

export PKG_CONFIG_PATH=$MONO/lib/pkgconfig

icon_name='"icon.ico"'

echo "1 ICON $icon_name" > icon.rc

export CC="i686-pc-mingw32-gcc icon.o -U _WIN32"

output_name=Output.exe

mkbundle JiraTempoApp.exe MonoPosixHelper.dll gtk-sharp.dll glib-sharp.dll atk-sharp.dll gdk-sharp.dll glade-sharp.dll glib-sharp.dll pango-sharp.dll RestSharp.dll JiraRestLib.dll --deps --machine-config "$machineconfig" -o $output_name -z

rm icon.rc 
rm icon.o

cp $MONO/bin/mono-2.0.dll .
cp $MONO/bin/zlib1.dll .

./$output_name
Run Code Online (Sandbox Code Playgroud)

我不得不添加MonoPosixHelper.dll,因为我找不到EntryPoint错误.现在我得到了这个奇怪的错误:

$ ./mkbundle_cygwin.sh
OS is: Windows
WARNING:
  Check that the machine.config file you are bundling
  doesn't contain sensitive information specific to this machine. …
Run Code Online (Sandbox Code Playgroud)

c# deployment mono mkbundle

7
推荐指数
1
解决办法
1243
查看次数

TouchEvent在Firefox和其他网站浏览器中不起作用

我有一个问题,在Chrome中运行良好,但在Firefox中无法启动

function normalizeEvent(e){     
  if(e.originalEvent instanceof TouchList){
    do somethings    
   }
}
Run Code Online (Sandbox Code Playgroud)

这是消息错误:ReferenceError:未定义TouchEvent

if(e.originalEvent instanceof TouchEvent){}
Run Code Online (Sandbox Code Playgroud)

javascript firefox html5

4
推荐指数
1
解决办法
2279
查看次数

标签 统计

c# ×2

deployment ×1

firefox ×1

html5 ×1

javascript ×1

mkbundle ×1

mono ×1

pointers ×1