Jump to content

sp0987

Members
  • Content Count

    56
  • Joined

  • Last visited

Everything posted by sp0987

  1. I am writing an HTTP server (TIdHTTPServer) program that services GET requests for images. This 'OnCommandGet ' procedure of Httpserver, calls other procedures to do various tasks, and then finally gets back to the client via TIdHTTPResponseInfo. procedure TVRMEditor.HTTPServerCommandGet(AContext: TIdContext; req: TIdHTTPRequestInfo; res: TIdHTTPResponseInfo); var act, DocExt: string; begin try res.SERVER := 'VRM Editor'; res.ContentType := 'text/html;charset="UTF-8"'; res.ResponseNo := 200; act := UpperCase(copy(req.Document, 2, Length(req.Document) - 1)); DocExt := UpperCase(ExtractFileExt(act)); self.Log(fcomp_name + ': ' + copy(req.RawHTTPCommand, 1, Length(req.RawHTTPCommand) - 9), allowed); -- allowed is a flag to print all the req commands when set to true if DocExt = '.MAX' then begin self.ProcessResponse(req, res); end else self.SendFileToClient(req, res); -- access all the js/css/jpg/css files which are needed to open a web page except on E: Exception do begin self.Log(req.URI + ' : ' + req.Document + sLineBreak + E.ClassName + ' : ' + E.Message); end; end; end; When the Allowed flag is set to true, it prints al the request commands and opens the webpage without any error. If it sets to false, am getting AV / Invalid pointer and couldn't open the page. Am not sure whether you can get the log, but you can see the exceptions. Allowed = true.log Allowed=false.log
  2. Procedure GLog(Msg: String); var gLogger: TFileLogger = nil; begin if Assigned(gLogger) and Assigned(gLogger.Memo) then begin gLogger.fmLock.Enter; gLogger.Memo.Lines.BeginUpdate; while gLogger.Memo.Lines.Count > 600 do gLogger.Memo.Lines.Delete(0); gLogger.Memo.Lines.Add(Msg); gLogger.Memo.Lines.EndUpdate; gLogger.Memo.Perform(EM_SCROLLCARET, 0, 0); gLogger.fmLock.Leave; end; _Log(Msg); end; Upon my observation, when log prints all the requests from web page, there was no AV/ Invalid pointer Exception. Am not sure that log function was the culprit...
  3. procedure TVRMEditor.SendFileToClient(req: TIdHTTPRequestInfo; res: TIdHTTPResponseInfo); var doc, ext, Data, fname, err: String; b: boolean; rlst: TStringList; begin Data := ''; fname := req.Document; doc := ExpandFilename(self.RootDir + fname); if not FileExists(doc) then begin self.Log(fcomp_name + ': ' + fname + ' not in editor''s webroot!', LogServer); doc := ExpandFilename(fclirootdir + '\webroot\' + fname); if not FileExists(doc) then begin self.Log(fcomp_name + ': ' + fname + ' not found in any webroot!'); doc := ''; end; end; if doc <> '' then begin ext := UpperCase(ExtractFileExt(fname)); b := (ext = '.CSS') or (ext = '.HTM') or (ext = '.HTML') or (ext = '.JS'); if not b then begin res.ContentType := fMIMEMap.GetFileMIMEType(doc); res.ContentStream := TFileStream.Create(doc, fmOpenRead or fmShareCompat); end else begin try rlst := TStringList.Create; GetConstantGroup('Global_Skin', rlst); Data := LoadDataFromFile(doc); Data := ReplaceAllStringParams(Data, [rlst], '#S', '#', true); if not ReplaceForIncludFiles(Data, err, rlst, true) then self.Log(' #Include Replace Error: ' + err); res.ContentType := fMIMEMap.GetFileMIMEType(doc); res.ContentStream := TStringStream.Create(Data); finally rlst.Free; end; end; end; end; Code to sendfiletoclient
  4. Hi, I am trying to create a .JSON file in Delphi 11 64-bit. While writing sample data to .json file , the &nbsp character was weird in 64-bit. In 32-bit version , it was like "u00A0" and when coming to 64-bit version it was like "u=<68" and sometimes "u3<78". When I parse this resulted json file in .JS files , it throws an error like "invalid JSON". Attached are samples from 32-bit and 64-bit. Please suggest. 32-bit.json 64-bit.json
  5. Attaching a sample project. The project will create a json file, which when we try to use in javascript reults in error "invalid Json". can be run in bot 32-bit and 64-bit with few changes. The changes were mentioned in the respected .pas files as comments. TestJson.7z
  6. Am having issue with "u3<78" . Instead of "u1618", am getting "u3<78" in some areas. When we see the 32-bit , it was 'u00A0' all over.
  7. It was just a part of json file, not the whole thing.
  8. We have introduced a new variable to the interface part and a function to the implementation portion of the Delphi 11 System.Sysutils.pas, in accordance with project requirements. The freshly generated variable is not accessible to me, and when I try to access it, I get the "Undefined Identifier" error. In Delphi 7, the same procedure was effective.
  9. Much grateful for you response. It worked. The problem is with this LOC. Without stdcall it worked in D7.
  10. AM sure, it's not working. When the call the Now() after "Interceptcreate", then as we hooked the "gettbttime" it will go to GetTBTtime proc and then decode the date which was given in the code. And then it goes to function Now() in sysutils.pas. In that function , the SystemTime var will be filled with either '0''s or weird numbers. The same code when in debugged using D7, the SystemTime var in Now() of sysutils.pas was filled with the date given in "gettbttime"
  11. In the DecodeDateTime, we will not use that param.
  12. Does DDetours offer support for Delphi 11? I'm having trouble using the library right now. DDetours was utilized in place of editing the sysutils.pas file, as advised. However, it functions properly with Delphi 7 but returns a "Inavalid Date to EncodeDate" issue with Delphi 11. This code sample, which functions well in D7 but not in D11, was supplied. implementation {$R *.dfm} var windows_GetLocalTime: procedure(var st: TSystemTime); stdcall; procedure getTbtTime(var st: TSystemTime); var dt: TDateTime; begin dt := strtodatetime('12/06/2024'); DecodeDateTime(dt, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); end; procedure TForm1.FormCreate(Sender: TObject); begin windows_GetLocalTime := Windows.GetLocalTime; end; procedure TForm1.Button1Click(Sender: TObject); var dt, value: TDateTime; s: string; begin dt := Now; showmessage('before hook:- ' + datetimetostr(dt)); windows_GetLocalTime := InterceptCreate(@Windows.GetLocalTime, @getTbtTime); dt := Now; // Returns error "Invalid date to Encodedate" s := FormatDateTime('mm/dd/yyyy : hh:nn:ss.zzz - ', dt); // showmessage('after hook:- ' + datetimetostr(dt)); end;
  13. I didn't fully go through their WiKi and examples before, but the "Hooking WinAPI function" example is exactly what I need. I've got the idea how it works now. Thank you ALL for helping out pointing me the right direction!
  14. I was planning to use the suggested DDetours library and since I didn't have it nor D11 in front of me I called it createNewDetour(). This is the actual function: function InterceptCreate(const TargetProc, InterceptProc: Pointer; const Param: Pointer = nil; const Options: TInterceptOptions = DefaultInterceptOptions): Pointer; overload; Calling reference of the original function will not work then. Thank you for the explanation of the internal DDetours implementation. If there is no other way than I'll look into modifying the PE imports table. That is something I never had to do. Hopefully it is easy.
  15. Great idea, thank you. I will save the original reference before the detour and use that from within. FYI, I'm going to rewrite the existing D7 implementation using the mentioned DDetour library and use same or built in D11 as well.
  16. before I start, how do I ensure that calling the original Windows.GetLocalTime from within my detoured function does not get also detoured causing circular reference errors? Or that will no longer possible? Example: procedure myNewLocalTime(var st: TSystemTime); begin st := Windows.GetLocalTime(st); // now further modify st end; createNewDetour(@Window.GetLocalTime, @myNewLocalTime, ...);
  17. Because our software needs to operate/tested through time from past to the future in cycles and we can't change the OS time as we did in past.
  18. Thanks for this suggestion too. GetLocalTime is just reference into external Windows DLL in Windows unit I think. I'll need to create a wrapper with same name around it with additional logic somewhere within my project which can be reached by the original GetLocalTime in sysUtils? Correction: it doesn't need to have same name. I could do something like: // excuse wrong code as I do not have D11 in front of me createNewDetour(@Window.GetLocalTime, @myNewLocalTime, ...); yes?
  19. If detours take care of this than that would be exactly what I need! I will attach detours in main's object constructor and test even 3rd party code goes through them. Thank you all for this suggestion!
  20. Hi, I looked into the detours, its definitely a cool feature but I'm not sure it will solve our dilemma. With some (coding) effort detours may intercept the few system's DateTime functions within our project units, but what about 3rd party units, code and components? They will probably be still using the core sysUtils with original functionality. This may introduce bugs as the app will use 2 different times (ours, and OS). Is there a way (place in Delphi) we could easily (without recompiling RTL/VCL) override the few sysUtils's functions? Or this exactly can be accomplished with proper implementation of detours?
  21. If it's really about the interface section, then i have tested the same without modifying interface section. I just created a new function in implementation section and tried to call the newly added function in our sample app. It also gives me the same error.
  22. The utility was a good suggestion. Thanks for that. But, in our case we would like to handle it in our code as we sync the changes with DB and other's.
  23. related to datetime or datetime conversions?
  24. In Delphi 7 we easily intercepted/modified result of all DateTime core functions as Now, Date, Time etc. to use our DateTime (not the real OS DateTime) for testing purposes without the need to change the machine's OS time. D7 easily allowed us to do that introducing an optional event. Here is a small example how we successfully handled it in D7: type TGetTbtTime = procedure(var st: TSystemTime) of object; var gGetTbtTime: TGetTbtTime; procedure tbtLocalTime(var st: TSystemTime); begin if Assigned(gGetTbtTime) then gGetTbtTime(st) // HERE WE PROVIDE BACK OUR OWN DATETIME else Window.GetLocalTime(st); end; // NATIVE DELPHI FUNCTION function Date: TDateTime; var SystemTime: TSystemTime; begin tbtLocalTime(SystemTime); with SystemTime do Result := EncodeDate(wYear, wMonth, wDay); end; D11 is giving us a hard time to do the same.
×