mirror of https://github.com/decompals/wibo.git
Command line parsing
This commit is contained in:
parent
82c05df74e
commit
e6dc3b4ffd
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
all: wibo
|
all: wibo
|
||||||
|
|
||||||
CXXFLAGS = -Wall -g -m32 -std=c++20 -lstdc++
|
CXXFLAGS = -Wall -g -m32 -std=c++20 -lstdc++ -MD
|
||||||
|
|
||||||
BUILD_DIR := build
|
BUILD_DIR := build
|
||||||
CPP_FILES := $(wildcard *.cpp)
|
CPP_FILES := $(wildcard *.cpp)
|
||||||
|
|
5
common.h
5
common.h
|
@ -6,15 +6,20 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define WIN_FUNC __attribute__((stdcall))
|
#define WIN_FUNC __attribute__((stdcall))
|
||||||
|
#define DEBUG_LOG(...) /* nothing */
|
||||||
|
// #define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)
|
||||||
|
|
||||||
namespace wibo {
|
namespace wibo {
|
||||||
extern uint32_t lastError;
|
extern uint32_t lastError;
|
||||||
extern char *commandLine;
|
extern char *commandLine;
|
||||||
|
|
||||||
|
void debug_log(const char *fmt, ...);
|
||||||
|
|
||||||
void *resolveVersion(const char *name);
|
void *resolveVersion(const char *name);
|
||||||
void *resolveKernel32(const char *name);
|
void *resolveKernel32(const char *name);
|
||||||
void *resolveUser32(const char *name);
|
void *resolveUser32(const char *name);
|
||||||
void *resolveAdvApi32(const char *name);
|
void *resolveAdvApi32(const char *name);
|
||||||
|
void *resolveLmgr11(uint16_t ordinal);
|
||||||
void *resolveStubByName(const char *dllName, const char *funcName);
|
void *resolveStubByName(const char *dllName, const char *funcName);
|
||||||
void *resolveStubByOrdinal(const char *dllName, uint16_t ordinal);
|
void *resolveStubByOrdinal(const char *dllName, uint16_t ordinal);
|
||||||
|
|
||||||
|
|
48
main.cpp
48
main.cpp
|
@ -106,6 +106,11 @@ struct TIB {
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
if (argc <= 1) {
|
||||||
|
printf("Usage: ./wibo program.exe ...\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Create TIB
|
// Create TIB
|
||||||
TIB tib;
|
TIB tib;
|
||||||
tib.tib = &tib;
|
tib.tib = &tib;
|
||||||
|
@ -125,13 +130,46 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a command line (todo, fill this with argv etc)
|
// Build a command line
|
||||||
wibo::commandLine = new char[1024];
|
std::string cmdLine;
|
||||||
strcpy(wibo::commandLine, "mwcceppc.exe");
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (i != 1) cmdLine += ' ';
|
||||||
|
std::string arg = argv[i];
|
||||||
|
bool needQuotes = arg.find_first_of("\\\" \t\n") != std::string::npos;
|
||||||
|
if (needQuotes)
|
||||||
|
cmdLine += '"';
|
||||||
|
int backslashes = 0;
|
||||||
|
for (const char *p = arg.c_str(); ; p++) {
|
||||||
|
char c = *p;
|
||||||
|
if (c == '\\') {
|
||||||
|
backslashes++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backslashes are doubled *before quotes*
|
||||||
|
for (int j = 0; j < backslashes; j++) {
|
||||||
|
cmdLine += '\\';
|
||||||
|
if (c == '\0' || c == '"')
|
||||||
|
cmdLine += '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '\0')
|
||||||
|
break;
|
||||||
|
if (c == '\"')
|
||||||
|
cmdLine += '\\';
|
||||||
|
cmdLine += c;
|
||||||
|
}
|
||||||
|
if (needQuotes)
|
||||||
|
cmdLine += '"';
|
||||||
|
}
|
||||||
|
cmdLine += '\0';
|
||||||
|
|
||||||
|
wibo::commandLine = cmdLine.data();
|
||||||
|
DEBUG_LOG("Command line: %s\n", wibo::commandLine);
|
||||||
|
|
||||||
wibo::Executable exec;
|
wibo::Executable exec;
|
||||||
|
|
||||||
FILE *f = fopen("mwcceppc.exe", "rb");
|
FILE *f = fopen(argv[1], "rb");
|
||||||
exec.loadPE(f);
|
exec.loadPE(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
@ -144,5 +182,5 @@ int main(int argc, char **argv) {
|
||||||
);
|
);
|
||||||
DEBUG_LOG("We came back\n");
|
DEBUG_LOG("We came back\n");
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue