/*      
  _____     ___ ____ 
   ____|   |    ____|      PSX2 OpenSource Project
  |     ___|   |____       (c) 2008 jMk0Nm 
------------------------------------------------------------------------
build_osd.c

*/

#include "mcboot.h"

int build_OSD(u8 *original_dvdelf, u8 *injected_dvdelf, u8 *hacked_dvdelf)
{
  int i;
  u32 offset;
  Bit_Data_t *b;

  b = (Bit_Data_t *) (injected_dvdelf + 32 + 8 + 32);   // bit offset

  printf("Merge: Replacing unencrypted blocks... ");
  offset = b->headersize;
  for (i = 0; i < b->block_count; i++) {
    if ((b->blocks[i].flags & 2) == 0)
      memcpy(original_dvdelf + offset, injected_dvdelf + offset, b->blocks[i].size);
    offset += b->blocks[i].size;
  }
  printf("done.\n");
  
  memcpy(hacked_dvdelf, original_dvdelf, ((mg_ELF_Header_t *)original_dvdelf)->ELF_size + ((mg_ELF_Header_t *)original_dvdelf)->mg_header_size);

  return 1;
}
