USHORT NEAR NotifyFLT (NPU npU, UCHAR CardEvent) { NPIORB_CHANGE_UNITSTATUS npTI = (NPIORB_CHANGE_UNITSTATUS)&InitIORB; NPA npA = npU->npA; PUNITINFO pUI; pUI = npU->pUnitInfoF; if (SELECTOROF(pUI) == NULL) return (1); clrmem (npTI, sizeof(*npTI)); npTI->iorbh.Length = sizeof(IORB_CHANGE_UNITSTATUS); npTI->iorbh.UnitHandle = (USHORT)(pUI->UnitHandle); npTI->iorbh.CommandCode = IOCC_UNIT_CONTROL; npTI->iorbh.CommandModifier = IOCM_CHANGE_UNITSTATUS; npTI->iorbh.RequestControl = IORB_ASYNC_POST | IORB_DISABLE_RETRY; npTI->UnitStatus = (npU->Flags & UCBF_NOTPRESENT ? 0 : US_PRESENT) | (npU->Flags & UCBF_BM_DMA ? US_BM_READ | US_BM_WRITE : 0) | (CardEvent ? US_PORT_UPDATE : 0); npTI->pIdentifyData = (NPIDENTIFYDATA)ScratchBuf + npU->UnitIndex; npTI->BasePort = DATAREG; npTI->StatusPort = DEVCTLREG; npTI->IRQLevel = npA->IRQLevel; return (Execute ((UCHAR)pUI->FilterADDHandle, (NPIORB)npTI)); }
int GetNcchInfo(ncch_info *info, ncch_hdr *hdr) { clrmem(info, sizeof(ncch_info)); info->titleId = u8_to_u64(hdr->titleId,LE); info->programId = u8_to_u64(hdr->programId,LE); u32 block_size = GetNcchBlockSize(hdr); info->formatVersion = u8_to_u16(hdr->formatVersion,LE); if(!IsCfa(hdr)){ info->exhdrOffset = sizeof(ncch_hdr); info->exhdrSize = u8_to_u32(hdr->exhdrSize,LE); info->acexOffset = (info->exhdrOffset + info->exhdrSize); info->acexSize = sizeof(access_descriptor); info->plainRegionOffset = (u64)(u8_to_u32(hdr->plainRegionOffset,LE)*block_size); info->plainRegionSize = (u64)(u8_to_u32(hdr->plainRegionSize,LE)*block_size); } info->logoOffset = (u64)(u8_to_u32(hdr->logoOffset,LE)*block_size); info->logoSize = (u64)(u8_to_u32(hdr->logoSize,LE)*block_size); info->exefsOffset = (u64)(u8_to_u32(hdr->exefsOffset,LE)*block_size); info->exefsSize = (u64)(u8_to_u32(hdr->exefsSize,LE)*block_size); info->exefsHashDataSize = (u64)(u8_to_u32(hdr->exefsHashSize,LE)*block_size); info->romfsOffset = (u64) (u8_to_u32(hdr->romfsOffset,LE)*block_size); info->romfsSize = (u64) (u8_to_u32(hdr->romfsSize,LE)*block_size); info->romfsHashDataSize = (u64)(u8_to_u32(hdr->romfsHashSize,LE)*block_size); return 0; }
void SetDevCardInfo(devcardinfo_hdr *hdr, cci_settings *set) { clrmem(hdr,sizeof(devcardinfo_hdr)); if(set->options.useExternalSdkCardInfo) memcpy(hdr->titleKey,(u8*)stock_title_key,0x10); else rndset(hdr->titleKey,0x10); return; }
void SetInitialData(cardinfo_hdr *hdr, cci_settings *set) { clrmem(hdr->initialData,0x30); if(set->options.useExternalSdkCardInfo) memcpy(hdr->initialData,(u8*)stock_initial_data,0x30); else rndset(hdr->initialData,0x2c); return; }
void AesCtrCrypt(u8 *key, u8 *ctr, u8 *input, u8 *output, u64 length, u64 offset) { u8 stream[16]; aes_context aes; size_t nc_off = 0; clrmem(&aes,sizeof(aes_context)); aes_setkey_enc(&aes, key, 128); SetAesCtrOffset(ctr,offset); aes_crypt_ctr(&aes, length, &nc_off, ctr, stream, input, output); return; }
void AesCbcCrypt(u8 *key, u8 *iv, u8 *input, u8 *output, u64 length, u8 mode) { aes_context aes; clrmem(&aes,sizeof(aes_context)); switch(mode){ case(ENC): aes_setkey_enc(&aes, key, 128); aes_crypt_cbc(&aes, AES_ENCRYPT, length, iv, input, output); return; case(DEC): aes_setkey_dec(&aes, key, 128); aes_crypt_cbc(&aes, AES_DECRYPT, length, iv, input, output); return; default: return; } }
long DoSyncPacket(MsgPort *dport, long action, long a1, long a2, long a3, long a4) { __aligned StdPacket std; clrmem(&std, sizeof(std)); std.sp_Msg.mn_Node.ln_Name = (char *)&std.sp_Pkt; std.sp_Pkt.dp_Link = &std.sp_Msg; std.sp_Pkt.dp_Port = AuxPort; std.sp_Pkt.dp_Type = action; std.sp_Pkt.dp_Arg1 = a1; std.sp_Pkt.dp_Arg2 = a2; std.sp_Pkt.dp_Arg3 = a3; std.sp_Pkt.dp_Arg4 = a4; dbprintf(("DoSynchPacket to %08lx type %08lx (%d) args %lx %lx %lx %lx\n", dport, std.sp_Pkt.dp_Type, std.sp_Pkt.dp_Type, std.sp_Pkt.dp_Arg1, std.sp_Pkt.dp_Arg2, std.sp_Pkt.dp_Arg3, std.sp_Pkt.dp_Arg4 )); PutMsg(dport, &std.sp_Msg); WaitPort(AuxPort); GetMsg(AuxPort); dbprintf(("Res1 %08lx Res2 %08lx\n", std.sp_Pkt.dp_Res1, std.sp_Pkt.dp_Res2 )); if (std.sp_Pkt.dp_Res1 == DOS_FALSE) return(-std.sp_Pkt.dp_Res2); /* if (std.sp_Pkt.dp_Res2 > 0) return(-std.sp_Pkt.dp_Res2); */ return(std.sp_Pkt.dp_Res1); }
void AddRelocInfo(short srcHunk, short dstHunk, long size, short flags, long offset, Symbol *sym) { RelocInfo *ri = malloc(sizeof(RelocInfo)); RelocInfo *r; if (ri == NULL) cerror(EFATAL, "malloc Failed"); clrmem(ri, sizeof(RelocInfo)); ri->ri_Sym = sym; ri->ri_SrcHunk = srcHunk; ri->ri_DstHunk = dstHunk; ri->ri_RelocSize = size; ri->ri_RelocFlags= flags; ri->ri_SrcOffset = offset; for (r = GetTail(&RelList); r; r = GetPred((Node *)&r->ri_Node)) { if (r->ri_SrcOffset < ri->ri_SrcOffset) break; } Insert(&RelList, (Node *)&ri->ri_Node, (Node *)&r->ri_Node); }
void SetDefaults(user_settings *set) { // Target Info set->common.keys.keyset = pki_TEST; set->common.keys.accessDescSign.presetType = desc_NotSpecified; // Build NCCH Info set->ncch.useSecCrypto = false; set->ncch.buildNcch0 = true; set->ncch.includeExefsLogo = false; set->common.outFormat = NCCH; set->ncch.ncchType = format_not_set; // RSF Settings clrmem(&set->common.rsfSet, sizeof(rsf_settings)); set->common.rsfSet.Option.EnableCompress = true; set->common.rsfSet.Option.EnableCrypt = false; set->common.rsfSet.Option.UseOnSD = false; set->common.rsfSet.Option.FreeProductCode = false; // Working File Info set->common.workingFileType = infile_ncch; // CCI Info set->cci.useSDKStockData = false; // CIA Info set->cia.includeUpdateNcch = false; set->cia.deviceId = 0; set->cia.eshopAccId = 0; set->cia.useDataTitleVer = false; set->cia.useFullTitleVer = false; set->cia.randomTitleKey = false; set->common.keys.aes.currentCommonKey = MAX_U8 + 1; // invalid so changes can be detected for (int i = 0; i < CIA_MAX_CONTENT; i++) set->cia.contentId[i] = MAX_U32 + 1; // invalid so changes can be detected }
void GetNcchAesCounter(u8 ctr[16], u64 titleId, u8 type) { clrmem(ctr,16); u64_to_u8(ctr,titleId,BE); ctr[8] = type; }