简体   繁体   中英

Trying to read DBM file

I have a stripped down real-time Linux box that interfaces with some hardware.

The configuration files are *.dbm files and I cannot access them. They seem to be some sort of key-value database but every library I have tried has come up empty.

I have tried the DBM reading libraries from Perl, Python, and Ruby with no luck. Any guidance on these files would be great, I have not seen them before.

This is what happens when I cat one file out.

 DBMFILE  Aug 31 2004,�
,jy                    �
�~���"��+�K&��gB��7JJ�
                                         ,��GLOBA.PB_COMBI�SMSI���
JG]
,��BUS_DP
PC  �
            '

xLokalT
          J��
                ,��SL_DP
                             PC!�
                                    ��
#,��PLC_PARAMJPf,��PROJEKT�PROFIBUS new network1.00022.02.2012J,��KBL_HEADER:�JJp,��KBLJ��,��ALI-SETUPB ����
������������������JJ,,��OBJ-DEFJJ��,��ALI_CLIENTTJJ�
,��ALI_SERVERJ      J\r�����2,  ��      ST_OV_00Boolean0Integer8    0Integer16
0Integer32
            0Unsigned8
0Unsigned32Floating-Point0igned16
Octet String Jo� ,��DESCRIPT �ABB OyABB Drives RPBA-01ABBSlave1***reserved***�
                                                                                      �
                                                                                      %  

So to show what i've tried already, and only come up with empty objects ( no key-values)*edit

perl -

#!/usr/bin/perl -w                                                                                                                                                                                                                             

use strict;

use DB_File;
use GDBM_File;

my ($filename, %hash, $flags, $mode, $DB_HASH) = @ARGV;

tie %hash,  'DB_File', [$filename, $flags, $mode, $DB_HASH]
  or die "Cannot open $filename: $!\n";

while ( my($key, $value) = each %hash ) {
   print "$key = $value\n";
}

 # these unties happen automatically at program exit                                                                                                                                                                                            
untie %hash;

which returns nothing

python -

db = dbm.open('file', 'c')

ruby -

db = DBM.open('file', 666, DBM::CREATRW)

Every one of these returned empty. I assume they use the same low level library. Some history/context on DBM files would be great as there seems to be some different versions.

**Edit

running file on it returns

$ file abb12mb_uncontrolledsynch_ppo2_1slave.dbm 
abb12mb_uncontrolledsynch_ppo2_1slave.dbm: data

and running strings outputs

$ strings abb12mb_uncontrolledsynch_ppo2_1slave.dbm 
DBMFILE  
Aug 31 2004
GLOBAL
PB_COMBI
SMSI
BUS_DP
Lokal
SL_DP
PLC_PARAM
PROJEKT
PROFIBUS new network
1 .000
22.02.2012
KBL_HEADER
ALI-SETUP
OBJ-DEF
ALI_CLIENT
ALI_SERVER
ST_OV_0
Boolean
Integer8
Integer16
Integer32
Unsigned8
Unsigned16
Unsigned32
Floating-Point
Octet String
DESCRIPT
ABB Oy
ABB Drives RPBA-01
ABBSlave1
***reserved***

Just to make my comment clear, you should try using the default options for DB_File , like this

use strict;
use warnings;

use DB_File;

my ($filename) = @ARGV;

tie my %dbm, 'DB_File', $filename or die qq{Cannot open DBM file "$filename": $!};

print "$_\n" for keys %dbm;

From the documentation for Perl's dbmopen function :

[This function has been largely superseded by the tie function.]

You probably want to try tie ing it with DB_File .

 use DB_File;
 tie %hash,  'DB_File', $filename, $flags, $mode, $DB_HASH;

Then your data is in %hash .

Might also be interesting to run file against the file to see what it actually is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM