mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Merge remote-tracking branch 'origin/GT-2926_dev747368_DmgClientFileSystem'
This commit is contained in:
@@ -21,7 +21,6 @@ import java.io.IOException;
|
|||||||
import generic.jar.ResourceFile;
|
import generic.jar.ResourceFile;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
import ghidra.app.util.bin.ByteProvider;
|
||||||
import ghidra.file.formats.xar.XARUtil;
|
import ghidra.file.formats.xar.XARUtil;
|
||||||
import ghidra.file.formats.zlib.ZLIB;
|
|
||||||
import ghidra.formats.gfilesystem.*;
|
import ghidra.formats.gfilesystem.*;
|
||||||
import ghidra.formats.gfilesystem.factory.GFileSystemFactoryWithFile;
|
import ghidra.formats.gfilesystem.factory.GFileSystemFactoryWithFile;
|
||||||
import ghidra.formats.gfilesystem.factory.GFileSystemProbeFull;
|
import ghidra.formats.gfilesystem.factory.GFileSystemProbeFull;
|
||||||
@@ -46,7 +45,7 @@ public class DmgClientFileSystemFactory
|
|||||||
@Override
|
@Override
|
||||||
public boolean probe(FSRL containerFSRL, ByteProvider byteProvider, File containerFile,
|
public boolean probe(FSRL containerFSRL, ByteProvider byteProvider, File containerFile,
|
||||||
FileSystemService fsService, TaskMonitor taskMonitor)
|
FileSystemService fsService, TaskMonitor taskMonitor)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
|
|
||||||
if (!isDmgPresent()) {
|
if (!isDmgPresent()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -56,9 +55,6 @@ public class DmgClientFileSystemFactory
|
|||||||
if (XARUtil.isXAR(byteProvider)) {
|
if (XARUtil.isXAR(byteProvider)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ZLIB.isZLIB(byteProvider)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isEncrypted(containerFile);
|
return isEncrypted(containerFile);
|
||||||
}
|
}
|
||||||
@@ -84,7 +80,7 @@ public class DmgClientFileSystemFactory
|
|||||||
@Override
|
@Override
|
||||||
public DmgClientFileSystem create(FSRL containerFSRL, FSRLRoot targetFSRL, File containerFile,
|
public DmgClientFileSystem create(FSRL containerFSRL, FSRLRoot targetFSRL, File containerFile,
|
||||||
FileSystemService fsService, TaskMonitor monitor)
|
FileSystemService fsService, TaskMonitor monitor)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
|
|
||||||
String dmgName = containerFSRL.getName();
|
String dmgName = containerFSRL.getName();
|
||||||
|
|
||||||
@@ -103,7 +99,7 @@ public class DmgClientFileSystemFactory
|
|||||||
fsService.getDerivedFile(containerFSRL, "decrypted " + containerName, (srcFile) -> {
|
fsService.getDerivedFile(containerFSRL, "decrypted " + containerName, (srcFile) -> {
|
||||||
monitor.initialize(srcFile.length());
|
monitor.initialize(srcFile.length());
|
||||||
return new DmgDecryptorStream(containerName, dmgName, srcFile);
|
return new DmgDecryptorStream(containerName, dmgName, srcFile);
|
||||||
} , monitor);
|
}, monitor);
|
||||||
decrypted_dmg_file = fce.file;
|
decrypted_dmg_file = fce.file;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -15,15 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.file.formats.ios.dmg;
|
package ghidra.file.formats.ios.dmg;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import ghidra.app.util.bin.*;
|
import ghidra.app.util.bin.*;
|
||||||
import ghidra.file.crypto.*;
|
import ghidra.file.crypto.*;
|
||||||
import ghidra.file.formats.ios.generic.iOS_AesCrypto;
|
import ghidra.file.formats.ios.generic.iOS_AesCrypto;
|
||||||
import ghidra.file.formats.ios.generic.iOS_Sha1Crypto;
|
import ghidra.file.formats.ios.generic.iOS_Sha1Crypto;
|
||||||
import ghidra.util.exception.CryptoException;
|
import ghidra.util.exception.CryptoException;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link InputStream} that decrypts a DMG file on the fly.
|
* An {@link InputStream} that decrypts a DMG file on the fly.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -76,19 +76,32 @@ public class DmgDecryptorStream extends InputStream {
|
|||||||
public DmgDecryptorStream(String containerName, String dmgName, ByteProvider provider)
|
public DmgDecryptorStream(String containerName, String dmgName, ByteProvider provider)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
CryptoKey cryptoKey = CryptoKeyFactory.getCryptoKey(containerName, dmgName);
|
||||||
|
if (cryptoKey.key.length != 36) {
|
||||||
|
throw new CryptoException("Invalid key length.");
|
||||||
|
}
|
||||||
|
if (cryptoKey.iv.length != 0) {
|
||||||
|
throw new CryptoException("Invalid initialization vector (IV) length.");
|
||||||
|
}
|
||||||
|
|
||||||
|
aes_key = Arrays.copyOfRange(cryptoKey.key, 0, 16);
|
||||||
|
sha1_key = Arrays.copyOfRange(cryptoKey.key, 16, 16 + 20);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
// Release the provider before this exception finishes since the #close() method can't
|
||||||
|
// be called later to release it.
|
||||||
|
try {
|
||||||
|
provider.close();
|
||||||
|
}
|
||||||
|
catch (IOException ioe) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
|
|
||||||
CryptoKey cryptoKey = CryptoKeyFactory.getCryptoKey(containerName, dmgName);
|
|
||||||
if (cryptoKey.key.length != 36) {
|
|
||||||
throw new CryptoException("Invalid key length.");
|
|
||||||
}
|
|
||||||
if (cryptoKey.iv.length != 0) {
|
|
||||||
throw new CryptoException("Invalid initialization vector (IV) length.");
|
|
||||||
}
|
|
||||||
|
|
||||||
aes_key = Arrays.copyOfRange(cryptoKey.key, 0, 16);
|
|
||||||
sha1_key = Arrays.copyOfRange(cryptoKey.key, 16, 16 + 20);
|
|
||||||
|
|
||||||
sha1 = new iOS_Sha1Crypto(sha1_key);
|
sha1 = new iOS_Sha1Crypto(sha1_key);
|
||||||
|
|
||||||
BinaryReader reader = new BinaryReader(provider, false);
|
BinaryReader reader = new BinaryReader(provider, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user