package main
import (
"encoding/binary"
"fmt"
"io"
"os"
)
// Powered by 黄林杰 15658655447
// Usered for parser oracle datafile header block 1 ....
// oracle 数据文件头块解析
// KCBlockStruct represents the structure of the Oracle block
type KCBlockStruct struct {
TypeKCBH byte
FrmtKCBH byte
RDBAKCBH uint32
ChkvalKCBH uint16
KCCFHDBI uint32
KCCFHDBNX []byte
KCCFHCSQ uint32
KCCFHFSZ uint32
KCCFHFNO uint16
KCCFHTYP uint16
KCVFHRDB uint32
KSCNBAS uint32
KSCNWRP uint16
KCVFHCRT uint32
KCVFHRLC uint32
KCVFHRLS struct {
KSCNBAS uint32
KSCNWRP uint16
}
KCVFHBSBSC struct {
KSCNBAS uint32
KSCNWRP uint16
}
KCVFHSTA uint16
KCVFHCPC uint32
KCVFHCCC uint32
KCVFHTSN uint32
KCVFHTLN uint16
KCVFHTNM [30]byte
KCVFHPRC uint32
KCVFHPRS struct {
KSCNBAS uint32
KSCNWRP uint16
}
KCVCPSN struct {
KSCNBAS uint32
KSCNWRP uint16
}
KCVCPTime uint32
KCVCPThr uint16
KCVCPRA struct {
KCRBASEQ uint32
KCRBABNO uint32
KCRBABOF uint32
}
// Add more fields based on your structure
}
func main() {
// Open the Oracle data file
file, err := os.Open("C:\\Users\\ZMI\\Desktop\\asm-diskb\\newoasm\\SYSTEM.260.1096299059.dbf")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()
// Read the first block (assuming 8192 bytes)
blockSize := 8192
block := make([]byte, blockSize)
// 指定要读取的块号
blockNumber := 1
// 计算块的偏移量
blockOffset := blockSize * blockNumber
// 移动文件指针到块的起始位置
_, err = file.Seek(int64(blockOffset), io.SeekStart)
if err != nil {
fmt.Println("Error seeking to block:", err)
return
}
_, err = file.Read(block)
if err != nil {
fmt.Println("Error reading file:", err)
return
}
hexString := fmt.Sprintf("%X", block)
// 打印结果
fmt.Println("oracle 8kb block Hexadecimal representation:", hexString)
// Parse the block using the defined structure
kcBlock := parseKCBlock(block)
// Print the extracted information
fmt.Printf("TypeKCBH: %X\n", kcBlock.TypeKCBH)
fmt.Printf("FrmtKCBH: %X\n", kcBlock.FrmtKCBH)
fmt.Printf("RDBAKCBH: %X\n", kcBlock.RDBAKCBH)
// Print more fields as needed
fmt.Printf("KCCFHDBI: %d\n", kcBlock.KCCFHDBI)
fmt.Printf("KCCFHDBNX: %s\n", kcBlock.KCCFHDBNX)
}
func parseKCBlock(block []byte) KCBlockStruct {
kcBlock := KCBlockStruct{
TypeKCBH: block[0],
FrmtKCBH: block[1],
RDBAKCBH: binary.LittleEndian.Uint32(block[4:8]),
// Parse more fields based on your structure
KCCFHDBI: binary.LittleEndian.Uint32(block[28:32]),
KCCFHDBNX: block[32:40],
}
return kcBlock
}
##代码执行结果:
##下载地址:
oracle11g数据文件头block1解析资源-CSDN文库