Skip to content

Commit

Permalink
Release 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mementum committed Jan 31, 2016
1 parent d219e1e commit e8c828b
Show file tree
Hide file tree
Showing 38 changed files with 1,528 additions and 314 deletions.
173 changes: 170 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,173 @@
fritzchecksum
=============

Quick and dirty utility to calculate the CRC of a modified Fritz!Box
configuration file and write it to a new file which can the be loaded to the
router
Small pip installable module and Windows GUI (32 & 64 bits) to calculate the
CRC of an AVM's Fritz!Box configuration file.

The command line/gui versions allow to overwrite the CRC directly in the read
file or save it to a new file.

Installation
------------

- *GUI* (look in **Releases** for the latest zip files)

The *zip* files contain standalone versions that need no installation. Any
settings/paths will be saved to the ``ini`` file in the same directory.

Simply unpack and run

- *Command Line* and *module*

Simply run::

pip install fritzchecksum

The command line utility is also named ``fritzchecksum``


Command Line Utility
--------------------

The usage is as follows::

$ fritzchecksum --help
usage: fritzchecksum-script.py [-h] [--change | --output OUTPUT] input

FritzChecksum Calculator/Overwriter

positional arguments:
input Write input to output with new CRC

optional arguments:
-h, --help show this help message and exit
--change, -c Change CRC directly in input file
--output OUTPUT, -o OUTPUT
Write input to output with new CRC


Module *fritzchecksum*
----------------------

In your code do things like::

import fritzchecksum

...
...

myexport = open('myexportdatei', 'r')
oldcrc, newcrc = fritzchecksum.calc_crc32(myexport)

...

The module contains two Python 1st class citizens:

- function *calc_crc32(fin, fout=None, logcb=log_null)*

Calculates the CRC of a Fritz!Box configuration export file and writes
the new CRC sum to a new configuration file

Accepts:

- fin: a file-like
- fout: None or a file-like object. If a file, then the input will be
written to the output with the new calculated CRC
- logcb (default: log_null -> empty stub
a logger which must a accepts *args (print will work)
Returns:

(oldcrc, newcrc) -> tuple

oldcrc and newcrc will be strings representing a CRC32 in hexadecimal
format if everything went fine

oldcrc can be ``None`` which means an ``IOError`` exception has been
raised and the operation has not completed successfully. In that case
the 2nd value in the tuple contains the raised exception

Note: the escape character '\' is escaped iself in some of the
lines. CRC calculation will be wrong if the character is not
un-escaped.

The file is composed of the following:

- A global "CONFIGURATION EXPORT" section

Some variables (a=b) may be defined at this level. This definition
contributes to the the CRC calculation by concatenating a and b and
null terminating the result.

- Subsections:

The name (null terminated) of the subsection contributes to the CRC
calculation

- XXXBINFILE Section

Lines represent hexadecimal values. The values (binary converted)
are used directly in the calculation of the CRC (stripping eol
before)

- CFGFILE Section

It is a textfile embedded in the larger export file. All lines
including '\n' contribute to the CRC except the last line which
must be stripped of the EOL character before being included in
the CRC calculation


- class *ExporFile*

Class to encapsulate the parsing of an export file and overwriting of
the CRC value

After loading a file it keeps the loaded content in an internal ``fout``

With the following methods:

- *load(self, fin, out=True)*

Loads from a file-like/string object ``fin`` and will update internal
``status``, ``error``, ``oldcrc`` and ``newcrc``

if ``out`` is ``False`` no internal buffering of the loaded input will
be made

Returns:
tuple -> (status, error)

If status is ST_OK (True) error will be None
If status is ST_ERROR (False) error will be the raised exception

- *load_file(self, fin, out=True)*
Loads from a file-like object ``fin`` and will update internal
``status``, ``error``, ``oldcrc`` and ``newcrc``

if ``out`` is ``False`` no internal buffering of the loaded input will
be made

Returns:
tuple -> (status, error)

If status is ST_OK (True) error will be None
If status is ST_ERROR (False) error will be the raised exception

- *save(self, fout)*
Writes the internal ``self.fout`` file to a file-like/string ``fout``

Returns:
tuple -> (status, error)

If status is ST_OK (True) error will be None
If status is ST_ERROR (False) error will be the raised exception

- *save_file(self, fout)*
Writes the internal ``self.fout`` file to a file-like object ``fout``

Returns:
tuple -> (status, error)

If status is ST_OK (True) error will be None
If status is ST_ERROR (False) error will be the raised exception
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0.0.2
- Made pip installable module and utility
- Reworkd GUI
- Tightened Regular Expressions (covering things like CRYPTXXXX)

0.0.1
- Initial version, mix and match
26 changes: 26 additions & 0 deletions fritzchecksum/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2016 Daniel Rodriguez
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from .version import __version__

from .checksum import *
Loading

0 comments on commit e8c828b

Please sign in to comment.