首页
社区
课程
招聘
[未解决,已结帖] DLL文件导出函数调用 300.00雪花
发表于: 2020-12-27 21:27 3838

[未解决,已结帖] DLL文件导出函数调用 300.00雪花

2020-12-27 21:27
3838

大家好!麻烦请忙写一个DLL导出函数调用的例子,例子最好是用.NET或C++。
原来程序的逻辑是1.dll的GetMachineInfo通过API调用2.dll的GetMachineInfo。1.dll的GetMachineInfo我是通过dnSpy查找出来,但通过dnSpy修改不了,另导出源码修改又不能运行。所以请高手帮忙写个调用2.dll
GetMachineInfo的例子,谢谢

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    1.dll的GetMachineInfo
public unsafe string GetMachineInfo(string guardServerInfo)
    {
        LicenseService* ptr = <Module>.@new(2056UL);
        LicenseService* ptr2;
        try
        {
            ptr2 = ((ptr == null) ? null : <Module>.LicenseService.{ctor}(ptr));
        }
        catch
        {
            <Module>.delete((void*)ptr);
            throw;
        }
        LicenseService* ptr3 = ptr2;
        basic_string<char,std::char_traits<char>,std::allocator<char>\u0020> basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>;
        basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>* ptr4 = <Module>.ConvertStringClrToStd(&basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>, guardServerInfo);
        basic_string<char,std::char_traits<char>,std::allocator<char>\u0020> basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>2;
        <Module>.LicenseService.GetMachineInfo(ptr3, &basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>2, (basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>*)ptr4);
        string result;
        try
        {
            LicenseService* ptr5 = ptr3;
            if (ptr5 != null)
            {
                void* ptr6 = <Module>.LicenseService.__delDtor(ptr5, 1U);
            }
            result = new string(<Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>.c_str(ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>2));
        }
        catch
        {
            <Module>.___CxxCallUnwindDtor(ldftn(std.basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>.{dtor}), (void*)(&basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>2));
            throw;
        }
        <Module>.std.basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>.{dtor}(ref basic_string<char,std::char_traits<char>,std::allocator<char>_u0020>2);
        return result;
    }
 
 
API调用   
[SuppressUnmanagedCodeSecurity]
[DllImport("", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
[MethodImpl(MethodImplOptions.Unmanaged)]
public unsafe static extern basic_string<char,std::char_traits<char>,std::allocator<char>\u0020>* GetMachineInf

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

最后于 2021-1-16 19:19 被caicaisin编辑 ,原因:
上传的附件:
收藏
免费 0
支持
分享
最新回复 (12)
雪    币: 3622
活跃值: (2559)
能力值: ( LV6,RANK:83 )
在线值:
发帖
回帖
粉丝
2

lz,这个dll还有其他依赖文件,能否一起发上来?或者在你的环境中试一下附件文件

最后于 2020-12-28 00:26 被yegu编辑 ,原因:
上传的附件:
2020-12-28 00:08
0
雪    币: 49
活跃值: (817)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
您好,yegu !请问是缺那个文件?你的例子是直接调用1.dll的GetMachineInfo,我的目的想调用2.dll的GetMachineInfo;所以给出1.dll调用2.dll的参考例子。
上传的附件:
2020-12-28 08:26
0
雪    币: 3622
活跃值: (2559)
能力值: ( LV6,RANK:83 )
在线值:
发帖
回帖
粉丝
4
caicaisin 您好,yegu !请问是缺那个文件?你的例子是直接调用1.dll的GetMachineInfo,我的目的想调用2.dll的GetMachineInfo;所以给出1.dll调用2.dll的参考例子。
能否提供原程序,可用来做调试?
2020-12-28 10:20
0
雪    币: 12045
活跃值: (4763)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5

不懂,来学习了
2020-12-28 13:03
0
雪    币: 312
活跃值: (713)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
就是 你说这么一大堆还不如直接丢程序上来
2020-12-28 13:54
0
雪    币: 130
活跃值: (639)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
#include <windows.h>
typedef LPSTR(WINAPI* FUNCGetMachineInfo)(LPSTR guardServerInfo);

FUNCGetMachineInfo GetMachineInfo;
int main()
{

	HMODULE hmodle=LoadLibrary("DLL名字.dll");
	//这个GetMachineInfo名字根据导出函数查看器得到的 完全可以这么调用 
	GetMachineInfo =(FUNCGetMachineInfo)GetProcAddress(hmodle, "?GetMachineInfo@LicenseService@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V23@@Z");
	if (!GetMachineInfo)
	{
		MessageBoxA(NULL,"获取函数地址错误","错误",MB_OK);
	}
	LPSTR strRet=GetMachineInfo("参数");
}

我不太理解你说的意思!但如果是调用DLL完全这样调用就可以!名字长也是这么搞C++代码

2020-12-29 13:31
0
雪    币: 49
活跃值: (817)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
之前我用IDA查这个DLL文件的导出函数,试过用你这个方法。但还是提示出错
Exception thrown at 0x6D897153 (msvcp90.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0x002BBEA4.
2020-12-30 08:54
0
雪    币: 49
活跃值: (817)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
yegu 能否提供原程序,可用来做调试?
您好,yegu !这个程序太大了,太复杂,运行环境不好部署!
2020-12-30 08:56
0
雪    币: 3622
活跃值: (2559)
能力值: ( LV6,RANK:83 )
在线值:
发帖
回帖
粉丝
10
caicaisin 您好,yegu !这个程序太大了,太复杂,运行环境不好部署!
远程调试看看也行
2020-12-30 22:34
0
雪    币: 48
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
11
解决了吗
2021-1-3 10:43
0
雪    币: 49
活跃值: (817)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
还没有,在忙工作事情
2021-1-5 07:51
0
雪    币: 211
活跃值: (118)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
?GetMachineInfo@LicenseService@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V23@@Z
这个函数应该是  public LicenseService::GetMachineInfo(std::string &tmp);  
2021-1-18 23:11
0
游客
登录 | 注册 方可回帖
返回
//