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