Bladeren bron

minor refactors

git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@500 f203690c-595d-4dc9-a70b-905162fa7fd2
tags/jackcess-1.2.2
James Ahlborn 13 jaren geleden
bovenliggende
commit
a3a009e03d

+ 33
- 26
src/java/com/healthmarketscience/jackcess/Database.java Bestand weergeven

@@ -1129,8 +1129,15 @@ public class Database
_buffer.position(_format.OFFSET_PASSWORD);
_buffer.get(pwdBytes);

// de-mask password
applyPasswordMask(pwdBytes);
// de-mask password using extra password mask if necessary (the extra
// password mask is generated from the database creation date stored in
// the header)
byte[] pwdMask = getPasswordMask(_buffer, _format);
if(pwdMask != null) {
for(int i = 0; i < pwdBytes.length; ++i) {
pwdBytes[i] ^= pwdMask[i % pwdMask.length];
}
}
boolean hasPassword = false;
for(int i = 0; i < pwdBytes.length; ++i) {
@@ -1155,30 +1162,6 @@ public class Database
return pwd;
}

/**
* Applies an extra mask to the password if required for the current
* JetFormat.
*/
private void applyPasswordMask(byte[] pwdBytes)
{
// apply extra password mask if necessary (the extra password mask is
// generated from the database creation date stored in the header)
int pwdMaskPos = _format.OFFSET_HEADER_DATE;
if(pwdMaskPos >= 0) {

_buffer.position(pwdMaskPos);
double dateVal = Double.longBitsToDouble(_buffer.getLong());

byte[] pwdMask = new byte[4];
ByteBuffer.wrap(pwdMask).order(PageChannel.DEFAULT_BYTE_ORDER)
.putInt((int)dateVal);

for(int i = 0; i < pwdBytes.length; ++i) {
pwdBytes[i] ^= pwdMask[i % pwdMask.length];
}
}
}

/**
* Finds the relationships matching the given from and to tables from the
* given cursor and adds them to the given list.
@@ -1635,6 +1618,30 @@ public class Database
}
}

/**
* Returns the password mask retrieved from the given header page and
* format, or {@code null} if this format does not use a password mask.
*/
static byte[] getPasswordMask(ByteBuffer buffer, JetFormat format)
{
// get extra password mask if necessary (the extra password mask is
// generated from the database creation date stored in the header)
int pwdMaskPos = format.OFFSET_HEADER_DATE;
if(pwdMaskPos < 0) {
return null;
}

buffer.position(pwdMaskPos);
double dateVal = Double.longBitsToDouble(buffer.getLong());

byte[] pwdMask = new byte[4];
ByteBuffer.wrap(pwdMask).order(PageChannel.DEFAULT_BYTE_ORDER)
.putInt((int)dateVal);

return pwdMask;
}


/**
* Utility class for storing table page number and actual name.
*/

+ 3
- 1
src/java/com/healthmarketscience/jackcess/JetFormat.java Bestand weergeven

@@ -64,7 +64,9 @@ public abstract class JetFormat {
private static final byte CODE_VERSION_5 = 0x2;

/** location of the engine name in the header */
private static final int OFFSET_ENGINE_NAME = 0x4;
static final int OFFSET_ENGINE_NAME = 0x4;
/** length of the engine name in the header */
static final int LENGTH_ENGINE_NAME = 0xF;
/** amount of initial data to be read to determine database type */
private static final int HEADER_LENGTH = 21;

Laden…
Annuleren
Opslaan