File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,34 @@ function discoverPlaceholder(
37
37
binaryBuffer : Buffer ,
38
38
searchString : string ,
39
39
padder : string ,
40
+ searchOffset : number = 0 ,
40
41
) : Placeholder | NotFound {
41
42
const placeholder = Buffer . from ( searchString ) ;
42
- const position = binaryBuffer . indexOf ( placeholder ) ;
43
+ const position = binaryBuffer . indexOf ( placeholder , searchOffset ) ;
43
44
44
45
if ( position === - 1 ) {
45
46
return { notFound : true } ;
46
47
}
47
48
49
+ /**
50
+ * the PAYLOAD/PRELUDE placeholders occur twice in the binaries:
51
+ * - in source text as a string literal
52
+ * - in bytecode as a raw string
53
+ * the ordering depends on the platform - we need to make sure that
54
+ * the bytecode string is replaced, not the source literal.
55
+ *
56
+ * this rejects the source code literal if it occurs first in the binary
57
+ * also see: https://github.com/yao-pkg/pkg/pull/86
58
+ */
59
+ if ( binaryBuffer [ position - 1 ] === 39 /* ascii for ' APOSTROPHE */ ) {
60
+ return discoverPlaceholder (
61
+ binaryBuffer ,
62
+ searchString ,
63
+ padder ,
64
+ position + placeholder . length ,
65
+ ) ;
66
+ }
67
+
48
68
return { position, size : placeholder . length , padder } ;
49
69
}
50
70
You can’t perform that action at this time.
0 commit comments