I'll create an HTML page with JavaScript that uses the AMF-JS library to read and parse .dat files as AMF3 format. Here's the complete solution:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AMF3 .dat File Reader</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.upload-area {
border: 2px dashed #ccc;
border-radius: 8px;
padding: 40px;
text-align: center;
margin-bottom: 20px;
transition: border-color 0.3s;
}
.upload-area:hover {
border-color: #007bff;
}
.upload-area.dragover {
border-color: #007bff;
background-color: #f8f9fa;
}
input[type="file"] {
margin: 10px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
width: 100%;
max-width: 300px;
}
.results {
margin-top: 20px;
}
.parsed-data {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 15px;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
font-size: 14px;
max-height: 500px;
overflow-y: auto;
}
.error {
color: #dc3545;
background: #f8d7da;
border: 1px solid #f5c6cb;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.success {
color: #155724;
background: #d4edda;
border: 1px solid #c3e6cb;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.file-info {
background: #e7f3ff;
border: 1px solid #b8daff;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #0056b3;
}
button:disabled {
background: #6c757d;
cursor: not-allowed;
}
</style>
</head>
<body>
<div class="container">
<h1>AMF3 .dat File Reader</h1>
<p>Upload a .dat file to parse it as AMF3 format and view the contents.</p>
<div class="upload-area" id="uploadArea">
<p>Drag and drop a .dat file here, or click to select</p>
<input type="file" id="fileInput" accept=".dat" />
</div>
<div id="fileInfo" class="file-info" style="display: none;"></div>
<div id="status"></div>
<div class="results">
<h3>Parsed Data:</h3>
<div id="parsedData" class="parsed-data">No file loaded yet.</div>
</div>
<div style="margin-top: 20px;">
<button id="clearBtn" onclick="clearResults()">Clear Results</button>
<button id="copyBtn" onclick="copyToClipboard()" disabled>Copy to Clipboard</button>
</div>
</div>
<!-- Include AMF-JS library -->
<script src="https://cdn.jsdelivr.net/npm/amf-js@1.0.4/src/amf.min.js"></script>
<script>
let currentParsedData = null;
// Get DOM elements
const fileInput = document.getElementById('fileInput');
const uploadArea = document.getElementById('uploadArea');
const fileInfo = document.getElementById('fileInfo');
const status = document.getElementById('status');
const parsedData = document.getElementById('parsedData');
const copyBtn = document.getElementById('copyBtn');
// File input change handler
fileInput.addEventListener('change', handleFileSelect);
// Drag and drop handlers
uploadArea.addEventListener('dragover', handleDragOver);
uploadArea.addEventListener('dragleave', handleDragLeave);
uploadArea.addEventListener('drop', handleDrop);
uploadArea.addEventListener('click', () => fileInput.click());
function handleDragOver(e) {
e.preventDefault();
uploadArea.classList.add('dragover');
}
function handleDragLeave(e) {
e.preventDefault();
uploadArea.classList.remove('dragover');
}
function handleDrop(e) {
e.preventDefault();
uploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
processFile(files[0]);
}
}
function handleFileSelect(e) {
const file = e.target.files[0];
if (file) {
processFile(file);
}
}
function processFile(file) {
// Display file information
fileInfo.style.display = 'block';
fileInfo.innerHTML = `
<strong>File Info:</strong><br>
Name: ${file.name}<br>
Size: ${formatFileSize(file.size)}<br>
Type: ${file.type || 'Unknown'}<br>
Last Modified: ${new Date(file.lastModified).toLocaleString()}
`;
// Show loading status
showStatus('Reading file...', 'info');
// Read file as ArrayBuffer
const reader = new FileReader();
reader.onload = function(e) {
try {
parseAMF3Data(e.target.result, file.name);
} catch (error) {
showStatus(`Error reading file: ${error.message}`, 'error');
console.error('File reading error:', error);
}
};
reader.onerror = function() {
showStatus('Error reading file', 'error');
console.error('FileReader error:', reader.error);
};
reader.readAsArrayBuffer(file);
}
function parseAMF3Data(arrayBuffer, fileName) {
try {
showStatus('Parsing AMF3 data...', 'info');
// Convert ArrayBuffer to Uint8Array
const uint8Array = new Uint8Array(arrayBuffer);
console.log(`Processing file: ${fileName}`);
console.log(`File size: ${uint8Array.length} bytes`);
console.log('Raw data (first 100 bytes):', uint8Array.slice(0, 100));
// Parse AMF3 data
const amfData = AMF.deserialize(uint8Array);
// Store parsed data
currentParsedData = amfData;
// Display parsed data
displayParsedData(amfData, fileName);
// Log to console
console.log('=== AMF3 PARSED DATA ===');
console.log('File:', fileName);
console.log('Parsed data:', amfData);
console.log('Data type:', typeof amfData);
console.log('Is Array:', Array.isArray(amfData));
if (Array.isArray(amfData)) {
console.log('Array length:', amfData.length);
amfData.forEach((item, index) => {
console.log(`Item ${index}:`, item);
});
} else if (typeof amfData === 'object' && amfData !== null) {
console.log('Object keys:', Object.keys(amfData));
for (const [key, value] of Object.entries(amfData)) {
console.log(`${key}:`, value);
}
}
showStatus(`Successfully parsed AMF3 data from ${fileName}`, 'success');
copyBtn.disabled = false;
} catch (error) {
showStatus(`Error parsing AMF3 data: ${error.message}`, 'error');
console.error('AMF3 parsing error:', error);
console.error('Error details:', {
name: error.name,
message: error.message,
stack: error.stack
});
// Try to show raw data as fallback
displayRawData(arrayBuffer, fileName);
}
}
function displayParsedData(data, fileName) {
let output = `File: ${fileName}\n`;
output += `Parsed AMF3 Data:\n`;
output += '='.repeat(50) + '\n\n';
if (data === null) {
output += 'null';
} else if (Array.isArray(data)) {
output += `Array (${data.length} items):\n`;
data.forEach((item, index) => {
output += `[${index}]: ${formatValue(item)}\n`;
});
} else if (typeof data === 'object') {
output += 'Object:\n';
for (const [key, value] of Object.entries(data)) {
output += `${key}: ${formatValue(value)}\n`;
}
} else {
output += formatValue(data);
}
parsedData.textContent = output;
}
function displayRawData(arrayBuffer, fileName) {
const uint8Array = new Uint8Array(arrayBuffer);
let output = `File: ${fileName}\n`;
output += `Raw Data (AMF3 parsing failed):\n`;
output += '='.repeat(50) + '\n\n';
output += `Size: ${uint8Array.length} bytes\n\n`;
output += 'Hex dump (first 500 bytes):\n';
const maxBytes = Math.min(500, uint8Array.length);
for (let i = 0; i < maxBytes; i += 16) {
const hex = Array.from(uint8Array.slice(i, i + 16))
.map(b => b.toString(16).padStart(2, '0'))
.join(' ');
const ascii = Array.from(uint8Array.slice(i, i + 16))
.map(b => (b >= 32 && b <= 126) ? String.fromCharCode(b) : '.')
.join('');
output += `${i.toString(16).padStart(8, '0')}: ${hex.padEnd(48)} ${ascii}\n`;
}
if (uint8Array.length > maxBytes) {
output += `\n... (${uint8Array.length - maxBytes} more bytes)`;
}
parsedData.textContent = output;
}
function formatValue(value) {
if (value === null) return 'null';
if (value === undefined) return 'undefined';
if (typeof value === 'string') return `"${value}"`;
if (typeof value === 'object') {
if (Array.isArray(value)) {
return `Array(${value.length}) [${value.slice(0, 3).map(formatValue).join(', ')}${value.length > 3 ? '...' : ''}]`;
}
return JSON.stringify(value, null, 2);
}
return String(value);
}
function showStatus(message, type) {
status.innerHTML = `<div class="${type}">${message}</div>`;
}
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function clearResults() {
parsedData.textContent = 'No file loaded yet.';
fileInfo.style.display = 'none';
status.innerHTML = '';
fileInput.value = '';
currentParsedData = null;
copyBtn.disabled = true;
}
function copyToClipboard() {
if (currentParsedData !== null) {
const text = parsedData.textContent;
navigator.clipboard.writeText(text).then(() => {
showStatus('Data copied to clipboard!', 'success');
}).catch(() => {
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
showStatus('Data copied to clipboard!', 'success');
});
}
}
// Initialize
console.log('AMF3 .dat File Reader initialized');
console.log('AMF library loaded:', typeof AMF !== 'undefined');
</script>
</body>
</html>
This HTML page provides a complete AMF3 .dat file reader with the following features:
Key Features:
- File Upload: Drag-and-drop or click to select .dat files
- AMF3 Parsing: Uses the AMF-JS library to parse binary AMF3 data
- Display: Shows parsed data in a formatted, readable way
- Console Logging: Logs all parsed items and details to the browser console
- Error Handling: Gracefully handles parsing errors and shows raw hex data as fallback
- File Information: Shows file details like size, name, and modification date
How it works:
- User uploads a .dat file
- File is read as an ArrayBuffer
- Data is passed to
AMF.deserialize() to parse AMF3 format
- Parsed data is displayed on the page and logged to console
- If parsing fails, it shows a hex dump of the raw data
Console Output:
The console will show detailed information including:
- File name and size
- Raw byte data (first 100 bytes)
- Parsed AMF3 data structure
- Individual items if it's an array
- Object properties if it's an object
To use this, save it as an HTML file and open it in a web browser. The AMF-JS library will be loaded from the CDN, and you can then upload .dat files to parse them as AMF3 format.