add: elements of strings are now 1 byte, new print api

This commit is contained in:
2024-08-24 19:38:45 +02:00
parent 5e230e1e02
commit 37c4a37287
4 changed files with 25 additions and 20 deletions

View File

@@ -20,17 +20,6 @@ add a1, 8
jmp loop2 jmp loop2
main: main:
mov a1, msg ; msg is a char * push msg
loop: call print
cmp *a1, 0 jmp show_arr
jne 1
jmp show_arr
push *a1
push 1
call put
add a1, 8 ; little ptr theory here, as the stack is of type long long
; to go to the next value you have to add sizeof(long long) to the ptr
; so you need to add 8
jmp loop

View File

@@ -40,6 +40,19 @@ void api_put() {
} }
} }
void api_print() {
char *address = (char *)state->STACK[state->STACK_IDX--];
int f = fstream;
#ifdef _WIN32
if (f == 2) //stderr (could use _fileno(stderr) but it uses the stdlib)
f = 1; //stdout
#else
if (f == fileno(stderr))
f = fileno(stdout);
#endif
dprintf(f, "%s", address);
}
void api_callrawaddr() { void api_callrawaddr() {
long long address = state->STACK[state->STACK_IDX--]; long long address = state->STACK[state->STACK_IDX--];

View File

@@ -2,6 +2,7 @@
#include "instructions.h" #include "instructions.h"
void api_put(); void api_put();
void api_print();
void api_callrawaddr(); void api_callrawaddr();
// generated APIs here // generated APIs here
@@ -13,6 +14,7 @@ void api_GetAsyncKeyState();
static const command_t api_map[] = { static const command_t api_map[] = {
{.command = "put", .fptr = api_put}, {.command = "put", .fptr = api_put},
{.command = "print", .fptr = api_print},
{.command = "CallRawAddress", .fptr = api_callrawaddr}, {.command = "CallRawAddress", .fptr = api_callrawaddr},
// generated APIs here // generated APIs here

View File

@@ -154,6 +154,7 @@ ARRAY_ERR add_array(char* line) {
char* start_of_values = ptr; char* start_of_values = ptr;
int array_size = 0; int array_size = 0;
long long *arr = NULL; long long *arr = NULL;
char* arr_char = NULL;
if (ptr[0] == '"') { if (ptr[0] == '"') {
++ptr; ++ptr;
while (*ptr++ != '"') { while (*ptr++ != '"') {
@@ -163,13 +164,13 @@ ARRAY_ERR add_array(char* line) {
} }
++array_size; ++array_size;
} }
long long *tmp = realloc_(arr, array_size * sizeof(long long)); char *tmp = realloc_(arr_char, array_size * sizeof(char));
if (tmp == NULL || array_size == 0) { if (tmp == NULL || array_size == 0) {
dprintf(fstream, "Error allocating memory.\n"); dprintf(fstream, "Error allocating memory.\n");
return ARRAY_ERROR; return ARRAY_ERROR;
} }
arr = tmp; arr_char = tmp;
memset__(arr, 0, array_size); memset__(arr_char, 0, array_size);
long long **temp = realloc_(state->ARRAYS_VALUES, (state->num_arrays + 1) * sizeof(long long*)); long long **temp = realloc_(state->ARRAYS_VALUES, (state->num_arrays + 1) * sizeof(long long*));
if (temp == NULL) { if (temp == NULL) {
dprintf(fstream, "Error allocating memory.\n"); dprintf(fstream, "Error allocating memory.\n");
@@ -185,12 +186,12 @@ ARRAY_ERR add_array(char* line) {
return ARRAY_ERROR; //" is never closed return ARRAY_ERROR; //" is never closed
} }
if (strncmp__(ptr, "\\0", 2) == 0) { if (strncmp__(ptr, "\\0", 2) == 0) {
arr[i++] = 0; arr_char[i++] = 0;
break; break;
} }
arr[i++] = (long long)* ptr++; arr_char[i++] = (long long)* ptr++;
} }
state->ARRAYS_VALUES[state->num_arrays++] = arr; state->ARRAYS_VALUES[state->num_arrays++] = arr_char;
return ARRAY_OK; return ARRAY_OK;
} }
ptr = strtok_(ptr, ","); ptr = strtok_(ptr, ",");