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

发布于 2024-12-04 11:26:47 字数 632 浏览 0 评论 0 原文

我不知道你是否知道excel-dna项目,它是一个帮助在excel插件中集成.net汇编和语言的项目。

我的问题是我想从 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);
        }

但它不起作用。 有人有办法从 xll 中解压 dll 吗?

提前致谢,

I don't know if you know excel-dna project, it's a project that help to integrate .net assembly and language in excel addins.

My problem is that I want to unpack a dll from an xll file (excel-dna is able to pack resources inside xll).

I donwloaded the excel-dna sources and already write this base on the source code :

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望喜 2024-12-11 11:26:47

如果您希望从 Excel-DNA 加载项中提取 .NET 程序集,我编写了一个名为 ExcelDnaUnpack。源代码位于 GitHub 上:https://github.com/augustoproiete/exceldna-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

If you're looking to extract the .NET assemblies from an Excel-DNA add-in, I wrote a small utility called ExcelDnaUnpack. Source code is on GitHub: https://github.com/augustoproiete/exceldna-unpack

ExcelDna-Unpack is a command-line utility to extract the contents of ExcelDna add-ins packed with ExcelDnaPack

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
娇纵 2024-12-11 11:26:47

我认为您正在尝试将 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);
}

希望这会有所帮助。

I think you are trying to load the x86 .xll file into a x64 bit process. It is not possible to mix x86 and x64 bit code. Instead use the LoadLibraryEx function to load your .xll file as a data file.

Here is a small code sample:

[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);
}

Hope, this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文