|
@@ -7,17 +7,16 @@ uses
|
|
//wasmbindebug,
|
|
//wasmbindebug,
|
|
wasmlink, wasmlinkchange;
|
|
wasmlink, wasmlinkchange;
|
|
|
|
|
|
-function ReadStream(st: TStream): Boolean;
|
|
|
|
-procedure ReadWasmFile(const fn: string);
|
|
|
|
-function WriteStream(st: TStream; syms: TStrings): Boolean;
|
|
|
|
-procedure ProcessWasmFile(const fn, symfn: string);
|
|
|
|
-procedure RenameExport(var x: TExportSection; syms: TStrings);
|
|
|
|
-function ProcessSections(st, dst: TStream; syms: TStrings): Boolean;
|
|
|
|
-procedure ProcessWasmSection(const fn, {%H-}symfn: string);
|
|
|
|
|
|
+function ChangeSymbolFlagStream(st: TStream; syms: TStrings): Boolean;
|
|
|
|
+procedure ChangeSymbolFlag(const fn, symfn: string);
|
|
|
|
+
|
|
|
|
+procedure ExportRenameSym(var x: TExportSection; syms: TStrings);
|
|
|
|
+function ExportRenameProcesss(st, dst: TStream; syms: TStrings): Boolean;
|
|
|
|
+procedure ExportRename(const fn, symfn: string);
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
-function ReadStream(st: TStream): Boolean;
|
|
|
|
|
|
+function ChangeSymbolFlagStream(st: TStream; syms: TStrings): Boolean;
|
|
var
|
|
var
|
|
dw : LongWord;
|
|
dw : LongWord;
|
|
ofs : int64;
|
|
ofs : int64;
|
|
@@ -27,78 +26,18 @@ var
|
|
begin
|
|
begin
|
|
dw := st.ReadDWord;
|
|
dw := st.ReadDWord;
|
|
Result := dw = WasmId_Int;
|
|
Result := dw = WasmId_Int;
|
|
- if not Result then begin
|
|
|
|
- writeln('not a wasm file');
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- dw := st.ReadDWord;
|
|
|
|
- writeln('version: ', dw);
|
|
|
|
- while st.Position<st.Size do begin
|
|
|
|
- ofs := st.Position;
|
|
|
|
- sc.id := st.ReadByte;
|
|
|
|
- sc.Size := ReadU(st);
|
|
|
|
- writeln(ofs,': id=', sc.id,'(', SectionIdToStr(sc.id),') sz=', sc.size);
|
|
|
|
-
|
|
|
|
- ps := st.Position+sc.size;
|
|
|
|
- if sc.id=0 then begin
|
|
|
|
- nm := GetName(st);
|
|
|
|
- writeln(nm);
|
|
|
|
- if nm = SectionName_Linking then
|
|
|
|
- DumpLinking(st, sc.size - (st.Position - ofs));
|
|
|
|
- end;
|
|
|
|
- //if sc.id= 1 then DumpTypes(st);
|
|
|
|
-
|
|
|
|
- if st.Position <> ps then
|
|
|
|
- begin
|
|
|
|
- //writeln('adjust stream targ=',ps,' actual: ', st.position);
|
|
|
|
- st.Position := ps;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-procedure ReadWasmFile(const fn: string);
|
|
|
|
-var
|
|
|
|
- fs :TFileStream;
|
|
|
|
-begin
|
|
|
|
- fs := TFileStream.Create(fn, fmOpenRead or fmShareDenyNone);
|
|
|
|
- try
|
|
|
|
- ReadStream(fs);
|
|
|
|
- finally
|
|
|
|
- fs.Free;
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
|
|
+ if not Result then Exit;
|
|
|
|
|
|
-function WriteStream(st: TStream; syms: TStrings): Boolean;
|
|
|
|
-var
|
|
|
|
- dw : LongWord;
|
|
|
|
- ofs : int64;
|
|
|
|
- sc : TSection;
|
|
|
|
- ps : int64;
|
|
|
|
- nm : string;
|
|
|
|
-begin
|
|
|
|
- writeln('read: ');
|
|
|
|
dw := st.ReadDWord;
|
|
dw := st.ReadDWord;
|
|
- writeln('dw: ' ,dw);
|
|
|
|
- Result := dw = WasmId_Int;
|
|
|
|
- if not Result then begin
|
|
|
|
- writeln('not a wasm file');
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- dw := st.ReadDWord;
|
|
|
|
- writeln('version: ', dw);
|
|
|
|
while st.Position<st.Size do begin
|
|
while st.Position<st.Size do begin
|
|
ofs := st.Position;
|
|
ofs := st.Position;
|
|
sc.id := st.ReadByte;
|
|
sc.id := st.ReadByte;
|
|
sc.Size := ReadU(st);
|
|
sc.Size := ReadU(st);
|
|
- writeln(ofs,': id=', sc.id,'(', SectionIdToStr(sc.id),') sz=', sc.size);
|
|
|
|
|
|
|
|
ps := st.Position+sc.size;
|
|
ps := st.Position+sc.size;
|
|
if sc.id=0 then begin
|
|
if sc.id=0 then begin
|
|
nm := GetName(st);
|
|
nm := GetName(st);
|
|
- writeln(nm);
|
|
|
|
if nm = SectionName_Linking then begin
|
|
if nm = SectionName_Linking then begin
|
|
- writeln('rewriting linking...');
|
|
|
|
ProcessLinkingSection(st, syms);
|
|
ProcessLinkingSection(st, syms);
|
|
break;
|
|
break;
|
|
end;
|
|
end;
|
|
@@ -114,26 +53,24 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure ProcessWasmFile(const fn, symfn: string);
|
|
|
|
|
|
+procedure ChangeSymbolFlag(const fn, symfn: string);
|
|
var
|
|
var
|
|
fs :TFileStream;
|
|
fs :TFileStream;
|
|
syms: TStringList;
|
|
syms: TStringList;
|
|
begin
|
|
begin
|
|
- writeln('proc: ', fn);
|
|
|
|
syms:=TStringList.Create;
|
|
syms:=TStringList.Create;
|
|
fs := TFileStream.Create(fn, fmOpenReadWrite or fmShareDenyNone);
|
|
fs := TFileStream.Create(fn, fmOpenReadWrite or fmShareDenyNone);
|
|
try
|
|
try
|
|
if (symfn<>'') then
|
|
if (symfn<>'') then
|
|
ReadSymbolsConf(symfn, syms);
|
|
ReadSymbolsConf(symfn, syms);
|
|
- writeln('size: ', fs.size);
|
|
|
|
- WriteStream(fs, syms);
|
|
|
|
|
|
+ ChangeSymbolFlagStream(fs, syms);
|
|
finally
|
|
finally
|
|
fs.Free;
|
|
fs.Free;
|
|
syms.Free;
|
|
syms.Free;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure RenameExport(var x: TExportSection; syms: TStrings);
|
|
|
|
|
|
+procedure ExportRenameSym(var x: TExportSection; syms: TStrings);
|
|
var
|
|
var
|
|
i : integer;
|
|
i : integer;
|
|
v : string;
|
|
v : string;
|
|
@@ -145,14 +82,13 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function ProcessSections(st, dst: TStream; syms: TStrings): Boolean;
|
|
|
|
|
|
+function ExportRenameProcesss(st, dst: TStream; syms: TStrings): Boolean;
|
|
var
|
|
var
|
|
dw : LongWord;
|
|
dw : LongWord;
|
|
ofs : int64;
|
|
ofs : int64;
|
|
sc : TSection;
|
|
sc : TSection;
|
|
ps : int64;
|
|
ps : int64;
|
|
x : TExportSection;
|
|
x : TExportSection;
|
|
- i : integer;
|
|
|
|
mem : TMemoryStream;
|
|
mem : TMemoryStream;
|
|
begin
|
|
begin
|
|
dw := st.ReadDWord;
|
|
dw := st.ReadDWord;
|
|
@@ -165,13 +101,12 @@ begin
|
|
ofs := st.Position;
|
|
ofs := st.Position;
|
|
sc.id := st.ReadByte;
|
|
sc.id := st.ReadByte;
|
|
sc.Size := ReadU(st);
|
|
sc.Size := ReadU(st);
|
|
- writeln(ofs,': id=', sc.id,'(', SectionIdToStr(sc.id),') sz=', sc.size);
|
|
|
|
|
|
|
|
ps := st.Position+sc.size;
|
|
ps := st.Position+sc.size;
|
|
|
|
|
|
if sc.id = SECT_EXPORT then begin
|
|
if sc.id = SECT_EXPORT then begin
|
|
ReadExport(st, x);
|
|
ReadExport(st, x);
|
|
- RenameExport(x, syms);
|
|
|
|
|
|
+ ExportRenameSym(x, syms);
|
|
|
|
|
|
st.Position:=0;
|
|
st.Position:=0;
|
|
dst.CopyFrom(st, ofs);
|
|
dst.CopyFrom(st, ofs);
|
|
@@ -185,41 +120,21 @@ begin
|
|
WriteU32(dst, mem.Size);
|
|
WriteU32(dst, mem.Size);
|
|
dst.CopyFrom(mem, mem.Size);
|
|
dst.CopyFrom(mem, mem.Size);
|
|
|
|
|
|
- writeln('entries = ', length(x.entries));
|
|
|
|
- for i:=0 to length(x.entries)-1 do begin
|
|
|
|
- writeln(x.entries[i].desc,' ', x.entries[i].name)
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
dst.CopyFrom(st, st.Size-st.Position);
|
|
dst.CopyFrom(st, st.Size-st.Position);
|
|
- break; // done
|
|
|
|
|
|
+ break;
|
|
end;
|
|
end;
|
|
- {if sc.id=0 then begin
|
|
|
|
- nm := GetName(st);
|
|
|
|
- writeln(nm);
|
|
|
|
- if nm = SectionName_Linking then begin
|
|
|
|
- writeln('rewriting linking...');
|
|
|
|
- ProcessLinkingSection(st, syms);
|
|
|
|
- break;
|
|
|
|
- end;
|
|
|
|
- //DumpLinking(st, sc.size - (st.Position - ofs));
|
|
|
|
- end;}
|
|
|
|
- //if sc.id= 1 then DumpTypes(st);
|
|
|
|
|
|
|
|
if st.Position <> ps then
|
|
if st.Position <> ps then
|
|
- begin
|
|
|
|
- //writeln('adjust stream targ=',ps,' actual: ', st.position);
|
|
|
|
st.Position := ps;
|
|
st.Position := ps;
|
|
- end;
|
|
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure ProcessWasmSection(const fn, {%H-}symfn: string);
|
|
|
|
|
|
+procedure ExportRename(const fn, symfn: string);
|
|
var
|
|
var
|
|
fs : TFileStream;
|
|
fs : TFileStream;
|
|
syms : TStringList;
|
|
syms : TStringList;
|
|
dst : TMemoryStream;
|
|
dst : TMemoryStream;
|
|
begin
|
|
begin
|
|
- writeln('proc: ', fn);
|
|
|
|
syms:=TStringList.Create;
|
|
syms:=TStringList.Create;
|
|
fs := TFileStream.Create(fn, fmOpenReadWrite or fmShareDenyNone);
|
|
fs := TFileStream.Create(fn, fmOpenReadWrite or fmShareDenyNone);
|
|
dst := TMemoryStream.Create;
|
|
dst := TMemoryStream.Create;
|
|
@@ -227,7 +142,8 @@ begin
|
|
if (symfn <> '') and fileExists(symfn) then
|
|
if (symfn <> '') and fileExists(symfn) then
|
|
syms.LoadFromFile(symfn);
|
|
syms.LoadFromFile(symfn);
|
|
|
|
|
|
- ProcessSections(fs, dst, syms);
|
|
|
|
|
|
+ ExportRenameProcesss(fs, dst, syms);
|
|
|
|
+
|
|
fs.Position:=0;
|
|
fs.Position:=0;
|
|
dst.Position:=0;
|
|
dst.Position:=0;
|
|
fs.CopyFrom(dst, dst.Size);
|
|
fs.CopyFrom(dst, dst.Size);
|