开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 7322|回复: 15
打印 上一主题 下一主题
收起左侧

[C#求助] 易语言 置入代码() 这个命令在C#怎么写?

[复制链接]
跳转到指定楼层
楼主
发表于 2023-8-24 20:22:27 | 只看该作者 回帖奖励 |正序浏览 |阅读模式   河北省廊坊市
易语言 置入代码() 这个命令在C#怎么写?
结帖率:100% (1/1)

签到天数: 4 天

16
发表于 2024-3-29 06:27:26 | 只看该作者   贵州省黔南布依族苗族自治州
都用C#了 还有必要用汇编吗..
他速度又不象易语言那么慢.
及时编译技术 只是在第一次使用函数时候进行编译而以. 第二次就快了.  或是直接AOT编译好了.
象千古风流服务端 就是C# 搞的. 人家几千人在线 都没啥问题.
还只是跑 Debug版  没跑 Release 版..
越高版本的.net优化得越好. 现在的性能都直逼C++. 甚至某些情况速度比c++还快. 感觉基本上用不到什么汇编. 一般最多调用点API就够了 ..
回复 支持 反对

使用道具 举报

15
发表于 2024-2-19 00:01:20 | 只看该作者   四川省成都市


using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;

/////////////////////////使用例子/////////////////////////////////
//f(a,b,c) = a*b+c
byte[] MulAdd_int64 =
            {
            0x55,               //push  rbp
            0x0f,0xaf,0xca,     //imul  rcx,rdx
            0x49,0x01,0xc8,     //add   r8,rcx
            0x49,0x8b,0xc0,     //mov   rax,r8
            0x5D,               //pop   rbp
            0xC3                //ret
            };

using ASM<Add> asm = new ASM<Add>(ref MulAdd_int64);
var result=asm.Invoke(12, 13, 14);
Console.WriteLine(result);
delegate long Add(long a, long b, long c);
////////////////////////////////////////////////////////////////


public static class Win32API
{
    [DllImport("kernel32.dll")]
    public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint fnp, out uint lp);
}
public class ASM<T> : IDisposable where T: Delegate
{
    private readonly byte[] data;

    private IntPtr ptr;

    public T Invoke;
    public ASM(ref byte[] asm_code)
    {
        data = asm_code;
        ptr = Marshal.AllocHGlobal(data.Length);
        Marshal.Copy(asm_code, 0, ptr, data.Length);

        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr,(UIntPtr)data.Length, 0x40 , out uint _))
        {
            throw new Win32Exception();
        }

        Invoke = Marshal.GetDelegateForFunctionPointer<T>(ptr);
    }
    public void Dispose()
    {
        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr, (UIntPtr)data.Length, 0x04, out uint _))
        {
            throw new Win32Exception();
        }
        Marshal.FreeHGlobal(ptr);
    }
}
回复 支持 反对

使用道具 举报

14
发表于 2024-2-19 00:00:03 | 只看该作者   四川省成都市
2101726857 发表于 2024-2-18 23:59
重新发一下,之前的不知道为什么有乱码
[mw_shl_code=csharp,true]using System.Diagnostics;
using Syst ...

靠,还是有乱码
回复 支持 反对

使用道具 举报

13
发表于 2024-2-18 23:59:31 | 只看该作者   四川省成都市
wuxinglong71 发表于 2024-2-18 16:36
大佬能封装一个方法不  ??怎么搞

重新发一下,之前的不知道为什么有乱码
[C#] 纯文本查看 复制代码
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;

/////////////////////////使用例子/////////////////////////////////
//f(a,b,c) = a*b+c
byte[] MulAdd_int64 =
            {
            0x55,               //push  rbp
            0x0f,0xaf,0xca,     //imul  rcx,rdx
            0x49,0x01,0xc8,     //add   r8,rcx
            0x49,0x8b,0xc0,     //mov   rax,r8
            0x5D,               //pop   rbp
            0xC3                //ret
            };

using ASM<Add> asm = new ASM<Add>(ref MulAdd_int64);
var result=asm.Invoke(12, 13, 14);
Console.WriteLine(result);
delegate long Add(long a, long b, long c);
////////////////////////////////////////////////////////////////


public static class Win32API
{
    [DllImport("kernel32.dll")]
    public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpf噜阿噜dProtect);
}
public class ASM<T> : IDisposable where T: Delegate
{
    private readonly byte[] data;

