Port: uhex (RO)
This commit is contained in:
@@ -147,3 +147,7 @@ Controls:
|
||||
#### `exec <binary>`
|
||||
|
||||
Executes a binary file. Warning: this is highly broken and syscalls aren't working. It's written in a childish manner. Help is always appreciated (lol).
|
||||
|
||||
#### `uhex <file>`
|
||||
|
||||
Prints the hex and ASCII contents of a file.
|
||||
|
||||
@@ -147,6 +147,7 @@ void shell_install()
|
||||
register_command("naval", program_navalbattle);
|
||||
register_command("snake", program_snake);
|
||||
register_command("exec", program_exec);
|
||||
register_command("uhex", program_uhex);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ void program_uptime()
|
||||
|
||||
void program_help()
|
||||
{
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake exec\n");
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake exec\t uhex\n");
|
||||
}
|
||||
|
||||
// Panic
|
||||
|
||||
@@ -7,12 +7,19 @@
|
||||
// and now by being here it is even worse because it is RO and will have
|
||||
// hardcoded stuff in it (no ioctl, STDOUT, or other stuff here...)
|
||||
|
||||
/*
|
||||
|
||||
#define BYTES 1024
|
||||
#define round(x) (int)(x < 0 ? (x -0.5) : x + 0.5)
|
||||
|
||||
// WIP: pushed but not done yet
|
||||
#include "../libc/stdio.h"
|
||||
#include "../kernel/kmain.h"
|
||||
#include "../kernel/initrd.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../kernel/kheap.h"
|
||||
|
||||
int isprint(int c)
|
||||
{
|
||||
return (c >= 32 && c <= 126);
|
||||
}
|
||||
|
||||
void print_hex(unsigned char* buf, int byteno, int pos, int BYTES_PER_LINE)
|
||||
{
|
||||
@@ -34,7 +41,7 @@ void print_hex(unsigned char* buf, int byteno, int pos, int BYTES_PER_LINE)
|
||||
if (pos == 0) printf("%06d: ", i);
|
||||
else printf("%06d: ", pos);
|
||||
}
|
||||
printf("%2x", buf[i]);
|
||||
printf("%2x ", buf[i]);
|
||||
}
|
||||
|
||||
int padding = BYTES_PER_LINE - (byteno % BYTES_PER_LINE);
|
||||
@@ -59,14 +66,17 @@ void program_uhex(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Usage: uhex <file>\nInline commands:\n\tpX - print position X\n\teX - edit position X\n\tq - quit\n");
|
||||
puts("Usage: uhex <file>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int BYTES_PER_LINE = 20;
|
||||
|
||||
//unsigned char buf[BYTES]; // malloc with file_size next?
|
||||
uint32_t file_size = tar_get_file_size((uint8_t*)initrd_addr, argv[1]);
|
||||
unsigned char* buf = (unsigned char*)malloc(file_size);
|
||||
tar_file_to_buffer((uint8_t*)initrd_addr, argv[1], (char*)buf);
|
||||
print_hex(buf, file_size, 0, BYTES_PER_LINE);
|
||||
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -48,4 +48,6 @@ void program_snake();
|
||||
// Binaries loading and execution
|
||||
void program_exec();
|
||||
|
||||
void program_uhex();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user