• golang 解析oracle 数据文件头


    1. package main
    2. import (
    3. "encoding/binary"
    4. "fmt"
    5. "io"
    6. "os"
    7. )
    8. // Powered by 黄林杰 15658655447
    9. // Usered for parser oracle datafile header block 1 ....
    10. // oracle 数据文件头块解析
    11. // KCBlockStruct represents the structure of the Oracle block
    12. type KCBlockStruct struct {
    13. TypeKCBH byte
    14. FrmtKCBH byte
    15. RDBAKCBH uint32
    16. ChkvalKCBH uint16
    17. KCCFHDBI uint32
    18. KCCFHDBNX []byte
    19. KCCFHCSQ uint32
    20. KCCFHFSZ uint32
    21. KCCFHFNO uint16
    22. KCCFHTYP uint16
    23. KCVFHRDB uint32
    24. KSCNBAS uint32
    25. KSCNWRP uint16
    26. KCVFHCRT uint32
    27. KCVFHRLC uint32
    28. KCVFHRLS struct {
    29. KSCNBAS uint32
    30. KSCNWRP uint16
    31. }
    32. KCVFHBSBSC struct {
    33. KSCNBAS uint32
    34. KSCNWRP uint16
    35. }
    36. KCVFHSTA uint16
    37. KCVFHCPC uint32
    38. KCVFHCCC uint32
    39. KCVFHTSN uint32
    40. KCVFHTLN uint16
    41. KCVFHTNM [30]byte
    42. KCVFHPRC uint32
    43. KCVFHPRS struct {
    44. KSCNBAS uint32
    45. KSCNWRP uint16
    46. }
    47. KCVCPSN struct {
    48. KSCNBAS uint32
    49. KSCNWRP uint16
    50. }
    51. KCVCPTime uint32
    52. KCVCPThr uint16
    53. KCVCPRA struct {
    54. KCRBASEQ uint32
    55. KCRBABNO uint32
    56. KCRBABOF uint32
    57. }
    58. // Add more fields based on your structure
    59. }
    60. func main() {
    61. // Open the Oracle data file
    62. file, err := os.Open("C:\\Users\\ZMI\\Desktop\\asm-diskb\\newoasm\\SYSTEM.260.1096299059.dbf")
    63. if err != nil {
    64. fmt.Println("Error opening file:", err)
    65. return
    66. }
    67. defer file.Close()
    68. // Read the first block (assuming 8192 bytes)
    69. blockSize := 8192
    70. block := make([]byte, blockSize)
    71. // 指定要读取的块号
    72. blockNumber := 1
    73. // 计算块的偏移量
    74. blockOffset := blockSize * blockNumber
    75. // 移动文件指针到块的起始位置
    76. _, err = file.Seek(int64(blockOffset), io.SeekStart)
    77. if err != nil {
    78. fmt.Println("Error seeking to block:", err)
    79. return
    80. }
    81. _, err = file.Read(block)
    82. if err != nil {
    83. fmt.Println("Error reading file:", err)
    84. return
    85. }
    86. hexString := fmt.Sprintf("%X", block)
    87. // 打印结果
    88. fmt.Println("oracle 8kb block Hexadecimal representation:", hexString)
    89. // Parse the block using the defined structure
    90. kcBlock := parseKCBlock(block)
    91. // Print the extracted information
    92. fmt.Printf("TypeKCBH: %X\n", kcBlock.TypeKCBH)
    93. fmt.Printf("FrmtKCBH: %X\n", kcBlock.FrmtKCBH)
    94. fmt.Printf("RDBAKCBH: %X\n", kcBlock.RDBAKCBH)
    95. // Print more fields as needed
    96. fmt.Printf("KCCFHDBI: %d\n", kcBlock.KCCFHDBI)
    97. fmt.Printf("KCCFHDBNX: %s\n", kcBlock.KCCFHDBNX)
    98. }
    99. func parseKCBlock(block []byte) KCBlockStruct {
    100. kcBlock := KCBlockStruct{
    101. TypeKCBH: block[0],
    102. FrmtKCBH: block[1],
    103. RDBAKCBH: binary.LittleEndian.Uint32(block[4:8]),
    104. // Parse more fields based on your structure
    105. KCCFHDBI: binary.LittleEndian.Uint32(block[28:32]),
    106. KCCFHDBNX: block[32:40],
    107. }
    108. return kcBlock
    109. }

    ##代码执行结果:

    ##下载地址:

    oracle11g数据文件头block1解析资源-CSDN文库

  • 相关阅读:
    c语言之字符串输入输出函数 puts函数,gets函数,strcat函数
    高频面试题1,删除有序数组重复元素
    Spring - FactoryBean扩展实战_MyBatis-Spring 启动过程源码解读
    centos7终端无图形界面安装tbb
    python带你采集不可言说网站数据,并带你多重骚操作~
    精通 Verilog HDL 设计之编码风格(5)顶层简洁化
    Mybatis的parameterType造成线程阻塞问题分析
    【PyTorch】Torchvision
    什么是Nginx?
    基于SpringBoot的“冬奥会科普平台”的设计与实现(源码+数据库+文档+PPT)
  • 原文地址:https://blog.csdn.net/royjj/article/details/134421174