从用Excel-DNA建立的Excel.XLL文件中解压内容。

问题描述 投票:4回答:2

我不知道你是否知道excel-dna项目,它是一个帮助将.net汇编和语言集成到excel插件中的项目,我的问题是,我想从一个xll文件中解包一个dll(excel-dna能够在xll中打包资源)。

我的问题是,我想从一个xll文件中解包一个dll(excel-dna能够在xll中打包资源)。

我没有加载excel-dna的源码,并且已经在源码上写了这个基础。

string xlllib = @"C:\pathtomyxllfile\myaddin.xll";
string xlloutput = @"C:\pathtomyxllfile\myaddin.dll";
var hModule = ResourceHelper.LoadLibrary(xlllib);
var content = ResourceHelper.LoadResourceBytes(hModule, "ASSEMBLY_LZMA", "MYASSEMBLYNAME");

using (BinaryWriter binWriter = new BinaryWriter(File.Open(xlloutput, FileMode.Create)))
        {
            binWriter.Write(content);
        }

but it doesn't work.Anyone have an idea to unpack a dll from xll ?

thanks in advance,

c# excel unpack xll excel-dna
2个回答
3
投票

我想你是想把x86.xll文件加载到x64位进程中。它不可能混合x86和x64位代码。相反,使用LoadLibraryEx函数将你的.xll文件作为数据文件加载。

这里有一个小的代码示例。

[Flags]
enum LoadLibraryFlags : uint
{
  DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
  LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
  LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
  LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
  LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
  LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
}

internal unsafe static class ResourceHelper
{
  [DllImport("kernel32.dll")]
  public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile,   LoadLibraryFlags dwFlags);
 // other methods such as LoadResourceBytes go here...
}


string xlllib = @"C:\pathtomyxllfile\myaddin.xll";
string xlloutput = @"C:\pathtomyxllfile\myaddin.dll";
var hModule = ResourceHelper.LoadLibraryEx(xlllib, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE | LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE);

var content = ResourceHelper.LoadResourceBytes(hModule, "ASSEMBLY_LZMA", "YOUR_ASSEMBLY_NAME_WITHOUT_EXTENSION");

using (BinaryWriter binWriter = new BinaryWriter(File.Open(xlloutput, FileMode.Create)))
{
  binWriter.Write(content);
}

希望能帮到你.


4
投票

如果你想从Excel-DNA插件中提取.NET程序集,我写了一个小工具,叫做 ExcelDnaUnpack. 源代码在GitHub上。https:/github.comaugustoproieteexceldna-unpack。

ExcelDna-Unpack 是一个命令行实用程序,用于提取与ExcelDnaPack打包的ExcelDna插件的内容。

ExcelDna-Unpack

Usage: ExcelDna-Unpack.exe [<options>]

Where [<options>] is any of:

--xllFile=VALUE    The XLL file to be unpacked; e.g. MyAddIn-packed.xll
--outFolder=VALUE  [Optional] The folder into which the extracted files will be written; defaults to '.\unpacked'
--overwrite        [Optional] Allow existing files of the same name to be overwritten

Example: ExcelDna-Unpack.exe --xllFile=MyAddIns\FirstAddin-packed.xll
         The extracted files will be saved to MyAddIns\unpacked
© www.soinside.com 2019 - 2024. All rights reserved.