diff --git a/pkg/msbimport/import_kakao.go b/pkg/msbimport/import_kakao.go index d525d216f..de3cdf24a 100644 --- a/pkg/msbimport/import_kakao.go +++ b/pkg/msbimport/import_kakao.go @@ -10,7 +10,8 @@ import ( "os/exec" "path" "path/filepath" - "strings" + "regexp" + "strconv" log "github.com/sirupsen/logrus" ) @@ -192,11 +193,24 @@ func fetchKakaoDetailsFromShareLink(link string) (string, string, error) { log.Errorln("fetchKakaoDetailsFromShareLink: failed httpGetAndroidUA!", err) return "", "", err } - split1 := strings.Split(res, "kakaotalk://store/emoticon/") - if len(split1) < 2 { + + eidRegex := regexp.MustCompile(`data-i="(\d+)"`) + rawEid := eidRegex.FindStringSubmatch(res)[1] + rawEidInt, err := strconv.Atoi(string(rawEid)) + if err != nil { + log.Errorln("fetchKakaoDetailsFromShareLink: failed to parse rawEid!", err) + return "", "", errors.New("error fetchKakaoDetailsFromShareLink") + } + xorKeysRegex := regexp.MustCompile(`(\d+)\^(\d+)`) + xorKeys := xorKeysRegex.FindStringSubmatch(res) + xorKey1, _ := strconv.Atoi(string(xorKeys[1])) + xorKey2, err := strconv.Atoi(string(xorKeys[2])) + if err != nil { + log.Errorln("fetchKakaoDetailsFromShareLink: failed to parse XOR Keys!", err) return "", "", errors.New("error fetchKakaoDetailsFromShareLink") } - eid := strings.Split(split1[1], "?")[0] + + eid := fmt.Sprintf("%d", rawEidInt-xorKey1^xorKey2) log.Debugln("kakao eid is: ", eid) redirLink, _, err := httpGetWithRedirLink(link) if err != nil {