netcore.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. package ebpftracer
  2. import (
  3. "bufio"
  4. "bytes"
  5. "errors"
  6. "io"
  7. "log"
  8. "os"
  9. "strconv"
  10. "strings"
  11. "debug/dwarf"
  12. "debug/elf"
  13. debugelf "debug/elf"
  14. "fmt"
  15. "github.com/cilium/ebpf/link"
  16. )
  17. const (
  18. // goServeHTTP = "net/http.serverHandler.ServeHTTP"
  19. // binPath = "/root/code/jdk8u/build/linux-x86_64-normal-server-release/jdk/lib/amd64/libnio.so"
  20. netcoresymbolsocketRead0 = "SystemNative_Receive"
  21. )
  22. type MemoryMap struct {
  23. Start, End uint64
  24. }
  25. func ReadFirstLineOfMapsFile(pid string) (*MemoryMap, error) {
  26. file, err := os.Open(fmt.Sprintf("/proc/%s/maps", pid))
  27. if err != nil {
  28. return nil, err
  29. }
  30. defer file.Close()
  31. scanner := bufio.NewScanner(file)
  32. if scanner.Scan() {
  33. fields := strings.Fields(scanner.Text())
  34. addresses := strings.Split(fields[0], "-")
  35. if len(addresses) != 2 {
  36. return nil, errors.New("unexpected format in /proc/<pid>/maps")
  37. }
  38. start, err := strconv.ParseUint(addresses[0], 16, 64)
  39. if err != nil {
  40. return nil, err
  41. }
  42. end, err := strconv.ParseUint(addresses[1], 16, 64)
  43. if err != nil {
  44. return nil, err
  45. }
  46. return &MemoryMap{
  47. Start: start,
  48. End: end,
  49. }, nil
  50. }
  51. if err := scanner.Err(); err != nil {
  52. return nil, err
  53. }
  54. return nil, errors.New("empty /proc/<pid>/maps")
  55. }
  56. func (t *Tracer) getFunctionOffsetDBG(libPath, functionName string) (elf.Symbol, error) {
  57. dwarfFile, err := elf.Open(libPath)
  58. dwarfData, err := dwarfFile.DWARF()
  59. if err != nil {
  60. log.Fatal(err)
  61. }
  62. type uprobesDef struct {
  63. Name string
  64. Offset uint64
  65. EntAddress uint64
  66. RetAddress uint64
  67. }
  68. listEntry := make(map[dwarf.Offset]uprobesDef)
  69. SpecListEntry := []dwarf.Entry{}
  70. entryReader := dwarfData.Reader()
  71. for {
  72. entry, err := entryReader.Next()
  73. if err == io.EOF {
  74. // We've reached the end of DWARF entries
  75. break
  76. }
  77. if err != nil {
  78. log.Fatalf("Error reading entry: %v", err)
  79. }
  80. if entry == nil {
  81. log.Println("Warning: a nil entry was returned with no error")
  82. break
  83. }
  84. if entry.Tag == dwarf.TagSubprogram {
  85. // fmt.Printf("entry address: %x, %d\n", entry.Offset, entry.Children)
  86. funName, _ := entry.Val(dwarf.AttrName).(string)
  87. if functionName == funName {
  88. entAddress, _ := entry.Val(dwarf.AttrLowpc).(uint64)
  89. retAddress, _ := entry.Val(dwarf.AttrHighpc).(uint64)
  90. fmt.Printf("Function %s address: %x, %x, %x\n", funName, entAddress, entry.Offset, retAddress)
  91. uprobes := uprobesDef{}
  92. uprobes.EntAddress = entAddress
  93. uprobes.RetAddress = retAddress
  94. uprobes.Offset = uint64(entry.Offset)
  95. uprobes.Name = funName
  96. listEntry[entry.Offset] = uprobes
  97. }
  98. specAddr, _ := entry.Val(dwarf.AttrSpecification).(dwarf.Offset)
  99. lowpc := entry.Val(dwarf.AttrLowpc)
  100. if lowpc != nil && specAddr > 0 && lowpc.(uint64) > 0 {
  101. // fmt.Printf("AttrSpecification address: %x, %x\n", specAddr, entry.Offset)
  102. SpecListEntry = append(SpecListEntry, *entry)
  103. }
  104. }
  105. }
  106. for _, v := range SpecListEntry {
  107. specAddr, _ := v.Val(dwarf.AttrSpecification).(dwarf.Offset)
  108. // fmt.Printf("SpecListEntrySpecListEntrySpecListEntry Attach Function: %x\n", specAddr)
  109. _, ok := listEntry[specAddr]
  110. if ok {
  111. vv := listEntry[specAddr]
  112. entAddr := v.Val(dwarf.AttrLowpc)
  113. if entAddr != nil {
  114. vv.EntAddress = entAddr.(uint64)
  115. }
  116. retAddr := v.Val(dwarf.AttrHighpc)
  117. if retAddr != nil {
  118. switch retAddr.(type) {
  119. case uint64:
  120. vv.RetAddress = uint64(retAddr.(uint64))
  121. case int64:
  122. vv.RetAddress = uint64(retAddr.(int64))
  123. default:
  124. fmt.Println("Unknown type")
  125. }
  126. }
  127. listEntry[specAddr] = vv
  128. }
  129. }
  130. for _, v := range listEntry {
  131. sSize := v.RetAddress
  132. if v.RetAddress > v.EntAddress {
  133. sSize = v.RetAddress - v.EntAddress
  134. }
  135. symbol := elf.Symbol{}
  136. symbol.Name = v.Name
  137. symbol.Value = v.EntAddress
  138. symbol.Size = 180
  139. fmt.Printf("Need Attach Function %s address: %x, %x, %d\n", v.Name, v.EntAddress, v.RetAddress, sSize)
  140. return symbol, nil
  141. }
  142. return elf.Symbol{}, fmt.Errorf("function %s not found", functionName)
  143. }
  144. func (t *Tracer) AttachNetCoreNetReadUprobes(pid uint32) ([]link.Link, error) {
  145. if t.DisableL7Tracing() {
  146. return nil, nil
  147. }
  148. libPath := "/data/NET8/CoreAoT/bin/Debug/net8.0/linux-x64/publish/CoreAoT"
  149. var links []link.Link
  150. ex, err := link.OpenExecutable(libPath)
  151. // 获取函数的偏移量
  152. functionSym, err := t.getFunctionOffsetDBG(libPath+".dbg", netcoresymbolsocketRead0)
  153. l, err := ex.Uprobe(functionSym.Name, t.uprobes["SystemNative_Receive"], &link.UprobeOptions{Address: functionSym.Value, Offset: 113})
  154. if err != nil {
  155. fmt.Println("failed to attach SystemNative_Receive uprobe", err, functionSym)
  156. return nil, err
  157. }
  158. links = append(links, l)
  159. if len(links) == 0 {
  160. return nil, nil
  161. }
  162. fmt.Println("netcore uprobes attached, pid is ", pid)
  163. return links, nil
  164. }
  165. func (t *Tracer) AttachNetCoreNetWriteUprobes(pid uint32) ([]link.Link, error) {
  166. if t.DisableL7Tracing() {
  167. return nil, nil
  168. }
  169. //
  170. //if pid != 251719 {
  171. // return nil
  172. //}
  173. var libnetSo = "/data/roger/han/libmylib.so"
  174. var sys = "asmnop"
  175. var links []link.Link
  176. ex, err := link.OpenExecutable(libnetSo)
  177. if err != nil {
  178. return nil, err
  179. }
  180. opt := link.UprobeOptions{
  181. Offset: 16,
  182. PID: int(pid),
  183. }
  184. upread02, err := ex.Uprobe(sys, t.uprobes["netcore_asmnop"], &opt)
  185. if err != nil {
  186. return nil, err
  187. }
  188. links = append(links, upread02)
  189. if len(links) == 0 {
  190. return nil, nil
  191. }
  192. fmt.Println("netcore client uprobes attached", pid)
  193. return links, nil
  194. }
  195. func contains(array []string, str string) bool {
  196. for _, v := range array {
  197. if v == str {
  198. return true
  199. }
  200. }
  201. return false
  202. }
  203. func SplitByteByDelimiter(data []byte) []byte {
  204. pre := data[:4]
  205. data = data[4:]
  206. // 查找两个字节序列的位置
  207. index1 := bytes.Index(data, []byte{0x55, 0x48, 0x83, 0xEC})
  208. index2 := bytes.Index(data, []byte{0x55, 0x48, 0x81, 0xEC})
  209. // 如果两个都没有找到,返回 nil
  210. if index1 == -1 && index2 == -1 {
  211. return nil
  212. }
  213. // 确定哪个字节序列在前
  214. var startIndex int
  215. if index1 == -1 {
  216. // 只有index2找到了
  217. startIndex = index2
  218. } else if index2 == -1 {
  219. // 只有index1找到了
  220. startIndex = index1
  221. } else {
  222. // 两个都找到了,选择较小的那个
  223. startIndex = min(index1, index2)
  224. }
  225. // 返回从开始到选定的起始位置之前的数据
  226. return append(pre, data[:startIndex]...)
  227. }
  228. func (t *Tracer) AttachNetCoreNetThreadUprobes(pid uint32) []link.Link {
  229. // uprobes := []tracer.Uprobe{}
  230. libPath := "/data/NET8/CoreAoT/bin/Debug/net8.0/linux-x64/publish/CoreAoT"
  231. binFile, err := os.Open(libPath + ".dbg")
  232. binFile2, err := os.Open(libPath)
  233. if err != nil {
  234. return nil
  235. }
  236. // cache := map[string]interface{}{}
  237. // 解析 elf 文件
  238. elfFile, _ := debugelf.NewFile(binFile)
  239. elfFile2, _ := debugelf.NewFile(binFile2)
  240. // 获取所有符号表
  241. symbols, _ := elfFile.Symbols()
  242. ex, err := link.OpenExecutable(libPath)
  243. words := []string{
  244. "Microsoft_AspNetCore_Server_Kestrel_Core_Microsoft_AspNetCore_Server_Kestrel_Core_Internal_HttpConnectionMiddleware_1<System___Canon>__OnConnectionAsync", "Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__DoSend_d__28__MoveNext", "System_Net_Http_System_Net_Http_HttpClient__SendAsync_2",
  245. "System_Net_Http_System_Net_Http_HttpConnection__SendAsync_d__57__MoveNext",
  246. "Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__Start"}
  247. wordsType := map[string]string{
  248. "Microsoft_AspNetCore_Server_Kestrel_Core_Microsoft_AspNetCore_Server_Kestrel_Core_Internal_HttpConnectionMiddleware_1<System___Canon>__OnConnectionAsync": "OnConnectionAsync",
  249. "Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__DoSend_d__28__MoveNext": "DoSend",
  250. "System_Net_Http_System_Net_Http_HttpClient__SendAsync_2": "SendAsync1",
  251. "System_Net_Http_System_Net_Http_HttpConnection__SendAsync_d__57__MoveNext": "SendAsync2",
  252. "Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__Start": "SocketConnectionStart"}
  253. textSection := elfFile2.Section("__managedcode")
  254. textSectionData, err := textSection.Data()
  255. if err != nil {
  256. fmt.Println("failed to read text section", err)
  257. return nil
  258. }
  259. if textSection == nil {
  260. fmt.Println("no text section", nil)
  261. return nil
  262. }
  263. textSectionLen := uint64(len(textSectionData) - 1)
  264. fmt.Printf("textSectionLen %x, %x, %x\n", textSectionLen, textSection.Addr, textSection.Size)
  265. var links []link.Link
  266. for _, sym := range symbols {
  267. exists := contains(words, sym.Name)
  268. if exists {
  269. fmt.Println("dddddddd:", sym.Name, sym.Value, sym.Size, sym.Info, sym)
  270. address := sym.Value
  271. sStart := sym.Value - textSection.Addr
  272. sEnd := sStart + sym.Size
  273. if sym.Size == 0 {
  274. sEnd = sStart + 5000
  275. }
  276. if sEnd > textSectionLen {
  277. fmt.Println("no text section333", nil)
  278. continue
  279. }
  280. sBytes := textSectionData[sStart:sEnd]
  281. if sym.Size == 0 {
  282. sBytes = SplitByteByDelimiter(sBytes)
  283. }
  284. fmt.Printf("dddddddd+++++: %s, %x, %d, %x, %s\n", sym.Name, sym.Value, sym.Size, address, wordsType[sym.Name])
  285. l, err := ex.Uprobe("", t.uprobes[wordsType[sym.Name]+"Start"], &link.UprobeOptions{Address: address})
  286. if err != nil {
  287. fmt.Println("failed to attach uprobe", err, wordsType[sym.Name])
  288. // return nil
  289. }
  290. links = append(links, l)
  291. returnOffsets := getReturnOffsets(elfFile.Machine, sBytes)
  292. for _, offset := range returnOffsets {
  293. fmt.Printf("dddddddd----: %s, %x, %d, %x\n", sym.Name, sym.Value, sym.Size, offset)
  294. l, err := ex.Uprobe("", t.uprobes[wordsType[sym.Name]+"End"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
  295. if err != nil {
  296. fmt.Println("failed to attach uprobe", err, wordsType[sym.Name])
  297. // return nil
  298. }
  299. links = append(links, l)
  300. }
  301. }
  302. }
  303. if len(links) == 0 {
  304. return nil
  305. }
  306. fmt.Println("netcore uprobes OnConnectionAsyncStart attached, pid is ", pid)
  307. return links
  308. }
  309. // func (t *Tracer) AttachNetCoreNetOnConnectionAsyncStartUprobes(pid uint32, insID utils.ID) []link.Link {
  310. // if t.disableL7Tracing {
  311. // return nil
  312. // }
  313. // var links []link.Link
  314. // ex, err := link.OpenExecutable(libPath)
  315. // // 获取函数的偏移量
  316. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  317. // var addr uint64 = 0x96d700 // Microsoft_AspNetCore_Server_Kestrel_Core_Microsoft_AspNetCore_Server_Kestrel_Core_Internal_HttpConnectionMiddleware_1<System___Canon>__OnConnectionAsync 入口处
  318. // // var addr uint64 = 0x96dc15
  319. // l, err := ex.Uprobe("", t.uprobes["OnConnectionAsyncStart"], &link.UprobeOptions{Address: addr})
  320. // if err != nil {
  321. // fmt.Println("failed to attach OnConnectionAsyncStart uprobe", err)
  322. // return nil
  323. // }
  324. // links = append(links, l)
  325. // if len(links) == 0 {
  326. // return nil
  327. // }
  328. // fmt.Println("netcore uprobes OnConnectionAsyncStart attached, pid is ", pid)
  329. // return links
  330. // }
  331. // func (t *Tracer) AttachNetCoreNetOnConnectionAsyncEndUprobes(pid uint32, insID utils.ID) []link.Link {
  332. // if t.disableL7Tracing {
  333. // return nil
  334. // }
  335. // var links []link.Link
  336. // ex, err := link.OpenExecutable(libPath)
  337. // // 获取函数的偏移量
  338. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  339. // var addr uint64 = 0x96dcbf
  340. // l, err := ex.Uprobe("", t.uprobes["OnConnectionAsyncEnd"], &link.UprobeOptions{Address: addr})
  341. // if err != nil {
  342. // fmt.Println("failed to attach OnConnectionAsyncEnd uprobe", err)
  343. // return nil
  344. // }
  345. // links = append(links, l)
  346. // if len(links) == 0 {
  347. // return nil
  348. // }
  349. // fmt.Println("netcore uprobes OnConnectionAsyncEnd attached, pid is ", pid)
  350. // return links
  351. // }
  352. // func (t *Tracer) AttachNetCoreNetDoSendStartUprobes(pid uint32, insID utils.ID) []link.Link {
  353. // if t.disableL7Tracing {
  354. // return nil
  355. // }
  356. // var links []link.Link
  357. // ex, err := link.OpenExecutable(libPath)
  358. // // 获取函数的偏移量
  359. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  360. // var addr uint64 = 0x260b40 // Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__DoSend_d__28__MoveNext 入口处
  361. // l, err := ex.Uprobe("", t.uprobes["DoSendStart"], &link.UprobeOptions{Address: addr})
  362. // if err != nil {
  363. // fmt.Println("failed to attach DoSendStart uprobe", err)
  364. // return nil
  365. // }
  366. // links = append(links, l)
  367. // if len(links) == 0 {
  368. // return nil
  369. // }
  370. // fmt.Println("netcore uprobes DoSendStart attached, pid is ", pid)
  371. // return links
  372. // }
  373. // func (t *Tracer) AttachNetCoreNetDoSendEndUprobes(pid uint32, insID utils.ID) []link.Link {
  374. // if t.disableL7Tracing {
  375. // return nil
  376. // }
  377. // var links []link.Link
  378. // ex, _ := link.OpenExecutable(libPath)
  379. // // 获取函数的偏移量
  380. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  381. // var addrArray = []uint64{0x26125d, 0x261295, 0x2612fd, 0x261396, 0x2613f4}
  382. // for _, addr := range addrArray {
  383. // l, err := ex.Uprobe("", t.uprobes["DoSendEnd"], &link.UprobeOptions{Address: addr})
  384. // if err != nil {
  385. // fmt.Println("failed to attach DoSendEnd uprobe", err)
  386. // return nil
  387. // }
  388. // links = append(links, l)
  389. // }
  390. // if len(links) == 0 {
  391. // return nil
  392. // }
  393. // fmt.Println("netcore uprobes DoSendEnd attached, pid is ", pid)
  394. // return links
  395. // }
  396. // func (t *Tracer) AttachNetCoreNetSendAsync1Uprobes(pid uint32, insID utils.ID) []link.Link {
  397. // if t.disableL7Tracing {
  398. // return nil
  399. // }
  400. // var links []link.Link
  401. // ex, err := link.OpenExecutable(libPath)
  402. // // 获取函数的偏移量
  403. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  404. // var addr uint64 = 0x32ab70 // System_Net_Http_System_Net_Http_HttpClient__SendAsync_2 入口处
  405. // l, err := ex.Uprobe("", t.uprobes["SendAsync1"], &link.UprobeOptions{Address: addr})
  406. // if err != nil {
  407. // fmt.Println("failed to attach SendAsync1 uprobe", err)
  408. // return nil
  409. // }
  410. // links = append(links, l)
  411. // if len(links) == 0 {
  412. // return nil
  413. // }
  414. // fmt.Println("netcore uprobes SendAsync1 attached, pid is ", pid)
  415. // return links
  416. // }
  417. // func (t *Tracer) AttachNetCoreNetSendAsync2Uprobes(pid uint32, insID utils.ID) []link.Link {
  418. // if t.disableL7Tracing {
  419. // return nil
  420. // }
  421. // var links []link.Link
  422. // ex, err := link.OpenExecutable(libPath)
  423. // // 获取函数的偏移量
  424. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  425. // var addr uint64 = 0x34ce90 // System_Net_Http_System_Net_Http_HttpConnection__SendAsync_d__57__MoveNext 入口处
  426. // l, err := ex.Uprobe("", t.uprobes["SendAsync2"], &link.UprobeOptions{Address: addr})
  427. // if err != nil {
  428. // fmt.Println("failed to attach SendAsync2 uprobe", err)
  429. // return nil
  430. // }
  431. // links = append(links, l)
  432. // if len(links) == 0 {
  433. // return nil
  434. // }
  435. // fmt.Println("netcore uprobes SendAsync2 attached, pid is ", pid)
  436. // return links
  437. // }
  438. // func (t *Tracer) AttachNetCoreNetSendAsync2EndUprobes(pid uint32, insID utils.ID) []link.Link {
  439. // if t.disableL7Tracing {
  440. // return nil
  441. // }
  442. // var links []link.Link
  443. // ex, _ := link.OpenExecutable(libPath)
  444. // // 获取函数的偏移量
  445. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  446. // var addrArray = []uint64{0x34f56c, 0x34f5af, 0x34f649, 0x34f6e3}
  447. // for _, addr := range addrArray {
  448. // l, err := ex.Uprobe("", t.uprobes["SendAsync2End"], &link.UprobeOptions{Address: addr})
  449. // if err != nil {
  450. // fmt.Println("failed to attach SendAsync2End uprobe", err)
  451. // return nil
  452. // }
  453. // links = append(links, l)
  454. // }
  455. // if len(links) == 0 {
  456. // return nil
  457. // }
  458. // fmt.Println("netcore uprobes SendAsync2End attached, pid is ", pid)
  459. // return links
  460. // }
  461. // func (t *Tracer) AttachNetCoreNetSocketConnectionStartStartUprobes(pid uint32, insID utils.ID) []link.Link {
  462. // if t.disableL7Tracing {
  463. // return nil
  464. // }
  465. // var links []link.Link
  466. // ex, err := link.OpenExecutable(libPath)
  467. // var addr uint64 = 0x25c4c0 // Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Microsoft_AspNetCore_Server_Kestrel_Transport_Sockets_Internal_SocketConnection__Start 入口处
  468. // l, err := ex.Uprobe("", t.uprobes["SocketConnectionStartStart"], &link.UprobeOptions{Address: addr})
  469. // if err != nil {
  470. // fmt.Println("failed to attach SocketConnectionStartStart uprobe", err)
  471. // return nil
  472. // }
  473. // links = append(links, l)
  474. // if len(links) == 0 {
  475. // return nil
  476. // }
  477. // fmt.Println("netcore uprobes SocketConnectionStartStart attached, pid is ", pid)
  478. // return links
  479. // }
  480. // func (t *Tracer) AttachNetCoreNetSocketConnectionStartEndUprobes(pid uint32, insID utils.ID) []link.Link {
  481. // if t.disableL7Tracing {
  482. // return nil
  483. // }
  484. // var links []link.Link
  485. // ex, _ := link.OpenExecutable(libPath)
  486. // // 获取函数的偏移量
  487. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  488. // var addrArray = []uint64{0x25c54e, 0x25c5c7}
  489. // for _, addr := range addrArray {
  490. // l, err := ex.Uprobe("", t.uprobes["SocketConnectionStartEnd"], &link.UprobeOptions{Address: addr})
  491. // if err != nil {
  492. // fmt.Println("failed to attach SocketConnectionStartEnd uprobe", err)
  493. // return nil
  494. // }
  495. // links = append(links, l)
  496. // }
  497. // if len(links) == 0 {
  498. // return nil
  499. // }
  500. // fmt.Println("netcore uprobes SocketConnectionStartEnd attached, pid is ", pid)
  501. // return links
  502. // }
  503. // func (t *Tracer) AttachNetCoreNetThreadUprobes(pid uint32, insID utils.ID) []link.Link {
  504. // if t.disableL7Tracing {
  505. // return nil
  506. // }
  507. // var links []link.Link
  508. // ex, err := link.OpenExecutable(libPath)
  509. // // 获取函数的偏移量
  510. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  511. // fmt.Println("netcore uprobes AttachNetCoreNetThreadUprobes hook value, pid is ", functionSym.Value)
  512. // var addr uint64 = 0x97b766
  513. // l, err := ex.Uprobe("", t.uprobes["AcceptConnectionsAsync"], &link.UprobeOptions{Address: addr})
  514. // if err != nil {
  515. // fmt.Println("failed to attach AcceptConnectionsAsync uprobe", err)
  516. // return nil
  517. // }
  518. // links = append(links, l)
  519. // if len(links) == 0 {
  520. // return nil
  521. // }
  522. // fmt.Println("netcore uprobes AcceptConnectionsAsync attached, pid is ", pid)
  523. // return links
  524. // }
  525. // func (t *Tracer) AttachNetCoreNetCreateContextStartUprobes(pid uint32, insID utils.ID) []link.Link {
  526. // if t.disableL7Tracing {
  527. // return nil
  528. // }
  529. // var links []link.Link
  530. // ex, err := link.OpenExecutable(libPath)
  531. // // 获取函数的偏移量
  532. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  533. // var addr uint64 = 0x97b60a
  534. // l, err := ex.Uprobe("", t.uprobes["CreateContextStart"], &link.UprobeOptions{Address: addr})
  535. // if err != nil {
  536. // fmt.Println("failed to attach CreateContextStart uprobe", err)
  537. // return nil
  538. // }
  539. // links = append(links, l)
  540. // if len(links) == 0 {
  541. // return nil
  542. // }
  543. // fmt.Println("netcore uprobes CreateContextStart attached, pid is ", pid)
  544. // return links
  545. // }
  546. // func (t *Tracer) AttachNetCoreNetReceiveStartUprobes(pid uint32, insID utils.ID) []link.Link {
  547. // if t.disableL7Tracing {
  548. // return nil
  549. // }
  550. // var links []link.Link
  551. // ex, err := link.OpenExecutable(libPath)
  552. // // 获取函数的偏移量
  553. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  554. // var addr uint64 = 0xec7d0
  555. // l, err := ex.Uprobe("", t.uprobes["ReceiveStart"], &link.UprobeOptions{Address: addr})
  556. // if err != nil {
  557. // fmt.Println("failed to attach ReceiveStart uprobe", err)
  558. // return nil
  559. // }
  560. // links = append(links, l)
  561. // if len(links) == 0 {
  562. // return nil
  563. // }
  564. // fmt.Println("netcore uprobes ReceiveStart attached, pid is ", pid)
  565. // return links
  566. // }
  567. // func (t *Tracer) AttachNetCoreNetReceiveEndUprobes(pid uint32, insID utils.ID) []link.Link {
  568. // if t.disableL7Tracing {
  569. // return nil
  570. // }
  571. // var links []link.Link
  572. // ex, err := link.OpenExecutable(libPath)
  573. // // 获取函数的偏移量
  574. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  575. // var addr uint64 = 0xec86e
  576. // l, err := ex.Uprobe("", t.uprobes["ReceiveEnd"], &link.UprobeOptions{Address: addr})
  577. // if err != nil {
  578. // fmt.Println("failed to attach ReceiveEnd uprobe", err)
  579. // return nil
  580. // }
  581. // links = append(links, l)
  582. // if len(links) == 0 {
  583. // return nil
  584. // }
  585. // fmt.Println("netcore uprobes ReceiveEnd attached, pid is ", pid)
  586. // return links
  587. // }
  588. // func (t *Tracer) AttachNetCoreNetSendStartUprobes(pid uint32, insID utils.ID) []link.Link {
  589. // if t.disableL7Tracing {
  590. // return nil
  591. // }
  592. // var links []link.Link
  593. // ex, err := link.OpenExecutable(libPath)
  594. // // 获取函数的偏移量
  595. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  596. // var addr uint64 = 0xeca40
  597. // l, err := ex.Uprobe("", t.uprobes["SendStart"], &link.UprobeOptions{Address: addr})
  598. // if err != nil {
  599. // fmt.Println("failed to attach SendStart uprobe", err)
  600. // return nil
  601. // }
  602. // links = append(links, l)
  603. // if len(links) == 0 {
  604. // return nil
  605. // }
  606. // fmt.Println("netcore uprobes SendStart attached, pid is ", pid)
  607. // return links
  608. // }
  609. // func (t *Tracer) AttachNetCoreNetSendEndUprobes(pid uint32, insID utils.ID) []link.Link {
  610. // if t.disableL7Tracing {
  611. // return nil
  612. // }
  613. // var links []link.Link
  614. // ex, err := link.OpenExecutable(libPath)
  615. // // 获取函数的偏移量
  616. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  617. // var addr uint64 = 0xecad1
  618. // l, err := ex.Uprobe("", t.uprobes["SendEnd"], &link.UprobeOptions{Address: addr})
  619. // if err != nil {
  620. // fmt.Println("failed to attach SendEnd uprobe", err)
  621. // return nil
  622. // }
  623. // links = append(links, l)
  624. // if len(links) == 0 {
  625. // return nil
  626. // }
  627. // fmt.Println("netcore uprobes SendEnd attached, pid is ", pid)
  628. // return links
  629. // }
  630. // func (t *Tracer) AttachNetCoreNetDoReceiveStartUprobes(pid uint32, insID utils.ID) []link.Link {
  631. // if t.disableL7Tracing {
  632. // return nil
  633. // }
  634. // var links []link.Link
  635. // ex, err := link.OpenExecutable(libPath)
  636. // // 获取函数的偏移量
  637. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  638. // var addr uint64 = 0x260150
  639. // l, err := ex.Uprobe("", t.uprobes["DoReceiveStart"], &link.UprobeOptions{Address: addr})
  640. // if err != nil {
  641. // fmt.Println("failed to attach DoReceiveStart uprobe", err)
  642. // return nil
  643. // }
  644. // links = append(links, l)
  645. // if len(links) == 0 {
  646. // return nil
  647. // }
  648. // fmt.Println("netcore uprobes DoReceiveStart attached, pid is ", pid)
  649. // return links
  650. // }
  651. // func (t *Tracer) AttachNetCoreNetDoReceiveEndUprobes(pid uint32, insID utils.ID) []link.Link {
  652. // if t.disableL7Tracing {
  653. // return nil
  654. // }
  655. // var links []link.Link
  656. // ex, _ := link.OpenExecutable(libPath)
  657. // // 获取函数的偏移量
  658. // // memoryMap, _ := ReadFirstLineOfMapsFile(strconv.Itoa(int(pid)))
  659. // var addrArray = []uint64{0x2609ed, 0x260a4f, 0x260aa3, 0x260adb, 0x260b33}
  660. // for _, addr := range addrArray {
  661. // l, err := ex.Uprobe("", t.uprobes["DoReceiveEnd"], &link.UprobeOptions{Address: addr})
  662. // if err != nil {
  663. // fmt.Println("failed to attach DoReceiveEnd uprobe", err)
  664. // return nil
  665. // }
  666. // links = append(links, l)
  667. // }
  668. // if len(links) == 0 {
  669. // return nil
  670. // }
  671. // fmt.Println("netcore uprobes DoReceiveEnd attached, pid is ", pid)
  672. // return links
  673. // }