Changeset 232


Ignore:
Timestamp:
04/28/11 12:45:10 (14 years ago)
Author:
tim
Message:

added a convenience openHive function in pyregfi
standardized static function names
improvements to scons release script and library versioning

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • SConstruct

    r226 r232  
     1import sys
     2import os
     3
    14cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -DREGFI_WIN32'
    25
    3 libiconv_path='win32/libiconv/'
    4 libpthreads_path='win32/libpthreads/'
     6libiconv_path='.export/win32/libiconv/'
     7libpthreads_path='.export/win32/libpthreads/'
    58libpthread_name='pthreadGC2'
    6 libtalloc_path='win32/libtalloc/'
     9libtalloc_path='.export/win32/libtalloc/'
    710
    8 source_targets=('reglookup-src-trunk.tar.gz',)
    9 win32_targets=('reglookup-win32-trunk.zip',)
    10 doc_targets=('reglookup-doc-trunk.tar.gz',)
    11 all_targets = source_targets+win32_targets+doc_targets 
     11source_targets=('src-trunk',)
     12win32_targets=('win32-trunk',)
     13doc_targets=('doc-trunk',)
     14all_targets = source_targets+win32_targets+doc_targets
    1215
    13 def target2version(target):
     16
     17
     18def parse_target(target):
    1419    chunks = target.split('-')
    15     if len(chunks) != 3:
     20    if len(chunks) != 2:
    1621        return None
    17     return chunks[2].split('.')[0]
     22    return chunks
    1823
    1924def version2input(version):
     
    2429
    2530
    26 source_cmds='''
    27 rm -rf .release;
    28 svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/$SOURCE .release/%s;
    29 cd .release/%s && scons doc
    30 cd .release && tar cf %s.tar %s && gzip -9 %s.tar;
    31 mv .release/%s.tar.gz . && rm -rf .release
     31export_cmds='''
     32rm -rf .export
     33svn export --depth files svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup .export
     34svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/doc .export/doc
     35svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/win32 .export/win32
     36svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/%s .export/%s
    3237'''
    3338
     39version_cmds='''
     40echo 'REGFI_VERSION="%s"' > .export/%s/regfi_version.py
     41'''
     42
     43cleanup_cmds='''
     44rm -rf .export
     45'''
     46
     47source_cmds='''
     48cd %s && scons doc
     49mv %s %s && tar cf %s.tar %s && gzip -9 %s.tar;
     50'''+cleanup_cmds
     51
    3452win32_cmds='''
    35 rm -rf .release && mkdir -p .release/%s/python/pyregfi
     53mkdir -p .release/%s/python/pyregfi
    3654cp %s/src/*.exe .release/%s
    3755
     
    3957cp %s/python/pyregfi/*.py .release/%s/python/pyregfi
    4058
    41 cp win32/libiconv/bin/*.dll win32/libpthreads/bin/*.dll win32/libtalloc/bin/*.dll trunk/lib/*.dll .release/%s
     59cp .export/win32/libiconv/bin/*.dll .export/win32/libpthreads/bin/*.dll .export/win32/libtalloc/bin/*.dll trunk/lib/*.dll .release/%s
    4260cd .release && zip -r %s.zip %s
    4361mv .release/%s.zip . && rm -rf .release
    44 '''
     62'''+cleanup_cmds
    4563
    4664doc_cmds='''
    47 rm -rf .release;
    48 svn export svn+ssh://sentinelchicken.org/home/projects/subversion/reglookup/ .release;
    49 cd .release && doxygen Doxyfile.regfi
    50 cd .release && doxygen Doxyfile.pyregfi
    51 mv .release/doc .release/%s
    52 cd .release && tar cf %s.tar %s && gzip -9 %s.tar;
    53 mv .release/%s.tar.gz . && rm -rf .release
    54 '''
     65cd .export && doxygen Doxyfile.regfi
     66cd .export && doxygen Doxyfile.pyregfi
     67mv .export/doc .export/%s
     68cd .export && tar cf %s.tar %s && gzip -9 %s.tar
     69mv .export/%s.tar.gz .
     70'''+cleanup_cmds
    5571
    5672def generate_cmds(source, target, env, for_signature):
    5773    ret_val = ''
     74    input_prefix = str(source[0])+'/'
     75
    5876    for t in target:
    59         t = str(t)
    60         t_base = t.split('.tar.gz')[0].split('.zip')[0]
    61         if t in source_targets:
    62             ret_val += source_cmds % (t_base,t_base,t_base,
    63                                       t_base,t_base,t_base)
    64         elif t in win32_targets:
    65             version = target2version(t)
    66             input_prefix = version2input(version)
     77        ttype,version = parse_target(str(t))
     78        t_base = 'reglookup-%s-%s' % (ttype, version)
    6779
     80        if ttype == 'src':
     81            ret_val += source_cmds % (input_prefix, input_prefix, t_base, t_base, t_base, t_base)
     82        elif ttype == 'win32':
    6883            env['platform']='cygwin'
    6984            env['CC']='i586-mingw32msvc-cc'
     
    122137
    123138            ret_val += win32_cmds % (t_base,input_prefix,t_base,input_prefix,
    124                                      t_base,input_prefix,
    125                                      t_base,t_base,t_base,t_base,t_base)
     139                                     t_base,input_prefix,t_base,
     140                                     t_base,t_base,t_base,t_base)
    126141
    127         elif t in doc_targets:
     142        elif ttype == 'doc':
    128143            ret_val += doc_cmds % (t_base,t_base,t_base,t_base,t_base)
    129144       
     
    131146
    132147
    133 
    134148release_builder = Builder(generator = generate_cmds,
    135                           suffix = '.tar.gz',
     149                          suffix = '',
    136150                          src_suffix = '',
    137                           prefix='reglookup-')
    138 
     151                          prefix='')
    139152
    140153env = Environment()
     154env['ENV']['SSH_AGENT_PID'] = os.environ['SSH_AGENT_PID']
     155env['ENV']['SSH_AUTH_SOCK'] = os.environ['SSH_AUTH_SOCK']
    141156env['BUILDERS']['Release'] = release_builder
    142157
     
    145160
    146161for target in COMMAND_LINE_TARGETS:
    147     AlwaysBuild(target)
    148162    if target not in all_targets:
    149163        print('ERROR: cannot build "%s".  Acceptable targets: %s'
    150164              % (target, repr(all_targets)))
    151         break
    152     env.Release(target, Dir(version2input(target2version(target))))
     165        sys.exit(1)
     166    AlwaysBuild(target)
     167    ttype,version = parse_target(target)
     168
     169    i = version2input(version)
     170    env.Execute(export_cmds % (i, i))
     171    if version != 'trunk':
     172        env.Execute(version_cmds % (version, i))
     173    env.Release(target, Dir('.export/'+i))
    153174
    154175Default(None)
  • doc/TODO

    r221 r232  
    3838
    3939 - Grep through the source for 'XXX', and you'll find more.
     40
     41
     42
     431.0 RELEASE
     44===========
     45
     46Add fields/methods for accessing security descriptors in pyregfi
     47
     48Key caching
     49
     50Add function to obtain path list from iterator
     51
     52convert MTIME structure to uint64_t if possible
     53
     54investigate why file descriptors can't be directly used in Windows
     55
     56Fill in and update remaining regfi/pyregfi API documentation
     57
     58Possible debian package build rules
     59
     60Testing
     61  Full diffs
     62  regfi and pyregfi threading
     63  valgrind in multiple scenarios for reglookup, reglookup-recover
     64
  • test/pyregfi-smoketest.py

    r228 r232  
    1010
    1111
    12 pyregfi.SetLogMask((pyregfi.LOG_TYPES.INFO, pyregfi.LOG_TYPES.WARN, pyregfi.LOG_TYPES.ERROR))
     12pyregfi.setLogMask((pyregfi.LOG_TYPES.INFO, pyregfi.LOG_TYPES.WARN, pyregfi.LOG_TYPES.ERROR))
    1313
    1414# Uses the HiveIterator to walk all keys
     
    262262        t(hive, fh)
    263263        print("##END %s; runtime=%f; messages:" % (tstr, time.time() - teststart))
    264         print(pyregfi.GetLogMessages())
     264        print(pyregfi.getLogMessages())
    265265        print
    266266        sys.stdout.flush()
  • trunk/SConstruct

    r225 r232  
    11import sys
    22import os
     3from regfi_version import REGFI_VERSION
    34
    45cflags = '-std=gnu99 -pedantic -Wall -D_FILE_OFFSET_BITS=64 -fvisibility=hidden'
     6cflags += ' -DREGFI_VERSION=\'"%s"\'' % REGFI_VERSION
    57cflags += ' -ggdb'
    68
  • trunk/include/regfi.h

    r228 r232  
    7979#include <range_list.h>
    8080#include <lru_cache.h>
     81
     82/* Library version can be overridden at build time */
     83#ifndef REGFI_VERSION
     84#define REGFI_VERSION "trunk"
     85#endif
    8186
    8287/* GCC-specific macro for library exports */
  • trunk/python/pyregfi/__init__.py

    r228 r232  
    189189# should be reported to the user.  Failure to retrieve these could result in
    190190# excessive memory consumption.
    191 def GetLogMessages():
     191def getLogMessages():
    192192    msgs = regfi.regfi_log_get_str()
    193193    if not msgs:
     
    206206# Example:
    207207# @code
    208 # SetLogMask((LOG_TYPES.ERROR, LOG_TYPES.WARN, LOG_TYPES.INFO))
     208# setLogMask((LOG_TYPES.ERROR, LOG_TYPES.WARN, LOG_TYPES.INFO))
    209209# @endcode
    210210#
     
    212212# For more information, see @ref regfi_log_set_mask.
    213213#
    214 def SetLogMask(log_types):
     214def setLogMask(log_types):
    215215    mask = 0
    216216    for m in log_types:
     
    219219
    220220
     221## Opens a file as a registry hive
     222#
     223# @param path The file path of a hive, as one would provide to the
     224#             open() built-in
     225#
     226# @return A new Hive instance
     227def openHive(path):
     228    fh = open(path, 'rb')
     229    return Hive(fh)
     230
     231
    221232## Abstract class for most objects returned by the library
    222233class _StructureWrapper(object):
     
    228239            raise Exception("Could not create _StructureWrapper,"
    229240                            + " hive is NULL.  Current log:\n"
    230                             + GetLogMessages())
     241                            + getLogMessages())
    231242        if not base:
    232243            raise Exception("Could not create _StructureWrapper,"
    233244                            + " base is NULL.  Current log:\n"
    234                             + GetLogMessages())
     245                            + getLogMessages())
    235246        self._hive = hive
    236247        self._base = base
     
    297308        if not key:
    298309            raise Exception("Could not create _GenericList; key is NULL."
    299                             + "Current log:\n" + GetLogMessages())
     310                            + "Current log:\n" + getLogMessages())
    300311       
    301312        if not regfi.regfi_reference_record(key._hive.file, key._base):
    302313            raise Exception("Could not create _GenericList; memory error."
    303                             + "Current log:\n" + GetLogMessages())
     314                            + "Current log:\n" + getLogMessages())
    304315        self._key_base = key._base
    305316        self._length = self._fetch_num(self._key_base)
     
    650661    minor_version = 5
    651662
    652     # XXX: Possibly add a second or factory function which opens a
    653     #      hive file for you
    654 
    655663    ## Constructor
     664    #
     665    # Initialize a new Hive based on a Python file object.  To open a file by
     666    # path, see @ref openHive.
    656667    #
    657668    # @param fh A Python file object.  The constructor first looks for a valid
     
    660671    #           access.
    661672    #
    662     # @note Supplied file must be seekable
     673    # @note Supplied file must be seekable.  Do not perform any operation on
     674    #       the provided file object while a Hive is using it.  Do not
     675    #       construct multiple Hive instances from the same file object.
     676    #       If a file must be accessed by separate code and pyregfi
     677    #       simultaneously, use a separate file descriptor.  Hives are
     678    #       thread-safe, so multiple threads may use a single Hive object.
    663679    def __init__(self, fh):
    664680        # The fileno method may not exist, or it may throw an exception
     
    678694                # XXX: switch to non-generic exception
    679695                raise Exception("Could not open registry file.  Current log:\n"
    680                                 + GetLogMessages())
     696                                + getLogMessages())
    681697        else:
    682698            fh.seek(0)
     
    689705                # XXX: switch to non-generic exception
    690706                raise Exception("Could not open registry file.  Current log:\n"
    691                                 + GetLogMessages())
     707                                + getLogMessages())
    692708
    693709
     
    753769        if not self._iter:
    754770            raise Exception("Could not create iterator.  Current log:\n"
    755                             + GetLogMessages())
     771                            + getLogMessages())
    756772        self._hive = hive
    757773        self._lock = threading.RLock()
     
    797813                self._lock.release()
    798814                raise Exception('Error traversing iterator downward.'+
    799                                 ' Current log:\n'+ GetLogMessages())
     815                                ' Current log:\n'+ getLogMessages())
    800816
    801817        regfi.regfi_iterator_first_subkey(self._iter)
     
    977993        if not result:
    978994            # XXX: Use non-generic exception
    979             raise Exception('Could not locate path.\n'+GetLogMessages())
     995            raise Exception('Could not locate path.\n'+getLogMessages())
    980996
    981997
  • trunk/regfi_version.py

    r231 r232  
    1 
    21SVN_REV = "$Rev$"
    3 REGFI_VERSION = "svn-%s" % SVN_REV.split(' ')[2]
     2REGFI_VERSION = "svn-%s" % SVN_REV.split(' ')[1]
  • trunk/src/common.c

    r219 r232  
    33 * XXX: This should be converted to a proper library.
    44 *
    5  * Copyright (C) 2005-2008 Timothy D. Morgan
     5 * Copyright (C) 2005-2008,2011 Timothy D. Morgan
    66 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
    77 *
     
    2828const char* subfield_special_chars = ",\"\\|";
    2929const char* common_special_chars = ",\"\\";
    30 
    31 #define REGLOOKUP_VERSION "0.1?.0"
    3230
    3331#define REGLOOKUP_EXIT_OK       0
  • trunk/src/reglookup-recover.c

    r228 r232  
    336336{
    337337  fprintf(stderr, "Usage: reglookup-recover [options] <REGISTRY_FILE>\n");
    338   fprintf(stderr, "Version: %s\n", REGLOOKUP_VERSION);
     338  fprintf(stderr, "Version: %s\n", REGFI_VERSION);
    339339  fprintf(stderr, "Options:\n");
    340340  fprintf(stderr, "\t-v\t sets verbose mode.\n");
  • trunk/src/reglookup.c

    r228 r232  
    551551          " [-p <PATH_FILTER>] [-t <TYPE_FILTER>]"
    552552          " <REGISTRY_FILE>\n");
    553   fprintf(stderr, "Version: %s\n", REGLOOKUP_VERSION);
     553  fprintf(stderr, "Version: %s\n", REGFI_VERSION);
    554554  fprintf(stderr, "Options:\n");
    555555  fprintf(stderr, "\t-v\t sets verbose mode.\n");
Note: See TracChangeset for help on using the changeset viewer.