add: elements of strings are now 1 byte, new print api
This commit is contained in:
@@ -20,17 +20,6 @@ add a1, 8
|
||||
jmp loop2
|
||||
|
||||
main:
|
||||
mov a1, msg ; msg is a char *
|
||||
loop:
|
||||
cmp *a1, 0
|
||||
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
|
||||
push msg
|
||||
call print
|
||||
jmp show_arr
|
||||
13
src/api.c
13
src/api.c
@@ -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() {
|
||||
long long address = state->STACK[state->STACK_IDX--];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "instructions.h"
|
||||
|
||||
void api_put();
|
||||
void api_print();
|
||||
void api_callrawaddr();
|
||||
|
||||
// generated APIs here
|
||||
@@ -13,6 +14,7 @@ void api_GetAsyncKeyState();
|
||||
|
||||
static const command_t api_map[] = {
|
||||
{.command = "put", .fptr = api_put},
|
||||
{.command = "print", .fptr = api_print},
|
||||
{.command = "CallRawAddress", .fptr = api_callrawaddr},
|
||||
|
||||
// generated APIs here
|
||||
|
||||
@@ -154,6 +154,7 @@ ARRAY_ERR add_array(char* line) {
|
||||
char* start_of_values = ptr;
|
||||
int array_size = 0;
|
||||
long long *arr = NULL;
|
||||
char* arr_char = NULL;
|
||||
if (ptr[0] == '"') {
|
||||
++ptr;
|
||||
while (*ptr++ != '"') {
|
||||
@@ -163,13 +164,13 @@ ARRAY_ERR add_array(char* line) {
|
||||
}
|
||||
++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) {
|
||||
dprintf(fstream, "Error allocating memory.\n");
|
||||
return ARRAY_ERROR;
|
||||
}
|
||||
arr = tmp;
|
||||
memset__(arr, 0, array_size);
|
||||
arr_char = tmp;
|
||||
memset__(arr_char, 0, array_size);
|
||||
long long **temp = realloc_(state->ARRAYS_VALUES, (state->num_arrays + 1) * sizeof(long long*));
|
||||
if (temp == NULL) {
|
||||
dprintf(fstream, "Error allocating memory.\n");
|
||||
@@ -185,12 +186,12 @@ ARRAY_ERR add_array(char* line) {
|
||||
return ARRAY_ERROR; //" is never closed
|
||||
}
|
||||
if (strncmp__(ptr, "\\0", 2) == 0) {
|
||||
arr[i++] = 0;
|
||||
arr_char[i++] = 0;
|
||||
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;
|
||||
}
|
||||
ptr = strtok_(ptr, ",");
|
||||
|
||||
Reference in New Issue
Block a user