Update the rubyscript2exe. RB script in ruby1.9.1.

Source: Internet
Author: User

In ruby1.9, if rubyscript2exe. Rb is usedProgram. $0 cannot be replaced because it is frozen.

At the same time, because in ruby1.9, require directly loads the contained file name into an absolute path, it also prevents users from loading different relative paths multiple times, but in fact, the absolute path is the same file.

 

These modifications benefit from program reliability and efficiency.

 

If you want to use the package, there are generally two options: rubyscript2exe. Rb and exerb.

 

In Ruby 1.8.7, we can use all of them, and in general, exerb feels a little faster.

 

However, when ruby1.9.1 was reached, it was found that both tools were unavailable. Modification is required.

 

Exerb also has the above problems. If you explore the implementation of the two, it feels that they are similar. It is more troublesome to install exerb, while rubyscript2exe is simpler.

 

In terms of implementation, the speed should be similar. Files are extracted from the resource section of the EXE and then executed in the temporary directory. Exerb adds the section to the resource section to the source code, while rubyscript2exe only provides the EXE file to implement this function. In fact, it is not difficult to understand the PE File Format header.

I started from rubyscript2exe. RB to see if I could change it. I can use it in ruby1.9.1. It is only a file and does not know how it is loaded. So when you are free, download exerb to study itsCodeMany, it is only available in version 1.4.8 of ruby1.9, and still unavailable, depressing.
No way, because I used mingw/msys to compile ruby1.9.1 code, so I had to use mingw to compile this piece, instead of using the VC module provided by it.

Then try to compile the module 1.9.1. By configuring the Mak file, you can compile it. But if you use it on exerb, there will be a problem, saying that the last section is not. rsrc. So I had to find the LD option, and added-wl, -- GC-sections, -- strip-all, and OK. Then you can generate an EXE file, but run the Win32 program that reports an invalid code. Use peeditor to fix it and run it.

If you use the magic comment of # encoding: GBK, we will report that GBK. So cannot be found. I have read the resource segment in the generated EXE and already include it. But that is not true. It seems that you have to carefully study the exerb code.

Due to the tight schedule, I had to temporarily release this task. As a result, I went back to rubyscript2exe. By carefully reading its code, I had accumulated experience in debugging exerb and soon found the tips in it.

With its options, decompress its own packaged tar file, and then you can see all the code in it. All of a sudden, I came to the spirit, because I know that I can also study exerb. In addition, it has less code, so now it runs ruby init. RB test. RB manually in its package, and slowly modifies several parameters so that it can be packaged into EXE smoothly.

The rest is very simple. Put the modified package file into rubyscript2exe using the inverse process, which is basically usable. Haha

This is the purpose of this blog.

The modified rubyscript2exe. RB can be found at this link: http://download.csdn.net/source/1199453

 

PS: for the study of exerb, I will post the results later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.