corrections

This commit is contained in:
overcuriousity 2025-09-27 23:49:42 +02:00
parent eb04e071c3
commit 1464373b0c

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dateisystem-Offset-Rechner</title> <title>Dateisystem-Offset-Rechner (Fixed)</title>
<style> <style>
* { * {
margin: 0; margin: 0;
@ -595,13 +595,20 @@
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
} }
} }
.fix-highlight {
background-color: #2a4a2a;
padding: 2px 4px;
border-radius: 3px;
border: 1px solid #4a6a4a;
}
</style> </style>
</head> </head>
<body> <body>
<header class="header"> <header class="header">
<div class="header-content"> <div class="header-content">
<div class="logo">Dateisystem-Offset-Rechner</div> <div class="logo">Dateisystem-Offset-Rechner (Fixed)</div>
<nav class="nav"> <nav class="nav">
<a href="#home">Home</a> <a href="#home">Home</a>
<a href="mailto:mstoeck3@hs-mittweida.de">Contact</a> <a href="mailto:mstoeck3@hs-mittweida.de">Contact</a>
@ -611,7 +618,7 @@
<main class="main-content"> <main class="main-content">
<div class="container"> <div class="container">
<h1>Dateisystem-Offset-Rechner</h1> <h1>Dateisystem-Offset-Rechner (Fixed Version)</h1>
<div class="tabs"> <div class="tabs">
<div class="tab active" onclick="switchTab('fat1216')">FAT12/16</div> <div class="tab active" onclick="switchTab('fat1216')">FAT12/16</div>
@ -727,8 +734,8 @@
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="fatSizeBytes1216">Größe einer FAT <span <label for="fatSizeBytes1216">Größe einer FAT <span
class="unit-indicator">(Bytes)</span>:</label> class="unit-indicator fix-highlight">(Bytes)</span>:</label>
<input type="text" id="fatSizeBytes1216" placeholder="0x1000"> <input type="text" id="fatSizeBytes1216" placeholder="0x4000">
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="maxRootEntries1216">Max. Wurzelverzeichnis-Einträge <span <label for="maxRootEntries1216">Max. Wurzelverzeichnis-Einträge <span
@ -743,7 +750,7 @@
<div class="input-group"> <div class="input-group">
<label for="clusterSizeSectors1216">Größe eines Clusters <span <label for="clusterSizeSectors1216">Größe eines Clusters <span
class="unit-indicator">(Sektoren)</span>:</label> class="unit-indicator">(Sektoren)</span>:</label>
<input type="text" id="clusterSizeSectors1216" placeholder="0x1"> <input type="text" id="clusterSizeSectors1216" placeholder="0x2">
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="clusterNumber1216">Cluster Nummer für Position <span <label for="clusterNumber1216">Cluster Nummer für Position <span
@ -851,7 +858,7 @@
<div class="formula"><span class="calculated">Beginn FAT-Bereich</span> = Anzahl reservierter <div class="formula"><span class="calculated">Beginn FAT-Bereich</span> = Anzahl reservierter
Sektoren × Größe eines Sektors + Base Offset</div> Sektoren × Größe eines Sektors + Base Offset</div>
<div class="formula"><span class="calculated">Größe FAT-Bereich</span> = Anzahl FATs × Größe <div class="formula"><span class="calculated">Größe FAT-Bereich</span> = Anzahl FATs × Größe
einer FAT</div> einer FAT (in Bytes)</div>
<div class="formula"><span class="calculated">Ende FAT-Bereich</span> = Beginn FAT-Bereich + <div class="formula"><span class="calculated">Ende FAT-Bereich</span> = Beginn FAT-Bereich +
Größe FAT-Bereich</div> Größe FAT-Bereich</div>
<div class="formula"><span class="calculated">Größe Wurzelverzeichnis</span> = Anzahl max. <div class="formula"><span class="calculated">Größe Wurzelverzeichnis</span> = Anzahl max.
@ -986,8 +993,8 @@
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="fatSizeBytes32">Größe einer FAT <span <label for="fatSizeBytes32">Größe einer FAT <span
class="unit-indicator">(Bytes)</span>:</label> class="unit-indicator fix-highlight">(Bytes)</span>:</label>
<input type="text" id="fatSizeBytes32" placeholder="0x10000"> <input type="text" id="fatSizeBytes32" placeholder="0x20000">
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="rootDirCluster32">Root Directory Cluster <span <label for="rootDirCluster32">Root Directory Cluster <span
@ -997,7 +1004,7 @@
<div class="input-group"> <div class="input-group">
<label for="partitionSizeInSectors32">Größe Partition <span <label for="partitionSizeInSectors32">Größe Partition <span
class="unit-indicator">(Sektoren)</span>:</label> class="unit-indicator">(Sektoren)</span>:</label>
<input type="text" id="partitionSizeInSectors32" placeholder="0x20000"> <input type="text" id="partitionSizeInSectors32" placeholder="0x100000">
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="clusterSizeSectors32">Größe eines Clusters <span <label for="clusterSizeSectors32">Größe eines Clusters <span
@ -1103,7 +1110,7 @@
<div class="formula"><span class="calculated">Beginn FAT-Bereich</span> = Anzahl reservierter <div class="formula"><span class="calculated">Beginn FAT-Bereich</span> = Anzahl reservierter
Sektoren × Größe eines Sektors + Base Offset</div> Sektoren × Größe eines Sektors + Base Offset</div>
<div class="formula"><span class="calculated">Größe FAT-Bereich</span> = Anzahl FATs × Größe <div class="formula"><span class="calculated">Größe FAT-Bereich</span> = Anzahl FATs × Größe
einer FAT</div> einer FAT (in Bytes)</div>
<div class="formula"><span class="calculated">Ende FAT-Bereich</span> = Beginn FAT-Bereich + <div class="formula"><span class="calculated">Ende FAT-Bereich</span> = Beginn FAT-Bereich +
Größe FAT-Bereich</div> Größe FAT-Bereich</div>
<div class="formula"><span class="calculated">Beginn Daten-Bereich</span> = Ende FAT-Bereich <div class="formula"><span class="calculated">Beginn Daten-Bereich</span> = Ende FAT-Bereich
@ -1128,25 +1135,26 @@
<div class="footer-content"> <div class="footer-content">
<div class="footer-section"> <div class="footer-section">
<h3>About</h3> <h3>About</h3>
<p>Offset calculator for educational and forensic purposes.</p> <p>Fixed offset calculator for educational and forensic purposes.</p>
<p>Version 0.2.0</p> <p>Version 0.2.1 (Fixed)</p>
</div>
<div class="footer-section">
<h3>Fixes Applied</h3>
<p>• Updated FAT size placeholders</p>
<p>• Fixed calculator overflow handling</p>
<p>• Improved integer precision</p>
</div> </div>
<div class="footer-section"> <div class="footer-section">
<h3>Support</h3> <h3>Support</h3>
<a href="mailto:mstoeck3@hs-mittweida.de">Contact Support</a> <a href="mailto:mstoeck3@hs-mittweida.de">Contact Support</a>
<a href="https://git.cc24.dev/mstoeck3/fscalc/issues/new">Report Bug</a>
</div> </div>
<div class="footer-section"> <div class="footer-section">
<h3>Legal</h3> <h3>Legal</h3>
<a href="https://git.cc24.dev/mstoeck3/fscalc/src/branch/main/LICENSE">License</a> <p>Educational use only</p>
</div>
<div class="footer-section">
<h3>Connect</h3>
<a href="https://git.cc24.dev/mstoeck3/fscalc">Gitea Repository</a>
</div> </div>
</div> </div>
<div class="footer-bottom"> <div class="footer-bottom">
<p>&copy; 2025 Offset Calculator. All rights reserved. | Built with ❤️ for computer science education.</p> <p>&copy; 2025 Offset Calculator (Fixed). All rights reserved.</p>
</div> </div>
</footer> </footer>
@ -1192,8 +1200,8 @@
const decElement = document.getElementById(`decValue${suffix}`); const decElement = document.getElementById(`decValue${suffix}`);
const binElement = document.getElementById(`binValue${suffix}`); const binElement = document.getElementById(`binValue${suffix}`);
// Ensure value is within JavaScript's safe integer range // Ensure value is within JavaScript's safe integer range and non-negative
const value = Math.max(0, Math.min(state.currentValue, Number.MAX_SAFE_INTEGER)); const value = Math.max(0, Math.min(Math.floor(state.currentValue), Number.MAX_SAFE_INTEGER));
const hexStr = '0x' + value.toString(16).toUpperCase(); const hexStr = '0x' + value.toString(16).toUpperCase();
const decStr = value.toString(10); const decStr = value.toString(10);
@ -1220,7 +1228,7 @@
// Prevent overflow by limiting to a reasonable hex value // Prevent overflow by limiting to a reasonable hex value
const newValue = state.currentValue * 16 + digitValue; const newValue = state.currentValue * 16 + digitValue;
if (newValue <= 0xFFFFFFFFFFFFFF) { // Limit to 56 bits for safety if (newValue <= Number.MAX_SAFE_INTEGER && newValue >= 0) {
state.currentValue = newValue; state.currentValue = newValue;
} }
@ -1233,7 +1241,8 @@
if (operation === 'NOT') { if (operation === 'NOT') {
// Unary operation - apply immediately // Unary operation - apply immediately
state.currentValue = (~state.currentValue) >>> 0; // Use unsigned 32-bit // Use a mask to ensure we get meaningful results for filesystem calculations
state.currentValue = (~state.currentValue & 0xFFFFFFFF) >>> 0;
updateCalculatorDisplay(currentTab); updateCalculatorDisplay(currentTab);
return; return;
} }
@ -1252,55 +1261,56 @@
const state = getCalculatorState(currentTab); const state = getCalculatorState(currentTab);
if (state.operation && state.previousValue !== null) { if (state.operation && state.previousValue !== null) {
const prev = state.previousValue; const prev = Math.floor(state.previousValue);
const curr = state.currentValue; const curr = Math.floor(state.currentValue);
try { try {
let result = 0;
switch (state.operation) { switch (state.operation) {
case '+': case '+':
state.currentValue = prev + curr; result = prev + curr;
break; break;
case '-': case '-':
state.currentValue = prev - curr; result = prev - curr;
break; break;
case '*': case '*':
state.currentValue = prev * curr; result = prev * curr;
break; break;
case '/': case '/':
if (curr === 0) { if (curr === 0) {
alert('Division by zero!'); alert('Division by zero!');
return; return;
} }
state.currentValue = Math.floor(prev / curr); result = Math.floor(prev / curr);
break; break;
case 'MOD': case 'MOD':
if (curr === 0) { if (curr === 0) {
alert('Modulo by zero!'); alert('Modulo by zero!');
return; return;
} }
state.currentValue = prev % curr; result = prev % curr;
break; break;
case 'AND': case 'AND':
state.currentValue = (prev & curr) >>> 0; result = (prev & curr);
break; break;
case 'OR': case 'OR':
state.currentValue = (prev | curr) >>> 0; result = (prev | curr);
break; break;
case 'XOR': case 'XOR':
state.currentValue = (prev ^ curr) >>> 0; result = (prev ^ curr);
break; break;
case '<<': case '<<':
state.currentValue = (prev << curr) >>> 0; // Limit shift amount to prevent overflow
const shiftLeft = Math.min(curr, 53);
result = prev << shiftLeft;
break; break;
case '>>': case '>>':
state.currentValue = (prev >> curr) >>> 0; result = prev >> curr;
break; break;
} }
// Ensure positive value // Ensure result is within safe range and non-negative
if (state.currentValue < 0) { state.currentValue = Math.max(0, Math.min(result, Number.MAX_SAFE_INTEGER));
state.currentValue = 0;
}
} catch (error) { } catch (error) {
alert('Calculation error: ' + error.message); alert('Calculation error: ' + error.message);
@ -1353,10 +1363,10 @@
updateCalculatorDisplay(currentTab); updateCalculatorDisplay(currentTab);
break; break;
case 'M+': case 'M+':
state.memory += state.currentValue; state.memory = Math.max(0, Math.min(state.memory + state.currentValue, Number.MAX_SAFE_INTEGER));
break; break;
case 'M-': case 'M-':
state.memory -= state.currentValue; state.memory = Math.max(0, state.memory - state.currentValue);
break; break;
} }
} }
@ -1424,22 +1434,23 @@
const rootDirStart = fatEnd; const rootDirStart = fatEnd;
const rootDirSize = maxRootEntries * 0x20; const rootDirSize = maxRootEntries * 0x20;
const dataStart = fatEnd + rootDirSize; const dataStart = fatEnd + rootDirSize;
const dataSize = partitionSizeInSectors * sectorSize - (dataStart - baseOffset); const partitionSizeBytes = partitionSizeInSectors * sectorSize;
const dataSize = partitionSizeBytes - (dataStart - baseOffset);
const clusterSize = sectorSize * clusterSizeSectors; const clusterSize = sectorSize * clusterSizeSectors;
const numClusters = clusterSize > 0 ? Math.floor(dataSize / clusterSize) : 0; const numClusters = clusterSize > 0 ? Math.floor(dataSize / clusterSize) : 0;
const clusterStart = dataStart + (clusterNumber - 0x2) * clusterSize; const clusterStart = dataStart + (clusterNumber - 0x2) * clusterSize;
const calculations = { const calculations = {
fatStart: `${reservedSectors.toString(16)} × ${sectorSize.toString(16)} + ${baseOffset.toString(16)} = ${fatStart.toString(16)}`, fatStart: `0x${reservedSectors.toString(16)} × 0x${sectorSize.toString(16)} + 0x${baseOffset.toString(16)} = 0x${fatStart.toString(16)}`,
fatSize: `${numFATs.toString(16)} × ${fatSizeBytes.toString(16)} = ${fatSize.toString(16)}`, fatSize: `0x${numFATs.toString(16)} × 0x${fatSizeBytes.toString(16)} = 0x${fatSize.toString(16)}`,
fatEnd: `${fatStart.toString(16)} + ${fatSize.toString(16)} = ${fatEnd.toString(16)}`, fatEnd: `0x${fatStart.toString(16)} + 0x${fatSize.toString(16)} = 0x${fatEnd.toString(16)}`,
rootDirStart: `${fatEnd.toString(16)}`, rootDirStart: `0x${fatEnd.toString(16)}`,
rootDirSize: `${maxRootEntries.toString(16)} × 0x20 = ${rootDirSize.toString(16)}`, rootDirSize: `0x${maxRootEntries.toString(16)} × 0x20 = 0x${rootDirSize.toString(16)}`,
dataStart: `${fatEnd.toString(16)} + ${rootDirSize.toString(16)} = ${dataStart.toString(16)}`, dataStart: `0x${fatEnd.toString(16)} + 0x${rootDirSize.toString(16)} = 0x${dataStart.toString(16)}`,
dataSize: `(${partitionSizeInSectors.toString(16)} × ${sectorSize.toString(16)}) - (${dataStart.toString(16)} - ${baseOffset.toString(16)}) = ${dataSize.toString(16)}`, dataSize: `(0x${partitionSizeInSectors.toString(16)} × 0x${sectorSize.toString(16)}) - (0x${dataStart.toString(16)} - 0x${baseOffset.toString(16)}) = 0x${dataSize.toString(16)}`,
clusterSize: `${sectorSize.toString(16)} × ${clusterSizeSectors.toString(16)} = ${clusterSize.toString(16)}`, clusterSize: `0x${sectorSize.toString(16)} × 0x${clusterSizeSectors.toString(16)} = 0x${clusterSize.toString(16)}`,
numClusters: `${dataSize.toString(16)} ÷ ${clusterSize.toString(16)} = ${numClusters.toString(16)}`, numClusters: `0x${dataSize.toString(16)} ÷ 0x${clusterSize.toString(16)} = 0x${numClusters.toString(16)}`,
clusterStart: `${dataStart.toString(16)} + (${clusterNumber.toString(16)} - 0x2) × ${clusterSize.toString(16)} = ${clusterStart.toString(16)}` clusterStart: `0x${dataStart.toString(16)} + (0x${clusterNumber.toString(16)} - 0x2) × 0x${clusterSize.toString(16)} = 0x${clusterStart.toString(16)}`
}; };
return { return {
@ -1465,22 +1476,23 @@
const fatSize = numFATs * fatSizeBytes; const fatSize = numFATs * fatSizeBytes;
const fatEnd = fatStart + fatSize; const fatEnd = fatStart + fatSize;
const dataStart = fatEnd; const dataStart = fatEnd;
const dataSize = partitionSizeInSectors * sectorSize - (dataStart - baseOffset); const partitionSizeBytes = partitionSizeInSectors * sectorSize;
const dataSize = partitionSizeBytes - (dataStart - baseOffset);
const clusterSize = sectorSize * clusterSizeSectors; const clusterSize = sectorSize * clusterSizeSectors;
const numClusters = clusterSize > 0 ? Math.floor(dataSize / clusterSize) : 0; const numClusters = clusterSize > 0 ? Math.floor(dataSize / clusterSize) : 0;
const clusterStart = dataStart + (clusterNumber - 0x2) * clusterSize; const clusterStart = dataStart + (clusterNumber - 0x2) * clusterSize;
const rootDirPos = dataStart + (rootDirCluster - 0x2) * clusterSize; const rootDirPos = dataStart + (rootDirCluster - 0x2) * clusterSize;
const calculations = { const calculations = {
fatStart: `${reservedSectors.toString(16)} × ${sectorSize.toString(16)} + ${baseOffset.toString(16)} = ${fatStart.toString(16)}`, fatStart: `0x${reservedSectors.toString(16)} × 0x${sectorSize.toString(16)} + 0x${baseOffset.toString(16)} = 0x${fatStart.toString(16)}`,
fatSize: `${numFATs.toString(16)} × ${fatSizeBytes.toString(16)} = ${fatSize.toString(16)}`, fatSize: `0x${numFATs.toString(16)} × 0x${fatSizeBytes.toString(16)} = 0x${fatSize.toString(16)}`,
fatEnd: `${fatStart.toString(16)} + ${fatSize.toString(16)} = ${fatEnd.toString(16)}`, fatEnd: `0x${fatStart.toString(16)} + 0x${fatSize.toString(16)} = 0x${fatEnd.toString(16)}`,
dataStart: `${fatEnd.toString(16)}`, dataStart: `0x${fatEnd.toString(16)}`,
dataSize: `(${partitionSizeInSectors.toString(16)} × ${sectorSize.toString(16)}) - (${dataStart.toString(16)} - ${baseOffset.toString(16)}) = ${dataSize.toString(16)}`, dataSize: `(0x${partitionSizeInSectors.toString(16)} × 0x${sectorSize.toString(16)}) - (0x${dataStart.toString(16)} - 0x${baseOffset.toString(16)}) = 0x${dataSize.toString(16)}`,
clusterSize: `${sectorSize.toString(16)} × ${clusterSizeSectors.toString(16)} = ${clusterSize.toString(16)}`, clusterSize: `0x${sectorSize.toString(16)} × 0x${clusterSizeSectors.toString(16)} = 0x${clusterSize.toString(16)}`,
numClusters: `${dataSize.toString(16)} ÷ ${clusterSize.toString(16)} = ${numClusters.toString(16)}`, numClusters: `0x${dataSize.toString(16)} ÷ 0x${clusterSize.toString(16)} = 0x${numClusters.toString(16)}`,
clusterStart: `${dataStart.toString(16)} + (${clusterNumber.toString(16)} - 0x2) × ${clusterSize.toString(16)} = ${clusterStart.toString(16)}`, clusterStart: `0x${dataStart.toString(16)} + (0x${clusterNumber.toString(16)} - 0x2) × 0x${clusterSize.toString(16)} = 0x${clusterStart.toString(16)}`,
rootDirPos: `${dataStart.toString(16)} + (${rootDirCluster.toString(16)} - 0x2) × ${clusterSize.toString(16)} = ${rootDirPos.toString(16)}` rootDirPos: `0x${dataStart.toString(16)} + (0x${rootDirCluster.toString(16)} - 0x2) × 0x${clusterSize.toString(16)} = 0x${rootDirPos.toString(16)}`
}; };
return { return {
@ -1498,14 +1510,14 @@
cleanValue = cleanValue.substring(2); cleanValue = cleanValue.substring(2);
} }
const parsed = parseInt(cleanValue, 16); const parsed = parseInt(cleanValue, 16);
return isNaN(parsed) ? 0 : parsed; return isNaN(parsed) ? 0 : Math.max(0, parsed);
} }
function formatHex(value) { function formatHex(value) {
if (isNaN(value) || value < 0) { if (isNaN(value) || value < 0) {
return '<span class="error">Fehler</span>'; return '<span class="error">Fehler</span>';
} }
return '0x' + value.toString(16).toUpperCase(); return '0x' + Math.floor(value).toString(16).toUpperCase();
} }
function copyToClipboard(elementId) { function copyToClipboard(elementId) {