Added support for changing the Windows agent bitmap logo within the executable. Agent needs to be changed to fully support this.
Ylian Saint-Hilaire committed
Aug 11, 2022 at 17:37 UTC
d519546a6c722f15b67b219f1bd7b29720f7176a
3 files changed
+60
-1
authenticode.js
+1
@@ -2482,4 +2482,5 @@ if (require.main === module) { start(); }
2482
module.exports.createAuthenticodeHandler = createAuthenticodeHandler;
2483
module.exports.loadCertificates = loadCertificates;
2484
module.exports.loadIcon = loadIcon;
2485
+module.exports.loadBitmap = loadBitmap;
2486
module.exports.hashObject = hashObject;
\ No newline at end of file
meshcentral.js
+57
@@ -1384,6 +1384,22 @@ function CreateMeshCentralServer(config, args) {
1384
// Invalid icon file path
1385
delete obj.config.domains[i].agentfileinfo.icon;
1386
}
1387
+ if (typeof obj.config.domains[i].agentfileinfo.logo == 'string') {
1388
+ // Load the agent .bmp file
1389
+ var logo = null;
1390
+ try { logo = require('./authenticode.js').loadBitmap(obj.path.join(obj.datapath, obj.config.domains[i].agentfileinfo.logo)); } catch (ex) { }
1391
+ if (logo != null) {
1392
+ // The logo file was correctly loaded
1393
+ obj.config.domains[i].agentfileinfo.logo = logo;
1394
+ } else {
1395
+ // Failed to load the icon file, display a server warning
1396
+ addServerWarning("Unable to load agent logo file: " + obj.config.domains[i].agentfileinfo.logo + ".", 24, [obj.config.domains[i].agentfileinfo.logo]);
1397
+ delete obj.config.domains[i].agentfileinfo.logo;
1398
+ }
1399
+ } else {
1400
+ // Invalid icon file path
1401
+ delete obj.config.domains[i].agentfileinfo.logo;
1402
+ }
1403
}
1404
}
1405
@@ -3022,6 +3038,35 @@ function CreateMeshCentralServer(config, args) {
3038
}
3039
}
3040
}
3041
+
3042
+ // Check the agent logo
3043
+ if (destinationAgentOk == true) {
3044
+ if ((domain.agentfileinfo != null) && (domain.agentfileinfo.logo != null)) {
3045
+ // Check if the destination agent matches the logo we want
3046
+ const agentBitmaps = destinationAgent.getBitmapInfo();
3047
+ if (agentBitmaps != null) {
3048
+ const agentBitmapNames = Object.keys(agentBitmaps);
3049
+ if (agentBitmapNames.length > 0) {
3050
+ const agentMainBitmap = agentBitmaps[agentBitmapNames[0]];
3051
+ const agentMainBitmapHash = require('./authenticode.js').hashObject(agentMainBitmap);
3052
+ const bitmapHash = require('./authenticode.js').hashObject(domain.agentfileinfo.logo);
3053
+ if (agentMainBitmapHash != bitmapHash) { destinationAgentOk = false; } // If the existing agent logo does not match the desired logo, we need to re-sign the agent.
3054
+ }
3055
+ }
3056
+ } else {
3057
+ // Check if the destination agent has the default icon
3058
+ const agentBitmaps1 = destinationAgent.getBitmapInfo();
3059
+ const agentBitmaps2 = originalAgent.getBitmapInfo();
3060
+ const agentBitmapNames = Object.keys(agentBitmaps1);
3061
+ if (agentBitmapNames.length == 0) {
3062
+ destinationAgentOk = false;
3063
+ } else {
3064
+ const iconHash1 = require('./authenticode.js').hashObject(agentBitmaps1[agentBitmapNames[0]]);
3065
+ const iconHash2 = require('./authenticode.js').hashObject(agentBitmaps2[agentBitmapNames[0]]);
3066
+ if (iconHash1 != iconHash2) { destinationAgentOk = false; } // If the existing agent icon does not match the desired icon, we need to re-sign the agent.
3067
+ }
3068
+ }
3069
+ }
3070
}
3071
3072
// If everything looks ok, runs a hash of the original and destination agent .text, .data and .rdata sections. If different, sign the agent again.
@@ -3084,6 +3129,18 @@ function CreateMeshCentralServer(config, args) {
3129
}
3130
}
3131
}
3132
+
3133
+ // Change the agent logo
3134
+ if (domain.agentfileinfo.logo != null) {
3135
+ const agentBitmaps = originalAgent.getBitmapInfo();
3136
+ if (agentBitmaps != null) {
3137
+ const agentBitmapNames = Object.keys(agentBitmaps);
3138
+ if (agentBitmapNames.length > 0) {
3139
+ agentBitmaps[agentBitmapNames[0]] = domain.agentfileinfo.logo;
3140
+ originalAgent.setBitmapInfo(agentBitmaps);
3141
+ }
3142
+ }
3143
+ }
3144
}
3145
3146
const signingArguments = { out: signeedagentpath, desc: signDesc, url: signUrl, time: timeStampUrl, proxy: timeStampProxy }; // Shallow clone
views/default.handlebars
+2
-1
@@ -2329,7 +2329,8 @@
2329
20: "Invalid \"LoginCookieEncryptionKey\" in config.json.",
2330
21: "Backup path can't be set within meshcentral-data folder, backup settings ignored.",
2331
22: "Failed to sign agent {0}: {1}",
2332
- 23: "Unable to load agent icon file: {0}."
2332
+ 23: "Unable to load agent icon file: {0}.",
2333
+ 24: "Unable to load agent logo file: {0}."
2334
};
2335
var x = '';
2336
for (var i in message.warnings) {