    private IntPtr ptr;

    public T Invoke;
    public ASM(ref byte[] asm_code)
    {
        data = asm_code;
        ptr = Marshal.AllocHGlobal(data.Length);
        Marshal.Copy(asm_code, 0, ptr, data.Length);

        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr,(UIntPtr)data.Length, 0x40 , out uint _))
        {
            throw new Win32Exception();
        }

        Invoke = Marshal.GetDelegateForFunctionPointer<T>(ptr);
    }
    public void Dispose()
    {
        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr, (UIntPtr)data.Length, 0x04, out uint _))
        {
            throw new Win32Exception();
        }
        Marshal.FreeHGlobal(ptr);
    }
}
回复 支持 反对

使用道具 举报

12
发表于 2024-2-18 23:48:46 | 只看该作者   四川省成都市
wuxinglong71 发表于 2024-2-18 16:36
大佬能封装一个方法不  ??怎么搞


using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;

/////////////////////////使用例子/////////////////////////////////
//f(a,b,c) = a*b+c
byte[] MulAdd_int64 =
            {
            0x55,               //push  rbp
            0x0f,0xaf,0xca,     //imul  rcx,rdx
            0x49,0x01,0xc8,     //add   r8,rcx
            0x49,0x8b,0xc0,     //mov   rax,r8
            0x5D,               //pop   rbp
            0xC3                //ret
            };

using ASM<Add> asm = new ASM<Add>(ref MulAdd_int64);
var result=asm.Invoke(12, 13, 14);
Console.WriteLine(result);
delegate long Add(long a, long b, long c);
////////////////////////////////////////////////////////////////


public static class Win32API
{
    [DllImport("kernel32.dll")]
    public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpf噜阿噜dProtect);
}
public class ASM<T> : IDisposable where T: Delegate
{
    private readonly byte[] data;

    private IntPtr ptr;

    public T Invoke;
    public ASM(ref byte[] asm_code)
    {
        data = asm_code;
        ptr = Marshal.AllocHGlobal(data.Length);
        Marshal.Copy(asm_code, 0, ptr, data.Length);

        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr,(UIntPtr)data.Length, 0x40 , out uint _))
        {
            throw new Win32Exception();
        }

        Invoke = Marshal.GetDelegateForFunctionPointer<T>(ptr);
    }
    public void Dispose()
    {
        if (!Win32API.VirtualProtectEx(Process.GetCurrentProcess().Handle, ptr, (UIntPtr)data.Length, 0x04, out uint _))
        {
            throw new Win32Exception();
        }
        Marshal.FreeHGlobal(ptr);
    }
}
回复 支持 反对

使用道具 举报

签到天数: 3 天

11
 楼主| 发表于 2024-2-18 16:36:43 | 只看该作者   河北省廊坊市
2101726857 发表于 2024-2-17 21:00
using Iced.Intel;
using System.Collections;
using System.Diagnostics;

大佬能封装一个方法不  ??怎么搞
回复 支持 反对

使用道具 举报

10
发表于 2024-2-18 09:32:14 高大上手机用户 | 只看该作者   四川省成都市
阮少小哥哥 发表于 2024-2-18 03:07
易语言置入代码就是内嵌汇编

我晓得,但楼主问的是c#,c#版的我放在下面了。
回复 支持 反对

使用道具 举报

结帖率:94% (15/16)

签到天数: 4 天

9
发表于 2024-2-18 03:07:14 | 只看该作者   福建省宁德市
2101726857 发表于 2024-2-18 00:28
这个是c++的内嵌汇编

易语言置入代码就是内嵌汇编
回复 支持 反对

使用道具 举报

8
发表于 2024-2-18 00:28:05 高大上手机用户 | 只看该作者   四川省自贡市
阮少小哥哥 发表于 2023-8-24 20:34
__asm
    {
}好像是这个吧?

这个是c++的内嵌汇编
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表