Skip to content

Commit

Permalink
Fix some warnings on Windows (#15532)
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoLCR authored and radare committed Nov 29, 2019
1 parent e0b1977 commit ebaf8b6
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion libr/asm/arch/or1k/or1k_disas.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define OR1K_DISAS_H

/** Default mask for opcode */
#define INSN_OPCODE_MASK (0b111111 * 0x4000000)
#define INSN_OPCODE_MASK (0b111111ULL * 0x4000000)
#define INSN_OPCODE_SHIFT 26

/** Empty mask for unused operands */
Expand Down
28 changes: 14 additions & 14 deletions libr/core/windows_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static bool GetFirstHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) {
if (index > heapInfo->BlockCount) {
return false;
}
hb->dwAddress = (void *)block[index].address;
hb->dwAddress = block[index].address;
hb->dwSize = block->size;
if (block[index].extra & EXTRA_FLAG) {
PHeapBlockExtraInfo extra = (PHeapBlockExtraInfo)(block[index].extra & ~EXTRA_FLAG);
Expand Down Expand Up @@ -209,7 +209,7 @@ static bool GetNextHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) {
}

// new address = curBlockAddress + Granularity;
hb->dwAddress = (void *)(block[index].address + heapInfo->Granularity);
hb->dwAddress = block[index].address + heapInfo->Granularity;

index++;
hb->dwSize = block->size;
Expand All @@ -221,7 +221,7 @@ static bool GetNextHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) {
PHeapBlockExtraInfo extra = (PHeapBlockExtraInfo)(block[index].extra & ~EXTRA_FLAG);
hb->extraInfo = extra;
hb->dwSize -= extra->unusedBytes;
hb->dwAddress = (void *)(block[index].address + extra->granularity);
hb->dwAddress = block[index].address + extra->granularity;
} else {
hb->extraInfo = NULL;
hb->dwAddress = (WPARAM)hb->dwAddress + hb->dwSize;
Expand Down Expand Up @@ -352,11 +352,11 @@ static bool GetLFHKey(RDebug *dbg, HANDLE h_proc, bool segment, WPARAM *lfhKey)
static bool DecodeHeapEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry) {
r_return_val_if_fail (heap && entry, false);
if (dbg->bits == R_SYS_BITS_64) {
entry = (WPARAM)entry + dbg->bits;
entry = (PHEAP_ENTRY)((ut8 *)entry + dbg->bits);
}
if (heap->EncodeFlagMask && (*(UINT32 *)entry & heap->EncodeFlagMask)) {
if (dbg->bits == R_SYS_BITS_64) {
heap = (WPARAM)heap + dbg->bits;
heap = (PHEAP)((ut8 *)heap + dbg->bits);
}
*(WPARAM *)entry ^= *(WPARAM *)&heap->Encoding;
}
Expand All @@ -366,7 +366,7 @@ static bool DecodeHeapEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry) {
static bool DecodeLFHEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry, PHEAP_USERDATA_HEADER userBlocks, WPARAM key, WPARAM addr) {
r_return_val_if_fail (heap && entry, false);
if (dbg->bits == R_SYS_BITS_64) {
entry = (WPARAM)entry + dbg->bits;
entry = (PHEAP_ENTRY)((ut8 *)entry + dbg->bits);
}

if (heap->EncodeFlagMask) {
Expand Down Expand Up @@ -407,10 +407,10 @@ static RList *GetListOfHeaps(RDebug *dbg, HANDLE ph) {
PVOID *processHeaps;
ULONG numberOfHeaps;
if (dbg->bits == R_SYS_BITS_64) {
processHeaps = *((ut64 *)(((ut8 *)&peb) + 0xF0));
processHeaps = *((PVOID *)(((ut8 *)&peb) + 0xF0));
numberOfHeaps = *((ULONG *)(((ut8 *)& peb) + 0xE8));
} else {
processHeaps = *((ut64 *)(((ut8 *)&peb) + 0x90));
processHeaps = *((PVOID *)(((ut8 *)&peb) + 0x90));
numberOfHeaps = *((ULONG *)(((ut8 *)& peb) + 0x88));
}
do {
Expand Down Expand Up @@ -986,7 +986,7 @@ static PHeapBlock GetSingleSegmentBlock(RDebug *dbg, HANDLE h_proc, PSEGMENT_HEA
HEAP_VS_CHUNK_HEADER header;
ReadProcessMemory (h_proc, (PVOID)(headerOff - sizeof (HEAP_VS_CHUNK_HEADER)), &header, sizeof (HEAP_VS_CHUNK_HEADER), NULL);
header.Sizes.HeaderBits ^= RtlpHpHeapGlobal ^ headerOff;
hb->dwAddress = (PVOID)offset;
hb->dwAddress = offset;
hb->dwSize = header.Sizes.UnsafeSize * sizeof (HEAP_VS_CHUNK_HEADER);
hb->dwFlags = 1 | SEGMENT_HEAP_BLOCK | VS_BLOCK;
extra->granularity = granularity + sizeof (HEAP_VS_CHUNK_HEADER);
Expand All @@ -1001,7 +1001,7 @@ static PHeapBlock GetSingleSegmentBlock(RDebug *dbg, HANDLE h_proc, PSEGMENT_HEA
WPARAM lfhKey;
GetLFHKey (dbg, h_proc, true, &lfhKey);
subsegment.BlockOffsets.EncodedData ^= (DWORD)lfhKey ^ ((DWORD)subsegmentOffset >> 0xC);
hb->dwAddress = (PVOID)offset;
hb->dwAddress = offset;
hb->dwSize = subsegment.BlockOffsets.BlockSize;
hb->dwFlags = 1 | SEGMENT_HEAP_BLOCK | LFH_BLOCK;
extra->granularity = granularity;
Expand All @@ -1028,11 +1028,11 @@ static PHeapBlock GetSingleSegmentBlock(RDebug *dbg, HANDLE h_proc, PSEGMENT_HEA
} else if ((offset & ~0xFFFFULL) < VirtualAddess) {
curr = (WPARAM)node.Left;
} else {
hb->dwAddress = (PVOID)VirtualAddess;
hb->dwAddress = VirtualAddess;
hb->dwSize = ((entry.AllocatedPages >> 12) << 12) - entry.UnusedBytes;
hb->dwFlags = SEGMENT_HEAP_BLOCK | LARGE_BLOCK | 1;
extra->unusedBytes = entry.UnusedBytes;
ReadProcessMemory (h_proc, hb->dwAddress, &extra->granularity, sizeof (USHORT), NULL);
ReadProcessMemory (h_proc, (PVOID)hb->dwAddress, &extra->granularity, sizeof (USHORT), NULL);
return hb;
}
if (curr) {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ static PHeapBlock GetSingleBlock(RDebug *dbg, ut64 offset) {
HEAP_ENTRY tmpEntry = entry;
if (DecodeHeapEntry (dbg, &h, &tmpEntry)) {
entry = tmpEntry;
hb->dwAddress = (PVOID)offset;
hb->dwAddress = offset;
UPDATE_FLAGS (hb, (DWORD)entry.Flags | NT_BLOCK);
if (entry.UnusedBytes == 0x4) {
HEAP_VIRTUAL_ALLOC_ENTRY largeEntry;
Expand Down Expand Up @@ -1133,7 +1133,7 @@ static PHeapBlock GetSingleBlock(RDebug *dbg, ut64 offset) {
if (!ReadProcessMemory (h_proc, (PVOID)UserBlocks.SubSegment, &subsegment, sizeof (HEAP_SUBSEGMENT), NULL)) {
continue;
}
hb->dwAddress = (PVOID)offset;
hb->dwAddress = offset;
hb->dwSize = (WPARAM)subsegment.BlockSize * heap.Granularity;
hb->dwFlags = 1 | LFH_BLOCK | NT_BLOCK;
break;
Expand Down
2 changes: 1 addition & 1 deletion libr/debug/p/debug_windbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static RList *r_debug_windbg_threads(RDebug *dbg, int pid) {
return ret;
}

static RList *r_debug_windbg_modules(RDebug *dbg, int pid) {
static RList *r_debug_windbg_modules(RDebug *dbg) {
RListIter *it;
WindModule *m;

Expand Down
8 changes: 4 additions & 4 deletions libr/debug/p/native/windows/windows_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {

static void __transfer_drx(RDebug *dbg, ut8 *buf) {
CONTEXT cur_ctx;
if (w32_reg_read (dbg, R_REG_TYPE_ALL, &cur_ctx, sizeof (CONTEXT))) {
if (w32_reg_read (dbg, R_REG_TYPE_ALL, (ut8 *)&cur_ctx, sizeof (CONTEXT))) {
CONTEXT *new_ctx = (CONTEXT *)buf;
size_t drx_size = offsetof (CONTEXT, Dr7) - offsetof (CONTEXT, Dr0) + sizeof (new_ctx->Dr7);
memcpy (&cur_ctx.Dr0, &new_ctx->Dr0, drx_size);
Expand Down Expand Up @@ -890,7 +890,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) {
void *bed = r_cons_sleep_begin ();
w32dbg_wrap_wait_ret (rio->inst);
r_cons_sleep_end (bed);
if (!w32dbgw_intret (inst)) {
if (!w32dbgw_ret (inst)) {
if (w32dbgw_err (inst) != ERROR_SEM_TIMEOUT) {
r_sys_perror ("w32_dbg_wait/WaitForDebugEvent");
ret = -1;
Expand Down Expand Up @@ -925,7 +925,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) {
rio->pi.hProcess = de.u.CreateProcessInfo.hProcess;
rio->pi.hThread = de.u.CreateProcessInfo.hThread;
rio->pi.dwProcessId = pid;
rio->winbase = de.u.CreateProcessInfo.lpBaseOfImage;
rio->winbase = (ULONG_PTR)de.u.CreateProcessInfo.lpBaseOfImage;
ret = R_DEBUG_REASON_NEW_PID;
next_event = 0;
break;
Expand Down Expand Up @@ -1094,7 +1094,7 @@ int w32_continue(RDebug *dbg, int pid, int tid, int sig) {
inst->params->tid = rio->pi.dwThreadId;
inst->params->continue_status = continue_status;
w32dbg_wrap_wait_ret (inst);
if (!w32dbgw_intret (inst)) {
if (!w32dbgw_ret (inst)) {
w32dbgw_err (inst);
r_sys_perror ("w32_continue/ContinueDebugEvent");
return -1;
Expand Down
8 changes: 4 additions & 4 deletions libr/include/r_util/r_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output,
#define W32_TCHAR_FSTR "%S"
#define W32_TCALL(name) name"W"
#define r_sys_conv_utf8_to_win(buf) r_utf8_to_utf16 (buf)
#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_utf16_l (buf, len)
#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_utf16_l ((ut8 *)buf, len)
#define r_sys_conv_win_to_utf8(buf) r_utf16_to_utf8 (buf)
#define r_sys_conv_win_to_utf8_l(buf, len) r_utf16_to_utf8_l (buf, len)
#define r_sys_conv_win_to_utf8_l(buf, len) r_utf16_to_utf8_l ((wchar_t *)buf, len)
#else
#define W32_TCHAR_FSTR "%s"
#define W32_TCALL(name) name"A"
#define r_sys_conv_utf8_to_win(buf) r_utf8_to_acp (buf)
#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_acp_l (buf, len)
#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_acp_l ((ut8 *)buf, len)
#define r_sys_conv_win_to_utf8(buf) r_acp_to_utf8 (buf)
#define r_sys_conv_win_to_utf8_l(buf, len) r_acp_to_utf8_l (buf, len)
#define r_sys_conv_win_to_utf8_l(buf, len) r_acp_to_utf8_l ((ut8 *)buf, len)
#endif
R_API char *r_sys_get_src_dir_w32(void);
R_API bool r_sys_cmd_str_full_w32(const char *cmd, const char *input, char **output, int *outlen, char **sterr);
Expand Down
12 changes: 6 additions & 6 deletions libr/include/r_util/r_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ R_API wchar_t *r_utf8_to_utf16_l(const char *cstring, int len);
R_API int r_utf_block_idx (RRune ch);
R_API int *r_utf_block_list (const ut8 *str, int len, int **freq_list);
R_API RStrEnc r_utf_bom_encoding(const ut8 *ptr, int ptrlen);
#define r_utf16_to_utf8(wc) r_utf16_to_utf8_l ((wc), -1)
#define r_utf8_to_utf16(cstring) r_utf8_to_utf16_l ((cstring), -1)
#define r_utf16_to_utf8(wc) r_utf16_to_utf8_l ((wchar_t *)wc, -1)
#define r_utf8_to_utf16(cstring) r_utf8_to_utf16_l ((char *)cstring, -1)
#if __WINDOWS__
R_API const char *r_acp_to_utf8_l (const ut8 *str, int len);
R_API char *r_utf8_to_acp_l(const ut8 *str, int len);
#define r_acp_to_utf8(str) r_acp_to_utf8_l ((str), -1)
#define r_utf8_to_acp(cstring) r_utf8_to_acp_l ((cstring), -1)
R_API char *r_acp_to_utf8_l(const char *str, int len);
R_API char *r_utf8_to_acp_l(const char *str, int len);
#define r_acp_to_utf8(str) r_acp_to_utf8_l ((char *)str, -1)
#define r_utf8_to_acp(cstring) r_utf8_to_acp_l ((char *)cstring, -1)
#endif // __WINDOWS__

#endif // R_UTF8_H
4 changes: 2 additions & 2 deletions libr/io/p/io_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
inst->params->func.func = __createprocess_wrap;
inst->params->func.user = &p;
w32dbg_wrap_wait_ret (inst);
if (!w32dbgw_intret (inst)) {
if (!w32dbgw_ret (inst)) {
w32dbgw_err (inst);
r_sys_perror ("fork_and_ptraceme/CreateProcess");
free (appname_);
Expand All @@ -164,7 +164,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
inst->params->wait.wait_time = 10000;
inst->params->wait.de = &de;
w32dbg_wrap_wait_ret (inst);
if (!w32dbgw_intret (inst)) goto err_fork;
if (!w32dbgw_ret (inst)) goto err_fork;

/* check if is a create process debug event */
if (de.dwDebugEventCode != CREATE_PROCESS_DEBUG_EVENT) {
Expand Down
4 changes: 2 additions & 2 deletions libr/io/p/io_w32dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int __open_proc(RIO *io, RIOW32Dbg *dbg, bool attach) {
inst->params->type = W32_ATTACH;
inst->params->pid = dbg->pi.dwProcessId;
w32dbg_wrap_wait_ret (inst);
if (!w32dbgw_intret (inst)) {
if (!w32dbgw_ret (inst)) {
w32dbgw_err (inst);
r_sys_perror ("__open_proc/DebugActiveProcess");
goto att_exit;
Expand All @@ -117,7 +117,7 @@ static int __open_proc(RIO *io, RIOW32Dbg *dbg, bool attach) {
inst->params->wait.wait_time = 10000;
inst->params->wait.de = &de;
w32dbg_wrap_wait_ret (inst);
if (!w32dbgw_intret (inst)) {
if (!w32dbgw_ret (inst)) {
w32dbgw_err (inst);
r_sys_perror ("__open_proc/WaitForDebugEvent");
goto att_exit;
Expand Down
6 changes: 3 additions & 3 deletions libr/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ R_API R_TH_TID r_th_self(void) {
#if HAVE_PTHREAD
return pthread_self ();
#elif __WINDOWS__
return (HANDLE)GetCurrentThreadId ();
return GetCurrentThread ();
#else
#pragma message("Not implemented on windows")
#pragma message("Not implemented on this platform")
return (R_TH_TID)-1;
#endif
}
Expand Down Expand Up @@ -158,7 +158,7 @@ R_API RThread *r_th_new(R_TH_FUNCTION(fun), void *user, int delay) {
if (th) {
th->lock = r_th_lock_new (false);
th->running = false;
th->fun = fun;
th->fun = fun;
th->user = user;
th->delay = delay;
th->breaked = false;
Expand Down
6 changes: 3 additions & 3 deletions libr/util/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ R_API wchar_t *r_utf8_to_utf16_l(const char *cstring, int len) {
return rutf16;
}

R_API char *r_utf8_to_acp_l(const ut8 *str, int len) {
R_API char *r_utf8_to_acp_l(const char *str, int len) {
if (!str || !len || len < -1) {
return NULL;
}
Expand Down Expand Up @@ -684,7 +684,7 @@ R_API char *r_utf8_to_acp_l(const ut8 *str, int len) {
return acp;
}

R_API const char *r_acp_to_utf8_l(const ut8 *str, int len) {
R_API char *r_acp_to_utf8_l(const char *str, int len) {
if (!str || !len || len < -1) {
return NULL;
}
Expand All @@ -697,7 +697,7 @@ R_API const char *r_acp_to_utf8_l(const ut8 *str, int len) {
if (len != -1) {
rutf16[wcsize - 1] = L'\0';
}
const char *ret = r_utf16_to_utf8_l (rutf16, wcsize);
char *ret = r_utf16_to_utf8_l (rutf16, wcsize);
free (rutf16);
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion shlr/heap/include/r_windows/windows_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ typedef struct _HeapBlockExtraInfo { // think of extra stuff to put here
} HeapBlockExtraInfo, *PHeapBlockExtraInfo;

typedef struct _HeapBlock {
PVOID dwAddress;
ULONG_PTR dwAddress;
SIZE_T dwSize;
DWORD dwFlags;
SIZE_T index;
Expand Down
3 changes: 1 addition & 2 deletions shlr/w32dbg_wrap/include/w32dbg_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct {
void *user;
} func;
};
void *ret;
int ret;
DWORD err;
} w32dbg_wrap_params;

Expand All @@ -46,7 +46,6 @@ typedef struct {
} RIOW32Dbg;

#define w32dbgw_ret(inst) inst->params->ret
#define w32dbgw_intret(inst) PtrToInt (w32dbgw_ret(inst))
#define w32dbgw_err(inst) (SetLastError (inst->params->err), inst->params->err)

w32dbg_wrap_instance *w32dbg_wrap_new(void);
Expand Down
2 changes: 1 addition & 1 deletion shlr/w32dbg_wrap/src/w32dbg_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ void w32dbg_wrap_fini(w32dbg_wrap_instance *inst) {
int w32dbg_wrap_wait_ret(w32dbg_wrap_instance *inst) {
ReleaseSemaphore (inst->request_sem, 1, NULL);
WaitForSingleObject (inst->result_sem, INFINITE);
return w32dbgw_intret(inst);
return w32dbgw_ret(inst);
}

0 comments on commit ebaf8b6

Please sign in to comment.