Sei sulla pagina 1di 3

********* Windows DLL *****************************************************

There is a new routex.dll for win32 in CSharpDemo\bin\Release or


CSharpDemo\bin\Debug

in CSharpDemo there is a demo project in C# to decode a file and get the decrypted
data as byte[] (byte array)

The implemented DLL functions are:

*** to decode a file and get the content as byte array ***

Int32 RLib_LoadDataFile([MarshalAs(UnmanagedType.BStr)] string filename,


[MarshalAs(UnmanagedType.BStr)] out string origfilename, ref Int32 ftype, out
double utctime, [MarshalAs(UnmanagedType.BStr)] string pwd, out UInt32 datasize,
[MarshalAs(UnmanagedType.BStr)] out string errdesc);

filename is the file to be decoded


origfilename is the original file name before encryption
ftype is a constant to mark the usage type of the file, for example 500 is used to
mark generic NaviGate updates
passing ftype to the function, if the encrytpted file has a different code, the
file will not be imported and will generate an error
passing 0 as ftype, all file types will be imported and ftype will contain the
file type of the encrypted file
utctime is the date when the file was created in Ole Automation double format
pwd is the password to decrypt. Default password is: @_1FAA_!B49EAA
datasize is the size in bytes of the decoded data
errordesc is a tring with description of errors, if any

after successful import, the data must be read with the function:

Int32 RLib_GetDataFileContent(IntPtr bufferPtr, UInt32 datasize);

Both functions are wrapped in the C# functions:

bool LoadDataFileToByteArr(out byte[] readbuffer, string filename, out string


origfilename, string pwd, ref Int32 ftype, out double utctime, out string errdesc)

byte[] readbuffer is the byte array where the file content will be imported

Functions and error codes are in file RoutexLib.cs

public const int FCR_ERR_OK = 0; //when the import is OK


public const int FCR_ERR_GENERIC = 1;
public const int FCR_ERR_INV_SIG = 2;
public const int FCR_ERR_NOFILE = 3;
public const int FCR_ERR_FILEOPEN = 4;
public const int FCR_ERR_FILEEMPTY = 5;
public const int FCR_ERR_VERNOTSUP = 6;
public const int FCR_ERR_TYPENOMATCH = 7;
public const int FCR_ERR_FILEPARTMISS = 8;

*** to decode a file and save directly to another file the content
Int32 RLib_RestoreDataFile([MarshalAs(UnmanagedType.BStr)] string filename,
[MarshalAs(UnmanagedType.BStr)] string outpath, [MarshalAs(UnmanagedType.BStr)]
string outname, ref Int32 ftype, out double utctime,
[MarshalAs(UnmanagedType.BStr)] string pwd, [MarshalAs(UnmanagedType.BStr)] out
string errdesc);

filename is the file to be decoded


outpath is the output path to save the decoded file (if blank, will be used the
input file path)
outname is the output file name of the decoded file (if blank, will be used the
original name of the file before encryption)
ftype is a constant to mark the usage type of the file, for example 500 is used to
mark generic NaviGate updates
passing ftype to the function, if the encrytpted file has a different code, the
file will not be imported and will generate an error
passing 0 as ftype, all file types will be imported and ftype will contain the
file type of the encrypted file
utctime is the utc date when the file was created in Ole Automation double format
pwd is the password to decrypt. Default password is: @_1FAA_!B49EAA
errordesc is a tring with description of errors, if any

*** to encode a file ***

Int32 RLib_CreateDataFile([MarshalAs(UnmanagedType.BStr)] string filename,


[MarshalAs(UnmanagedType.BStr)] string destfilename, Int32 ftype, Int32 compmode,
Int32 maxsizekb, double utctime, [MarshalAs(UnmanagedType.BStr)] string pwd);

filename filename of the source file to be encrypted and/or compressed


destfilename is filename of the output file
ftype is a numeric code to mark the file type (ftyp=500 is "Navigate Update File
Type")
compmode is the compression / encryption mode:
0 = no encryption and no compression
1 = encryption with no compression
2 = encryption + compression
3 = compression without encryption

maxsizekb is the size in kB of the splitted files. If zero, no split.


utctime is the utc date when the file was created in Ole Automation double format
pwd is the encryption password. The default one is: @_1FAA_!B49EAA

********* LINUX (Tested on UBUNTU, same version of NaviServer)


****************************************

In Ubuntu folder there is the "filecrypt" standalone commandline Linux executable.

Example of commandline to encrypt a file (from linux terminal):


./filecrypt
"fnm=/home/username/Documents/test.zip;outnm=/home/username/Documents/test.ngte;fty
p=500;mode=2;spltsz=0;pwd=@_1FAA_!B49EAA"

is equivalent to the following commandline because blank values are replaced by


default values:

./filecrypt
"fnm=/home/username/Documents/test.zip;outnm=;ftyp=500;mode=2;spltsz=0;pwd="

fnm= filename of the source file to be encrypted and/or compressed

outnm= filename of the output file (if blank, will use by default the source file
name with extension .ngte)

ftyp= a numeric code to mark the file type (if blank, the file will use ftyp=500
that is "Navigate Update File Type")

mode= is the compression / encryption mode:


0 = no encryption and no compression
1 = encryption with no compression
2 = encryption + compression
3 = compression without encryption

spltsz= size in kB of the splitted files. If zero, no split.

pwd= encryption password. If blank, by default will be used: @_1FAA_!B49EAA

********* DESCRIPTION OF THE COMPRESSED FILE FORMAT:


******************************************

FILE SIGNATURE DWORD (4 bytes) = hex 46444543


FILE VERSION WORD (2 bytes) = 1
FILE TYPE DWORD (4 bytes) = for Navigate updates is 500
FILE DATE UTC DOUBLE (8 bytes) = UTC date when encryptes file was created, in Ole
Automation format
FILE PART WORD (2 bytes) = 1 for not splitted files, otherwise is the number of the
splitted file part
FILE TOT PARTS WORD (2 bytes) = 1 for not splitted files, otherwise is the total
number of splitted parts
FILE COMPRESSION MODE DWORD (4 bytes) = defines if the file is compressed and or
encrypted (0,1,2,3)
FILE CRC32 DWORD (4 bytes) = CRC32 of the payload before compression (payload is 4
bytes with original file size in bytes + original file data)
FILE DATASIZE = size of the encrypted data part
FILE ORIGINAL NAME = 2 bytes with string length + original file name without path
in unicode with xor (using letter "K" on every char to obfuscate the name
Encrypted part with blowfish (before encryption the data could be also compressed
with the standard "deflate" zip/gzip algorithm

Potrebbero piacerti anche