netcore.go 23 KB

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