/// <summary> /// 컴파일 메서드 /// </summary> /// <returns>컴파일 작업후 결과값</returns> public CResult Compile() { if (!File.Exists(_binaryPath)) { return(CResult.NotExistBinFile); //Bin파일이 없을때 } if (!File.Exists(_scriptPath)) { return(CResult.NotExistScriptFile); //ahk파일이 없을때 } string temp = null; //작업 임시 경로 string fileName = null; //파일 이름 if (_fileDestPath == null) { //목적지가 없다면 temp = Path.GetDirectoryName(_scriptPath); fileName = Path.GetFileNameWithoutExtension(_scriptPath) + ".exe"; } else { temp = Path.GetDirectoryName(_fileDestPath); fileName = Path.GetFileNameWithoutExtension(_fileDestPath) + ".exe"; } if (File.Exists(temp + @"\" + fileName)) { File.Delete(temp + @"\" + fileName); } try { string Ahk = null; //전처리기 결과값을 받을 변수 List <string> ExtraFiles = new List <string>(); //전처리기 분석결과 리소스에 올려야 할 파일들 Preprocessor.PreProcess(ref Ahk, _scriptPath, ref ExtraFiles, new List <string>()); _scriptCode = Ahk; File.Copy(_binaryPath, temp + @"\" + fileName); //목적지에 복사 IntPtr handle = WinAPI.BeginUpdateResource(temp + @"\" + fileName, false); bool res = WinAPI.UpdateResource(handle, 10, Encoding.UTF8.GetBytes(">AUTOHOTKEY SCRIPT<"), 0x409, Encoding.UTF8.GetBytes(_scriptCode), Convert.ToUInt32(Encoding.UTF8.GetBytes(_scriptCode).Length)); if (res) { WinAPI.EndUpdateResource(handle, false); } if (!FileUploadResource(temp + @"\" + fileName, ExtraFiles)) //리소스 업로드에 실패했을때 { return(CResult.FileInstallFailed); } } catch (Exception) { return(CResult.Failed); } return(CResult.Success); }
public CiconResult ChangeIcon(string p_exeFilePath, Icons p_icons) { // Load executable IntPtr handleExe = WinAPI.BeginUpdateResource(p_exeFilePath, false); if (handleExe == null) { return(CiconResult.FailBegin); } ushort startindex = 159; ushort index = 1; CiconResult result = CiconResult.Success; bool ret = true; foreach (var icon in p_icons) { // Replace the icon // todo :Improve the return value handling of UpdateResource ret = WinAPI.UpdateResource(handleExe, RT_ICON, index, 0x409, icon.Data, icon.Size); index++; } var groupdata = p_icons.ToGroupData(); // todo :Improve the return value handling of UpdateResource ret = WinAPI.UpdateResource(handleExe, RT_GROUP_ICON, startindex, 0x409, groupdata, (uint)groupdata.Length); if (ret) { if (WinAPI.EndUpdateResource(handleExe, false)) { result = CiconResult.Success; } else { result = CiconResult.Failed; } } else { result = CiconResult.FailUpdate; } return(result); }
/// <summary> /// FileInstall 명령어에 필요한 파일들을 업로드 해주는 함수 /// </summary> /// <param name="p_targetExe">파일을 업로드할 바이너리(.EXE)파일</param> /// <param name="p_fileList">업로드할 파일 리스트</param> /// <returns>성공 or 실패 여부</returns> public bool FileUploadResource(string p_targetExe, List <string> p_fileList) { if (p_fileList.Count == 0) { return(true); } if (!File.Exists(p_targetExe)) { return(false); } IntPtr handle = WinAPI.BeginUpdateResource(p_targetExe, false); for (int i = 0; i < p_fileList.Count; i++) { bool res = WinAPI.UpdateResource(handle, 10, Encoding.UTF8.GetBytes(p_fileList[i].ToUpper()), 0x409, Encoding.UTF8.GetBytes(File.ReadAllText(p_fileList[i])), Convert.ToUInt32(Encoding.UTF8.GetBytes(File.ReadAllText(p_fileList[i])).Length)); if (!res) { WinAPI.EndUpdateResource(handle, false); return(false); } } WinAPI.EndUpdateResource(handle, false); return(true); }