Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ unreleased Version 0.3.38
* updated to cv2pdb 0.28
- support mspdb120.dll from VS 2013
- bugzilla 11537: improved search for appropriate mspdb*.dll if multiple version of VS installed
- fix support for DWARF conversion for gcc 4.8
* updated to mago 0.9
- bugzilla 11547: remove error message when stopping debugging
- bugzilla 11437: debug info rejected if records don't have "recommended" order
Expand All @@ -613,4 +614,10 @@ unreleased Version 0.3.38
* Windows SDK 8.0/8.1 detection
* fix bad "\n" in default x64 library search path
* x64 executable and library search path not correctly saved for next VS start
* improve project automation to mute NuGet (still empty project pretended)
* improve project automation to mute NuGet (still empty project pretended)

* add source control support for git in VS2013 (and maybe others)
* fix DnD of project items in VS2013
* disguise functionality of pipedmd.exe and filemonitor.dll to let it pass
most anti-virus checks
* added option to select the C runtime library when compiling for x64
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Project:
- custom command: quotes in dependencies not supported
- VS2013: property pages don't follow resize
- custom command: writes build batch to souce folder
- does not work with VS2013 git integration

Language service:
-----------------
Expand Down Expand Up @@ -148,3 +149,4 @@ Unsorted
- save file before "Compile & run"
- coverage line highlight after "Compile & run" doesn't update
- better keeping track of line changes

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#define VERSION_MINOR 3
#define VERSION_REVISION 38
#define VERSION_BETA -beta
#define VERSION_BUILD 3
#define VERSION_BUILD 4
5 changes: 3 additions & 2 deletions build/build.visualdproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@
<useStdLibPath>1</useStdLibPath>
<additionalOptions />
<preBuildCommand />
<postBuildCommand>echo Success &gt;$(TargetPath)</postBuildCommand>
<postBuildCommand>echo Success &gt;$(TargetPath)
echo. &gt;$(TargetDir)\build.dep</postBuildCommand>
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
</Config>
<Folder name="build">
Expand All @@ -194,7 +195,7 @@ if errorlevel 1 goto reportError
call $(InputPath) &quot;$(OutDir)\tlb2idl.exe&quot; &quot;$(OutDir)\dte_idl.success&quot;" outfile="$(OutDir)\dte_idl.success" />
<File tool="Custom" path="..\tools\filemonitor.d" customcmd="dmd -map $(OutDir)\$(InputName).map -of$(OutDir)\$(InputName).dll -defaultlib=user32.lib -L/ENTRY:_DllMain@12 $(InputPath)" outfile="$(OutDir)\$(InputName).dll" />
<File tool="Custom" path="..\tools\largeadr.d" customcmd="dmd -map $(OutDir)\$(InputName).map -of$(OutDir)\$(InputName).exe $(InputPath)" outfile="$(OutDir)\$(InputName).exe" />
<File tool="Custom" path="..\tools\pipedmd.d" customcmd="dmd -map $(OutDir)\$(InputName).map -of$(OutDir)\$(InputName).exe $(InputPath)" outfile="$(OutDir)\$(InputName).exe" />
<File tool="Custom" path="..\tools\pipedmd.d" dependencies="..\tools\nostacktrace.d" customcmd="dmd -map $(OutDir)\$(InputName).map -of$(OutDir)\$(InputName).exe $(InputPath) ..\tools\nostacktrace.d" outfile="$(OutDir)\$(InputName).exe" />
<File tool="Custom" path="sdk.bat" dependencies="$(OutDir)\dte_idl.success $(OutDir)\vsi2d.exe" customcmd="call $(VSINSTALLDIR)\Common7\Tools\vsvars32.bat
if errorlevel 1 goto reportError
call $(InputPath) &quot;$(OutDir)\vsi2d.exe&quot; &quot;$(OutDir)\sdk.success&quot;" outfile="$(OutDir)\sdk.success" />
Expand Down
88 changes: 49 additions & 39 deletions tools/filemonitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,67 @@ BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
g_hInst = hInstance;
if(ulReason == DLL_PROCESS_ATTACH)
{
RedirectCreateFileA();
RedirectCreateFileW();
if (dumpFile[0]) // only execute if it was injected by pipedmd
{
//origWriteFile = getWriteFileFunc();
RedirectCreateFileA();
RedirectCreateFileW();
}
}
return true;
}

alias typeof(&CreateFileA) fnCreateFileA;
alias typeof(&CreateFileW) fnCreateFileW;
alias typeof(&WriteFile) fnWriteFile;
__gshared fnCreateFileA origCreateFileA;
__gshared fnCreateFileW origCreateFileW;
__gshared fnWriteFile origWriteFile;

__gshared fnCreateFileA myCF = &MyCreateFileA;

alias typeof(&VirtualProtect) fnVirtualProtect;

