From 973f9e1cfbb73ccd70b4414c43bf6e3f5f273c13 Mon Sep 17 00:00:00 2001 From: liuwenlong Date: Mon, 22 Jul 2024 00:10:11 +0800 Subject: [PATCH] Support Harmony --- .idea/.gitignore | 8 ++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/modules.xml | 8 ++++++++ .idea/useragent.iml | 9 +++++++++ .idea/vcs.xml | 6 ++++++ ua.go | 10 ++++++++-- ua_test.go | 5 +++++ 7 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/useragent.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b85bfeb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/useragent.iml b/.idea/useragent.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/useragent.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ua.go b/ua.go index a292f9c..44b1a2d 100644 --- a/ua.go +++ b/ua.go @@ -34,6 +34,7 @@ const ( FreeBSD = "FreeBSD" ChromeOS = "ChromeOS" BlackBerry = "BlackBerry" + Harmony = "Harmony" Opera = "Opera" OperaMini = "Opera Mini" @@ -132,6 +133,11 @@ func Parse(userAgent string) UserAgent { ua.OS = BlackBerry ua.OSVersion = tokens.get("BlackBerry") ua.Mobile = true + + case tokens.exists("OpenHarmony"): + ua.OS = Harmony + ua.OSVersion = tokens.get("OpenHarmony") + ua.Mobile = true } switch { @@ -472,7 +478,7 @@ func checkVer(s string) (name, v string) { //v = s[i+1:] switch s[:i] { - case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android": + case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android", "OpenHarmony": return s[:i], s[i+1:] case "CrOS x86_64", "CrOS aarch64", "CrOS armv7l": j := strings.LastIndex(s[:i], " ") @@ -607,7 +613,7 @@ func (p properties) findBestMatch(withVerOnly bool) string { for i := 0; i < n; i++ { for _, prop := range p.list { switch prop.Key { - case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", "CrOS", "Tablet": + case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", "CrOS", "Tablet", "OpenHarmony": default: // don' pick if starts with number if len(prop.Key) != 0 && prop.Key[0] >= 48 && prop.Key[0] <= 57 { diff --git a/ua_test.go b/ua_test.go index fd88446..f514c01 100644 --- a/ua_test.go +++ b/ua_test.go @@ -153,6 +153,8 @@ var testTable = [][]string{ //{`${jndi:ldap://log4shell-generic-8ZnJfq2XFL3GWyaLyOpT${lower:ten}.w.nessus.org/nessus}`, "", "mobile", ua.Android}, // + {"Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile", "ArkWeb", "4.1.6.1", "mobile", ua.Harmony, ""}, + // // ${jndi:ldap://log4shell-generic-8ZnJfq2XFL3GWyaLyOpT${lower:ten}.w.nessus.org/nessus} @@ -258,6 +260,9 @@ func ExampleParse() { "Mozilla/5.0 (Linux; U; Android 4.3; en-us; GT-I9300 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", "Mozilla/5.0 (Linux; Android 6.0.1; SAMSUNG SM-A310F/A310FXXU2BQB1 Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.4 Chrome/51.0.2704.106 Mobile Safari/537.36", + + // Harmony + "Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile", } for _, s := range userAgents {