本文整理汇总了C++中fs::file类的典型用法代码示例。如果您正苦于以下问题:C++ file类的具体用法?C++ file怎么用?C++ file使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了file类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sys_spu_image_open
s32 sys_spu_image_open(vm::ptr<sys_spu_image_t> img, vm::cptr<char> path)
{
sys_spu.warning("sys_spu_image_open(img=*0x%x, path=*0x%x)", img, path);
const fs::file f(vfs::get(path.get_ptr()));
if (!f)
{
sys_spu.error("sys_spu_image_open() error: '%s' not found!", path.get_ptr());
return CELL_ENOENT;
}
SceHeader hdr;
hdr.Load(f);
if (hdr.CheckMagic())
{
throw fmt::exception("sys_spu_image_open() error: '%s' is encrypted! Try to decrypt it manually and try again.", path.get_ptr());
}
f.seek(0);
u32 entry;
u32 offset = LoadSpuImage(f, entry);
img->type = SYS_SPU_IMAGE_TYPE_USER;
img->entry_point = entry;
img->segs.set(offset); // TODO: writing actual segment info
img->nsegs = 1; // wrong value
return CELL_OK;
}
示例2: verify_npdrm_self_headers
extern bool verify_npdrm_self_headers(const fs::file& self, u8* klic_key)
{
if (!self)
return false;
self.seek(0);
if (self.size() >= 4 && self.read<u32>() == "SCE\0"_u32)
{
// Check the ELF file class (32 or 64 bit).
bool isElf32 = IsSelfElf32(self);
// Start the decrypter on this SELF file.
SELFDecrypter self_dec(self);
// Load the SELF file headers.
if (!self_dec.LoadHeaders(isElf32))
{
LOG_ERROR(LOADER, "SELF: Failed to load SELF file headers!");
return false;
}
// Load and decrypt the SELF file metadata.
if (!self_dec.LoadMetadata(klic_key))
{
LOG_ERROR(LOADER, "SELF: Failed to load SELF file metadata!");
return false;
}
}
return true;
}
示例3: cellUserInfoGetStat
s32 cellUserInfoGetStat(u32 id, vm::ptr<CellUserInfoUserStat> stat)
{
cellUserInfo.warning("cellUserInfoGetStat(id=%d, stat=*0x%x)", id, stat);
if (id > CELL_SYSUTIL_USERID_MAX)
return CELL_USERINFO_ERROR_NOUSER;
if (id == CELL_SYSUTIL_USERID_CURRENT)
{
// TODO: Return current user/profile when that is implemented
id = 1;
}
const std::string& path = vfs::get(fmt::format("/dev_hdd0/home/%08d/", id));
if (!fs::is_dir(path))
return CELL_USERINFO_ERROR_NOUSER;
const fs::file f(path + "localusername");
if (!f)
return CELL_USERINFO_ERROR_INTERNAL;
stat->id = id;
strcpy_trunc(stat->name, f.to_string());
return CELL_OK;
}
示例4: sys_raw_spu_load
s32 sys_raw_spu_load(s32 id, vm::cptr<char> path, vm::ptr<u32> entry)
{
sysPrxForUser.warning("sys_raw_spu_load(id=%d, path=*0x%x, entry=*0x%x)", id, path, entry);
sysPrxForUser.warning("*** path = '%s'", path.get_ptr());
const fs::file f(vfs::get(path.get_ptr()));
if (!f)
{
sysPrxForUser.error("sys_raw_spu_load() error: '%s' not found!", path.get_ptr());
return CELL_ENOENT;
}
SceHeader hdr;
hdr.Load(f);
if (hdr.CheckMagic())
{
throw fmt::exception("sys_raw_spu_load() error: '%s' is encrypted! Try to decrypt it manually and try again.", path.get_ptr());
}
f.seek(0);
u32 _entry;
LoadSpuImage(f, _entry, RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id);
*entry = _entry | 1;
return CELL_OK;
}
示例5: save_gui_cfg
void save_gui_cfg()
{
YAML::Emitter out;
out.SetSeqFormat(YAML::Flow);
out << g_gui_cfg;
// Save to file
s_gui_cfg.seek(0);
s_gui_cfg.trunc(0);
s_gui_cfg.write(out.c_str(), out.size());
}
示例6: decrypt_self
extern fs::file decrypt_self(fs::file elf_or_self, u8* klic_key)
{
if (!elf_or_self)
{
return fs::file{};
}
elf_or_self.seek(0);
// Check SELF header first. Check for a debug SELF.
if (elf_or_self.size() >= 4 && elf_or_self.read<u32>() == "SCE\0"_u32 && !CheckDebugSelf(elf_or_self))
{
// Check the ELF file class (32 or 64 bit).
bool isElf32 = IsSelfElf32(elf_or_self);
// Start the decrypter on this SELF file.
SELFDecrypter self_dec(elf_or_self);
// Load the SELF file headers.
if (!self_dec.LoadHeaders(isElf32))
{
LOG_ERROR(LOADER, "SELF: Failed to load SELF file headers!");
return fs::file{};
}
// Load and decrypt the SELF file metadata.
if (!self_dec.LoadMetadata(klic_key))
{
LOG_ERROR(LOADER, "SELF: Failed to load SELF file metadata!");
return fs::file{};
}
// Decrypt the SELF file data.
if (!self_dec.DecryptData())
{
LOG_ERROR(LOADER, "SELF: Failed to decrypt SELF file data!");
return fs::file{};
}
// Make a new ELF file from this SELF.
return self_dec.MakeElf(isElf32);
}
return elf_or_self;
}
示例7: Load
void ControlInfo::Load(const fs::file& f)
{
type = Read32(f);
size = Read32(f);
next = Read64(f);
if (type == 1)
{
control_flags.ctrl_flag1 = Read32(f);
control_flags.unknown1 = Read32(f);
control_flags.unknown2 = Read32(f);
control_flags.unknown3 = Read32(f);
control_flags.unknown4 = Read32(f);
control_flags.unknown5 = Read32(f);
control_flags.unknown6 = Read32(f);
control_flags.unknown7 = Read32(f);
}
else if (type == 2)
{
if (size == 0x30)
{
f.read(file_digest_30.digest, 20);
file_digest_30.unknown = Read64(f);
}
else if (size == 0x40)
{
f.read(file_digest_40.digest1, 20);
f.read(file_digest_40.digest2, 20);
file_digest_40.unknown = Read64(f);
}
}
else if (type == 3)
{
npdrm.magic = Read32(f);
npdrm.unknown1 = Read32(f);
npdrm.license = Read32(f);
npdrm.type = Read32(f);
f.read(npdrm.content_id, 48);
f.read(npdrm.digest, 16);
f.read(npdrm.invdigest, 16);
f.read(npdrm.xordigest, 16);
npdrm.unknown2 = Read64(f);
npdrm.unknown3 = Read64(f);
}
}
示例8: IsSelfElf32
static bool IsSelfElf32(const fs::file& f)
{
if (!f) return false;
f.seek(0);
SceHeader hdr;
SelfHeader sh;
hdr.Load(f);
sh.Load(f);
// Locate the class byte and check it.
u8 elf_class[0x8];
f.seek(sh.se_elfoff);
f.read(elf_class, 0x8);
return (elf_class[4] == 1);
}
示例9: CheckDebugSelf
static bool CheckDebugSelf(fs::file& s)
{
if (s.size() < 0x18)
{
return false;
}
// Get the key version.
s.seek(0x08);
const u16 key_version = s.read<le_t<u16>>();
// Check for DEBUG version.
if (key_version == 0x80 || key_version == 0xc0)
{
LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header...");
// Get the real elf offset.
s.seek(0x10);
// Start at the real elf offset.
s.seek(key_version == 0x80 ? +s.read<be_t<u64>>() : +s.read<le_t<u64>>());
// Write the real ELF file back.
fs::file e = fs::make_stream<std::vector<u8>>();
// Copy the data.
char buf[2048];
while (u64 size = s.read(buf, 2048))
{
e.write(buf, size);
}
s = std::move(e);
return true;
}
// Leave the file untouched.
return false;
}
示例10: cellUserInfoGetStat
error_code cellUserInfoGetStat(u32 id, vm::ptr<CellUserInfoUserStat> stat)
{
cellUserInfo.warning("cellUserInfoGetStat(id=%d, stat=*0x%x)", id, stat);
if (id > CELL_SYSUTIL_USERID_MAX)
{
return CELL_USERINFO_ERROR_NOUSER;
}
if (id == CELL_SYSUTIL_USERID_CURRENT)
{
// TODO: Return current user/profile when that is implemented
id = 1;
}
if (!stat)
return CELL_USERINFO_ERROR_PARAM;
const std::string& path = vfs::get(fmt::format("/dev_hdd0/home/%08d/", id));
if (!fs::is_dir(path))
{
cellUserInfo.error("cellUserInfoGetStat(): CELL_USERINFO_ERROR_NOUSER. User %d doesn't exist. Did you delete the user folder?", id);
return CELL_USERINFO_ERROR_NOUSER;
}
const fs::file f(path + "localusername");
if (!f)
{
cellUserInfo.error("cellUserInfoGetStat(): CELL_USERINFO_ERROR_INTERNAL. Username for user %d doesn't exist. Did you delete the username file?", id);
return CELL_USERINFO_ERROR_INTERNAL;
}
stat->id = id;
strcpy_trunc(stat->name, f.to_string());
return CELL_OK;
}
示例11: Init
void Emulator::Init()
{
if (!g_tty)
{
g_tty.open(fs::get_config_dir() + "TTY.log", fs::rewrite + fs::append);
}
idm::init();
fxm::init();
// Reset defaults, cache them
cfg::root.from_default();
g_cfg_defaults = cfg::root.to_string();
// Reload global configuration
cfg::root.from_string(fs::file(fs::get_config_dir() + "/config.yml", fs::read + fs::create).to_string());
}
示例12: Init
void Emulator::Init()
{
if (!g_tty)
{
g_tty.open(fs::get_config_dir() + "TTY.log", fs::rewrite + fs::append);
}
idm::init();
fxm::init();
// Reset defaults, cache them
g_cfg.from_default();
g_cfg_defaults = g_cfg.to_string();
// Reload global configuration
g_cfg.from_string(fs::file(fs::get_config_dir() + "/config.yml", fs::read + fs::create).to_string());
// Create directories
const std::string emu_dir_ = g_cfg.vfs.emulator_dir;
const std::string emu_dir = emu_dir_.empty() ? fs::get_config_dir() : emu_dir_;
const std::string dev_hdd0 = fmt::replace_all(g_cfg.vfs.dev_hdd0, "$(EmulatorDir)", emu_dir);
const std::string dev_hdd1 = fmt::replace_all(g_cfg.vfs.dev_hdd1, "$(EmulatorDir)", emu_dir);
const std::string dev_usb = fmt::replace_all(g_cfg.vfs.dev_usb000, "$(EmulatorDir)", emu_dir);
fs::create_path(dev_hdd0);
fs::create_dir(dev_hdd0 + "game/");
fs::create_dir(dev_hdd0 + "game/TEST12345/");
fs::create_dir(dev_hdd0 + "game/TEST12345/USRDIR/");
fs::create_dir(dev_hdd0 + "home/");
fs::create_dir(dev_hdd0 + "home/00000001/");
fs::create_dir(dev_hdd0 + "home/00000001/exdata/");
fs::create_dir(dev_hdd0 + "home/00000001/savedata/");
fs::create_dir(dev_hdd0 + "home/00000001/trophy/");
fs::write_file(dev_hdd0 + "home/00000001/localusername", fs::create + fs::excl + fs::write, "User"s);
fs::create_dir(dev_hdd0 + "disc/");
fs::create_dir(dev_hdd1 + "cache/");
fs::create_dir(dev_hdd1 + "game/");
fs::create_path(dev_hdd1);
fs::create_path(dev_usb);
#ifdef WITH_GDB_DEBUGGER
fxm::make<GDBDebugServer>();
#endif
// Initialize patch engine
fxm::make_always<patch_engine>()->append(fs::get_config_dir() + "/patch.yml");
}
示例13: Write16LE
inline void Write16LE(const fs::file& f, const u16 data)
{
f.write(&data, sizeof(data));
}
示例14: sizeof
void Elf32_Phdr::LoadLE(const fs::file& f)
{
f.read(this, sizeof(*this));
}
示例15: sys_tty_write
error_code sys_tty_write(s32 ch, vm::cptr<char> buf, u32 len, vm::ptr<u32> pwritelen)
{
sys_tty.notice("sys_tty_write(ch=%d, buf=*0x%x, len=%d, pwritelen=*0x%x)", ch, buf, len, pwritelen);
if (ch > 15)
{
return CELL_EINVAL;
}
if (static_cast<s32>(len) <= 0)
{
*pwritelen = 0;
return CELL_OK;
}
if (g_tty)
{
g_tty.write(buf.get_ptr(), len);
}
*pwritelen = len;
return CELL_OK;
}