#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <ctype.h>
#include "zlib.h"
#include "aes128.h"
gehe zum Quellcode dieser Datei
|
char * | _strlwr (char *moep) |
|
static uint32_t | read32_be (const void *src_buffer) |
|
static void | store32_be (void *dst_buffer, uint32_t value) |
|
static uint32_t | align128 (uint32_t value) |
|
static int | get_hexstring (void *dst, const char *str, int len) |
|
static int | fi2rec_size (uint32_t dryos_ver) |
|
static int | fi2enc (char *infname, char *outfname, uint32_t *key, uint32_t *iv, uint32_t pid, uint32_t dryos_ver, int32_t cs_words) |
|
int | main (int argc, char **argv) |
|
char* _strlwr |
( |
char * |
moep) | |
|
Definiert in Zeile 66 der Datei fi2enc.c.
68 return ( (value + 16 - 1) & 0xFFFFFFF0ul );
Definiert in Zeile 117 der Datei fi2enc.c.
127 unsigned char *upkbuf =
NULL;
128 unsigned char exkey[176];
132 printf(
"Please supply input file name.\n");
136 printf(
"Please supply target file name.\n");
141 memset(&hdr, 0,
sizeof (hdr));
142 memset(&fi2rec, 0,
sizeof (fi2rec));
150 if ( !(fi =
fopen(infname,
"rb")) ){
151 printf(
"Can't open data file %s\n", infname );
158 if( flen <= 0 || flen > (256 << 20) ){
159 printf(
"Data file %s have unacceptable file size (%ld)\n", infname, (
unsigned long) flen );
162 upkbuf = (
unsigned char*)
malloc( flen );
167 if( flen >
fread( upkbuf, 1, flen, fi ) ){
168 printf(
"Error reading data file\n" );
173 buf = (
unsigned char*)
malloc( i );
181 printf(
"Data compression error\n" );
185 fi2rec.upklen = flen;
193 for( i = 0; i < fi2rec.len/4; i++) cs += wbuf[i];
196 for( i = 0; i < fi2rec.len; i++) cs += buf[i];
207 buf = (
unsigned char*)
malloc( i );
219 printf(
"Saving %s\n", outfname );
220 fo =
fopen(outfname,
"wb");
222 printf(
"Can't open file %s for writing\n", outfname);
226 if ( i !=
fwrite(buf, 1, i, fo ) ){
227 printf(
"\nError writing header to %s (%ld bytes)\n", outfname, i);
232 if (fi2rec.len !=
fwrite( pblk, 1, fi2rec.len, fo ) ){
233 printf(
"\nError writing data block to %s (%d bytes)\n", outfname, fi2rec.len);
static int fi2rec_size |
( |
uint32_t |
dryos_ver) | |
|
|
static |
Definiert in Zeile 100 der Datei fi2enc.c.
107 else if (dryos_ver >= 50)
static int get_hexstring |
( |
void * |
dst, |
|
|
const char * |
str, |
|
|
int |
len |
|
) |
| |
|
static |
Definiert in Zeile 71 der Datei fi2enc.c.
75 unsigned char *p = (
unsigned char *)
dst;
78 printf(
"No hex string supplied!\n" );
83 printf(
"Hex length mismatch in \"%s\"!\n",
str );
86 for( i = 0; i < len*2; i++ ){
88 if( c < (
'9'+1) && c >=
'0' ) c-= 0x30;
89 else if( c < 'G' && c >=
'A' ) c -= (
'A' - 0x0A);
90 else if( c < 'g' && c >=
'a' ) c -= (
'a' - 0x0A);
92 printf(
"Non-hex character \'%c\' at %d in string %s\n", c, i+1,
str );
95 p[i/2] = i & 1 ? p[i/2] | c : c << 4;
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definiert in Zeile 241 der Datei fi2enc.c.
255 for( i = 1; i < argc; i++){
256 if( argv[i][0] ==
'/' || argv[i][0] ==
'-' ){
259 if (
get_hexstring( key_buf, argv[++i],
sizeof key_buf ) )
return -1;
263 if (
get_hexstring( iv_buf, argv[++i],
sizeof iv_buf ) )
return -1;
268 pid =
strtoul(argv[++i], &err, 0);
273 dryos_ver =
strtoul(argv[++i], &err, 0);
280 printf(
"Unexpected option: %s\n", argv[i]);
284 if( !fni ) fni = argv[i];
285 else if( !fno ) fno = argv[i];
287 printf(
"Unexpected parameter: %s\n", argv[i]);
292 if( !key || !iv || !pid){
297 if (
strstr(flags,
"W") ) {
301 for( i = 0; i < 4; i ++ ) key[i] =
read32_be( key+i );
302 i =
fi2enc( fni, fno, key, iv , pid, dryos_ver, cs_words);
303 if ( !i )
printf(
"Done\n" );
else printf(
"Failed!\n" );
Definiert in Zeile 51 der Datei fi2enc.c.
53 unsigned char *b = (
unsigned char *)src_buffer;
54 return (b[0]<<24) | (b[1] << 16) | (b[2] << 8) | b[3];
static void store32_be |
( |
void * |
dst_buffer, |
|
|
uint32_t |
value |
|
) |
| |
|
static |
Definiert in Zeile 57 der Datei fi2enc.c.
59 unsigned char *b = (
unsigned char *)dst_buffer;
60 b[0] = ( value >> 24 ) & 0xFF;
61 b[1] = ( value >> 16 ) & 0xFF;
62 b[2] = ( value >> 8 ) & 0xFF;
63 b[3] = ( value >> 0 ) & 0xFF;
const char* g_str_shorthelp |
|
static |
Initialisierung:= "Usage: fi2encdec [-p PID] [-key KEY -iv IV] [-x FLAGS] in.file out.file\n"
" FLAGS: one or more of the following letters\n"
" W: checksum is word based (on new models)\n"
"\n"
Definiert in Zeile 14 der Datei fi2enc.c.