parent
ffc0b9cf74
commit
ce262c485b
8 changed files with 0 additions and 299 deletions
|
|
@ -179,10 +179,6 @@ Files: test/unit/rz_test_cmd_test
|
|||
Copyright: 2021 RizinOrg <info@rizin.re>
|
||||
License: LGPL-3.0-only
|
||||
|
||||
Files: binrz/preload/trap-*
|
||||
Copyright: 2021 RadareOrg <pancake@nopcode.org>
|
||||
License: LGPL-3.0-only
|
||||
|
||||
Files: librz/asm/arch/avr/README
|
||||
Copyright: RadareOrg <pancake@nopcode.org>
|
||||
License: LGPL-3.0-only
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2011 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
#define RZ_API
|
||||
#define RZ_ALLOC_USE_MMAP 1
|
||||
#define USE_MALLOC 0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
|
||||
#if USE_MALLOC
|
||||
RZ_API void rz_initmem(char *p, size_t s) {
|
||||
}
|
||||
|
||||
RZ_API void *rz_malloc(size_t s) {
|
||||
return malloc(s);
|
||||
}
|
||||
|
||||
RZ_API void rz_free(void *p) {
|
||||
free(s);
|
||||
}
|
||||
#else
|
||||
|
||||
typedef struct {
|
||||
int is_available;
|
||||
int size;
|
||||
} MCB, *MCB_P;
|
||||
|
||||
static char *mem_start_p;
|
||||
static int max_mem;
|
||||
static int allocated_mem; /* this is the memory in use. */
|
||||
static int mcb_count;
|
||||
static char *heap_end;
|
||||
|
||||
enum { NEW_MCB = 0,
|
||||
NO_MCB,
|
||||
REUSE_MCB };
|
||||
enum { FREE,
|
||||
IN_USE };
|
||||
|
||||
void InitMem(char *ptr, int size_in_bytes) {
|
||||
/* store the ptr and size_in_bytes in global variable */
|
||||
max_mem = size_in_bytes;
|
||||
mem_start_p = ptr;
|
||||
mcb_count = 0;
|
||||
allocated_mem = 0;
|
||||
heap_end = mem_start_p + size_in_bytes;
|
||||
memset(mem_start_p, 0x00, max_mem);
|
||||
/* This function is complete :-) */
|
||||
}
|
||||
|
||||
RZ_API void *rz_malloc(int elem_size) {
|
||||
/* check whether any chunk (allocated before) is free first */
|
||||
MCB_P p_mcb;
|
||||
int flag = NO_MCB;
|
||||
int sz;
|
||||
|
||||
p_mcb = (MCB_P)mem_start_p;
|
||||
sz = sizeof(MCB);
|
||||
|
||||
if ((elem_size + sz) > (max_mem - (allocated_mem + mcb_count * sz)))
|
||||
return NULL;
|
||||
while (heap_end > ((char *)p_mcb + elem_size + sz)) {
|
||||
if (p_mcb->is_available == 0) {
|
||||
if (p_mcb->size == 0) {
|
||||
flag = NEW_MCB;
|
||||
break;
|
||||
}
|
||||
if (p_mcb->size >= (elem_size + sz)) {
|
||||
flag = REUSE_MCB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
p_mcb = (MCB_P)((char *)p_mcb + p_mcb->size);
|
||||
}
|
||||
|
||||
if (flag != NO_MCB) {
|
||||
p_mcb->is_available = 1;
|
||||
if (flag == NEW_MCB) {
|
||||
p_mcb->size = elem_size + sizeof(MCB);
|
||||
} else if (flag == REUSE_MCB) {
|
||||
elem_size = p_mcb->size - sizeof(MCB);
|
||||
}
|
||||
mcb_count++;
|
||||
allocated_mem += elem_size;
|
||||
return ((char *)p_mcb + sz);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rz_free(void *p) {
|
||||
/* Mark in MCB that this chunk is free */
|
||||
MCB_P ptr = (MCB_P)p;
|
||||
ptr--;
|
||||
|
||||
if (ptr->is_available != FREE) {
|
||||
mcb_count--;
|
||||
ptr->is_available = FREE;
|
||||
allocated_mem -= (ptr->size - sizeof(MCB));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __MAIN__
|
||||
int main() {
|
||||
#define MB 1024 * 1024
|
||||
#define RZ_MALLOC_MAX 2 * MB
|
||||
|
||||
#if RZ_ALLOC_USE_STACK
|
||||
char B[RZ_MALLOC_MAX];
|
||||
#endif
|
||||
#if RZ_ALLOC_USE_MMAP
|
||||
int fd = open(".mem", O_CREAT | O_RDWR, 0600);
|
||||
ftruncate(fd, RZ_MALLOC_MAX);
|
||||
char *B = mmap(NULL, RZ_MALLOC_MAX, PROT_WRITE | PROT_READ,
|
||||
MAP_FILE | MAP_PRIVATE, fd, 0);
|
||||
unlink(".mem");
|
||||
close(fd);
|
||||
#endif
|
||||
|
||||
InitMem(B, RZ_MALLOC_MAX);
|
||||
|
||||
char *a = rz_malloc(10);
|
||||
if (!a) {
|
||||
printf("can't malloc\n");
|
||||
return 1;
|
||||
}
|
||||
strcpy(a, "hello");
|
||||
char *b = rz_malloc(10);
|
||||
strcpy(b, "world");
|
||||
printf("%p: %s\n%p: %s\n", a, a, b, b);
|
||||
rz_free(b);
|
||||
rz_free(a);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2019 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
void *a = dlopen(NULL, RTLD_LAZY);
|
||||
void *m = dlsym(a, "rz_main_rizin");
|
||||
if (m) {
|
||||
int (*rz_main)(int argc, char **argv) = m;
|
||||
return rz_main(argc, argv);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2014-2020 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_core.h>
|
||||
|
||||
#if __WINDOWS__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static RzCore *core = NULL;
|
||||
|
||||
#if __UNIX__
|
||||
|
||||
// XXX check if its already opened
|
||||
static RzCoreFile *openself(void) {
|
||||
RzCoreFile *fd = NULL;
|
||||
char *out = rz_core_cmd_str(core, "o");
|
||||
if (out) {
|
||||
if (!strstr(out, "self://")) {
|
||||
fd = rz_core_file_open(core, "self://", RZ_PERM_RW, 0);
|
||||
}
|
||||
free(out);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void sigusr1(int s) {
|
||||
RzCoreFile *fd = openself();
|
||||
rz_core_prompt_loop(core);
|
||||
rz_core_file_close(core, fd);
|
||||
}
|
||||
|
||||
static void sigusr2(int s) {
|
||||
(void)openself();
|
||||
rz_equal_H_handler_old(core, "&");
|
||||
}
|
||||
|
||||
static void _libwrap_init() __attribute__((constructor));
|
||||
static void _libwrap_init(void) {
|
||||
char *web;
|
||||
rz_sys_signal(SIGUSR1, sigusr1);
|
||||
rz_sys_signal(SIGUSR2, sigusr2);
|
||||
printf("librz initialized. send SIGUSR1 to %d in order to reach the rizin prompt\n", getpid());
|
||||
printf("kill -USR1 %d\n", getpid());
|
||||
fflush(stdout);
|
||||
web = rz_sys_getenv("RZ_RUN_WEB");
|
||||
core = rz_core_new();
|
||||
rz_core_loadlibs(core, RZ_CORE_LOADLIBS_ALL, NULL);
|
||||
if (web) {
|
||||
rz_equal_H_handler_old(core, "&");
|
||||
rz_sys_setenv("RZ_RUN_WEB", NULL);
|
||||
free(web);
|
||||
}
|
||||
// TODO: maybe reopen every time a signal is spawned to reload memory regions information
|
||||
// TODO: open io_self
|
||||
}
|
||||
#elif __WINDOWS__
|
||||
void alloc_console(void) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO coninfo;
|
||||
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD lpMode;
|
||||
|
||||
AllocConsole();
|
||||
GetConsoleMode(hStdin, &lpMode);
|
||||
SetConsoleMode(hStdin, lpMode & (~ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT));
|
||||
GetConsoleScreenBufferInfo(hStdin, &coninfo);
|
||||
coninfo.dwSize.Y = 4096;
|
||||
SetConsoleScreenBufferSize(hStdin, coninfo.dwSize);
|
||||
|
||||
rz_xfreopen("conin$", "r", stdin);
|
||||
rz_xfreopen("conout$", "w", stdout);
|
||||
rz_xfreopen("conout$", "w", stderr);
|
||||
}
|
||||
|
||||
static void start_rz(void) {
|
||||
core = rz_core_new();
|
||||
rz_core_loadlibs(core, RZ_CORE_LOADLIBS_ALL, NULL);
|
||||
RzCoreFile *fd = rz_core_file_open(core, "self://", RZ_PERM_RW, 0);
|
||||
rz_core_prompt_loop(core);
|
||||
rz_core_file_close(core, fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Neat little helper function to later enable injecting without
|
||||
* a .exe
|
||||
* simply call: rundll32.exe librz.dll,rundll_inject 0,0,0,0
|
||||
* TODO: implement all injecting methods
|
||||
*/
|
||||
void rundll_inject(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
|
||||
/* do something here */
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD result, LPVOID lpReserved) {
|
||||
switch (result) {
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_PROCESS_ATTACH:
|
||||
alloc_console();
|
||||
start_rz();
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
.os darwin
|
||||
.arch x86
|
||||
.bits 32
|
||||
|
||||
mov eax, $sys.getpid
|
||||
sub esp, 4
|
||||
int 0x80
|
||||
mov ebx, $sys.kill
|
||||
xchg eax, ebx
|
||||
sub esp, 8
|
||||
int 0x80
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
.os darwin
|
||||
.arch x86
|
||||
.bits 64
|
||||
|
||||
mov rax, $sys.getpid
|
||||
syscall
|
||||
mov rdi, $sys.kill
|
||||
xchg rax, rdi
|
||||
syscall
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
.os linux
|
||||
.arch x86
|
||||
.bits 32
|
||||
|
||||
mov eax, $sys.getpid
|
||||
int 0x80
|
||||
mov ebx, $sys.kill
|
||||
xchg eax, ebx
|
||||
int 0x80
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
.os linux
|
||||
.arch x86
|
||||
.bits 64
|
||||
|
||||
mov rax, $sys.getpid
|
||||
syscall
|
||||
mov rdi, $sys.kill
|
||||
xchg rax, rdi
|
||||
syscall
|
||||
Loading…
Reference in a new issue