Jump to content
  • Advertisement

Iris_Technologies

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

2 Neutral

About Iris_Technologies

  • Rank
    Newbie

Personal Information

  • Role
    Programmer
  • Interests
    Programming
  1. Okay so, for future readers of that post, after reading about that, port forwarding means that the info that comes to the router public address through the port 8888 must be redirected to the local specific ip machine(192.168.x.x). Why? Because there can be different machines connected to one router, so the router needs to map all of them(i.e. pc1 -> 192.168.1.1, phone1 -> 192.168.1.2, pc2 -> 192.168.1.3, etc...). You need to tell the router which device will receive the incoming data, but it does not know about names, so you need to specify it with the specific local ip of your machine. How? Here is where upnp comes to the rescue. You need to use a dll called natupnp.dll and import some functions to your c# code (details here: http://pietschsoft.com/post/2009/02/NET-Framework-Communicate-through-NAT-Router-via-UPnP) and link the port to the local ip address of your machine(you can get it using ipconfig). Thanks to all for your help.
  2. Yes, I'm using a normal router, i already opened that port for all the applications through the firewall inbound rules(I setted that as Tcp) and yet that did not work for me. What can be wrong?
  3. I tried to program a simple networking test with a WAN server/client, but it failed. I know the problem is not the ports or the buffer to be sent, because I tried it using the localhost(127.0.0.1) and the string "hihi" was shown correctly by the server, but when I tried with my public IPv4(the ip you can get on any website googling for 'my ip'), that just don't works, and the server stays on the Waiting for connection... forever, and the client launchs an exception(not timeout) which says that the server didn't response. It's not a port forwarding problem, because then my localhost would not been worked neither. The code: Server: static void Main(string[] args) { TcpListener s = null; try { s = new TcpListener(IPAddress.Any, 8888); s.Start(1); byte[] dataBytes = new byte[4]; string data; while(true) { Console.WriteLine("Waiting for a connection..."); TcpClient c = s.AcceptTcpClient(); Console.WriteLine("Connected!"); c.ReceiveTimeout = 999999999; NetworkStream ns = c.GetStream(); int i; while((i = ns.Read(dataBytes, 0, dataBytes.Length)) != 0) { data = Encoding.ASCII.GetString(dataBytes, 0, i); Console.WriteLine("Received: {0}", data); } c.Close(); } } catch(SocketException e) { Console.WriteLine("An exception ocurred!"); } finally { s.Stop(); } Console.ReadLine(); } Client: static void Main(string[] args) { string msg = "hihi"; bool localhost = false; TcpClient c = null; try { if(!localhost) c = new TcpClient("83.xx.xx.xx", 8888); else c = new TcpClient("127.0.0.1", 8888); c.SendTimeout = 999999999; byte[] data = Encoding.ASCII.GetBytes(msg); NetworkStream ns = c.GetStream(); ns.Write(data, 0, data.Length); Console.WriteLine("Sent: {0}", msg); ns.Close(); } catch(SocketException e) { Console.WriteLine("An exception ocurred: {0}", e.ToString()); } finally { c.Close(); } Console.ReadLine(); }
  4. Iris_Technologies

    Creating a language - Static Libraries

    Linkers not only work with native calls, they are also used to link functions and calls inside your code. One feature of my language needs to have access to the memory offset of the instructions, so I need to do it for myself.
  5. Iris_Technologies

    Creating a language - Static Libraries

    I thinked about the fact that adding a procedure to the import table of a .exe could be the answer. But i didn't think on it pretty well. So, you are telling me basically that, if i add the demangled function name and the base RVA, which i could extract from the .dll without needing to relocate, on the import table, when the .exe is loaded into memory, the RVA of the imported functions will be relocated by the OS loader and i don't need to do any black magic?
  6. So, after days of headaches, I finally clarify a lot of how to call native functions of the operating system from a new programming language. The key are static libraries(.lib, on Windows, don't confuse with import libraries which have the same file extension). Dynamic libraries(.dll) won't do the work because: 1.- You could still read the RVA(Relative Virtual Address), from the exported table, but still even if you link the call to the function with such memory address on your binary, that would fail because, that RVA on dynamic libraries are the base address. To get the real address(process of converting RVA to VA(virtual address)) of such function, you need to relocate the RVA at runtime, because its address is shared across multiple binaries, so you would need to call LoadLibrary, FreeLibrary and GetProcAddress, which redirect us to the point 2. 2.- Because that functions are also SO calls, you can't call their RVA, because we will end with the problem of point 1. So I were in a death point, until I read about Static Linking and Static Libraries. The concept of such kind of libraries is, they don't have RVA, because the VA of its exported functions are resolved at compile-time. But now, I faced another problem, finding information about that kind of file format is hard, and is opaqued by relocation on dynamic libraries, all that I read is by using Dumpbin and the command /SYMBOLS you could create a table of exported functions, but I can't make the users of my language download Visual Studio just for this tool. So, all I wanted to do is reading this by my own, but it's not so easy. First, I tried to read such files from the Dependency Walker, but seems like they don't use DOS Header or PE Header. So I ended up reading about how other languages did this kind of stuff, and I founded that they used a technique called FFI, which, could be described as some kind of Marshallization(it's just my point of view, may is incorrect), but this is not what I want just yet, first, I want to read the fixed VA of the exported functions of such static libraries, but seems like they are missing such information. Any clarification about it?
  7. Suppose i don't have any linker at hand but i am calling an exported function from a C++ DLL Windows, i.e. sqrt from mvcrt14.dll, how would i get just and only just the Relative Virtual Address of sqrt from that dll to simulate what linker does and convert this call to a call to such RVA on the hexcoded generated .exe file? Either, how would i read the RVA of Mac, Android, iOS and Linux library formats?
  8. Now another question comes to my mind, how the assembler would manage negative offsets?, like, suppose you have a function that is being called on Byte ID Offset 3, but the call is performed on Byte ID Offset 8, how would the Opcode look? EDIT Nvm, I tried it for myself: I had this kind of code gh: mov ax, dx hh: mov dx, cx call gh so the call procedure would be at Byte ID Offset 6 and the gh function would be at 0. The Opcode would look like 'e8 f5 ff ff ff'. Looks like for negative offsets It works as the max. byte value('ff ff ff ff'), minus the Byte ID Offset of the next instruction after the call procedure. So if we have the start of call procedure at Byte ID 6 plus the size of the call opcode itself(which is 5) would end at Byte ID Offset b(11 in decimal). Now, if we do the rest of 'ff ff ff ff' - 'b' we would end up with 'f5 ff ff ff'.
  9. I had some doubts about hex formats(assembler output) and linkers: 1.- So, I disassembly a raw binary(no ELF, PE, etc... headers) X64 assembly code and i got that result: 0: 66 89 c8 mov ax,cx 3: e8 00 00 00 00 call 8 <gh> 0000000000000008 <gh>: 8: 66 89 c2 mov dx,ax I understand how Byte Offset works('66' is the byte ID 0, '89' is 1, 'c8' is 2 and on 3 the call instruction starts(that is why '3:' is there)) but, by that logic, shouldn't 'call gh' be translated to 'e8 00 00 00 00 00 00 00 08' instead of 'e8 00 00 00 00' since the byte offset of the first instruction of gh, which is 'mov dx, ax' is 8 and the output is 64 bits? 2.- Using the example of above, if endianness is little end., how the assembler would swap the bytes, by each instruction? Like: Original, no endiannes { 66 89 c8 e8 00 00 00 00(in case that would be correct and i'm wrong in the question 1.-) 66 89 c2 } to { c8 89 66 00 00 00 00 e8 c2 89 66 } 3.- And then, the big end. would be like the original, without endiannes, code of the question 2.-? 4.- Suppose that i mark gh as .globl, then, would the assembler create a map table file where gh is in 'e8 00 00 00 00'(again, in case that would be correct and i'm wrong in question 1.-), and linker will look into such map file, and if another object file calls gh, the linker will then translate call gh as either 'e8 00 00 00 00'?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!