Raised This Month: $32 Target: $400
 8% 

Reading nVault Files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-01-2010 , 09:39   Reading nVault Files
Reply With Quote #1

I wrote this code for those who may have the need to iterate through all entries in a nVault file. Please let me know if you notice any errors or have any requests/questions.

The below code will display all entries in the server console in the below format.
Code:
nVault | Magic=1851149396 Version=512 Entries=2

Entry=1 KeyLen=22 ValLen=29 TimeStamp=1272719603
Key="This is an example key"
Val="This is the data for this key"
 
Entry=2 KeyLen=27 ValLen=9 TimeStamp=1272719618
Key="This is another example key"
Val="More data"
PHP Code:
#include <amxmodx>
#include <amxmisc>

// - From nvault.h -
#define VAULT_MAGIC   0x6E564C54     //nVLT
#define VAULT_VERSION 0x0200         //second version

/*  
    nVault File Format
 
    VAULT_MAGIC       (uint32)
    VAULT_VERSION     (uint16)
    ENTRIES           (int32)
    [
        TimeStamp     (int32)
        KeyLen        (uint8)
        ValLen        (uint16)
        KeyData       ([])
        ValData       ([])
    ]                                 
*/

new const Version[] = "0.1";

const 
MaxKeyLen  255;     //Max 255
const MaxValLen  512;     //Max 65535
const DataBuffer 128;     //Make this the greater of (MaxKeyLen / 4) or (MaxValLen / 4)

public plugin_init() 
{
    
register_plugin"nVault File Reader" Version "bugsy" );
    
    
ReadVault"TheVaultFile" );
}

public 
ReadVault( const szVault[] )
{
    new 
szFile64 ] , iFile;
    new 
iVaultMagic iVaultVersion iVaultEntries;
    new 
iKeyLen iValLen iTimeStamp;
    new 
szKeyMaxKeyLen ] , szValMaxValLen ] , RawDataDataBuffer ];
    
    
formatexszFileget_datadirszFile charsmaxszFile ) ) ] , charsmaxszFile ) , "/vault/%s.vault" szVault );
    
    
iFile fopenszFile "rb" );

    if ( !
iFile )
        return 
0;
    
    
// Vault Magic
    
fread_rawiFile RawData BLOCK_INT );
    
iVaultMagic RawData];
    
    if ( 
iVaultMagic != VAULT_MAGIC )
        
set_fail_state"Error reading nVault: Vault Magic" );
    
    
// Vault Version
    
fread_rawiFile RawData BLOCK_SHORT );
    
iVaultVersion RawData] & 0xFFFF;
    
    if ( 
iVaultVersion != VAULT_VERSION )
        
set_fail_state"Error reading nVault: Vault Version" );
        
    
// Vault Entries
    
fread_rawiFile RawData BLOCK_INT );
    
iVaultEntries RawData];

    
server_print"nVault | Magic=%d Version=%d Entries=%d" iVaultMagic iVaultVersion iVaultEntries );
    
server_print" " );

    for ( new 
iEntry iEntry iVaultEntries iEntry++ )
    {
        
// TimeStamp
        
fread_rawiFile RawData BLOCK_INT );
        
iTimeStamp RawData];
        
        
// Key Length
        
fread_rawiFile RawData BLOCK_BYTE );
        
iKeyLen RawData] & 0xFF;
        
        
// Val Length
        
fread_rawiFile RawData BLOCK_SHORT );
        
iValLen RawData] & 0xFFFF;
        
        
// Key Data
        
fread_rawiFile RawData iKeyLen BLOCK_CHAR );
        
ReadStringszKey iKeyLen charsmaxszKey ) , RawData );
    
        
// Val Data
        
fread_rawiFile RawData iValLen BLOCK_CHAR );
        
ReadStringszVal iValLen charsmaxszVal ) , RawData );

        
server_print"Entry=%d KeyLen=%d ValLen=%d TimeStamp=%d" iEntry iKeyLen iValLen iTimeStamp );
        
server_print"Key=^"%s^"" szKey );
        
server_print"Val=^"%s^"" szVal );
        
server_print" " );
    }
    
    
fcloseiFile );
    
    return 
iVaultEntries;
}

ReadStringszDestString[] , iLen iMaxLen SourceData[] )
{
    new 
iStrPos = -1;
    new 
iRawPos 0;
    
    while ( ( ++
iStrPos iLen ) && ( iStrPos iMaxLen ) && ( iRawPos DataBuffer ) )
    {
        
szDestStringiStrPos ] = ( SourceDataiRawPos ] >> ( ( iStrPos ) * ) ) & 0xFF;
        
        if ( 
iStrPos && ( ( iStrPos ) == ) )
            
iRawPos++
    }
    
    
szDestStringiStrPos ] = EOS;

__________________

Last edited by Bugsy; 09-06-2010 at 23:07.
Bugsy is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 05-04-2010 , 17:40   Re: Reading nVault Files
Reply With Quote #2

cool
__________________
Dr.G is offline
Ex3cuTioN
Member
Join Date: May 2010
Old 07-22-2010 , 08:03   Re: Reading nVault Files
Reply With Quote #3

tnx
Ex3cuTioN is offline
MMYTH
BANNED
Join Date: May 2010
Location: Brazil
Old 07-25-2010 , 20:13   Re: Reading nVault Files
Reply With Quote #4

nice
MMYTH is offline
Send a message via MSN to MMYTH
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-25-2010 , 21:15   Re: Reading nVault Files
Reply With Quote #5

I used this today to migrate nvault data to sql

Nice work
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
tm.
Member
Join Date: Apr 2010
Old 07-26-2010 , 03:57   Re: Reading nVault Files
Reply With Quote #6

You should make this an include. It would be usefull.

Last edited by tm.; 07-26-2010 at 04:02.
tm. is offline
xiaojian
Member
Join Date: Jan 2009
Location: the world's end
Old 09-08-2010 , 05:28   Re: Reading nVault Files
Reply With Quote #7

thank you ,learning...
xiaojian is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 10-02-2010 , 16:14   Re: Reading nVault Files
Reply With Quote #8

Thx For This. I Need It
.Dare Devil. is offline
Laccess
Junior Member
Join Date: May 2010
Old 04-14-2013 , 23:01   Re: Reading nVault Files
Reply With Quote #9

This is freakin' awesome. Used it to get rid of a nvault file with about 58 000 entries of which only 11 000 were actually necessary and usable.
Laccess is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode