mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-7095 remove sevenzipjbinding and formats that relied on it
Formats refactored: zip - apache commons compress + zip4j 7z - apache commons compress bzip2 - apache commons compress cabarc - 7z cli tool xz - apache commons compress Formats now unsupported: hfsplus iso9660 ms wim arj chm deb lha rar rpm vhd z
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* 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 ghidra.app.util.bin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
|
||||
/**
|
||||
* Adapter between Ghidra {@link ByteProvider} and java nio {@link SeekableByteChannel}
|
||||
*/
|
||||
public class ByteProviderSeekableByteChannel implements SeekableByteChannel {
|
||||
|
||||
protected ByteProvider bp;
|
||||
protected long position;
|
||||
|
||||
public ByteProviderSeekableByteChannel(ByteProvider bp) {
|
||||
this.bp = bp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return bp != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (bp != null) {
|
||||
bp.close();
|
||||
bp = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ByteBuffer dst) throws IOException {
|
||||
ensureOpen();
|
||||
|
||||
long bpRemaining = bp.length() - position;
|
||||
if (bpRemaining <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bufRemaining = dst.remaining();
|
||||
int bytesToRead = (int) Math.min(bufRemaining, bpRemaining);
|
||||
|
||||
byte[] tmp = bp.readBytes(position, bytesToRead);
|
||||
|
||||
dst.put(tmp, 0, tmp.length);
|
||||
|
||||
position += tmp.length;
|
||||
return tmp.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int write(ByteBuffer src) throws IOException {
|
||||
throw new IOException("unimplemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long position() throws IOException {
|
||||
ensureOpen();
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeekableByteChannel position(long newPosition) throws IOException {
|
||||
ensureOpen();
|
||||
this.position = newPosition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() throws IOException {
|
||||
ensureOpen();
|
||||
return bp.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeekableByteChannel truncate(long size) throws IOException {
|
||||
throw new IOException("unimplemented");
|
||||
}
|
||||
|
||||
private void ensureOpen() throws IOException {
|
||||
if (bp == null) {
|
||||
throw new ClosedChannelException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,10 +38,10 @@ public class FileSystemIndexHelper<METADATATYPE> {
|
||||
private FileData<METADATATYPE> rootDir;
|
||||
|
||||
static class FileData<METADATATYPE> {
|
||||
final long fileIndex;
|
||||
GFile file;
|
||||
METADATATYPE metaData;
|
||||
final long fileIndex;
|
||||
final String symlinkPath;
|
||||
String symlinkPath;
|
||||
|
||||
FileData(GFile file, METADATATYPE metaData, long fileIndex) {
|
||||
this(file, metaData, fileIndex, null);
|
||||
@@ -137,6 +137,15 @@ public class FileSystemIndexHelper<METADATATYPE> {
|
||||
return (fileData != null) ? fileData.file : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the index of the specified file}
|
||||
* @param file GFile
|
||||
*/
|
||||
public synchronized long getFileIndex(GFile file) {
|
||||
FileData<METADATATYPE> fd = file == null ? rootDir : fileToEntryMap.get(file);
|
||||
return fd != null ? fd.fileIndex : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors {@link GFileSystem#getListing(GFile)} interface.
|
||||
*
|
||||
@@ -270,11 +279,28 @@ public class FileSystemIndexHelper<METADATATYPE> {
|
||||
return fd != null ? fd.file : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the symlink path that the specified file contains}
|
||||
* @param file GFile
|
||||
*/
|
||||
public synchronized String getSymlinkPath(GFile file) {
|
||||
FileData<METADATATYPE> fd = file == null ? rootDir : fileToEntryMap.get(file);
|
||||
return fd != null ? fd.symlinkPath : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the symlink path of the specified file
|
||||
*
|
||||
* @param file GFile
|
||||
* @param newSymlinkPath string path
|
||||
*/
|
||||
public synchronized void updateSymlinkPath(GFile file, String newSymlinkPath) {
|
||||
FileData<METADATATYPE> fd = fileToEntryMap.get(file);
|
||||
if (fd != null) {
|
||||
fd.symlinkPath = newSymlinkPath;
|
||||
}
|
||||
}
|
||||
|
||||
private FileData<METADATATYPE> getFileData(GFile f) throws IOException {
|
||||
if (f == null) {
|
||||
return rootDir;
|
||||
|
||||
Reference in New Issue
Block a user