void RedirectCreateFileA()
fnVirtualProtect getVirtualProtectFunc()
{
version(msgbox) MessageBoxA(null, "RedirectCreateFileA", "filemonitor", MB_OK);
ubyte* jmpAdr = cast(ubyte*)&CreateFileA;
auto impTableEntry = cast(fnCreateFileA*) (*cast(void**)(jmpAdr + 2));
origCreateFileA = *impTableEntry;

DWORD oldProtect, newProtect;
version(all)
{
VirtualProtect(impTableEntry, (*impTableEntry).sizeof, PAGE_READWRITE, &oldProtect);
*impTableEntry = &MyCreateFileA;
VirtualProtect(impTableEntry, (*impTableEntry).sizeof, oldProtect, &newProtect);
HANDLE krnl = GetModuleHandleA("kernel32.dll");
return cast(fnVirtualProtect) GetProcAddress(krnl, "VirtualProtect");
}
else
{
char[16] func;
char*p = func.ptr;
mixin({
string s;
foreach(c; [ 'V','i','r','t','u','a','l','P','r','o','t','e','c','t' ])
{ s ~= "*p++ = '"; s ~= c; s ~= "';"; }
return s;
}());
*p = 0;
return &VirtualProtect;
}
}

fnWriteFile getWriteFileFunc()
{
version(all)
{
HANDLE krnl = GetModuleHandleA("kernel32.dll");
if(fnVirtualProtect fn = cast(fnVirtualProtect) GetProcAddress(krnl, func.ptr))
{
DWORD oldProtect, newProtect;
fn(impTableEntry, (*impTableEntry).sizeof, PAGE_READWRITE, &oldProtect);
*impTableEntry = &MyCreateFileA;
fn(impTableEntry, (*impTableEntry).sizeof, oldProtect, &newProtect);
}
return cast(fnWriteFile) GetProcAddress(krnl, "WriteFile");
}
else
{
return &WriteFile;
}
}

void RedirectCreateFileA()
{
version(msgbox) MessageBoxA(null, "RedirectCreateFileA", "filemonitor", MB_OK);
ubyte* jmpAdr = cast(ubyte*)&CreateFileA;
auto impTableEntry = cast(fnCreateFileA*) (*cast(void**)(jmpAdr + 2));
origCreateFileA = *impTableEntry;

DWORD oldProtect, newProtect;
auto pfnVirtualProtect = getVirtualProtectFunc();
pfnVirtualProtect(impTableEntry, (*impTableEntry).sizeof, PAGE_READWRITE, &oldProtect);
*impTableEntry = &MyCreateFileA;
pfnVirtualProtect(impTableEntry, (*impTableEntry).sizeof, oldProtect, &newProtect);
}

void RedirectCreateFileW()
{
version(msgbox) MessageBoxA(null, "RedirectCreateFileW", "filemonitor", MB_OK);
Expand All @@ -109,12 +120,10 @@ void RedirectCreateFileW()
origCreateFileW = *impTableEntry;

DWORD oldProtect, newProtect;
version(all)
{
VirtualProtect(impTableEntry, (*impTableEntry).sizeof, PAGE_READWRITE, &oldProtect);
*impTableEntry = &MyCreateFileW;
VirtualProtect(impTableEntry, (*impTableEntry).sizeof, oldProtect, &newProtect);
}
auto pfnVirtualProtect = getVirtualProtectFunc();
pfnVirtualProtect(impTableEntry, (*impTableEntry).sizeof, PAGE_READWRITE, &oldProtect);
*impTableEntry = &MyCreateFileW;
pfnVirtualProtect(impTableEntry, (*impTableEntry).sizeof, oldProtect, &newProtect);
}

