mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-22 23:24:22 +08:00
update whereami and avoid compiling unnneded troublesome parts
This commit is contained in:
parent
d00714d43a
commit
e68dd9e5cb
2 changed files with 60 additions and 35 deletions
|
@ -58,7 +58,7 @@ INCLUDES_CLIENT += -I./src -I../include -I../common -I../common_fpga $(LIBS)
|
|||
CFLAGS ?= $(DEFCFLAGS)
|
||||
|
||||
# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env:
|
||||
PM3CFLAGS = $(CFLAGS) $(INCLUDES_CLIENT)
|
||||
PM3CFLAGS = $(CFLAGS) $(INCLUDES_CLIENT) -DWAI_PM3_TUNED
|
||||
# WIP Testing
|
||||
#PM3CFLAGS = $(CFLAGS) -std=c11 -pedantic $(INCLUDES_CLIENT)
|
||||
PREFIX ?= /usr/local
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
// by Gregory Pakosz (@gpakosz)
|
||||
// https://github.com/gpakosz/whereami
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef WAI_PM3_TUNED
|
||||
|
||||
#include "whereami.h"
|
||||
|
||||
|
@ -14,6 +12,19 @@ extern "C" {
|
|||
#define _DEFAULT_SOURCE
|
||||
#endif
|
||||
|
||||
#else // WAI_PM3_TUNED
|
||||
|
||||
// in case you want to #include "whereami.c" in a larger compilation unit
|
||||
#if !defined(WHEREAMI_H)
|
||||
#include <whereami.h>
|
||||
#endif
|
||||
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
@ -50,11 +61,14 @@ extern "C" {
|
|||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push, 3)
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <intrin.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
@ -123,36 +137,36 @@ static int WAI_PREFIX(getModulePath_)(HMODULE module, char *out, int capacity, i
|
|||
return length;
|
||||
}
|
||||
|
||||
WAI_NOINLINE
|
||||
WAI_FUNCSPEC
|
||||
WAI_NOINLINE WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length) {
|
||||
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
|
||||
}
|
||||
|
||||
// GetModuleHandleEx() is not available on old mingw environments. We don't need getModulePath() yet.
|
||||
// Sacrifice it for the time being to improve backwards compatibility
|
||||
/* WAI_NOINLINE
|
||||
WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
||||
{
|
||||
HMODULE module;
|
||||
int length = -1;
|
||||
#ifndef WAI_PM3_TUNED
|
||||
|
||||
WAI_NOINLINE WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
||||
HMODULE module;
|
||||
int length = -1;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4054)
|
||||
#endif
|
||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)WAI_RETURN_ADDRESS(), &module))
|
||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)WAI_RETURN_ADDRESS(), &module))
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
{
|
||||
length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length);
|
||||
}
|
||||
{
|
||||
length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length);
|
||||
}
|
||||
|
||||
return length;
|
||||
return length;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
|
||||
|
||||
|
@ -228,14 +242,14 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length)
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
WAI_NOINLINE
|
||||
WAI_FUNCSPEC
|
||||
#ifndef WAI_PM3_TUNED
|
||||
|
||||
WAI_NOINLINE WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
||||
int length = -1;
|
||||
FILE *maps = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < WAI_PROC_SELF_MAPS_RETRY; ++i) {
|
||||
for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r) {
|
||||
maps = fopen(WAI_PROC_SELF_MAPS, "r");
|
||||
if (!maps)
|
||||
break;
|
||||
|
@ -252,9 +266,8 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
if (!fgets(buffer, sizeof(buffer), maps))
|
||||
break;
|
||||
|
||||
if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) {
|
||||
void *addr_tmp = WAI_RETURN_ADDRESS();
|
||||
uint64_t addr = (uint64_t)addr_tmp;
|
||||
if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) {
|
||||
uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS();
|
||||
if (low <= addr && addr <= high) {
|
||||
char *resolved;
|
||||
|
||||
|
@ -300,9 +313,11 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
memcpy(out, resolved, length);
|
||||
|
||||
if (dirname_length) {
|
||||
for (int j = length - 1; j >= 0; --j) {
|
||||
if (out[j] == '/') {
|
||||
*dirname_length = j;
|
||||
int i;
|
||||
|
||||
for (i = length - 1; i >= 0; --i) {
|
||||
if (out[i] == '/') {
|
||||
*dirname_length = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -326,6 +341,7 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
|
||||
return length;
|
||||
}
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
|
@ -381,8 +397,9 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length)
|
|||
return length;
|
||||
}
|
||||
|
||||
WAI_NOINLINE
|
||||
WAI_FUNCSPEC
|
||||
#ifndef WAI_PM3_TUNED
|
||||
|
||||
WAI_NOINLINE WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
||||
char buffer[PATH_MAX];
|
||||
char *resolved = NULL;
|
||||
|
@ -419,6 +436,8 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
return length;
|
||||
}
|
||||
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#elif defined(__QNXNTO__)
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -475,6 +494,8 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length)
|
|||
return length;
|
||||
}
|
||||
|
||||
#ifndef WAI_PM3_TUNED
|
||||
|
||||
WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
||||
char buffer[PATH_MAX];
|
||||
|
@ -512,11 +533,12 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
return length;
|
||||
}
|
||||
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
|
||||
defined(__FreeBSD_kernel__) || defined(__NetBSD__)
|
||||
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -532,8 +554,8 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length)
|
|||
int length = -1;
|
||||
|
||||
for (;;) {
|
||||
#ifdef KERN_PROC_ARGV
|
||||
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
|
||||
#if defined(__NetBSD__)
|
||||
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
|
||||
#else
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
#endif
|
||||
|
@ -571,8 +593,9 @@ int WAI_PREFIX(getExecutablePath)(char *out, int capacity, int *dirname_length)
|
|||
return length;
|
||||
}
|
||||
|
||||
WAI_NOINLINE
|
||||
WAI_FUNCSPEC
|
||||
#ifndef WAI_PM3_TUNED
|
||||
|
||||
WAI_NOINLINE WAI_FUNCSPEC
|
||||
int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
||||
char buffer[PATH_MAX];
|
||||
char *resolved = NULL;
|
||||
|
@ -609,6 +632,8 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
|
|||
return length;
|
||||
}
|
||||
|
||||
#endif // WAI_PM3_TUNED
|
||||
|
||||
#else
|
||||
|
||||
#error unsupported platform
|
||||
|
|
Loading…
Reference in a new issue