forked from rebolsource/r3
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an encapper for Windows and Linux
The way it works is: 1. embedded the script into the executable file 2. the interpreter checks for the existence of the embedded script 3. if it finds it, runs it and ignores "--do" and script passed in from the command line 4. if not, act as a regular interpreter The encapper on linux is just a wrapper around objcopy, wihch adds a section with the script to the executable On Windows, the script is added as a resource, and some windows APIs are used to retrieve the information.
- Loading branch information
Showing
8 changed files
with
317 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
REBOL[] | ||
|
||
args: parse system/script/args "" | ||
exe: none | ||
payload: none | ||
output: none | ||
windows?: 3 = fourth system/version | ||
|
||
while [not tail? args] [ | ||
arg: first args | ||
case [ | ||
any [arg = "/rebol" | ||
arg = "/r"] [ | ||
exe: second args | ||
args: next args | ||
] | ||
any [arg = "/payload" | ||
arg = "/p"] [ | ||
payload: second args | ||
args: next args | ||
] | ||
any [arg = "/payload" | ||
arg = "/p"] [ | ||
payload: second args | ||
args: next args | ||
] | ||
any [arg = "/output" | ||
arg = "/o"] [ | ||
output: second args | ||
args: next args | ||
] | ||
] | ||
args: next args | ||
] | ||
|
||
if any [none? exe | ||
none? payload | ||
none? output][ | ||
print ["pack.r"] | ||
print ["^-/rebol | /r^- path-to-rebol"] | ||
print ["^-/payload | /p^- path-to-payload"] | ||
print ["^-/output | /o^- path-to-output"] | ||
quit | ||
] | ||
|
||
payload-data: join #{01000000} compress read to file! payload | ||
tmp: join payload ".tmp" | ||
write to file! tmp payload-data | ||
|
||
either windows? [ | ||
unicodify: function [ | ||
s [string!] | ||
][ | ||
ret: copy #{} | ||
foreach c s [ | ||
append ret join to binary! c #{00} | ||
] | ||
join ret #{0000} ;NULL terminator | ||
] | ||
|
||
kernel32: make library! %kernel32 | ||
|
||
print ["kernel:" mold kernel32] | ||
BeginUpdateResource: make routine! compose [[ | ||
filename [pointer] | ||
delete-existing-resources [int32] | ||
return: [pointer] | ||
] (kernel32) "BeginUpdateResourceW"] | ||
|
||
UpdateResource: make routine! compose [[ | ||
hUpdate [pointer] | ||
lpType [pointer] | ||
lpName [pointer] | ||
wLanguage [uint16] | ||
lpData [pointer] | ||
cbData [uint32] | ||
return: [int32] | ||
] (kernel32) "UpdateResourceW"] | ||
|
||
EndUpdateResource: make routine! compose [[ | ||
hUpdate [pointer] | ||
fDiscard [uint8] | ||
return: [int32] | ||
] (kernel32) "EndUpdateResourceW"] | ||
|
||
GetLastError: make routine! compose [[ | ||
return: [uint32] | ||
] (kernel32) "GetLastError"] | ||
|
||
write to file! output read to file! exe | ||
h: BeginUpdateResource unicodify output 0 | ||
if zero? h [ | ||
print ["failed to open exe"] | ||
halt | ||
] | ||
if zero? UpdateResource h 10 | ||
unicodify "EmbEddEdREbol" | ||
0 payload-data length? payload-data [ | ||
print ["failed to update resource"] | ||
halt | ||
] | ||
if zero? EndUpdateResource h 0 [ | ||
print ["failed to write change back to the file due to " GetLastError] | ||
halt | ||
] | ||
][ | ||
magic: ".EmbEddEdREbol" | ||
call reform ["objcopy -R" magic exe] | ||
call rejoin ["objcopy --add-section " magic "=" tmp " " exe " " output] | ||
delete to file! tmp | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c4a478b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zsx Is there a reason why you added
embedded_script
and not just used the script which could be included withCUSTOM_STARTUP
definition? Are you having situation when you embed a script with additional custom script?c4a478b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really other than being back compatible.