madsiddiqui Posted September 4, 2011 Share Posted September 4, 2011 (edited) Hi guys, I need help. I currently have this code: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <String.au3> Opt('MustDeclareVars', 1) Local $btn1, $msg, $btn2, $btn3, $btn4, $btn5, $var, $xOrigText, $xEncryptText, $file, $xxEncryptTex Local $sOrig = '470123" & @CR & @LF Local $sConv = " #$%&''& @CR & @LF Global $aOrig = StringSplit($sOrig, "", 2) Global $aConv = StringSplit($sConv, "", 2) MsgB() ;Local $sOrigText = "" & "" & "" & "" GUICreate("Majid's Khan .BIN Cryptor v1.0.3", 460, 570); WS_EX_ACCEPTFILES , -1, -1, -1, 0x00000018 $xOrigText = GUICtrlCreateEdit("Enter decrypted text here." & @TAB & "You cant use the Alt+A key but you may rightclick then select all.", 1, 1, 459, 250) $xEncryptText = GUICtrlCreateEdit("Enter encrypted text here." & @TAB & "Khan .BIN files are found at /data/msg/*.bin or some other folders.", 1, 300, 459, 250) $btn5 = GUICtrlCreateButton("Encrypt", 40, 260, 80, 30) $btn4 = GUICtrlCreateButton("Decrypt", 120, 260, 80, 30) $btn3 = GUICtrlCreateButton("Load Encrypted File", 200, 260, 110, 30) $btn2 = GUICtrlCreateButton("Save", 310, 260, 60, 30) $btn1 = GUICtrlCreateButton("Exit", 370, 260, 50, 30) GUICtrlCreateLabel("Created by Majid Siddiqui for khan.forumotion.com", 130, 553) GUISetState() $msg = 0 While 1 $msg = GUIGetMsg() Switch $msg Case $btn1, $GUI_EVENT_CLOSE ExitLoop Case $btn2 $file = FileOpen($var, 1) $xxEncryptTex = _HexToString("1d") FileWrite($file, $xxEncryptTex) FileClose($file) Case $btn5 If GUICtrlRead($xOrigText) <> "" Then _ GUICtrlSetData($xEncryptText, StringRegExpReplace(_Encrypt(GUICtrlRead($xOrigText)), _ "(\d+)(.+\v*)", "\1" & @TAB & "\2")) Case $btn4 If GUICtrlRead($xEncryptText) <> "" Then _ GUICtrlSetData($xOrigText, StringRegExpReplace(_Decrypt(GUICtrlRead($xEncryptText)), _ "(\d+)(.+\v*)", "\1" & @TAB & "\2")) Case $btn3 $var = FileOpenDialog("Locate Khan .Bin File.", @ScriptDir & "\", _ "Bin files (*.bin)|Text files (*.txt)|All (*.*)", 1 + 4) If Not @error Then GUICtrlSetData($xEncryptText, FileRead($var)) EndIf EndSwitch WEnd Func _Encrypt($sOrigText) Local $iIndex, $sConvText = "" Local $aOrigText = StringSplit($sOrigText, "", 2) For $i = 0 To UBound($aOrigText) - 1 $iIndex = _ArraySearch($aOrig, $aOrigText[$i], 0, 0, 1) ; Case sensitive search If $iIndex <> -1 Then $sConvText &= $aConv[$iIndex] Next Return $sConvText EndFunc ;==>_Encrypt Func _Decrypt($sConvText) Local $iIndex, $sOrigText = "" Local $aConvText = StringSplit($sConvText, "", 2) For $i = 0 To UBound($aConvText) - 1 $iIndex = _ArraySearch($aConv, $aConvText[$i], 0, 0, 1) ; Case sensitive search If $iIndex <> -1 Then $sOrigText &= $aOrig[$iIndex] Next Return $sOrigText EndFunc ;==>_Decrypt Func MsgB() MsgBox(4096, "Welcome | Notice", "This program will help you view encrypted files, and create translations for Khan.", 0) EndFunc ;==>Menu But, I this is how I want it. I want to read file as hex, and save it as hex.. But when I open the file via text editor it will still display the anscii/string. As If my script was an hex editor. My reason, as you see my script is a conversion script. the problem is I can't convert "TAB" to the correct value because its [GS], but in hex its 1D. So, to implement it I wish to read where a [GS] is as HEX then view it as a TAB. When saving I just wan't the file to be encrypted again. Thanks, God Bless. Edited September 4, 2011 by madsiddiqui Link to comment Share on other sites More sharing options...
madsiddiqui Posted September 4, 2011 Author Share Posted September 4, 2011 (edited) Anyways this is the conversion data. A file contains something like this, $[THIS IS A TAB]Z{4Bqfg}{z4]zr{:4@|}g4df{sfuy4c}xx4vq4wx{gqp: converts to 0[THIS IS A TAB]No Version Info. This program will be closed. I have this working, except for the tab. In string the conversion is 4 = [space], $ = 0..so on.. But I wish to read the file's hex data, and convert it. Conversion table,(decryption) HEX -> STRING If hex 20 is found convert it to hex(4). If hex 21 is found convert it to hex(5). If hex 1e is found convert it to newline. If hex 1d is found convert it to TAB. Conversion table,(encryption) HEX -> HEX If hex(4) is found convert to 20 If hex(5) is found convert to 21 If newline is found convert to 1e If TAB is found convert to 1d But when I view the file from notepad++ It should still be the string data showing.. Edited September 4, 2011 by madsiddiqui Link to comment Share on other sites More sharing options...
guinness Posted September 4, 2011 Share Posted September 4, 2011 Look at the flags in FileOpen() & then _StringToHex() and _HexToString(). Hopes this gets you started. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
madsiddiqui Posted September 9, 2011 Author Share Posted September 9, 2011 Thanks, I'll be looking into it. Link to comment Share on other sites More sharing options...
madsiddiqui Posted September 9, 2011 Author Share Posted September 9, 2011 I now have this code, But the problem is its still not reading the HEX of the file, but its just reading the file then converting it to hex... Please advise? expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <String.au3> ;declerations here Local $sOrig = '!"' & "#$%&'()*+,-./01234 56789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ" & _HexToString("1d") & _HexToString("1e") Local $sConv = "5670123<=>?89:;$%&'" & ' 4!"#,-./()*+TUVWPQRS\]^_XYZ[DEFG@ABCLMNOHIJKtuvwpqrs|}~xyz{defg`abclmnohijk”•–—‘’“œžŸ˜™š›„…†‡€‚ƒŒŽˆ‰Š‹´µ¶·°±²³¼½¾¿¸¹º»¤¥¦§ ¡¢£¬®¯¨©ª«ÔÕÖ×ÐÑÒÓÜÝÞßØÙÚÛÄÅÆÇÀÁÂÃÌÍÎÏÈÉÊËôõö÷ðñòóüýþÿøùúûäåæçàáâãìíîïèéê' & '@TAB' & '@CRLF' Global $aOrig = StringSplit($sOrig, "", 1) Global $aConv = StringSplit($sConv, "", 1) MsgB() #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("BlazeKhan BIN Packer/Unpacker Tool", 571, 446, 192, 124) $Edit1 = GUICtrlCreateEdit("", 8, 8, 553, 353, BitOR($GUI_SS_DEFAULT_EDIT,$ES_OEMCONVERT)) $Open = GUICtrlCreateButton("Open", 16, 384, 89, 33) $Unpack = GUICtrlCreateButton("Unpack", 112, 384, 89, 33) $Repack = GUICtrlCreateButton("Repack", 208, 384, 89, 33) $Save = GUICtrlCreateButton("Save", 304, 384, 89, 33) $Exit = GUICtrlCreateButton("Exit", 496, 384, 57, 33) $Reset = GUICtrlCreateButton("Reset", 400, 384, 89, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetState() $msg = 0 While 1 $msg = GUIGetMsg() Switch $msg Case $Exit, $GUI_EVENT_CLOSE ExitLoop Case $Reset GUICtrlSetData($Edit1, "") Case $Unpack If GUICtrlRead($Edit1) <> "" Then _ GUICtrlSetData($Edit1, _Encrypt(GUICtrlRead($Edit1))) Case $Repack If GUICtrlRead($Edit1) <> "" Then _ GUICtrlSetData($Edit1, _Decrypt(GUICtrlRead($Edit1))) Case $Open $var = FileOpenDialog("Locate Khan .Bin File.", @ScriptDir & "\", _ "Bin files (*.bin)|Text files (*.txt)|All (*.*)", 1 + 4) If Not @error Then GUICtrlSetData($Edit1, FileRead($var)) EndIf Case $Save $hFile = FileOpen($var, 17) $hFile2 = FileOpen($var, 17) $chars2 = FileRead($hFile2) $bString2 = StringMid(_HexToString(GUICtrlRead($Edit1)), 3) FileWrite($hFile2, $bString2) FileClose($hFile2) EndSwitch WEnd ;functions here Func _Encrypt($sOrigText) Local $iIndex, $sConvText = "" Local $aOrigText = StringSplit($sOrigText, "", 2) For $i = 0 To UBound($aOrigText) - 1 $iIndex = _ArraySearch($aOrig, $aOrigText[$i], 0, 0, 1) ; Case sensitive search If $iIndex <> -1 Then $sConvText &= $aConv[$iIndex] Next Return $sConvText EndFunc ;==>_Encrypt Func _Decrypt($sConvText) Local $iIndex, $sOrigText = "" Local $aConvText = StringSplit($sConvText, "", 2) For $i = 0 To UBound($aConvText) - 1 $iIndex = _ArraySearch($aConv, $aConvText[$i], 0, 0, 1) ; Case sensitive search If $iIndex <> -1 Then $sOrigText &= $aOrig[$iIndex] Next Return $sOrigText EndFunc ;==>_Decrypt Func MsgB() MsgBox(4096, "Welcome | Notice", "This program will help you view encrypted files, and create translations for Khan.", 0) EndFunc ;==>Menu Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 9, 2011 Moderators Share Posted September 9, 2011 But the problem is its still not reading the HEX of the file, but its just reading the file then converting it to hex This makes absolutely no sense. What is the "Hex" of a file? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now