Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Accessing a DLL File

by PrimeLord (Pilgrim)
on Feb 11, 2005 at 19:11 UTC ( [id://430214]=perlquestion: print w/replies, xml ) Need Help??

PrimeLord has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks. I was hoping you could assisst me in accessing a DLL file. I don;t need to update the DLL I only need to be able to read a bunch of text values out of the DLL into a hash. When I open the DLL in file in ResHacker I see the resources I need under numbered folders under the main folder called String Table. Inside each of the numbered sub folders is what I believe is a resource and the data within that resource looks some thing like this:

STRINGTABLE LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US { 1, "foo" 2, "faz" 3, "far" 4, "bar" 5, "baz" 6, "boo" 7, "abc" 8, "def" 9, "ghi" 10, "jkl" 11, "mno" 12, "pqr" 13, "stu" 14, "vwx" 15, "yz1" }


I need to pull that data out and make it into key/value pairs in a hash. And then move down to the next numbered folder and do the same. Any suggestions on the best way to do this? I took a look at Win32::API, but I have no idea how to use it or if it is even what I need for this.

Thanks!

-Prime

Replies are listed 'Best First'.
Re: Accessing a DLL File
by Courage (Parson) on Feb 11, 2005 at 19:57 UTC
    two ways come to my mind: one is simplier but requires C, another pure-perl but harder.

    1. create a simple C wrapper program that takes one argument - DLL file, and then, using API calls (FindResource and such) performs the trick. Use this program from Perl.
    2. Use MS Visual Studio, use Win32::OLE and control it to open DLL file and save it as resource. You will get text file containing your string table
    I was requested to write such a program at work, but I switched to other tasks for some reason, so I don't have code.
Re: Accessing a DLL File
by holli (Abbot) on Feb 11, 2005 at 21:11 UTC
      I thought I had it figured out, but it seems that I don't. I took a look at Win32::Resources, but I understand what is getting written to data. Here is an example of the code I am using:

      #!perl -w use strict; use Win32::Resources; my $filename = "C:/path/to/file.dll"; my $data = Win32::Resources::LoadResource( filename => $filename, type => 'STRING', name => '1', language => '0' ); print "$data\n";


      $data appears to just be a bunch binary data. Not the text strings I was looking for. Any suggestions on what I am doing wrong? Thanks again.
Re: Accessing a DLL File
by Anonymous Monk on Feb 11, 2005 at 20:19 UTC
    You can open the DLL-File in binary mode, read the MZ-header (first 64 bytes) unpack the offset of the PE-header from it, seek there, read the PE-header, unpack ...

    Do you get the drift? Don't have the SDK here so I can't be precise.

      I sort of understand where you are going, but I am confused about a few things. I don't know what the MZ-header and PE-header are. And I don't know what I need to unpack it as. Thanks.
        He's refering to the format of executables (.dll uses the same format as .exe). He's saying you could search the Microsoft site for documentation on the file format and work your way through it to extra the info you need.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://430214]
Approved by holli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-25 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found