//Pascal &or the FreePascal use of nintendo 2ds, 3ds regime // // Copyright (c) 2013, 2015 Kenny D. Lee // all rights reserved // type AM_TitleEntry = record titleID : u64; size : u64; version : u16; unk : array[0..5] of u8; end; PAM_TitleEntry = ^AM_TitleEntry; {/ Pending title status mask values. } const AM_STATUS_MASK_INSTALLING = $0000; ///< Titles currently installing. AM_STATUS_MASK_AWAITING_FINALIZATION = $0001; ///< Titles awaiting finalization. {/ Pending title deletion flags. } AM_DELETE_PENDING_NON_SYSTEM = (1 shl 0);// BIT(0), // Non-system titles. AM_DELETE_PENDING_SYSTEM = (1 shl 1); //BIT(1) // System titles. type AM_InstallStatus = (AM_STATUS_ABORTED := $0002,AM_STATUS_SAVED := $0003, AM_STATUS_INSTALL_IN_PROGRESS := $0802, AM_STATUS_AWAITING_FINALIZATION := $0803 ); AM_PendingTitleEntry = record titleId : u64; version : u16; status : u16; titleType : u32; unk : array[0..7] of u8; end; PAM_PendingTitleEntry = ^AM_PendingTitleEntry; {/ Partition Info } AM_TWLPartitionInfo = record capacity : u64; freeSpace : u64; titlesCapacity : u64; titlesFreeSpace : u64; end; PAM_TWLPartitionInfo = ^AM_TWLPartitionInfo; {/ Initializes AM. This doesn't initialize with "am:app", see amAppInit(). } function amInit:s32;cdecl;external; {/ Initializes AM with a service which has access to the amapp-commands. This should only be used when using the amapp commands, not non-amapp AM commands. } function amAppInit:s32;cdecl;external; {/ Exits AM. } procedure amExit;cdecl;external; {/ Gets the current AM session handle. } function amGetSessionHandle:PHandle;cdecl;external; {* * @brief Gets the number of titles for a given media type. * @param mediatype Media type to get titles from. * @param[out] count Pointer to write the title count to. } function AM_GetTitleCount(mediatype:FS_MediaType; count:Pu32):s32;cdecl;external; {* * @brief Gets a list of title IDs present in a mediatype. * @param[out] titlesRead Pointer to output the number of read titles to. * @param mediatype Media type to get titles from. * @param titleCount Number of title IDs to get. * @param titleIds Buffer to output the retrieved title IDs to. } function AM_GetTitleList(titlesRead:Pu32; mediatype:FS_MediaType; titleCount:u32; titleIds:Pu64):s32;cdecl;external; {* * @brief Gets a list of details about installed titles. * @param mediatype Media type to get titles from. * @param titleCount Number of titles to list. * @param titleIds List of title IDs to retrieve details for. * @param titleInfo Buffer to write AM_TitleEntry's to. } function AM_GetTitleInfo(mediatype:FS_MediaType; titleCount:u32; titleIds:Pu64; titleInfo:PAM_TitleEntry):s32;cdecl;external; {* * @brief Gets the number of tickets installed on the system. * @param[out] count Pointer to output the ticket count to. } function AM_GetTicketCount(count:Pu32):s32;cdecl;external; {* * @brief Gets a list of tickets installed on the system. * @param[out] ticketsRead Pointer to output the number of read tickets to. * @param ticketCount Number of tickets to read. * @param skip Number of tickets to skip. * @param ticketIds Buffer to output the retrieved ticket IDs to. } function AM_GetTicketList(ticketsRead:Pu32; ticketCount:u32; skip:u32; ticketIds:Pu64):s32;cdecl;external; {* * @brief Gets the number of pending titles on this system. * @param[out] count Pointer to output the pending title count to. * @param mediatype Media type of pending titles to count. * @param statusMask Bit mask of status values to include. } function AM_GetPendingTitleCount(count:Pu32; mediatype:FS_MediaType; statusMask:u32):s32;cdecl;external; {* * @brief Gets a list of pending titles on this system. * @param[out] titlesRead Pointer to output the number of read pending titles to. * @param titleCount Number of pending titles to read. * @param mediatype Media type of pending titles to list. * @param statusMask Bit mask of status values to include. * @param titleIds Buffer to output the retrieved pending title IDs to. } function AM_GetPendingTitleList(titlesRead:Pu32; titleCount:u32; mediatype:FS_MediaType; statusMask:u32; titleIds:Pu64):s32;cdecl;external; {* * @brief Gets information about pending titles on this system. * @param titleCount Number of pending titles to read. * @param mediatype Media type of pending titles to get information on. * @param titleIds IDs of the titles to get information about. * @param titleInfo Buffer to output the retrieved pending title info to. } function AM_GetPendingTitleInfo(titleCount:u32; mediatype:FS_MediaType; titleIds:Pu64; titleInfo:PAM_PendingTitleEntry):s32;cdecl;external; {* * @brief Gets a 32-bit device-specific ID. * @param deviceID Pointer to write the device ID to. } function AM_GetDeviceId(deviceID:Pu32):s32;cdecl;external; {* * @brief Exports DSiWare to the specified filepath. * @param titleID TWL titleID. * @param operation DSiWare operation type. * @param workbuf Work buffer. * @param workbuf_size Work buffer size, must be >=0x20000. * @param filepath UTF-8 filepath(converted to UTF-16 internally). } (* Const before type ignored *) function AM_ExportTwlBackup(titleID:u64; operation:u8; workbuf:pointer; workbuf_size:u32; filepath:pcchar):s32;cdecl;external; {* * @brief Imports DSiWare from the specified file. * @param filehandle FSUSER file handle. * @param operation DSiWare operation type. * @param buffer Work buffer. * @param size Buffer size, must be >=0x20000. } function AM_ImportTwlBackup(filehandle:Handle; operation:u8; buffer:pointer; size:u32):s32;cdecl;external; {* * @brief Reads info from the specified DSiWare export file. This can only be used with DSiWare exported with certain operation value(s). * @param filehandle FSUSER file handle. * @param outinfo Output info buffer. * @param outinfo_size Output info buffer size. * @param workbuf Work buffer. * @param workbuf_size Work buffer size. * @param banner Output banner buffer. * @param banner_size Output banner buffer size. } function AM_ReadTwlBackupInfo(filehandle:Handle; outinfo:pointer; outinfo_size:u32; workbuf:pointer; workbuf_size:u32; banner:pointer; banner_size:u32):s32;cdecl;external; {* * @brief Retrieves information about the NAND TWL partition. * @param[out] info Pointer to output the TWL partition info to. } function AM_GetTWLPartitionInfo(info:PAM_TWLPartitionInfo):s32;cdecl;external; {* * @brief Initializes the CIA install process, returning a handle to write CIA data to. * @param mediatype Media type to install the CIA to. * @param[out] ciaHandle Pointer to write the CIA handle to. } function AM_StartCiaInstall(mediatype:FS_MediaType; ciaHandle:PHandle):s32;cdecl;external; {* * @brief Initializes the CIA install process for Download Play CIAs, returning a handle to write CIA data to. * @param[out] ciaHandle Pointer to write the CIA handle to. } function AM_StartDlpChildCiaInstall(ciaHandle:PHandle):s32;cdecl;external; {* * @brief Aborts the CIA install process. * @param ciaHandle CIA handle to cancel. } function AM_CancelCIAInstall(ciaHandle:Handle):s32;cdecl;external; {* * @brief Finalizes the CIA install process. * @param ciaHandle CIA handle to finalize. } function AM_FinishCiaInstall(ciaHandle:Handle):s32;cdecl;external; {* * @brief Finalizes the CIA install process without committing the title to title.db or tmp*.db. * @param ciaHandle CIA handle to finalize. } function AM_FinishCiaInstallWithoutCommit(ciaHandle:Handle):s32;cdecl;external; {* * @brief Commits installed CIAs. * @param mediaType Location of the titles to finalize. * @param titleCount Number of titles to finalize. * @param temp Whether the titles being finalized are in the temporary database. * @param titleIds Title IDs to finalize. } (* Const before type ignored *) function AM_CommitImportPrograms(mediaType:FS_MediaType; titleCount:u32; temp:bool; titleIds:Pu64):s32;cdecl;external; {* * @brief Deletes a title. * @param mediatype Media type to delete from. * @param titleID ID of the title to delete. } function AM_DeleteTitle(mediatype:FS_MediaType; titleID:u64):s32;cdecl;external; {* * @brief Deletes a title, provided that it is not a system title. * @param mediatype Media type to delete from. * @param titleID ID of the title to delete. } function AM_DeleteAppTitle(mediatype:FS_MediaType; titleID:u64):s32;cdecl;external; {* * @brief Deletes a ticket. * @param titleID ID of the ticket to delete. } function AM_DeleteTicket(ticketId:u64):s32;cdecl;external; {* * @brief Deletes a pending title. * @param mediatype Media type to delete from. * @param titleId ID of the pending title to delete. } function AM_DeletePendingTitle(mediatype:FS_MediaType; titleId:u64):s32;cdecl;external; {* * @brief Deletes pending titles. * @param mediatype Media type to delete from. * @param flags Flags used to select pending titles. } function AM_DeletePendingTitles(mediatype:FS_MediaType; flags:u32):s32;cdecl;external; {* * @brief Deletes all pending titles. * @param mediatype Media type to delete from. } function AM_DeleteAllPendingTitles(mediatype:FS_MediaType):s32;cdecl;external; {/ Installs the current NATIVE_FIRM title to NAND (firm0:/ & firm1:/) } function AM_InstallNativeFirm:s32;cdecl;external; {* * @brief Installs a NATIVE_FIRM title to NAND. Accepts 0004013800000002 or 0004013820000002 (N3DS). * @param titleID Title ID of the NATIVE_FIRM to install. } function AM_InstallFirm(titleID:u64):s32;cdecl;external; {* * @brief Gets the product code of a title. * @param mediatype Media type of the title. * @param titleID ID of the title. * @param[out] productCode Pointer to output the product code to. (length = 16) } function AM_GetTitleProductCode(mediatype:FS_MediaType; titleId:u64; productCode:pcchar):s32;cdecl;external; {* * @brief Gets the ext data ID of a title. * @param[out] extDataId Pointer to output the ext data ID to. * @param mediatype Media type of the title. * @param titleID ID of the title. } function AM_GetTitleExtDataId(extDataId:Pu64; mediatype:FS_MediaType; titleId:u64):s32;cdecl;external; {* * @brief Gets an AM_TitleEntry instance for a CIA file. * @param mediatype Media type that this CIA would be installed to. * @param[out] titleEntry Pointer to write the AM_TitleEntry instance to. * @param fileHandle Handle of the CIA file. } function AM_GetCiaFileInfo(mediatype:FS_MediaType; titleEntry:PAM_TitleEntry; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the SMDH icon data of a CIA file. * @param icon Buffer to store the icon data in. Must be of size 0x36C0 bytes. * @param fileHandle Handle of the CIA file. } function AM_GetCiaIcon(icon:pointer; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the title ID dependency list of a CIA file. * @param dependencies Buffer to store dependency title IDs in. Must be of size 0x300 bytes. * @param fileHandle Handle of the CIA file. } function AM_GetCiaDependencies(dependencies:Pu64; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the meta section offset of a CIA file. * @param[out] metaOffset Pointer to output the meta section offset to. * @param fileHandle Handle of the CIA file. } function AM_GetCiaMetaOffset(metaOffset:Pu64; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the core version of a CIA file. * @param[out] coreVersion Pointer to output the core version to. * @param fileHandle Handle of the CIA file. } function AM_GetCiaCoreVersion(coreVersion:Pu32; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the free space, in bytes, required to install a CIA file. * @param[out] requiredSpace Pointer to output the required free space to. * @param mediaType Media type to check free space needed to install to. * @param fileHandle Handle of the CIA file. } function AM_GetCiaRequiredSpace(requiredSpace:Pu64; mediaType:FS_MediaType; fileHandle:Handle):s32;cdecl;external; {* * @brief Gets the full meta section of a CIA file. * @param meta Buffer to store the meta section in. * @param size Size of the buffer. Must be greater than or equal to the actual section data's size. * @param fileHandle Handle of the CIA file. } function AM_GetCiaMetaSection(meta:pointer; size:u32; fileHandle:Handle):s32;cdecl;external; {* * @brief Initializes the external (SD) title database. * @param overwrite Overwrites the database if it already exists. } function AM_InitializeExternalTitleDatabase(overwrite:bool):s32;cdecl;external; {* * @brief Queries whether the external title database is available. * @param[out] available Pointer to output the availability status to. } function AM_QueryAvailableExternalTitleDatabase(available:Pbool):s32;cdecl;external; {* * @brief Begins installing a ticket. * @param[out] ticketHandle Pointer to output a handle to write ticket data to. } function AM_InstallTicketBegin(ticketHandle:PHandle):s32;cdecl;external; {* * @brief Aborts installing a ticket. * @param ticketHandle Handle of the installation to abort. } function AM_InstallTicketAbort(ticketHandle:Handle):s32;cdecl;external; {* * @brief Finishes installing a ticket. * @param ticketHandle Handle of the installation to finalize. } function AM_InstallTicketFinish(ticketHandle:Handle):s32;cdecl;external; {* * @brief Begins installing a title. * @param mediaType Destination to install to. * @param titleId ID of the title to install. * @param unk Unknown. (usually false) } function AM_InstallTitleBegin(mediaType:FS_MediaType; titleId:u64; unk:bool):s32;cdecl;external; {/ Stops installing a title, generally to be resumed later. } function AM_InstallTitleStop:s32;cdecl;external; {* * @brief Resumes installing a title. * @param mediaType Destination to install to. * @param titleId ID of the title to install. } function AM_InstallTitleResume(mediaType:FS_MediaType; titleId:u64):s32;cdecl;external; {/ Aborts installing a title. } function AM_InstallTitleAbort:s32;cdecl;external; {/ Finishes installing a title. } function AM_InstallTitleFinish:s32;cdecl;external; {* * @brief Commits installed titles. * @param mediaType Location of the titles to finalize. * @param titleCount Number of titles to finalize. * @param temp Whether the titles being finalized are in the temporary database. * @param titleIds Title IDs to finalize. } (* Const before type ignored *) function AM_CommitImportTitles(mediaType:FS_MediaType; titleCount:u32; temp:bool; titleIds:Pu64):s32;cdecl;external; {* * @brief Begins installing a TMD. * @param[out] tmdHandle Pointer to output a handle to write TMD data to. } function AM_InstallTmdBegin(tmdHandle:PHandle):s32;cdecl;external; {* * @brief Aborts installing a TMD. * @param tmdHandle Handle of the installation to abort. } function AM_InstallTmdAbort(tmdHandle:Handle):s32;cdecl;external; {* * @brief Finishes installing a TMD. * @param tmdHandle Handle of the installation to finalize. * @param unk Unknown. (usually true) } function AM_InstallTmdFinish(tmdHandle:Handle; unk:bool):s32;cdecl;external; {* * @brief Prepares to import title contents. * @param contentCount Number of contents to be imported. * @param contentIndices Indices of the contents to be imported. } function AM_CreateImportContentContexts(contentCount:u32; contentIndices:Pu16):s32;cdecl;external; {* * @brief Begins installing title content. * @param[out] contentHandle Pointer to output a handle to write content data to. * @param index Index of the content to install. } function AM_InstallContentBegin(contentHandle:PHandle; index:u16):s32;cdecl;external; {* * @brief Stops installing title content, generally to be resumed later. * @param contentHandle Handle of the installation to abort. } function AM_InstallContentStop(contentHandle:Handle):s32;cdecl;external; {* * @brief Resumes installing title content. * @param[out] contentHandle Pointer to output a handle to write content data to. * @param[out] resumeOffset Pointer to write the offset to resume content installation at to. * @param index Index of the content to install. } function AM_InstallContentResume(contentHandle:PHandle; resumeOffset:Pu64; index:u16):s32;cdecl;external; {* * @brief Cancels installing title content. * @param contentHandle Handle of the installation to finalize. } function AM_InstallContentCancel(contentHandle:Handle):s32;cdecl;external; {* * @brief Finishes installing title content. * @param contentHandle Handle of the installation to finalize. } function AM_InstallContentFinish(contentHandle:Handle):s32;cdecl;external; {* * @brief Imports up to four certificates into the ticket certificate chain. * @param cert1Size Size of the first certificate. * @param cert1 Data of the first certificate. * @param cert2Size Size of the second certificate. * @param cert2 Data of the second certificate. * @param cert3Size Size of the third certificate. * @param cert3 Data of the third certificate. * @param cert4Size Size of the fourth certificate. * @param cert4 Data of the fourth certificate. } function AM_ImportCertificates(cert1Size:u32; cert1:pointer; cert2Size:u32; cert2:pointer; cert3Size:u32; cert3:pointer; cert4Size:u32; cert4:pointer):s32;cdecl;external; {* * @brief Imports a certificate into the ticket certificate chain. * @param certSize Size of the certificate. * @param cert Data of the certificate. } function AM_ImportCertificate(certSize:u32; cert:pointer):s32;cdecl;external; {* * @brief Commits installed titles, and updates FIRM if necessary. * @param mediaType Location of the titles to finalize. * @param titleCount Number of titles to finalize. * @param temp Whether the titles being finalized are in the temporary database. * @param titleIds Title IDs to finalize. } function AM_CommitImportTitlesAndUpdateFirmwareAuto(mediaType:FS_MediaType; titleCount:u32; temp:bool; titleIds:Pu64):s32;cdecl;external; {/ Resets play count of all installed demos by deleting their launch info. } function AM_DeleteAllDemoLaunchInfos:s32;cdecl;external;