Skip to content

Instantly share code, notes, and snippets.

@an1creator
Last active April 13, 2023 21:02
Show Gist options
  • Save an1creator/c1ea0ca5da38253d2e883bc631e4cc64 to your computer and use it in GitHub Desktop.
Save an1creator/c1ea0ca5da38253d2e883bc631e4cc64 to your computer and use it in GitHub Desktop.
Decodes a ini file from HeidiSQL. HeidiSQL passwords can be found in the registry. Use File -> Export Settings to dump all settings. Output to file: host, port, user, password
const fs = require("fs");
function heidiDecode(hex) {
var str = "";
var shift = parseInt(hex.substr(-1));
hex = hex.substr(0, hex.length - 1);
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16) - shift);
return str;
}
function splitData(data) {
return data.split(/Servers\\/).slice(1);
}
function findPasswords(filePath) {
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading file:", err);
return;
}
const allDataRegex =
/(?:\w+\\)*(Host|Port|User|Password)<\|\|\|>1<\|\|\|>([^<]+)/g;
let sections = splitData(data);
let results = [];
let result = {};
sections.forEach((section) => {
let match;
while ((match = allDataRegex.exec(section)) !== null) {
const key = match[1];
const value = match[2];
result[key] =
key === "Password" ? heidiDecode(value.trim()) : value.trim();
}
if (result.Host && result.Port && result.User && result.Password) {
results.push(result);
result = {};
}
});
const outputFile = "heididecode-output.txt";
let outputData = "";
let loop = 1;
results.forEach((result) => {
outputData += `#${loop}\nHost: ${result.Host}\nPort: ${result.Port}\nUser: ${result.User}\nPassword: ${result.Password}\n\n`;
loop++;
});
fs.writeFile(outputFile, outputData, (err) => {
if (err) {
console.error("Error writing file:", err);
} else {
console.log(`Results saved to ${outputFile}`);
}
});
});
}
const filePath = process.argv[2];
if (filePath) {
findPasswords(filePath);
} else {
console.error("Please provide a file path");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment