Skip to content

Commit

Permalink
Implemented optional rebasing of system object in assembly:
Browse files Browse the repository at this point in the history
`netstandard` } `System.Runtime` } `mscorlib`

Closes #7
  • Loading branch information
3F committed Dec 8, 2019
1 parent dd79fc8 commit 7550c45
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
29 changes: 2 additions & 27 deletions src/dlls/mscorpe/ceefilegenwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,40 +1048,15 @@ void pathToCvtRes(LPCWSTR workdir, LPCWSTR path, LPCWSTR fname, __out PathString
}
}

HRESULT GetClrSystemDirectory(SString& pbuffer)
{
HRESULT hr = S_OK;


PathString pPath;
DWORD dwPath;

_ASSERTE (g_hThisInst);

dwPath = WszGetModuleFileName(g_hThisInst, pPath);
if(dwPath == 0)
{
hr = HRESULT_FROM_GetLastErrorNA();
return (hr);
}

return CopySystemDirectory(pPath, pbuffer);
}

#ifndef FEATURE_PAL
BOOL CeeFileGenWriter::RunProcess(LPCWSTR tempResObj, LPCWSTR pszFilename, DWORD* pdwExitCode, PEWriter &pewriter)
{
BOOL fSuccess = FALSE;

PROCESS_INFORMATION pi;

PathString wszSystemDir, cvtres;
if(FAILED(GetClrSystemDirectory(wszSystemDir))) {
pathToCvtRes(nullptr, m_pathToCvtRes, nullptr, cvtres);
}
else {
pathToCvtRes(wszSystemDir.GetUnicode(), m_pathToCvtRes, nullptr, cvtres);
}
PathString cvtres;
pathToCvtRes(nullptr, m_pathToCvtRes, nullptr, cvtres);

const WCHAR* wzMachine;
if(pewriter.isIA64())
Expand Down
2 changes: 2 additions & 0 deletions src/ilasm/assem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Assembler::Assembler()

m_pbsMD = NULL;

m_sysObjRebase = false;

m_pOutputBuffer = new BYTE[OUTPUT_BUFFER_SIZE];

m_pCurOutputPos = m_pOutputBuffer;
Expand Down
28 changes: 28 additions & 0 deletions src/ilasm/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ mdToken Assembler::GetBaseAsmRef()
return GetAsmRef(coreLibAsm->szAlias ? coreLibAsm->szAlias : coreLibAsm->szName);
}

return (m_sysObjRebase)? GetBaseAsmRefClr() : GetBaseAsmRefRt();
}

mdToken Assembler::GetBaseAsmRefRt()
{
AsmManAssembly* sysRuntime = m_pManifest->GetAsmRefByAsmName("System.Runtime");
if(sysRuntime != NULL)
{
Expand All @@ -305,6 +310,29 @@ mdToken Assembler::GetBaseAsmRef()
return GetAsmRef("mscorlib");
}

mdToken Assembler::GetBaseAsmRefClr()
{
AsmManAssembly* mscorlibAsm = m_pManifest->GetAsmRefByAsmName("mscorlib");
if(mscorlibAsm != NULL)
{
return GetAsmRef(mscorlibAsm->szAlias ? mscorlibAsm->szAlias : mscorlibAsm->szName);
}

AsmManAssembly* sysRuntime = m_pManifest->GetAsmRefByAsmName("System.Runtime");
if(sysRuntime != NULL)
{
return GetAsmRef(sysRuntime->szAlias ? sysRuntime->szAlias : sysRuntime->szName);
}

AsmManAssembly* netstandardAsm = m_pManifest->GetAsmRefByAsmName("netstandard");
if (netstandardAsm != NULL)
{
return GetAsmRef(netstandardAsm->szAlias ? netstandardAsm->szAlias : netstandardAsm->szName);
}

return GetAsmRef("mscorlib");
}

mdToken Assembler::GetInterfaceImpl(mdToken tsClass, mdToken tsInterface)
{
mdToken result = mdTokenNil;
Expand Down
4 changes: 4 additions & 0 deletions src/ilasm/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ class Assembler {

BinStr* m_pbsMD;

bool m_sysObjRebase;

Instr m_Instr[INSTR_POOL_SIZE]; // 16
inline Instr* GetInstr()
{
Expand Down Expand Up @@ -795,6 +797,8 @@ class Assembler {
mdToken ResolveClassRef(mdToken tkResScope, __in __nullterminated const char *pszClassName, Class** ppClass);
mdToken ResolveTypeSpec(BinStr* typeSpec);
mdToken GetBaseAsmRef();
mdToken GetBaseAsmRefRt();
mdToken GetBaseAsmRefClr();
mdToken GetAsmRef(__in __nullterminated const char* szName);
mdToken GetModRef(__in __nullterminated char* szName);
mdToken GetInterfaceImpl(mdToken tsClass, mdToken tsInterface);
Expand Down
8 changes: 7 additions & 1 deletion src/ilasm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
// printf("\n/ERROR Try to create .exe or .dll file despite errors reported");
// printf("\n Warning! Results are unpredictable, use this option at your own risk!");
printf("\n/CVRES=<path_to_file> Set path to cvtres tool: /CVR=cvtres.exe /CVR=tool\\cvtres.cmd /CVR=D:\\tool\\");
printf("\n/REBASE Try to rebase system object: `netstandard` > `System.Runtime` > `mscorlib`");
printf("\n ! This option at your own risk: https://github.com/3F/DllExport/issues/125");
printf("\n/OUTPUT=<targetfile> Compile to file with specified name \n\t\t\t(user must provide extension, if any)");
printf("\n/KEY=<keyfile> Compile with strong signature \n\t\t\t(<keyfile> contains private key)");
printf("\n/KEY=@<keysource> Compile with strong signature \n\t\t\t(<keysource> is the private key source name)");
Expand Down Expand Up @@ -411,13 +413,17 @@ extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
}
else if (!_stricmp(szOpt, "CVR"))
{
// TODO: ^v omg, how about common handler o_O
// TODO: ^v omg, how about a common handler o_O
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
if(wcslen(pStr) == 0) goto InvalidOption; //if no file name
wzPathToCvtRes = pStr;
}
else if (!_stricmp(szOpt, "REB"))
{
pAsm->m_sysObjRebase = true;
}
else if (!_stricmp(szOpt, "OUT"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
Expand Down

0 comments on commit 7550c45

Please sign in to comment.