Guest User

Untitled

a guest
Jun 18th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.03 KB | None | 0 0
  1. //dont wait an app from me, here source perhaps it can help to get all pieces togeher, now all is up to you
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. #include <kernel.h>
  7. #include <system_service.h>
  8. #include <orbis2d.h>
  9. #include <orbisPad.h>
  10. #include <orbisAudio.h>
  11. #include <modplayer.h>
  12. #include <ps4link.h>
  13. #include <debugnet.h>
  14. #include <orbissys.h>
  15.  
  16. #include <string.h>
  17.  
  18. #include <elfloader.h>
  19.  
  20. #include <ps4/error.h>
  21.  
  22. typedef struct OrbisGlobalConf
  23. {
  24. Orbis2dConfig *conf;
  25. OrbisPadConfig *confPad;
  26. OrbisAudioConfig *confAudio;
  27. ps4LinkConfiguration *confLink;
  28. int orbisLinkFlag;
  29. }OrbisGlobalConf;
  30.  
  31. OrbisGlobalConf globalConf;
  32. //IV0002-NPXS29040_00-ORBISLINK0000000
  33.  
  34.  
  35. size_t sceLibcHeapSize = 256 * 1024 * 1024;
  36.  
  37.  
  38.  
  39. typedef struct Ps4MemoryProtected
  40. {
  41. void *writable;
  42. void *executable;
  43. size_t size;
  44. }Ps4MemoryProtected;
  45. int ps4MemoryProtectedCreate(Ps4MemoryProtected **memory, size_t size)
  46. {
  47. int executableHandle, writableHandle;
  48. Ps4MemoryProtected *m;
  49. long pageSize = 0x4000;//sysconf(_SC_PAGESIZE);
  50.  
  51. if(memory == NULL)
  52. return PS4_ERROR_ARGUMENT_PRIMARY_MISSING;
  53.  
  54. if(size == 0)
  55. return PS4_ERROR_ARGUMENT_SIZE_NULL;
  56.  
  57. m = (Ps4MemoryProtected *)malloc(sizeof(Ps4MemoryProtected));
  58. if(m == NULL)
  59. return PS4_ERROR_OUT_OF_MEMORY;
  60.  
  61. m->size = (size / pageSize + 1) * pageSize; // align to pageSize
  62.  
  63.  
  64. m->executable = mmap(NULL, m->size, 7, 0x1000, -1, 0);
  65. if(m->executable == MAP_FAILED)
  66. goto e1;
  67. m->writable = m->executable;
  68. if(m->writable == MAP_FAILED)
  69. goto e1;
  70. *memory = m;
  71. return PS4_OK;
  72.  
  73. e1:
  74. free(m);
  75.  
  76. return PS4_ERROR_OUT_OF_MEMORY; // make error codes proper errnos ... everywhere ... meh
  77. }
  78.  
  79. int ps4MemoryProtectedDestroy(Ps4MemoryProtected *memory)
  80. {
  81. int r = 0;
  82. if(memory == NULL)
  83. return -1;
  84. r |= munmap(memory->writable, memory->size);
  85. r |= munmap(memory->executable, memory->size);
  86. free(memory);
  87. return r;
  88. }
  89.  
  90. int ps4MemoryProtectedGetWritableAddress(Ps4MemoryProtected *memory, void **address)
  91. {
  92. if(memory == NULL)
  93. return PS4_ERROR_ARGUMENT_PRIMARY_MISSING;
  94. if(address == NULL)
  95. return PS4_ERROR_ARGUMENT_OUT_MISSING;
  96. *address = memory->writable;
  97. return PS4_OK;
  98. }
  99.  
  100. int ps4MemoryProtectedGetExecutableAddress(Ps4MemoryProtected *memory, void **address)
  101. {
  102. if(memory == NULL)
  103. return PS4_ERROR_ARGUMENT_PRIMARY_MISSING;
  104. if(address == NULL)
  105. return PS4_ERROR_ARGUMENT_OUT_MISSING;
  106. *address = memory->executable;
  107. return PS4_OK;
  108. }
  109.  
  110. int ps4MemoryProtectedGetSize(Ps4MemoryProtected *memory, size_t *size)
  111. {
  112. if(memory == NULL)
  113. return PS4_ERROR_ARGUMENT_PRIMARY_MISSING;
  114. if(size == NULL)
  115. return PS4_ERROR_ARGUMENT_OUT_MISSING;
  116. *size = memory->size;
  117. return PS4_OK;
  118. }
  119.  
  120. void orbisMemorySet(void *p,unsigned char value,int size)
  121. {
  122.  
  123. unsigned char *buf=(unsigned char *)p;
  124. //for(i=0;i<size;i++)
  125. //{
  126. // buf[i]=value;
  127. //}
  128. debugNetPrintf(3,"[ORBISLINK] orbisMemorySet before memset\n");
  129. memset(buf,value,size);
  130. debugNetPrintf(3,"[ORBISLINK] orbisMemorySet after memset\n");
  131.  
  132.  
  133. }
  134. void orbisMemoryCopy(void *to,void *from,size_t size)
  135. {
  136.  
  137.  
  138. debugNetPrintf(DEBUG,"[ORBISLINK] orbisMemoryCopy before memcpy\n");
  139.  
  140. memcpy(to,from,size);
  141. debugNetPrintf(DEBUG,"[ORBISLINK] orbisMemoryCopy after memcpy\n");
  142.  
  143. }
  144.  
  145. /* Defines */
  146.  
  147. #define elfRelocationSymbol __ELFN(R_SYM)
  148. #define elfRelocationType __ELFN(R_TYPE)
  149. #define elfRelocationInfo __ELFN(R_INFO)
  150.  
  151. #define elfSymbolBind __ELFN(ST_BIND)
  152. #define elfSymbolType __ELFN(ST_TYPE)
  153. #define elfSymbolInfo __ELFN(ST_INFO)
  154.  
  155. #define elfIsElf(e) IS_ELF(*elfHeader(e)) // FIXME: Null deref
  156.  
  157. #define elfClass(e) (e == NULL ? 0 : e->data[4])
  158. #define elfEncoding(e) (e == NULL ? 0 : e->data[5])
  159. #define elfVersion(e) (e == NULL ? 0 : e->data[6])
  160. #define elfABI(e) (e == NULL ? 0 : e->data[7])
  161.  
  162. /* Constants */
  163.  
  164. enum{ ELF_MAXIMAL_STRING_LENGTH = 4096 };
  165.  
  166. /* Type */
  167.  
  168. typedef struct Elf // FIXME: We could cache a lot of offsets here to inc. performance
  169. {
  170. uint8_t *data;
  171. size_t size; // FIXME: Do more checks on size
  172. }
  173. Elf;
  174.  
  175. size_t elfGetSize(Elf *elf)
  176. {
  177. return elf->size;
  178. }
  179.  
  180. uint8_t *elfGetData(Elf *elf)
  181. {
  182. return elf->data;
  183. }
  184.  
  185. /* --- elf header --- */
  186.  
  187. ElfHeader *elfHeader(Elf *elf)
  188. {
  189. if(!elf)
  190. return NULL;
  191. return (ElfHeader *)elf->data;
  192. }
  193.  
  194. uint64_t elfEntry(Elf *elf)
  195. {
  196. if(!elf)
  197. return 0;
  198. ElfHeader *h = elfHeader(elf);
  199. if(!h)
  200. return 0;
  201. return h->e_entry;
  202. }
  203.  
  204. uint64_t elfLargestAlignment(Elf *elf) //ignore ...
  205. {
  206. uint16_t index = 0;
  207. uint64_t alignment = 0;
  208.  
  209. while(1)
  210. {
  211. ElfSegment *h = elfSegment(elf, &index, ELF_SEGMENT_ATTRIBUTE_TYPE, PT_LOAD);
  212. if(!h)
  213. break;
  214.  
  215. // FIXME: Tired of bogus 2MB alignment -> ignore
  216. if(alignment < h->p_align && h->p_align < 0x200000)
  217. alignment = h->p_align;
  218. ++index;
  219. }
  220. return alignment;
  221. }
  222.  
  223. size_t elfMemorySize(Elf *elf)
  224. {
  225. ElfSection *sections;
  226. ElfSegment *segments;
  227.  
  228. uint16_t size;
  229. uint16_t length;
  230. uint16_t index;
  231.  
  232. size_t memorySize = 0;
  233.  
  234. if(!elf)
  235. return 0;
  236.  
  237. segments = elfSegments(elf, &size, &length);
  238. if(segments)
  239. {
  240. for(index = 0; index < length; ++index)
  241. {
  242. ElfSegment *s = (ElfSegment *)((uint8_t *)segments + index * size);
  243. if(memorySize < s->p_paddr + s->p_memsz)
  244. memorySize = s->p_paddr + s->p_memsz;
  245. }
  246. }
  247. else
  248. {
  249. length = 0;
  250. sections = elfSections(elf, &size, &length);
  251. if(!sections)
  252. return 0;
  253. for(index = 0; index < length; ++index)
  254. {
  255. ElfSection *s = (ElfSection *)((uint8_t *)sections + index * size);
  256. if(memorySize < s->sh_addr + s->sh_size)
  257. memorySize = s->sh_addr + s->sh_size;
  258. }
  259. }
  260.  
  261. return memorySize;
  262. }
  263.  
  264. /* --- elf section header --- */
  265.  
  266. char *elfSectionStrings(Elf *elf, uint64_t *size)
  267. {
  268. ElfHeader *h;
  269. uint16_t i;
  270. ElfSection *s;
  271. h = elfHeader(elf);
  272. i = h->e_shstrndx;
  273. s = elfSection(elf, &i, ELF_SECTION_ATTRIBUTE_NONE, 0);
  274. if(size)
  275. *size = s->sh_size;
  276. return (char *)elf->data + s->sh_offset;
  277. }
  278.  
  279. uint64_t elfSectionAttribute(ElfSection *elfSection, ElfSectionAttribute attribute)
  280. {
  281. switch(attribute)
  282. {
  283. case ELF_SECTION_ATTRIBUTE_NAME:
  284. return elfSection->sh_name;
  285. case ELF_SECTION_ATTRIBUTE_TYPE:
  286. return elfSection->sh_type;
  287. case ELF_SECTION_ATTRIBUTE_FLAGS:
  288. return elfSection->sh_flags;
  289. case ELF_SECTION_ATTRIBUTE_ADDRESS:
  290. return elfSection->sh_addr;
  291. case ELF_SECTION_ATTRIBUTE_OFFSET:
  292. return elfSection->sh_offset;
  293. case ELF_SECTION_ATTRIBUTE_SIZE:
  294. return elfSection->sh_size;
  295. case ELF_SECTION_ATTRIBUTE_LINK:
  296. return elfSection->sh_link;
  297. case ELF_SECTION_ATTRIBUTE_INFO:
  298. return elfSection->sh_info;
  299. case ELF_SECTION_ATTRIBUTE_MEMORY_ALIGNMENT:
  300. return elfSection->sh_addralign;
  301. case ELF_SECTION_ATTRIBUTE_ENTRY_SIZE:
  302. return elfSection->sh_entsize;
  303. default:
  304. break;
  305. }
  306. return 0;
  307. }
  308.  
  309. ElfSection *elfSections(Elf *elf, uint16_t *size, uint16_t *length)
  310. {
  311. ElfHeader *h;
  312.  
  313. if(!elf)
  314. return NULL;
  315.  
  316. h = elfHeader(elf);
  317.  
  318. if(h->e_shoff == 0)
  319. return NULL;
  320.  
  321. if(size != NULL)
  322. *size = h->e_shentsize;
  323. if(length != NULL)
  324. *length = h->e_shnum;
  325.  
  326. return (ElfSection *)(elf->data + h->e_shoff);
  327. }
  328.  
  329. ElfSection *elfSection(Elf *elf, uint16_t *index, ElfSectionAttribute attribute, uint64_t value)
  330. {
  331. uint16_t size;
  332. uint16_t length;
  333. ElfSection *h, *t;
  334. uint16_t i = 0;
  335.  
  336. if(!index)
  337. index = &i;
  338.  
  339. h = elfSections(elf, &size, &length);
  340.  
  341. if(!h)
  342. return NULL;
  343.  
  344. for(; *index < length; ++(*index))
  345. {
  346. t = (ElfSection *)((uint8_t *)h + *index * size);
  347. if(attribute == ELF_SECTION_ATTRIBUTE_NONE || elfSectionAttribute(t, attribute) == value)
  348. return t;
  349. }
  350.  
  351. return NULL;
  352. }
  353.  
  354. ElfSection *elfSectionByName(Elf *elf, char *name)
  355. {
  356. uint64_t size;
  357. char *mem = elfSectionStrings(elf, &size);
  358.  
  359. uint32_t offset = elfStringToOffset(mem, size, name);
  360. ElfSection *sh = elfSection(elf, NULL, ELF_SECTION_ATTRIBUTE_NAME, offset);
  361.  
  362. return sh;
  363. }
  364.  
  365. /* --- elf segment header --- */
  366.  
  367. uint64_t elfSegmentAttribute(ElfSegment *elfSegment, ElfSegmentAttribute attribute)
  368. {
  369. switch(attribute)
  370. {
  371. case ELF_SEGMENT_ATTRIBUTE_TYPE:
  372. return elfSegment->p_type;
  373. case ELF_SEGMENT_ATTRIBUTE_FLAGS:
  374. return elfSegment->p_flags;
  375. case ELF_SEGMENT_ATTRIBUTE_OFFSET:
  376. return elfSegment->p_offset;
  377. case ELF_SEGMENT_ATTRIBUTE_VIRTUAL_ADDRESS:
  378. return elfSegment->p_vaddr;
  379. case ELF_SEGMENT_ATTRIBUTE_PHYSICAL_ADDRESS:
  380. return elfSegment->p_paddr;
  381. case ELF_SEGMENT_ATTRIBUTE_FILE_SIZE:
  382. return elfSegment->p_filesz;
  383. case ELF_SEGMENT_ATTRIBUTE_MEMORY_SIZE:
  384. return elfSegment->p_memsz;
  385. case ELF_SEGMENT_ATTRIBUTE_ALIGNMENT:
  386. return elfSegment->p_align;
  387. default:
  388. break;
  389. }
  390. return 0;
  391. }
  392.  
  393. ElfSegment *elfSegments(Elf *elf, uint16_t *size, uint16_t *length)
  394. {
  395. ElfHeader *h;
  396.  
  397. if(!elf)
  398. return NULL;
  399.  
  400. h = elfHeader(elf);
  401.  
  402. if(h->e_phoff == 0)
  403. return NULL;
  404.  
  405. if(size != NULL)
  406. *size = h->e_phentsize;
  407. if(length != NULL)
  408. *length = h->e_phnum;
  409.  
  410. return (ElfSegment *)(elf->data + h->e_phoff);
  411. }
  412.  
  413. ElfSegment *elfSegment(Elf *elf, uint16_t *index, ElfSegmentAttribute attribute, uint64_t value)
  414. {
  415. uint16_t size;
  416. uint16_t length;
  417. ElfSegment *h, *t;
  418. uint16_t i = 0;
  419.  
  420. if(!index)
  421. index = &i;
  422.  
  423. h = elfSegments(elf, &size, &length);
  424.  
  425. if(!h)
  426. return NULL;
  427.  
  428. for(; *index < length; ++(*index))
  429. {
  430. t = (ElfSegment *)((uint8_t *)h + *index * size);
  431. if(attribute == ELF_SEGMENT_ATTRIBUTE_NONE || elfSegmentAttribute(t, attribute) == value)
  432. return t;
  433. }
  434.  
  435. return NULL;
  436. }
  437.  
  438. /* --- elf dynamic section --- */
  439.  
  440. uint64_t elfDynamicAttribute(ElfDynamic *elfDynamic, ElfDynamicAttribute attribute)
  441. {
  442. switch(attribute)
  443. {
  444. case ELF_DYNAMIC_ATTRIBUTE_TAG:
  445. return elfDynamic->d_tag;
  446. case ELF_DYNAMIC_ATTRIBUTE_VALUE:
  447. return elfDynamic->d_un.d_val;
  448. case ELF_DYNAMIC_ATTRIBUTE_POINTER:
  449. return elfDynamic->d_un.d_ptr;
  450. default:
  451. break;
  452. }
  453. return 0;
  454. }
  455.  
  456. uint16_t elfDynamicsLength(ElfDynamic *dyn)
  457. {
  458. uint16_t i = 0;
  459. if(dyn != NULL)
  460. for(;dyn->d_tag != DT_NULL; ++dyn)
  461. ++i;
  462. return i;
  463. }
  464.  
  465. ElfDynamic *elfDynamics(Elf *elf, uint16_t *size, uint16_t *length)
  466. {
  467. ElfSection *h;
  468. ElfSegment *h2;
  469.  
  470. if(!elf)
  471. return NULL;
  472.  
  473. if((h = elfSection(elf, NULL, ELF_SECTION_ATTRIBUTE_TYPE, SHT_DYNAMIC)))
  474. {
  475. if(size != NULL)
  476. *size = h->sh_entsize;
  477. if(length != NULL)
  478. *length = h->sh_size / h->sh_entsize;
  479.  
  480. return (ElfDynamic *)(elf->data + h->sh_offset);
  481. }
  482. else if((h2 = elfSegment(elf, NULL, ELF_SEGMENT_ATTRIBUTE_TYPE, PT_DYNAMIC)))
  483. {
  484. if(size != NULL)
  485. *size = sizeof(ElfDynamic);
  486. if(length != NULL) //h2->p_filesz / sizeof(ElfDynamic);
  487. *length = elfDynamicsLength((ElfDynamic *)(elf->data + h2->p_offset));
  488.  
  489. return (ElfDynamic *)(elf->data + h2->p_offset);
  490. }
  491.  
  492. return NULL;
  493. }
  494.  
  495. ElfDynamic *elfDynamic(Elf *elf, uint16_t *index, ElfDynamicAttribute attribute, uint64_t value)
  496. {
  497. uint16_t size;
  498. uint16_t length;
  499. ElfDynamic *h, *t;
  500. uint16_t i = 0;
  501.  
  502. if(!index)
  503. index = &i;
  504.  
  505. h = elfDynamics(elf, &size, &length);
  506.  
  507. if(!h)
  508. return NULL;
  509.  
  510. for(; *index < length; ++(*index))
  511. {
  512. t = (ElfDynamic *)((uint8_t *)h + *index * size);
  513. if(attribute == ELF_DYNAMIC_ATTRIBUTE_NONE || elfDynamicAttribute(t, attribute) == value)
  514. return t;
  515. }
  516.  
  517. return NULL;
  518. }
  519.  
  520. ElfDynamic *elfLoadedDynamics(Elf *elf, uint16_t *size, uint16_t *length)
  521. {
  522. //ElfSection *h;
  523. ElfSegment *h2;
  524.  
  525. if(!elf)
  526. return NULL;
  527.  
  528. if((h2 = elfSegment(elf, NULL, ELF_SEGMENT_ATTRIBUTE_TYPE, PT_DYNAMIC)))
  529. {
  530. if(size != NULL)
  531. *size = sizeof(ElfDynamic);
  532. if(length != NULL)
  533. *length = elfDynamicsLength((ElfDynamic *)h2->p_vaddr);
  534.  
  535. return (ElfDynamic *)h2->p_vaddr;
  536. }
  537.  
  538. return NULL;
  539. }
  540.  
  541. ElfDynamic *elfLoadedDynamic(Elf *elf, uint16_t *index, ElfDynamicAttribute attribute, uint64_t value)
  542. {
  543. uint16_t size;
  544. uint16_t length;
  545. ElfDynamic *h, *t;
  546. uint16_t i = 0;
  547.  
  548. if(!index)
  549. index = &i;
  550.  
  551. h = elfLoadedDynamics(elf, &size, &length);
  552.  
  553. if(!h)
  554. return NULL;
  555.  
  556. for(; *index < length; ++(*index))
  557. {
  558. t = (ElfDynamic *)((uint8_t *)h + *index * size);
  559. if(attribute == ELF_DYNAMIC_ATTRIBUTE_NONE || elfDynamicAttribute(t, attribute) == value)
  560. return t;
  561. }
  562.  
  563. return NULL;
  564. }
  565.  
  566. /* --- elf string tables --- */
  567.  
  568. char *elfStringFromIndex(char *mem, uint64_t size, uint32_t index)
  569. {
  570. uint64_t i, j = 0;
  571.  
  572. if(!mem)
  573. return NULL;
  574.  
  575. if(index == 0)
  576. return mem;
  577.  
  578. for(i = 0; i < size - 1; ++i)
  579. if(mem[i] == '\0' && ++j == index)
  580. return mem + i + 1;
  581.  
  582. return NULL;
  583. }
  584.  
  585. char *elfStringFromOffset(char *mem, uint64_t size, uint32_t offset)
  586. {
  587. if(!mem || offset >= size)
  588. return NULL;
  589.  
  590. return mem + offset;
  591. }
  592.  
  593. uint32_t elfStringToOffset(char *mem, uint64_t size, char *str)
  594. {
  595. uint64_t i, j;
  596.  
  597. if(!str)
  598. return 0;
  599.  
  600. for(i = 0; i < size; ++i)
  601. {
  602. for(j = 0; j < ELF_MAXIMAL_STRING_LENGTH && mem[i + j] == str[j]; ++j)
  603. if(str[j] == '\0')
  604. return i;
  605. }
  606.  
  607. return 0;
  608. }
  609.  
  610. uint32_t elfStringToIndex(char *mem, uint64_t size, char *str)
  611. {
  612. uint64_t index, i, j;
  613.  
  614. if(!str)
  615. return 0;
  616.  
  617. index = 0;
  618. for(i = 0; i < size; ++i)
  619. {
  620. for(j = 0; j < ELF_MAXIMAL_STRING_LENGTH && mem[i + j] == str[j]; ++j)
  621. if(str[j] == '\0')
  622. return index;
  623.  
  624. if(mem[i] == '\0')
  625. index++;
  626. }
  627.  
  628. return 0;
  629. }
  630.  
  631. /* --- elf relocations --- */
  632.  
  633. uint64_t elfAddendRelocationAttribute(ElfAddendRelocation *elfAddendRelocation, ElfAddendRelocationAttribute attribute)
  634. {
  635. switch(attribute)
  636. {
  637. case ELF_ADDEND_RELOCATION_ATTRIBUTE_INFO:
  638. return elfAddendRelocation->r_info;
  639. case ELF_ADDEND_RELOCATION_ATTRIBUTE_OFFSET:
  640. return elfAddendRelocation->r_offset;
  641. case ELF_ADDEND_RELOCATION_ATTRIBUTE_ADDEND:
  642. return elfAddendRelocation->r_addend;
  643. default:
  644. break;
  645. }
  646. return 0;
  647. }
  648.  
  649. ElfAddendRelocation *elfAddendRelocations(Elf *elf, char *name, uint16_t *size, uint16_t *length)
  650. {
  651. ElfSection *h;
  652.  
  653. h = elfSectionByName(elf, name);
  654.  
  655. if(!h || h->sh_type != SHT_RELA)
  656. return NULL;
  657.  
  658. if(size != NULL)
  659. *size = h->sh_entsize;
  660. if(length != NULL)
  661. *length = h->sh_size / h->sh_entsize;
  662.  
  663. return (ElfAddendRelocation *)(elf->data + h->sh_offset);
  664. }
  665.  
  666. // FIXME this is not performant, better to pass in the base ElfAddendRelocation *, size and length
  667. /*
  668. ElfAddendRelocation *elfAddendRelocation(Elf *elf, char *name, uint16_t *index, ElfAddendRelocationAttribute attribute, uint64_t value)
  669. {
  670. uint16_t size;
  671. uint16_t length;
  672. ElfAddendRelocation *h, *t;
  673. uint16_t i = 0;
  674.  
  675. if(!index)
  676. index = &i;
  677.  
  678. h = elfAddendRelocations(elf, name, &size, &length);
  679.  
  680. if(!h)
  681. return NULL;
  682.  
  683. for(; *index < length; ++(*index))
  684. {
  685. t = (ElfAddendRelocation *)((uint8_t *)h + *index * size);
  686. if(attribute == ElfAddendRelocationAttributeNone || elfAddendRelocationAttribute(t, attribute) == value)
  687. return t;
  688. }
  689.  
  690. return NULL;
  691. }
  692. */
  693.  
  694. /* --- elf symbols --- */
  695.  
  696. uint64_t elfSymbolAttribute(ElfSymbol *elfSymbol, ElfSymbolAttribute attribute)
  697. {
  698. switch(attribute)
  699. {
  700. case ELF_SYMBOL_ATTRIBUTE_NAME:
  701. return elfSymbol->st_name;
  702. case ELF_SYMBOL_ATTRIBUTE_INFO:
  703. return elfSymbol->st_info;
  704. case ELF_SYMBOL_ATTRIBUTE_UNUSED:
  705. return elfSymbol->st_other;
  706. case ELF_SYMBOL_ATTRIBUTE_SECTION_INDEX:
  707. return elfSymbol->st_shndx;
  708. case ELF_SYMBOL_ATTRIBUTE_VALUE:
  709. return elfSymbol->st_value;
  710. case ELF_SYMBOL_ATTRIBUTE_SIZE:
  711. return elfSymbol->st_size;
  712. default:
  713. break;
  714. }
  715. return 0;
  716. }
  717.  
  718. ElfSymbol *elfSymbols(Elf *elf, char *name, uint16_t *size, uint16_t *length)
  719. {
  720. ElfSection *h;
  721.  
  722. h = elfSectionByName(elf, name);
  723.  
  724. if(!h || (h->sh_type != SHT_SYMTAB && h->sh_type != SHT_DYNSYM))
  725. return NULL;
  726.  
  727. if(size != NULL)
  728. *size = h->sh_entsize;
  729. if(length != NULL)
  730. *length = h->sh_size / h->sh_entsize;
  731.  
  732. return (ElfSymbol *)(elf->data + h->sh_offset);
  733. }
  734.  
  735. /*
  736. ElfSymbol *elfSymbol(Elf *elf, char *name, uint16_t *index, ElfSymbolAttribute attribute, uint64_t value)
  737. {
  738. uint16_t size;
  739. uint16_t length;
  740. ElfSymbol *h, *t;
  741. uint16_t i = 0;
  742.  
  743. if(!index)
  744. index = &i;
  745.  
  746. h = elfSymbols(elf, name, &size, &length);
  747.  
  748. if(!h)
  749. return NULL;
  750.  
  751. for(; *index < length; ++(*index))
  752. {
  753. t = (ElfSymbol *)((uint8_t *)h + *index * size);
  754. if(attribute == ElfSymbolAttributeNone || elfSymbolAttribute(t, attribute) == value)
  755. return t;
  756. }
  757.  
  758. return NULL;
  759. }*/
  760.  
  761. /* actions */
  762.  
  763. Elf *elfCreate(void *data, size_t size)
  764. {
  765. Elf *elf, t;
  766.  
  767. if(data == NULL)
  768. return NULL;
  769.  
  770. t.data = data;
  771. t.size = size;
  772.  
  773. if(!elfIsElf(&t))
  774. return NULL;
  775.  
  776. elf = malloc(sizeof(Elf));
  777. if(elf==NULL)
  778. {
  779. debugNetPrintf(DEBUG,"[ORBISLINK] elfCreate error malloc return null\n");
  780. return NULL;
  781. }
  782. elf->data = (uint8_t *)data;
  783. elf->size = size;
  784.  
  785. return elf;
  786. }
  787.  
  788. Elf *elfCreateLocal(void *elfl, void *data, size_t size)
  789. {
  790. Elf *elf, t;
  791.  
  792. if(elfl == NULL || data == NULL)
  793. return NULL;
  794.  
  795. t.data = data;
  796. t.size = size;
  797.  
  798. if(!elfIsElf(&t))
  799. return NULL;
  800.  
  801. elf = (Elf *)elfl;
  802. elf->data = (uint8_t *)data;
  803. elf->size = size;
  804.  
  805. return elf;
  806. }
  807.  
  808. Elf *elfCreateLocalUnchecked(void *elfl, void *data, size_t size)
  809. {
  810. Elf *elf;
  811.  
  812. if(elfl == NULL || data == NULL)
  813. return NULL;
  814.  
  815. elf = (Elf *)elfl;
  816. elf->data = (uint8_t *)data;
  817. elf->size = size;
  818.  
  819. return elf;
  820. }
  821.  
  822. void *elfDestroy(Elf *elf)
  823. {
  824. void *data;
  825.  
  826. if(elf == NULL)
  827. return NULL;
  828.  
  829. if(elf->data!=NULL)
  830. {
  831. //debugNetPrintf(3,"data %x\n",elf->data);
  832.  
  833. //data = elf->data;
  834. munmap(elf->data,elf->size);
  835. //free(elf->data);
  836. }
  837.  
  838. return elf;
  839. }
  840.  
  841. void elfDestroyAndFree(Elf *elf)
  842. {
  843. void *d;
  844.  
  845. if(elf == NULL)
  846. return;
  847. //debugNetPrintf(3,"elf %x\n",elf);
  848. d = elfDestroy(elf);
  849. //debugNetPrintf(3,"d %x\n",d);
  850.  
  851. if(d)
  852. free(d);
  853. }
  854.  
  855. /* --- --- */
  856.  
  857. int elfLoaderIsLoadable(Elf *elf)
  858. {
  859. ElfHeader *h;
  860.  
  861. if(!elfIsElf(elf))
  862. return 0;
  863.  
  864. h = elfHeader(elf);
  865.  
  866. return elfClass(elf) == ELFCLASS64 &&
  867. elfEncoding(elf) == ELFDATA2LSB &&
  868. elfVersion(elf) == EV_CURRENT &&
  869. (elfABI(elf) == ELFOSABI_SYSV || elfABI(elf) == ELFOSABI_FREEBSD) &&
  870. h->e_type == ET_DYN &&
  871. h->e_phoff != 0 &&
  872. h->e_shoff != 0 &&
  873. h->e_machine == EM_X86_64 &&
  874. h->e_version == EV_CURRENT;
  875. }
  876.  
  877. int elfLoaderInstantiate(Elf *elf, void *memory)
  878. {
  879. ElfSection *sections;
  880. ElfSegment *segments;
  881.  
  882. uint16_t size;
  883. uint16_t length;
  884. uint16_t index;
  885.  
  886. if(elf == NULL)
  887. return ELF_LOADER_RETURN_ELF_NULL;
  888. if(memory == NULL)
  889. return ELF_LOADER_RETURN_NO_WRITABLE_MEMORY;
  890.  
  891. segments = elfSegments(elf, &size, &length);
  892. if(segments)
  893. {
  894. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate in segments length=%d\n",length);
  895.  
  896. for(index = 0; index < length; ++index)
  897. {
  898. ElfSegment *s = (ElfSegment *)((uint8_t *)segments + index * size);
  899. if(s->p_filesz)
  900. {
  901. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate before elfLoaderInstantiate memcpy %p %p %d\n",(char *)memory + s->p_paddr,elf->data + s->p_offset,s->p_filesz);
  902.  
  903. orbisMemoryCopy((char *)memory + s->p_paddr, elf->data + s->p_offset, s->p_filesz);
  904. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate after elfLoaderInstantiate memcpy\n");
  905.  
  906. }
  907. if(s->p_memsz - s->p_filesz)
  908. { //memset((char *)memory + s->p_paddr + s->p_filesz, 0, s->p_memsz - s->p_filesz);
  909. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate before elfLoaderInstantiate orbisMemorySet\n");
  910.  
  911. orbisMemorySet((char *)memory + s->p_paddr + s->p_filesz,0,s->p_memsz - s->p_filesz);
  912. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate after elfLoaderInstantiate orbisMemorySet\n");
  913.  
  914. }
  915. }
  916. }
  917. else
  918. {
  919. length = 0;
  920. sections = elfSections(elf, &size, &length);
  921. if(!sections)
  922. return 0;
  923. for(index = 0; index < length; ++index)
  924. {
  925. ElfSection *s = (ElfSection *)((uint8_t *)sections + index * size);
  926. if(!(s->sh_flags & SHF_ALLOC))
  927. continue;
  928. if(s->sh_size)
  929. {
  930. orbisMemoryCopy((char *)memory + s->sh_addr, elf->data + s->sh_offset, s->sh_size);
  931. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderInstantiate after elfLoaderInstantiate second memcpy\n");
  932.  
  933. }
  934. }
  935. }
  936.  
  937. return ELF_LOADER_RETURN_OK;
  938. }
  939.  
  940. int elfLoaderRelativeAddressIsExecutable(Elf *elf, int64_t address)
  941. {
  942. ElfSection *sections;
  943. ElfSegment *segments;
  944.  
  945. uint16_t size;
  946. uint16_t length;
  947. uint16_t index;
  948.  
  949. if(elf == NULL)
  950. return 0;
  951.  
  952. segments = elfSegments(elf, &size, &length);
  953. if(segments)
  954. {
  955. for(index = 0; index < length; ++index)
  956. {
  957. ElfSegment *s = (ElfSegment *)((uint8_t *)segments + index * size);
  958. if(address >= s->p_paddr && address <= s->p_paddr + s->p_memsz)
  959. return s->p_flags & PF_X;
  960. }
  961. }
  962. else
  963. {
  964. length = 0;
  965. sections = elfSections(elf, &size, &length);
  966. if(!sections)
  967. return ELF_LOADER_RETURN_NO_SECTIONS_OR_SEGMENTS;
  968. for(index = 0; index < length; ++index)
  969. {
  970. ElfSection *s = (ElfSection *)((uint8_t *)sections + index * size);
  971. if(address >= s->sh_addr && address <= s->sh_addr + s->sh_size)
  972. return s->sh_flags & SHF_EXECINSTR;
  973. }
  974. }
  975.  
  976. return 1; // FIXME: Recheck
  977. }
  978.  
  979. // FIXME: Implement ps4 aware relocation for functions using dlsym
  980. int elfLoaderRelocate(Elf *elf, void *writable, void *executable)
  981. {
  982. int i, j;
  983.  
  984. uint16_t relocationSize = 0;
  985. uint16_t relocationsLength = 0;
  986. ElfAddendRelocation *relocations;
  987.  
  988. uint16_t dynamicSymbolSize = 0;
  989. uint16_t dynamicSymbolsLength = 0;
  990. ElfSymbol *dynamicSymbols;
  991.  
  992. char *r1 = ".rela.dyn";
  993. char *r2 = ".rela.plt";
  994. char *rel[2] = {r1, r2};
  995.  
  996. if(elf == NULL)
  997. return ELF_LOADER_RETURN_ELF_NULL;
  998. if(writable == NULL)
  999. return ELF_LOADER_RETURN_NO_WRITABLE_MEMORY;
  1000. if(executable == NULL)
  1001. return ELF_LOADER_RETURN_NO_EXECUTABLE_MEMORY;
  1002.  
  1003. dynamicSymbols = elfSymbols(elf, ".dynsym", &dynamicSymbolSize, &dynamicSymbolsLength);
  1004. //symbols = elfSymbols(elf, ".symtab", &symbolSize, &symbolsLength);
  1005.  
  1006. for(j = 0; j < sizeof(rel) / sizeof(rel[0]); ++j)
  1007. {
  1008. relocationsLength = 0;
  1009. relocations = elfAddendRelocations(elf, rel[j], &relocationSize, &relocationsLength);
  1010.  
  1011. for(i = 0; i < relocationsLength; ++i)
  1012. {
  1013. ElfSymbol *symbol;
  1014. ElfAddendRelocation *relocation = (ElfAddendRelocation *)(((uint8_t *)relocations) + relocationSize * i);
  1015. uint16_t relocationType = (uint16_t)elfRelocationType(relocation->r_info);
  1016. uint16_t relocationSymbol = (uint16_t)elfRelocationSymbol(relocation->r_info);
  1017. uint8_t **offset = (uint8_t **)((uint8_t *)writable + relocation->r_offset);
  1018. int64_t value = 0;
  1019.  
  1020. switch(relocationType)
  1021. {
  1022. case R_X86_64_RELATIVE:
  1023. value = relocation->r_addend;
  1024. break;
  1025. case R_X86_64_64:
  1026. symbol = (ElfSymbol *)(((uint8_t *)dynamicSymbols) + dynamicSymbolSize * relocationSymbol);
  1027. value = symbol->st_value + relocation->r_addend;
  1028. break;
  1029. case R_X86_64_JMP_SLOT:
  1030. case R_X86_64_GLOB_DAT:
  1031. symbol = (ElfSymbol *)(((uint8_t *)dynamicSymbols) + dynamicSymbolSize * relocationSymbol);
  1032. value = symbol->st_value;
  1033. break;
  1034. default:
  1035. return ELF_LOADER_RETURN_UNKNOWN_RELOCATION;
  1036. }
  1037.  
  1038. if(elfLoaderRelativeAddressIsExecutable(elf, value))
  1039. *offset = (uint8_t *)executable + value;
  1040. else
  1041. *offset = (uint8_t *)writable + value;
  1042. }
  1043. }
  1044.  
  1045. return ELF_LOADER_RETURN_OK;
  1046. }
  1047.  
  1048. int elfLoaderLoad(Elf *elf, void *writable, void *executable)
  1049. {
  1050. int r = ELF_LOADER_RETURN_OK;
  1051.  
  1052. if(elf == NULL)
  1053. return ELF_LOADER_RETURN_ELF_NULL;
  1054. if(writable == NULL)
  1055. return ELF_LOADER_RETURN_NO_WRITABLE_MEMORY;
  1056. if(executable == NULL)
  1057. return ELF_LOADER_RETURN_NO_EXECUTABLE_MEMORY;
  1058.  
  1059. if(!elfLoaderIsLoadable(elf))
  1060. return ELF_LOADER_RETURN_IS_NOT_LOADABLE;
  1061.  
  1062. if((r = elfLoaderInstantiate(elf, writable)) != ELF_LOADER_RETURN_OK)
  1063. {
  1064. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderLoad after elfLoaderInstantiate error return=%d\n",r);
  1065.  
  1066. return r;
  1067. }
  1068. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderLoad after elfLoaderInstantiate return=%d\n",r);
  1069. r = elfLoaderRelocate(elf, writable, executable);
  1070. debugNetPrintf(DEBUG,"[ORBISLINK] elfLoaderLoad after elfLoaderRelocate return=%d\n",r);
  1071.  
  1072.  
  1073. return r;
  1074. }
  1075.  
  1076. extern ps4LinkConfiguration *configuration;
  1077. typedef int (*ElfMain)(int argc, char **argv);
  1078. typedef void (*ElfProcessMain)(void *arg);
  1079.  
  1080. typedef void (*ElfProcessExit)(int ret);
  1081. typedef void (*ElfProcessFree)(void *m, void *t);
  1082.  
  1083.  
  1084. typedef struct ElfRunUserArgument
  1085. {
  1086. ElfMain main;
  1087. Ps4MemoryProtected *memory;
  1088. }
  1089. ElfRunUserArgument;
  1090.  
  1091. void *orbisUserMain(void *arg)
  1092. {
  1093. ElfRunUserArgument *argument = (ElfRunUserArgument *)arg;
  1094. globalConf.confLink=configuration;
  1095. //ps4LinkConfiguration *shared_conf=configuration;
  1096. char pointer_conf[256];
  1097. sprintf(pointer_conf,"%p",&globalConf);
  1098. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserMain Configuration pointer %p, pointer_conf string %s\n",&globalConf,pointer_conf);
  1099. char *elfName = "elf";
  1100. char *elfArgv[3] = { elfName, pointer_conf, NULL };
  1101. int elfArgc = 2;
  1102.  
  1103. int r;
  1104.  
  1105. if(argument == NULL)
  1106. return NULL;
  1107.  
  1108. r = argument->main(elfArgc, elfArgv);
  1109. ps4MemoryProtectedDestroy(argument->memory);
  1110. //ps4MemoryDestroy(argument->memory);
  1111. free(argument);
  1112. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserMain return (user): %i\n", r);
  1113.  
  1114. return NULL;
  1115. }
  1116.  
  1117. int orbisUserRun(Elf *elf)
  1118. {
  1119. //pthread_t thread;
  1120. ScePthread thread;
  1121. int ret;
  1122. ElfRunUserArgument *argument;
  1123. void *writable, *executable;
  1124. int r;
  1125.  
  1126. if(elf == NULL)
  1127. return -1;
  1128. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun malloc for argument\n");
  1129.  
  1130. argument = (ElfRunUserArgument *)malloc(sizeof(ElfRunUserArgument));
  1131. if(argument == NULL)
  1132. {
  1133. elfDestroyAndFree(elf);
  1134. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun argument is NULL\n");
  1135. return -1;
  1136. }
  1137. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after malloc for argument\n");
  1138.  
  1139. if(ps4MemoryProtectedCreate(&argument->memory, elfMemorySize(elf)) != 0)
  1140. //if(ps4MemoryCreate(&argument->memory, elfMemorySize(elf)) != PS4_OK)
  1141. {
  1142. free(argument);
  1143. elfDestroyAndFree(elf);
  1144. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after elfDestroyAndFree\n");
  1145.  
  1146. return -1;
  1147. }
  1148. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after ps4MemoryProtectedCreate\n");
  1149.  
  1150. argument->main = NULL;
  1151. ps4MemoryProtectedGetWritableAddress(argument->memory, &writable);
  1152. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after ps4MemoryProtectedGetWritableAddress writable=%p\n",writable);
  1153.  
  1154. ps4MemoryProtectedGetExecutableAddress(argument->memory, &executable);
  1155. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after ps4MemoryProtectedGetExecutableAddress executable=%p\n",executable);
  1156.  
  1157. r = elfLoaderLoad(elf, writable, executable);
  1158. //r = elfLoaderLoad(elf, ps4MemoryGetAddress(argument->memory), ps4MemoryGetAddress(argument->memory));
  1159. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after elfLoaderLoad return r=%d readable=%p executable=%p\n",r,writable,executable);
  1160.  
  1161. if(r == ELF_LOADER_RETURN_OK)
  1162. {
  1163. argument->main = (ElfMain)((uint8_t *)executable + elfEntry(elf));
  1164. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after set argument->main %p \n",argument->main);
  1165.  
  1166. }
  1167. //elfDestroyAndFree(elf); // we don't need the "file" anymore but if i leave this line i got a memory crash
  1168. debugNetPrintf(DEBUG,"[ORBISLINK] orbisUserRun after elfDestroyAndFree \n");
  1169.  
  1170. if(argument->main != NULL)
  1171. { //pthread_create(&thread, NULL, elfLoaderUserMain, argument);
  1172. ret=scePthreadCreate(&thread, NULL, orbisUserMain, argument, "elf_user_thid");
  1173. if(ret==0)
  1174. {
  1175. debugNetPrintf(DEBUG,"[ORBISLINK] New user elf thread UID: 0x%08X\n", thread);
  1176. }
  1177. else
  1178. {
  1179. debugNetPrintf(DEBUG,"[ORBISLINK] New user elf thread could not create error: 0x%08X\n", ret);
  1180. scePthreadCancel(thread);
  1181. //ps4LinkFinish();
  1182. return PS4_NOT_OK;
  1183. }
  1184. }
  1185. else
  1186. {
  1187. ps4MemoryProtectedDestroy(argument->memory);
  1188. free(argument);
  1189. debugNetPrintf(DEBUG,"[ORBISLINK]orbisUserRun argument->main is released\n");
  1190. return -1;
  1191. }
  1192. return PS4_OK;
  1193. }
  1194.  
  1195. Elf * orbisReadElfFromHost(char *path)
  1196. {
  1197. int fd; //descriptor to manage file from host0
  1198. int filesize;//variable to control file size
  1199. uint8_t *buf=NULL;//buffer for read from host0 file
  1200. Elf *elf;//elf to create from buf
  1201.  
  1202. //we open file in read only from host0 ps4sh include the full path with host0:/.......
  1203. fd=ps4LinkOpen(path,O_RDONLY,0);
  1204.  
  1205. //If we can't open file from host0 print the error and return
  1206. if(fd<0)
  1207. {
  1208. debugNetPrintf(DEBUG,"[ORBISLINK] ps4LinkOpen returned error opening file %d\n",fd);
  1209. return NULL;
  1210. }
  1211. //Seek to final to get file size
  1212. filesize=ps4LinkLseek(fd,0,SEEK_END);
  1213. //If we get an error print it and return
  1214. if(filesize<0)
  1215. {
  1216. debugNetPrintf(DEBUG,"[ORBISLINK] ps4LinkSeek returned error %d\n",fd);
  1217. ps4LinkClose(fd);
  1218. return NULL;
  1219. }
  1220. //Seek back to start
  1221. ps4LinkLseek(fd,0,SEEK_SET);
  1222. //Reserve memory for read buffer
  1223. //buf=malloc(filesize);
  1224. //char buf[filesize];
  1225. debugNetPrintf(DEBUG,"[ORBISLINK] before orbisSysMmap\n");
  1226.  
  1227. buf=mmap(NULL,filesize,0x01|0x02,0x1000|0x0002,-1,0);
  1228.  
  1229. if(buf==MAP_FAILED)
  1230. {
  1231. debugNetPrintf(DEBUG,"[ORBISLINK] mmap returned error tryng one more time\n");
  1232.  
  1233. buf=mmap(NULL,filesize,0x01|0x02,0x1000|0x0002,-1,0);
  1234. if(buf==MAP_FAILED)
  1235. {
  1236. debugNetPrintf(DEBUG,"[ORBISLINK] mmap returned error again\n");
  1237. ps4LinkClose(fd);
  1238. return NULL;
  1239. }
  1240. }
  1241. //Read filsesize bytes to buf
  1242. int numread=ps4LinkRead(fd,buf,filesize);
  1243. //if we don't get filesize bytes we are in trouble
  1244. if(numread!=filesize)
  1245. {
  1246. sleep(1);
  1247. debugNetPrintf(DEBUG,"[ORBISLINK] ps4LinkRead returned error %d\n",numread);
  1248. sleep(1);
  1249. ps4LinkClose(fd);
  1250. return NULL;
  1251. }
  1252. //Close file
  1253. ps4LinkClose(fd);
  1254. //create elf from elfloader code from hitodama :P
  1255. elf = elfCreate((void*)buf, filesize);
  1256. //check is it is loadable
  1257. if(!elfLoaderIsLoadable(elf))
  1258. {
  1259. debugNetPrintf(DEBUG,"[ORBISLINK] elf %s is not loadable\n",path);
  1260. //free(buf);
  1261. elfDestroy(elf);
  1262. elf = NULL;
  1263. }
  1264. return elf;
  1265. }
  1266. void orbisExecUserElf()
  1267. {
  1268.  
  1269. Elf *elf=NULL;
  1270. debugNetPrintf(DEBUG,"[ORBISLINK] orbisExecUserElf called\n");
  1271. elf=orbisReadElfFromHost("host0:homebrew.elf");
  1272. if(elf==NULL)
  1273. {
  1274. debugNetPrintf(DEBUG,"[ORBISLINK] orbisExecUserElf we can't create elf\n");
  1275. return;
  1276. }
  1277. debugNetPrintf(DEBUG,"[ORBISLINK] orbisExecUserElf ready to run elf\n");
  1278. orbisUserRun(elf);
  1279. return;
  1280. }
  1281.  
  1282.  
  1283. void finishOrbisLinkApp()
  1284. {
  1285. orbisAudioFinish();
  1286. orbisPadFinish();
  1287. orbis2dFinish();
  1288. ps4LinkFinish();
  1289. }
  1290. void initOrbisLinkApp()
  1291. {
  1292. int ret;
  1293. int jailbreak_out=-1;
  1294. //jailbreak_out=orbisSysJailBreak();
  1295.  
  1296. globalConf.orbisLinkFlag=0;
  1297. ret=ps4LinkInit("192.168.1.3",0x4711,0x4712,0x4712,3);
  1298. if(!ret)
  1299. {
  1300. ps4LinkFinish();
  1301. return;
  1302. }
  1303. while(!ps4LinkRequestsIsConnected())
  1304. {
  1305.  
  1306. }
  1307. //debugNetPrintf(DEBUG,"[ORBISLINK] orbisSysJailBreak returned %d\n",jailbreak_out);
  1308.  
  1309. debugNetPrintf(DEBUG,"[ORBISLINK] Initialized and connected from pc/mac ready to receive commands\n");
  1310.  
  1311. ret=orbisPadInit();
  1312.  
  1313. if(ret==1)
  1314. {
  1315.  
  1316. globalConf.confPad=orbisPadGetConf();
  1317.  
  1318. ret=orbis2dInit();
  1319. debugNetPrintf(DEBUG,"[ORBISLINK] orbis2dInit return %x \n",ret);
  1320.  
  1321. if(ret==1)
  1322. {
  1323. globalConf.conf=orbis2dGetConf();
  1324. ret=orbisAudioInit();
  1325. if(ret==1)
  1326. {
  1327. ret=orbisAudioInitChannel(ORBISAUDIO_CHANNEL_MAIN,1024,48000,ORBISAUDIO_FORMAT_S16_STEREO);
  1328. sleep(1);
  1329. debugNetPrintf(DEBUG,"[ORBISLINK] orbisAudioInitChannel return %x \n",ret);
  1330. sleep(1);
  1331. globalConf.confAudio=orbisAudioGetConf();
  1332.  
  1333. }
  1334. }
  1335. }
  1336.  
  1337.  
  1338.  
  1339. //hide orbislink splash
  1340. //sceSystemServiceHideSplashScreen();
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346. }
  1347. int main()
  1348. {
  1349.  
  1350. initOrbisLinkApp();
  1351.  
  1352.  
  1353. debugNetPrintf(DEBUG,"[ORBISLINK]Loading homebrew.elf from host\n");
  1354. orbisExecUserElf();
  1355.  
  1356. while(!globalConf.orbisLinkFlag)
  1357. {
  1358.  
  1359. }
  1360.  
  1361. finishOrbisLinkApp();
  1362.  
  1363. exit(0);
  1364.  
  1365. return 0;
  1366. }
Add Comment
Please, Sign In to add comment