@@ -42,6 +42,7 @@ public class SystemInfoCollector {
4242 // Permanent caches - CPU info and memory never change at runtime
4343 private static String cachedCpuName ;
4444 private static long cachedPhysicalMemory = -1 ;
45+ private static String cachedDeviceModel ;
4546
4647 // SHA-256 checksums for chip rules files (update when file content changes)
4748 private static final String PHONE_CHIPS_SHA = "428b078c2ba8395b84f2dd2a7ed964ee80feef685ecc6335e9679606ec63162a" ;
@@ -79,7 +80,8 @@ public static SystemInfo collect() {
7980 javaVersion ,
8081 jvmName ,
8182 minecraftVersion ,
82- modVersion
83+ modVersion ,
84+ getDeviceModel ()
8385 );
8486
8587 return cachedInfo ;
@@ -118,14 +120,14 @@ private static String getCpuName() {
118120
119121 private static String getWindowsCpuName () {
120122 String [] commands = {
121- "powershell -NoProfile -Command Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name" ,
122- "powershell -NoProfile -Command (Get-WmiObject Win32_Processor).Name"
123+ "powershell -NoProfile -Command \" Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name\" " ,
124+ "powershell -NoProfile -Command \" (Get-WmiObject Win32_Processor).Name\" "
123125 };
124126
125127 for (String command : commands ) {
126128 String result = runCommand (command );
127129 if (result != null && !result .trim ().isEmpty ()) {
128- return result .trim ();
130+ return result .lines (). findFirst (). orElse ( result ). trim ();
129131 }
130132 }
131133
@@ -136,23 +138,87 @@ private static String getLinuxCpuName() {
136138 String output = readFile ("/proc/cpuinfo" );
137139 if (output == null ) return "Unknown" ;
138140
139- String [] prefixes = { "model name" , "Model name" , "Processor" , "Hardware" , "model" , "Model" };
140- for ( String prefix : prefixes ) {
141- for ( String line : output . split ( " \n " )) {
142- if ( line .startsWith (prefix )) {
143- int colon = line .indexOf ( ':' );
144- if ( colon > 0 ) {
145- return line . substring ( colon + 1 ). trim ();
146- }
147- }
141+ for ( String line : output . split ( " \n " )) {
142+ line = line . trim ();
143+
144+ if ( line . startsWith ( "model name" ) || line .startsWith ("Model name" )) {
145+ return line .split ( ":" , 2 )[ 1 ]. trim ( );
146+ }
147+
148+ if ( line . startsWith ( "Hardware" ) || line . startsWith ( "Processor" )) {
149+ return line . split ( ":" , 2 )[ 1 ]. trim ();
148150 }
149151 }
150- return "Unknown" ;
152+
153+ return System .getProperty ("os.arch" );
151154 }
152155
153156 private static String getMacCpuName () {
154157 String result = runCommand ("sysctl -n machdep.cpu.brand_string" );
155- return result != null ? result .trim () : System .getProperty ("os.arch" );
158+ if (result != null && !result .isBlank ()) {
159+ return result .trim ();
160+ }
161+ return System .getProperty ("os.arch" );
162+ }
163+
164+ private static String getDeviceModel () {
165+ if (cachedDeviceModel != null ) {
166+ return cachedDeviceModel ;
167+ }
168+
169+ String osName = System .getProperty ("os.name" ).toLowerCase ();
170+
171+ if (osName .contains ("mac" ) || osName .contains ("darwin" )) {
172+ cachedDeviceModel = getMacDeviceModel ();
173+ } else if (osName .contains ("linux" )) {
174+ cachedDeviceModel = getLinuxDeviceModel ();
175+ } else if (osName .contains ("windows" )) {
176+ cachedDeviceModel = getWindowsDeviceModel ();
177+ } else {
178+ cachedDeviceModel = "Unknown" ;
179+ }
180+
181+ if (cachedDeviceModel .equalsIgnoreCase ("To Be Filled By O.E.M." ) || cachedDeviceModel .equalsIgnoreCase ("Default String" )) {
182+ cachedDeviceModel = "Unknown" ;
183+ }
184+
185+ return cachedDeviceModel ;
186+ }
187+
188+ private static String getMacDeviceModel () {
189+ String result = runCommand ("sysctl -n hw.model" );
190+ return result != null ? result .trim () : "Unknown" ;
191+ }
192+
193+ private static String getLinuxDeviceModel () {
194+ String model = readFile ("/sys/devices/virtual/dmi/id/product_name" );
195+ if (model != null && !model .isBlank ()) {
196+ return model .trim ();
197+ }
198+
199+ model = readFile ("/proc/device-tree/model" );
200+ if (model != null && !model .isBlank ()) {
201+ return model .trim ();
202+ }
203+
204+ return "Unknown" ;
205+ }
206+
207+ private static String getWindowsDeviceModel () {
208+ String [] commands = {
209+ "powershell -NoProfile -Command \" (Get-CimInstance Win32_ComputerSystem).Model\" " ,
210+ "powershell -NoProfile -Command \" (Get-WmiObject Win32_ComputerSystem).Model\" " ,
211+ "cmd /c for /f \" tokens=2 delims==\" %A in ('wmic computersystem get model /value') do @echo %A"
212+ };
213+
214+ for (String command : commands ) {
215+ String result = runCommand (command );
216+ if (result != null && !result .trim ().isEmpty ()) {
217+ return result .trim ();
218+ }
219+ }
220+
221+ return "Unknown" ;
156222 }
157223
158224 private static String runCommand (String command ) {
0 commit comments