internal static async Task <ParameterStorage> GetLoginParameterAsync(string script) { return(await Task.Run(() => { ParameterStorage retVal = new ParameterStorage(); Match frmData = Regex.Match(script, "name:\"(.*?)\", value:\"(.*?)\""); if (frmData.Success) { retVal.Push(frmData.Groups[1].Value, frmData.Groups[2].Value); } else { throw new Exception("스크립트 파싱에 실패하였습니다."); } return retVal; })); }
internal static async Task <Tuple <string, ParameterStorage> > GetDeleteGalleryArticleParameterAsync(string script, GalleryType gallType) { return(await Task.Run(() => { string encCode = null; ParameterStorage storage = new ParameterStorage(); #if false Match encData = Regex.Match(script, "var _r = _d\\(\'(.*)\'\\)"); #else Match encData = null; throw new Exception("알 수 없는 오류가 발생했습니다."); #endif if (encData.Success) { encCode = encData.Groups[1].Value; } else { if (gallType == GalleryType.Normal) { throw new Exception("자바스크립트 파싱에 실패하였습니다."); } } Match frmData = Regex.Match(script, "formData \\+= \"&(.*)=(.*)\";"); if (frmData.Success) { storage.Push(frmData.Groups[1].Value, frmData.Groups[2].Value); } else { throw new Exception("자바스크립트 파싱에 실패하였습니다."); } return new Tuple <string, ParameterStorage>(encCode, storage); })); }
/// <summary> /// 삭제할 글의 파라미터를 가져오는 함수 /// </summary> /// <param name="html">글 삭제 페이지의 HTML 소스</param> /// <param name="gallType">갤러리 구분</param> /// <param name="delete_Params">글 삭제에 필요한 파라미터</param> /// <param name="lately_gallery">최근 방문한 갤러리</param> internal static async Task <Tuple <ParameterStorage, string> > GetDeleteArticleParameterAsync(string html, GalleryType gallType) { return(await Task.Run(async() => { string lately_gallery = null; ParameterStorage delete_Params = new ParameterStorage(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode deleteNode = null; try { deleteNode = doc.GetElementbyId("id").ParentNode.SelectSingleNode(".//form"); lately_gallery = doc.GetElementbyId("lately_gallery").GetAttributeValue("value", ""); } catch { } // 삭제 노드가 없는 경우 이미 삭제된 글이거나 오류 if (deleteNode == null) { if (html.Contains("/error/deleted")) { throw new Exception("이미 삭제된 글입니다."); } else if (doc.GetElementbyId("password_confirm") != null) { throw new Exception("이미 삭제된 글입니다."); } else { throw new Exception("알 수 없는 오류입니다."); } } // 회원글인데 비밀번호 입력하는 페이지인 경우 이미 삭제된 글 if (deleteNode.Attributes["action"].Value.Contains("delete_password_submit")) { throw new Exception("이미 삭제된 글입니다."); } foreach (HtmlNode input in deleteNode.ParentNode.Descendants("input").Where(n => n.GetAttributeValue("type", "") == "hidden")) { delete_Params.Push(input.GetAttributeValue("name", ""), input.GetAttributeValue("value", "")); } string jsEncCode; ParameterStorage jsParam; string jsScript = ""; foreach (HtmlNode scriptNode in doc.DocumentNode.Descendants("script")) { jsScript += scriptNode.InnerHtml; } if (jsScript == "") { throw new Exception("알 수 없는 오류입니다."); } // 글 삭제시 실행되는 스크립트의 추가 값을 가져옴 var parseResult = await JSParser.GetDeleteGalleryArticleParameterAsync(jsScript, gallType); jsEncCode = parseResult.Item1; jsParam = parseResult.Item2; delete_Params.Push(jsParam); if (gallType == GalleryType.Normal) { delete_Params["service_code"] = Cryption.DecryptCode(jsEncCode, delete_Params["service_code"]); } return new Tuple <ParameterStorage, string>(delete_Params, lately_gallery); })); }