add: malloc and free APIs
malloc doesn't work on Windows, TOFIX
This commit is contained in:
15
src/api.c
15
src/api.c
@@ -53,6 +53,21 @@ void api_print() {
|
|||||||
dprintf(f, "%s", address);
|
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() {
|
void api_callrawaddr() {
|
||||||
long long address = state->STACK[state->STACK_IDX--];
|
long long address = state->STACK[state->STACK_IDX--];
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
void api_put();
|
void api_put();
|
||||||
void api_print();
|
void api_print();
|
||||||
|
void api_free();
|
||||||
|
void api_malloc();
|
||||||
void api_callrawaddr();
|
void api_callrawaddr();
|
||||||
|
|
||||||
// generated APIs here
|
// generated APIs here
|
||||||
@@ -15,6 +17,8 @@ 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 = "print", .fptr = api_print},
|
||||||
|
{.command = "malloc", .fptr = api_malloc},
|
||||||
|
{.command = "free", .fptr = api_free},
|
||||||
{.command = "CallRawAddress", .fptr = api_callrawaddr},
|
{.command = "CallRawAddress", .fptr = api_callrawaddr},
|
||||||
|
|
||||||
// generated APIs here
|
// generated APIs here
|
||||||
|
|||||||
Reference in New Issue
Block a user