Changeset 446 for EcnlProtoTool/trunk/ntshell/src/main.c
- Timestamp:
- Jul 21, 2020, 8:38:44 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/main.c
r443 r446 125 125 static const Elf32_Ehdr *load_elf(const uint8_t *file); 126 126 static void execute_elf(const Elf32_Ehdr *, long *args); 127 static void read_cmdlist_from_elf(const Elf32_Ehdr *Ehdr); 127 128 static int usrcmd_ntopt_callback(long *args, void *extobj); 128 129 #ifndef NTSHELL_NO_SOCKET … … 527 528 {"info", "This is a description text string for info command.", usrcmd_info}, 528 529 {"exit", "Exit Natural Tiny Shell", usrcmd_exit}, 530 {"help", "This is a description text string for help command.", usrcmd_help}, 529 531 }; 530 cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) }; 532 const cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) }; 533 cmd_table_info_t elf_cmd_table_info; 531 534 532 535 static int usrcmd_ntopt_callback(long *args, void *extobj) … … 540 543 541 544 if (strcmp((const char *)args[1], "help") == 0) { 545 found = 1; 542 546 result = usrcmd_help(args[0], (char **)&args[1]); 543 547 } … … 567 571 int usrcmd_help(int argc, char **argv) 568 572 { 569 const cmd_table_t *p = cmd_table_info.table; 570 for (int i = 0; i < cmd_table_info.count; i++) { 571 printf(p->cmd); 572 printf("\t:"); 573 puts(p->desc); 574 p++; 573 const cmd_table_t *p, *q; 574 const Elf32_Ehdr *elf = load_elf((const uint8_t *)0x18200000); 575 if (elf != NULL) { 576 read_cmdlist_from_elf(elf); 577 } 578 else { 579 elf_cmd_table_info.count = 0; 580 } 581 p = cmd_table_info.table; 582 for (int i = 0; i < cmd_table_info.count - 3; i++, p++) { 583 printf("%s\t:%s\n", p->cmd, p->desc); 584 } 585 p = elf_cmd_table_info.table; 586 for (int i = 0; i < elf_cmd_table_info.count; i++, p++) { 587 printf("%s\t:%s\n", p->cmd, p->desc); 588 } 589 p = &cmd_table_info.table[cmd_table_info.count - 3]; 590 for (int i = cmd_table_info.count - 3; i < cmd_table_info.count; i++, p++) { 591 printf("%s\t:%s\n", p->cmd, p->desc); 575 592 } 576 593 return 0; … … 700 717 Shdr.sh_size -= Shdr.sh_addr; 701 718 702 char *name;703 if (Shdr.sh_name > 0) {704 name = (char *)&file[StringShdr.sh_offset + Shdr.sh_name];705 }706 else {707 name = NULL;708 }709 710 719 if ((Shdr.sh_flags & SHF_ALLOC) == 0) { 711 720 // skip … … 730 739 ((elf_entry_t)Ehdr->e_entry)(args); 731 740 } 741 742 void read_cmdlist_from_elf(const Elf32_Ehdr *Ehdr) 743 { 744 const uint8_t *file = (const uint8_t *)Ehdr; 745 Elf32_Shdr StringShdr; 746 memcpy(&StringShdr, &file[Ehdr->e_shoff + (Ehdr->e_shstrndx * Ehdr->e_shentsize)], sizeof(StringShdr)); 747 748 if (Ehdr->e_shoff > 0) { 749 Elf32_Shdr Shdr; 750 for (int i = 0; i < Ehdr->e_shnum; i++) { 751 memcpy(&Shdr, (Elf32_Shdr *)&file[Ehdr->e_shoff + (i * Ehdr->e_shentsize)], sizeof(Elf32_Shdr)); 752 Shdr.sh_size -= Shdr.sh_addr; 753 754 char *name; 755 if (Shdr.sh_name > 0) { 756 name = (char *)&file[StringShdr.sh_offset + Shdr.sh_name]; 757 } 758 else { 759 name = NULL; 760 } 761 762 if ((name != NULL) && (strcmp(name, ".cmdlist") == 0)) { 763 elf_cmd_table_info.table = (const cmd_table_t *)Shdr.sh_addr; 764 elf_cmd_table_info.count = Shdr.sh_size / sizeof(cmd_table_t); 765 } 766 } 767 } 768 }
Note:
See TracChangeset
for help on using the changeset viewer.