File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,37 @@ 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 can 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
+ const nextPlaceholder = discoverPlaceholder (
61
+ binaryBuffer ,
62
+ searchString ,
63
+ padder ,
64
+ position + placeholder . length ,
65
+ ) ;
66
+ if ( ! ( 'notFound' in nextPlaceholder ) ) {
67
+ return nextPlaceholder ;
68
+ }
69
+ }
70
+
48
71
return { position, size : placeholder . length , padder } ;
49
72
}
50
73
You can’t perform that action at this time.
0 commit comments