package mainimport ("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 byteFrmtKCBH byteRDBAKCBH uint32ChkvalKCBH uint16KCCFHDBI uint32KCCFHDBNX []byteKCCFHCSQ uint32KCCFHFSZ uint32KCCFHFNO uint16KCCFHTYP uint16KCVFHRDB uint32KSCNBAS uint32KSCNWRP uint16KCVFHCRT uint32KCVFHRLC uint32KCVFHRLS struct {KSCNBAS uint32KSCNWRP uint16}KCVFHBSBSC struct {KSCNBAS uint32KSCNWRP uint16}KCVFHSTA uint16KCVFHCPC uint32KCVFHCCC uint32KCVFHTSN uint32KCVFHTLN uint16KCVFHTNM [30]byteKCVFHPRC uint32KCVFHPRS struct {KSCNBAS uint32KSCNWRP uint16}KCVCPSN struct {KSCNBAS uint32KSCNWRP uint16}KCVCPTime uint32KCVCPThr uint16KCVCPRA struct {KCRBASEQ uint32KCRBABNO uint32KCRBABOF uint32}// Add more fields based on your structure
}func main() {// Open the Oracle data filefile, 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 := 8192block := 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 structurekcBlock := parseKCBlock(block)// Print the extracted informationfmt.Printf("TypeKCBH: %X\n", kcBlock.TypeKCBH)fmt.Printf("FrmtKCBH: %X\n", kcBlock.FrmtKCBH)fmt.Printf("RDBAKCBH: %X\n", kcBlock.RDBAKCBH)// Print more fields as neededfmt.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 structureKCCFHDBI: binary.LittleEndian.Uint32(block[28:32]),KCCFHDBNX: block[32:40],}return kcBlock
}
##代码执行结果:
##下载地址:
oracle11g数据文件头block1解析资源-CSDN文库