add: malloc and free APIs

malloc doesn't work on Windows, TOFIX
This commit is contained in:
2025-01-16 13:38:04 +01:00
parent a60307609f
commit 2adaa9773a
2 changed files with 19 additions and 0 deletions

View File

@@ -53,6 +53,21 @@ void api_print() {
dprintf(f, "%s", address);
}
void api_free() {
void *addr = (void *)state->STACK[state->STACK_IDX--];
free_(addr);
}
void api_malloc() {
long size = state->STACK[state->STACK_IDX--];
#ifdef _WIN32
state->registers->eax = 0;
return;
#else
state->registers->eax = (long long)malloc(size);
#endif
}
void api_callrawaddr() {
long long address = state->STACK[state->STACK_IDX--];

View File

@@ -3,6 +3,8 @@
void api_put();
void api_print();
void api_free();
void api_malloc();
void api_callrawaddr();
// generated APIs here
@@ -15,6 +17,8 @@ void api_GetAsyncKeyState();
static const command_t api_map[] = {
{.command = "put", .fptr = api_put},
{.command = "print", .fptr = api_print},
{.command = "malloc", .fptr = api_malloc},
{.command = "free", .fptr = api_free},
{.command = "CallRawAddress", .fptr = api_callrawaddr},
// generated APIs here