-
-
Save jacwright/40c50faa29257c8b76666c1e077352f1 to your computer and use it in GitHub Desktop.
obfuscate ttf file to odttf file, asked ChatGPT4 to reverse https://gist.github.com/jacwright/40c50faa29257c8b76666c1e077352f1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const purpose = "Purpose: obfuscate ttf file (convert to Microsoft's ODTTF format)" | |
const usage = "Usage: node obfuscate-ttf-to-odttf.js <guid-font-file.ttf> [<output-file.odttf>]" | |
const obfuscatedStartOffset = 0 | |
const obfuscatedEndOffset = 32 | |
const guidSize = 32 | |
const fs = require('fs') | |
const path = require('path') | |
const fontFilepath = process.argv[2] | |
if (fontFilepath == null) { | |
console.warn(purpose) | |
console.warn(usage) | |
return | |
} | |
const fontFilename = path.basename(fontFilepath) | |
const guid = fontFilename.replace(/-/g, "").replace(/\..+$/, "") | |
if (guid.length !== guidSize) { | |
console.warn(guid, "Error: Cannot extract GUID from font filename (ex: A5C0272A-DD4C-401C-8661-BEAD77E57818.ttf)") | |
return | |
} | |
const hexStrings = guid.replace(/(..)/g,"$1 ").trim().split(" ") | |
const hexNumbers = hexStrings.map((hexString) => parseInt(hexString, 16)) | |
hexNumbers.reverse() | |
const buf = fs.readFileSync(fontFilepath) | |
const bytesToObfuscate = buf.slice(obfuscatedStartOffset, obfuscatedEndOffset) | |
const obfuscatedBytes = bytesToObfuscate.map((byte, i) => byte ^ hexNumbers[i % hexNumbers.length] ) | |
const out = Buffer.concat([ | |
buf.slice(0, obfuscatedStartOffset), | |
obfuscatedBytes, | |
buf.slice(obfuscatedEndOffset) | |
]) | |
const outputFilepath = process.argv[3] || fontFilepath + '.odttf' | |
fs.writeFile( | |
outputFilepath, | |
out, | |
{ encoding: null }, | |
(error) => { if (error) throw error; } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment