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
|
||||
|
||||
CXXFLAGS = -Wall -g -m32 -std=c++20 -lstdc++
|
||||
CXXFLAGS = -Wall -g -m32 -std=c++20 -lstdc++ -MD
|
||||
|
||||
BUILD_DIR := build
|
||||
CPP_FILES := $(wildcard *.cpp)
|
||||
|
|
5
common.h
5
common.h
|
@ -6,15 +6,20 @@
|
|||
#include <assert.h>
|
||||
|
||||
#define WIN_FUNC __attribute__((stdcall))
|
||||
#define DEBUG_LOG(...) /* nothing */
|
||||
// #define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)
|
||||
|
||||
namespace wibo {
|
||||
extern uint32_t lastError;
|
||||
extern char *commandLine;
|
||||
|
||||
void debug_log(const char *fmt, ...);
|
||||
|
||||
void *resolveVersion(const char *name);
|
||||
void *resolveKernel32(const char *name);
|
||||
void *resolveUser32(const char *name);
|
||||
void *resolveAdvApi32(const char *name);
|
||||
void *resolveLmgr11(uint16_t ordinal);
|
||||
void *resolveStubByName(const char *dllName, const char *funcName);
|
||||
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) {
|
||||
if (argc <= 1) {
|
||||
printf("Usage: ./wibo program.exe ...\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create TIB
|
||||
TIB tib;
|
||||
tib.tib = &tib;
|
||||
|
@ -125,13 +130,46 @@ int main(int argc, char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Build a command line (todo, fill this with argv etc)
|
||||
wibo::commandLine = new char[1024];
|
||||
strcpy(wibo::commandLine, "mwcceppc.exe");
|
||||
// Build a command line
|
||||
std::string cmdLine;
|
||||
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;
|
||||
|
||||
FILE *f = fopen("mwcceppc.exe", "rb");
|
||||
FILE *f = fopen(argv[1], "rb");
|
||||
exec.loadPE(f);
|
||||
fclose(f);
|
||||
|
||||
|
@ -144,5 +182,5 @@ int main(int argc, char **argv) {
|
|||
);
|
||||
DEBUG_LOG("We came back\n");
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue