Skip to content

Commit 7a0bc2e

Browse files
authored
FIRST NATIVE SUPPORT :)
Added C and C++ languages
1 parent 49b707e commit 7a0bc2e

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

BinariesSorter.vb

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
Imports System.Diagnostics.Eventing.Reader
66
Imports System.IO
7+
Imports System.Security.Cryptography
78
Imports System.Text
89

910
Module Module1
@@ -32,6 +33,9 @@ Module Module1
3233
If Not File1 = Process.GetCurrentProcess().MainModule.FileName Then
3334
Dim ExeData = File.ReadAllBytes(File1)
3435
Try
36+
37+
38+
3539
If IsBinaryEXE(ExeData) Then
3640
Counter += 1
3741
Dim FileName = Path.GetFileName(File1)
@@ -45,8 +49,9 @@ Module Module1
4549
End If
4650
ProcessLog(Prefix, FileName, ".NET", IIf(NET_Info(1) Is "VB_NET", "VB NET", "C# or IL"), True, NET_Info(2))
4751
Else
48-
File.Copy(File1, $"exec-sorted\{FileName}")
49-
ProcessLog(Prefix, FileName, "NATIVE", "??", False, "BIN")
52+
Dim NativeInfo = GuessNativeRuntime(ExeData)
53+
File.Copy(File1, $"exec-sorted\{IIf(NativeInfo IsNot "??", NativeInfo, "Unknown")}_{FileName}")
54+
ProcessLog(Prefix, FileName, "NATIVE", NativeInfo, False, NET_Info(2))
5055
End If
5156
End If
5257
Catch Exc As Exception : End Try
@@ -78,15 +83,15 @@ Module Module1
7883
End Sub
7984
Function IsBinaryEXE(ExeData)
8085
Dim InputData = Encoding.UTF8.GetString(ExeData).ToLower()
81-
Dim TextSigns = ".dll,pe,�!�l"
86+
Dim TextSigns = ".dll,pe" ' OLD "�!�l"
8287
For Each Sign In TextSigns.Split(","c)
8388
If Not InputData.Contains(Sign) Then
8489
Return False
8590
End If
8691
Next
8792

88-
If IndexOf(ExeData, ByteStr("{NUL}")) Then
89-
If InputData.Length > 2 Then
93+
If IndexOf(ExeData, ByteStr("{NUL}{NUL}")) Then
94+
If InputData.Length > 170 Then
9095
If InputData.Substring(0, 2) = "mz" Then
9196
Return True
9297
End If
@@ -102,16 +107,17 @@ Module Module1
102107

103108
For Each Sign In TextSigns.Split(","c)
104109
If Not InputData.Contains(Sign) Then
105-
Return {False, "NATIVE"}
110+
Return {False, "NATIVE", FileProjectType}
106111
End If
107112
Next
108113

109114
'_CorExeMain - EXE; _CorDllMain - DLL
110-
If IndexOf(ExeData, ByteStr("{NUL}mscoree")) OrElse
111-
IndexOf(ExeData, ByteStr("{NUL}mscorlib")) Then
115+
Dim BinToLower = ToLowerInBinary(ExeData)
116+
If IndexOf(BinToLower, ByteStr("{NUL}mscoree.dll")) OrElse
117+
IndexOf(BinToLower, ByteStr("{NUL}mscorlib.dll")) Then
112118

113-
If IndexOf(ExeData, ByteStr("{NUL}_CorExe")) Then FileProjectType = "EXE" ' .NET exe
114119
If IndexOf(ExeData, ByteStr("{NUL}_CorDllMain{NUL}")) Then FileProjectType = "DLL" ' .NET dll
120+
If IndexOf(ExeData, ByteStr("{NUL}_CorExe")) Then FileProjectType = "EXE" ' .NET exe
115121

116122
If Not FileProjectType = "BIN" Then
117123
If IndexOf(ExeData, ByteStr("{NUL}Microsoft.VisualBasic{NUL}")) AndAlso
@@ -125,6 +131,35 @@ Module Module1
125131
Return {False, "NATIVE", FileProjectType}
126132
End Function
127133

134+
Function ToLowerInBinary(ExeData) ' Change registry of all chars in Byte() to lower
135+
Dim ChangedData = ExeData
136+
For Each CurStr In "QWERTYUIOPASDFGHJKLZXCVBNM"
137+
ChangedData = ReplaceBytes(ChangedData, ByteStr(CurStr.ToString), ByteStr(CurStr.ToString.ToLower))
138+
Next
139+
Return ChangedData
140+
End Function
141+
Public Detects = {"msvcrt.dll=C++", ' Microsoft C++ Runtime
142+
"libgcj-13.dll=C++", ' GNU GCC (C++)
143+
"crtdll.dll=C", ' Microsoft C Runtime
144+
"upx0{NUL}{NUL}=UPX-Packed"} ' UPX Packer
145+
146+
Function GuessNativeRuntime(ExeData)
147+
Try
148+
Dim AssemblyData = ToLowerInBinary(ExeData)
149+
For Each SearchForSigns In Detects
150+
Dim SignAndRuntime = SearchForSigns.Split("=")
151+
Dim Sign = SignAndRuntime(0)
152+
Dim Runtime = SignAndRuntime(1)
153+
If IndexOf(AssemblyData, ByteStr($"{{NUL}}{Sign}{{NUL}}")) Then
154+
Return Runtime
155+
End If
156+
Next
157+
Return "??"
158+
Catch ex As Exception
159+
MsgBox(ex.Message)
160+
End Try
161+
162+
End Function
128163

129164
Function ByteStr(InputStr As String) As Byte() ' {NUL} ==> \d{00}
130165
Return ReplaceBytes(Encoding.ASCII.GetBytes(InputStr), Encoding.ASCII.GetBytes("{NUL}"), {CByte(0)})

0 commit comments

Comments
 (0)