Skip to content

Commit

Permalink
Merge branch 'gcc'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed Sep 25, 2015
2 parents 2b2f4e1 + f7a1003 commit 315a6c1
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 383 deletions.
26 changes: 19 additions & 7 deletions win/build.bat
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
@setlocal
@set CO=/W3 /nologo /O2 /c /Fo:
@set LO=/nologo /Fe:
@set DO=/nologo /dll
@set CO=/DNTDDI_VERSION=0x60000000 /D_WIN32_WINNT=0x600 /MT /EHs-c- /W3 /nologo /O2 /c /Fo:
@set LO=/SUBSYSTEM:console /nologo ntdll.lib kernel32.lib libvcruntime.lib
@set DO=/nologo /dll ntdll.lib shell32.lib
@setlocal
call "%VS140COMNTOOLS%..\..\vc\vcvarsall.bat" x64
cl %CO% dbg.obj dbg.c
cl %CO% inject.obj inject.c
cl %CO% patch.obj patch.c
cl %CO% hooks.obj hooks.c
cl %CO% emit.obj emit.c
cl %CO% handle.obj handle.c
cl %CO% utf8.obj utf8.c
cl %CO% fsatrace.obj fsatrace.c
cl %LO% fsatrace.exe fsatrace.obj inject.obj
link %LO% /out:fsatrace.exe fsatrace.obj dbg.obj inject.obj shell32.lib
cl %CO% fsatrace64.obj fsatracedll.c
link %DO% /out:fsatrace64.dll fsatrace64.obj inject.obj ntdll.lib
link %DO% /out:fsatrace64.dll fsatrace64.obj inject.obj patch.obj hooks.obj emit.obj handle.obj utf8.obj
@endlocal
@setlocal
call "%VS140COMNTOOLS%..\..\vc\vcvarsall.bat" x86
cl %CO% dbg.obj dbg.c
cl %CO% inject.obj inject.c
cl %CO% patch.obj patch.c
cl %CO% hooks.obj hooks.c
cl %CO% emit.obj emit.c
cl %CO% handle.obj handle.c
cl %CO% utf8.obj utf8.c
cl %CO% fsatracehelper.obj fsatracehelper.c
cl %LO% fsatracehelper.exe fsatracehelper.obj
link %LO% /out:fsatracehelper.exe fsatracehelper.obj
cl %CO% fsatrace32.obj fsatracedll.c
link %DO% /out:fsatrace32.dll fsatrace32.obj inject.obj ntdll.lib
link %DO% /out:fsatrace32.dll fsatrace32.obj inject.obj patch.obj hooks.obj emit.obj handle.obj utf8.obj
@endlocal
@endlocal

39 changes: 23 additions & 16 deletions win/fsatrace.c
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include "dbg.h"
#include "inject.h"
#include "fsatrace.h"

int main(int argc, char **argv) {
STARTUPINFOW si;
PROCESS_INFORMATION pi;
FILE *of;
DWORD rc;
HANDLE mf;
char *buf;
char *out;
LPWSTR cmd;
if (argc < 4 || strcmp(argv[2], "--")) {
fprintf(stderr, "Usage: %s <output> -- <cmdline>\n", argv[0]);
return EXIT_FAILURE;
}
if (argc < 4 || strcmp(argv[2], "--"))
fatal("Usage: %s <output> -- <cmdline>", argv[0]);
out = argv[1];
mf = CreateFileMappingA(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE,
0, LOGSZ, out);
SetEnvironmentVariableA(ENVOUT, out);
buf = MapViewOfFile(mf, FILE_MAP_ALL_ACCESS, 0, 0, LOGSZ);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
cmd = GetCommandLineW();
cmd = wcsstr(GetCommandLineW(), L"-- ");
CreateProcessW(0, cmd+3, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &si, &pi);
inject(pi.hProcess);
if (!CreateProcessW(0, cmd+3, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &si, &pi))
fatal("unable to create process");
injectProcess(pi.hProcess);
ResumeThread(pi.hThread);
WaitForSingleObject(pi.hThread, INFINITE);
GetExitCodeProcess(pi.hProcess, &rc);
CloseHandle(pi.hProcess);
if (!rc) {
if (0 == strcmp(out, "-"))
of = stdout;
else
fopen_s(&of, out, "a+");
fprintf(of, "%s", buf + sizeof(LONG));
if (of != stdout)
fclose(of);
HANDLE of;
int con = 0 == strcmp(out, "-");
if (con)
of = GetStdHandle(STD_OUTPUT_HANDLE);
else
of = CreateFileA(out,
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
WriteFile(of, buf + 4, *(DWORD*)buf, 0, 0);
if (!con)
CloseHandle(of);
}
UnmapViewOfFile(buf);
CloseHandle(mf);
Expand Down
Loading

0 comments on commit 315a6c1

Please sign in to comment.