All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jsign.pe.ExtendedRandomAccessFile Maven / Gradle / Ivy

Go to download

Pure Java implementation of Microsoft Authenticode for signing Windows executable files

The newest version!
/**
 * Copyright 2012 Emmanuel Bourg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.jsign.pe;

import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @author Emmanuel Bourg
 * @since 1.0
 */
class ExtendedRandomAccessFile extends RandomAccessFile {

    ExtendedRandomAccessFile(File file, String mode) throws FileNotFoundException {
        super(file, mode);
    }

    public int readWord() throws IOException {
        int ch1 = this.read();
        int ch2 = this.read();
        if ((ch1 | ch2) < 0) {
            throw new EOFException();
        }
        return 0xffff & (ch1) + (ch2 << 8);
    }

    public long readDWord() throws IOException {
        int ch1 = this.read();
        int ch2 = this.read();
        int ch3 = this.read();
        int ch4 = this.read();
        if ((ch1 | ch2 | ch3 | ch4) < 0) {
            throw new EOFException();
        }
        return 0xffffffffL & (ch1 + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
    }

    public long readQWord() throws IOException {
        long ch1 = this.read();
        long ch2 = this.read();
        long ch3 = this.read();
        long ch4 = this.read();
        long ch5 = this.read();
        long ch6 = this.read();
        long ch7 = this.read();
        long ch8 = this.read();
        if ((ch1 | ch2 | ch3 | ch4) < 0) {
            throw new EOFException();
        }
        return ch1 + (ch2 << 8) + (ch3 << 16) + (ch4 << 24) + (ch5 << 32) + (ch6 << 40) + (ch7 << 48) + (ch8 << 56);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy