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

I have the following binary data that I need to put into a REG_BINARY value in the registry. I know how to access the registry and insert data, but I can't figure out how to insert the following binary data exactly as is:
1f b0 67 8c 79
I think it must have something to do with the pack statement and a template? Everything I try changes the binary data to something else? I just don't know that much about binary.

Any help would be much appreciated.

Replies are listed 'Best First'.
Re: REG_BINARY Registry Data
by AidanLee (Chaplain) on Jan 03, 2002 at 03:32 UTC

    If you already have the binary data in a variable, it should be as simple as using a print statement to put it into whatever you want (watch out for binmode on win32). If you have an ascii or hex representation of the binary, then you'll have to use something like pack, or hex and then pack to turn it into binary.

    so it would probably be something like

    pack "c5", map { hex $_ } qw( 1f b0 67 8c 79 )
      I do already have the binary data, but I don't know how to use the print statement to write to the registry. Here is what I have, and note that all works well except for the param2enc registry entry that must write that exact binary data back to the registry.
      use Win32::TieRegistry; $Registry->Delimiter("/"); $Registry->{"LMachine/SOFTWARE/Microsoft/Windows/CurrentVersion/Networ +k/"}={ "LanMan/" => { "VIRUSSCAN\$/" => { "/Flags" => ["0x00000102","REG_DWORD"], "/Parm1enc" => ["","REG_BINARY"], "/Parm2enc" => [ pack("A","1f","b0","67","8c","79"),"REG_BINARY"], "/Type" => ["0x00000000","REG_DWORD"], "/Path" => "C:\\", "/Remark" => "Do Not Delete This Share"}, },
      All I am trying to do is create a share on Win9x machines. I have attempted to do it with win32::netresource but it has a known bug that won't allow it to work on 9x machines. Only on NT/2000/XP. Apparently ActiveState is working on it, but until they fix it, editing the registry is the only way I can think to create a share. I have it working, at least all except inserting pre-existing binary data into the registry. }

      Edit by tye

        Well, I'm not familiar with Win32::TieRegistry, but looking at your snippet I can guess that what you probably want is:
        use Win32::TieRegistry; $Registry->Delimiter("/"); $Registry->{"LMachine/SOFTWARE/Microsoft/Windows/CurrentVersion/Networ +k/"}={ "LanMan/" => { "VIRUSSCAN\$/" => { "/Flags" => [ "0x00000102", "REG_DWORD", ] "/Parm1enc" => [ "", "REG_BINARY", ] "/Parm2enc" => [ pack( "c5", map { hex $_ } qw( 1f b0 67 8 +c 79 ) ), "REG_BINARY", ] "/Type" => [ "0x00000000", "REG_DWORD", ] "/Path" => "C:\\", "/Remark" => "Do Not Delete This Share" }, }, };

        I'm assuming that those are hex values you've got there. If they're not you'll have to tell me otherwise. I'll also note that I've never seen a hash where each key takes two values, but I'll assume that that is the nature of Win32::TieRegistry, and that you know what you are doing.

        Update: I see code tags have been applied in the above post, and things make much more sense. I've modified my code to reflect the change.
Re: REG_BINARY Registry Data
by Anonymous Monk on Jan 04, 2002 at 07:44 UTC
    Thank you very much, AidanLee. Your suggestion worked very well! I really appreciate the assistance.