extern(Windows) HANDLE
Expand Down Expand Up @@ -146,8 +155,8 @@ MyCreateFileA(
WaitForSingleObject(hndMutex, INFINITE);

size_t length = mystrlen(lpFileName);
WriteFile(hndDumpFile, lpFileName, length, &length, null);
WriteFile(hndDumpFile, "\n".ptr, 1, &length, null);
origWriteFile(hndDumpFile, lpFileName, length, &length, null);
origWriteFile(hndDumpFile, "\n".ptr, 1, &length, null);

if(hndMutex != INVALID_HANDLE_VALUE)
ReleaseMutex(hndMutex);
Expand Down Expand Up @@ -185,7 +194,7 @@ MyCreateFileW(
ushort bom = 0xFEFF;
size_t written;
if(hndDumpFile != INVALID_HANDLE_VALUE)
WriteFile(hndDumpFile, &bom, 2, &written, null);
origWriteFile(hndDumpFile, &bom, 2, &written, null);

if(hndMutex != INVALID_HANDLE_VALUE)
ReleaseMutex(hndMutex);
Expand All @@ -197,8 +206,8 @@ MyCreateFileW(
WaitForSingleObject(hndMutex, INFINITE);

size_t length = mystrlen(lpFileName);
WriteFile(hndDumpFile, lpFileName, 2*length, &length, null);
WriteFile(hndDumpFile, "\n".ptr, 2, &length, null);
origWriteFile(hndDumpFile, lpFileName, 2*length, &length, null);
origWriteFile(hndDumpFile, "\n".ptr, 2, &length, null);

if(hndMutex != INVALID_HANDLE_VALUE)
ReleaseMutex(hndMutex);
Expand Down Expand Up @@ -239,6 +248,7 @@ size_t mystrlen(const(wchar)* str) nothrow
///////// shut up compiler generated GC info failing to link
extern(C)
{
__gshared int D10TypeInfo_i6__initZ;
__gshared int D10TypeInfo_v6__initZ;
__gshared int D16TypeInfo_Pointer6__vtblZ;
__gshared int D17TypeInfo_Function6__vtblZ;
Expand Down
36 changes: 36 additions & 0 deletions tools/nostacktrace.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// replacement module to disable stack traces and avoid the default stacktrace code
// to be linked in

module core.sys.windows.stacktrace;

import core.sys.windows.windows;

class StackTrace : Throwable.TraceInfo
{
public:
this(size_t skip, CONTEXT* context)
{
}
int opApply(scope int delegate(ref const(char[])) dg) const
{
return 0;
}
int opApply(scope int delegate(ref size_t, ref const(char[])) dg) const
{
return 0;
}
override string toString() const
{
return null;
}
static ulong[] trace(size_t skip = 0, CONTEXT* context = null)
{
return null;
}
static char[][] resolve(const(ulong)[] addresses)
{
return [];
}
private:
ulong[] m_trace;
}
20 changes: 17 additions & 3 deletions tools/pipedmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,13 @@ void InjectDLL(HANDLE hProcess, string depsfile)
// copy path to other process
auto wdll = to!wstring(dll) ~ cast(wchar)0;
auto wdllRemote = VirtualAllocEx(hProcess, null, wdll.length * 2, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess, wdllRemote, wdll.ptr, wdll.length * 2, null);
auto procWrite = getWriteProcFunc();
procWrite(hProcess, wdllRemote, wdll.ptr, wdll.length * 2, null);

// load dll into other process, assuming LoadLibraryW is at the same address in all processes
HMODULE mod = GetModuleHandleA("Kernel32");
auto proc = GetProcAddress(mod, "LoadLibraryW");
hThread = CreateRemoteThread(hProcess, null, 0, cast(LPTHREAD_START_ROUTINE)proc, wdllRemote, 0, null);
hThread = getCreateRemoteThreadFunc()(hProcess, null, 0, cast(LPTHREAD_START_ROUTINE)proc, wdllRemote, 0, null);
WaitForSingleObject(hThread, INFINITE);

// Get handle of the loaded module
Expand All @@ -472,6 +473,19 @@ void InjectDLL(HANDLE hProcess, string depsfile)

void* pDumpFile = cast(char*)hRemoteModule + 0x3000; // offset taken from map file
auto szDepsFile = toMBSz(depsfile);
WriteProcessMemory(hProcess, pDumpFile, szDepsFile, strlen(szDepsFile) + 1, null);
procWrite(hProcess, pDumpFile, szDepsFile, strlen(szDepsFile) + 1, null);
}

typeof(WriteProcessMemory)* getWriteProcFunc ()
{
HMODULE mod = GetModuleHandleA("Kernel32");
auto proc = GetProcAddress(mod, "WriteProcessMemory");
return cast(typeof(WriteProcessMemory)*)proc;
}

typeof(CreateRemoteThread)* getCreateRemoteThreadFunc ()
{
HMODULE mod = GetModuleHandleA("Kernel32");
auto proc = GetProcAddress(mod, "CreateRemoteThread");
return cast(typeof(CreateRemoteThread)*)proc;
}
7 changes: 6 additions & 1 deletion vdc/abothe/VDServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public void AddPackage(string packageName)
addExpansion(packageName, "PKG", "");
}

public void AddCodeGeneratingNodeItem(INode node, string codeToGenerate)
{
addExpansion(codeToGenerate, "OVR", codeToGenerate);
}

void addExpansion(string name, string type, string desc)
{
if(!string.IsNullOrEmpty(name))
Expand Down Expand Up @@ -277,7 +282,7 @@ public static string GeneratePrototype(DMethod dm, bool isTemplateParamInsight=f
foreach (var attr in dm.Attributes)
{
var m = attr as Modifier;
if (m != null && DTokens.StorageClass[m.Token])
if (m != null && DTokens.IsStorageClass(m.Token))
{
sb.Append(DTokens.GetTokenString(m.Token));
sb.Append(" ");
Expand Down
Loading