* Fix build on mingw32
This commit is contained in:
parent
d47e67cdd1
commit
e101e5023d
|
@ -9,10 +9,10 @@ CFLAGS+=-DLIBDIR=\"${PREFIX}/lib\"
|
|||
#LIBS=$(subst r_,-lr_,$(DEPS))
|
||||
LIBS+=$(subst r_,-L../../libr/,$(DEPS))
|
||||
|
||||
all: ${BIN}
|
||||
all: ${BIN}${EXT_EXE}
|
||||
|
||||
${BIN}: ${BIN}.o
|
||||
${CC} -o ${BIN} ${LIBS} ${LDFLAGS} ${BIN}.o
|
||||
${BIN}${EXT_EXE}: ${BIN}.o
|
||||
${CC} -o ${BIN}${EXT_EXE} ${LIBS} ${LDFLAGS} ${BIN}.o
|
||||
|
||||
clean:
|
||||
rm -f ${BIN} ${BIN}.o ${BIN}.d
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
#include <r_types.h>
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#if __WINDOWS__
|
||||
# include <windows.h>
|
||||
|
@ -1003,7 +1004,7 @@ void x86im_fmt_format_operand( __in x86im_instr_object *io,
|
|||
{
|
||||
if ( X86IM_IO_MOP_AMC_HAS_DISP64( io ) )
|
||||
{
|
||||
p = "%s%llX";
|
||||
p = "%s%"PFMT64x;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1090,7 +1091,7 @@ void x86im_fmt_format_operand( __in x86im_instr_object *io,
|
|||
{
|
||||
if ( io->imm_size == X86IM_IO_IM_SZ_QWORD )
|
||||
{
|
||||
sprintf( src, "%llX", io->imm );
|
||||
sprintf( src, "%"PFMT64x, io->imm );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1114,7 +1115,7 @@ void x86im_fmt_format_operand( __in x86im_instr_object *io,
|
|||
|
||||
if ( io->imm_size == 8 )
|
||||
{
|
||||
sprintf( dst + strlen(dst), "%llX", io->imm );
|
||||
sprintf( dst + strlen(dst), "%"PFMT64x, io->imm );
|
||||
}
|
||||
else if ( io->imm_size == 3 )
|
||||
{
|
||||
|
@ -1125,7 +1126,7 @@ void x86im_fmt_format_operand( __in x86im_instr_object *io,
|
|||
}
|
||||
else
|
||||
{
|
||||
sprintf( dst + strlen(dst), "%llX", io->imm );
|
||||
sprintf( dst + strlen(dst), "%"PFMT64x, io->imm );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,15 @@
|
|||
#define __X86IM_FMT_H__
|
||||
|
||||
#ifdef __X86IM_USE_FMT__
|
||||
#ifndef __in
|
||||
#define __in
|
||||
#endif
|
||||
#ifndef __out
|
||||
#define __out
|
||||
#endif
|
||||
#ifndef __inout
|
||||
#define __inout
|
||||
#endif
|
||||
|
||||
char *x86f_get_imn( __in x86im_instr_object *io );
|
||||
char *x86f_get_reg( __in unsigned short reg );
|
||||
|
|
|
@ -2,6 +2,7 @@ include ../../config.mk
|
|||
|
||||
CFLAGS=-I../../include -I../arch -Wall -fPIC ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
|
||||
CFLAGS+=-L../../util -lr_util
|
||||
LDFLAGS+=${LINK}
|
||||
|
||||
foo: all
|
||||
|
||||
|
|
|
@ -7,4 +7,4 @@ TARGET_X86=anal_x86.${EXT_SO}
|
|||
ALL_TARGETS+=${TARGET_X86}
|
||||
|
||||
${TARGET_X86}: ${OBJ_X86}
|
||||
${CC} ${LDFLAGS} ${CFLAGS} -o anal_x86.${EXT_SO} ${OBJ_X86}
|
||||
${CC} -L../../reg -lr_reg -L.. -lr_anal ${LDFLAGS} ${CFLAGS} -o anal_x86.${EXT_SO} ${OBJ_X86}
|
||||
|
|
|
@ -48,6 +48,14 @@ R_API void r_cons_break_end() {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if __WINDOWS__
|
||||
static HANDLE h;
|
||||
static BOOL __w32_control(DWORD type) {
|
||||
if (type == CTRL_C_EVENT)
|
||||
break_signal (2); // SIGINT
|
||||
}
|
||||
#endif
|
||||
|
||||
R_API RCons *r_cons_new () {
|
||||
I.is_interactive = R_TRUE;
|
||||
I.breaked = R_FALSE;
|
||||
|
@ -69,10 +77,10 @@ R_API RCons *r_cons_new () {
|
|||
I.term_raw.c_cflag |= CS8;
|
||||
I.term_raw.c_cc[VMIN] = 1; // Solaris stuff hehe
|
||||
#elif __WINDOWS__
|
||||
h = GetStdPlugin (STD_INPUT_HANDLE);
|
||||
h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
GetConsoleMode (h, &I.term_buf);
|
||||
I.term_raw = 0;
|
||||
if (!SetConsoleCtrlPlugin ((PHANDLER_ROUTINE)__w32_control, TRUE))
|
||||
if (!SetConsoleCtrlHandler ((PHANDLER_ROUTINE)__w32_control, TRUE))
|
||||
eprintf ("r_cons: Cannot set control console handler\n");
|
||||
#endif
|
||||
//r_cons_palette_init(NULL);
|
||||
|
@ -85,14 +93,6 @@ R_API RCons *r_cons_free (RCons *foo) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if __WINDOWS__
|
||||
static HANDLE h;
|
||||
static BOOL __w32_control(DWORD type) {
|
||||
if (type == CTRL_C_EVENT)
|
||||
break_signal (2); // SIGINT
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MOAR 4096*4
|
||||
static void palloc(int moar) {
|
||||
if (I.buffer == NULL) {
|
||||
|
@ -116,7 +116,7 @@ R_API void r_cons_gotoxy(int x, int y) {
|
|||
coord.X = x;
|
||||
coord.Y = y;
|
||||
if (!hStdout)
|
||||
hStdout = GetStdPlugin (STD_OUTPUT_HANDLE);
|
||||
hStdout = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
SetConsoleCursorPosition (hStdout,coord);
|
||||
#else
|
||||
r_cons_printf ("\x1b[%d;%dH", y, x);
|
||||
|
@ -136,7 +136,7 @@ R_API void r_cons_clear() {
|
|||
DWORD dummy;
|
||||
|
||||
if (!hStdout) {
|
||||
hStdout = GetStdPlugin (STD_OUTPUT_HANDLE);
|
||||
hStdout = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
GetConsoleScreenBufferInfo (hStdout,&csbi);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ R_API int r_cons_readchar() {
|
|||
BOOL ret;
|
||||
DWORD out;
|
||||
LPDWORD mode;
|
||||
HANDLE h = GetStdPlugin (STD_INPUT_HANDLE);
|
||||
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
GetConsoleMode (h, &mode);
|
||||
SetConsoleMode (h, 0); // RAW
|
||||
ret = ReadConsole (h, buf,1, &out, NULL);
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
#include <r_cons.h>
|
||||
|
||||
#if __WINDOWS__
|
||||
int r_cons_w32_print(ut8 *ptr)
|
||||
{
|
||||
HANDLE hConsole = GetStdPlugin(STD_OUTPUT_HANDLE);
|
||||
R_API int r_cons_w32_print(ut8 *ptr) {
|
||||
HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
int esc = 0;
|
||||
int bg = 0;
|
||||
ut8 *str = ptr;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
include ../../config.mk
|
||||
# XXX
|
||||
CFLAGS=-I../../include -I../arch/ -I../arch/include -Wall -fPIC ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
|
||||
LDFLAGS+=${LINK}
|
||||
|
||||
foo: all
|
||||
|
||||
|
|
|
@ -6,4 +6,4 @@ TARGET_AES=crypto_aes.${EXT_SO}
|
|||
ALL_TARGETS+=${TARGET_AES}
|
||||
|
||||
${TARGET_AES}: ${OBJ_AES}
|
||||
${CC} ${CFLAGS} -o ${TARGET_AES} ${OBJ_AES}
|
||||
${CC} ${LDFLAGS} ${CFLAGS} -o ${TARGET_AES} ${OBJ_AES}
|
||||
|
|
|
@ -90,19 +90,19 @@ static int w32_dbg_init() {
|
|||
HANDLE lib;
|
||||
|
||||
w32_detach = (BOOL WINAPI (*)(DWORD))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"),
|
||||
GetProcAddress (GetModuleHandle ("kernel32"),
|
||||
"DebugActiveProcessStop");
|
||||
w32_openthread = (HANDLE WINAPI (*)(DWORD, BOOL, DWORD))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"), "OpenThread");
|
||||
GetProcAddress (GetModuleHandle ("kernel32"), "OpenThread");
|
||||
w32_dbgbreak = (HANDLE WINAPI (*)(HANDLE))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"),
|
||||
GetProcAddress (GetModuleHandle ("kernel32"),
|
||||
"DebugBreakProcess");
|
||||
// only windows vista :(
|
||||
w32_getthreadid = (DWORD WINAPI (*)(HANDLE))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"), "GetThreadId");
|
||||
GetProcAddress (GetModuleHandle ("kernel32"), "GetThreadId");
|
||||
// from xp1
|
||||
w32_getprocessid = (DWORD WINAPI (*)(HANDLE))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"), "GetProcessId");
|
||||
GetProcAddress (GetModuleHandle ("kernel32"), "GetProcessId");
|
||||
|
||||
lib = LoadLibrary ("psapi.dll");
|
||||
if(lib == NULL) {
|
||||
|
|
|
@ -154,6 +154,10 @@ R_API void r_cons_break_end();
|
|||
R_API int r_cons_pipe_open(const char *file, int append);
|
||||
R_API void r_cons_pipe_close(int fd);
|
||||
|
||||
#if __WINDOWS__
|
||||
R_API int r_cons_w32_print(ut8 *ptr);
|
||||
#endif
|
||||
|
||||
/* control */
|
||||
R_API void r_cons_reset();
|
||||
R_API void r_cons_clear();
|
||||
|
|
|
@ -70,7 +70,7 @@ static int setup_tokens() {
|
|||
err = 0;
|
||||
err_enable:
|
||||
if (tok != NULL)
|
||||
ClosePlugin (tok);
|
||||
CloseHandle (tok);
|
||||
if (err)
|
||||
r_sys_perror ("setup_tokens");
|
||||
return err;
|
||||
|
@ -102,7 +102,7 @@ static int fork_and_ptraceme(const char *cmd) {
|
|||
THREADENTRY32 te32;
|
||||
HANDLE WINAPI (*win32_openthread)(DWORD, BOOL, DWORD) = NULL;
|
||||
win32_openthread = (HANDLE WINAPI (*)(DWORD, BOOL, DWORD))
|
||||
GetProcAddress (GetModulePlugin ("kernel32"), "OpenThread");
|
||||
GetProcAddress (GetModuleHandle ("kernel32"), "OpenThread");
|
||||
|
||||
th = CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, pid);
|
||||
if (th == INVALID_HANDLE_VALUE || !Thread32First(th, &te32)) {
|
||||
|
@ -140,7 +140,7 @@ static int fork_and_ptraceme(const char *cmd) {
|
|||
}
|
||||
|
||||
if (th != INVALID_HANDLE_VALUE)
|
||||
ClosePlugin (th);
|
||||
CloseHandle (th);
|
||||
|
||||
|
||||
eprintf ("PID=%d\n", pid);
|
||||
|
@ -150,7 +150,7 @@ static int fork_and_ptraceme(const char *cmd) {
|
|||
err_fork:
|
||||
TerminateProcess (pi.hProcess, 1);
|
||||
if (th != INVALID_HANDLE_VALUE)
|
||||
ClosePlugin (th);
|
||||
CloseHandle (th);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -39,7 +39,7 @@ static int r_line_readchar() {
|
|||
#if __WINDOWS__
|
||||
BOOL ret;
|
||||
LPDWORD mode, out;
|
||||
HANDLE h = GetStdPlugin (STD_INPUT_HANDLE);
|
||||
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
||||
GetConsoleMode (h, &mode);
|
||||
SetConsoleMode (h, 0); // RAW
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
/* locks/mutex/sems */
|
||||
|
||||
R_API struct r_th_lock_t *r_th_lock_new()
|
||||
{
|
||||
RThreadLock *thl;
|
||||
|
||||
thl = R_NEW(RThreadLock);
|
||||
R_API struct r_th_lock_t *r_th_lock_new() {
|
||||
RThreadLock *thl = R_NEW(RThreadLock);
|
||||
if (thl) {
|
||||
thl->refs = 0;
|
||||
#if HAVE_PTHREAD
|
||||
|
@ -21,22 +18,20 @@ R_API struct r_th_lock_t *r_th_lock_new()
|
|||
return thl;
|
||||
}
|
||||
|
||||
R_API int r_th_lock_wait(struct r_th_lock_t *thl)
|
||||
{
|
||||
R_API int r_th_lock_wait(struct r_th_lock_t *thl) {
|
||||
#if HAVE_PTHREAD
|
||||
r_th_lock_enter(thl);
|
||||
r_th_lock_enter(thl); // locks here
|
||||
r_th_lock_leave(thl); // releases previous mutex
|
||||
r_th_lock_enter (thl);
|
||||
r_th_lock_enter (thl); // locks here
|
||||
r_th_lock_leave (thl); // releases previous mutex
|
||||
#elif __WIN32__
|
||||
WaitForSingleObject (thl->lock, INFINITE);
|
||||
#else
|
||||
while(r_th_lock_check());
|
||||
while (r_th_lock_check ());
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
R_API int r_th_lock_enter(struct r_th_lock_t *thl)
|
||||
{
|
||||
R_API int r_th_lock_enter(struct r_th_lock_t *thl) {
|
||||
#if HAVE_PTHREAD
|
||||
pthread_mutex_lock(&thl->lock);
|
||||
#elif __WIN32__
|
||||
|
@ -45,8 +40,7 @@ R_API int r_th_lock_enter(struct r_th_lock_t *thl)
|
|||
return ++thl->refs;
|
||||
}
|
||||
|
||||
R_API int r_th_lock_leave(struct r_th_lock_t *thl)
|
||||
{
|
||||
R_API int r_th_lock_leave(struct r_th_lock_t *thl) {
|
||||
#if HAVE_PTHREAD
|
||||
pthread_mutex_unlock(&thl->lock);
|
||||
#elif __WIN32__
|
||||
|
@ -58,20 +52,18 @@ R_API int r_th_lock_leave(struct r_th_lock_t *thl)
|
|||
return thl->refs;
|
||||
}
|
||||
|
||||
R_API int r_th_lock_check(struct r_th_lock_t *thl)
|
||||
{
|
||||
R_API int r_th_lock_check(struct r_th_lock_t *thl) {
|
||||
//w32 // TryEnterCriticalSection(&thl->lock);
|
||||
return thl->refs;
|
||||
}
|
||||
|
||||
R_API void *r_th_lock_free(struct r_th_lock_t *thl)
|
||||
{
|
||||
R_API void *r_th_lock_free(struct r_th_lock_t *thl) {
|
||||
if (thl) {
|
||||
#if HAVE_PTHREAD
|
||||
pthread_mutex_destroy(&thl->lock);
|
||||
pthread_mutex_destroy (&thl->lock);
|
||||
#elif __WIN32__
|
||||
DeleteCriticalSection(&thl->lock);
|
||||
ClosePlugin(thl->lock);
|
||||
DeleteCriticalSection (&thl->lock);
|
||||
CloseHandle (thl->lock);
|
||||
#endif
|
||||
free(thl);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ R_API char *r_sys_cmd_str_w32(const char *cmd) {
|
|||
|
||||
// Set the bInheritPlugin flag so pipe handles are inherited.
|
||||
saAttr.nLength = sizeof (SECURITY_ATTRIBUTES);
|
||||
saAttr.bInheritPlugin = TRUE;
|
||||
saAttr.bInheritHandle = TRUE;
|
||||
saAttr.lpSecurityDescriptor = NULL;
|
||||
HANDLE fh;
|
||||
|
||||
|
@ -41,8 +41,8 @@ R_API char *r_sys_cmd_str_w32(const char *cmd) {
|
|||
ErrorExit ("StdoutRd CreatePipe");
|
||||
|
||||
// Ensure the read handle to the pipe for STDOUT is not inherited.
|
||||
if (!SetPluginInformation (fh, HANDLE_FLAG_INHERIT, 0) )
|
||||
ErrorExit ("Stdout SetPluginInformation");
|
||||
if (!SetHandleInformation (fh, HANDLE_FLAG_INHERIT, 0) )
|
||||
ErrorExit ("Stdout SetHandleInformation");
|
||||
|
||||
CreateChildProcess (cmd, out);
|
||||
|
||||
|
@ -61,8 +61,8 @@ R_API char *r_sys_cmd_str_w32(const char *cmd) {
|
|||
// read end of the pipe, to control child process execution.
|
||||
// The pipe is assumed to have enough buffer space to hold the
|
||||
// data the child process has already written to it.
|
||||
if (!ClosePlugin (out))
|
||||
ErrorExit ("StdOutWr ClosePlugin");
|
||||
if (!CloseHandle (out))
|
||||
ErrorExit ("StdOutWr CloseHandle");
|
||||
ret = ReadFromPipe (fh);
|
||||
free (argv0);
|
||||
|
||||
|
@ -97,8 +97,8 @@ static int CreateChildProcess(const char *szCmdline, HANDLE out) {
|
|||
&piProcInfo); // receives PROCESS_INFORMATION
|
||||
|
||||
if (bSuccess) {
|
||||
ClosePlugin (piProcInfo.hProcess);
|
||||
ClosePlugin (piProcInfo.hThread);
|
||||
CloseHandle (piProcInfo.hProcess);
|
||||
CloseHandle (piProcInfo.hThread);
|
||||
} else r_sys_perror ("CreateProcess");
|
||||
return bSuccess;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CC=i486-mingw32-gcc
|
||||
OSTYPE=windows
|
||||
ONELIB=0
|
||||
LINK=
|
||||
LINK=-shared
|
||||
CC_AR=echo ar -r ${LIBAR}
|
||||
PICFLAGS=
|
||||
CFLAGS+=${PICFLAGS} -MD -D__WINDOWS__=1
|
||||
|
|
Loading…
Reference in New Issue