├── Archiver.cs ├── DllExport.bat ├── DllExport_Configure.bat ├── DotNetLoader.cs ├── FodyWeavers.xml ├── Properties └── AssemblyInfo.cs ├── README.md ├── SharpPack.cs ├── SharpPack.csproj ├── SharpPack.sln └── packages.config /Archiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Security.Cryptography; 5 | using System.IO.Compression; 6 | using Ionic.Zip; 7 | class Archiver 8 | { 9 | 10 | 11 | public byte[] DecryptArchiveAndGetFile(string zipfile, string retrievefile, string password) 12 | { 13 | byte[] unpacked = null; 14 | MemoryStream unzippedEntryStream = new MemoryStream(); 15 | ZipFile zip = ZipFile.Read(zipfile); 16 | ZipEntry e = zip[retrievefile]; 17 | e.ExtractWithPassword(unzippedEntryStream, password); 18 | unpacked =unzippedEntryStream.ToArray(); 19 | return unpacked; 20 | } 21 | 22 | /* Legacy methods replaced by DotNetZip 23 | * 24 | * public byte[] ReadFully(Stream input) 25 | { 26 | byte[] buffer = new byte[16 * 1024]; 27 | using (MemoryStream ms = new MemoryStream()) 28 | { 29 | int read; 30 | while ((read = input.Read(buffer, 0, buffer.Length)) > 0) 31 | { 32 | ms.Write(buffer, 0, read); 33 | } 34 | return ms.ToArray(); 35 | } 36 | } 37 | 38 | public byte[] Decrypt(string inFileName, string password) 39 | { 40 | byte[] saltValueBytes = Encoding.ASCII.GetBytes("SharpMacro"); 41 | Rfc2898DeriveBytes passwordKey = new Rfc2898DeriveBytes(password, saltValueBytes); 42 | 43 | RijndaelManaged alg = new RijndaelManaged(); 44 | alg.Key = passwordKey.GetBytes(alg.KeySize / 8); 45 | alg.IV = passwordKey.GetBytes(alg.BlockSize / 8); 46 | 47 | ICryptoTransform decryptor = alg.CreateDecryptor(); 48 | FileStream inFile = new FileStream(inFileName, FileMode.Open, FileAccess.Read); 49 | CryptoStream decryptStream = new CryptoStream(inFile, decryptor, CryptoStreamMode.Read); 50 | byte[] fileData = new byte[inFile.Length]; 51 | decryptStream.Read(fileData, 0, (int)inFile.Length); 52 | 53 | decryptStream.Close(); 54 | inFile.Close(); 55 | 56 | return fileData; 57 | } 58 | 59 | public byte[] ReadFileFromZipFile(byte[] zip, string zipfile) 60 | { 61 | byte[] unpacked = null; 62 | try 63 | { 64 | Stream data = new MemoryStream(zip); 65 | Stream unzippedEntryStream; 66 | ZipArchive archive = new ZipArchive(data); 67 | 68 | foreach (ZipArchiveEntry entry in archive.Entries) 69 | { 70 | if (entry.FullName == zipfile) 71 | { 72 | unzippedEntryStream = entry.Open(); 73 | unpacked = ReadFully(unzippedEntryStream); 74 | } 75 | 76 | } 77 | 78 | } 79 | catch (Exception ex) 80 | { 81 | while (ex != null) 82 | { 83 | Console.WriteLine(ex.Message); 84 | ex = ex.InnerException; 85 | } 86 | } 87 | return unpacked; 88 | }*/ 89 | 90 | public byte[] ArchiveHelper(string encpath, string passwd, string getfile) 91 | { 92 | //byte[] decrypted = Decrypt(encpath, passwd); 93 | //byte[] unpacked = ReadFileFromZipFile(decrypted, getfile); 94 | byte[] unpacked = DecryptArchiveAndGetFile(encpath, getfile, passwd); 95 | 96 | return unpacked; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /DllExport.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: Copyright (c) 2016-2018 Denis Kuzmin [ entry.reg@gmail.com ] :: github.com/3F 3 | :: https://github.com/3F/DllExport 4 | :: --- 5 | :: Based on hMSBuild logic and includes GetNuTool core. 6 | :: https://github.com/3F/hMSBuild 7 | :: https://github.com/3F/GetNuTool 8 | setlocal enableDelayedExpansion 9 | set "aa=1.6.1" 10 | set "wAction=" 11 | set "ab=DllExport" 12 | set "ac=tools/net.r_eg.DllExport.Wizard.targets" 13 | set "ad=packages" 14 | set "ae=https://www.nuget.org/api/v2/package/" 15 | set "af=build_info.txt" 16 | set "wRootPath=%cd%" 17 | set wMgrArgs="%*" 18 | set /a ag=0 19 | set /a ah=0 20 | set "ai=" 21 | set "aj=" 22 | set "ak=" 23 | set "al=" 24 | set "am=" 25 | set "an=" 26 | set ao=0 27 | set ap=2 28 | set aq=3 29 | set "ar=%* " 30 | set "as=%~dpnx0" 31 | set at=%ar:"=% 32 | set au=%at% 33 | set au=%au:-help =% 34 | set au=%au:-h =% 35 | set au=%au:-? =% 36 | if not "%at%"=="%au%" goto bb 37 | goto bc 38 | :bb 39 | echo. 40 | @echo DllExport - v1.6.1.51910 [ e6c3d30 ] 41 | @echo Copyright (c) 2009-2015 Robert Giesecke 42 | @echo Copyright (c) 2016-2018 Denis Kuzmin [ entry.reg@gmail.com :: github.com/3F ] 43 | echo. 44 | echo Distributed under the MIT license 45 | @echo https://github.com/3F/DllExport 46 | echo Wizard - based on hMSBuild logic and includes GetNuTool core - https://github.com/3F 47 | echo. 48 | @echo. 49 | @echo Usage: DllExport [args to DllExport] [args to GetNuTool core] 50 | echo ------ 51 | echo. 52 | echo Arguments: 53 | echo ---------- 54 | echo -action {type} - Specified action for Wizard. Where {type}: 55 | echo * Configure - To configure DllExport for specific projects. 56 | echo * Update - To update pkg reference for already configured projects. 57 | echo * Restore - To restore configured DllExport. 58 | echo * Export - To export configured projects data. 59 | echo * Recover - To re-configure projects via predefined/exported data. 60 | echo * Unset - To unset all data from specified projects. 61 | echo * Upgrade - Aggregates an Update action with additions for upgrading. 62 | echo. 63 | echo -sln-dir {path} - Path to directory with .sln files to be processed. 64 | echo -sln-file {path} - Optional predefined .sln file to process via the restore operations etc. 65 | echo -metalib {path} - Relative path from PkgPath to DllExport meta library. 66 | echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core. 67 | echo -dxp-version {num} - Specific version of DllExport. Where {num}: 68 | echo * Versions: 1.6.0 ... 69 | echo * Keywords: 70 | echo `actual` to use unspecified local version or to get latest available; 71 | echo. 72 | echo -msb {path} - Full path to specific msbuild. 73 | echo -packages {path} - A common directory for packages. 74 | echo -server {url} - Url for searching remote packages. 75 | echo -proxy {cfg} - To use proxy. The format: [usr[:pwd]@]host[:port] 76 | echo -pkg-link {uri} - Direct link to package from the source via specified URI. 77 | echo -force - Aggressive behavior, e.g. like removing pkg when updating. 78 | echo -mgr-up - Updates this manager to version from '-dxp-version'. 79 | echo -wz-target {path} - Relative path to entrypoint wrapper of the main wizard. 80 | echo -pe-exp-list {module} - To list all available exports from PE32/PE32+ module. 81 | echo -eng - Try to use english language for all build messages. 82 | echo -GetNuTool {args} - Access to GetNuTool core. https://github.com/3F/GetNuTool 83 | echo -debug - To show additional information. 84 | echo -version - Displays version for which (together with) it was compiled. 85 | echo -build-info - Displays actual build information from selected DllExport. 86 | echo -help - Displays this help. Aliases: -help -h -? 87 | echo. 88 | echo. 89 | echo -------- 90 | echo Samples: 91 | echo -------- 92 | echo DllExport -action Configure 93 | echo DllExport -action Restore -sln-file "Conari.sln" 94 | echo DllExport -proxy guest:1234@10.0.2.15:7428 -action Configure 95 | echo. 96 | echo DllExport -build-info 97 | echo DllExport -restore -sln-dir -sln-dir ..\ -debug 98 | echo. 99 | echo DllExport -GetNuTool -unpack 100 | echo DllExport -GetNuTool /p:ngpackages="Conari;regXwild" 101 | echo DllExport -pe-exp-list bin\Debug\regXwild.dll 102 | exit /B 0 103 | :bc 104 | call :bd ar _is 105 | if [!_is!]==[1] ( 106 | if defined wAction goto be 107 | goto bb 108 | ) 109 | set /a av=1 & set aw=20 110 | :bf 111 | if "!ar:~0,8!"=="-action " ( 112 | call :bg %1 & shift 113 | set wAction=%2 114 | call :bg %2 & shift 115 | ) 116 | if "!ar:~0,9!"=="-sln-dir " ( 117 | call :bg %1 & shift 118 | set wSlnDir=%2 119 | call :bg %2 & shift 120 | ) 121 | if "!ar:~0,10!"=="-sln-file " ( 122 | call :bg %1 & shift 123 | set wSlnFile=%2 124 | call :bg %2 & shift 125 | ) 126 | if "!ar:~0,9!"=="-metalib " ( 127 | call :bg %1 & shift 128 | set wMetaLib=%2 129 | call :bg %2 & shift 130 | ) 131 | if "!ar:~0,12!"=="-dxp-target " ( 132 | call :bg %1 & shift 133 | set wDxpTarget=%2 134 | call :bg %2 & shift 135 | ) 136 | if "!ar:~0,13!"=="-dxp-version " ( 137 | call :bg %1 & shift 138 | set aa=%2 139 | call :bg %2 & shift 140 | ) 141 | if "!ar:~0,5!"=="-msb " ( 142 | call :bg %1 & shift 143 | set ai=%2 144 | call :bg %2 & shift 145 | ) 146 | if "!ar:~0,10!"=="-packages " ( 147 | call :bg %1 & shift 148 | set ad=%2 149 | set "ad=!ad:"=!" 150 | call :bg %2 & shift 151 | ) 152 | if "!ar:~0,8!"=="-server " ( 153 | call :bg %1 & shift 154 | set ae=%2 155 | call :bg %2 & shift 156 | ) 157 | if "!ar:~0,7!"=="-proxy " ( 158 | call :bg %1 & shift 159 | set an=%2 160 | call :bg %2 & shift 161 | ) 162 | if "!ar:~0,10!"=="-pkg-link " ( 163 | call :bg %1 & shift 164 | set aj=%2 165 | call :bg %2 & shift 166 | ) 167 | if "!ar:~0,7!"=="-force " ( 168 | call :bg %1 & shift 169 | set /a al=1 170 | ) 171 | if "!ar:~0,8!"=="-mgr-up " ( 172 | call :bg %1 & shift 173 | set /a am=1 174 | ) 175 | if "!ar:~0,11!"=="-wz-target " ( 176 | call :bg %1 & shift 177 | set ac=%2 178 | call :bg %2 & shift 179 | ) 180 | if "!ar:~0,13!"=="-pe-exp-list " ( 181 | call :bg %1 & shift 182 | set ak=%2 183 | call :bg %2 & shift 184 | ) 185 | if "!ar:~0,5!"=="-eng " ( 186 | call :bg %1 & shift 187 | chcp 437 >nul 188 | ) 189 | if "!ar:~0,11!"=="-GetNuTool " ( 190 | call :bg %1 & shift 191 | goto bh 192 | ) 193 | if "!ar:~0,7!"=="-debug " ( 194 | call :bg %1 & shift 195 | set /a ag=1 196 | ) 197 | if "!ar:~0,9!"=="-version " ( 198 | @echo v1.6.1.51910 [ e6c3d30 ] 199 | exit /B 0 200 | ) 201 | if "!ar:~0,12!"=="-build-info " ( 202 | call :bg %1 & shift 203 | set /a ah=1 204 | ) 205 | set /a "av+=1" 206 | if !av! LSS %aw% goto bf 207 | goto be 208 | :bg 209 | set ar=!!ar:%1 ^=!! 210 | call :bi ar 211 | set "ar=!ar! " 212 | exit /B 0 213 | :be 214 | call :bj "dxpName = '%ab%'" 215 | call :bj "dxpVersion = '!aa!'" 216 | if defined aa ( 217 | if "!aa!"=="actual" ( 218 | set "aa=" 219 | ) 220 | ) 221 | if z%wAction%==zUpgrade ( 222 | call :bj "Upgrade is on" 223 | set /a am=1 224 | set /a al=1 225 | ) 226 | call :bi ad 227 | set "ad=!ad!\\" 228 | set "ax=!ab!" 229 | set "wPkgPath=!ad!!ab!" 230 | if defined aa ( 231 | set "ax=!ax!/!aa!" 232 | set "wPkgPath=!wPkgPath!.!aa!" 233 | ) 234 | if defined al ( 235 | if exist "!wPkgPath!" ( 236 | call :bj "Removing old version '!wPkgPath!' before continue. '-force' key rule." 237 | rmdir /S/Q "!wPkgPath!" 238 | ) 239 | ) 240 | set ay="!wPkgPath!\\!ac!" 241 | call :bj "dxpTarget = '!ay!'" 242 | if not exist !ay! ( 243 | if exist "!wPkgPath!" ( 244 | call :bj "Wizard was not found. Trying to replace obsolete version '!wPkgPath!' ..." 245 | rmdir /S/Q "!wPkgPath!" 246 | ) 247 | call :bj "-pkg-link = '!aj!'" 248 | call :bj "-server = '!ae!'" 249 | if defined aj ( 250 | set ae=!aj! 251 | if "!wPkgPath::=!"=="!wPkgPath!" ( 252 | set "az=../" 253 | ) 254 | set "ax=:!az!!wPkgPath!" 255 | ) 256 | call :bj "_remoteUrl = '!ax!'" 257 | call :bj "ngpath = '!ad!'" 258 | if defined ai ( 259 | set a0=-msbuild !ai! 260 | ) 261 | set a1=!a0! /p:ngserver="!ae!" /p:ngpackages="!ax!" /p:proxycfg="!an!" 262 | if "!ag!"=="1" ( 263 | call :bk !a1! 264 | ) else ( 265 | call :bk !a1! >nul 266 | ) 267 | ) 268 | if defined ak ( 269 | !wPkgPath!\\tools\\PeViewer.exe -list -pemodule "!ak!" 270 | exit /B %ERRORLEVEL% 271 | ) 272 | if "!ah!"=="1" ( 273 | call :bj "buildInfo = '!wPkgPath!\\!af!'" 274 | if not exist "!wPkgPath!\\!af!" ( 275 | echo information about build is not available. 276 | exit /B %ap% 277 | ) 278 | type "!wPkgPath!\\!af!" 279 | exit /B 0 280 | ) 281 | if not exist !ay! ( 282 | echo Something went wrong. Try to use another keys. 283 | exit /B %ap% 284 | ) 285 | call :bj "-sln-dir = '!wSlnDir!'" 286 | call :bj "-sln-file = '!wSlnFile!'" 287 | call :bj "-metalib = '!wMetaLib!'" 288 | call :bj "-dxp-target = '!wDxpTarget!'" 289 | call :bj "wRootPath = !wRootPath!" 290 | call :bj "wAction = !wAction!" 291 | if defined ai ( 292 | set "ai=%ai:"=%" 293 | call :bj "Use specific MSBuild tools '!ai!'" 294 | set a2=!ai! 295 | goto bl 296 | ) 297 | call :bm 298 | if "!ERRORLEVEL!"=="0" goto bl 299 | echo MSBuild tools was not found. Try with `-msb` key. `-help` for details. 300 | exit /B %ap% 301 | :bl 302 | call :bd a2 _is 303 | if [!_is!]==[1] ( 304 | echo Something went wrong. Use `-debug` key for details. 305 | exit /B %ap% 306 | ) 307 | set a3="!a2!" 308 | call :bj "Target: '!a2!' !ay!" 309 | !a3! /nologo /v:m /m:4 !ay! 310 | if defined am ( 311 | (copy /B/Y "!wPkgPath!\\DllExport.bat" "%as%" > nul) & echo Manager has been updated. & exit /B 0 312 | ) 313 | exit /B 0 314 | :bm 315 | call :bj "trying via MSBuild tools from .NET Framework - .net 4.0, ..." 316 | for %%v in (4.0, 3.5, 2.0) do ( 317 | call :bn %%v Y & if [!Y!]==[1] exit /B 0 318 | ) 319 | call :bj "msbnetf: unfortunately we didn't find anything." 320 | exit /B %ap% 321 | :bn 322 | call :bj "checking of version: %1" 323 | for /F "usebackq tokens=2* skip=2" %%a in ( 324 | `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%1" /v MSBuildToolsPath 2^> nul` 325 | ) do if exist %%b ( 326 | call :bj "found: %%b" 327 | set a2=%%b 328 | call :bo 329 | set /a %2=1 330 | exit /B 0 331 | ) 332 | set /a %2=0 333 | exit /B 0 334 | :bh 335 | call :bj "direct access to GetNuTool..." 336 | call :bk !ar! 337 | exit /B 0 338 | :bo 339 | set a2=!a2!\MSBuild.exe 340 | exit /B 0 341 | :bj 342 | if "!ag!"=="1" ( 343 | set a4=%1 344 | set a4=!a4:~0,-1! 345 | set a4=!a4:~1! 346 | echo.[%TIME% ] !a4! 347 | ) 348 | exit /B 0 349 | :bi 350 | call :a6 %%%1%% 351 | set %1=%a5% 352 | exit /B 0 353 | :a6 354 | set "a5=%*" 355 | exit /B 0 356 | :bd 357 | setlocal enableDelayedExpansion 358 | set "a6=!%1!" 359 | if not defined a6 endlocal & set /a %2=1 & exit /B 0 360 | set a6=%a6: =% 361 | set "a6= %a6%" 362 | if [^%a6:~1,1%]==[] endlocal & set /a %2=1 & exit /B 0 363 | endlocal & set /a %2=0 364 | exit /B 0 365 | :bk 366 | setlocal disableDelayedExpansion 367 | @echo off 368 | :: GetNuTool - Executable version 369 | :: Copyright (c) 2015-2018 Denis Kuzmin [ entry.reg@gmail.com ] 370 | :: https://github.com/3F/GetNuTool 371 | set a7=gnt.core 372 | set a8="%temp%\%random%%random%%a7%" 373 | set "ar=%* " 374 | set a=%ar:~0,30% 375 | set a=%a:"=% 376 | if "%a:~0,8%"=="-unpack " goto bp 377 | if "%a:~0,9%"=="-msbuild " goto bq 378 | for %%v in (4.0, 14.0, 12.0, 3.5, 2.0) do ( 379 | for /F "usebackq tokens=2* skip=2" %%a in ( 380 | `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul` 381 | ) do if exist %%b ( 382 | set a9="%%b\MSBuild.exe" 383 | goto br 384 | ) 385 | ) 386 | echo MSBuild was not found, try: gnt -msbuild "fullpath" args 1>&2 387 | exit /B 2 388 | :bq 389 | call :bs %1 390 | shift 391 | set a9=%1 392 | call :bs %1 393 | :br 394 | call :bt 395 | %a9% %a8% /nologo /p:wpath="%~dp0/" /v:m %ar% 396 | del /Q/F %a8% 397 | exit /B 0 398 | :bs 399 | call set ar=%%ar:%1 ^=%% 400 | exit /B 0 401 | :bp 402 | set a8="%~dp0\%a7%" 403 | echo Generate minified version in %a8% ... 404 | :bt 405 | %a8% 406 | ^ 130 | -------------------------------------------------------------------------------- /SharpPack.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2036 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpPack", "SharpPack.csproj", "{56598F1C-6D88-4994-A392-AF337ABE5777}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Release|Any CPU = Release|Any CPU 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Debug|x64.ActiveCfg = Debug|x64 19 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Debug|x64.Build.0 = Debug|x64 20 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Release|x64.ActiveCfg = Release|x64 23 | {56598F1C-6D88-4994-A392-AF337ABE5777}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {3CE1B701-143E-4986-AC58-FFFE7052235C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | --------------------------------------------------------------------------------