Advertisement
Guest User

new types.h

a guest
Mar 12th, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 KB | None | 0 0
  1. // Copyright 2010       Sven Peter <svenpeter@gmail.com>
  2. // Licensed under the terms of the GNU GPL, version 2
  3. // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
  4. #ifndef TYPES_H__
  5. #define TYPES_H__
  6.  
  7. #include <stdint.h>
  8.  
  9. typedef uint64_t u64;
  10. typedef uint32_t u32;
  11. typedef uint16_t u16;
  12. typedef uint8_t u8;
  13.  
  14.  
  15. struct elf_phdr {
  16.     u32 p_type;
  17.     u64 p_off;
  18.     u64 p_vaddr;
  19.     u64 p_paddr;
  20.     u64 p_filesz;
  21.     u64 p_memsz;
  22.     u32 p_flags;
  23.     u64 p_align;
  24.  
  25.     void *ptr;
  26. };
  27.  
  28. struct elf_shdr {
  29.     u32 sh_name;
  30.     u32 sh_type;
  31.     u32 sh_flags;
  32.     u64 sh_addr;
  33.     u64 sh_offset;
  34.     u32 sh_size;
  35.     u32 sh_link;
  36.     u32 sh_info;
  37.     u32 sh_addralign;
  38.     u32 sh_entsize;
  39. };
  40.  
  41. #define ET_NONE     0
  42. #define ET_REL      1
  43. #define ET_EXEC     2
  44. #define ET_DYN      3
  45. #define ET_CORE     4
  46. #define ET_LOOS     0xfe00
  47. #define ET_HIOS     0xfeff
  48. #define ET_LOPROC   0xff00
  49. #define ET_HIPROC   0xffff
  50. struct elf_hdr {
  51.     char e_ident[16];
  52.     u16 e_type;
  53.     u16 e_machine;
  54.     u32 e_version;
  55.     u64 e_entry;
  56.     u64 e_phoff;
  57.     u64 e_shoff;
  58.     u32 e_flags;
  59.     u16 e_ehsize;
  60.     u16 e_phentsize;
  61.     u16 e_phnum;
  62.     u16 e_shentsize;
  63.     u16 e_shnum;
  64.     u16 e_shtrndx;
  65. };
  66.  
  67. typedef struct {
  68.    u32 magic;
  69.    u32 pkg_type;
  70.    u32 pkg_info_offset;
  71.    u32 pkg_info_size;
  72.    u32 header_size;
  73.    u32 item_count;
  74.    u64 total_size;
  75.    u64 data_offset;
  76.    u64 data_size;
  77.    char contentid[0x30];
  78.    u8 digest[0x10];
  79.    u8 k_licensee[0x10];
  80. } PKG_HEADER;
  81.  
  82. typedef struct {
  83.    u32 filename_offset;
  84.    u32 filename_size;
  85.    u64 data_offset;
  86.    u64 data_size;
  87.    u32 flags;
  88.    u32 padding;
  89. } PKG_FILE_HEADER;
  90.  
  91.  
  92. struct id2name_tbl {
  93.     u32 id;
  94.     const char *name;
  95. };
  96.  
  97. struct key {
  98.     u8 key[32];
  99.     u8 iv[16];
  100.  
  101.     int pub_avail;
  102.     int priv_avail;
  103.     u8 pub[40];
  104.     u8 priv[21];
  105.     u32 ctype;
  106. };
  107.  
  108. struct keylist {
  109.     u32 n;
  110.     struct key *keys;
  111.     struct key *idps;
  112.     struct key *klic;
  113.     struct key *rif;
  114.     struct key *npdrm_const;
  115.     struct key *free_klicensee;
  116. };
  117.  
  118. struct rif {
  119.     u8 unk1[0x10]; //version, license type and user number
  120.     u8 titleid[0x30]; //Content ID
  121.     u8 padding[0xC]; //Padding for randomness
  122.     u32 actDatIndex; //Key index on act.dat between 0x00 and 0x7F
  123.     u8 key[0x10]; //encrypted klicensee
  124.     u64 unk2; //timestamp??
  125.     u64 unk3; //Always 0
  126.     u8 rs[0x28];
  127. } __attribute__ ((packed));
  128.  
  129. struct actdat {
  130.     u8 unk1[0x10]; //Version, User number
  131.     u8 keyTable[0x800]; //Key Table
  132.     u8 unk2[0x800];
  133.     u8 signature[0x28];
  134. } __attribute__ ((packed));
  135.  
  136. static inline u8 be8(u8 *p)
  137. {
  138.     return *p;
  139. }
  140.  
  141. static inline u16 be16(u8 *p)
  142. {
  143.     u16 a;
  144.  
  145.     a  = p[0] << 8;
  146.     a |= p[1];
  147.  
  148.     return a;
  149. }
  150.  
  151. static inline u32 be32(u8 *p)
  152. {
  153.     u32 a;
  154.  
  155.     a  = p[0] << 24;
  156.     a |= p[1] << 16;
  157.     a |= p[2] <<  8;
  158.     a |= p[3] <<  0;
  159.  
  160.     return a;
  161. }
  162.  
  163. static inline u64 be64(u8 *p)
  164. {
  165.     u32 a, b;
  166.  
  167.     a = be32(p);
  168.     b = be32(p + 4);
  169.  
  170.     return ((u64)a<<32) | b;
  171. }
  172.  
  173. static inline void wbe16(u8 *p, u16 v)
  174. {
  175.     p[0] = v >>  8;
  176.     p[1] = v;
  177. }
  178.  
  179. static inline void wbe32(u8 *p, u32 v)
  180. {
  181.     p[0] = v >> 24;
  182.     p[1] = v >> 16;
  183.     p[2] = v >>  8;
  184.     p[3] = v;
  185. }
  186.  
  187. static inline void wbe64(u8 *p, u64 v)
  188. {
  189.     wbe32(p + 4, v);
  190.     v >>= 32;
  191.     wbe32(p, v);
  192. }
  193.  
  194. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement