【问题标题】:Invoking a dll function without a call in the main调用 dll 函数而不在 main 中调用
【发布时间】:2018-02-05 15:35:07
【问题描述】:

我想知道我们如何调用在外部静态类(dll 文件)中定义的函数而不在 main 中调用它。

为了让事情更清楚,考虑一个 exe 文件,它的代码没有公开,我们不能对其进行任何类型的修改,现在我想用我的 dll 文件中定义的某些测试用例来测试一个 exe 文件,我必须在 exe 文件的 main() 函数中调用该函数。但如前所述,我无权修改 exe 文件的代码。现在如何在需要的执行点调用这个 dll 函数,而无需使用 Visual Studio 调用它。

我想调用一个函数而不向主函数添加任何行。

为了让事情更清楚,我只想添加一些例子

static class DllClass
{
   static void dllFunction()
   {
      //some implementation.
   }
}
class ThirdParty
{
  public static void Main()
  {
    //Default implementation that i cannot modify.
    //Invoking my static function at this point without calling.(i.e i cannot call DllClass.dllFunction()) 
    //continuing with default implementation.
  }
}     

【问题讨论】:

  • 真的不清楚你在问什么。能否展示一些代码示例或图表?
  • 所以你想从一个exe调用一个dll而没有修改exe的权限?
  • @rory.ap 我添加了一个例子,请检查一下
  • @Richard Boyce 是的!在某种程度上,我想从 exe 调用 dll 中的函数而不修改 exe 文件中的 main(在 Visual Studio 中)
  • 您是否正在尝试构建您的第一个代码注入漏洞?

标签: c# visual-studio debugging dll runtimemodification


【解决方案1】:

一个想法是,如果您无法修改 .exe 中的代码,则使用 Powershell 调用 dll 文件。

例如,一个带有方法的简单库。

命名空间数学
{
公共类方法
{
公共方法()
{
}
public static int Compare1(int a, int b)
{
如果一个 返回一个;
其他
返回 b;
}

public int Compare2(int a, int b)
{
如果一个 返回一个;
其他
返回 b;
}
}
}

然后在Powershell环境中调用:

[void][reflection.assembly]::LoadFile("C:/xxx.dll")
02.[Math.methods]::Compare1(10,8)
03.$a=新对象 Math.Methods
04.$a.Compare2(2,6)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多