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