Add pinned APFS FUSE source and guarded read-only NAS probe

这个提交包含在:
mac 于 2026-11-11 22:07:35 +08:00 提交
1 父节点 08e7da7f23
当前提交 737773eb76
111 个文件已更改
+26555 -3

没有与搜索条件相匹配的文件

+483
查看文件
@@ -0,0 +1,483 @@
/*
This file is part of apfs-fuse, a read-only implementation of APFS
(Apple File System) for FUSE.
Copyright (C) 2017 Simon Gander
Apfs-fuse is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Apfs-fuse is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with apfs-fuse. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <ApfsLib/Device.h>
#include <ApfsLib/Util.h>
#include <ApfsLib/DiskStruct.h>
#include <ApfsLib/BlockDumper.h>
#include <ApfsLib/GptPartitionMap.h>
#include "Dumper.h"
#ifdef __linux__
#include <signal.h>
#endif
#undef RAW_VERBOSE
constexpr size_t BLOCKSIZE = 0x1000;
volatile bool g_abort = 0;
void DumpBlockTrunc(std::ostream &os, const uint8_t *data)
{
unsigned int sz = BLOCKSIZE - 1;
while (sz > 0 && data[sz] == 0)
sz--;
sz = (sz + 0x10) & 0xFFFFFFF0;
DumpHex(os, data, sz);
}
#if 0
void MapBlocks(std::ostream &os, Device &dev, uint64_t bid_start, uint64_t bcnt)
{
using namespace std;
uint64_t bid;
uint8_t block[BLOCKSIZE];
const APFS_ObjHeader * const blk = reinterpret_cast<const APFS_ObjHeader *>(block);
const APFS_TableHeader * const tbl = reinterpret_cast<const APFS_TableHeader *>(block + sizeof(APFS_ObjHeader));
bool last_was_used = false;
os << hex << uppercase << setfill('0');
os << "[Block] | oid | xid | type | subtype | Page | Levl | Entries | Description" << endl;
os << "---------+----------+----------+----------+----------+------+------+----------+---------------------------------" << endl;
for (bid = 0; bid < bcnt && !g_abort; bid++)
{
if ((bid & 0xFFF) == 0)
{
std::cout << '.';
std::cout.flush();
}
dev.Read(block, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
if (IsEmptyBlock(block, BLOCKSIZE))
{
if (last_was_used)
os << "---------+----------+----------+----------+----------+------+------+----------+ Empty" << endl;
last_was_used = false;
continue;
}
if (VerifyBlock(block, BLOCKSIZE))
{
os << setw(8) << bid << " | ";
os << setw(8) << blk->oid << " | ";
os << setw(8) << blk->xid << " | ";
os << setw(8) << blk->type << " | ";
os << setw(8) << blk->subtype << " | ";
os << setw(4) << tbl->page << " | ";
os << setw(4) << tbl->level << " | ";
os << setw(8) << tbl->entries_cnt << " | ";
os << BlockDumper::GetNodeType(blk->type, blk->subtype);
if (APFS_OBJ_TYPE(blk->type) == 2)
os << " [Root]";
os << endl;
last_was_used = true;
}
else
{
os << setw(8) << bid;
os << " | | | | | | | | Data" << endl;
last_was_used = true;
}
}
os << endl;
}
void ScanBlocks(std::ostream &os, Device &dev, uint64_t bid_start, uint64_t bcnt)
{
BlockDumper bd(os, BLOCKSIZE);
uint64_t bid;
uint8_t block[BLOCKSIZE];
bd.SetTextFlags(0x00);
for (bid = 0; bid < bcnt && !g_abort; bid++)
{
if ((bid & 0xFFF) == 0)
{
std::cout << '.';
std::cout.flush();
}
dev.Read(block, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
if (IsEmptyBlock(block, BLOCKSIZE))
continue;
if (VerifyBlock(block, BLOCKSIZE))
bd.DumpNode(block, bid);
else
{
#if 0
os << std::hex << std::setw(16) << blk_nr << std::endl;
DumpBlockTrunc(os, block);
os << std::endl;
os << "===========================================================================================================================" << std::endl;
os << std::endl;
#endif
}
}
}
void DumpSpaceman(std::ostream &os, Device &dev, uint64_t bid_start, uint64_t bcnt)
{
uint8_t sb[BLOCKSIZE];
uint8_t data[BLOCKSIZE];
BlockDumper bd(os, BLOCKSIZE);
const APFS_ObjHeader *bhdr;
const APFS_Spaceman *sm;
const APFS_NX_Superblock *nxsb;
uint64_t bid;
uint64_t cnt;
uint64_t smbmp_bid = 0;
uint64_t smbmp_cnt = 0;
uint64_t volbmp_bid = 0;
uint64_t volbmp_cnt = 0;
(void)bcnt;
if (!dev.Read(sb, bid_start * BLOCKSIZE, BLOCKSIZE))
return;
if (!VerifyBlock(sb, BLOCKSIZE))
return;
nxsb = reinterpret_cast<const APFS_NX_Superblock *>(sb);
if (nxsb->hdr.type != 0x80000001)
return;
if (nxsb->nx_magic != 0x4253584E)
return;
bd.DumpNode(sb, 0);
os << std::endl;
os << "Dumping Superblock Area" << std::endl;
os << std::endl;
bid = nxsb->nx_xp_desc_base;
cnt = nxsb->nx_xp_desc_blocks;
while (cnt > 0)
{
dev.Read(data, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
bd.DumpNode(data, bid);
cnt--;
bid++;
}
os << std::endl;
os << "Dumping Spaceman Area" << std::endl;
os << std::endl;
bid = nxsb->nx_xp_data_base;
cnt = nxsb->nx_xp_data_blocks;
while (cnt > 0)
{
dev.Read(data, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
bd.DumpNode(data, bid);
cnt--;
bid++;
bhdr = reinterpret_cast<const APFS_ObjHeader *>(data);
if (bhdr->type == 0x80000005)
{
sm = reinterpret_cast<const APFS_Spaceman *>(data);
smbmp_bid = sm->ip_bm_base_address;
smbmp_cnt = sm->ip_bitmap_block_count;
volbmp_bid = sm->ip_base_address;
volbmp_cnt = sm->ip_block_count;
}
}
bid = smbmp_bid;
cnt = smbmp_cnt;
while (cnt > 0)
{
dev.Read(data, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
bd.DumpNode(data, bid);
cnt--;
bid++;
}
bid = volbmp_bid;
cnt = volbmp_cnt;
while (cnt > 0)
{
dev.Read(data, (bid_start + bid) * BLOCKSIZE, BLOCKSIZE);
bd.DumpNode(data, bid);
cnt--;
bid++;
}
}
#endif
static void ctrl_c_handler(int sig)
{
(void)sig;
g_abort = true;
}
#if 0
int main(int argc, const char *argv[])
{
if (argc < 3)
{
std::cerr << "Syntax: apfs-dump file.img output.txt [map.txt]" << std::endl;
return 1;
}
Device *dev;
std::ofstream os;
uint64_t bid_start = 0;
uint64_t bcnt = 0;
g_debug = 255;
#if defined(__linux__) || defined(__APPLE__)
signal(SIGINT, ctrl_c_handler);
#endif
dev = Device::OpenDevice(argv[1]);
if (!dev)
{
std::cerr << "Device " << argv[1] << " not found." << std::endl;
return 2;
}
{
GptPartitionMap pmap;
if (pmap.LoadAndVerify(*dev))
{
int partid = pmap.FindFirstAPFSPartition();
if (partid >= 0)
{
std::cout << "Dumping EFI partition" << std::endl;
pmap.GetPartitionOffsetAndSize(partid, bid_start, bcnt);
bid_start /= BLOCKSIZE;
bcnt /= BLOCKSIZE;
}
}
}
if (bcnt == 0)
bcnt = dev->GetSize() / BLOCKSIZE;
if (argc > 3)
{
os.open(argv[3]);
if (!os.is_open())
{
std::cerr << "Could not open output file " << argv[3] << std::endl;
dev->Close();
delete dev;
return 3;
}
MapBlocks(os, *dev, bid_start, bcnt);
os.close();
}
os.open(argv[2]);
if (!os.is_open())
{
std::cerr << "Could not open output file " << argv[2] << std::endl;
dev->Close();
delete dev;
return 3;
}
DumpSpaceman(os, *dev, bid_start, bcnt);
ScanBlocks(os, *dev, bid_start, bcnt);
dev->Close();
os.close();
delete dev;
return 0;
}
#else
void usage()
{
std::cerr << "Syntax:" << std::endl;
std::cerr << "apfs-dump [-map mapfile.txt] file.img output.txt" << std::endl;
std::cerr << "apfs-dump [-map mapfile.txt] -fusion main.img tier2.img output.txt" << std::endl;
}
int main(int argc, const char *argv[])
{
const char *name_dev_main = 0;
const char *name_dev_tier2 = 0;
const char *name_map = 0;
const char *name_output = 0;
bool use_fusion = false;
int n;
int idx = 0;
for (n = 1; n < argc; n++)
{
if (!strcmp(argv[n], "-map"))
{
n++;
if (n >= argc)
{
usage();
return 1;
}
name_map = argv[n];
}
else if (!strcmp(argv[n], "-fusion"))
use_fusion = true;
else
{
switch (idx)
{
case 0:
name_dev_main = argv[n];
printf("main: %s\n", name_dev_main);
if (use_fusion)
idx++;
else
idx += 2;
break;
case 1:
name_dev_tier2 = argv[n];
printf("tier2: %s\n", name_dev_tier2);
idx++;
break;
case 2:
name_output = argv[n];
printf("out: %s\n", name_output);
idx++;
break;
default:
usage();
return 1;
break;
}
}
}
if ((name_output == 0) || (use_fusion && name_dev_tier2 == 0))
{
usage();
return 1;
}
std::unique_ptr<Device> dev_main;
std::unique_ptr<Device> dev_tier2;
std::ofstream os;
g_debug = 255;
#if defined(__linux__) || defined(__APPLE__)
signal(SIGINT, ctrl_c_handler);
#endif
dev_main.reset(Device::OpenDevice(name_dev_main));
if (use_fusion)
dev_tier2.reset(Device::OpenDevice(name_dev_tier2));
if (!dev_main)
{
std::cerr << "Device " << name_dev_main << " not found." << std::endl;
return 2;
}
if (use_fusion && !dev_tier2)
{
std::cerr << "Device " << name_dev_tier2 << " not found." << std::endl;
return 2;
}
{
Dumper dmp(dev_main.get(), dev_tier2.get());
if (!dmp.Initialize())
return -1;
#if 1
if (name_map)
{
os.open(name_map);
if (!os.is_open())
{
std::cerr << "Could not open map file " << name_map << std::endl;
dev_main->Close();
if (dev_tier2)
dev_tier2->Close();
return 3;
}
dmp.DumpBlockList(os);
os.close();
}
#endif
os.open(name_output);
if (!os.is_open())
{
std::cerr << "Could not open output file " << name_output << std::endl;
dev_main->Close();
if (dev_tier2)
dev_tier2->Close();
return 3;
}
dmp.DumpContainer(os);
}
dev_main->Close();
if (dev_tier2)
dev_tier2->Close();
os.close();
return 0;
}
#endif
+476
查看文件
@@ -0,0 +1,476 @@
#include <iostream>
#include <iomanip>
#include <ApfsLib/BlockDumper.h>
#include <ApfsLib/Device.h>
#include <ApfsLib/DiskStruct.h>
#include <ApfsLib/GptPartitionMap.h>
#include <ApfsLib/Util.h>
#include "Dumper.h"
Dumper::Dumper(Device *dev_main, Device *dev_tier2)
{
m_dev_main = dev_main;
m_dev_tier2 = dev_tier2;
m_base_main = 0;
m_size_main = 0;
m_base_tier2 = 0;
m_size_tier2 = 0;
m_blocksize = 0;
m_is_encrypted = false;
}
Dumper::~Dumper()
{
}
bool Dumper::Initialize()
{
m_base_main = 0;
m_size_main = 0;
m_base_tier2 = 0;
m_size_tier2 = 0;
m_blocksize = 0;
GptPartitionMap pmap;
if (pmap.LoadAndVerify(*m_dev_main))
{
int partid = pmap.FindFirstAPFSPartition();
if (partid >= 0)
{
std::cout << "Dumping EFI partition on main" << std::endl;
pmap.GetPartitionOffsetAndSize(partid, m_base_main, m_size_main);
}
}
if (m_size_main == 0)
m_size_main = m_dev_main->GetSize();
if (m_size_main == 0)
return false;
if (m_dev_tier2)
{
if (pmap.LoadAndVerify(*m_dev_tier2))
{
int partid = pmap.FindFirstAPFSPartition();
if (partid >= 0)
{
std::cout << "Dumping EFI partition on tier2" << std::endl;
pmap.GetPartitionOffsetAndSize(partid, m_base_tier2, m_size_tier2);
}
}
if (m_size_tier2 == 0)
m_size_tier2 = m_dev_tier2->GetSize();
if (m_size_tier2 == 0)
return false;
}
std::vector<uint8_t> nx_data;
const nx_superblock_t *nx;
nx_data.resize(0x1000);
m_dev_main->Read(nx_data.data(), m_base_main, 0x1000);
nx = reinterpret_cast<const nx_superblock_t *>(nx_data.data());
if (nx->nx_magic != NX_MAGIC)
{
std::cerr << "Could not load NX superblock. Invalid magic number." << std::endl;
return false;
}
m_blocksize = nx->nx_block_size;
if (m_blocksize != 0x1000)
{
nx_data.resize(m_blocksize);
nx = reinterpret_cast<const nx_superblock_t *>(nx_data.data());
m_dev_main->Read(nx_data.data(), m_base_main, m_blocksize);
}
if (!VerifyBlock(nx_data.data(), m_blocksize))
{
std::cerr << "NX superblock checksum incorrect!" << std::endl;
return false;
}
return true;
}
bool Dumper::DumpContainer(std::ostream &os)
{
BlockDumper bd(os, m_blocksize);
std::vector<uint8_t> nx_data;
std::vector<uint8_t> cpm_data;
std::vector<uint8_t> sm_data;
std::vector<uint8_t> cxb_data;
std::vector<uint8_t> bmp_data;
std::vector<uint8_t> blk_data;
const nx_superblock_t *nx = nullptr;
const checkpoint_map_phys_t *cpm = nullptr;
const spaceman_phys_t *sm = nullptr;
const chunk_info_block_t *cib = nullptr;
const cib_addr_block_t *cab = nullptr;
const checkpoint_mapping_t *cm = nullptr;
uint64_t paddr;
uint64_t block_count;
uint32_t block_size;
uint32_t blocks_per_chunk;
uint32_t chunks_per_cib;
uint32_t cibs_per_cab;
uint32_t cib_count;
uint32_t cab_count;
const le_uint64_t *cxb_oid;
uint32_t cab_id;
uint32_t cib_id;
uint32_t chunk_id;
uint32_t blk_id;
size_t n;
int devidx;
uint64_t offs = 0;
std::vector<uint64_t> cib_oid_list;
// Get NX superblock
if (!Read(nx_data, 0, 1))
return false;
bd.DumpNode(nx_data.data(), 0);
if (!VerifyBlock(nx_data.data(), nx_data.size()))
{
std::cerr << "Superblock checksum error" << std::endl;
return false;
}
nx = reinterpret_cast<const nx_superblock_t *>(nx_data.data());
// TODO: Scan xp_desc for most recent nxsb
// Get Check Point Info Block
if (!Read(cpm_data, nx->nx_xp_desc_base + nx->nx_xp_desc_index, 1))
{
std::cerr << "Error reading the cpm block" << std::endl;
return false;
}
bd.DumpNode(cpm_data.data(), cpm_data.size());
if (!VerifyBlock(cpm_data.data(), cpm_data.size()))
return false;
cpm = reinterpret_cast<const checkpoint_map_phys_t *>(cpm_data.data());
cm = cpm_lookup(cpm, nx->nx_spaceman_oid);
if (cm == 0)
return false;
// Get Spaceman
if (!Read(sm_data, cm->cpm_paddr, cm->cpm_size / nx->nx_block_size))
return false;
bd.DumpNode(sm_data.data(), cm->cpm_paddr);
if (!VerifyBlock(sm_data.data(), sm_data.size()))
return false;
sm = reinterpret_cast<const spaceman_phys_t *>(sm_data.data());
os << "Now dumping blocks according to bitmap ..." << std::endl;
block_size = sm->sm_block_size;
blocks_per_chunk = sm->sm_blocks_per_chunk;
chunks_per_cib = sm->sm_chunks_per_cib;
cibs_per_cab = sm->sm_cibs_per_cab;
for (devidx = SD_MAIN; devidx < SD_COUNT; devidx++)
{
std::cout << "Dumping device " << devidx << std::endl;
if (devidx == SD_TIER2 && m_dev_tier2 == 0)
{
std::cout << "Aborting" << std::endl;
break;
}
offs = (devidx == SD_TIER2) ? (FUSION_TIER2_DEVICE_BYTE_ADDR / m_blocksize) : 0;
block_count = sm->sm_dev[devidx].sm_block_count;
cib_count = sm->sm_dev[devidx].sm_cib_count;
cab_count = sm->sm_dev[devidx].sm_cab_count;
cxb_oid = reinterpret_cast<const le_uint64_t *>(sm_data.data() + sm->sm_dev[devidx].sm_addr_offset);
paddr = 0;
std::cout << std::hex;
#if 0
static const uint8_t vek[0x20] = { 0 /* enter VEK here */ };
m_is_encrypted = true;
m_aes.SetKey(vek, vek + 0x10);
#endif
cib_oid_list.clear();
cib_oid_list.reserve(cib_count);
if (cab_count > 0)
{
for (cab_id = 0; cab_id < cab_count; cab_id++)
{
if (!Read(cxb_data, cxb_oid[cab_id], 1))
return false;
if (!VerifyBlock(cxb_data.data(), cxb_data.size()))
return false;
cab = reinterpret_cast<const cib_addr_block_t *>(cxb_data.data());
for (n = 0; n < cab->cab_cib_count; n++)
cib_oid_list.push_back(cab->cab_cib_addr[n]);
}
}
else
{
for (n = 0; n < cib_count; n++)
cib_oid_list.push_back(cxb_oid[n]);
}
for (cib_id = 0; cib_id < cib_count; cib_id++)
{
std::cout << "cib " << cib_id << std::endl;
if (!Read(cxb_data, cib_oid_list[cib_id], 1))
return false;
if (!VerifyBlock(cxb_data.data(), cxb_data.size()))
return false;
cib = reinterpret_cast<const chunk_info_block_t *>(cxb_data.data());
for (chunk_id = 0; chunk_id < cib->cib_chunk_info_count; chunk_id++)
{
if (g_abort)
return false;
std::cout << " chunk " << chunk_id << " avail=" << cib->cib_chunk_info[chunk_id].ci_free_count << " paddr=" << paddr << std::endl;
if (cib->cib_chunk_info[chunk_id].ci_bitmap_addr == 0)
{
paddr += blocks_per_chunk;
continue;
}
if (!Read(bmp_data, cib->cib_chunk_info[chunk_id].ci_bitmap_addr, 1))
return false;
for (blk_id = 0; blk_id < blocks_per_chunk && paddr < block_count; blk_id++)
{
if (bmp_data[blk_id >> 3] & (1 << (blk_id & 7)))
{
Read(blk_data, paddr + offs, 1);
if (VerifyBlock(blk_data.data(), m_blocksize))
bd.DumpNode(blk_data.data(), paddr + offs);
else if (m_is_encrypted)
{
Decrypt(blk_data.data(), blk_data.size(), paddr + offs);
if (VerifyBlock(blk_data.data(), m_blocksize))
bd.DumpNode(blk_data.data(), paddr + offs);
}
}
++paddr;
}
}
}
}
return true;
}
bool Dumper::DumpBlockList(std::ostream& os)
{
using namespace std;
constexpr size_t BLOCKSIZE = 0x1000; // Should make this dynamic ...
uint64_t bid;
uint8_t block[BLOCKSIZE];
const obj_phys_t * const o = reinterpret_cast<const obj_phys_t *>(block);
const btree_node_phys_t * const bt = reinterpret_cast<const btree_node_phys_t *>(block);
bool last_was_used = false;
os << hex << uppercase << setfill('0');
os << "[Block] | oid | xid | type | subtype | Page | Levl | Entries | Description" << endl;
os << "---------+----------+----------+----------+----------+------+------+----------+---------------------------------" << endl;
for (bid = 0; bid < (m_size_main / BLOCKSIZE) && !g_abort; bid++)
{
if ((bid & 0xFFF) == 0)
{
std::cout << '.';
std::cout.flush();
}
Read(block, bid, 1);
if (IsEmptyBlock(block, BLOCKSIZE))
{
if (last_was_used)
os << "---------+----------+----------+----------+----------+------+------+----------+ Empty" << endl;
last_was_used = false;
continue;
}
if (VerifyBlock(block, BLOCKSIZE))
{
os << setw(8) << bid << " | ";
os << setw(8) << o->o_oid << " | ";
os << setw(8) << o->o_xid << " | ";
os << setw(8) << o->o_type << " | ";
os << setw(8) << o->o_subtype << " | ";
os << setw(4) << bt->btn_flags << " | ";
os << setw(4) << bt->btn_level << " | ";
os << setw(8) << bt->btn_nkeys << " | ";
os << BlockDumper::GetNodeType(o->o_type, o->o_subtype);
if ((o->o_type & OBJECT_TYPE_MASK) == OBJECT_TYPE_BTREE)
os << " [Root]";
os << endl;
last_was_used = true;
}
else
{
os << setw(8) << bid;
os << " | | | | | | | | Data" << endl;
last_was_used = true;
}
}
if (m_dev_tier2)
{
const uint64_t off = FUSION_TIER2_DEVICE_BYTE_ADDR / m_blocksize;
for (bid = 0; bid < (m_size_tier2 / BLOCKSIZE) && !g_abort; bid++)
{
if ((bid & 0xFFF) == 0)
{
std::cout << '.';
std::cout.flush();
}
Read(block + off, bid, 1);
if (IsEmptyBlock(block, BLOCKSIZE))
{
if (last_was_used)
os << "---------+----------+----------+----------+----------+------+------+----------+ Empty" << endl;
last_was_used = false;
continue;
}
if (VerifyBlock(block, BLOCKSIZE))
{
os << setw(8) << bid << " | ";
os << setw(8) << o->o_oid << " | ";
os << setw(8) << o->o_xid << " | ";
os << setw(8) << o->o_type << " | ";
os << setw(8) << o->o_subtype << " | ";
os << setw(4) << bt->btn_flags << " | ";
os << setw(4) << bt->btn_level << " | ";
os << setw(8) << bt->btn_nkeys << " | ";
os << BlockDumper::GetNodeType(o->o_type, o->o_subtype);
if ((o->o_type & OBJECT_TYPE_MASK) == OBJECT_TYPE_BTREE)
os << " [Root]";
os << endl;
last_was_used = true;
}
else
{
os << setw(8) << bid;
os << " | | | | | | | | Data" << endl;
last_was_used = true;
}
}
}
os << endl;
return true;
}
bool Dumper::Read(void* data, uint64_t paddr, uint64_t cnt)
{
uint64_t offs;
uint64_t size;
offs = paddr * m_blocksize;
size = cnt * m_blocksize;
if (offs & FUSION_TIER2_DEVICE_BYTE_ADDR)
{
offs = offs - FUSION_TIER2_DEVICE_BYTE_ADDR + m_base_tier2;
return m_dev_tier2->Read(data, offs, size);
}
else
{
offs = offs + m_base_main;
return m_dev_main->Read(data, offs, size);
}
}
bool Dumper::Read(std::vector<uint8_t>& data, uint64_t paddr, uint64_t cnt)
{
if (data.size() != cnt * m_blocksize)
data.resize(cnt * m_blocksize);
return Read(data.data(), paddr, cnt);
}
void Dumper::Decrypt(uint8_t* data, size_t size, uint64_t paddr)
{
uint64_t cs_factor = m_blocksize / 0x200;
uint64_t uno = paddr * cs_factor;
size_t k;
for (k = 0; k < size; k += 0x200)
{
m_aes.Decrypt(data + k, data + k, 0x200, uno);
uno++;
}
}
const checkpoint_mapping_t *Dumper::cpm_lookup(const checkpoint_map_phys_t* cpm, uint64_t oid)
{
uint32_t k;
uint32_t cnt;
cnt = cpm->cpm_count;
for (k = 0; k < cnt; k++)
{
if (cpm->cpm_map[k].cpm_oid == oid)
return &cpm->cpm_map[k];
}
return nullptr;
}
+40
查看文件
@@ -0,0 +1,40 @@
#pragma once
#include <vector>
#include <iosfwd>
#include <Crypto/AesXts.h>
extern volatile bool g_abort; // In Apfs.cpp
class Device;
class Dumper
{
public:
Dumper(Device *dev_main, Device *dev_tier2);
~Dumper();
bool Initialize();
bool DumpContainer(std::ostream &os);
bool DumpBlockList(std::ostream &os);
private:
bool Read(void *data, uint64_t paddr, uint64_t cnt);
bool Read(std::vector<uint8_t> &data, uint64_t paddr, uint64_t cnt);
void Decrypt(uint8_t *data, size_t size, uint64_t paddr);
const checkpoint_mapping_t* cpm_lookup(const checkpoint_map_phys_t *cpm, uint64_t oid);
Device *m_dev_main;
Device *m_dev_tier2;
uint64_t m_base_main;
uint64_t m_size_main;
uint64_t m_base_tier2;
uint64_t m_size_tier2;
uint32_t m_blocksize;
AesXts m_aes;
bool m_is_encrypted;
};