js实现浏览器中 x86/x64 Linux二进制程序与汇编语言互转工具代码

代码语言:html

所属分类:其他

代码描述:js实现浏览器中 x86/x64 Linux二进制程序与汇编语言互转工具代码

代码标签: js 浏览器 x86 x64 Linux 二进制 程序 汇编 语言 互转 工具 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Linux x86/x64 二进制 ⇄ 汇编 转换器</title>
<style>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #0c0c1d 0%, #1a1a3e 50%, #0d0d2b 100%);
    min-height: 100vh;
    color: #e0e0e0;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 30px 0;
}

header h1 {
    font-size: 2.2em;
    background: linear-gradient(90deg, #00d4ff, #7b2ff7, #ff6b9d);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

header p {
    color: #888;
    font-size: 1.1em;
}

.toolbar {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar select, .toolbar button {
    padding: 10px 20px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1a1a3e;
    color: #e0e0e0;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.toolbar select:hover, .toolbar button:hover {
    border-color: #7b2ff7;
    box-shadow: 0 0 15px rgba(123, 47, 247, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, #7b2ff7, #00d4ff) !important;
    border: none !important;
    font-weight: bold;
    color: #fff !important;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(123, 47, 247, 0.5) !important;
}

.btn-danger {
    background: linear-gradient(135deg, #ff4757, #ff6b9d) !important;
    border: none !important;
    color: #fff !important;
}

.btn-success {
    background: linear-gradient(135deg, #2ed573, #1abc9c) !important;
    border: none !important;
    color: #fff !important;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 80px 1fr;
    gap: 15px;
    margin: 20px 0;
    align-items: stretch;
}

.panel {
    background: rgba(20, 20, 50, 0.8);
    border: 1px solid #2a2a5a;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 15px 20px;
    background: rgba(30, 30, 70, 0.9);
    border-bottom: 1px solid #2a2a5a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 1.1em;
    color: #00d4ff;
}

.panel-header .badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    background: rgba(123, 47, 247, 0.3);
    color: #b388ff;
}

.panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor {
    width: 100%;
    flex: 1;
    min-height: 500px;
    background: rgba(10, 10, 30, 0.9);
    border: none;
    color: #00ff88;
    font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    padding: 15px;
    resize: none;
    outline: none;
    line-height: 1.6;
    tab-size: 4;
}

.editor::placeholder {
    color: #444;
}

.editor.hex-editor {
    color: #ff9f43;
}

.arrows {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.arrow-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #7b2ff7;
    background: rgba(123, 47, 247, 0.1);
    color: #7b2ff7;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.arrow-btn:hover {
    background: rgba(123, 47, 247, 0.3);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(123, 47, 247, 0.4);
}

.file-upload {
    padding: 15px;
    border-bottom: 1px solid #2a2a5a;
    text-align: center;
}

.file-upload label {
    display: inline-block;
    padding: 8px 20px;
    background: rgba(123, 47, 247, 0.2);
    border: 1px dashed #7b2ff7;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
}

.file-upload label:hover {
    background: rgba(123, 47, 247, 0.4);
}

.file-upload input[type="file"] {
    display: none;
}

.status-bar {
    padding: 10px 20px;
    background: rgba(10, 10, 30, 0.9);
    border-top: 1px solid #2a2a5a;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #666;
}

.output-panel {
    margin: 20px 0;
}

.output-panel .panel-body {
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
}

#log-output {
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.8;
    white-space: pre-wrap;
    color: #aaa;
}

.log-error { color: #ff4757 !important; }
.log-success { color: #2ed573 !important; }
.log-info { color: #00d4ff !important; }
.log-warn { color: #ffa502 !important; }

.tabs {
    display: flex;
    gap: 2px;
}

.tab {
    padding: 8px 16px;
    background: rgba(20, 20, 50, 0.5);
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 12px;
    color: #888;
    transition: all 0.3s;
}

.tab.active {
    background: rgba(30, 30, 70, 0.9);
    color: #00d4ff;
    border-color: #2a2a5a;
}

.reference-section {
    margin: 30px 0;
}

.reference-section h3 {
    color: #7b2ff7;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.ref-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
}

.ref-card {
    background: rgba(20, 20, 50, 0.8);
    border: 1px solid #2a2a5a;
    border-radius: 10px;
    padding: 15px;
}

.ref-card h4 {
    color: #00d4ff;
    margin-bottom: 10px;
    font-size: 0.95em;
}

.ref-card table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.ref-card th, .ref-card td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid #1a1a3e;
}

.ref-card th {
    color: #7b2ff7;
}

.ref-card td:first-child {
    color: #ff9f43;
    font-family: monospace;
}

.ref-card td:nth-child(2) {
    color: #00ff88;
    font-family: monospace;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #1a1a3e;
    border: 1px solid #2a2a5a;
    border-radius: 15px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 {
    color: #00d4ff;
    margin-bottom: 20px;
}

.modal textarea {
    width: 100%;
    min-height: 200px;
    background: rgba(10, 10, 30, 0.9);
    border: 1px solid #333;
    border-radius: 8px;
    color: #00ff88;
    font-family: monospace;
    font-size: 13px;
    padding: 10px;
    margin: 10px 0;
    resize: vertical;
}

.modal .btn-row {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 15px;
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .arrows {
        flex-direction: row;
        padding: 10px;
    }
    .arrow-btn {
        width: 50px;
        height: 50px;
    }
    header h1 {
        font-size: 1.5em;
    }
}

.highlight-line {
    background: rgba(123, 47, 247, 0.1);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0c0c1d;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.template-btns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 15px;
    border-bottom: 1px solid #2a2a5a;
}

.template-btn {
    padding: 4px 12px;
    border-radius: 15px;
    border: 1px solid #333;
    background: transparent;
    color: #888;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s;
}

.template-btn:hover {
    border-color: #7b2ff7;
    color: #b388ff;
}

.syntax-select {
    padding: 4px 8px;
    background: rgba(10, 10, 30, 0.9);
    border: 1px solid #333;
    border-radius: 4px;
    color: #aaa;
    font-size: 12px;
}

.progress-bar {
    height: 3px;
    background: #1a1a3e;
    border-radius: 2px;
    overflow: hidden;
    margin: 5px 0;
    display: none;
}

.progress-bar.active {
    display: block;
}

.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, #7b2ff7, #00d4ff);
    width: 0%;
    transition: width 0.3s;
    border-radius: 2px;
}
</style>
</head>
<body>

<div class="container">
    <header>
        <h1>🔧 Linux x86/x64 二进制 ⇄ 汇编 转换器</h1>
        <p>在浏览器中实现ELF可执行文件与汇编语言的相互转换 | 支持x86 &amp; x86-64</p>
    </header>

    <div class="toolbar">
        <select id="arch-select">
            <option value="x86">x86 (32-bit)</option>
            <option value="x64" selected>x86-64 (64-bit)</option>
        </select>
        <select id="syntax-select">
            <option value="nasm" selected>NASM 语法</option>
            <option value="gas">GAS/AT&T 语法</option>
        </select>
        <button class="btn-primary" onclick="assemble()">🔨 汇编 (ASM→BIN)</button>
        <button class="btn-primary" onclick="disassemble()">🔍 反汇编 (BIN→ASM)</button>
        <button class="btn-success" onclick="downloadBinary()">💾 下载ELF</button>
        <button class="btn-success" onclick="downloadAsm()">📄 下载ASM</button>
        <button class="btn-danger" onclick="clearAll()">🗑️ 清除</button>
    </div>

    <div class="progress-bar" id="progress-bar">
        <div class="fill" id="progress-fill"></div>
    </div>

    <div class="main-content">
        <!-- 左侧: 汇编代码面板 -->
        <div class="panel">
            <div class="panel-header">
                <h3>📝 汇编代码</h3>
                <span class="badge" id="asm-lines">0 行</span>
            </div>
            <div class="template-btns">
                <button class="template-btn" onclick="loadTemplate('hello64')">Hello World (64)</button>
                <button class="template-btn" onclick="loadTemplate('hello32')">Hello World (32)</button>
                <button class="te.........完整代码请登录后点击上方下载按钮下载查看

网友评论0