Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] Manipulate Binary data with Pointers


  • Please log in to reply
141 replies to this topic
VaultBoss
  • Members
  • 7 posts
  • Last active: Nov 27 2012 01:24 PM
  • Joined: 14 Nov 2012
Ok, after I read a bit more about AHK and with the help of your script up there, I came up with this solution, that seems to work properly, whenever I drag'n'drop a file onto either the .ahk or, as a matter of fact the compiled .exe of the same...

IfNotExist, %1%
{
MsgBox, 49,, Missing File Name Parameter...
IfMsgBox, Cancel
  Return
Return
}
Else
{
; Example #6: Convert filenames passed in via command-line parameters to long names,
; complete path, and correct uppercase/lowercase characters as stored in the file system.
Loop %0%  ; For each file dropped onto the script (or passed as a parameter).
{
	 GivenPath := %A_Index%  ; Retrieve the next command line parameter.
	 Loop %GivenPath%, 1
		 LongPath = %A_LoopFileLongPath%
  MsgBox, 49,, The case-corrected long path name of file %GivenPath% is: %LongPath%
  IfMsgBox, Cancel
   Return
  FileRead, FileText, %LongPath% ; Read source file into Variable 'FileText'
  MsgBox, 49,, Just Read file %LongPath% into memory
  IfMsgBox, Cancel
   Return
  if not ErrorLevel  ; Successfully loaded.
  {
	  StringReplace, TargetFile, LongPath, .ovpn, -Mod.ovpn ; Create the path/name of the result file from the initial source file's name
	  MsgBox, 49,, New content will be saved to %TargetFile%
	  IfMsgBox, Cancel
   Return
	  StringReplace, FileText, FileText, `r`n, `n, All ; Find all CRLF and replace it with LF
	  FileDelete, %TargetFile% ; Delete target file, if it exists
	  FileAppend, %FileText%, *%TargetFile%, CP0 ; Write 'FileText' contents into target file.
	  FileText =  ; Free the memory.
  }
}
}

However, I wasn't able to run it from the command line yet...

Maybe there are compiling options, I need to read more about...

VaultBoss
  • Members
  • 7 posts
  • Last active: Nov 27 2012 01:24 PM
  • Joined: 14 Nov 2012
When I am trying to launch the newly made .exe from the command line, I get this error message:

'MY-Good-AHK_EOL_WtoUnix.exe' is not recognized as an internal or external command


I suspect there is something that pertains to the setup of the PATH environment variable or so in Windows, but the fact is I'd like everything to be completely independent and wouldn't like to have to hard write a new PATH... keeping full portability of this .exe file as in being able to run even with or w/o AHK installed and no matter in which folder the program sits...

Any ideas?..

VaultBoss
  • Members
  • 7 posts
  • Last active: Nov 27 2012 01:24 PM
  • Joined: 14 Nov 2012
NVM... stupid thing, there was a slight mistype error in the file name.

All cool now.

And working... Posted Image

ruespe
  • Members
  • 567 posts
  • Last active: Dec 01 2014 07:59 PM
  • Joined: 17 Jun 2008
Hhmmm... but what has this all to do with this topic
[How To] Manipulate Binary data with Pointers

???

VaultBoss
  • Members
  • 7 posts
  • Last active: Nov 27 2012 01:24 PM
  • Joined: 14 Nov 2012
Nothing per se, but as I couldn't contact SKAN directly (probably due to limitations related to me being new here) I picked up one of his threads that was the closest possible match to the subject.

The closeness comes from the fact that for instance, manipulating binary files for say... FTP upload, might need the same kind of feature I was looking to get built.

Of course, there is no closeness to any pointers, though... lol

Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

I tried followings;

 

Variable := "年 月 日"                 ; Year Month Day
Pointer := &Variable
Pointer += 2
Asc     := *(Pointer)
MsgBox, % Chr(Asc)

 

As you expected, I got an alien character.

I am on v1.1.09.00 Unicode and Vista 32.

I am very beginner of this job.

Do I need some special step(s) for Unicode characters ?

 

 

I have serious problem with version 1.1 which is not seen in version 1.0.

It gets slower and slower.

I got a simple plain text data file, its contents are;

 

Year (tab)

Month (tab)

Day (tab)

..

(and about 30,000 more lines and getting bigger with days).

 

 

My script works like this;  If I type "Year" on an GUI, I got "" as a result.  Easy.

 

But, I am doing this search_and_find_loop more than 30 times in a minute.

So, recently it gets jammed or frozen from time to time. It feels very uncomfortable.

 

I heard, If I use "binary" ways, I can do my work more faster. So I am here.

Now, the very first step I got problem.

 

Can you tell how to solve this first problem ?

 

 

 

Or.. is this really faster way than using plain text file ?

I mean, binary searching / binary comparing with a binary data file is really faster than plain text searching/comparing with a plain text data file ?

 

 

Thanks.



3rror
  • Members
  • 18 posts
  • Last active:
  • Joined: 29 May 2013

@Hamlet

 

I know this is too late but I just happened to see this while looking for something.

 

 

 

For your problem you should use an .ahk hotstrings script.

 

Your script should be full of lines like:

::year::年`t

Start with #Persistent and make sure to save it with UTF-8 encoding. Typing "year" with the script running will automatically replace it with "年" for example.

 

That will already be much faster than parsing a text file each time to look for the right line.   Look up the "hotstrings and auto-replace" page in the help file for all the options and examples..