Skip to content

Commit 9bf256e

Browse files
committed
Create native script that works the same as the shell script
shc creates code that makes corporate antivirus (or at least SentinelOne) very angry, for reasonably understandable reasons.
1 parent 5c85fa7 commit 9bf256e

File tree

5 files changed

+633
-1
lines changed

5 files changed

+633
-1
lines changed

.github/workflows/compile.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ jobs:
7373
strip universalJavaApplicationStub
7474
chmod ug=rwx,o=rx universalJavaApplicationStub
7575
76+
- name: Build nativeJavaApplicationStub
77+
run: |
78+
make universal
79+
7680
- name: Upload universalJavaApplicationStub.x86_64 asset
7781
uses: actions/upload-release-asset@v1
7882
env:
@@ -103,6 +107,36 @@ jobs:
103107
asset_path: ./universalJavaApplicationStub
104108
asset_content_type: application/octet-stream
105109

110+
- name: Upload nativeJavaApplicationStub.x86_64 asset
111+
uses: actions/upload-release-asset@v1
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GH_API_PERSONAL_ACCESS_TOKEN }}
114+
with:
115+
upload_url: ${{ needs.draft_release.outputs.upload_url }}
116+
asset_name: nativeJavaApplicationStub.x86_64
117+
asset_path: ./build/x86_64/nativeJavaApplicationStub
118+
asset_content_type: application/octet-stream
119+
120+
- name: Upload nativeJavaApplicationStub.arm64 asset
121+
uses: actions/upload-release-asset@v1
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GH_API_PERSONAL_ACCESS_TOKEN }}
124+
with:
125+
upload_url: ${{ needs.draft_release.outputs.upload_url }}
126+
asset_name: nativeJavaApplicationStub.arm64
127+
asset_path: ./build/arm64/nativeJavaApplicationStub
128+
asset_content_type: application/octet-stream
129+
130+
- name: Upload nativeJavaApplicationStub asset
131+
uses: actions/upload-release-asset@v1
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GH_API_PERSONAL_ACCESS_TOKEN }}
134+
with:
135+
upload_url: ${{ needs.draft_release.outputs.upload_url }}
136+
asset_name: nativeJavaApplicationStub
137+
asset_path: ./build/universal/nativeJavaApplicationStub
138+
asset_content_type: application/octet-stream
139+
106140
publish_release:
107141
name: Publish drafted release
108142
needs: [ draft_release, compile ]

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
# shc compiler
44
*.x
5-
*.x.c
5+
*.x.c
6+
7+
build

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
CC = clang
2+
3+
CFLAGS = -Wall -Werror -g
4+
CFLAGS_ARM64 = -target arm64-apple-macos11
5+
CFLAGS_X86_64 = -target x86_64-apple-macos10.12
6+
LIBS = -lobjc -framework Foundation -framework AppKit
7+
INCLUDES =
8+
9+
SRCS = src/nativeStub.m
10+
OBJS = $(SRCS:src/%.m=build/%.o)
11+
OBJS_ARM64 = $(SRCS:src/%.m=build/arm64/%.o)
12+
OBJS_X86_64 = $(SRCS:src/%.m=build/x86_64/%.o)
13+
14+
# define the executable file
15+
APP_NAME = nativeJavaApplicationStub
16+
MAIN = build/$(APP_NAME)
17+
MAIN_ARM64 = build/arm64/$(APP_NAME)
18+
MAIN_X86_64 = build/x86_64/$(APP_NAME)
19+
MAIN_UNIVERSAL = build/universal/$(APP_NAME)
20+
21+
.PHONY: depend clean
22+
23+
default: $(MAIN)
24+
universal: $(MAIN_UNIVERSAL)
25+
26+
$(MAIN): $(OBJS)
27+
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LFLAGS) $(LIBS)
28+
29+
$(MAIN_ARM64): $(OBJS_ARM64)
30+
$(CC) $(CFLAGS) $(CFLAGS_ARM64) $(INCLUDES) -o $@ $^ $(LFLAGS) $(LIBS)
31+
32+
$(MAIN_X86_64): $(OBJS_X86_64)
33+
$(CC) $(CFLAGS) $(CFLAGS_X86_64) $(INCLUDES) -o $@ $^ $(LFLAGS) $(LIBS)
34+
35+
$(MAIN_UNIVERSAL): $(MAIN_ARM64) $(MAIN_X86_64)
36+
@mkdir -p build/universal
37+
lipo -create -output $@ $^
38+
39+
build/%.o: src/%.m
40+
@mkdir -p build
41+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
42+
43+
build/arm64/%.o: src/%.m
44+
@mkdir -p build/arm64
45+
$(CC) $(CFLAGS) $(INCLUDES) $(CFLAGS_ARM64) -c $< -o $@
46+
47+
build/x86_64/%.o: src/%.m
48+
@mkdir -p build/x86_64
49+
$(CC) $(CFLAGS) $(INCLUDES) $(CFLAGS_X86_64) -c $< -o $@
50+
51+
clean:
52+
rm -rf build/
53+
54+
depend: $(SRCS)
55+
makedepend $(INCLUDES) $^
56+
57+
# DO NOT DELETE THIS LINE -- make depend needs it

src/nativeStub.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface JVMMetadata : NSObject
4+
@property(strong) NSString *path;
5+
@property(strong) NSString *version;
6+
@end
7+
8+
NSString *resolvePlaceholders(NSString *src, NSString *javaFolder);
9+
NSString *execute(NSString *command, NSArray *args);
10+
NSString *fetchJavaVersion(NSString *path);
11+
NSString *normalizeJavaVersion(NSString *version);
12+
BOOL isValidRequirement(NSString *version);
13+
BOOL versionMeetsConstraint(NSString *version, NSString *constraint, BOOL hasMax);
14+
BOOL versionMeetsMaxConstraint(NSString *version, NSString *constraint);
15+

0 commit comments

Comments
 (0)