ลำดับไบต์และการเรียงลำดับไบต์
ทำความเข้าใจว่าค่าแบบหลายไบต์ถูกจัดวางในหน่วยความจำและไฟล์อย่างไร เหตุใดลำดับไบต์จึงทำให้ผู้เริ่มต้นสับสน และวิธีอ่านไบต์ดิบอย่างถูกต้อง
ลำดับไบต์และการเรียงลำดับไบต์ เป็นบทเรียน Reverse Engineering & Binary Analysis Basics ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Reverse Engineering & Binary Analysis Basics และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Reverse Engineering & Binary Analysis Basics มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Bytes Have an Order
You learned how data is represented in binaries. But a number like 0x12345678 occupies four bytes, and the CPU must decide which byte comes first in memory.
That decision is called endianness.
Little-Endian
In little-endian, the least significant byte is stored first (lowest address).
The value 0x12345678 is stored as the bytes 78 56 34 12. x86, x64, and most ARM systems use little-endian.
Value: 0x12345678
Memory: 78 56 34 12 (low -> high address)Big-Endian
In big-endian, the most significant byte is stored first.
The same value 0x12345678 is stored as 12 34 56 78. Network protocols and some older RISC chips use big-endian, so it is also called network byte order.
Value: 0x12345678
Memory: 12 34 56 78 (low -> high address)Why It Matters in RE
When you see raw bytes in a hex editor, you must apply the correct endianness to recover the real value. Misreading endianness turns a valid pointer into garbage.
- Reading addresses
- Parsing file headers
- Interpreting struct fields
Reading a 4-Byte Integer
Suppose a hex dump shows the bytes 2A 00 00 00. On a little-endian machine that is the integer 42, not 0x2A000000.
Always know the platform before interpreting.
Bytes: 2A 00 00 00
LE int: 0x0000002A = 42
BE int: 0x2A000000 = 704643072Seeing It in Code
This C snippet inspects the running machine's endianness by aliasing an int through a byte pointer.
#include <stdio.h>
int main(void) {
unsigned int x = 0x12345678;
unsigned char *p = (unsigned char *)&x;
printf('First byte: %02X\n', p[0]);
return 0;
}Network Byte Order
Protocols standardize on big-endian so machines of different architectures agree. C provides conversion helpers like htons and ntohl.
When reversing network code, watch for these calls; they reveal which fields are multi-byte.
uint16_t port = htons(8080); // host -> network orderByte Swapping
Converting between endian formats means reversing the byte order. Tools and disassemblers often offer a one-click swap, but understanding the mechanism is essential.
uint32_t swap32(uint32_t v) {
return ((v & 0xFF) << 24) |
((v & 0xFF00) << 8) |
((v >> 8) & 0xFF00) |
((v >> 24) & 0xFF);
}Endianness in File Formats
Many file formats declare their endianness in a magic field. ELF stores EI_DATA in its header; TIFF starts with II (Intel/little) or MM (Motorola/big).
Reading this field first tells you how to parse the rest.
Common Pitfalls
Beginners often:
- Read bytes left-to-right and forget to reverse for little-endian
- Assume the target matches their own machine
- Mix endianness mid-struct
When a pointer looks absurd, suspect endianness first.
Tools That Show Endianness
Most analysis tools let you toggle interpretation. In a hex editor you can flip between little- and big-endian data inspectors; disassemblers display the architecture's native order automatically.
When carving raw structures, always confirm the tool's current setting matches the target.
xxd -l 4 sample.bin
# 00000000: 2a00 0000 -> LE int = 42Quick Check
How is the value 0x12345678 stored on a little-endian machine?
Recap
Endianness decides byte order for multi-byte values:
- Little-endian: least significant byte first (x86/x64)
- Big-endian: most significant first (network order)
- Check the format's endianness field before parsing
Mastering this stops the most common 'garbage value' confusion in binary analysis.
คำถามที่พบบ่อย
บทเรียน “ลำดับไบต์และการเรียงลำดับไบต์” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ลำดับไบต์และการเรียงลำดับไบต์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Reverse Engineering & Binary Analysis Basics ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Reverse Engineering & Binary Analysis Basics มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ลำดับไบต์และการเรียงลำดับไบต์”
ทำความเข้าใจว่าค่าแบบหลายไบต์ถูกจัดวางในหน่วยความจำและไฟล์อย่างไร เหตุใดลำดับไบต์จึงทำให้ผู้เริ่มต้นสับสน และวิธีอ่านไบต์ดิบอย่างถูกต้อง คุณปฏิบัติ Reverse Engineering & Binary Analysis Basics ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Reverse Engineering & Binary Analysis Basics หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Reverse Engineering & Binary Analysis Basics บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ลำดับไบต์และการเรียงลำดับไบต์” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Reverse Engineering & Binary Analysis Basics นี้ได้ไหม
ได้ บทเรียน Reverse Engineering & Binary Analysis Basics ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ภาพรวมสถาปัตยกรรม CPU
- การแทนข้อมูลในไบนารี
- รูปแบบไฟล์ไบนารีทั่วไป
- ลำดับไบต์และการเรียงลำดับไบต์