Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)
New Posts  All Forums:Forum Nav:

Programming Challenge #7 (by Plan9) - Page 2

post #11 of 50
Quote:
Originally Posted by Sikku View Post

It can be useful upto may be certain extent.. But writing self modifying code is not that easy.. First of all not all programming languages support for self modifying code..
C compilers compile the source code into segments which are read-only so self-modification is not possible.. You may have to use assembly language programming for such matter but it is very tedious to do so... It is very difficult to debug and you never know what could be the output.. In turn you may harm the system... So a perfectly safe challenge isnt that perfect... smile.gif

I hate to be pig-headed, but I've been programming long enough to know all of this 30 times over smile.gif
You won't harm the system unless you exploit a bug in it. It's hard to write to memory outside of your address space by accident.

Also you can actually modify whatever the heck you want inside your address space, regardless of what the compiler does. Once it is in memory and you have the privileges, you're already on the other end of the airtight hatchway smile.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #12 of 50
Here we go, this demonstrates how to modify/create code in memory on Windows. It simply generates 4 methods for the most basic arithmetic operations using x86 instructions. {I had to refer to the x86 op-code list, I hadn't done this sort of thing for so long!}.

You can use the same technique to modify op-codes already present in memory.
Code:
#define VM_SIZE_SUB_START ( sizeof( BYTE ) * 6 ) /* 6 bytes for function start */
#define VM_SIZE_SUB_END   ( sizeof( BYTE ) * 2 ) /* 2 bytes for function end */

#define VM_SIZE_COMPUTE_SUM_1 ( VM_SIZE_SUB_START + VM_SIZE_SUB_END ) + sizeof( BYTE ) * 3 /* 11 byte routine for addition, subtraction */
#define VM_SIZE_COMPUTE_SUM_2 ( VM_SIZE_SUB_START + VM_SIZE_SUB_END ) + sizeof( BYTE ) * 4 /* 12 byte routine for multiplication */
#define VM_SIZE_COMPUTE_SUM_3 ( VM_SIZE_SUB_START + VM_SIZE_SUB_END ) + sizeof( BYTE ) * 6 /* 14 byte routine for division */

typedef LONG ( *PCALCULATESUM ) ( LONG, LONG );

/* Forward declarations */
PCALCULATESUM GenerateAddRoutine();
PCALCULATESUM GenerateSubtractRoutine();
PCALCULATESUM GenerateMultiplyRoutine();
PCALCULATESUM GenerateDivisionRoutine();
BOOL GenerateRoutineStart( LPBYTE buffer, PDWORD dwNextOffset );
BOOL GenerateRoutineEnd( LPBYTE buffer, DWORD dwOffset );
BOOL SetExecutable( LPBYTE buffer, SIZE_T dwSize );

int main()
{
        /* Generate routines */
        PCALCULATESUM AddRoutine      = GenerateAddRoutine();
        PCALCULATESUM SubtractRoutine = GenerateSubtractRoutine();
        PCALCULATESUM MultiplyRoutine = GenerateMultiplyRoutine();
        PCALCULATESUM DivisionRoutine = GenerateDivisionRoutine();

        /* Make sure we got all the routines generated */
        if ( !AddRoutine || !SubtractRoutine || !MultiplyRoutine || !DivisionRoutine )
                return 1;

        /* Tests */
        LONG result = AddRoutine( 10, 10 );
        printf( "ADD - 10+10: %d\n\n", result );

        result = SubtractRoutine( 20, 10 );
        printf( "SUBTRACT - 20-10: %d\n\n", result );

        result = MultiplyRoutine( 10, 10 );
        printf( "MULTIPLY - 10*10: %d\n\n", result );

        result = DivisionRoutine( 10, 2 );
        printf( "DIVIDE: - 10/2: %d\n\n", result );

        /* Clean up */
        VirtualFree( AddRoutine, VM_SIZE_COMPUTE_SUM_1, MEM_RELEASE );
        VirtualFree( SubtractRoutine, VM_SIZE_COMPUTE_SUM_1, MEM_RELEASE );
        VirtualFree( MultiplyRoutine, VM_SIZE_COMPUTE_SUM_2, MEM_RELEASE );
        VirtualFree( DivisionRoutine, VM_SIZE_COMPUTE_SUM_3, MEM_RELEASE );

        getchar();
        return 0;
}

BOOL GenerateRoutineStart( LPBYTE buffer, PDWORD dwNextOffset )
{
        *dwNextOffset = 0;
        if ( !buffer )
                return FALSE;

        /* Fill contents of this memory region with our op-codes */
        /* */
        /* push ebp */
        buffer[0] = 0x55;
        /* mov ebp, esp */
        buffer[1] = 0x8B;
        buffer[2] = 0xEC;
        /* mov eax, [ebp+8] */
        buffer[3] = 0x8B;
        buffer[4] = 0x45;
        buffer[5] = 0x08;

        /* Set next offset */
        *dwNextOffset = 6;
        return TRUE;
}

BOOL GenerateRoutineEnd( LPBYTE buffer, DWORD dwOffset )
{
        if ( !buffer || !dwOffset ) /* can't start at 0 */
                return FALSE;

        /* Fill contents of this memory region with our op-codes */
        /* */
        /* pop ebp */
        buffer[dwOffset] = 0x5D;
        /* ret eax */
        buffer[dwOffset+1] = 0xC3;
}

BOOL SetExecutable( LPBYTE buffer, SIZE_T dwSize )
{
        /* Allow this memory of region to be executable */
        DWORD oldProtect;
        if ( !VirtualProtect( buffer, dwSize, PAGE_EXECUTE, &oldProtect ) )
                return NULL;

        /* Flush the instruction cache */
        FlushInstructionCache( GetCurrentProcess(), NULL, NULL );
}

/* Let's build some functions dynamically in memory using x86 op-codes */
PCALCULATESUM GenerateAddRoutine()
{
        LPBYTE __add = ( LPBYTE ) VirtualAlloc( NULL, 
                VM_SIZE_COMPUTE_SUM_1, 
                MEM_COMMIT | MEM_RESERVE, 
                PAGE_READWRITE );

        if ( !__add )
                return NULL;

        /* Fill contents of this memory region with our op-codes */
        DWORD offset;
        if ( !GenerateRoutineStart( __add, &offset ) )
                return NULL;

        /* Generate the sum operation */
        /* */
        /* add eax, [ebp+12] */
        __add[offset++] = 0x03;
        __add[offset++] = 0x45;
        __add[offset++] = 0x0C;

        /* Finalize */
        if ( !GenerateRoutineEnd( __add, offset ) )
                return NULL;

        if ( !SetExecutable( __add, VM_SIZE_COMPUTE_SUM_1 ) )
                return NULL;

        return ( PCALCULATESUM ) __add;
}

PCALCULATESUM GenerateSubtractRoutine()
{
        LPBYTE __subtract = ( LPBYTE ) VirtualAlloc( NULL,
                VM_SIZE_COMPUTE_SUM_1, 
                MEM_COMMIT | MEM_RESERVE,
                PAGE_READWRITE );

        if ( !__subtract )
                return NULL;

        /* Fill contents of this memory region with our op-codes */
        DWORD offset;
        if ( !GenerateRoutineStart( __subtract, &offset ) )
                return NULL;

        /* Generate the sum operation */
        /* */
        /* sub eax, [ebp+12] */
        __subtract[offset++] = 0x2B;
        __subtract[offset++] = 0x45;
        __subtract[offset++] = 0x0C;

        /* Finalize */
        if ( !GenerateRoutineEnd( __subtract, offset ) )
                return NULL;

        if ( !SetExecutable( __subtract, VM_SIZE_COMPUTE_SUM_1 ) )
                return NULL;

        return ( PCALCULATESUM ) __subtract;
}

PCALCULATESUM GenerateMultiplyRoutine()
{
        LPBYTE __multiply = ( LPBYTE ) VirtualAlloc( NULL,
                VM_SIZE_COMPUTE_SUM_2, 
                MEM_COMMIT | MEM_RESERVE,
                PAGE_READWRITE );

        if ( !__multiply )
                return NULL;

        /* Fill contents of this memory region with our op-codes */
        DWORD offset;
        if ( !GenerateRoutineStart( __multiply, &offset ) )
                return NULL;

        /* Generate the sum operation */
        /* */
        /* imul ecx, [ebp+12] */
        __multiply[offset++] = 0x0F;
        __multiply[offset++] = 0xAF;
        __multiply[offset++] = 0x45;
        __multiply[offset++] = 0x0C;

        /* Finalize */
        if ( !GenerateRoutineEnd( __multiply, offset ) )
                return NULL;

        if ( !SetExecutable( __multiply, VM_SIZE_COMPUTE_SUM_2 ) )
                return NULL;

        return ( PCALCULATESUM ) __multiply;
}

PCALCULATESUM GenerateDivisionRoutine()
{
        LPBYTE __division = ( LPBYTE ) VirtualAlloc( NULL,
                VM_SIZE_COMPUTE_SUM_3, 
                MEM_COMMIT | MEM_RESERVE,
                PAGE_READWRITE );

        if ( !__division )
                return NULL;

        /* Fill contents of this memory region with our op-codes */
        DWORD offset;
        if ( !GenerateRoutineStart( __division, &offset ) )
                return NULL;

        /* Generate the sum operation */
        /* */
        /* mov ecx, [ebp+12] */
        __division[offset++] = 0x8B;
        __division[offset++] = 0x4D;
        __division[offset++] = 0x0C;
        /* cdq */
        __division[offset++] = 0x99;
        /* idiv eax, ecx */
        __division[offset++] = 0xF7;
        __division[offset++] = 0xF9;

        /* Finalize */
        if ( !GenerateRoutineEnd( __division, offset ) )
                return NULL;

        if ( !SetExecutable( __division, VM_SIZE_COMPUTE_SUM_3 ) )
                return NULL;

        return ( PCALCULATESUM ) __division;
}

Enjoy smile.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #13 of 50
Thread Starter 
oh wow. I can't even pretend to understand half of that. applaud.gif
post #14 of 50
Quote:
Originally Posted by Plan9 View Post

oh wow. I can't even pretend to understand half of that. applaud.gif

It's relatively simple - allocate a chunk of memory as read/write, write x86 instructions to it (we are using __stdcall here), then ask Windows to mark it as executable. Lastly cast the memory chunk to a function pointer, and then call the function.

Have fun tongue.gif

Now excuse me while I go and kill myself for remembering what x86 op-codes are and how they work. Thank you so much C#.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #15 of 50
Cool challenge, I started researching for it and found the programming language Malbolge

http://en.wikipedia.org/wiki/Malbolge_programming_language

I LOL'd for about 5 minutes.
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
post #16 of 50
In java the only way to have 'dynamic code' is to use java to compile a new class. (involves writing to disc in most cases)

Then I stumbled on this: http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm

So basically you construct a java file around the line you want to compile, then compile it (all inside memory) and then execute, catching all the exceptions....


very very not nice.

Other solutions (if writing to disc was allowed): JavaAssist, Groovy, and even a normal use case of Javac.


I am currently at work and don't have time to make my own version of the above.... but know that it can be done in java......
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  hide details  
Reply
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  hide details  
Reply
post #17 of 50
Quote:
Originally Posted by rush2049 View Post

In java the only way to have 'dynamic code' is to use java to compile a new class. (involves writing to disc in most cases)
Then I stumbled on this: http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm
So basically you construct a java file around the line you want to compile, then compile it (all inside memory) and then execute, catching all the exceptions....
very very not nice.
Other solutions (if writing to disc was allowed): JavaAssist, Groovy, and even a normal use case of Javac.
I am currently at work and don't have time to make my own version of the above.... but know that it can be done in java......

I was wondering how it could be done in Java. Thanks for the link. smile.gif
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #18 of 50
Quote:
Originally Posted by rush2049 View Post

In java the only way to have 'dynamic code' is to use java to compile a new class. (involves writing to disc in most cases)
Then I stumbled on this: http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm
So basically you construct a java file around the line you want to compile, then compile it (all inside memory) and then execute, catching all the exceptions....
very very not nice.
Other solutions (if writing to disc was allowed): JavaAssist, Groovy, and even a normal use case of Javac.
I am currently at work and don't have time to make my own version of the above.... but know that it can be done in java......

Another area where .NET smokes Java tongue.gif
http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx (requires knowledge of MSIL).

You can also use expression trees: (easier than System.Reflection.Emit)
http://msdn.microsoft.com/en-us/library/bb397951.aspx
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #19 of 50
Code:
#!/usr/bin/env python

print eval( raw_input( "Enter equation: " ) )

tongue.gif
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #20 of 50
Quote:
Originally Posted by poroboszcz View Post

Code:
#!/usr/bin/env python
print eval( raw_input( "Enter equation: " ) )
tongue.gif

LOL
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)