Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  FILE *in = NULL;
  FILE *out = NULL;
  SELF self;
  APP_INFO app_info;
  ELF elf;
  ELF_PHDR *phdr = NULL;
  ELF_SHDR *shdr = NULL;
  SECTION_INFO *section_info = NULL;
  SCEVERSION_INFO sceversion_info;
  CONTROL_INFO *control_info = NULL;
  METADATA_INFO metadata_info;
  METADATA_HEADER metadata_header;
  METADATA_SECTION_HEADER *section_headers = NULL;
  uint8_t *keys = NULL;
  SIGNATURE_INFO signature_info;
  SIGNATURE signature;
  SELF_SECTION *sections = NULL;
  int num_sections;
  int i;

  if (argc != 3) {
    fprintf(stderr, "usage: %s in.self out.elf\n", argv[0]);
    return -1;
  }

  in = fopen (argv[1], "rb");
  if (in == NULL) {
    ERROR (-2, "Can't open input file");
  }

  self_read_headers(in, &self, &app_info, &elf, &phdr, &shdr,
      &section_info, &sceversion_info, &control_info);

  self_read_metadata (in, &self, &app_info, &metadata_info,
      &metadata_header, &section_headers,  &keys,
      &signature_info, &signature);

  num_sections = self_load_sections (in, &self, &elf, &phdr,
      &metadata_header, &section_headers, &keys, &sections);

  fclose (in);

  out = fopen (argv[2], "wb");
  if (out == NULL) {
    ERROR (-2, "Can't open output file");
  }

  for (i = 0; i < num_sections; i++) {
    fseek (out, sections[i].offset, SEEK_SET);
    if (fwrite (sections[i].data, 1, sections[i].size, out) != sections[i].size) {
      ERROR (-7, "Error writing section");
    }
  }

  self_free_sections (&sections, num_sections);

  return 0;
}
Ejemplo n.º 2
0
static int install_sac_module(void)
{
#if 0
    FILE                      *in  = NULL;
    FILE                      *out = NULL;
    self_ehdr_t               self;
    app_info_t                app_info;
    elf_ehdr_t                elf;
    elf_phdr_t                *phdr         = NULL;
    elf_shdr_t                *shdr         = NULL;
    section_info_t            *section_info = NULL;
    sceversion_info_t         sceversion_info;
    control_info_t            *control_info = NULL;
    metadata_info_t           metadata_info;
    metadata_header_t         metadata_header;
    metadata_section_header_t *section_headers = NULL;
    uint8_t                   *keys            = NULL;
    signature_info_t          signature_info;
    signature_t               signature;
    self_section_t            *sections    = NULL;
    int                       num_sections = 0, ret;
    int                       i;
    uint8_t                   *isoself_data;
    size_t                    isoself_size;

    in = fopen(FILE_SAC_MODULE_SOURCE, "rb");
    if (in == NULL)
    {
        return -1;
    }

    ret = self_read_headers(in, &self, &app_info, &elf, &phdr, &shdr,
                            &section_info, &sceversion_info, &control_info);

    if (ret != 0)
        goto fail;

    ret = self_read_metadata(in, &self, &app_info, &metadata_info,
                             &metadata_header, &section_headers, &keys,
                             &signature_info, &signature);

    if (ret != 0)
        goto fail;

    num_sections = self_load_sections(in, &self, &elf, &phdr,
                                      &metadata_header, &section_headers, &keys, &sections);

    if (num_sections <= 0)
        goto fail;

    out = fopen(FILE_SAC_MODULE, "wb");
    if (out == NULL)
    {
        return -1;
    }

    for (i = 0; i < num_sections; i++)
    {
        fseek(out, (long) sections[i].offset, SEEK_SET);
        if (fwrite(sections[i].data, 1, (size_t) sections[i].size, out) != sections[i].size)
        {
            return -1;
        }
    }
    fclose(out);
    fclose(in);
    self_free_sections(&sections, num_sections);

    return 0;

 fail:

    fclose(in);
    self_free_sections(&sections, num_sections);

    return -1;
#else
    return unself(FILE_SAC_MODULE_SOURCE, FILE_SAC_MODULE);
#endif
}
Ejemplo n.º 3
0
static int install_decoder_module(void)
{
    FILE                      *in  = NULL;
    FILE                      *out = NULL;
    self_ehdr_t               self;
    app_info_t                app_info;
    elf_ehdr_t                elf;
    elf_phdr_t                *phdr         = NULL;
    elf_shdr_t                *shdr         = NULL;
    section_info_t            *section_info = NULL;
    sceversion_info_t         sceversion_info;
    control_info_t            *control_info = NULL;
    metadata_info_t           metadata_info;
    metadata_header_t         metadata_header;
    metadata_section_header_t *section_headers = NULL;
    uint8_t                   *keys            = NULL;
    signature_info_t          signature_info;
    signature_t               signature;
    self_section_t            *sections    = NULL;
    int                       num_sections = 0, ret;
    uint8_t                   *isoself_data;
    size_t                    isoself_size;

    in = fopen(FILE_SACD_PLUGIN_SOURCE, "rb");
    if (in == NULL)
    {
        return -1;
    }

    ret = self_read_headers(in, &self, &app_info, &elf, &phdr, &shdr,
                            &section_info, &sceversion_info, &control_info);

    if (ret != 0)
        goto fail;

    ret = self_read_metadata(in, &self, &app_info, &metadata_info,
                             &metadata_header, &section_headers, &keys,
                             &signature_info, &signature);

    if (ret != 0)
        goto fail;

    num_sections = self_load_sections(in, &self, &elf, &phdr,
                                      &metadata_header, &section_headers, &keys, &sections);

    isoself_size = find_isoself(sections, num_sections, "decoder.spu", &isoself_data);
    if (isoself_size)
    {
        out = fopen(FILE_DECODER, "wb");
        if (out == NULL)
        {
            return -1;
        }
        fwrite(isoself_data, isoself_size, 1, out);
        fclose(out);
    }

    fclose(in);

    self_free_sections(&sections, num_sections);

    if (!isoself_size)
        return -1;

    return 0;

 fail:

    fclose(in);
    self_free_sections(&sections, num_sections);

    return -1;
}